Slight refactoring, add some Logging

live-sensor-data
cpfeiffer 2015-05-10 00:18:42 +02:00
parent 39d84831ed
commit 86119a877a
1 changed files with 18 additions and 9 deletions

View File

@ -43,11 +43,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
break; break;
case BluetoothAdapter.ACTION_DISCOVERY_FINISHED: case BluetoothAdapter.ACTION_DISCOVERY_FINISHED:
// continue with LE scan, if available // continue with LE scan, if available
if (GB.supportsBluetoothLE()) { startDiscovery(Scanning.SCANNING_BTLE);
startBTLEDiscovery();
} else {
discoveryFinished();
}
break; break;
case BluetoothAdapter.ACTION_STATE_CHANGED: case BluetoothAdapter.ACTION_STATE_CHANGED:
int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, BluetoothAdapter.STATE_OFF); int oldState = intent.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, BluetoothAdapter.STATE_OFF);
@ -177,14 +173,25 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
*/ */
private void startDiscovery() { private void startDiscovery() {
if (isScanning()) { if (isScanning()) {
Log.w(TAG, "Not starting BLE discovery, because already scanning."); Log.w(TAG, "Not starting discovery, because already scanning.");
return; return;
} }
startDiscovery(Scanning.SCANNING_BT);
}
Log.i(TAG, "Starting discovery..."); private void startDiscovery(Scanning what) {
discoveryStarted(Scanning.SCANNING_BT); // just to make sure Log.i(TAG, "Starting discovery: " + what);
discoveryStarted(what); // just to make sure
if (ensureBluetoothReady()) { if (ensureBluetoothReady()) {
startBTDiscovery(); if (what == Scanning.SCANNING_BT) {
startBTDiscovery();
} else if (what == Scanning.SCANNING_BTLE){
if (GB.supportsBluetoothLE()) {
startBTLEDiscovery();
} else {
discoveryFinished();
}
}
} else { } else {
discoveryFinished(); discoveryFinished();
Toast.makeText(this, "Enable Bluetooth to discover devices.", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Enable Bluetooth to discover devices.", Toast.LENGTH_LONG).show();
@ -265,12 +272,14 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli
} }
private void startBTLEDiscovery() { private void startBTLEDiscovery() {
Log.i(TAG, "Starting BTLE Discovery");
handler.removeMessages(0, stopRunnable); handler.removeMessages(0, stopRunnable);
handler.postDelayed(stopRunnable, SCAN_DURATION); handler.postDelayed(stopRunnable, SCAN_DURATION);
adapter.startLeScan(leScanCallback); adapter.startLeScan(leScanCallback);
} }
private void startBTDiscovery() { private void startBTDiscovery() {
Log.i(TAG, "Starting BT Discovery");
handler.removeMessages(0, stopRunnable); handler.removeMessages(0, stopRunnable);
handler.postDelayed(stopRunnable, SCAN_DURATION); handler.postDelayed(stopRunnable, SCAN_DURATION);
adapter.startDiscovery(); adapter.startDiscovery();