diff options
author | Xavier Ducrohet <xav@android.com> | 2010-11-18 19:51:30 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-11-18 19:51:30 -0800 |
commit | 755b46d597b8e8a616d53e2a7dfea295dd78d713 (patch) | |
tree | fa3f05456069a08badfc9d845f4e20b7617311ab /tools | |
parent | 5a09488a158b669577cd8eb557ce4feb62929e75 (diff) | |
download | frameworks_base-755b46d597b8e8a616d53e2a7dfea295dd78d713.zip frameworks_base-755b46d597b8e8a616d53e2a7dfea295dd78d713.tar.gz frameworks_base-755b46d597b8e8a616d53e2a7dfea295dd78d713.tar.bz2 |
Layoutlib: use int[] wrapper to use as map keys.
This fixes the SlidingDrawer that failed to load.
For some reason, in case of the SlidingDrawer, when the constructor
uses android.R.styleable.SlidingDrawer it's the same values but not
the same instance as the array read from android.R through reflection.
So what works for all other widgets, and has worked since the very first
layoutlib isn't working anymore, and we'll now have to use a wrapper
similarly to what we use in ADT in the project callback.
We should probably provide a single int[] wrapper class in layoutlib
API for all to use.
Change-Id: I4d7d038540f8a24541a588696f1059a020b589e5
Diffstat (limited to 'tools')
-rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java index efa0f27..e691fdf 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java @@ -37,6 +37,7 @@ import android.util.Finalizers; import java.lang.ref.SoftReference; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -62,7 +63,7 @@ public final class Bridge extends LayoutBridge { /** * Same as sRMap except for int[] instead of int resources. This is for android.R only. */ - private final static Map<int[], String> sRArrayMap = new HashMap<int[], String>(); + private final static Map<IntArray, String> sRArrayMap = new HashMap<IntArray, String>(); /** * Reverse map compared to sRMap, resource type -> (resource name -> id). * This is for android.R only. @@ -83,6 +84,44 @@ public final class Bridge extends LayoutBridge { private static Map<String, Map<String, Integer>> sEnumValueMap; /** + * int[] wrapper to use as keys in maps. + */ + private final static class IntArray { + private int[] mArray; + + private IntArray() { + // do nothing + } + + private IntArray(int[] a) { + mArray = a; + } + + private void set(int[] a) { + mArray = a; + } + + @Override + public int hashCode() { + return Arrays.hashCode(mArray); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + + IntArray other = (IntArray) obj; + if (!Arrays.equals(mArray, other.mArray)) return false; + return true; + } + } + + /** Instance of IntArrayWrapper to be reused in {@link #resolveResourceValue(int[])}. */ + private final static IntArray sIntArrayWrapper = new IntArray(); + + /** * A default logger than prints to stdout/stderr. */ private final static ILayoutLog sDefaultLogger = new ILayoutLog() { @@ -183,7 +222,7 @@ public final class Bridge extends LayoutBridge { Class<?> type = f.getType(); if (type.isArray() && type.getComponentType() == int.class) { // if the object is an int[] we put it in sRArrayMap - sRArrayMap.put((int[]) f.get(null), f.getName()); + sRArrayMap.put(new IntArray((int[]) f.get(null)), f.getName()); } else if (type == int.class) { Integer value = (Integer) f.get(null); sRMap.put(value, new String[] { f.getName(), resType }); @@ -319,7 +358,8 @@ public final class Bridge extends LayoutBridge { * @param array */ public static String resolveResourceValue(int[] array) { - return sRArrayMap.get(array); + sIntArrayWrapper.set(array); + return sRArrayMap.get(sIntArrayWrapper); } /** |