X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosDroid.java;fp=altosdroid%2Fsrc%2Forg%2Faltusmetrum%2FAltosDroid%2FAltosDroid.java;h=4f1dcb1a3b441cee951af66fd9728ba060e6eaf8;hp=855133253cd36e6ae142c3316698cae48fb7dc4d;hb=f49fd5d2be68de97ebe65fa4f6484746e91dd677;hpb=ea89feedd4185a5f583fa8ddf33a2ec0906e0dc0 diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index 85513325..4f1dcb1a 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -564,22 +564,15 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, mAgeOldColor = getResources().getColor(R.color.old_color); } - private boolean ensureBluetooth() { + private void ensureBluetooth() { // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - // If the adapter is null, then Bluetooth is not supported - if (mBluetoothAdapter == null) { - Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); - return false; - } - - if (!mBluetoothAdapter.isEnabled()) { + /* if there is a BT adapter and it isn't turned on, then turn it on */ + if (mBluetoothAdapter != null && !mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, AltosDroid.REQUEST_ENABLE_BT); } - - return true; } private boolean check_usb() { @@ -645,9 +638,7 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, return; } AltosDebug.debug("Starting by looking for bluetooth devices"); - if (ensureBluetooth()) - return; - finish(); + ensureBluetooth(); } } @@ -738,12 +729,11 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, if (resultCode == Activity.RESULT_OK) { // Bluetooth is now enabled, so set up a chat session //setupChat(); + AltosDebug.debug("BT enabled"); + bluetoothEnabled(data); } else { // User did not enable Bluetooth or an error occured - AltosDebug.error("BT not enabled"); - stopService(new Intent(AltosDroid.this, TelemetryService.class)); - Toast.makeText(this, R.string.bt_not_enabled, Toast.LENGTH_SHORT).show(); - finish(); + AltosDebug.debug("BT not enabled"); } break; case REQUEST_MAP_TYPE: @@ -767,6 +757,14 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, } } + private void bluetoothEnabled(Intent data) { + try { + mService.send(Message.obtain(null, TelemetryService.MSG_BLUETOOTH_ENABLED, null)); + } catch (RemoteException e) { + AltosDebug.debug("send BT enabled message failed"); + } + } + private void connectDevice(Intent data) { // Attempt to connect to the device try { @@ -907,11 +905,10 @@ public class AltosDroid extends FragmentActivity implements AltosUnitsListener, Intent serverIntent = null; switch (item.getItemId()) { case R.id.connect_scan: - if (ensureBluetooth()) { - // Launch the DeviceListActivity to see devices and do scan - serverIntent = new Intent(this, DeviceListActivity.class); - startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); - } + ensureBluetooth(); + // Launch the DeviceListActivity to see devices and do scan + serverIntent = new Intent(this, DeviceListActivity.class); + startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE); return true; case R.id.disconnect: /* Disconnect the device