Skip to content

Commit

Permalink
Battery Style Manager: Rescale battery size in landscape mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Oct 10, 2023
1 parent 860a5a6 commit 5eb635f
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ protected void afterHookedMethod(MethodHookParam param) {
mBatteryPercentView.setVisibility(mShowPercentInside ? View.GONE : View.VISIBLE);
}

scaleBatteryMeterViews(view);
scaleBatteryMeterView(view);
updateChargingIconView(view, mIsCharging);
});
} catch (Throwable ignored) {
Expand Down Expand Up @@ -584,6 +584,7 @@ private void updateBatteryResources(XC_MethodHook.MethodHookParam param) {
callMethod(getObjectField(param.thisObject, "iconManager"), "setTint", textColorPrimary);
}
callMethod(batteryIcon, "updateColors", textColorPrimary, textColorSecondary, textColorPrimary);
scaleBatteryMeterView((Object) batteryIcon);
} catch (Throwable throwable) {
log(TAG + throwable);
}
Expand All @@ -603,7 +604,7 @@ private void refreshBatteryIcons() {
}

if (CustomBatteryEnabled) {
scaleBatteryMeterViews(mBatteryIconView);
scaleBatteryMeterView(mBatteryIconView);

try {
BatteryDrawable mBatteryDrawable = (BatteryDrawable) getAdditionalInstanceField(view, "mBatteryDrawable");
Expand All @@ -619,12 +620,12 @@ private void refreshBatteryIcons() {
}
}

public static void scaleBatteryMeterViews(Object thisObject) {
public static void scaleBatteryMeterView(Object thisObject) {
ImageView mBatteryIconView = (ImageView) getObjectField(thisObject, "mBatteryIconView");
scaleBatteryMeterViews(mBatteryIconView);
scaleBatteryMeterView(mBatteryIconView);
}

public static void scaleBatteryMeterViews(ImageView mBatteryIconView) {
public static void scaleBatteryMeterView(ImageView mBatteryIconView) {
if (mBatteryIconView == null) {
return;
}
Expand Down Expand Up @@ -670,7 +671,15 @@ private ImageView initBatteryIfNull(XC_MethodHook.MethodHookParam param, ImageVi
}
}

final ViewGroup.MarginLayoutParams mlp = new ViewGroup.MarginLayoutParams(mContext.getResources().getDimensionPixelSize(mContext.getResources().getIdentifier("status_bar_battery_icon_width", "dimen", mContext.getPackageName())), mContext.getResources().getDimensionPixelSize(mContext.getResources().getIdentifier("status_bar_battery_icon_height", "dimen", mContext.getPackageName())));
TypedValue typedValue = new TypedValue();

mContext.getResources().getValue(mContext.getResources().getIdentifier("status_bar_icon_scale_factor", "dimen", mContext.getPackageName()), typedValue, true);
float iconScaleFactor = typedValue.getFloat();

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());

final ViewGroup.MarginLayoutParams mlp = new ViewGroup.MarginLayoutParams((int) (batteryWidth * iconScaleFactor), (int) (batteryHeight * iconScaleFactor));
mlp.setMargins(0, 0, 0, mContext.getResources().getDimensionPixelOffset(mContext.getResources().getIdentifier("battery_margin_bottom", "dimen", mContext.getPackageName())));
setObjectField(param.thisObject, "mBatteryIconView", mBatteryIconView);
callMethod(param.thisObject, "addView", mBatteryIconView, mlp);
Expand Down

0 comments on commit 5eb635f

Please sign in to comment.