diff options
author | Xavier Ducrohet <xav@android.com> | 2012-05-16 11:35:07 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-05-16 11:35:07 -0700 |
commit | b9f706c82683c9e82197577b7ade91984cc6539a (patch) | |
tree | aa7d8edc80e5be627c0354f7aa8d01a993cc8880 | |
parent | 7911fa1ef67338907a2fb22d4fdb4203930a4549 (diff) | |
download | sdk-b9f706c82683c9e82197577b7ade91984cc6539a.zip sdk-b9f706c82683c9e82197577b7ade91984cc6539a.tar.gz sdk-b9f706c82683c9e82197577b7ade91984cc6539a.tar.bz2 |
Improve search of items into style for legacy layoutlibs.
Legacy versions uses the old API that doesn't specify the
namespace of the attribute being queried. The implementation
used the namespace of the style as the namespace of the attribute
but this make little sense.
At better implementation searches in the project's namespace
and, if the attribute is not found, then searches in the
framework namespace.
Change-Id: Ief43ecd45f108162de2b1512027d4eedf2c132db
-rw-r--r-- | ide_common/src/com/android/ide/common/resources/ResourceResolver.java | 16 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java | 10 |
2 files changed, 14 insertions, 12 deletions
diff --git a/ide_common/src/com/android/ide/common/resources/ResourceResolver.java b/ide_common/src/com/android/ide/common/resources/ResourceResolver.java index 43416e7..772d75e 100644 --- a/ide_common/src/com/android/ide/common/resources/ResourceResolver.java +++ b/ide_common/src/com/android/ide/common/resources/ResourceResolver.java @@ -167,15 +167,13 @@ public class ResourceResolver extends RenderResources { @Override @Deprecated - public ResourceValue findItemInStyle(StyleResourceValue style, String itemName) { - ResourceValue item = style.findValue(itemName, style.isFramework()); - - // if we didn't find it, we look in the parent style (if applicable) - if (item == null && mStyleInheritanceMap != null) { - StyleResourceValue parentStyle = mStyleInheritanceMap.get(style); - if (parentStyle != null) { - return findItemInStyle(parentStyle, itemName); - } + public ResourceValue findItemInStyle(StyleResourceValue style, String attrName) { + // this method is deprecated because it doesn't know about the namespace of the + // attribute so we search for the project namespace first and then in the + // android namespace if needed. + ResourceValue item = findItemInStyle(style, attrName, false /*isFrameworkAttr*/); + if (item == null) { + item = findItemInStyle(style, attrName, true /*isFrameworkAttr*/); } return item; diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java index 8ccbd69..f9e02d6 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java @@ -127,14 +127,18 @@ public class RenderResources { * Returns the {@link ResourceValue} matching a given name in a given style. If the * item is not directly available in the style, the method looks in its parent style. * + * This version of doesn't support providing the namespace of the attribute so it'll search + * in both the project's namespace and then in the android namespace. + * * @param style the style to search in - * @param itemName the name of the item to search for. + * @param attrName the name of the attribute to search for. * @return the {@link ResourceValue} object or <code>null</code> * - * @Deprecated Use {@link #findItemInStyle(StyleResourceValue, String, boolean)} + * @Deprecated Use {@link #findItemInStyle(StyleResourceValue, String, boolean)} since this + * method doesn't know the item namespace. */ @Deprecated - public ResourceValue findItemInStyle(StyleResourceValue style, String itemName) { + public ResourceValue findItemInStyle(StyleResourceValue style, String attrName) { return null; } |