Skip to content

Commit 3c8e114

Browse files
committed
Override getColorStateList()
XResources claimed that this was handled by loadXmlResourceParser(), but in fact it wasn't handled by the variant that was overridden previously. Now it is handled. Possible replacements are ColorStateLists, integers (handled as color constants) and resource forwarders.
1 parent 2e60194 commit 3c8e114

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

src/android/content/res/XResources.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class XResources extends MiuiResources {
4141
private static final byte[] systemReplacementsCache = new byte[256]; // bitmask: 0x000700ff => 2048 bit => 256 bytes
4242
private byte[] replacementsCache; // bitmask: 0x0007007f => 1024 bit => 128 bytes
4343
private static final HashMap<String, byte[]> replacementsCacheMap = new HashMap<String, byte[]>();
44+
private static final SparseArray<ColorStateList> colorStateListCache = new SparseArray<ColorStateList>(0);
4445

4546
private static final SparseArray<HashMap<String, CopyOnWriteSortedSet<XC_LayoutInflated>>> layoutCallbacks
4647
= new SparseArray<HashMap<String, CopyOnWriteSortedSet<XC_LayoutInflated>>>();
@@ -392,6 +393,29 @@ public int getColor(int id) throws NotFoundException {
392393
return super.getColor(id);
393394
}
394395

396+
@Override
397+
public ColorStateList getColorStateList(int id) throws NotFoundException {
398+
Object replacement = getReplacement(id);
399+
if (replacement instanceof ColorStateList) {
400+
return (ColorStateList) replacement;
401+
} else if (replacement instanceof Integer) {
402+
int color = (Integer) replacement;
403+
synchronized (colorStateListCache) {
404+
ColorStateList result = colorStateListCache.get(color);
405+
if (result == null) {
406+
result = ColorStateList.valueOf(color);
407+
colorStateListCache.put(color, result);
408+
}
409+
return result;
410+
}
411+
} else if (replacement instanceof XResForwarder) {
412+
Resources repRes = ((XResForwarder) replacement).getResources();
413+
int repId = ((XResForwarder) replacement).getId();
414+
return repRes.getColorStateList(repId);
415+
}
416+
return super.getColorStateList(id);
417+
}
418+
395419
@Override
396420
public float getDimension(int id) throws NotFoundException {
397421
Object replacement = getReplacement(id);
@@ -816,6 +840,29 @@ public int getColor(int index, int defValue) {
816840
return super.getColor(index, defValue);
817841
}
818842

843+
@Override
844+
public ColorStateList getColorStateList(int index) {
845+
Object replacement = res.getReplacement(getResourceId(index, 0));
846+
if (replacement instanceof ColorStateList) {
847+
return (ColorStateList) replacement;
848+
} else if (replacement instanceof Integer) {
849+
int color = (Integer) replacement;
850+
synchronized (colorStateListCache) {
851+
ColorStateList result = colorStateListCache.get(color);
852+
if (result == null) {
853+
result = ColorStateList.valueOf(color);
854+
colorStateListCache.put(color, result);
855+
}
856+
return result;
857+
}
858+
} else if (replacement instanceof XResForwarder) {
859+
Resources repRes = ((XResForwarder) replacement).getResources();
860+
int repId = ((XResForwarder) replacement).getId();
861+
return repRes.getColorStateList(repId);
862+
}
863+
return super.getColorStateList(index);
864+
}
865+
819866
@Override
820867
public float getDimension(int index, float defValue) {
821868
Object replacement = res.getReplacement(getResourceId(index, 0));

0 commit comments

Comments
 (0)