Skip to content

Commit 1589265

Browse files
committed
Improve Custom Theme V2
Signed-off-by: Dev4Mod <[email protected]>
1 parent e20e09b commit 1589265

File tree

5 files changed

+82
-463
lines changed

5 files changed

+82
-463
lines changed

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

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

33
import static com.wmods.wppenhacer.utils.DrawableColors.replaceColor;
4-
import static com.wmods.wppenhacer.utils.IColors.parseColor;
5-
import static de.robv.android.xposed.XposedHelpers.callMethod;
64

75
import android.graphics.PorterDuffColorFilter;
86
import android.view.View;
@@ -11,16 +9,19 @@
119
import android.widget.ImageView;
1210
import android.widget.TextView;
1311

12+
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
13+
1414
import java.util.HashMap;
1515

16+
import de.robv.android.xposed.XposedBridge;
1617
import de.robv.android.xposed.XposedHelpers;
1718

1819
public class ColorReplacement {
1920
public static void replaceColors(View view, HashMap<String, String> colors) {
2021
if (view instanceof ImageView imageView) {
2122
Image.replace(imageView,colors);
2223
} else if (view instanceof TextView textView) {
23-
Text.replace(textView,colors);
24+
Text.replace(textView, colors);
2425
} else if (view instanceof ViewGroup viewGroup) {
2526
Group.replace(viewGroup,colors);
2627
} else if (view instanceof ViewStub viewStub) {
@@ -47,49 +48,30 @@ static void replace(ImageView view, HashMap<String, String> colors) {
4748
view.setColorFilter(IColors.parseColor(sColorSub + newColor));
4849
}
4950
}
50-
}/* else {
51-
XposedBridge.log("Image replacement: " + colorFilter.getClass().getName());
52-
}*/
53-
}
54-
}
55-
56-
public static class CircularProgressBar {
57-
static void replace(Object view, HashMap<String, String> colors) {
58-
var progressColor = (int) callMethod(view, "getProgressBarColor");
59-
var progressBackgroundColor = (int) callMethod(view, "getProgressBarBackgroundColor");
60-
61-
var pcSColor = IColors.toString(progressColor);
62-
var pcbSColor = IColors.toString(progressBackgroundColor);
63-
64-
var newPColor = colors.get(pcSColor);
65-
var newPBColor = colors.get(pcbSColor);
66-
67-
if (newPColor != null) {
68-
callMethod(view, "setProgressBarColor", parseColor(newPColor));
6951
}
70-
71-
if (newPBColor != null) {
72-
callMethod(view, "setProgressBarBackgroundColor", parseColor(newPBColor));
73-
}
74-
7552
}
7653
}
7754

7855
public static class Text {
7956
static void replace(TextView view, HashMap<String, String> colors) {
80-
replaceColor(view.getBackground(), colors);
8157
var color = view.getCurrentTextColor();
8258
var sColor = IColors.toString(color);
59+
if (sColor.equals("#ffffffff") && !DesignUtils.isNightMode()) {
60+
return;
61+
}
62+
replaceColor(view.getBackground(), colors);
8363
var newColor = colors.get(sColor);
8464
if (newColor != null) {
85-
// XposedBridge.log(sColor + "/" + newColor + ": " + view.getText());
8665
view.setTextColor(IColors.parseColor(newColor));
66+
XposedBridge.log("ColorReplacement.Text.replace: " + sColor + "->" + newColor);
8767
} else {
8868
if (!sColor.startsWith("#ff") && !sColor.startsWith("#0")) {
8969
var sColorSub = sColor.substring(0, 3);
9070
newColor = colors.get(sColor.substring(3));
91-
if (newColor != null)
71+
if (newColor != null) {
9272
view.setTextColor(IColors.parseColor(sColorSub + newColor));
73+
XposedBridge.log("ColorReplacement.Text.replace: " + sColor + "->" + newColor);
74+
}
9375
}
9476
}
9577
}

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

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,20 @@
33
import android.content.res.ColorStateList;
44
import android.graphics.Bitmap;
55
import android.graphics.NinePatch;
6-
import android.graphics.PorterDuff;
7-
import android.graphics.PorterDuffColorFilter;
8-
import android.graphics.drawable.ClipDrawable;
96
import android.graphics.drawable.ColorDrawable;
107
import android.graphics.drawable.Drawable;
118
import android.graphics.drawable.DrawableContainer;
9+
import android.graphics.drawable.DrawableWrapper;
1210
import android.graphics.drawable.GradientDrawable;
1311
import android.graphics.drawable.InsetDrawable;
1412
import android.graphics.drawable.LayerDrawable;
1513
import android.graphics.drawable.LevelListDrawable;
1614
import android.graphics.drawable.NinePatchDrawable;
1715
import android.graphics.drawable.RippleDrawable;
18-
import android.graphics.drawable.RotateDrawable;
19-
import android.graphics.drawable.ScaleDrawable;
2016
import android.graphics.drawable.ShapeDrawable;
2117
import android.graphics.drawable.StateListDrawable;
2218
import android.graphics.drawable.TransitionDrawable;
2319

24-
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
25-
2620
import java.util.HashMap;
2721

2822
import de.robv.android.xposed.XposedBridge;
@@ -35,10 +29,6 @@ public class DrawableColors {
3529
public static void replaceColor(Drawable drawable, HashMap<String, String> colors) {
3630
if (drawable == null) return;
3731

38-
if (DesignUtils.isNightMode()) {
39-
colors.remove("#ffffffff");
40-
}
41-
4232
if (drawable instanceof StateListDrawable stateListDrawable) {
4333
var count = StateListDrawableCompact.getStateCount(stateListDrawable);
4434
for (int i = 0; i < count; i++) {
@@ -57,43 +47,23 @@ public static void replaceColor(Drawable drawable, HashMap<String, String> color
5747
}
5848
gradientDrawable.setColors(gradientColors);
5949
}
60-
} else if (drawable instanceof InsetDrawable insetDrawable) {
61-
replaceColor(insetDrawable.getDrawable(), colors);
50+
} else if (drawable instanceof DrawableWrapper drawableWrapper) {
51+
replaceColor(drawableWrapper.getDrawable(), colors);
6252
} else if (drawable instanceof NinePatchDrawable ninePatchDrawable) {
6353
var color = getNinePatchDrawableColor(ninePatchDrawable);
6454
var newColor = IColors.getFromIntColor(color, colors);
6555
if (color == newColor) return;
6656
ninePatchDrawable.setTintList(ColorStateList.valueOf(newColor));
6757
} else if (drawable instanceof ColorDrawable colorDrawable) {
6858
var color = getColorDrawableColor(colorDrawable);
69-
colorDrawable.setColor(IColors.getFromIntColor(color, colors));
59+
var newColor = IColors.getFromIntColor(color, colors);
60+
if (newColor == color) return;
61+
colorDrawable.setColor(newColor);
7062
} else if (drawable instanceof ShapeDrawable shapeDrawable) {
7163
var color = getShapeDrawableColor(shapeDrawable);
7264
var newColor = IColors.getFromIntColor(color, colors);
7365
if (color == newColor) return;
7466
shapeDrawable.getPaint().setColor(newColor);
75-
} else if (drawable instanceof RippleDrawable rippleDrawable) {
76-
var color = getRippleDrawableColor(rippleDrawable);
77-
var newColor = IColors.getFromIntColor(color, colors);
78-
if (color == newColor) return;
79-
rippleDrawable.setColor(ColorStateList.valueOf(newColor));
80-
81-
// Also handle the content and mask drawables of the ripple
82-
Drawable contentDrawable = rippleDrawable.getDrawable(0);
83-
if (contentDrawable != null) {
84-
replaceColor(contentDrawable, colors);
85-
}
86-
87-
Drawable maskDrawable = rippleDrawable.getDrawable(1);
88-
if (maskDrawable != null) {
89-
replaceColor(maskDrawable, colors);
90-
}
91-
} else if (drawable instanceof ClipDrawable clipDrawable) {
92-
replaceColor(clipDrawable.getDrawable(), colors);
93-
} else if (drawable instanceof RotateDrawable rotateDrawable) {
94-
replaceColor(rotateDrawable.getDrawable(), colors);
95-
} else if (drawable instanceof ScaleDrawable scaleDrawable) {
96-
replaceColor(scaleDrawable.getDrawable(), colors);
9767
} else if (drawable instanceof LevelListDrawable levelListDrawable) {
9868
int count = (int) XposedHelpers.callMethod(levelListDrawable, "getNumberOfLevels");
9969
for (int i = 0; i < count; i++) {
@@ -125,13 +95,7 @@ public static void replaceColor(Drawable drawable, HashMap<String, String> color
12595
for (var drawable1 : drawables) {
12696
replaceColor(drawable1, colors);
12797
}
128-
} else {
129-
var color = getColor(drawable);
130-
var newColor = IColors.getFromIntColor(color, colors);
131-
if (color == newColor) return;
132-
drawable.setColorFilter(new PorterDuffColorFilter(newColor, PorterDuff.Mode.SRC_IN));
13398
}
134-
13599
}
136100

137101
public static int getColor(Drawable drawable) {

0 commit comments

Comments
 (0)