Skip to content

Commit

Permalink
Increase icon dimension for notification with app icon
Browse files Browse the repository at this point in the history
  • Loading branch information
DHD2280 committed Apr 30, 2024
1 parent 7a8e958 commit a005066
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,12 @@ public static String getBottomDxR(String key) {
getBottomDxR(QS_HEADER_CLOCK_STOCK_DATE_BACKGROUND_CHIP)
};
}

public static class Buttons {
public static final String BUTTONS_POWER_LONGPRESS_TORCH = "torch_long_press_power_gesture";
public static final String BUTTONS_POWER_LONGPRESS_TORCH_TIMEOUT_SWITCH = "torch_long_press_power_gesture_enable_timeout";
public static final String BUTTONS_POWER_LONGPRESS_TORCH_TIMEOUT = "torch_long_press_power_timeout";
public static final String BUTTONS_VOLUME_MUSIC = "volbtn_music_controls";
}

public static class Lockscreen {
public static final String DISABLE_POWER = "disable_power_on_lockscreen";
public static final String LOCKSCREEN_REMOVE_SOS = "hide_sos_lockscreen";
Expand All @@ -373,7 +371,6 @@ public static class Lockscreen {
public static final String LOCKSCREEN_HIDE_CAPSULE = "lockscreen_hide_capsule";
public static final String LOCKSCREEN_CARRIER_REPLACEMENT = "lockscreen_carrier_replacement";
}

public static class LockscreenClock {
public static final String LOCKSCREEN_CLOCK_SWITCH = "lockscreen_custom_clock_switch";
public static final String LOCKSCREEN_CLOCK_STYLE = "lockscreen_custom_clock_style";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import static de.robv.android.xposed.XposedHelpers.findClass;
import static de.robv.android.xposed.XposedHelpers.findClassIfExists;
import static de.robv.android.xposed.XposedHelpers.getBooleanField;
import static de.robv.android.xposed.XposedHelpers.getIntField;
import static de.robv.android.xposed.XposedHelpers.getObjectField;
import static de.robv.android.xposed.XposedHelpers.setObjectField;
Expand All @@ -19,6 +20,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
Expand All @@ -45,6 +47,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_InitPackageResources;
Expand All @@ -58,6 +61,8 @@ public class StatusbarMods extends XposedMods {

private static final String listenPackage = Constants.Packages.SYSTEM_UI;

private static final String TAG = "StatusbarMods: ";

// general use
private Object PSBV;
private View mStatusBarContents = null;
Expand Down Expand Up @@ -96,6 +101,7 @@ public class StatusbarMods extends XposedMods {
private DisplayManager mDisplayManager = null;
private Object mCollapsedStatusBarFragment = null;
private ViewGroup mStatusBar;
private Class<?> FwkResIdLoader = null;
private boolean doubleTapToSleepStatusbarEnabled;
GestureDetector mLockscreenDoubleTapToSleep; //event callback for double tap to sleep detection of statusbar only

Expand All @@ -109,12 +115,12 @@ public class StatusbarMods extends XposedMods {

private Object mActivityStarter;
private Class<?> NotificationIconAreaController;
private Class<?> DrawableSize = null;
private Class<?> DrawableSize = null, ScalingDrawableWrapper = null;
private Object mNotificationIconAreaController = null;
private Object mNotificationIconContainer = null;
private boolean mNewIconStyle;
private boolean mNotificationCount;
private boolean oos13 = false;
boolean force = true;

public StatusbarMods(Context context) {
super(context);
Expand Down Expand Up @@ -155,7 +161,6 @@ public void updatePrefs(String... Key) {

// Notifications
mNewIconStyle = Xprefs.getBoolean("statusbar_notification_app_icon", false);
mNotificationCount = Xprefs.getBoolean("statusbar_notification_count", false);

if (paddings.size() > 1) {
SBPaddingStart = paddings.get(0);
Expand All @@ -168,7 +173,6 @@ public void updatePrefs(String... Key) {
"statusbar_top_padding" -> updateStatusbarHeight();
case "statusbar_padding_enabled" -> updateResources();
case "statusbar_notification_app_icon" -> updateNotificationIcons();
case "statusbar_notification_count" -> enableCount();
}
}

Expand Down Expand Up @@ -511,9 +515,15 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
mNotificationIconContainer = param.thisObject;
}
});
try {
FwkResIdLoader = findClass("com.android.systemui.util.FwkResIdLoader", lpparam.classLoader);
} catch (Throwable ignored) {}
try {
DrawableSize = findClassIfExists("com.android.systemui.util.drawable.DrawableSize", lpparam.classLoader);
} catch (Throwable ignored) {}
try {
ScalingDrawableWrapper = findClass("com.android.systemui.statusbar.ScalingDrawableWrapper", lpparam.classLoader);
} catch (Throwable ignored) {}
Class<?> StatusBarIconView = findClass("com.android.systemui.statusbar.StatusBarIconView", lpparam.classLoader);
findAndHookMethod(StatusBarIconView,
"getIcon",
Expand All @@ -524,6 +534,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!mNewIconStyle) return;
Context sysuiContext = (Context) param.args[0];
Context context = (Context) param.args[1];
Drawable icon = null;
Object statusBarIcon = param.args[2];

Expand All @@ -535,84 +547,38 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
} catch (Throwable e) {
return;
}
int dimen = 0;
try {
dimen = (int) callMethod(FwkResIdLoader, "dimen", "notification_small_icon_size");
} catch (Throwable e) {
}
TypedValue typedValue = new TypedValue();
sysuiContext.getResources().getValue(
sysuiContext.getResources().getIdentifier("status_bar_icon_scale_factor", "dimen", listenPackage),
typedValue, true);
float scaleFactor = typedValue.getFloat();

int dimen;
if (icon != null) {
dimen = 48;
float density = mContext.getResources().getDisplayMetrics().density;
int dimensionPixelSize = Math.round(dimen * density);
if (DrawableSize != null) {
Drawable icon2 = (Drawable) callStaticMethod(DrawableSize, "downscaleToSize", mContext.getResources(), icon, dimensionPixelSize, dimensionPixelSize);
if (icon2 != null) {
param.setResult(icon2);
}
Resources res = sysuiContext.getResources();
int maxIconSize = dimen;
icon = (Drawable) callStaticMethod(DrawableSize, "downscaleToSize", mContext.getResources(), icon, maxIconSize, maxIconSize);
} else {
param.setResult(icon);
}
}

}
});

hookAllConstructors(StatusBarIconView, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Paint mNumberPain = (Paint) getObjectField(param.thisObject, "mNumberPain");
mNumberPain.setColor(Color.RED);

}
});

hookAllMethods(StatusBarIconView, "set", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (!mNotificationCount) return;
Object statusBarIcon = param.args[0];
Object statusBarIcon3 = getObjectField(param.thisObject, "mIcon");
boolean z4 = statusBarIcon3 != null && getIntField(statusBarIcon3, "number") == getIntField(statusBarIcon, "number");
Drawable mNumberBackground = (Drawable) getObjectField(param.thisObject, "mNumberBackground");
if (!z4) {
if (getIntField(statusBarIcon, "number") > 0) {
if (mNumberBackground == null) {
log("mNumberBackground == null");
GradientDrawable gradient = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[]{
Color.BLACK,
Color.BLACK
});
Drawable d = ResourcesCompat.getDrawable(mContext.getResources(),
mContext.getResources().getIdentifier("ic_notification_overlay", "drawable", listenPackage),
mContext.getTheme());
setObjectField(param.thisObject, "mNumberBackground", gradient);
}
/*Paint mNumberPain = (Paint) getObjectField(param.thisObject, "mNumberPain");
mNumberPain.setColor(Color.RED);*/
log("placeNumber");
if (getObjectField(param.thisObject, "mIcon") != null) {
callMethod(param.thisObject, "placeNumber");
log("placeNumber");
// No need to scale the icon, so return it as is.
if (scaleFactor == 1.f && icon != null) {
param.setResult(icon);
}

//callMethod(param.thisObject, "placeNumber");
} else {
setObjectField(param.thisObject, "mNumberBackground", (Drawable) null);
setObjectField(param.thisObject, "mNumberText", null);
// Scale the icon to the desired size.
param.setResult(ScalingDrawableWrapper.getConstructor(Drawable.class, float.class).newInstance(icon, scaleFactor));
}
log("invalidate"
);
callMethod(param.thisObject, "invalidate");
}


}
});
});

}

private void enableCount() {
XC_InitPackageResources.InitPackageResourcesParam ourResparam = resparams.get(Constants.Packages.SYSTEM_UI);
if (ourResparam == null) return;
log("enableCount");
ourResparam.res.setReplacement("com.android.systemui", "bool", "config_statusBarShowNumber", mNotificationCount);
}

//region icon tap related
Expand Down

0 comments on commit a005066

Please sign in to comment.