diff --git a/app/src/main/java/com/google/devrel/gmscore/tools/apk/arsc/BinaryResourceValue.java b/app/src/main/java/com/google/devrel/gmscore/tools/apk/arsc/BinaryResourceValue.java index 52c40b491..50e8d9e44 100644 --- a/app/src/main/java/com/google/devrel/gmscore/tools/apk/arsc/BinaryResourceValue.java +++ b/app/src/main/java/com/google/devrel/gmscore/tools/apk/arsc/BinaryResourceValue.java @@ -130,9 +130,9 @@ public class BinaryResourceValue implements SerializableResource { */ public static final int SIZE = 8; - private final int size; - private final Type type; - private final int data; + public int size; + public Type type; + public int data; public static BinaryResourceValue create(ByteBuffer buffer) { int size = (buffer.getShort() & 0xFFFF); diff --git a/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java b/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java index e813a5a74..0edc5e13f 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java +++ b/app/src/main/java/ru/vtosters/lite/themes/ThemesManager.java @@ -161,8 +161,7 @@ public class ThemesManager { final var arscEntry = apk.getEntry("resources.arsc"); final var arscBis = new BufferedInputStream(apk.getInputStream(arscEntry)); final var arsc = BinaryResourceFile.fromInputStream(arscBis); - if (!ArscEditor.changeColors(arsc, ACCENT_COLORS, accentColor)) - throw new IllegalStateException("Not all colors have been changed"); + ArscEditor.changeColors(arsc, ACCENT_COLORS, accentColor); try ( final var zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(modApk))) diff --git a/app/src/main/java/ru/vtosters/lite/themes/utils/ArscEditor.java b/app/src/main/java/ru/vtosters/lite/themes/utils/ArscEditor.java index d25e6b705..fc96719e5 100644 --- a/app/src/main/java/ru/vtosters/lite/themes/utils/ArscEditor.java +++ b/app/src/main/java/ru/vtosters/lite/themes/utils/ArscEditor.java @@ -4,34 +4,40 @@ import com.google.devrel.gmscore.tools.apk.arsc.*; public class ArscEditor { - public static boolean changeColors(BinaryResourceFile arsc, int[] colorIds, int color /*int[] colors*/) { - int q = 0; - for (var chunk : arsc.getChunks()) { - final var resourceTableChunk = (ResourceTableChunk) chunk; - - for (PackageChunk packageChunk : resourceTableChunk.getPackages()) { - for (TypeSpecChunk typeSpecChunk : packageChunk.getTypeSpecChunks()) { - for (TypeChunk typeChunk : packageChunk.getTypeChunks(typeSpecChunk.getId())) { - if (!"color".equals(typeChunk.getTypeName())) continue; - - for (var entry : typeChunk.getEntries().entrySet()) { - if (entry.getValue().isComplex()) continue; - - final var id = BinaryResourceIdentifier.create(packageChunk.getId(), typeSpecChunk.getId(), entry.getKey()); - - for (int colorId : colorIds) { - if (colorId != id.resId()) continue; - - final var value = entry.getValue(); - value.updateValue(new BinaryResourceValue(8, value.value().type(), color /*colors[i]*/)); - ++q; + public static void changeColors(BinaryResourceFile arsc,int[] colorIds,int color) { + for(var chunk:arsc.getChunks()) + { + final var resTableChunk=(ResourceTableChunk)chunk; + for(var packageChunk:resTableChunk.getPackages()) + { + for(var typeChunk:packageChunk.getTypeChunks("color")) + { + for(var entry:typeChunk.getEntries().entrySet()) + { + final var value=entry.getValue(); + if(value.isComplex())continue; + final var binValue=value.value(); + if(!isColorResourceValue(binValue))continue; + final var resId=packageChunk.getId()<<24|typeChunk.getId()<<16|entry.getKey(); + for(var colodId:colorIds) + { + if(resId==colodId) + { + binValue.data=color; + break; } } } } } } + } - return q == colorIds.length; + private static boolean isColorResourceValue(BinaryResourceValue value) + { + return value.type==BinaryResourceValue.Type.INT_COLOR_ARGB8 + ||value.type==BinaryResourceValue.Type.INT_COLOR_RGB8 + ||value.type==BinaryResourceValue.Type.INT_COLOR_ARGB4 + ||value.type==BinaryResourceValue.Type.INT_COLOR_RGB4; } }