Loading tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +3 −0 Original line number Diff line number Diff line Loading @@ -638,6 +638,9 @@ public final class BridgeTypedArray extends TypedArray { return mContext.getProjectResourceValue(ResourceType.ID, idName, defValue); } } else if (value.startsWith("@aapt:_aapt")) { return mContext.getLayoutlibCallback().getResourceId(ResourceType.AAPT, value); } // not a direct id valid reference. First check if it's an enum (this is a corner case // for attributes that have a reference|enum type), then fallback to resolve Loading tools/layoutlib/bridge/src/android/content/res/Resources_Delegate.java +9 −2 Original line number Diff line number Diff line Loading @@ -131,9 +131,16 @@ public class Resources_Delegate { if (resourceInfo != null) { String attributeName = resourceInfo.getSecond(); RenderResources renderResources = resources.mContext.getRenderResources(); return Pair.of(attributeName, platformResFlag_out[0] ? ResourceValue value = platformResFlag_out[0] ? renderResources.getFrameworkResource(resourceInfo.getFirst(), attributeName) : renderResources.getProjectResource(resourceInfo.getFirst(), attributeName)); renderResources.getProjectResource(resourceInfo.getFirst(), attributeName); if (value == null) { // Unable to resolve the attribute, just leave the unresolved value value = new ResourceValue(resourceInfo.getFirst(), attributeName, attributeName, platformResFlag_out[0]); } return Pair.of(attributeName, value); } return null; Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java +24 −29 Original line number Diff line number Diff line Loading @@ -286,18 +286,15 @@ public final class ResourceHelper { Density density = Density.MEDIUM; if (value instanceof DensityBasedResourceValue) { density = ((DensityBasedResourceValue)value).getResourceDensity(); density = ((DensityBasedResourceValue) value).getResourceDensity(); } if (lowerCaseValue.endsWith(NinePatch.EXTENSION_9PATCH)) { File file = new File(stringValue); if (file.isFile()) { try { return getNinePatchDrawable( new FileInputStream(file), density, value.isFramework(), stringValue, context); return getNinePatchDrawable(new FileInputStream(file), density, value.isFramework(), stringValue, context); } catch (IOException e) { // failed to read the file, we'll return null below. Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, Loading @@ -306,16 +303,19 @@ public final class ResourceHelper { } return null; } else if (lowerCaseValue.endsWith(".xml")) { } else if (lowerCaseValue.endsWith(".xml") || stringValue.startsWith("@aapt:_aapt/")) { // create a block parser for the file File f = new File(stringValue); if (f.isFile()) { try { // let the framework inflate the Drawable from the XML file. XmlPullParser parser = ParserFactory.create(f); XmlPullParser parser = context.getLayoutlibCallback().getParser(value); if (parser == null) { File drawableFile = new File(stringValue); if (drawableFile.isFile()) { parser = ParserFactory.create(drawableFile); } } BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser( parser, context, value.isFramework()); BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, context, value.isFramework()); try { return Drawable.createFromXml(context.getResources(), blockParser, theme); } finally { Loading @@ -324,12 +324,7 @@ public final class ResourceHelper { } catch (Exception e) { // this is an error and not warning since the file existence is checked before // attempting to parse it. Bridge.getLog().error(null, "Failed to parse file " + stringValue, e, null /*data*/); } } else { Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("File %s does not exist (or is not a file)", stringValue), Bridge.getLog().error(null, "Failed to parse file " + stringValue, e, null /*data*/); } Loading @@ -342,8 +337,8 @@ public final class ResourceHelper { value.isFramework() ? null : context.getProjectKey()); if (bitmap == null) { bitmap = Bitmap_Delegate.createBitmap(bmpFile, false /*isMutable*/, density); bitmap = Bitmap_Delegate.createBitmap(bmpFile, false /*isMutable*/, density); Bridge.setCachedBitmap(stringValue, bitmap, value.isFramework() ? null : context.getProjectKey()); } Loading Loading
tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +3 −0 Original line number Diff line number Diff line Loading @@ -638,6 +638,9 @@ public final class BridgeTypedArray extends TypedArray { return mContext.getProjectResourceValue(ResourceType.ID, idName, defValue); } } else if (value.startsWith("@aapt:_aapt")) { return mContext.getLayoutlibCallback().getResourceId(ResourceType.AAPT, value); } // not a direct id valid reference. First check if it's an enum (this is a corner case // for attributes that have a reference|enum type), then fallback to resolve Loading
tools/layoutlib/bridge/src/android/content/res/Resources_Delegate.java +9 −2 Original line number Diff line number Diff line Loading @@ -131,9 +131,16 @@ public class Resources_Delegate { if (resourceInfo != null) { String attributeName = resourceInfo.getSecond(); RenderResources renderResources = resources.mContext.getRenderResources(); return Pair.of(attributeName, platformResFlag_out[0] ? ResourceValue value = platformResFlag_out[0] ? renderResources.getFrameworkResource(resourceInfo.getFirst(), attributeName) : renderResources.getProjectResource(resourceInfo.getFirst(), attributeName)); renderResources.getProjectResource(resourceInfo.getFirst(), attributeName); if (value == null) { // Unable to resolve the attribute, just leave the unresolved value value = new ResourceValue(resourceInfo.getFirst(), attributeName, attributeName, platformResFlag_out[0]); } return Pair.of(attributeName, value); } return null; Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java +24 −29 Original line number Diff line number Diff line Loading @@ -286,18 +286,15 @@ public final class ResourceHelper { Density density = Density.MEDIUM; if (value instanceof DensityBasedResourceValue) { density = ((DensityBasedResourceValue)value).getResourceDensity(); density = ((DensityBasedResourceValue) value).getResourceDensity(); } if (lowerCaseValue.endsWith(NinePatch.EXTENSION_9PATCH)) { File file = new File(stringValue); if (file.isFile()) { try { return getNinePatchDrawable( new FileInputStream(file), density, value.isFramework(), stringValue, context); return getNinePatchDrawable(new FileInputStream(file), density, value.isFramework(), stringValue, context); } catch (IOException e) { // failed to read the file, we'll return null below. Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, Loading @@ -306,16 +303,19 @@ public final class ResourceHelper { } return null; } else if (lowerCaseValue.endsWith(".xml")) { } else if (lowerCaseValue.endsWith(".xml") || stringValue.startsWith("@aapt:_aapt/")) { // create a block parser for the file File f = new File(stringValue); if (f.isFile()) { try { // let the framework inflate the Drawable from the XML file. XmlPullParser parser = ParserFactory.create(f); XmlPullParser parser = context.getLayoutlibCallback().getParser(value); if (parser == null) { File drawableFile = new File(stringValue); if (drawableFile.isFile()) { parser = ParserFactory.create(drawableFile); } } BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser( parser, context, value.isFramework()); BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, context, value.isFramework()); try { return Drawable.createFromXml(context.getResources(), blockParser, theme); } finally { Loading @@ -324,12 +324,7 @@ public final class ResourceHelper { } catch (Exception e) { // this is an error and not warning since the file existence is checked before // attempting to parse it. Bridge.getLog().error(null, "Failed to parse file " + stringValue, e, null /*data*/); } } else { Bridge.getLog().error(LayoutLog.TAG_BROKEN, String.format("File %s does not exist (or is not a file)", stringValue), Bridge.getLog().error(null, "Failed to parse file " + stringValue, e, null /*data*/); } Loading @@ -342,8 +337,8 @@ public final class ResourceHelper { value.isFramework() ? null : context.getProjectKey()); if (bitmap == null) { bitmap = Bitmap_Delegate.createBitmap(bmpFile, false /*isMutable*/, density); bitmap = Bitmap_Delegate.createBitmap(bmpFile, false /*isMutable*/, density); Bridge.setCachedBitmap(stringValue, bitmap, value.isFramework() ? null : context.getProjectKey()); } Loading