Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dee58df5 authored by Lucas Dupin's avatar Lucas Dupin Committed by android-build-merger
Browse files

Merge "Disable dark mode tile when in battery saver" into qt-dev

am: 46c92d3f

Change-Id: Ifdc625ac804ef31bb5a0edfeb50ecc068174b999
parents 1c82a5a1 46c92d3f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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>
+26 −5
Original line number Diff line number Diff line
@@ -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();
        if (powerSave) {
            state.state = Tile.STATE_UNAVAILABLE;
        } else {
            state.state = state.value ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
        }
        state.showRippleEffect = false;
    }