Skip to content

Commit

Permalink
Removed useless battery margins
Browse files Browse the repository at this point in the history
  • Loading branch information
DHD2280 committed Apr 26, 2024
1 parent 66658eb commit 8a96488
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 108 deletions.
12 changes: 1 addition & 11 deletions app/src/main/java/it/dhd/oxygencustomizer/utils/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -91,7 +82,6 @@ public static class BatteryPrefs {
CUSTOM_BATTERY_STYLE,
CUSTOM_BATTERY_WIDTH,
CUSTOM_BATTERY_HEIGHT

};

// Battery styles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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" -> {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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) ||
Expand All @@ -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) ||
Expand All @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/values-ru-rRU/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@
<string name="battery_landscape_r_style_b">Пейзаж в стиле R B</string>
<string name="battery_landscape_smiley">Пейзажный смайлик</string>
<string name="battery_level_percentage">Уровень заряда батареи</string>
<string name="battery_margin_bottom_title">Нижний запас заряда батареи</string>
<string name="battery_margin_left_title">Оставшийся запас заряда батареи</string>
<string name="battery_margin_right_title">Правый запас заряда батареи</string>
<string name="battery_margin_title">Запас заряда батареи</string>
<string name="battery_margin_top_title">Максимальный запас заряда батареи</string>
<string name="battery_percentage_size">Процентный размер</string>
<string name="battery_portrait_airoo">Portrait Airoo</string>
<string name="battery_portrait_capsule">Portrait Capsule</string>
Expand Down Expand Up @@ -154,8 +150,6 @@
<string name="custom_color">Пользовательский цвет</string>
<string name="custom_header_image_notice">Набор изображений заголовка</string>
<string name="custom_location_title">Пользовательское местоположение</string>
<string name="custom_margins_desc">Установите пользовательские поля для значка батареи</string>
<string name="custom_margins_title">Настраиваемые поля</string>
<string name="customize_brightness_slider_title">Настройка ползунка яркости</string>
<string name="default_user_name">User</string>
<string name="default_value">По умолчанию</string>
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@
<string name="powersave_indicator_color_title">Powersave Indicator Color</string>
<string name="powersave_indicator_color_desc">Change color of powersave indicator</string>
<string name="battery_icon_margins">Battery icon margins</string>
<string name="custom_margins_title">Custom Margins</string>
<string name="custom_margins_desc">Set custom margins for battery icon</string>
<string name="battery_margin_left_title">Battery Margin Left</string>
<string name="battery_margin_right_title">Battery Margin Right</string>
<string name="battery_margin_top_title">Battery Margin Top</string>
<string name="battery_margin_bottom_title">Battery Margin Bottom</string>
<string name="reverse_layout_title">Reverse Layout</string>
<string name="reverse_layout_desc">Show percentage on the opposite side</string>
<string name="rotate_layout_title">Rotate Layout</string>
Expand Down
Loading

0 comments on commit 8a96488

Please sign in to comment.