Skip to content

Commit

Permalink
Custom Shortcut: check if some classes exists, then load image
Browse files Browse the repository at this point in the history
  • Loading branch information
DHD2280 committed May 8, 2024
1 parent e49232b commit 0cbd838
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class CustomShortcut extends XposedMods {
private final String listenPackage = SETTINGS;
private boolean showInSettings = true;
private Context c;
private Class<?> ThemeUtils = null;

public CustomShortcut(Context context) {
super(context);
Expand Down Expand Up @@ -69,8 +70,8 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
}
});
Class<?> COUITintUtil = findClass("com.coui.appcompat.tintimageview.COUITintUtil", lpparam.classLoader);
Class<?> ThemeUtils = findClass("com.oplus.settings.utils.ThemeUtils", lpparam.classLoader);
try { ThemeUtils = findClass("com.oplus.settings.utils.ThemeUtils", lpparam.classLoader);
} catch (Throwable ignored) {}
hookAllMethods(TopLevelSettingsClass, "onCreateAdapter", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Expand All @@ -85,11 +86,17 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
R.drawable.pref_icon,
mContext.getTheme());
Drawable tinted;
try {
tinted = (Drawable) callStaticMethod(ThemeUtils, "getApplyCOUITintDrawable", c, OCIcon, true);
} catch (Throwable t) {
if (ThemeUtils == null) {
tinted = OCIcon;
} else {
try {
if (ThemeUtils == null) throw new Throwable();
tinted = (Drawable) callStaticMethod(ThemeUtils, "getApplyCOUITintDrawable", c, OCIcon, true);
} catch (Throwable t) {
tinted = OCIcon;
}
}

callMethod(OCPreference, "setIcon",
tinted);
callMethod(OCPreference, "setTitle", "Oxygen Customizer");
Expand Down

0 comments on commit 0cbd838

Please sign in to comment.