summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/res/values/strings.xml2
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/UiModeNightTile.java31
2 files changed, 28 insertions, 5 deletions
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 87d03ee978c4..26432210e233 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -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>
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 f26a94fed8a4..dd0ea5ef17f4 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<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
@@ -58,12 +64,20 @@ public class UiModeNightTile extends QSTileImpl<QSTile.BooleanState> implements
}
@Override
+ public void onPowerSaveChanged(boolean isPowerSave) {
+ refreshState();
+ }
+
+ @Override
public BooleanState newTileState() {
return new BooleanState();
}
@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;
}