OSDN Git Service

LayoutLib: fix Capabilities and getDimensionPixelSize
authorXavier Ducrohet <xav@android.com>
Tue, 8 Mar 2011 19:50:21 +0000 (11:50 -0800)
committerXavier Ducrohet <xav@android.com>
Tue, 8 Mar 2011 23:00:35 +0000 (15:00 -0800)
Commented out a Capability that is not in ADT 10.

BridgeTypedArray.getDimensionPixelSize shouldn't call
getDimension since most of the code is duplicated, and
it prevents use from properly detecting malformed attribute
values.

Change-Id: I005b17061590dc0668729af16e896fad815f1973

tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java

index 85bc785..db14e53 100644 (file)
@@ -393,7 +393,7 @@ public final class Path_Delegate {
         for (int i = 0 ; i < 3 ; i++) {
             if (radii[i * 2] != radii[(i + 1) * 2] || radii[i * 2 + 1] != radii[(i + 1) * 2 + 1]) {
                 Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED,
-                        "Different corner size is not support in Path.addRoundRect.",
+                        "Different corner sizes are not supported in Path.addRoundRect.",
                         null, null /*data*/);
                 break;
             }
index acc7379..e6e9647 100644 (file)
@@ -192,7 +192,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
                 Capability.UNBOUND_RENDERING,
                 Capability.CUSTOM_BACKGROUND_COLOR,
                 Capability.RENDER,
-                Capability.LAYOUT_ONLY,
+                //Capability.LAYOUT_ONLY, // disable to run on ADT 10.0 which doesn't include this.
                 Capability.EMBEDDED_LAYOUT,
                 Capability.VIEW_MANIPULATION,
                 Capability.PLAY_ANIMATION,
index 77c1789..138a455 100644 (file)
@@ -488,18 +488,29 @@ public final class BridgeTypedArray extends TypedArray {
             return defValue;
         }
 
-        float f = getDimension(index, defValue);
-        final int res = (int)(f+0.5f);
-        if (res != 0) return res;
-        if (f == 0) return 0;
-        if (f > 0) return 1; // this is to support ]0;1[ range (since >=1 is handled 2 lines above)
-        if (f < 0) {
-            // negative values are not allowed in pixel dimensions
-            Bridge.getLog().error(LayoutLog.TAG_BROKEN,
-                    "Negative pixel dimension: " + s,
-                    null, null /*data*/);
+        if (ResourceHelper.stringToFloat(s, mValue)) {
+            float f = mValue.getDimension(mBridgeResources.mMetrics);
+
+            if (f < 0) {
+                // negative values are not allowed in pixel dimensions
+                Bridge.getLog().error(LayoutLog.TAG_BROKEN,
+                        "Negative pixel dimension: " + s,
+                        null, null /*data*/);
+                return defValue;
+            }
+
+            if (f == 0) return 0;
+            if (f < 1) return 1;
+
+            return (int)(f+0.5f);
         }
 
+        // looks like we were unable to resolve the dimension value
+        Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
+                String.format(
+                    "\"%1$s\" in attribute \"%2$s\" is not a valid format.",
+                    s, mNames[index]), null /*data*/);
+
         return defValue;
     }