Loading tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +26 −42 Original line number Diff line number Diff line Loading @@ -90,11 +90,18 @@ public final class BridgeTypedArray extends TypedArray { // fills TypedArray.mIndices which is used to implement getIndexCount/getIndexAt // first count the array size int count = 0; for (ResourceValue data : mResourceData) { if (data != null && !RenderResources.REFERENCE_NULL.equals(data.getValue())) { for (int i = 0; i < mResourceData.length; i++) { ResourceValue data = mResourceData[i]; if (data != null) { if (RenderResources.REFERENCE_NULL.equals(data.getValue())) { // No need to store this resource value. This saves needless checking for // "@null" every time an attribute is requested. mResourceData[i] = null; } else { count++; } } } // allocate the table with an extra to store the size mIndices = new int[count+1]; Loading @@ -103,8 +110,7 @@ public final class BridgeTypedArray extends TypedArray { // fill the array with the indices. int index = 1; for (int i = 0 ; i < mResourceData.length ; i++) { if (mResourceData[i] != null && !RenderResources.REFERENCE_NULL.equals(mResourceData[i].getValue())) { if (mResourceData[i] != null) { mIndices[index++] = i; } } Loading Loading @@ -215,10 +221,6 @@ public final class BridgeTypedArray extends TypedArray { String s = mResourceData[index].getValue(); if (RenderResources.REFERENCE_NULL.equals(s)) { return defValue; } if (s == null || s.length() == 0) { return defValue; } Loading Loading @@ -258,7 +260,7 @@ public final class BridgeTypedArray extends TypedArray { Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, String.format( "\"%s\" in attribute \"%2$s\" is not a valid value", keyword, mNames[index]), null /*data*/); keyword, mNames[index]), null); } } return result; Loading Loading @@ -293,7 +295,7 @@ public final class BridgeTypedArray extends TypedArray { Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, String.format( "\"%s\" in attribute \"%2$s\" cannot be converted to float.", s, mNames[index]), null /*data*/); s, mNames[index]), null); // we'll return the default value below. } Loading Loading @@ -358,10 +360,6 @@ public final class BridgeTypedArray extends TypedArray { return null; } if (RenderResources.REFERENCE_NULL.equals(value)) { return null; } // let the framework inflate the ColorStateList from the XML file. File f = new File(value); if (f.isFile()) { Loading @@ -377,13 +375,13 @@ public final class BridgeTypedArray extends TypedArray { } } catch (XmlPullParserException e) { Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Failed to configure parser for " + value, e, null /*data*/); "Failed to configure parser for " + value, e, null); return null; } catch (Exception e) { // this is an error and not warning since the file existence is checked before // attempting to parse it. Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed to parse file " + value, e, null /*data*/); "Failed to parse file " + value, e, null); return null; } Loading @@ -393,7 +391,7 @@ public final class BridgeTypedArray extends TypedArray { int color = ResourceHelper.getColor(value); return ColorStateList.valueOf(color); } catch (NumberFormatException e) { Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, e.getMessage(), e, null /*data*/); Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, e.getMessage(), e, null); } return null; Loading Loading @@ -448,11 +446,9 @@ public final class BridgeTypedArray extends TypedArray { 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.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) { if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true)) { return mValue.getDimension(mBridgeResources.getDisplayMetrics()); } Loading @@ -460,7 +456,7 @@ public final class BridgeTypedArray extends TypedArray { 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*/); s, mNames[index]), null); return defValue; } Loading Loading @@ -518,7 +514,7 @@ public final class BridgeTypedArray extends TypedArray { 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*/); s, mNames[index]), null); } } Loading Loading @@ -575,11 +571,9 @@ public final class BridgeTypedArray extends TypedArray { 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.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) { if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true)) { float f = mValue.getDimension(mBridgeResources.getDisplayMetrics()); final int res = (int)(f+0.5f); Loading Loading @@ -621,8 +615,7 @@ public final class BridgeTypedArray extends TypedArray { return defValue; } if (ResourceHelper.parseFloatAttribute(mNames[index], value, mValue, false /*requireUnit*/)) { if (ResourceHelper.parseFloatAttribute(mNames[index], value, mValue, false)) { return mValue.getFraction(base, pbase); } Loading @@ -630,7 +623,7 @@ public final class BridgeTypedArray extends TypedArray { Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, String.format( "\"%1$s\" in attribute \"%2$s\" cannot be converted to a fraction.", value, mNames[index]), null /*data*/); value, mNames[index]), null); return defValue; } Loading Loading @@ -669,10 +662,6 @@ public final class BridgeTypedArray extends TypedArray { return mContext.getDynamicIdByStyle((StyleResourceValue)resValue); } if (RenderResources.REFERENCE_NULL.equals(resValue.getValue())) { return defValue; } // if the attribute was a reference to a resource, and not a declaration of an id (@+id), // then the xml attribute value was "resolved" which leads us to a ResourceValue with a // valid getType() and getName() returning a resource name. Loading Loading @@ -782,7 +771,7 @@ public final class BridgeTypedArray extends TypedArray { ResourceValue value = mResourceData[index]; String stringValue = value.getValue(); if (stringValue == null || RenderResources.REFERENCE_NULL.equals(stringValue)) { if (stringValue == null) { return null; } Loading Loading @@ -812,17 +801,13 @@ public final class BridgeTypedArray extends TypedArray { String value = mResourceData[index].getValue(); if (value != null) { if (RenderResources.REFERENCE_NULL.equals(value)) { return null; } return new CharSequence[] { value }; } Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, String.format( String.format("Unknown value for getTextArray(%d) => %s", //DEBUG index, mResourceData[index].getName())), null /*data*/); index, mResourceData[index].getName())), null); return null; } Loading Loading @@ -862,8 +847,7 @@ public final class BridgeTypedArray extends TypedArray { String s = mResourceData[index].getValue(); return ResourceHelper.parseFloatAttribute(mNames[index], s, outValue, false /*requireUnit*/); return ResourceHelper.parseFloatAttribute(mNames[index], s, outValue, false); } /** Loading Loading
tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +26 −42 Original line number Diff line number Diff line Loading @@ -90,11 +90,18 @@ public final class BridgeTypedArray extends TypedArray { // fills TypedArray.mIndices which is used to implement getIndexCount/getIndexAt // first count the array size int count = 0; for (ResourceValue data : mResourceData) { if (data != null && !RenderResources.REFERENCE_NULL.equals(data.getValue())) { for (int i = 0; i < mResourceData.length; i++) { ResourceValue data = mResourceData[i]; if (data != null) { if (RenderResources.REFERENCE_NULL.equals(data.getValue())) { // No need to store this resource value. This saves needless checking for // "@null" every time an attribute is requested. mResourceData[i] = null; } else { count++; } } } // allocate the table with an extra to store the size mIndices = new int[count+1]; Loading @@ -103,8 +110,7 @@ public final class BridgeTypedArray extends TypedArray { // fill the array with the indices. int index = 1; for (int i = 0 ; i < mResourceData.length ; i++) { if (mResourceData[i] != null && !RenderResources.REFERENCE_NULL.equals(mResourceData[i].getValue())) { if (mResourceData[i] != null) { mIndices[index++] = i; } } Loading Loading @@ -215,10 +221,6 @@ public final class BridgeTypedArray extends TypedArray { String s = mResourceData[index].getValue(); if (RenderResources.REFERENCE_NULL.equals(s)) { return defValue; } if (s == null || s.length() == 0) { return defValue; } Loading Loading @@ -258,7 +260,7 @@ public final class BridgeTypedArray extends TypedArray { Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, String.format( "\"%s\" in attribute \"%2$s\" is not a valid value", keyword, mNames[index]), null /*data*/); keyword, mNames[index]), null); } } return result; Loading Loading @@ -293,7 +295,7 @@ public final class BridgeTypedArray extends TypedArray { Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, String.format( "\"%s\" in attribute \"%2$s\" cannot be converted to float.", s, mNames[index]), null /*data*/); s, mNames[index]), null); // we'll return the default value below. } Loading Loading @@ -358,10 +360,6 @@ public final class BridgeTypedArray extends TypedArray { return null; } if (RenderResources.REFERENCE_NULL.equals(value)) { return null; } // let the framework inflate the ColorStateList from the XML file. File f = new File(value); if (f.isFile()) { Loading @@ -377,13 +375,13 @@ public final class BridgeTypedArray extends TypedArray { } } catch (XmlPullParserException e) { Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Failed to configure parser for " + value, e, null /*data*/); "Failed to configure parser for " + value, e, null); return null; } catch (Exception e) { // this is an error and not warning since the file existence is checked before // attempting to parse it. Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed to parse file " + value, e, null /*data*/); "Failed to parse file " + value, e, null); return null; } Loading @@ -393,7 +391,7 @@ public final class BridgeTypedArray extends TypedArray { int color = ResourceHelper.getColor(value); return ColorStateList.valueOf(color); } catch (NumberFormatException e) { Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, e.getMessage(), e, null /*data*/); Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, e.getMessage(), e, null); } return null; Loading Loading @@ -448,11 +446,9 @@ public final class BridgeTypedArray extends TypedArray { 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.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) { if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true)) { return mValue.getDimension(mBridgeResources.getDisplayMetrics()); } Loading @@ -460,7 +456,7 @@ public final class BridgeTypedArray extends TypedArray { 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*/); s, mNames[index]), null); return defValue; } Loading Loading @@ -518,7 +514,7 @@ public final class BridgeTypedArray extends TypedArray { 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*/); s, mNames[index]), null); } } Loading Loading @@ -575,11 +571,9 @@ public final class BridgeTypedArray extends TypedArray { 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.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) { if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true)) { float f = mValue.getDimension(mBridgeResources.getDisplayMetrics()); final int res = (int)(f+0.5f); Loading Loading @@ -621,8 +615,7 @@ public final class BridgeTypedArray extends TypedArray { return defValue; } if (ResourceHelper.parseFloatAttribute(mNames[index], value, mValue, false /*requireUnit*/)) { if (ResourceHelper.parseFloatAttribute(mNames[index], value, mValue, false)) { return mValue.getFraction(base, pbase); } Loading @@ -630,7 +623,7 @@ public final class BridgeTypedArray extends TypedArray { Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, String.format( "\"%1$s\" in attribute \"%2$s\" cannot be converted to a fraction.", value, mNames[index]), null /*data*/); value, mNames[index]), null); return defValue; } Loading Loading @@ -669,10 +662,6 @@ public final class BridgeTypedArray extends TypedArray { return mContext.getDynamicIdByStyle((StyleResourceValue)resValue); } if (RenderResources.REFERENCE_NULL.equals(resValue.getValue())) { return defValue; } // if the attribute was a reference to a resource, and not a declaration of an id (@+id), // then the xml attribute value was "resolved" which leads us to a ResourceValue with a // valid getType() and getName() returning a resource name. Loading Loading @@ -782,7 +771,7 @@ public final class BridgeTypedArray extends TypedArray { ResourceValue value = mResourceData[index]; String stringValue = value.getValue(); if (stringValue == null || RenderResources.REFERENCE_NULL.equals(stringValue)) { if (stringValue == null) { return null; } Loading Loading @@ -812,17 +801,13 @@ public final class BridgeTypedArray extends TypedArray { String value = mResourceData[index].getValue(); if (value != null) { if (RenderResources.REFERENCE_NULL.equals(value)) { return null; } return new CharSequence[] { value }; } Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, String.format( String.format("Unknown value for getTextArray(%d) => %s", //DEBUG index, mResourceData[index].getName())), null /*data*/); index, mResourceData[index].getName())), null); return null; } Loading Loading @@ -862,8 +847,7 @@ public final class BridgeTypedArray extends TypedArray { String s = mResourceData[index].getValue(); return ResourceHelper.parseFloatAttribute(mNames[index], s, outValue, false /*requireUnit*/); return ResourceHelper.parseFloatAttribute(mNames[index], s, outValue, false); } /** Loading