From e96ba600cba325f8ed4d7dfca3908f59f0e86717 Mon Sep 17 00:00:00 2001 From: aliveoutside <53598473+aliveoutside@users.noreply.github.com> Date: Sun, 28 Aug 2022 20:08:02 +0300 Subject: [PATCH] uncomments --- .../ru/vtosters/lite/res/VTLResources.java | 51 +++++++------- .../lite/res/proxy/ProxyLayoutInflater.java | 4 +- .../lite/res/proxy/ProxyResources.java | 68 +++++++++---------- 3 files changed, 59 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/res/VTLResources.java b/app/src/main/java/ru/vtosters/lite/res/VTLResources.java index 7333796d1..5e4bf1605 100644 --- a/app/src/main/java/ru/vtosters/lite/res/VTLResources.java +++ b/app/src/main/java/ru/vtosters/lite/res/VTLResources.java @@ -4,19 +4,14 @@ import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Resources; import android.content.res.TypedArray; -import android.graphics.drawable.Drawable; import android.os.Build; import android.util.AttributeSet; import android.util.SparseIntArray; import android.util.TypedValue; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import com.vtosters.lite.R; import java.lang.reflect.Field; -import java.util.HashMap; import ru.vtosters.lite.utils.ReflectionUtils; import ru.vtosters.lite.utils.ThemesUtils; @@ -48,29 +43,29 @@ public class VTLResources { } private static void prepareTypedArray(TypedArray target, int[] attrs) { -// if (attrs == null) return; -// var data = getData(target); -// for (int i = 0; i < attrs.length; i++) { -// var attr = attrs[i]; -// var replacement = otherAttrs.get(attr, -1); -// if (replacement == -1) continue; -// var index = STYLE_NUM_ENTRIES * i; -// var type = data[index]; -// if (type == TypedValue.TYPE_ATTRIBUTE) -// replacement = data[index + 0x1]; -// else if (type == TypedValue.TYPE_INT_COLOR_ARGB8 || type == TypedValue.TYPE_INT_COLOR_RGB8) -// replacement = forcedAttrs.get(data[index + 0x1], 0); -// else -// continue; -// try { -// data[index] = TypedValue.TYPE_INT_COLOR_RGB8; // type -// data[index + 0x1] = ThemesUtils.getColorFromAttr(attr); // data -// data[index + 0x2] = 0x0; // asset cookie -// data[index + 0x3] = 0x0; // resource id -// -// } catch (Throwable ignored) { -// } -// } + if (attrs == null) return; + var data = getData(target); + for (int i = 0; i < attrs.length; i++) { + var attr = attrs[i]; + var replacement = otherAttrs.get(attr, -1); + if (replacement == -1) continue; + var index = STYLE_NUM_ENTRIES * i; + var type = data[index]; + if (type == TypedValue.TYPE_ATTRIBUTE) + replacement = data[index + 0x1]; + else if (type == TypedValue.TYPE_INT_COLOR_ARGB8 || type == TypedValue.TYPE_INT_COLOR_RGB8) + replacement = forcedAttrs.get(data[index + 0x1], 0); + else + continue; + try { + data[index] = TypedValue.TYPE_INT_COLOR_RGB8; // type + data[index + 0x1] = ThemesUtils.getColorFromAttr(attr); // data + data[index + 0x2] = 0x0; // asset cookie + data[index + 0x3] = 0x0; // resource id + + } catch (Throwable ignored) { + } + } } private static int[] getData(TypedArray target) { diff --git a/app/src/main/java/ru/vtosters/lite/res/proxy/ProxyLayoutInflater.java b/app/src/main/java/ru/vtosters/lite/res/proxy/ProxyLayoutInflater.java index 4a3e93280..7e2399351 100644 --- a/app/src/main/java/ru/vtosters/lite/res/proxy/ProxyLayoutInflater.java +++ b/app/src/main/java/ru/vtosters/lite/res/proxy/ProxyLayoutInflater.java @@ -41,9 +41,9 @@ public class ProxyLayoutInflater extends LayoutInflater { @Override public View inflate(int resource, @Nullable ViewGroup root, boolean attachToRoot) { - //parseLayout(resource); + parseLayout(resource); var target = super.inflate(resource, root, attachToRoot); - //Recolor.recolorViewOrViewGroup(target, layouts.get(resource)); + Recolor.recolorViewOrViewGroup(target, layouts.get(resource)); return target; } diff --git a/app/src/main/java/ru/vtosters/lite/res/proxy/ProxyResources.java b/app/src/main/java/ru/vtosters/lite/res/proxy/ProxyResources.java index f3b3ec9c0..464e9f730 100644 --- a/app/src/main/java/ru/vtosters/lite/res/proxy/ProxyResources.java +++ b/app/src/main/java/ru/vtosters/lite/res/proxy/ProxyResources.java @@ -41,39 +41,39 @@ public class ProxyResources extends Resources { } public static void addProxyResources(Object target) { -// if (!ThemesUtils.isCustomThemeApplied()) return; -// try { -// Class clz = target.getClass(); -// Field field = null; -// if (!resourceFieldsMap.containsKey(clz)) { -// loop: -// while (clz != null) { -// for (var f : clz.getDeclaredFields()) { -// if (f.getType() == Resources.class) { -// field = f; -// break loop; -// } -// } -// for (var f : clz.getFields()) { -// if (f.getType() == Resources.class) { -// field = f; -// break loop; -// } -// } -// clz = clz.getSuperclass(); -// } -// resourceFieldsMap.put(target.getClass(), field); -// } else { -// field = resourceFieldsMap.get(clz); -// } -// if (field == null) return; -// field.setAccessible(true); -// ReflectionUtils.unfinalField(field); -// var original = (Resources) field.get(target); -// if (original != null && !(original instanceof ProxyResources)) -// field.set(target, new ProxyResources(original)); -// } catch (Throwable e) { -// e.printStackTrace(); -// } + if (!ThemesUtils.isCustomThemeApplied()) return; + try { + Class clz = target.getClass(); + Field field = null; + if (!resourceFieldsMap.containsKey(clz)) { + loop: + while (clz != null) { + for (var f : clz.getDeclaredFields()) { + if (f.getType() == Resources.class) { + field = f; + break loop; + } + } + for (var f : clz.getFields()) { + if (f.getType() == Resources.class) { + field = f; + break loop; + } + } + clz = clz.getSuperclass(); + } + resourceFieldsMap.put(target.getClass(), field); + } else { + field = resourceFieldsMap.get(clz); + } + if (field == null) return; + field.setAccessible(true); + ReflectionUtils.unfinalField(field); + var original = (Resources) field.get(target); + if (original != null && !(original instanceof ProxyResources)) + field.set(target, new ProxyResources(original)); + } catch (Throwable e) { + e.printStackTrace(); + } } }