ParanoidSystemUI: AODTile: Cycle through AOD states

Change-Id: I8ab75ca41bcbf006b30ec6c7529488c6d8da52fb
Co-authored-by: Jyotiraditya Panda <jyotiraditya@aospa.co>
Signed-off-by: Fazil Sheik <fazil.sheik96@gmail.com>
This commit is contained in:
shagbag913 2020-02-06 17:25:25 -05:00 committed by fazilsheik96
parent 7fda71fd59
commit 7143e4efcf
2 changed files with 49 additions and 20 deletions

View File

@ -42,6 +42,7 @@
<!-- Always-on Display QS tile --> <!-- Always-on Display QS tile -->
<string name="quick_settings_aod_label">Always-on display</string> <string name="quick_settings_aod_label">Always-on display</string>
<string name="quick_settings_aod_secondary_label_on_at_charge">On at charge</string>
<!-- PowerShare QS tile --> <!-- PowerShare QS tile -->
<string name="quick_settings_powershare_label">Battery Share</string> <string name="quick_settings_powershare_label">Battery Share</string>

View File

@ -1,7 +1,7 @@
/* /*
* Copyright (C) 2018 The OmniROM Project * Copyright (C) 2018 The OmniROM Project
* 2020-2021 The LineageOS Project * 2020-2021 The LineageOS Project
* 2023 Paranoid Android * 2024 Paranoid Android
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import static com.android.internal.logging.MetricsLogger.VIEW_UNKNOWN;
import android.content.Intent; import android.content.Intent;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.service.quicksettings.Tile; import android.service.quicksettings.Tile;
import android.view.View; import android.view.View;
@ -35,7 +36,7 @@ import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.FalsingManager; import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.qs.QSTile.BooleanState; import com.android.systemui.plugins.qs.QSTile.State;
import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.qs.QSHost; import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.SettingObserver; import com.android.systemui.qs.SettingObserver;
@ -47,7 +48,7 @@ import com.android.systemui.util.settings.SecureSettings;
import javax.inject.Inject; import javax.inject.Inject;
public class AlwaysOnDisplayTile extends QSTileImpl<BooleanState> implements public class AlwaysOnDisplayTile extends QSTileImpl<State> implements
BatteryController.BatteryStateChangeCallback { BatteryController.BatteryStateChangeCallback {
public static final String TILE_SPEC = "aod"; public static final String TILE_SPEC = "aod";
@ -86,6 +87,16 @@ public class AlwaysOnDisplayTile extends QSTileImpl<BooleanState> implements
batteryController.observe(getLifecycle(), this); batteryController.observe(getLifecycle(), this);
} }
private int getDozeState() {
int dozeState = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.DOZE_ALWAYS_ON, 0, UserHandle.USER_CURRENT);
if (dozeState == 0) {
dozeState = Settings.Secure.getIntForUser(mContext.getContentResolver(),
Settings.Secure.DOZE_ON_CHARGE, 0, UserHandle.USER_CURRENT) == 1 ? 2 : 0;
}
return dozeState;
}
@Override @Override
public void onPowerSaveChanged(boolean isPowerSave) { public void onPowerSaveChanged(boolean isPowerSave) {
refreshState(); refreshState();
@ -104,8 +115,8 @@ public class AlwaysOnDisplayTile extends QSTileImpl<BooleanState> implements
} }
@Override @Override
public BooleanState newTileState() { public State newTileState() {
BooleanState state = new BooleanState(); State state = new State();
state.handlesLongClick = false; state.handlesLongClick = false;
return state; return state;
} }
@ -124,7 +135,22 @@ public class AlwaysOnDisplayTile extends QSTileImpl<BooleanState> implements
@Override @Override
protected void handleClick(@Nullable View view) { protected void handleClick(@Nullable View view) {
mSetting.setValue(mState.value ? 0 : 1); int dozeState = getDozeState();
dozeState = dozeState < 2 ? dozeState + 1 : 0;
Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.DOZE_ALWAYS_ON,
dozeState == 2 ? 0 : dozeState, UserHandle.USER_CURRENT);
Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.DOZE_ON_CHARGE,
dozeState == 2 ? 1 : 0, UserHandle.USER_CURRENT);
refreshState();
}
@Override
protected void handleLongClick(@Nullable View view) {
Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.DOZE_ALWAYS_ON,
getDozeState() != 0 ? 0 : 1, UserHandle.USER_CURRENT);
Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.DOZE_ON_CHARGE,
0, UserHandle.USER_CURRENT);
refreshState();
} }
@Override @Override
@ -138,22 +164,24 @@ public class AlwaysOnDisplayTile extends QSTileImpl<BooleanState> implements
} }
@Override @Override
protected void handleUpdateState(BooleanState state, Object arg) { protected void handleUpdateState(State state, Object arg) {
final int value = arg instanceof Integer ? (Integer) arg : mSetting.getValue();
final boolean enable = value != 0;
if (state.slash == null) {
state.slash = new SlashState();
}
state.icon = mIcon; state.icon = mIcon;
state.value = enable;
state.slash.isSlashed = state.value;
state.label = mContext.getString(R.string.quick_settings_aod_label); state.label = mContext.getString(R.string.quick_settings_aod_label);
if (mBatteryController.isAodPowerSave()) {
state.state = Tile.STATE_UNAVAILABLE; int dozeState = getDozeState();
state.secondaryLabel = mContext.getString(R.string.battery_detail_switch_title); switch (dozeState) {
} else { case 0:
state.state = enable ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE; state.state = Tile.STATE_INACTIVE;
state.secondaryLabel = null; state.secondaryLabel = mContext.getString(R.string.switch_bar_off);
break;
case 1:
state.state = Tile.STATE_ACTIVE;
state.secondaryLabel = mContext.getString(R.string.switch_bar_on);
break;
case 2:
state.state = Tile.STATE_ACTIVE;
state.secondaryLabel = mContext.getString(R.string.quick_settings_aod_secondary_label_on_at_charge);
break;
} }
} }
} }