Disable dark mode tile when in battery saver

Test: toggle battery saver, try to toggle dark mode
Test: toggle battery saver, look at dark mode tile
Fixes: 132348329
Change-Id: I265309fb554637ac342c4cb360b03897d0b47b8f
This commit is contained in:
Lucas Dupin
2019-05-10 14:45:42 -07:00
parent c560293e15
commit e7acd0ff79
2 changed files with 28 additions and 5 deletions

View File

@@ -871,6 +871,8 @@
<string name="quick_settings_secondary_label_until">Until <xliff:g id="time" example="7 am">%s</xliff:g></string>
<!-- QuickSettings: Label for the toggle to activate Dark theme (A.K.A Dark Mode). [CHAR LIMIT=20] -->
<string name="quick_settings_ui_mode_night_label">Dark Theme</string>
<!-- QuickSettings: Label for the Dark theme tile when enabled by battery saver. [CHAR LIMIT=40] -->
<string name="quick_settings_ui_mode_night_label_battery_saver">Dark Theme\nBattery saver</string>
<!-- QuickSettings: NFC tile [CHAR LIMIT=NONE] -->
<string name="quick_settings_nfc_label">NFC</string>

View File

@@ -28,6 +28,7 @@ import com.android.systemui.R;
import com.android.systemui.plugins.qs.QSTile;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.ConfigurationController;
import javax.inject.Inject;
@@ -39,17 +40,22 @@ import javax.inject.Inject;
* taken by {@link NightDisplayTile}.
*/
public class UiModeNightTile extends QSTileImpl<QSTile.BooleanState> implements
ConfigurationController.ConfigurationListener {
ConfigurationController.ConfigurationListener,
BatteryController.BatteryStateChangeCallback {
private final Icon mIcon = ResourceIcon.get(
com.android.internal.R.drawable.ic_qs_ui_mode_night);
private UiModeManager mUiModeManager;
private final UiModeManager mUiModeManager;
private final BatteryController mBatteryController;
@Inject
public UiModeNightTile(QSHost host, ConfigurationController configurationController) {
public UiModeNightTile(QSHost host, ConfigurationController configurationController,
BatteryController batteryController) {
super(host);
mBatteryController = batteryController;
mUiModeManager = mContext.getSystemService(UiModeManager.class);
configurationController.observe(getLifecycle(), this);
batteryController.observe(getLifecycle(), this);
}
@Override
@@ -57,6 +63,11 @@ public class UiModeNightTile extends QSTileImpl<QSTile.BooleanState> implements
refreshState();
}
@Override
public void onPowerSaveChanged(boolean isPowerSave) {
refreshState();
}
@Override
public BooleanState newTileState() {
return new BooleanState();
@@ -64,6 +75,9 @@ public class UiModeNightTile extends QSTileImpl<QSTile.BooleanState> implements
@Override
protected void handleClick() {
if (getState().state == Tile.STATE_UNAVAILABLE) {
return;
}
boolean newState = !mState.value;
mUiModeManager.setNightMode(newState ? UiModeManager.MODE_NIGHT_YES
: UiModeManager.MODE_NIGHT_NO);
@@ -72,15 +86,22 @@ public class UiModeNightTile extends QSTileImpl<QSTile.BooleanState> implements
@Override
protected void handleUpdateState(BooleanState state, Object arg) {
boolean powerSave = mBatteryController.isPowerSave();
boolean nightMode = (mContext.getResources().getConfiguration().uiMode
& Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
state.value = nightMode;
state.label = mContext.getString(R.string.quick_settings_ui_mode_night_label);
state.label = mContext.getString(powerSave
? R.string.quick_settings_ui_mode_night_label_battery_saver
: R.string.quick_settings_ui_mode_night_label);
state.contentDescription = state.label;
state.icon = mIcon;
state.expandedAccessibilityClassName = Switch.class.getName();
state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
if (powerSave) {
state.state = Tile.STATE_UNAVAILABLE;
} else {
state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
}
state.showRippleEffect = false;
}