From e7acd0ff7984cf3e0ac56dc26ea5081445194060 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Fri, 10 May 2019 14:45:42 -0700 Subject: [PATCH] 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 --- packages/SystemUI/res/values/strings.xml | 2 ++ .../systemui/qs/tiles/UiModeNightTile.java | 31 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index dc35653e5f7d8..d4d366bd0f4b7 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -871,6 +871,8 @@ Until %s Dark Theme + + Dark Theme\nBattery saver NFC diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/UiModeNightTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/UiModeNightTile.java index f26a94fed8a4f..dd0ea5ef17f49 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/UiModeNightTile.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/UiModeNightTile.java @@ -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 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 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 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 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; }