Skip to content

Commit 1882ebf

Browse files
committed
fix bugs in colors
1 parent 1b2c9cf commit 1882ebf

File tree

3 files changed

+51
-68
lines changed

3 files changed

+51
-68
lines changed

app/src/main/java/com/wmods/wppenhacer/utils/DrawableColors.java

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.wmods.wppenhacer.utils;
22

3-
import static com.wmods.wppenhacer.utils.IColors.parseColor;
43
import static com.wmods.wppenhacer.xposed.features.customization.CustomTheme.loader1;
54

65
import android.content.res.ColorStateList;
@@ -27,12 +26,15 @@
2726

2827
public class DrawableColors {
2928

30-
private static final HashMap<Bitmap,Integer> ninePatchs = new HashMap<>();
29+
private static final HashMap<Bitmap, Integer> ninePatchs = new HashMap<>();
3130

3231
public static void replaceColor(Drawable drawable, HashMap<String, String> colors) {
33-
if (DesignUtils.isNightMode()){
32+
if (drawable == null) return;
33+
34+
if (DesignUtils.isNightMode()) {
3435
colors.remove("#ffffffff");
3536
}
37+
3638
if (drawable instanceof StateListDrawable stateListDrawable) {
3739
var count = StateListDrawableCompact.getStateCount(stateListDrawable);
3840
for (int i = 0; i < count; i++) {
@@ -59,49 +61,29 @@ public static void replaceColor(Drawable drawable, HashMap<String, String> color
5961
var gradientColors = gradientDrawable.getColors();
6062
if (gradientColors != null) {
6163
for (var i = 0; i < gradientColors.length; i++) {
62-
var gradientColor = IColors.toString(gradientColors[i]);
63-
var newColor = colors.get(gradientColor);
64-
// XposedBridge.log(gradientColor + " / " + newColor);
65-
if (newColor != null) {
66-
gradientColors[i] = IColors.parseColor(newColor);
67-
} else {
68-
if (!gradientColor.startsWith("#ff") && !gradientColor.startsWith("#0")) {
69-
var sColorSub = gradientColor.substring(0, 3);
70-
newColor = colors.get(gradientColor.substring(3));
71-
if (newColor != null)
72-
gradientColors[i] = IColors.parseColor(sColorSub + newColor);
73-
}
74-
}
64+
var color = gradientColors[i];
65+
var newColor = IColors.getFromIntColor(color);
66+
if (color == newColor) continue;
67+
gradientColors[i] = newColor;
7568
}
7669
gradientDrawable.setColors(gradientColors);
7770
}
7871
} else if (drawable instanceof InsetDrawable insetDrawable) {
7972
replaceColor(insetDrawable.getDrawable(), colors);
8073
} else if (drawable instanceof NinePatchDrawable ninePatchDrawable) {
8174
var color = getNinePatchDrawableColor(ninePatchDrawable);
82-
var sColor = IColors.toString(color);
83-
var newColor = colors.get(sColor);
84-
// XposedBridge.log(sColor + " / " + newColor);
85-
if (newColor != null) {
86-
ninePatchDrawable.setTintList(ColorStateList.valueOf(parseColor(newColor)));
87-
}
75+
var newColor = IColors.getFromIntColor(color);
76+
if (color == newColor) return;
77+
ninePatchDrawable.setTintList(ColorStateList.valueOf(newColor));
78+
79+
} else if (drawable instanceof ColorDrawable colorDrawable) {
80+
var color = getColorDrawableColor(colorDrawable);
81+
colorDrawable.setColor(IColors.getFromIntColor(color));
8882
} else {
89-
if (drawable == null) return;
9083
var color = getColor(drawable);
91-
var sColor = IColors.toString(color);
92-
var newColor = colors.get(sColor);
93-
// XposedBridge.log(sColor + " / " + newColor);
94-
if (newColor != null) {
95-
drawable.setColorFilter(new PorterDuffColorFilter(parseColor(newColor), PorterDuff.Mode.SRC_IN));
96-
} else {
97-
if (!sColor.startsWith("#ff") && !sColor.startsWith("#0")) {
98-
var sColorSub = sColor.substring(0, 3);
99-
newColor = colors.get(sColor.substring(3));
100-
if (newColor != null) {
101-
drawable.setColorFilter(new PorterDuffColorFilter(parseColor(sColorSub + newColor), PorterDuff.Mode.SRC_IN));
102-
}
103-
}
104-
}
84+
var newColor = IColors.getFromIntColor(color);
85+
if (color == newColor) return;
86+
drawable.setColorFilter(new PorterDuffColorFilter(newColor, PorterDuff.Mode.SRC_IN));
10587
}
10688

10789
}
@@ -140,7 +122,6 @@ public static int getNinePatchDrawableColor(NinePatchDrawable ninePatchDrawable)
140122
var corSalva = ninePatchs.get(bitmap);
141123
if (corSalva != null) return corSalva;
142124

143-
// return bitmap.getPixel(width / 2, Math.min(5, height));
144125
HashMap<Integer, Integer> contagemCores = new HashMap<>();
145126
int corMaisFrequente = 0;
146127
int contagemMaxima = 0;

app/src/main/java/com/wmods/wppenhacer/utils/IColors.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class IColors {
3131
colors.put("#ff0a1014", "#ff0a1014"); // background green color (above version 22)
3232
colors.put("#ff10161a", "#ff10161a"); // background header green color (above version 22)
3333
colors.put("#ff12181c", "#ff12181c"); // background header green color (above version 22)
34+
colors.put("#ff20272b", "#ff20272b"); // background footer (above version 22)
3435

3536

3637
colors.put("#ffffffff", "#ffffffff"); // background color in light theme
@@ -54,8 +55,28 @@ public static int parseColor(String str) {
5455
}
5556

5657
public static String toString(int i) {
57-
return "#" + Integer.toHexString(i);
58+
var color = Integer.toHexString(i);
59+
if (color.length() == 7) {
60+
color = "0" + color;
61+
}
62+
return "#" + color;
5863
}
5964

6065

66+
public static int getFromIntColor(int color) {
67+
var sColor = IColors.toString(color);
68+
var newColor = colors.get(sColor);
69+
if (newColor != null && newColor.length() == 9) {
70+
return IColors.parseColor(newColor);
71+
} else {
72+
if (!sColor.equals("#0") && !sColor.startsWith("#ff")) {
73+
var sColorSub = sColor.substring(0, 3);
74+
newColor = colors.get(sColor.substring(3));
75+
if (newColor != null) {
76+
return IColors.parseColor(sColorSub + newColor);
77+
}
78+
}
79+
}
80+
return color;
81+
}
6182
}

app/src/main/java/com/wmods/wppenhacer/xposed/features/customization/CustomTheme.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ private void hookColors() throws Exception {
184184
switch (c) {
185185
case "0b141a", "0a1014" ->
186186
IColors.colors.put(c, backgroundColor.substring(3));
187-
case "#ff0b141a", "#ff111b21", "#ff000000", "#ff0a1014", "#ff10161a" ->
188-
IColors.colors.put(c, backgroundColor);
187+
case "#ff0b141a", "#ff111b21", "#ff000000", "#ff0a1014", "#ff10161a",
188+
"#ff12181c", "#ff20272b" -> IColors.colors.put(c, backgroundColor);
189189
}
190190
}
191191

@@ -256,7 +256,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
256256
private void replaceTransparency(HashMap<String, String> wallpaperColors, float mAlpha) {
257257
var hexAlpha = Integer.toHexString((int) Math.ceil(mAlpha * 255));
258258
hexAlpha = hexAlpha.length() == 1 ? "0" + hexAlpha : hexAlpha;
259-
for (var c : List.of("#ff0b141a", "#ff10161a", "#ff111b21", "#ff000000", "#ffffffff", "#ff1b8755", "#ff0a1014", "#ff12181c")) {
259+
for (var c : List.of("#ff0b141a", "#ff10161a", "#ff111b21", "#ff000000", "#ffffffff", "#ff1b8755", "#ff0a1014", "#ff12181c", "#ff10161a", "#ff20272b")) {
260260
var oldColor = wallpaperColors.get(c);
261261
if (oldColor == null) continue;
262262
var newColor = "#" + hexAlpha + oldColor.substring(3);
@@ -293,24 +293,11 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
293293
public static class ColorStateListHook extends XC_MethodHook {
294294
@Override
295295
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
296-
var colors = IColors.colors;
297296
var colorStateList = param.args[0];
298297
if (colorStateList != null) {
299298
var mColors = (int[]) XposedHelpers.getObjectField(colorStateList, "mColors");
300299
for (int i = 0; i < mColors.length; i++) {
301-
var sColor = IColors.toString(mColors[i]);
302-
var newColor = colors.get(sColor);
303-
if (newColor != null && newColor.length() == 9) {
304-
mColors[i] = IColors.parseColor(newColor);
305-
} else {
306-
if (!sColor.equals("#0") && !sColor.startsWith("#ff")) {
307-
var sColorSub = sColor.substring(0, 3);
308-
newColor = colors.get(sColor.substring(3));
309-
if (newColor != null) {
310-
mColors[i] = IColors.parseColor(sColorSub + newColor);
311-
}
312-
}
313-
}
300+
mColors[i] = IColors.getFromIntColor(mColors[i]);
314301
}
315302
XposedHelpers.setObjectField(colorStateList, "mColors", mColors);
316303
param.args[0] = colorStateList;
@@ -321,28 +308,22 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
321308
public static class IntBgColorHook extends XC_MethodHook {
322309
@Override
323310
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
324-
var colors = IColors.colors;
325311
var color = (int) param.args[0];
326312
var sColor = IColors.toString(color);
313+
327314
if (param.thisObject instanceof TextView textView) {
328315
var id = Utils.getID("conversations_row_message_count", "id");
329316
if (textView.getId() == id) {
330317
param.args[0] = IColors.parseColor("#ff" + sColor.substring(sColor.length() == 9 ? 3 : 1));
331318
return;
332319
}
333-
}
334-
var newColor = colors.get(sColor);
335-
if (newColor != null && newColor.length() == 9) {
336-
param.args[0] = IColors.parseColor(newColor);
337-
} else {
338-
if (!sColor.equals("#0") && !sColor.startsWith("#ff")) {
339-
var sColorSub = sColor.substring(0, 3);
340-
newColor = colors.get(sColor.substring(3));
341-
if (newColor != null) {
342-
param.args[0] = IColors.parseColor(sColorSub + newColor);
343-
}
320+
} else if (param.thisObject instanceof Paint) {
321+
// This fixes the issue with background colors affecting chat bubbles
322+
if (ReflectionUtils.isCalledFromStrings("getValue")) {
323+
return;
344324
}
345325
}
326+
param.args[0] = IColors.getFromIntColor(color);
346327
}
347328
}
348329
}

0 commit comments

Comments
 (0)