Skip to content

Commit

Permalink
Revert Wallpaper to old inject
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev4Mod committed May 15, 2024
1 parent 499adf5 commit 18820b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 50 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/wmods/wppenhacer/utils/IColors.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class IColors {
colors.put("#21c063", "#21c063");
colors.put("#ff21c063", "#ff21c063");
colors.put("#ff000000", "#ff000000");
colors.put("#0b141a", "#ff000000");

// Secondary
colors.put("#ff202c33", "#ff202c33");
Expand Down
22 changes: 16 additions & 6 deletions app/src/main/java/com/wmods/wppenhacer/views/WallpaperView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
@SuppressLint("ViewConstructor")
public class WallpaperView extends FrameLayout {
private final XSharedPreferences prefs;
private float mAlpha = 1.0f;
private ImageView bgView;

public WallpaperView(@NonNull Context context, XSharedPreferences preferences) {
super(context);
Expand All @@ -27,18 +29,26 @@ public WallpaperView(@NonNull Context context, XSharedPreferences preferences) {
}

private void init(Context context) {
ImageView imageView = new ImageView(context);
imageView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setAdjustViewBounds(false);
bgView = new ImageView(context);
bgView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
bgView.setScaleType(ImageView.ScaleType.CENTER_CROP);
bgView.setAdjustViewBounds(false);
try {
Bitmap bitmap = BitmapFactory.decodeFile(prefs.getString("wallpaper_file", ""));
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(drawable);
addView(imageView);
bgView.setImageDrawable(drawable);
mAlpha = (100 - prefs.getInt("wallpaper_alpha", 30)) / 100.0f;
addView(bgView);
} catch (Exception e) {
log(e.toString());
}
}

@Override
public void addView(View child) {
if (child != bgView){
child.setAlpha(mAlpha);
}
super.addView(child);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
public class CustomTheme extends Feature {

public static ClassLoader classLoader;
private HashMap<String, String> newColors;
private boolean isWallpaper;

public CustomTheme(ClassLoader loader, XSharedPreferences preferences) {
super(loader, preferences);
Expand Down Expand Up @@ -107,7 +105,7 @@ private void hookColors() throws Exception {

if (!backgroundColor.equals("0")) {
switch (c) {
// case "0b141a" -> IColors.colors.put(c, backgroundColor.substring(3));
case "0b141a" -> IColors.colors.put(c, backgroundColor.substring(3));
case "#ff0b141a", "#ff111b21", "#ff000000" ->
IColors.colors.put(c, backgroundColor);
}
Expand All @@ -121,27 +119,11 @@ private void hookColors() throws Exception {
}
}

var mAlpha = (100 - prefs.getInt("wallpaper_alpha", 30)) / 100.0f;
var hexAlpha = Integer.toHexString((int) Math.floor(mAlpha * 255f)).toLowerCase();
hexAlpha = hexAlpha.length() == 1 ? "0" + hexAlpha : hexAlpha;
var bgColors = List.of("#ff0b141a", "#ff111b21", "#ff000000");
newColors = new HashMap<>(IColors.colors);
for (var color : bgColors) {
var bgColor = IColors.colors.get(color);
var alphaBgColor = "#" + hexAlpha + bgColor.substring(3);
newColors.put(color, alphaBgColor);
IColors.colors.put(alphaBgColor, bgColor);
if (Objects.equals(hexAlpha, "00")) {
IColors.colors.put(alphaBgColor.substring(3), bgColor);
}
}
isWallpaper = prefs.getBoolean("wallpaper", false);

findAndHookMethod(Activity.class.getName(), loader, "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
var colors = getAlpha();
var colors = IColors.colors;
var activity = (Activity) param.thisObject;
var view = activity.findViewById(android.R.id.content).getRootView();
replaceColors(view, colors);
Expand Down Expand Up @@ -175,27 +157,14 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", int.class, ViewGroup.class, boolean.class, inflaterHook);
findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", XmlPullParser.class, ViewGroup.class, boolean.class, inflaterHook);

// findAndHookMethod(View.class.getName(), loader, "setBackground", Drawable.class, new XC_MethodHook() {
// @Override
// protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// var colors = getAlpha();
// var drawable = (Drawable) param.args[0];
// replaceColor(drawable, colors);
// }
// });
}

private HashMap<String, String> getAlpha() {
if (!isWallpaper) return IColors.colors;
// if (!Unobfuscator.isCalledFromString("HomeActivity.onCreate")) return IColors.colors;
if (Unobfuscator.isCalledFromClass(Window.class)) return IColors.colors;
if (Unobfuscator.isCalledFromStrings(
"setStatusBarColor", "WDSToolbar", "WDSFab", "onPreparePanel"
, "onCreateOptionsMenu", "onLongClick", "PhoneWindow", "Image"))
return IColors.colors;
if (Unobfuscator.isCalledFromClass(ShowEditMessage.class)) return IColors.colors;
if (Unobfuscator.isCalledFromClass(DesignUtils.class)) return IColors.colors;
return newColors;
findAndHookMethod(View.class.getName(), loader, "setBackground", Drawable.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var colors = IColors.colors;
var drawable = (Drawable) param.args[0];
replaceColor(drawable, colors);
}
});
}

private void injectWallpaper(View view) {
Expand All @@ -222,7 +191,7 @@ public String getPluginName() {
public class LayoutInflaterHook extends XC_MethodHook {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
var colors = getAlpha();
var colors = IColors.colors;
var view = (View) param.getResult();
if (view == null) return;
replaceColors(view, colors);
Expand All @@ -232,7 +201,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
public class ColorStateListHook extends XC_MethodHook {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var colors = getAlpha();
var colors = IColors.colors;
var colorStateList = param.args[0];
if (colorStateList != null) {
var mColors = (int[]) XposedHelpers.getObjectField(colorStateList, "mColors");
Expand Down Expand Up @@ -260,7 +229,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
public class IntBgColorHook extends XC_MethodHook {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
var colors = getAlpha();
var colors = IColors.colors;
var color = (int) param.args[0];
var sColor = IColors.toString(color);
var newColor = colors.get(sColor);
Expand Down

0 comments on commit 18820b1

Please sign in to comment.