OSDN Git Service

LayoutLib: Update with the new resource map APIs.
authorXavier Ducrohet <xav@android.com>
Fri, 28 Jan 2011 19:44:21 +0000 (11:44 -0800)
committerXavier Ducrohet <xav@android.com>
Fri, 28 Jan 2011 19:44:21 +0000 (11:44 -0800)
Change-Id: I30d83c2bb4569513f4f5e22670cffe938706f105

tools/layoutlib/bridge/src/android/graphics/Gradient_Delegate.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/FontLoader.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java

index 7a0c2f7..38c092d 100644 (file)
@@ -95,7 +95,7 @@ public abstract class Gradient_Delegate extends Shader_Delegate {
          * Pre-computes the colors for the gradient. This must be called once before any call
          * to {@link #getGradientColor(float)}
          */
-        protected synchronized void precomputeGradientColors() {
+        protected void precomputeGradientColors() {
             if (mGradient == null) {
                 // actually create an array with an extra size, so that we can really go
                 // from 0 to SIZE (100%), or currentPos in the loop below will never equal 1.0
index bd52dc2..0ed4305 100644 (file)
@@ -28,6 +28,7 @@ import com.android.layoutlib.bridge.android.BridgeAssetManager;
 import com.android.layoutlib.bridge.impl.FontLoader;
 import com.android.layoutlib.bridge.impl.RenderSessionImpl;
 import com.android.ninepatch.NinePatchChunk;
+import com.android.resources.ResourceType;
 import com.android.tools.layoutlib.create.MethodAdapter;
 import com.android.tools.layoutlib.create.OverrideMethod;
 
@@ -410,8 +411,9 @@ 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(String type, String name) {
-        Map<String, Integer> map = sRFullMap.get(type);
+    public static Integer getResourceValue(ResourceType type, String name) {
+        String typeString = type.getName();
+        Map<String, Integer> map = sRFullMap.get(typeString);
         if (map != null) {
             return map.get(name);
         }
index 79264d0..abea8c7 100644 (file)
@@ -24,6 +24,7 @@ import com.android.ide.common.rendering.api.StyleResourceValue;
 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 android.app.Activity;
 import android.app.Fragment;
@@ -614,7 +615,7 @@ public final class BridgeContext extends Activity {
         return null;
     }
 
-    int getFrameworkResourceValue(String resType, String resName, int defValue) {
+    int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) {
         Integer value = Bridge.getResourceValue(resType, resName);
         if (value != null) {
             return value.intValue();
@@ -623,7 +624,7 @@ public final class BridgeContext extends Activity {
         return defValue;
     }
 
-    int getProjectResourceValue(String resType, String resName, int defValue) {
+    int getProjectResourceValue(ResourceType resType, String resName, int defValue) {
         if (mProjectCallback != null) {
             Integer value = mProjectCallback.getResourceValue(resType, resName);
             if (value != null) {
index 465bf1d..edc92c2 100644 (file)
@@ -19,9 +19,9 @@ package com.android.layoutlib.bridge.android;
 import com.android.ide.common.rendering.api.IProjectCallback;
 import com.android.ide.common.rendering.api.LayoutLog;
 import com.android.ide.common.rendering.api.MergeCookie;
-import com.android.ide.common.rendering.api.RenderResources;
 import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.layoutlib.bridge.Bridge;
+import com.android.resources.ResourceType;
 
 import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
@@ -158,13 +158,13 @@ public final class BridgeInflater extends LayoutInflater {
             String[] layoutInfo = Bridge.resolveResourceValue(resource);
             if (layoutInfo != null) {
                 value = bridgeContext.getRenderResources().getFrameworkResource(
-                        RenderResources.RES_LAYOUT, layoutInfo[0]);
+                        ResourceType.LAYOUT, layoutInfo[0]);
             } else {
                 layoutInfo = mProjectCallback.resolveResourceValue(resource);
 
                 if (layoutInfo != null) {
                     value = bridgeContext.getRenderResources().getProjectResource(
-                            RenderResources.RES_LAYOUT, layoutInfo[0]);
+                            ResourceType.LAYOUT, layoutInfo[0]);
                 }
             }
 
index 7b66809..e71bbb2 100644 (file)
@@ -22,6 +22,7 @@ import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
 import com.android.layoutlib.bridge.impl.ResourceHelper;
+import com.android.resources.ResourceType;
 
 import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
@@ -103,9 +104,14 @@ public final class BridgeResources extends Resources {
         String[] resourceInfo = Bridge.resolveResourceValue(id);
 
         if (resourceInfo != null) {
+            ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
+            if (resType == null) {
+                return null;
+            }
+
             platformResFlag_out[0] = true;
             return mContext.getRenderResources().getFrameworkResource(
-                    resourceInfo[1], resourceInfo[0]);
+                    resType, resourceInfo[0]);
         }
 
         // didn't find a match in the framework? look in the project.
@@ -113,9 +119,14 @@ public final class BridgeResources extends Resources {
             resourceInfo = mProjectCallback.resolveResourceValue(id);
 
             if (resourceInfo != null) {
+                ResourceType resType = ResourceType.getEnum(resourceInfo[1]);
+                if (resType == null) {
+                    return null;
+                }
+
                 platformResFlag_out[0] = false;
                 return mContext.getRenderResources().getProjectResource(
-                        resourceInfo[1], resourceInfo[0]);
+                        resType, resourceInfo[0]);
             }
         }
 
index 8d3c929..2b48539 100644 (file)
@@ -24,6 +24,7 @@ import com.android.internal.util.XmlUtils;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
 import com.android.layoutlib.bridge.impl.ResourceHelper;
+import com.android.resources.ResourceType;
 
 import org.kxml2.io.KXmlParser;
 import org.xmlpull.v1.XmlPullParser;
@@ -39,6 +40,7 @@ import android.view.ViewGroup.LayoutParams;
 
 import java.io.File;
 import java.io.FileReader;
+import java.util.Arrays;
 import java.util.Map;
 
 /**
@@ -587,17 +589,17 @@ public final class BridgeTypedArray extends TypedArray {
         // 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.getType() != null && resValue.getType().startsWith("@+") == false) {
+        if (resValue.getResourceType() != null && resValue.getType().startsWith("@+") == false) {
             // if this is a framework id
             if (mPlatformFile || resValue.isFramework()) {
                 // look for idName in the android R classes
                 return mContext.getFrameworkResourceValue(
-                        resValue.getType(), resValue.getName(), defValue);
+                        resValue.getResourceType(), resValue.getName(), defValue);
             }
 
             // look for idName in the project R class.
             return mContext.getProjectResourceValue(
-                    resValue.getType(), resValue.getName(), defValue);
+                    resValue.getResourceType(), resValue.getName(), defValue);
         }
 
         // else, try to get the value, and resolve it somehow.
@@ -634,21 +636,22 @@ public final class BridgeTypedArray extends TypedArray {
             // if this is a framework id
             if (mPlatformFile || value.startsWith("@android") || value.startsWith("@+android")) {
                 // look for idName in the android R classes
-                return mContext.getFrameworkResourceValue(RenderResources.RES_ID, idName, defValue);
+                return mContext.getFrameworkResourceValue(ResourceType.ID, idName, defValue);
             }
 
             // look for idName in the project R class.
-            return mContext.getProjectResourceValue(RenderResources.RES_ID, idName, defValue);
+            return mContext.getProjectResourceValue(ResourceType.ID, idName, defValue);
         }
 
         // not a direct id valid reference? resolve it
         Integer idValue = null;
 
         if (resValue.isFramework()) {
-            idValue = Bridge.getResourceValue(resValue.getType(), resValue.getName());
+            idValue = Bridge.getResourceValue(resValue.getResourceType(),
+                    resValue.getName());
         } else {
             idValue = mContext.getProjectCallback().getResourceValue(
-                    resValue.getType(), resValue.getName());
+                    resValue.getResourceType(), resValue.getName());
         }
 
         if (idValue != null) {
@@ -796,6 +799,6 @@ public final class BridgeTypedArray extends TypedArray {
 
     @Override
     public String toString() {
-        return mResourceData.toString();
+        return Arrays.toString(mResourceData);
     }
  }
index 4a6880b..f39961e 100644 (file)
@@ -20,6 +20,7 @@ import com.android.ide.common.rendering.api.RenderResources;
 import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
+import com.android.resources.ResourceType;
 
 import org.xmlpull.v1.XmlPullParser;
 
@@ -58,7 +59,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
         String ns = mParser.getAttributeNamespace(index);
 
         if (BridgeConstants.NS_RESOURCES.equals(ns)) {
-            Integer v = Bridge.getResourceValue(RenderResources.RES_ATTR, name);
+            Integer v = Bridge.getResourceValue(ResourceType.ATTR, name);
             if (v != null) {
                 return v.intValue();
             }
@@ -69,7 +70,7 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
         // 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(RenderResources.RES_ATTR,
+            Integer v = mContext.getProjectCallback().getResourceValue(ResourceType.ATTR,
                     name);
             if (v != null) {
                 return v.intValue();
@@ -110,10 +111,10 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes {
         if (resource != null) {
             Integer id = null;
             if (mPlatformFile || resource.isFramework()) {
-                id = Bridge.getResourceValue(resource.getType(), resource.getName());
+                id = Bridge.getResourceValue(resource.getResourceType(), resource.getName());
             } else {
                 id = mContext.getProjectCallback().getResourceValue(
-                        resource.getType(), resource.getName());
+                        resource.getResourceType(), resource.getName());
             }
 
             if (id != null) {
index 5d56370..f62fad2 100644 (file)
@@ -163,7 +163,7 @@ public final class FontLoader {
             mTtfToFontMap.put(ttf, styleMap);
         }
 
-        Font f = styleMap.get(style);
+        Font f = styleMap.get(style[0]);
 
         if (f != null) {
             return f;
index 978832f..19251f9 100644 (file)
@@ -48,6 +48,7 @@ import com.android.layoutlib.bridge.android.BridgeWindow;
 import com.android.layoutlib.bridge.android.BridgeWindowSession;
 import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
 import com.android.resources.Density;
+import com.android.resources.ResourceType;
 import com.android.resources.ScreenSize;
 
 import android.animation.Animator;
@@ -566,17 +567,16 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
         int animationId = 0;
         if (isFrameworkAnimation) {
             animationResource = mContext.getRenderResources().getFrameworkResource(
-                    RenderResources.RES_ANIMATOR, animationName);
+                    ResourceType.ANIMATOR, animationName);
             if (animationResource != null) {
-                animationId = Bridge.getResourceValue(RenderResources.RES_ANIMATOR,
-                        animationName);
+                animationId = Bridge.getResourceValue(ResourceType.ANIMATOR, animationName);
             }
         } else {
             animationResource = mContext.getRenderResources().getProjectResource(
-                    RenderResources.RES_ANIMATOR, animationName);
+                    ResourceType.ANIMATOR, animationName);
             if (animationResource != null) {
                 animationId = mContext.getProjectCallback().getResourceValue(
-                        RenderResources.RES_ANIMATOR, animationName);
+                        ResourceType.ANIMATOR, animationName);
             }
         }
 
@@ -1022,7 +1022,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
                 mStatusBarSize = DEFAULT_STATUS_BAR_HEIGHT;
 
                 // get the real value
-                ResourceValue value = resources.getFrameworkResource(RenderResources.RES_DIMEN,
+                ResourceValue value = resources.getFrameworkResource(ResourceType.DIMEN,
                         "status_bar_height");
 
                 if (value != null) {
@@ -1110,7 +1110,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
             mSystemBarSize = 56; // ??
 
             // get the real value
-            ResourceValue value = resources.getFrameworkResource(RenderResources.RES_DIMEN,
+            ResourceValue value = resources.getFrameworkResource(ResourceType.DIMEN,
                     "status_bar_height");
 
             if (value != null) {
@@ -1309,7 +1309,7 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider {
     // --- FrameworkResourceIdProvider methods
 
     @Override
-    public Integer getId(String resType, String resName) {
+    public Integer getId(ResourceType resType, String resName) {
         return Bridge.getResourceValue(resType, resName);
     }
 }
index 119dfb1..ae7a77f 100644 (file)
@@ -298,7 +298,7 @@ public final class ResourceHelper {
      */
     public static boolean stringToFloat(String s, TypedValue outValue) {
         // remove the space before and after
-        s.trim();
+        s = s.trim();
         int len = s.length();
 
         if (len <= 0) {