From adf39f26808589d642e52c1d20a4f6f4f3f789e4 Mon Sep 17 00:00:00 2001 From: Mauro Del Rio Date: Sat, 22 Feb 2014 11:20:45 +0100 Subject: [PATCH] added some toasts --- .../musiccontroller/BluetoothLeService.java | 37 ++++++++----------- .../example/musiccontroller/MainActivity.java | 3 ++ 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/MusicController/src/com/example/musiccontroller/BluetoothLeService.java b/MusicController/src/com/example/musiccontroller/BluetoothLeService.java index 3e6bf64..d107f83 100644 --- a/MusicController/src/com/example/musiccontroller/BluetoothLeService.java +++ b/MusicController/src/com/example/musiccontroller/BluetoothLeService.java @@ -51,7 +51,7 @@ public class BluetoothLeService extends Service { private static final UUID SIMPLE_KEYS_SERVICE_UUID = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb"); private static final UUID SIMPLE_KEYS_DATA_UUID = UUID.fromString("0000ffe1-0000-1000-8000-00805f9b34fb"); private BluetoothGattCharacteristic keyCharacteristic; - + private static SimpleKeysStatus previousStatus; private BluetoothDevice sensorTag; @@ -101,27 +101,22 @@ public void onCharacteristicChanged (BluetoothGatt gatt, BluetoothGattCharacter SimpleKeysStatus newValue = SimpleKeysStatus.values()[encodedInteger % 4]; Log.i(TAG, "newValue " + newValue.toString()); - if (newValue == SimpleKeysStatus.OFF_ON){ - AudioManager mAudioManager = (AudioManager) getSystemService(BluetoothLeService.this.AUDIO_SERVICE); - - if(mAudioManager.isMusicActive()) { - Intent i = new Intent(SERVICECMD); - i.putExtra(CMDNAME , CMDNEXT ); - BluetoothLeService.this.sendBroadcast(i); - } - } - else if (newValue == SimpleKeysStatus.ON_OFF){ - AudioManager mAudioManager = (AudioManager) getSystemService(BluetoothLeService.this.AUDIO_SERVICE); - - if(mAudioManager.isMusicActive()) { - Intent i = new Intent(SERVICECMD); - i.putExtra(CMDNAME , CMDPREVIOUS); - BluetoothLeService.this.sendBroadcast(i); - } - } + AudioManager mAudioManager = (AudioManager) getSystemService(BluetoothLeService.this.AUDIO_SERVICE); + Intent i = new Intent(SERVICECMD); + if(mAudioManager.isMusicActive()) { + if (newValue == SimpleKeysStatus.OFF_ON){ + i.putExtra(CMDNAME , CMDNEXT ); + } + else if (newValue == SimpleKeysStatus.ON_OFF){ + i.putExtra(CMDNAME , CMDPREVIOUS); + } + BluetoothLeService.this.sendBroadcast(i); + previousStatus = newValue; + } + } - } - + } + @Override // New services discovered public void onServicesDiscovered(BluetoothGatt gatt, int status) { diff --git a/MusicController/src/com/example/musiccontroller/MainActivity.java b/MusicController/src/com/example/musiccontroller/MainActivity.java index c1e46ac..ac530b9 100644 --- a/MusicController/src/com/example/musiccontroller/MainActivity.java +++ b/MusicController/src/com/example/musiccontroller/MainActivity.java @@ -13,6 +13,7 @@ import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; +import android.widget.Toast; import android.util.Log; public class MainActivity extends Activity { @@ -42,6 +43,7 @@ public void onLeScan(final BluetoothDevice device, int rssi, public void run() { Log.i(TAG,"Found device " + device.getName()); if (device.getName().contains("SensorTag") ){ + Toast.makeText(MainActivity.this, "SensorTag found! ", Toast.LENGTH_SHORT).show(); Log.i(TAG,"Starting service..."); mBluetoothAdapter.stopLeScan(mLeScanCallback); Intent intent = new Intent(MainActivity.this, BluetoothLeService.class); @@ -108,6 +110,7 @@ public boolean onCreateOptionsMenu(Menu menu) { } private void scanLeDevice(final boolean enable) { + Toast.makeText(MainActivity.this, "Start scanning for BLE... ", Toast.LENGTH_SHORT).show(); Log.i(TAG, "starting scanLeDevice"); mScanning = true; mBluetoothAdapter.startLeScan(mLeScanCallback);