LayoutLib: update with Pair API.

Change-Id: Iba945153f7544872ea84e3311584223aea740e2e
diff --git a/tools/layoutlib/bridge/.classpath b/tools/layoutlib/bridge/.classpath
index 64c1fb5..2eaf8e3 100644
--- a/tools/layoutlib/bridge/.classpath
+++ b/tools/layoutlib/bridge/.classpath
@@ -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>
diff --git a/tools/layoutlib/bridge/Android.mk b/tools/layoutlib/bridge/Android.mk
index 57dd7ae..3d4c76a 100644
--- a/tools/layoutlib/bridge/Android.mk
+++ b/tools/layoutlib/bridge/Android.mk
@@ -21,7 +21,7 @@
 LOCAL_JAVA_LIBRARIES := \
 	kxml2-2.3.0 \
 	layoutlib_api-prebuilt \
-	resources-prebuilt
+	common-prebuilt
 
 LOCAL_STATIC_JAVA_LIBRARIES := \
 	temp_layoutlib \
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 0ed4305..93c81d1 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -31,6 +31,7 @@
 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;
@@ -42,6 +43,7 @@
 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;
@@ -69,9 +71,11 @@
     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.
      */
@@ -80,8 +84,8 @@
      * 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>>>();
@@ -131,7 +135,7 @@
         }
     }
 
-    /** 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();
 
     /**
@@ -237,28 +241,30 @@
             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);
 
-                Map<String, Integer> fullMap = new HashMap<String, Integer>();
-                sRFullMap.put(resType, fullMap);
-
-                for (Field f : inner.getDeclaredFields()) {
-                    // only process static final fields. Since the final attribute may have
-                    // been altered by layoutlib_create, we only check static
-                    int modifiers = f.getModifiers();
-                    if (Modifier.isStatic(modifiers)) {
-                        Class<?> type = f.getType();
-                        if (type.isArray() && type.getComponentType() == int.class) {
-                            // if the object is an int[] we put it in sRArrayMap using an IntArray
-                            // wrapper that properly implements equals and hashcode for the array
-                            // objects, as required by the map contract.
-                            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 });
-                            fullMap.put(f.getName(), value);
-                        } else {
-                            assert false;
+                    for (Field f : inner.getDeclaredFields()) {
+                        // only process static final fields. Since the final attribute may have
+                        // been altered by layoutlib_create, we only check static
+                        int modifiers = f.getModifiers();
+                        if (Modifier.isStatic(modifiers)) {
+                            Class<?> type = f.getType();
+                            if (type.isArray() && type.getComponentType() == int.class) {
+                                // if the object is an int[] we put it in sRArrayMap using an IntArray
+                                // wrapper that properly implements equals and hashcode for the array
+                                // objects, as required by the map contract.
+                                sRArrayMap.put(new IntArray((int[]) f.get(null)), f.getName());
+                            } else if (type == int.class) {
+                                Integer value = (Integer) f.get(null);
+                                sRMap.put(value, Pair.of(resType, f.getName()));
+                                fullMap.put(f.getName(), value);
+                            } else {
+                                assert false;
+                            }
                         }
                     }
                 }
@@ -389,10 +395,10 @@
     /**
      * 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
-     * does not match any resource.
+     * @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);
     }
 
@@ -400,7 +406,7 @@
      * 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);
     }
@@ -411,9 +417,8 @@
      * @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);
         }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index abea8c70..037ad23 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -25,6 +25,7 @@
 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;
@@ -518,14 +519,14 @@
      */
     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);
@@ -541,13 +542,13 @@
 
         // 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);
@@ -572,14 +573,14 @@
      *         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;
@@ -616,7 +617,7 @@
     }
 
     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();
         }
@@ -626,7 +627,7 @@
 
     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();
             }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
index edc92c2..5740e8b 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
@@ -22,6 +22,7 @@
 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;
@@ -155,16 +156,16 @@
 
             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());
                 }
             }
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
index e71bbb23..5ea0a8df 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
@@ -23,6 +23,7 @@
 import com.android.layoutlib.bridge.BridgeConstants;
 import com.android.layoutlib.bridge.impl.ResourceHelper;
 import com.android.resources.ResourceType;
+import com.android.util.Pair;
 
 import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
@@ -101,32 +102,22 @@
 
     private ResourceValue getResourceValue(int id, boolean[] platformResFlag_out) {
         // first get the String related to this id in the framework
-        String[] resourceInfo = Bridge.resolveResourceValue(id);
+        Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(id);
 
         if (resourceInfo != null) {
-            ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
-            if (resType == null) {
-                return null;
-            }
-
             platformResFlag_out[0] = true;
             return mContext.getRenderResources().getFrameworkResource(
-                    resType, resourceInfo[0]);
+                    resourceInfo.getFirst(), resourceInfo.getSecond());
         }
 
         // didn't find a match in the framework? look in the project.
         if (mProjectCallback != null) {
-            resourceInfo = mProjectCallback.resolveResourceValue(id);
+            resourceInfo = mProjectCallback.resolveResourceId(id);
 
             if (resourceInfo != null) {
-                ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
-                if (resType == null) {
-                    return null;
-                }
-
                 platformResFlag_out[0] = false;
                 return mContext.getRenderResources().getProjectResource(
-                        resType, resourceInfo[0]);
+                        resourceInfo.getFirst(), resourceInfo.getSecond());
             }
         }
 
@@ -625,18 +616,18 @@
      */
     private void throwException(int id) throws NotFoundException {
         // first get the String related to this id in the framework
-        String[] resourceInfo = Bridge.resolveResourceValue(id);
+        Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(id);
 
         // if the name is unknown in the framework, get it from the custom view loader.
         if (resourceInfo == null && mProjectCallback != null) {
-            resourceInfo = mProjectCallback.resolveResourceValue(id);
+            resourceInfo = mProjectCallback.resolveResourceId(id);
         }
 
         String message = null;
         if (resourceInfo != null) {
             message = String.format(
                     "Could not find %1$s resource matching value 0x%2$X (resolved name: %3$s) in current configuration.",
-                    resourceInfo[1], id, resourceInfo[0]);
+                    resourceInfo.getFirst(), id, resourceInfo.getSecond());
         } else {
             message = String.format(
                     "Could not resolve resource value: 0x%1$X.", id);
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
index 2b48539..cf2c0ff 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
@@ -589,7 +589,7 @@
         // then the xml attribute value was "resolved" which leads us to a ResourceValue with a
         // valid getType() and getName() returning a resource name.
         // (and getValue() returning null!). We need to handle this!
-        if (resValue.getResourceType() != null && resValue.getType().startsWith("@+") == false) {
+        if (resValue.getResourceType() != null) {
             // if this is a framework id
             if (mPlatformFile || resValue.isFramework()) {
                 // look for idName in the android R classes
@@ -647,10 +647,10 @@
         Integer idValue = null;
 
         if (resValue.isFramework()) {
-            idValue = Bridge.getResourceValue(resValue.getResourceType(),
+            idValue = Bridge.getResourceId(resValue.getResourceType(),
                     resValue.getName());
         } else {
-            idValue = mContext.getProjectCallback().getResourceValue(
+            idValue = mContext.getProjectCallback().getResourceId(
                     resValue.getResourceType(), resValue.getName());
         }
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java
index f39961e..ba856e0 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java
@@ -59,7 +59,7 @@
         String ns = mParser.getAttributeNamespace(index);
 
         if (BridgeConstants.NS_RESOURCES.equals(ns)) {
-            Integer v = Bridge.getResourceValue(ResourceType.ATTR, name);
+            Integer v = Bridge.getResourceId(ResourceType.ATTR, name);
             if (v != null) {
                 return v.intValue();
             }
@@ -70,8 +70,7 @@
         // this is not an attribute in the android namespace, we query the customviewloader, if
         // the namespaces match.
         if (mContext.getProjectCallback().getNamespace().equals(ns)) {
-            Integer v = mContext.getProjectCallback().getResourceValue(ResourceType.ATTR,
-                    name);
+            Integer v = mContext.getProjectCallback().getResourceId(ResourceType.ATTR, name);
             if (v != null) {
                 return v.intValue();
             }
@@ -111,9 +110,9 @@
         if (resource != null) {
             Integer id = null;
             if (mPlatformFile || resource.isFramework()) {
-                id = Bridge.getResourceValue(resource.getResourceType(), resource.getName());
+                id = Bridge.getResourceId(resource.getResourceType(), resource.getName());
             } else {
-                id = mContext.getProjectCallback().getResourceValue(
+                id = mContext.getProjectCallback().getResourceId(
                         resource.getResourceType(), resource.getName());
             }
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 19251f9..d816d18 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -50,6 +50,7 @@
 import com.android.resources.Density;
 import com.android.resources.ResourceType;
 import com.android.resources.ScreenSize;
+import com.android.util.Pair;
 
 import android.animation.Animator;
 import android.animation.AnimatorInflater;
@@ -569,13 +570,13 @@
             animationResource = mContext.getRenderResources().getFrameworkResource(
                     ResourceType.ANIMATOR, animationName);
             if (animationResource != null) {
-                animationId = Bridge.getResourceValue(ResourceType.ANIMATOR, animationName);
+                animationId = Bridge.getResourceId(ResourceType.ANIMATOR, animationName);
             }
         } else {
             animationResource = mContext.getRenderResources().getProjectResource(
                     ResourceType.ANIMATOR, animationName);
             if (animationResource != null) {
-                animationId = mContext.getProjectCallback().getResourceValue(
+                animationId = mContext.getProjectCallback().getResourceId(
                         ResourceType.ANIMATOR, animationName);
             }
         }
@@ -1227,10 +1228,10 @@
                 View child = content.getChildAt(i);
                 String tabSpec = String.format("tab_spec%d", i+1);
                 int id = child.getId();
-                String[] resource = projectCallback.resolveResourceValue(id);
+                Pair<ResourceType, String> resource = projectCallback.resolveResourceId(id);
                 String name;
                 if (resource != null) {
-                    name = resource[0]; // 0 is resource name, 1 is resource type.
+                    name = resource.getSecond();
                 } else {
                     name = String.format("Tab %d", i+1); // default name if id is unresolved.
                 }
@@ -1310,6 +1311,6 @@
 
     @Override
     public Integer getId(ResourceType resType, String resName) {
-        return Bridge.getResourceValue(resType, resName);
+        return Bridge.getResourceId(resType, resName);
     }
 }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
index ae7a77f..25bb81c 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
@@ -197,7 +197,8 @@
                 } catch (Exception e) {
                     // this is an error and not warning since the file existence is checked before
                     // attempting to parse it.
-                    Bridge.getLog().error(null, "Failed to parse file " + value, e, null /*data*/);
+                    Bridge.getLog().error(null, "Failed to parse file " + stringValue,
+                            e, null /*data*/);
                 }
             } else {
                 Bridge.getLog().error(LayoutLog.TAG_BROKEN,