Update bluetooth preference to take user to new screen

This CL removes the toggle from the bluetooth preference and instead
takes users to a new dedicated screen for toggling bluetooth status.
On this screen we show a different summary text depending on whether
bluetooth and bluetooth scanning are on/off. Also, we were able to
delegate most of the UI/bluetooth handling to already existing
classes.

Test: robotests
Bug: 77543471
Change-Id: I036a3992bbd78896da8364b55ecc51afc4464b6e
This commit is contained in:
Salvador Martinez
2018-04-04 14:23:57 -07:00
parent 837f279db9
commit 21c5ed2894
12 changed files with 312 additions and 170 deletions

View File

@@ -47,6 +47,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
private final LocalBluetoothAdapter mLocalAdapter;
private final IntentFilter mIntentFilter;
private final RestrictionUtils mRestrictionUtils;
private SwitchWidgetController.OnSwitchChangeListener mCallback;
private static final String EVENT_DATA_IS_BT_ON = "is_bluetooth_on";
private static final int EVENT_UPDATE_INDEX = 0;
@@ -170,6 +171,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
@Override
public boolean onSwitchToggled(boolean isChecked) {
if (maybeEnforceRestrictions()) {
triggerParentPreferenceCallback(isChecked);
return true;
}
@@ -179,6 +181,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
// Reset switch to off
mSwitchController.setChecked(false);
triggerParentPreferenceCallback(false);
return false;
}
@@ -193,13 +196,24 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
mSwitchController.setChecked(false);
mSwitchController.setEnabled(true);
mSwitchController.updateTitle(false);
triggerParentPreferenceCallback(false);
return false;
}
}
mSwitchController.setEnabled(false);
triggerParentPreferenceCallback(isChecked);
return true;
}
/**
* Sets a callback back that this enabler will trigger in case the preference using the enabler
* still needed the callback on the SwitchController (which we now use).
* @param listener The listener with a callback to trigger.
*/
public void setToggleCallback(SwitchWidgetController.OnSwitchChangeListener listener) {
mCallback = listener;
}
/**
* Enforces user restrictions disallowing Bluetooth (or its configuration) if there are any.
*
@@ -227,4 +241,11 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
return admin;
}
// This triggers the callback which was manually set for this enabler since the enabler will
// take over the switch controller callback
private void triggerParentPreferenceCallback(boolean isChecked) {
if (mCallback != null) {
mCallback.onSwitchToggled(isChecked);
}
}
}