Disable context menu while busy and add "Disconnect" to context menu
This commit is contained in:
parent
dc8d1e961d
commit
ba76f64bf6
|
@ -58,6 +58,8 @@ public class BluetoothCommunicationService extends Service {
|
|||
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.install_pebbbleapp";
|
||||
public static final String ACTION_REBOOT = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.reboot";
|
||||
public static final String ACTION_FETCH_ACTIVITY_DATA = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.fetch_activity_data";
|
||||
public static final String ACTION_DISCONNECT = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.disconnect";
|
||||
|
||||
public static final String EXTRA_PERFORM_PAIR = "perform_pair";
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BluetoothCommunicationService.class);
|
||||
|
@ -76,7 +78,8 @@ public class BluetoothCommunicationService extends Service {
|
|||
GBDevice device = intent.getParcelableExtra("device");
|
||||
if (mGBDevice.equals(device)) {
|
||||
mGBDevice = device;
|
||||
GB.setReceiversEnableState(mDeviceSupport.useAutoConnect() || mGBDevice.isConnected(), context);
|
||||
boolean enableReceivers = mDeviceSupport != null && (mDeviceSupport.useAutoConnect() || mGBDevice.isConnected());
|
||||
GB.setReceiversEnableState(enableReceivers, context);
|
||||
GB.updateNotification(mGBDevice.getName() + " " + mGBDevice.getStateString(), context);
|
||||
}
|
||||
}
|
||||
|
@ -200,6 +203,11 @@ public class BluetoothCommunicationService extends Service {
|
|||
mDeviceSupport.onFetchActivityData();
|
||||
break;
|
||||
}
|
||||
case ACTION_DISCONNECT: {
|
||||
mDeviceSupport.dispose();
|
||||
mDeviceSupport = null;
|
||||
break;
|
||||
}
|
||||
case ACTION_CALLSTATE:
|
||||
GBCommand command = GBCommand.values()[intent.getIntExtra("call_command", 0)]; // UGLY
|
||||
|
||||
|
|
|
@ -160,10 +160,14 @@ public class ControlCenter extends Activity {
|
|||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
getMenuInflater().inflate(
|
||||
R.menu.controlcenter_context, menu);
|
||||
AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
selectedDevice = deviceList.get(acmi.position);
|
||||
if (selectedDevice != null && selectedDevice.isBusy()) {
|
||||
// no context menu when device is busy
|
||||
return;
|
||||
}
|
||||
getMenuInflater().inflate(
|
||||
R.menu.controlcenter_context, menu);
|
||||
menu.setHeaderTitle(selectedDevice.getName());
|
||||
}
|
||||
|
||||
|
@ -183,6 +187,13 @@ public class ControlCenter extends Activity {
|
|||
startIntent.setAction(BluetoothCommunicationService.ACTION_FETCH_ACTIVITY_DATA);
|
||||
startService(startIntent);
|
||||
}
|
||||
case R.id.controlcenter_disconnect:
|
||||
if (selectedDevice != null) {
|
||||
selectedDevice = null;
|
||||
Intent startIntent = new Intent(this, BluetoothCommunicationService.class);
|
||||
startIntent.setAction(BluetoothCommunicationService.ACTION_DISCONNECT);
|
||||
startService(startIntent);
|
||||
}
|
||||
default:
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
|
|
@ -161,6 +161,7 @@ public final class BtLEQueue {
|
|||
mBluetoothGatt.disconnect();
|
||||
mBluetoothGatt.close();
|
||||
mBluetoothGatt = null;
|
||||
setDeviceConnectionState(State.NOT_CONNECTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,4 +6,7 @@
|
|||
<item
|
||||
android:id="@+id/controlcenter_start_sleepmonitor"
|
||||
android:title="@string/controlcenter_start_sleepmonitor"/>
|
||||
<item
|
||||
android:id="@+id/controlcenter_disconnect"
|
||||
android:title="@string/controlcenter_disconnect"/>
|
||||
</menu>
|
|
@ -107,5 +107,6 @@
|
|||
<string name="initializing">initializing</string>
|
||||
<string name="busy_task_fetch_activity_data">Fetching Activity Data</string>
|
||||
<string name="controlcenter_fetch_activity_data">Fetch Activity Data</string>
|
||||
<string name="controlcenter_disconnect">Disconnect</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue