Skip to content

Commit

Permalink
CHANGELOG: Don't scale battery icon if not required / a bit of compat…
Browse files Browse the repository at this point in the history
…ibility with other battery icon mods
  • Loading branch information
siavash79 committed Jan 21, 2024
1 parent 34783d7 commit 7e25ce8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/edit2MakeNewCanary
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Editing this file will trigger the build script for a new canary.
Editing this file will trigger the build script for a new canary..
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ public class BatteryStyleManager extends XposedModPack {
public static int scaleFactor = 100;
private static int BatteryIconOpacity = 100;
private static boolean BatteryChargingAnimationEnabled = true;
private static final ArrayList<Object> batteryViews = new ArrayList<>();
private final ArrayList<Object> batteryViews = new ArrayList<>();
private static boolean mShouldScale = false;

public BatteryStyleManager(Context context) {
super(context);
}

public void updatePrefs(String... Key) {
if (Xprefs == null) return;

String BatteryStyleStr = Xprefs.getString("BatteryStyle", "0");
scaleFactor = Xprefs.getSliderInt( "BatteryIconScaleFactor", 50) * 2;
int batteryStyle = Integer.parseInt(BatteryStyleStr);

customBatteryEnabled = batteryStyle != 0;
mShouldScale = mShouldScale || customBatteryEnabled || scaleFactor != 100;

if (batteryStyle == 99) {
scaleFactor = 0;
}
Expand Down Expand Up @@ -112,7 +117,7 @@ public void updatePrefs(String... Key) {
refreshAllBatteryIcons();
}

private static void refreshAllBatteryIcons() {
private void refreshAllBatteryIcons() {
for (Object view : batteryViews) {
updateBatteryViewValues((View) view);
}
Expand All @@ -133,7 +138,7 @@ private static void updateBatteryViewValues(View view)

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) {
BatteryDataProvider.registerInfoCallback(BatteryStyleManager::refreshAllBatteryIcons);
BatteryDataProvider.registerInfoCallback(this::refreshAllBatteryIcons);

findAndHookConstructor("com.android.settingslib.graph.ThemedBatteryDrawable", lpparam.classLoader, Context.class, int.class, new XC_MethodHook() {
@Override
Expand Down Expand Up @@ -213,7 +218,7 @@ private BatteryDrawable getNewDrawable(Context context) {

@SuppressLint("DiscouragedApi")
public static void scale(ImageView mBatteryIconView) {
if (mBatteryIconView == null) {
if (mBatteryIconView == null || !mShouldScale) {
return;
}

Expand Down

0 comments on commit 7e25ce8

Please sign in to comment.