Loading tools/layoutlib/bridge/.classpath +1 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,6 @@ <classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/kxml2/kxml2-2.3.0.jar" sourcepath="/ANDROID_PLAT_SRC/dalvik/libcore/xml/src/main/java"/> <classpathentry kind="var" path="ANDROID_PLAT_SRC/out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar" sourcepath="/ANDROID_PLAT_SRC/frameworks/base"/> <classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/ninepatch/ninepatch-prebuilt.jar"/> <classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/resources/resources-prebuilt.jar"/> <classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/common/common-prebuilt.jar"/> <classpathentry kind="output" path="bin"/> </classpath> tools/layoutlib/bridge/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under,src) LOCAL_JAVA_LIBRARIES := \ kxml2-2.3.0 \ layoutlib_api-prebuilt \ resources-prebuilt common-prebuilt LOCAL_STATIC_JAVA_LIBRARIES := \ temp_layoutlib \ Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +39 −34 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import com.android.ninepatch.NinePatchChunk; import com.android.resources.ResourceType; import com.android.tools.layoutlib.create.MethodAdapter; import com.android.tools.layoutlib.create.OverrideMethod; import com.android.util.Pair; import android.graphics.Bitmap; import android.graphics.Typeface; Loading @@ -42,6 +43,7 @@ import java.lang.ref.SoftReference; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.EnumMap; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; Loading Loading @@ -69,9 +71,11 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { private final static ReentrantLock sLock = new ReentrantLock(); /** * Maps from id to resource name/type. This is for android.R only. * Maps from id to resource type/name. This is for android.R only. */ private final static Map<Integer, String[]> sRMap = new HashMap<Integer, String[]>(); private final static Map<Integer, Pair<ResourceType, String>> sRMap = new HashMap<Integer, Pair<ResourceType, String>>(); /** * Same as sRMap except for int[] instead of int resources. This is for android.R only. */ Loading @@ -80,8 +84,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { * Reverse map compared to sRMap, resource type -> (resource name -> id). * This is for android.R only. */ private final static Map<String, Map<String, Integer>> sRFullMap = new HashMap<String, Map<String,Integer>>(); private final static Map<ResourceType, Map<String, Integer>> sRFullMap = new EnumMap<ResourceType, Map<String,Integer>>(ResourceType.class); private final static Map<Object, Map<String, SoftReference<Bitmap>>> sProjectBitmapCache = new HashMap<Object, Map<String, SoftReference<Bitmap>>>(); Loading Loading @@ -131,7 +135,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { } } /** Instance of IntArrayWrapper to be reused in {@link #resolveResourceValue(int[])}. */ /** Instance of IntArrayWrapper to be reused in {@link #resolveResourceId(int[])}. */ private final static IntArray sIntArrayWrapper = new IntArray(); /** Loading Loading @@ -237,8 +241,9 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { Class<?> r = com.android.internal.R.class; for (Class<?> inner : r.getDeclaredClasses()) { String resType = inner.getSimpleName(); String resTypeName = inner.getSimpleName(); ResourceType resType = ResourceType.getEnum(resTypeName); if (resType != null) { Map<String, Integer> fullMap = new HashMap<String, Integer>(); sRFullMap.put(resType, fullMap); Loading @@ -255,7 +260,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { 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 }); sRMap.put(value, Pair.of(resType, f.getName())); fullMap.put(f.getName(), value); } else { assert false; Loading @@ -263,6 +268,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { } } } } } catch (Throwable throwable) { if (log != null) { log.error(LayoutLog.TAG_BROKEN, Loading Loading @@ -389,10 +395,10 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { /** * Returns details of a framework resource from its integer value. * @param value the integer value * @return an array of 2 strings containing the resource name and type, or null if the id * @return a Pair containing the resource type and name, or null if the id * does not match any resource. */ public static String[] resolveResourceValue(int value) { public static Pair<ResourceType, String> resolveResourceId(int value) { return sRMap.get(value); } Loading @@ -400,7 +406,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { * Returns the name of a framework resource whose value is an int array. * @param array */ public static String resolveResourceValue(int[] array) { public static String resolveResourceId(int[] array) { sIntArrayWrapper.set(array); return sRArrayMap.get(sIntArrayWrapper); } Loading @@ -411,9 +417,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { * @param name the name of the resource. * @return an {@link Integer} containing the resource id, or null if no resource were found. */ public static Integer getResourceValue(ResourceType type, String name) { String typeString = type.getName(); Map<String, Integer> map = sRFullMap.get(typeString); public static Integer getResourceId(ResourceType type, String name) { Map<String, Integer> map = sRFullMap.get(type); if (map != null) { return map.get(name); } Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +13 −12 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.impl.Stack; import com.android.resources.ResourceType; import com.android.util.Pair; import android.app.Activity; import android.app.Fragment; Loading Loading @@ -518,14 +519,14 @@ public final class BridgeContext extends Activity { */ private TreeMap<Integer,String> searchAttrs(int[] attrs, boolean[] outFrameworkFlag) { // get the name of the array from the framework resources String arrayName = Bridge.resolveResourceValue(attrs); String arrayName = Bridge.resolveResourceId(attrs); if (arrayName != null) { // if we found it, get the name of each of the int in the array. TreeMap<Integer,String> attributes = new TreeMap<Integer, String>(); for (int i = 0 ; i < attrs.length ; i++) { String[] info = Bridge.resolveResourceValue(attrs[i]); Pair<ResourceType, String> info = Bridge.resolveResourceId(attrs[i]); if (info != null) { attributes.put(i, info[0]); attributes.put(i, info.getSecond()); } else { // FIXME Not sure what we should be doing here... attributes.put(i, null); Loading @@ -541,13 +542,13 @@ public final class BridgeContext extends Activity { // if the name was not found in the framework resources, look in the project // resources arrayName = mProjectCallback.resolveResourceValue(attrs); arrayName = mProjectCallback.resolveResourceId(attrs); if (arrayName != null) { TreeMap<Integer,String> attributes = new TreeMap<Integer, String>(); for (int i = 0 ; i < attrs.length ; i++) { String[] info = mProjectCallback.resolveResourceValue(attrs[i]); Pair<ResourceType, String> info = mProjectCallback.resolveResourceId(attrs[i]); if (info != null) { attributes.put(i, info[0]); attributes.put(i, info.getSecond()); } else { // FIXME Not sure what we should be doing here... attributes.put(i, null); Loading @@ -572,14 +573,14 @@ public final class BridgeContext extends Activity { * if nothing is found. */ public String searchAttr(int attr) { String[] info = Bridge.resolveResourceValue(attr); Pair<ResourceType, String> info = Bridge.resolveResourceId(attr); if (info != null) { return info[0]; return info.getSecond(); } info = mProjectCallback.resolveResourceValue(attr); info = mProjectCallback.resolveResourceId(attr); if (info != null) { return info[0]; return info.getSecond(); } return null; Loading Loading @@ -616,7 +617,7 @@ public final class BridgeContext extends Activity { } int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) { Integer value = Bridge.getResourceValue(resType, resName); Integer value = Bridge.getResourceId(resType, resName); if (value != null) { return value.intValue(); } Loading @@ -626,7 +627,7 @@ public final class BridgeContext extends Activity { int getProjectResourceValue(ResourceType resType, String resName, int defValue) { if (mProjectCallback != null) { Integer value = mProjectCallback.getResourceValue(resType, resName); Integer value = mProjectCallback.getResourceId(resType, resName); if (value != null) { return value.intValue(); } Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java +5 −4 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.ide.common.rendering.api.MergeCookie; import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.resources.ResourceType; import com.android.util.Pair; import org.kxml2.io.KXmlParser; import org.xmlpull.v1.XmlPullParser; Loading Loading @@ -155,16 +156,16 @@ public final class BridgeInflater extends LayoutInflater { ResourceValue value = null; String[] layoutInfo = Bridge.resolveResourceValue(resource); Pair<ResourceType, String> layoutInfo = Bridge.resolveResourceId(resource); if (layoutInfo != null) { value = bridgeContext.getRenderResources().getFrameworkResource( ResourceType.LAYOUT, layoutInfo[0]); ResourceType.LAYOUT, layoutInfo.getSecond()); } else { layoutInfo = mProjectCallback.resolveResourceValue(resource); layoutInfo = mProjectCallback.resolveResourceId(resource); if (layoutInfo != null) { value = bridgeContext.getRenderResources().getProjectResource( ResourceType.LAYOUT, layoutInfo[0]); ResourceType.LAYOUT, layoutInfo.getSecond()); } } Loading Loading
tools/layoutlib/bridge/.classpath +1 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,6 @@ <classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/kxml2/kxml2-2.3.0.jar" sourcepath="/ANDROID_PLAT_SRC/dalvik/libcore/xml/src/main/java"/> <classpathentry kind="var" path="ANDROID_PLAT_SRC/out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar" sourcepath="/ANDROID_PLAT_SRC/frameworks/base"/> <classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/ninepatch/ninepatch-prebuilt.jar"/> <classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/resources/resources-prebuilt.jar"/> <classpathentry kind="var" path="ANDROID_PLAT_SRC/prebuilt/common/common/common-prebuilt.jar"/> <classpathentry kind="output" path="bin"/> </classpath>
tools/layoutlib/bridge/Android.mk +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under,src) LOCAL_JAVA_LIBRARIES := \ kxml2-2.3.0 \ layoutlib_api-prebuilt \ resources-prebuilt common-prebuilt LOCAL_STATIC_JAVA_LIBRARIES := \ temp_layoutlib \ Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +39 −34 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import com.android.ninepatch.NinePatchChunk; import com.android.resources.ResourceType; import com.android.tools.layoutlib.create.MethodAdapter; import com.android.tools.layoutlib.create.OverrideMethod; import com.android.util.Pair; import android.graphics.Bitmap; import android.graphics.Typeface; Loading @@ -42,6 +43,7 @@ import java.lang.ref.SoftReference; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.EnumMap; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; Loading Loading @@ -69,9 +71,11 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { private final static ReentrantLock sLock = new ReentrantLock(); /** * Maps from id to resource name/type. This is for android.R only. * Maps from id to resource type/name. This is for android.R only. */ private final static Map<Integer, String[]> sRMap = new HashMap<Integer, String[]>(); private final static Map<Integer, Pair<ResourceType, String>> sRMap = new HashMap<Integer, Pair<ResourceType, String>>(); /** * Same as sRMap except for int[] instead of int resources. This is for android.R only. */ Loading @@ -80,8 +84,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { * Reverse map compared to sRMap, resource type -> (resource name -> id). * This is for android.R only. */ private final static Map<String, Map<String, Integer>> sRFullMap = new HashMap<String, Map<String,Integer>>(); private final static Map<ResourceType, Map<String, Integer>> sRFullMap = new EnumMap<ResourceType, Map<String,Integer>>(ResourceType.class); private final static Map<Object, Map<String, SoftReference<Bitmap>>> sProjectBitmapCache = new HashMap<Object, Map<String, SoftReference<Bitmap>>>(); Loading Loading @@ -131,7 +135,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { } } /** Instance of IntArrayWrapper to be reused in {@link #resolveResourceValue(int[])}. */ /** Instance of IntArrayWrapper to be reused in {@link #resolveResourceId(int[])}. */ private final static IntArray sIntArrayWrapper = new IntArray(); /** Loading Loading @@ -237,8 +241,9 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { Class<?> r = com.android.internal.R.class; for (Class<?> inner : r.getDeclaredClasses()) { String resType = inner.getSimpleName(); String resTypeName = inner.getSimpleName(); ResourceType resType = ResourceType.getEnum(resTypeName); if (resType != null) { Map<String, Integer> fullMap = new HashMap<String, Integer>(); sRFullMap.put(resType, fullMap); Loading @@ -255,7 +260,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { 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 }); sRMap.put(value, Pair.of(resType, f.getName())); fullMap.put(f.getName(), value); } else { assert false; Loading @@ -263,6 +268,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { } } } } } catch (Throwable throwable) { if (log != null) { log.error(LayoutLog.TAG_BROKEN, Loading Loading @@ -389,10 +395,10 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { /** * Returns details of a framework resource from its integer value. * @param value the integer value * @return an array of 2 strings containing the resource name and type, or null if the id * @return a Pair containing the resource type and name, or null if the id * does not match any resource. */ public static String[] resolveResourceValue(int value) { public static Pair<ResourceType, String> resolveResourceId(int value) { return sRMap.get(value); } Loading @@ -400,7 +406,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { * Returns the name of a framework resource whose value is an int array. * @param array */ public static String resolveResourceValue(int[] array) { public static String resolveResourceId(int[] array) { sIntArrayWrapper.set(array); return sRArrayMap.get(sIntArrayWrapper); } Loading @@ -411,9 +417,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { * @param name the name of the resource. * @return an {@link Integer} containing the resource id, or null if no resource were found. */ public static Integer getResourceValue(ResourceType type, String name) { String typeString = type.getName(); Map<String, Integer> map = sRFullMap.get(typeString); public static Integer getResourceId(ResourceType type, String name) { Map<String, Integer> map = sRFullMap.get(type); if (map != null) { return map.get(name); } Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +13 −12 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.impl.Stack; import com.android.resources.ResourceType; import com.android.util.Pair; import android.app.Activity; import android.app.Fragment; Loading Loading @@ -518,14 +519,14 @@ public final class BridgeContext extends Activity { */ private TreeMap<Integer,String> searchAttrs(int[] attrs, boolean[] outFrameworkFlag) { // get the name of the array from the framework resources String arrayName = Bridge.resolveResourceValue(attrs); String arrayName = Bridge.resolveResourceId(attrs); if (arrayName != null) { // if we found it, get the name of each of the int in the array. TreeMap<Integer,String> attributes = new TreeMap<Integer, String>(); for (int i = 0 ; i < attrs.length ; i++) { String[] info = Bridge.resolveResourceValue(attrs[i]); Pair<ResourceType, String> info = Bridge.resolveResourceId(attrs[i]); if (info != null) { attributes.put(i, info[0]); attributes.put(i, info.getSecond()); } else { // FIXME Not sure what we should be doing here... attributes.put(i, null); Loading @@ -541,13 +542,13 @@ public final class BridgeContext extends Activity { // if the name was not found in the framework resources, look in the project // resources arrayName = mProjectCallback.resolveResourceValue(attrs); arrayName = mProjectCallback.resolveResourceId(attrs); if (arrayName != null) { TreeMap<Integer,String> attributes = new TreeMap<Integer, String>(); for (int i = 0 ; i < attrs.length ; i++) { String[] info = mProjectCallback.resolveResourceValue(attrs[i]); Pair<ResourceType, String> info = mProjectCallback.resolveResourceId(attrs[i]); if (info != null) { attributes.put(i, info[0]); attributes.put(i, info.getSecond()); } else { // FIXME Not sure what we should be doing here... attributes.put(i, null); Loading @@ -572,14 +573,14 @@ public final class BridgeContext extends Activity { * if nothing is found. */ public String searchAttr(int attr) { String[] info = Bridge.resolveResourceValue(attr); Pair<ResourceType, String> info = Bridge.resolveResourceId(attr); if (info != null) { return info[0]; return info.getSecond(); } info = mProjectCallback.resolveResourceValue(attr); info = mProjectCallback.resolveResourceId(attr); if (info != null) { return info[0]; return info.getSecond(); } return null; Loading Loading @@ -616,7 +617,7 @@ public final class BridgeContext extends Activity { } int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) { Integer value = Bridge.getResourceValue(resType, resName); Integer value = Bridge.getResourceId(resType, resName); if (value != null) { return value.intValue(); } Loading @@ -626,7 +627,7 @@ public final class BridgeContext extends Activity { int getProjectResourceValue(ResourceType resType, String resName, int defValue) { if (mProjectCallback != null) { Integer value = mProjectCallback.getResourceValue(resType, resName); Integer value = mProjectCallback.getResourceId(resType, resName); if (value != null) { return value.intValue(); } Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java +5 −4 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import com.android.ide.common.rendering.api.MergeCookie; import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.resources.ResourceType; import com.android.util.Pair; import org.kxml2.io.KXmlParser; import org.xmlpull.v1.XmlPullParser; Loading Loading @@ -155,16 +156,16 @@ public final class BridgeInflater extends LayoutInflater { ResourceValue value = null; String[] layoutInfo = Bridge.resolveResourceValue(resource); Pair<ResourceType, String> layoutInfo = Bridge.resolveResourceId(resource); if (layoutInfo != null) { value = bridgeContext.getRenderResources().getFrameworkResource( ResourceType.LAYOUT, layoutInfo[0]); ResourceType.LAYOUT, layoutInfo.getSecond()); } else { layoutInfo = mProjectCallback.resolveResourceValue(resource); layoutInfo = mProjectCallback.resolveResourceId(resource); if (layoutInfo != null) { value = bridgeContext.getRenderResources().getProjectResource( ResourceType.LAYOUT, layoutInfo[0]); ResourceType.LAYOUT, layoutInfo.getSecond()); } } Loading