Loading tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java +14 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ import java.io.IOException; */ public class LayoutInflater_Delegate { public static boolean sIsInInclude = false; @LayoutlibDelegate /*package*/ static void parseInclude(LayoutInflater thisInflater, XmlPullParser parser, View parent, AttributeSet attrs) Loading Loading @@ -109,10 +111,22 @@ public class LayoutInflater_Delegate { // false means we need to rely on the included layout params. ViewGroup.LayoutParams params = null; try { // ---- START CHANGES sIsInInclude = true; // ---- END CHANGES params = group.generateLayoutParams(attrs); } catch (RuntimeException e) { // ---- START CHANGES sIsInInclude = false; // ---- END CHANGES params = group.generateLayoutParams(childAttrs); } finally { // ---- START CHANGES sIsInInclude = false; // ---- END CHANGES if (params != null) { view.setLayoutParams(params); } Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java +58 −31 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.LayoutInflater_Delegate; import android.view.ViewGroup.LayoutParams; import java.io.File; Loading Loading @@ -471,41 +472,24 @@ public final class BridgeTypedArray extends TypedArray { */ @Override public int getDimensionPixelSize(int index, int defValue) { if (mResourceData[index] == null) { return defValue; } try { return getDimension(index); } catch (RuntimeException e) { if (mResourceData[index] != null) { String s = mResourceData[index].getValue(); if (s == null) { return defValue; } else if (s.equals(BridgeConstants.MATCH_PARENT) || s.equals(BridgeConstants.FILL_PARENT)) { return LayoutParams.MATCH_PARENT; } else if (s.equals(BridgeConstants.WRAP_CONTENT)) { return LayoutParams.WRAP_CONTENT; } else if (RenderResources.REFERENCE_NULL.equals(s)) { return defValue; } if (ResourceHelper.stringToFloat(s, mValue)) { float f = mValue.getDimension(mBridgeResources.mMetrics); final int res = (int)(f+0.5f); if (res != 0) return res; if (f == 0) return 0; if (f > 0) return 1; return defValue; // this is basically unreachable. } if (s != null) { // 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; } } /** * Special version of {@link #getDimensionPixelSize} for retrieving Loading @@ -521,7 +505,20 @@ public final class BridgeTypedArray extends TypedArray { */ @Override public int getLayoutDimension(int index, String name) { return getDimensionPixelSize(index, 0); try { // this will throw an exception return getDimension(index); } catch (RuntimeException e) { if (LayoutInflater_Delegate.sIsInInclude) { throw new RuntimeException(); } Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, "You must supply a " + name + " attribute.", null); return 0; } } @Override Loading @@ -529,6 +526,36 @@ public final class BridgeTypedArray extends TypedArray { return getDimensionPixelSize(index, defValue); } private int getDimension(int index) { if (mResourceData[index] == null) { throw new RuntimeException(); } String s = mResourceData[index].getValue(); if (s == null) { throw new RuntimeException(); } else if (s.equals(BridgeConstants.MATCH_PARENT) || s.equals(BridgeConstants.FILL_PARENT)) { return LayoutParams.MATCH_PARENT; } else if (s.equals(BridgeConstants.WRAP_CONTENT)) { return LayoutParams.WRAP_CONTENT; } else if (RenderResources.REFERENCE_NULL.equals(s)) { throw new RuntimeException(); } if (ResourceHelper.stringToFloat(s, mValue)) { float f = mValue.getDimension(mBridgeResources.mMetrics); final int res = (int)(f+0.5f); if (res != 0) return res; if (f == 0) return 0; if (f > 0) return 1; } throw new RuntimeException(); } /** * Retrieve a fractional unit attribute at <var>index</var>. * Loading tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +0 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,6 @@ public final class CreateInfo implements ICreateInfo { "android.view.LayoutInflater#parseInclude", "android.view.View#isInEditMode", "com.android.internal.util.XmlUtils#convertValueToInt", // TODO: comment out once DelegateClass is working }; /** Loading Loading
tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java +14 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,8 @@ import java.io.IOException; */ public class LayoutInflater_Delegate { public static boolean sIsInInclude = false; @LayoutlibDelegate /*package*/ static void parseInclude(LayoutInflater thisInflater, XmlPullParser parser, View parent, AttributeSet attrs) Loading Loading @@ -109,10 +111,22 @@ public class LayoutInflater_Delegate { // false means we need to rely on the included layout params. ViewGroup.LayoutParams params = null; try { // ---- START CHANGES sIsInInclude = true; // ---- END CHANGES params = group.generateLayoutParams(attrs); } catch (RuntimeException e) { // ---- START CHANGES sIsInInclude = false; // ---- END CHANGES params = group.generateLayoutParams(childAttrs); } finally { // ---- START CHANGES sIsInInclude = false; // ---- END CHANGES if (params != null) { view.setLayoutParams(params); } Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java +58 −31 Original line number Diff line number Diff line Loading @@ -36,6 +36,7 @@ import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.LayoutInflater_Delegate; import android.view.ViewGroup.LayoutParams; import java.io.File; Loading Loading @@ -471,41 +472,24 @@ public final class BridgeTypedArray extends TypedArray { */ @Override public int getDimensionPixelSize(int index, int defValue) { if (mResourceData[index] == null) { return defValue; } try { return getDimension(index); } catch (RuntimeException e) { if (mResourceData[index] != null) { String s = mResourceData[index].getValue(); if (s == null) { return defValue; } else if (s.equals(BridgeConstants.MATCH_PARENT) || s.equals(BridgeConstants.FILL_PARENT)) { return LayoutParams.MATCH_PARENT; } else if (s.equals(BridgeConstants.WRAP_CONTENT)) { return LayoutParams.WRAP_CONTENT; } else if (RenderResources.REFERENCE_NULL.equals(s)) { return defValue; } if (ResourceHelper.stringToFloat(s, mValue)) { float f = mValue.getDimension(mBridgeResources.mMetrics); final int res = (int)(f+0.5f); if (res != 0) return res; if (f == 0) return 0; if (f > 0) return 1; return defValue; // this is basically unreachable. } if (s != null) { // 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; } } /** * Special version of {@link #getDimensionPixelSize} for retrieving Loading @@ -521,7 +505,20 @@ public final class BridgeTypedArray extends TypedArray { */ @Override public int getLayoutDimension(int index, String name) { return getDimensionPixelSize(index, 0); try { // this will throw an exception return getDimension(index); } catch (RuntimeException e) { if (LayoutInflater_Delegate.sIsInInclude) { throw new RuntimeException(); } Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, "You must supply a " + name + " attribute.", null); return 0; } } @Override Loading @@ -529,6 +526,36 @@ public final class BridgeTypedArray extends TypedArray { return getDimensionPixelSize(index, defValue); } private int getDimension(int index) { if (mResourceData[index] == null) { throw new RuntimeException(); } String s = mResourceData[index].getValue(); if (s == null) { throw new RuntimeException(); } else if (s.equals(BridgeConstants.MATCH_PARENT) || s.equals(BridgeConstants.FILL_PARENT)) { return LayoutParams.MATCH_PARENT; } else if (s.equals(BridgeConstants.WRAP_CONTENT)) { return LayoutParams.WRAP_CONTENT; } else if (RenderResources.REFERENCE_NULL.equals(s)) { throw new RuntimeException(); } if (ResourceHelper.stringToFloat(s, mValue)) { float f = mValue.getDimension(mBridgeResources.mMetrics); final int res = (int)(f+0.5f); if (res != 0) return res; if (f == 0) return 0; if (f > 0) return 1; } throw new RuntimeException(); } /** * Retrieve a fractional unit attribute at <var>index</var>. * Loading
tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +0 −1 Original line number Diff line number Diff line Loading @@ -102,7 +102,6 @@ public final class CreateInfo implements ICreateInfo { "android.view.LayoutInflater#parseInclude", "android.view.View#isInEditMode", "com.android.internal.util.XmlUtils#convertValueToInt", // TODO: comment out once DelegateClass is working }; /** Loading