mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-07-07 22:22:00 +02:00
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";
|
= "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.install_pebbbleapp";
|
||||||
public static final String ACTION_REBOOT = "nodomain.freeyourgadget.gadgetbride.bluetoothcommunicationservice.action.reboot";
|
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_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";
|
public static final String EXTRA_PERFORM_PAIR = "perform_pair";
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BluetoothCommunicationService.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BluetoothCommunicationService.class);
|
||||||
|
@ -76,7 +78,8 @@ public class BluetoothCommunicationService extends Service {
|
||||||
GBDevice device = intent.getParcelableExtra("device");
|
GBDevice device = intent.getParcelableExtra("device");
|
||||||
if (mGBDevice.equals(device)) {
|
if (mGBDevice.equals(device)) {
|
||||||
mGBDevice = 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);
|
GB.updateNotification(mGBDevice.getName() + " " + mGBDevice.getStateString(), context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,6 +203,11 @@ public class BluetoothCommunicationService extends Service {
|
||||||
mDeviceSupport.onFetchActivityData();
|
mDeviceSupport.onFetchActivityData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ACTION_DISCONNECT: {
|
||||||
|
mDeviceSupport.dispose();
|
||||||
|
mDeviceSupport = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case ACTION_CALLSTATE:
|
case ACTION_CALLSTATE:
|
||||||
GBCommand command = GBCommand.values()[intent.getIntExtra("call_command", 0)]; // UGLY
|
GBCommand command = GBCommand.values()[intent.getIntExtra("call_command", 0)]; // UGLY
|
||||||
|
|
||||||
|
|
|
@ -160,10 +160,14 @@ public class ControlCenter extends Activity {
|
||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
getMenuInflater().inflate(
|
|
||||||
R.menu.controlcenter_context, menu);
|
|
||||||
AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||||
selectedDevice = deviceList.get(acmi.position);
|
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());
|
menu.setHeaderTitle(selectedDevice.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,6 +187,13 @@ public class ControlCenter extends Activity {
|
||||||
startIntent.setAction(BluetoothCommunicationService.ACTION_FETCH_ACTIVITY_DATA);
|
startIntent.setAction(BluetoothCommunicationService.ACTION_FETCH_ACTIVITY_DATA);
|
||||||
startService(startIntent);
|
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:
|
default:
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,7 @@ public final class BtLEQueue {
|
||||||
mBluetoothGatt.disconnect();
|
mBluetoothGatt.disconnect();
|
||||||
mBluetoothGatt.close();
|
mBluetoothGatt.close();
|
||||||
mBluetoothGatt = null;
|
mBluetoothGatt = null;
|
||||||
|
setDeviceConnectionState(State.NOT_CONNECTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,7 @@
|
||||||
<item
|
<item
|
||||||
android:id="@+id/controlcenter_start_sleepmonitor"
|
android:id="@+id/controlcenter_start_sleepmonitor"
|
||||||
android:title="@string/controlcenter_start_sleepmonitor"/>
|
android:title="@string/controlcenter_start_sleepmonitor"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/controlcenter_disconnect"
|
||||||
|
android:title="@string/controlcenter_disconnect"/>
|
||||||
</menu>
|
</menu>
|
|
@ -107,5 +107,6 @@
|
||||||
<string name="initializing">initializing</string>
|
<string name="initializing">initializing</string>
|
||||||
<string name="busy_task_fetch_activity_data">Fetching Activity Data</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_fetch_activity_data">Fetch Activity Data</string>
|
||||||
|
<string name="controlcenter_disconnect">Disconnect</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user