OSDN Git Service

Fix include tag rendering. [DO NOT MERGE]
authorDeepanshu Gupta <deepanshu@google.com>
Tue, 19 May 2015 18:55:15 +0000 (11:55 -0700)
committerDeepanshu Gupta <deepanshu@google.com>
Tue, 25 Aug 2015 19:06:42 +0000 (12:06 -0700)
A missing catch clause caused rendering to be failed when there is an
include tag that doesn't specify layout_width and layout_height. Also
improve the error messages to make debugging easier next time.

Change-Id: I617762636973a010b34da167c7b5fcd328b7d178
(cherry picked from commit 21b564573327b1ed2f7e06146b8a01c47ede3089)

tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java
tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java

index 7d4271b..1397acb 100644 (file)
@@ -444,7 +444,7 @@ public final class BridgeTypedArray extends TypedArray {
     @Override
     public int getDimensionPixelSize(int index, int defValue) {
         try {
-            return getDimension(index);
+            return getDimension(index, null);
         } catch (RuntimeException e) {
             String s = getString(index);
 
@@ -474,12 +474,12 @@ public final class BridgeTypedArray extends TypedArray {
     @Override
     public int getLayoutDimension(int index, String name) {
         try {
-            // this will throw an exception
-            return getDimension(index);
+            // this will throw an exception if not found.
+            return getDimension(index, name);
         } catch (RuntimeException e) {
 
             if (LayoutInflater_Delegate.sIsInInclude) {
-                throw new RuntimeException();
+                throw new RuntimeException("Layout Dimension '" + name + "' not found.");
             }
 
             Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
@@ -494,9 +494,13 @@ public final class BridgeTypedArray extends TypedArray {
         return getDimensionPixelSize(index, defValue);
     }
 
-    private int getDimension(int index) {
+    /** @param name attribute name, used for error reporting. */
+    private int getDimension(int index, @Nullable String name) {
         String s = getString(index);
         if (s == null) {
+            if (name != null) {
+                throw new RuntimeException("Attribute '" + name + "' not found");
+            }
             throw new RuntimeException();
         }
         // Check if the value is a magic constant that doesn't require a unit.
index 7a73fae..579f274 100644 (file)
@@ -134,12 +134,8 @@ public class LayoutInflater_Delegate {
 
                             params = group.generateLayoutParams(attrs);
 
-                        } catch (RuntimeException e) {
-                            // ---- START CHANGES
-                            sIsInInclude = false;
-                            // ---- END CHANGES
-
-                            params = group.generateLayoutParams(childAttrs);
+                        } catch (RuntimeException ignored) {
+                            // Ignore, just fail over to child attrs.
                         } finally {
                             // ---- START CHANGES
                             sIsInInclude = false;