[DNM] ParanoidSystemUI: Introduce Force HBM mode QS tile [2/2]

Thanks to WSTxda for the icon.

Change-Id: I83199cbde73737ca51c2f516bd7504cb42e32cfb
This commit is contained in:
Adithya R 2023-10-17 21:28:27 +05:30
parent 161ebee24d
commit 7113e82641
5 changed files with 200 additions and 1 deletions

View File

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M20 8.69V4h-4.69L12 0.69 8.69 4H4v4.69L0.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Zm-2 5.79V18h-3.52L12 20.48 9.52 18H6v-3.52L3.52 12 6 9.52V6h3.52L12 3.52 14.48 6H18v3.52L20.48 12 18 14.48Z"/>
<path
android:fillColor="#FF000000"
android:pathData="M13 11V8h-2v3H8v2h3v3h2v-3h3v-2h-3Z"/>
</vector>

View File

@ -54,4 +54,8 @@
<string name="bluetooth_is_off">Bluetooth is off</string>
<string name="tap_a_device_to_connect">Tap a device to connect/disconnect</string>
<!-- Force HBM -->
<string name="force_hbm">Force HBM</string>
<string name="auto_brightness_is_off">Auto brightness is off</string>
</resources>

View File

@ -8,7 +8,7 @@
<!-- Tiles native to System UI. Order should match "quick_settings_tiles_default" -->
<string name="quick_settings_tiles_stock" translatable="false">
internet,wifi,cell,bt,flashlight,dnd,alarm,airplane,nfc,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness,qr_code_scanner,onehanded,color_correction,dream,caffeine,dataswitch,heads_up,dc_dimming,aod,powershare
internet,wifi,cell,bt,flashlight,dnd,alarm,airplane,nfc,controls,wallet,rotation,battery,cast,screenrecord,mictoggle,cameratoggle,location,hotspot,inversion,saver,dark,work,night,reverse,reduce_brightness,qr_code_scanner,onehanded,color_correction,dream,caffeine,dataswitch,heads_up,dc_dimming,aod,powershare,force_hbm
</string>
<!-- Determines whether the shell features all run on another thread. -->

View File

@ -24,6 +24,7 @@ import co.aospa.systemui.qs.tiles.CaffeineTile;
import co.aospa.systemui.qs.tiles.CellularTile
import co.aospa.systemui.qs.tiles.DataSwitchTile;
import co.aospa.systemui.qs.tiles.DcDimmingTile;
import co.aospa.systemui.qs.tiles.ForceHbmTile;
import co.aospa.systemui.qs.tiles.HeadsUpTile;
import co.aospa.systemui.qs.tiles.PowerShareTile;
import co.aospa.systemui.qs.tiles.WifiTile
@ -89,4 +90,10 @@ interface ParanoidQSModule {
@StringKey(WifiTile.TILE_SPEC)
fun bindWifiTile(wifiTile: WifiTile): QSTileImpl<*>
/** Inject ForceHbmTile into tileMap in QSModule */
@Binds
@IntoMap
@StringKey(ForceHbmTile.TILE_SPEC)
fun bindForceHbmTile(forceHbmTile: ForceHbmTile): QSTileImpl<*>
}

View File

@ -0,0 +1,176 @@
/*
* Copyright (C) 2018 The OmniROM Project
* 2020-2021 The LineageOS Project
* 2023 Paranoid Android
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package co.aospa.systemui.qs.tiles;
import static com.android.internal.logging.MetricsLogger.VIEW_UNKNOWN;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.service.quicksettings.Tile;
import android.view.View;
import androidx.annotation.Nullable;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.qs.QSTile.BooleanState;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.qs.QSHost;
import com.android.systemui.qs.SettingObserver;
import com.android.systemui.qs.logging.QSLogger;
import com.android.systemui.qs.tileimpl.QSTileImpl;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.util.settings.SystemSettings;
import javax.inject.Inject;
public class ForceHbmTile extends QSTileImpl<BooleanState> implements
BatteryController.BatteryStateChangeCallback {
public static final String TILE_SPEC = "force_hbm";
private final Icon mIcon = ResourceIcon.get(R.drawable.ic_qs_hbm);
private final BatteryController mBatteryController;
private final SettingObserver mSetting, mBrightnessSetting;
@Inject
public ForceHbmTile(
QSHost host,
@Background Looper backgroundLooper,
@Main Handler mainHandler,
FalsingManager falsingManager,
MetricsLogger metricsLogger,
StatusBarStateController statusBarStateController,
ActivityStarter activityStarter,
QSLogger qsLogger,
SystemSettings systemSettings,
BatteryController batteryController,
UserTracker userTracker
) {
super(host, backgroundLooper, mainHandler, falsingManager, metricsLogger,
statusBarStateController, activityStarter, qsLogger);
mSetting = new SettingObserver(systemSettings, mHandler, Settings.System.FORCE_HBM,
userTracker.getUserId()) {
@Override
protected void handleValueChanged(int value, boolean observedChange) {
refreshState();
}
};
mBrightnessSetting = new SettingObserver(systemSettings, mHandler,
Settings.System.SCREEN_BRIGHTNESS_MODE, userTracker.getUserId()) {
@Override
protected void handleValueChanged(int value, boolean observedChange) {
refreshState();
}
};
mBatteryController = batteryController;
batteryController.observe(getLifecycle(), this);
}
@Override
public void onPowerSaveChanged(boolean isPowerSave) {
refreshState();
}
@Override
protected void handleDestroy() {
super.handleDestroy();
mSetting.setListening(false);
mBrightnessSetting.setListening(false);
}
@Override
public boolean isAvailable() {
return true; // TODO: check if device supports hbm
}
@Override
public BooleanState newTileState() {
BooleanState state = new BooleanState();
state.handlesLongClick = false;
return state;
}
@Override
public void handleSetListening(boolean listening) {
super.handleSetListening(listening);
mSetting.setListening(listening);
mBrightnessSetting.setListening(listening);
}
@Override
protected void handleUserSwitch(int newUserId) {
mSetting.setUserId(newUserId);
refreshState();
}
@Override
protected void handleClick(@Nullable View view) {
mSetting.setValue(mState.value ? 0 : 1);
}
@Override
public Intent getLongClickIntent() {
return null;
}
@Override
public CharSequence getTileLabel() {
return mContext.getString(R.string.force_hbm);
}
@Override
protected void handleUpdateState(BooleanState state, Object arg) {
final boolean enable = (mSetting.getValue() == 1);
if (state.slash == null) {
state.slash = new SlashState();
}
state.icon = mIcon;
state.value = enable;
state.slash.isSlashed = state.value;
state.label = mContext.getString(R.string.force_hbm);
if (mBatteryController.isPowerSave()) {
state.state = Tile.STATE_UNAVAILABLE;
state.secondaryLabel = mContext.getString(R.string.battery_detail_switch_title);
} else if (mBrightnessSetting.getValue() !=
Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
state.state = Tile.STATE_UNAVAILABLE;
state.secondaryLabel = mContext.getString(R.string.auto_brightness_is_off);
} else {
state.state = enable ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
state.secondaryLabel = null;
}
}
@Override
public int getMetricsCategory() {
return MetricsEvent.QS_CUSTOM;
}
}