Guest User

light Remote android BT

a guest
Dec 10th, 2012
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.53 KB | None | 0 0
  1. package com.jon.light.remote;
  2.  
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.util.Set;
  6. import java.util.UUID;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.CheckBox;
  11. import android.widget.CompoundButton;
  12. import android.widget.Toast;
  13. import android.app.Activity;
  14. import android.bluetooth.BluetoothAdapter;
  15. import android.bluetooth.BluetoothDevice;
  16. import android.bluetooth.BluetoothSocket;
  17. import android.content.Context;
  18. import android.content.Intent;
  19.  
  20. public class MainActivity extends Activity {
  21.  
  22.    
  23.     //MAC Address of the device
  24.     private static String MAC_ADDRESS = "cc:52:af:f2:44:aa"; /*"00:00:00:00:00:00";*/
  25.     //UUID to identify both devices
  26.     private final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
  27.     private CheckBox ChkBluetooth, ChkLED;
  28.     private Button BtnConnect, BtnNext;
  29.     private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
  30.     private BluetoothDevice mBluetoothDevice;
  31.  
  32.  
  33.     @Override
  34.     public void onCreate(Bundle savedInstanceState) {
  35.         super.onCreate(savedInstanceState);
  36.         setContentView(R.layout.activity_main);
  37.         //Privates that are lunched on startup
  38.         //Connect_to_BTdevice();
  39.         //Jon
  40.         ButtonsandCheckbox();
  41.         VerifyBTstate();
  42.         //Jon
  43.     } //Fin onCreate
  44.        
  45.    
  46.     private void VerifyBTstate() {
  47.         if(mBluetoothAdapter.isEnabled()) {
  48.             ChkBluetooth.setChecked(true);
  49.         }
  50.     } //Fin VerifyBTState
  51.  
  52.  
  53.     private void ButtonsandCheckbox() {
  54.          ChkBluetooth = (CheckBox) findViewById(R.id.ChkBluetooth);
  55.          ChkBluetooth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  56.             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
  57.             {
  58.                 if (isChecked) {
  59.                     mBluetoothAdapter.enable();
  60.                    
  61.                     Context context = getApplicationContext();
  62.                     CharSequence text = "Bluetooth Enabled";
  63.                     int duration = Toast.LENGTH_SHORT;
  64.                     Toast.makeText(context, text, duration).show();
  65.                 } else
  66.                     {mBluetoothAdapter.disable();
  67.                     Context context = getApplicationContext();
  68.                     CharSequence text = "Bluetooth Disabled";
  69.                     int duration = Toast.LENGTH_SHORT;
  70.                     Toast.makeText(context, text, duration).show();}}});
  71.          
  72.        
  73.         BtnConnect = (Button) findViewById(R.id.BtnConnect);
  74.         BtnConnect.setOnClickListener(new View.OnClickListener() {
  75.  
  76.             public void onClick(View v) {
  77.                 //Connect to an already paired device.
  78.                
  79.                 if (ChkBluetooth.isChecked()) {}
  80.                 else
  81.                     {Context context = getApplicationContext();
  82.                     CharSequence text = "Le bluetooth est désactivé";
  83.                     int duration = Toast.LENGTH_SHORT;
  84.                     Toast.makeText(context, text, duration).show();}
  85.             }});
  86.          
  87.         ChkLED = (CheckBox) findViewById(R.id.ChkLED);
  88.         ChkLED.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  89.             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
  90.             {if (isChecked) {
  91.                     Context context = getApplicationContext();
  92.                     CharSequence text = "Activé";
  93.                     int duration = Toast.LENGTH_SHORT;
  94.                     Toast.makeText(context, text, duration).show();}
  95.             else
  96.                     {Context context = getApplicationContext();
  97.                     CharSequence text = "Désactivé";
  98.                     int duration = Toast.LENGTH_SHORT;
  99.                     Toast.makeText(context, text, duration).show();}
  100.             }});   
  101.             } //Fin ButtonandCheck
  102. } //Fin Activity
Advertisement
Add Comment
Please, Sign In to add comment