|
| 1 | +package com.wmods.wppenhacer.xposed.features.customization; |
| 2 | + |
| 3 | +import android.content.res.AssetManager; |
| 4 | +import android.graphics.drawable.Drawable; |
| 5 | +import android.util.TypedValue; |
| 6 | + |
| 7 | +import androidx.annotation.NonNull; |
| 8 | + |
| 9 | +import com.wmods.wppenhacer.utils.DrawableColors; |
| 10 | +import com.wmods.wppenhacer.utils.IColors; |
| 11 | +import com.wmods.wppenhacer.xposed.core.Feature; |
| 12 | +import com.wmods.wppenhacer.xposed.utils.DesignUtils; |
| 13 | +import com.wmods.wppenhacer.xposed.utils.Utils; |
| 14 | + |
| 15 | +import java.util.Objects; |
| 16 | +import java.util.Properties; |
| 17 | + |
| 18 | +import de.robv.android.xposed.XC_MethodHook; |
| 19 | +import de.robv.android.xposed.XSharedPreferences; |
| 20 | +import de.robv.android.xposed.XposedBridge; |
| 21 | +import de.robv.android.xposed.XposedHelpers; |
| 22 | + |
| 23 | +public class CustomThemeV2 extends Feature { |
| 24 | + |
| 25 | + public CustomThemeV2(@NonNull ClassLoader classLoader, @NonNull XSharedPreferences preferences) { |
| 26 | + super(classLoader, preferences); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public void doHook() throws Throwable { |
| 31 | + |
| 32 | + Properties properties = Utils.extractProperties(prefs.getString("custom_css", "")); |
| 33 | + |
| 34 | + var primaryColorInt = prefs.getInt("primary_color", 0); |
| 35 | + var secondaryColorInt = prefs.getInt("secondary_color", 0); |
| 36 | + var backgroundColorInt = prefs.getInt("background_color", 0); |
| 37 | + |
| 38 | + var primaryColor = DesignUtils.checkSystemColor(properties.getProperty("primary_color", "0")); |
| 39 | + var secondaryColor = DesignUtils.checkSystemColor(properties.getProperty("secondary_color", "0")); |
| 40 | + var backgroundColor = DesignUtils.checkSystemColor(properties.getProperty("background_color", "0")); |
| 41 | + |
| 42 | + if (prefs.getBoolean("changecolor", false)) { |
| 43 | + primaryColor = primaryColorInt == 0 ? "0" : IColors.toString(primaryColorInt); |
| 44 | + secondaryColor = secondaryColorInt == 0 ? "0" : IColors.toString(secondaryColorInt); |
| 45 | + backgroundColor = backgroundColorInt == 0 ? "0" : IColors.toString(backgroundColorInt); |
| 46 | + } |
| 47 | + |
| 48 | + if (prefs.getBoolean("changecolor", false) || Objects.equals(properties.getProperty("change_colors"), "true")) { |
| 49 | + for (var c : IColors.colors.keySet()) { |
| 50 | + if (!primaryColor.equals("0") && DesignUtils.isValidColor(primaryColor)) { |
| 51 | + primaryColor = primaryColor.length() == 9 ? primaryColor : "#ff" + primaryColor.substring(1); |
| 52 | + switch (c) { |
| 53 | + case "00a884", "1da457", "21c063", "d9fdd3" -> |
| 54 | + IColors.colors.put(c, primaryColor.substring(3)); |
| 55 | + case "#ff00a884", "#ff1da457", "#ff21c063", "#ff1daa61", "#ff25d366", |
| 56 | + "#ffd9fdd3" -> IColors.colors.put(c, primaryColor); |
| 57 | + case "#ff103529" -> |
| 58 | + IColors.colors.put(c, "#66" + primaryColor.substring(3)); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + if (!backgroundColor.equals("0") && DesignUtils.isValidColor(backgroundColor)) { |
| 63 | + backgroundColor = backgroundColor.length() == 9 ? backgroundColor : "#ff" + backgroundColor.substring(1); |
| 64 | + switch (c) { |
| 65 | + case "0b141a", "0a1014" -> |
| 66 | + IColors.colors.put(c, backgroundColor.substring(3)); |
| 67 | + case "#ff0b141a", "#ff111b21", "#ff000000", "#ff0a1014", "#ff10161a", |
| 68 | + "#ff12181c", "#ff20272b" -> IColors.colors.put(c, backgroundColor); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + if (!secondaryColor.equals("0") && DesignUtils.isValidColor(secondaryColor)) { |
| 73 | + secondaryColor = secondaryColor.length() == 9 ? secondaryColor : "#ff" + secondaryColor.substring(1); |
| 74 | + if (c.equals("#ff202c33") || c.equals("#ff2a2f33")) { |
| 75 | + IColors.colors.put(c, secondaryColor); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + XposedBridge.hookAllMethods(AssetManager.class, "getResourceValue", new XC_MethodHook() { |
| 82 | + @Override |
| 83 | + protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
| 84 | + var id = (int) param.args[0]; |
| 85 | + var typedValue = (TypedValue) param.args[2]; |
| 86 | + if (id >= 0x7f060000 && id <= 0x7f06ffff) { |
| 87 | + if (typedValue.type >= TypedValue.TYPE_FIRST_INT |
| 88 | + && typedValue.type <= TypedValue.TYPE_LAST_INT) { |
| 89 | + if (typedValue.data == 0) return; |
| 90 | + typedValue.data = IColors.getFromIntColor(typedValue.data); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + }); |
| 95 | + |
| 96 | + var resourceImpl = XposedHelpers.findClass("android.content.res.ResourcesImpl", classLoader); |
| 97 | + XposedBridge.hookAllMethods(resourceImpl, "loadDrawable", new XC_MethodHook() { |
| 98 | + @Override |
| 99 | + protected void afterHookedMethod(MethodHookParam param) throws Throwable { |
| 100 | + var drawable = (Drawable) param.getResult(); |
| 101 | + DrawableColors.replaceColor(drawable, IColors.colors); |
| 102 | + } |
| 103 | + }); |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | + @NonNull |
| 108 | + @Override |
| 109 | + public String getPluginName() { |
| 110 | + return "Custom Theme V2"; |
| 111 | + } |
| 112 | + |
| 113 | +} |
0 commit comments