Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jon.light.remote;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.util.Set;
- import java.util.UUID;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.CompoundButton;
- import android.widget.Toast;
- import android.app.Activity;
- import android.bluetooth.BluetoothAdapter;
- import android.bluetooth.BluetoothDevice;
- import android.bluetooth.BluetoothSocket;
- import android.content.Context;
- import android.content.Intent;
- public class MainActivity extends Activity {
- //MAC Address of the device
- private static String MAC_ADDRESS = "cc:52:af:f2:44:aa"; /*"00:00:00:00:00:00";*/
- //UUID to identify both devices
- private final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
- private CheckBox ChkBluetooth, ChkLED;
- private Button BtnConnect, BtnNext;
- private BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
- private BluetoothDevice mBluetoothDevice;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- //Privates that are lunched on startup
- //Connect_to_BTdevice();
- //Jon
- ButtonsandCheckbox();
- VerifyBTstate();
- //Jon
- } //Fin onCreate
- private void VerifyBTstate() {
- if(mBluetoothAdapter.isEnabled()) {
- ChkBluetooth.setChecked(true);
- }
- } //Fin VerifyBTState
- private void ButtonsandCheckbox() {
- ChkBluetooth = (CheckBox) findViewById(R.id.ChkBluetooth);
- ChkBluetooth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
- {
- if (isChecked) {
- mBluetoothAdapter.enable();
- Context context = getApplicationContext();
- CharSequence text = "Bluetooth Enabled";
- int duration = Toast.LENGTH_SHORT;
- Toast.makeText(context, text, duration).show();
- } else
- {mBluetoothAdapter.disable();
- Context context = getApplicationContext();
- CharSequence text = "Bluetooth Disabled";
- int duration = Toast.LENGTH_SHORT;
- Toast.makeText(context, text, duration).show();}}});
- BtnConnect = (Button) findViewById(R.id.BtnConnect);
- BtnConnect.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- //Connect to an already paired device.
- if (ChkBluetooth.isChecked()) {}
- else
- {Context context = getApplicationContext();
- CharSequence text = "Le bluetooth est désactivé";
- int duration = Toast.LENGTH_SHORT;
- Toast.makeText(context, text, duration).show();}
- }});
- ChkLED = (CheckBox) findViewById(R.id.ChkLED);
- ChkLED.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
- {if (isChecked) {
- Context context = getApplicationContext();
- CharSequence text = "Activé";
- int duration = Toast.LENGTH_SHORT;
- Toast.makeText(context, text, duration).show();}
- else
- {Context context = getApplicationContext();
- CharSequence text = "Désactivé";
- int duration = Toast.LENGTH_SHORT;
- Toast.makeText(context, text, duration).show();}
- }});
- } //Fin ButtonandCheck
- } //Fin Activity
Advertisement
Add Comment
Please, Sign In to add comment