From 8a9648826318d5c82ecbfe3c44338cc44e2832e8 Mon Sep 17 00:00:00 2001 From: DHD2280 Date: Fri, 26 Apr 2024 17:09:42 +0200 Subject: [PATCH] Removed useless battery margins --- .../dhd/oxygencustomizer/utils/Constants.java | 12 +---- .../utils/PreferenceHelper.java | 16 +----- .../statusbar/BatteryStyleManager.java | 54 ++++++++----------- app/src/main/res/values-ru-rRU/strings.xml | 6 --- app/src/main/res/values/strings.xml | 6 --- .../main/res/xml/statusbar_battery_icon.xml | 40 -------------- 6 files changed, 26 insertions(+), 108 deletions(-) diff --git a/app/src/main/java/it/dhd/oxygencustomizer/utils/Constants.java b/app/src/main/java/it/dhd/oxygencustomizer/utils/Constants.java index a63ca9c12..0db2850b3 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/utils/Constants.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/utils/Constants.java @@ -31,11 +31,7 @@ public static class Framework { public static class BatteryPrefs { public static final String CUSTOMIZE_BATTERY_ICON = "battery_icon_customize"; public static final String CUSTOM_BATTERY_LAYOUT_REVERSE = "battery_rotate_layout"; - public static final String CUSTOM_BATTERY_MARGINS = "category_battery_margins"; - public static final String CUSTOM_BATTERY_MARGIN_LEFT = "battery_margin_left"; - public static final String CUSTOM_BATTERY_MARGIN_TOP = "battery_margin_top"; - public static final String CUSTOM_BATTERY_MARGIN_RIGHT = "battery_margin_right"; - public static final String CUSTOM_BATTERY_MARGIN_BOTTOM = "battery_margin_bottom"; + public static final String CATEGORY_CUSTOM_BATTERY_MARGINS = "category_battery_margins"; public static final String CUSTOM_BATTERY_PERIMETER_ALPHA = "battery_perimeter_alpha"; public static final String CUSTOM_BATTERY_FILL_ALPHA = "battery_fill_alpha"; public static final String CUSTOM_BATTERY_RAINBOW_FILL_COLOR = "battery_rainbow_color"; @@ -64,11 +60,6 @@ public static class BatteryPrefs { public static final String[] BatteryPrefs = { CUSTOMIZE_BATTERY_ICON, CUSTOM_BATTERY_LAYOUT_REVERSE, - CUSTOM_BATTERY_MARGINS, - CUSTOM_BATTERY_MARGIN_LEFT, - CUSTOM_BATTERY_MARGIN_TOP, - CUSTOM_BATTERY_MARGIN_RIGHT, - CUSTOM_BATTERY_MARGIN_BOTTOM, CUSTOM_BATTERY_PERIMETER_ALPHA, CUSTOM_BATTERY_FILL_ALPHA, CUSTOM_BATTERY_RAINBOW_FILL_COLOR, @@ -91,7 +82,6 @@ public static class BatteryPrefs { CUSTOM_BATTERY_STYLE, CUSTOM_BATTERY_WIDTH, CUSTOM_BATTERY_HEIGHT - }; // Battery styles diff --git a/app/src/main/java/it/dhd/oxygencustomizer/utils/PreferenceHelper.java b/app/src/main/java/it/dhd/oxygencustomizer/utils/PreferenceHelper.java index 2dc108aa4..1ac1f72cd 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/utils/PreferenceHelper.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/utils/PreferenceHelper.java @@ -30,6 +30,7 @@ import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.BATTERY_STYLE_LANDSCAPE_BATTERYM; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.BATTERY_STYLE_LANDSCAPE_IOS_16; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.BatteryPrefs; +import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CATEGORY_CUSTOM_BATTERY_MARGINS; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOMIZE_BATTERY_ICON; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_BLEND_COLOR; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_CHARGING_ICON_MARGIN_LEFT; @@ -38,10 +39,6 @@ import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_CHARGING_ICON_WIDTH_HEIGHT; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_HEIGHT; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_HIDE_PERCENTAGE; -import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_MARGIN_BOTTOM; -import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_MARGIN_LEFT; -import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_MARGIN_RIGHT; -import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_MARGIN_TOP; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_WIDTH; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.Lockscreen.LOCKSCREEN_FINGERPRINT_SCALING; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.LockscreenClock.LOCKSCREEN_CLOCK_BOTTOM_MARGIN; @@ -211,10 +208,6 @@ public static boolean isVisible(String key) { return !instance.mPreferences.getBoolean(CUSTOMIZE_BATTERY_ICON, false) && instance.mPreferences.getBoolean("customize_stock_percentage_size", false); } - // Battery Icon Dimensions - case "battery_margin_left", "battery_margin_right", "battery_margin_top", "battery_margin_bottom" -> { - return instance.mPreferences.getBoolean("battery_custom_margins", false); - } // QuickSettings Prefs case "quick_pulldown_side", "quick_pulldown_length" -> { @@ -468,8 +461,7 @@ public static boolean isVisibleBattery(String key) { return switch(key) { case "category_battery_icon_settings", - "battery_icon_style", - "category_battery_margins" -> showCommonCustomizations; + "battery_icon_style" -> showCommonCustomizations; case "category_battery_charging_icon" -> showChargingIconCustomization; case "battery_perimeter_alpha", "battery_fill_alpha", @@ -562,10 +554,6 @@ public static String getSummary(Context fragmentCompat, @NonNull String key) { // Battery case CUSTOM_BATTERY_WIDTH -> instance.mPreferences.getSliderInt(CUSTOM_BATTERY_WIDTH, 20) + "dp"; case CUSTOM_BATTERY_HEIGHT -> instance.mPreferences.getSliderInt(CUSTOM_BATTERY_HEIGHT, 20) + "dp"; - case CUSTOM_BATTERY_MARGIN_LEFT -> instance.mPreferences.getSliderInt(CUSTOM_BATTERY_MARGIN_LEFT, 4) + "dp"; - case CUSTOM_BATTERY_MARGIN_RIGHT -> instance.mPreferences.getSliderInt(CUSTOM_BATTERY_MARGIN_RIGHT, 4) + "dp"; - case CUSTOM_BATTERY_MARGIN_TOP -> instance.mPreferences.getSliderInt(CUSTOM_BATTERY_MARGIN_TOP, 0) + "dp"; - case CUSTOM_BATTERY_MARGIN_BOTTOM -> instance.mPreferences.getSliderInt(CUSTOM_BATTERY_MARGIN_BOTTOM, 0) + "dp"; case CUSTOM_BATTERY_CHARGING_ICON_WIDTH_HEIGHT -> instance.mPreferences.getSliderInt(CUSTOM_BATTERY_CHARGING_ICON_WIDTH_HEIGHT, 14) + "dp"; case CUSTOM_BATTERY_CHARGING_ICON_MARGIN_LEFT -> instance.mPreferences.getSliderInt(CUSTOM_BATTERY_CHARGING_ICON_MARGIN_LEFT, 1) + "dp"; case CUSTOM_BATTERY_CHARGING_ICON_MARGIN_RIGHT -> instance.mPreferences.getSliderInt(CUSTOM_BATTERY_CHARGING_ICON_MARGIN_RIGHT, 1) + "dp"; diff --git a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/BatteryStyleManager.java b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/BatteryStyleManager.java index 5aaf06e0c..c08d6da3d 100644 --- a/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/BatteryStyleManager.java +++ b/app/src/main/java/it/dhd/oxygencustomizer/xposed/hooks/systemui/statusbar/BatteryStyleManager.java @@ -1,5 +1,6 @@ package it.dhd.oxygencustomizer.xposed.hooks.systemui.statusbar; +import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import static de.robv.android.xposed.XposedBridge.hookAllConstructors; import static de.robv.android.xposed.XposedBridge.hookAllMethods; import static de.robv.android.xposed.XposedBridge.log; @@ -60,11 +61,6 @@ import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_HIDE_PERCENTAGE; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_INSIDE_PERCENTAGE; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_LAYOUT_REVERSE; -import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_MARGINS; -import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_MARGIN_BOTTOM; -import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_MARGIN_LEFT; -import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_MARGIN_RIGHT; -import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_MARGIN_TOP; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_PERIMETER_ALPHA; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_POWERSAVE_FILL_COLOR; import static it.dhd.oxygencustomizer.utils.Constants.Preferences.BatteryPrefs.CUSTOM_BATTERY_POWERSAVE_INDICATOR_COLOR; @@ -87,10 +83,12 @@ import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.Drawable; +import android.media.Image; import android.os.Build; import android.util.TypedValue; import android.view.Gravity; import android.view.View; +import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; @@ -158,11 +156,6 @@ public class BatteryStyleManager extends XposedMods { private static boolean CustomBatteryEnabled = false; private static int mBatteryScaleWidth = 20; private static int mBatteryScaleHeight = 20; - private static boolean mBatteryCustomDimension = false; - private static int mBatteryMarginLeft = 0; - private static int mBatteryMarginTop = 0; - private static int mBatteryMarginRight = 0; - private static int mBatteryMarginBottom = 0; private static int mBatteryStockMarginLeft = 0, mBatteryStockMarginRight = 0; private boolean DefaultLandscapeBatteryEnabled = false; private int frameColor = Color.WHITE; @@ -188,10 +181,12 @@ public class BatteryStyleManager extends XposedMods { private boolean mIsChargingImpl = false; private boolean mIsCharging = false; private ImageView mStockChargingIcon = null, mBatteryIcon = null; + private ImageView mBatteryOOS13 = null; private Object BatteryControllerImpl = null; private boolean updating = false; private boolean customizePercSize = false; - private int mBatteryPercSize = 14; + private int mBatteryPercSize = 12; + private static boolean oos13 = false; public BatteryStyleManager(Context context) { super(context); @@ -229,7 +224,6 @@ public void updatePrefs(String... Key) { mShowPercentInside = insidePercentage && (defaultInsidePercentage || !hidePercentage); mHideBattery = Xprefs.getBoolean(CUSTOM_BATTERY_HIDE_BATTERY, false); mBatteryLayoutReverse = Xprefs.getBoolean(CUSTOM_BATTERY_LAYOUT_REVERSE, false); - mBatteryCustomDimension = Xprefs.getBoolean(CUSTOM_BATTERY_MARGINS, false); mBatteryScaleWidth = Xprefs.getSliderInt(CUSTOM_BATTERY_WIDTH, 20); mBatteryScaleHeight = Xprefs.getSliderInt(CUSTOM_BATTERY_HEIGHT, 20); mScaledPerimeterAlpha = Xprefs.getBoolean(CUSTOM_BATTERY_PERIMETER_ALPHA, false); @@ -247,20 +241,15 @@ public void updatePrefs(String... Key) { mChargingIconML = Xprefs.getSliderInt(CUSTOM_BATTERY_CHARGING_ICON_MARGIN_LEFT, 1); mChargingIconMR = Xprefs.getSliderInt(CUSTOM_BATTERY_CHARGING_ICON_MARGIN_RIGHT, 0); mChargingIconWH = Xprefs.getSliderInt(CUSTOM_BATTERY_CHARGING_ICON_WIDTH_HEIGHT, 14); - mBatteryMarginLeft = dp2px(mContext, Xprefs.getSliderInt(CUSTOM_BATTERY_MARGIN_LEFT, mBatteryStockMarginLeft)); - mBatteryMarginTop = dp2px(mContext, Xprefs.getSliderInt(CUSTOM_BATTERY_MARGIN_TOP, 0)); - mBatteryMarginRight = dp2px(mContext, Xprefs.getSliderInt(CUSTOM_BATTERY_MARGIN_RIGHT, mBatteryStockMarginRight)); - mBatteryMarginBottom = dp2px(mContext, Xprefs.getSliderInt(CUSTOM_BATTERY_MARGIN_BOTTOM, 0)); // Stock Style customizePercSize = Xprefs.getBoolean(STOCK_CUSTOMIZE_PERCENTAGE_SIZE, false); - mBatteryPercSize = Xprefs.getSliderInt(STOCK_PERCENTAGE_SIZE, 14); + mBatteryPercSize = Xprefs.getSliderInt(STOCK_PERCENTAGE_SIZE, 12); if (Key.length > 0 && (Key[0].equals(CUSTOMIZE_BATTERY_ICON) || Key[0].equals(CUSTOM_BATTERY_STYLE) || Key[0].equals(CUSTOM_BATTERY_HIDE_PERCENTAGE) || Key[0].equals(CUSTOM_BATTERY_LAYOUT_REVERSE) || - Key[0].equals(CUSTOM_BATTERY_MARGINS) || Key[0].equals(CUSTOM_BATTERY_PERIMETER_ALPHA) || Key[0].equals(CUSTOM_BATTERY_FILL_ALPHA) || Key[0].equals(CUSTOM_BATTERY_RAINBOW_FILL_COLOR) || @@ -276,10 +265,6 @@ public void updatePrefs(String... Key) { Key[0].equals(CUSTOM_BATTERY_CHARGING_ICON_MARGIN_LEFT) || Key[0].equals(CUSTOM_BATTERY_CHARGING_ICON_MARGIN_RIGHT) || Key[0].equals(CUSTOM_BATTERY_CHARGING_ICON_WIDTH_HEIGHT) || - Key[0].equals(CUSTOM_BATTERY_MARGIN_LEFT) || - Key[0].equals(CUSTOM_BATTERY_MARGIN_TOP) || - Key[0].equals(CUSTOM_BATTERY_MARGIN_RIGHT) || - Key[0].equals(CUSTOM_BATTERY_MARGIN_BOTTOM) || Key[0].equals(CUSTOM_BATTERY_INSIDE_PERCENTAGE) || Key[0].equals(CUSTOM_BATTERY_WIDTH) || Key[0].equals(CUSTOM_BATTERY_HEIGHT) || @@ -297,6 +282,11 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Th if (Build.VERSION.SDK_INT >= 34) { hookBattery(lpparam); // OOS 14 } else { + if (mBatteryOOS13 == null) { + mBatteryOOS13 = new ImageView(mContext); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT); + mBatteryOOS13.setLayoutParams(lp); + } hookBattery13(lpparam); // OOS 13 } @@ -474,7 +464,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { } private void hookBattery13(XC_LoadPackage.LoadPackageParam lpparam) { - + oos13 = true; Class TwoBatteryMeterDrawable = findClass("com.oplusos.systemui.statusbar.widget.TwoBatteryMeterDrawable", lpparam.classLoader); findAndHookMethod(TwoBatteryMeterDrawable, "setColors", int.class, @@ -517,7 +507,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { mBatteryIcon = (ImageView) getObjectField(param.thisObject, "mBatteryIconView"); batteryPercentOutView = (TextView) getObjectField(param.thisObject, "batteryPercentText"); - if (CustomBatteryEnabled && mBatteryIcon != null) { + if (CustomBatteryEnabled && mBatteryOOS13 != null) { + if (mHidePercentage) batteryPercentOutView.setVisibility(View.GONE); else { @@ -546,8 +537,10 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable { mCustomPowerSaveFillColor, mChargingIconSwitch ); + if (mBatteryIcon.getScaleType() != mBatteryOOS13.getScaleType()) + mBatteryIcon.setScaleType(mBatteryOOS13.getScaleType()); mBatteryIcon.setImageDrawable(mBatteryDrawable); - + mBatteryIcon.setVisibility(View.VISIBLE); } scaleBatteryMeterViews(mBatteryIcon); @@ -682,17 +675,16 @@ public static void scaleBatteryMeterViews(@Nullable ImageView mBatteryIconView) int batteryWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mBatteryScaleWidth, mBatteryIconView.getContext().getResources().getDisplayMetrics()); int batteryHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mBatteryScaleHeight, mBatteryIconView.getContext().getResources().getDisplayMetrics()); - LinearLayout.LayoutParams scaledLayoutParams = (LinearLayout.LayoutParams) mBatteryIconView.getLayoutParams(); + LinearLayout.LayoutParams scaledLayoutParams; + if (!oos13) scaledLayoutParams = (LinearLayout.LayoutParams) mBatteryIconView.getLayoutParams(); + else scaledLayoutParams = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT); scaledLayoutParams.width = (int) (batteryWidth * iconScaleFactor); scaledLayoutParams.height = (int) (batteryHeight * iconScaleFactor); - if (mBatteryCustomDimension) { - scaledLayoutParams.setMargins(mBatteryMarginLeft, mBatteryMarginTop, mBatteryMarginRight, mBatteryMarginBottom); - } else { - scaledLayoutParams.setMargins(mBatteryStockMarginLeft, 0, mBatteryStockMarginRight, context.getResources().getDimensionPixelOffset(context.getResources().getIdentifier("battery_margin_bottom", "dimen", context.getPackageName()))); - } + scaledLayoutParams.setMargins(mBatteryStockMarginLeft, 0, mBatteryStockMarginRight, context.getResources().getDimensionPixelOffset(context.getResources().getIdentifier("battery_margin_bottom", "dimen", context.getPackageName()))); mBatteryIconView.setLayoutParams(scaledLayoutParams); mBatteryIconView.setVisibility(mHideBattery ? View.GONE : View.VISIBLE); + mBatteryIconView.requestLayout(); } catch (Throwable throwable) { log(TAG + throwable); } diff --git a/app/src/main/res/values-ru-rRU/strings.xml b/app/src/main/res/values-ru-rRU/strings.xml index 140ac0234..f1446639b 100644 --- a/app/src/main/res/values-ru-rRU/strings.xml +++ b/app/src/main/res/values-ru-rRU/strings.xml @@ -95,11 +95,7 @@ Пейзаж в стиле R B Пейзажный смайлик Уровень заряда батареи - Нижний запас заряда батареи - Оставшийся запас заряда батареи - Правый запас заряда батареи Запас заряда батареи - Максимальный запас заряда батареи Процентный размер Portrait Airoo Portrait Capsule @@ -154,8 +150,6 @@ Пользовательский цвет Набор изображений заголовка Пользовательское местоположение - Установите пользовательские поля для значка батареи - Настраиваемые поля Настройка ползунка яркости User По умолчанию diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9cb62cf1a..682e244f4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -210,12 +210,6 @@ Powersave Indicator Color Change color of powersave indicator Battery icon margins - Custom Margins - Set custom margins for battery icon - Battery Margin Left - Battery Margin Right - Battery Margin Top - Battery Margin Bottom Reverse Layout Show percentage on the opposite side Rotate Layout diff --git a/app/src/main/res/xml/statusbar_battery_icon.xml b/app/src/main/res/xml/statusbar_battery_icon.xml index 2aaec251b..9e348b8db 100644 --- a/app/src/main/res/xml/statusbar_battery_icon.xml +++ b/app/src/main/res/xml/statusbar_battery_icon.xml @@ -146,46 +146,6 @@ - - - - - - - - - - - - -