From 86119a877ae8e6fe620df635ebd55196e3b3184f Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Sun, 10 May 2015 00:18:42 +0200 Subject: [PATCH] Slight refactoring, add some Logging --- .../discovery/DiscoveryActivity.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/discovery/DiscoveryActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/discovery/DiscoveryActivity.java index d47dfb70..6ed80aee 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/discovery/DiscoveryActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/discovery/DiscoveryActivity.java @@ -43,11 +43,7 @@ public class DiscoveryActivity extends Activity implements AdapterView.OnItemCli break; case BluetoothAdapter.ACTION_DISCOVERY_FINISHED: // continue with LE scan, if available - if (GB.supportsBluetoothLE()) { - startBTLEDiscovery(); - } else { - discoveryFinished(); - } + startDiscovery(Scanning.SCANNING_BTLE); break; case BluetoothAdapter.ACTION_STATE_CHANGED: 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() { if (isScanning()) { - Log.w(TAG, "Not starting BLE discovery, because already scanning."); + Log.w(TAG, "Not starting discovery, because already scanning."); return; } + startDiscovery(Scanning.SCANNING_BT); + } - Log.i(TAG, "Starting discovery..."); - discoveryStarted(Scanning.SCANNING_BT); // just to make sure + private void startDiscovery(Scanning what) { + Log.i(TAG, "Starting discovery: " + what); + discoveryStarted(what); // just to make sure if (ensureBluetoothReady()) { - startBTDiscovery(); + if (what == Scanning.SCANNING_BT) { + startBTDiscovery(); + } else if (what == Scanning.SCANNING_BTLE){ + if (GB.supportsBluetoothLE()) { + startBTLEDiscovery(); + } else { + discoveryFinished(); + } + } } else { discoveryFinished(); 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() { + Log.i(TAG, "Starting BTLE Discovery"); handler.removeMessages(0, stopRunnable); handler.postDelayed(stopRunnable, SCAN_DURATION); adapter.startLeScan(leScanCallback); } private void startBTDiscovery() { + Log.i(TAG, "Starting BT Discovery"); handler.removeMessages(0, stopRunnable); handler.postDelayed(stopRunnable, SCAN_DURATION); adapter.startDiscovery();