diff options
author | Xavier Ducrohet <xav@android.com> | 2012-03-16 14:49:49 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-03-16 15:13:45 -0700 |
commit | 8818ca4db2f1ae396964912bf8035ee88988f4dd (patch) | |
tree | ea6af86d983f35246c18489da6bc3e39e58812c4 /layoutlib_api/src/com/android | |
parent | 45a6d2d3883b33a3a8391c0c491b9d6476b0d2e2 (diff) | |
download | sdk-8818ca4db2f1ae396964912bf8035ee88988f4dd.zip sdk-8818ca4db2f1ae396964912bf8035ee88988f4dd.tar.gz sdk-8818ca4db2f1ae396964912bf8035ee88988f4dd.tar.bz2 |
Properly support attr ns when used in styles.
Previously we just stripped the namespace prefix when reading attribute
names in styles and declare-styleables. This was bad if one created
a declare-styleable mixing platform and app attributes that were
named the same.
This change is Eclipse side only and prevents ADT crashed (due to stack
overflows) but the rendering won't be correct. An updated version of
layoutlib using API 8 is necessary.
Change-Id: I3029f3e06cdd96cd46af511bb029bc5274b935ad
Diffstat (limited to 'layoutlib_api/src/com/android')
4 files changed, 59 insertions, 5 deletions
diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java b/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java index 026907e..06a01d5 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java @@ -32,7 +32,7 @@ import java.util.Map; */ public abstract class Bridge { - public final static int API_CURRENT = 7; + public final static int API_CURRENT = 8; /** * Returns the API level of the layout library. diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java b/layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java index 45679b2..f14255f 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java @@ -27,7 +27,12 @@ import java.util.Map; * {@link #getValue()} will return null, instead use {@link #getAttributeValues(String)} to * get the enum/flag value associated with an attribute defined in the declare-styleable. * + * @Deprecated This class is broken as it does not handle the namespace for each attribute. + * Thankfully, newer versions of layoutlib don't actually use it, so we just keep it as is for + * backward compatibility on older layoutlibs. + * */ +@Deprecated public class DeclareStyleableResourceValue extends ResourceValue { private Map<String, AttrResourceValue> mAttrMap; 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 ea572bc..8ccbd69 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 @@ -93,7 +93,10 @@ public class RenderResources { * * @param itemName the name of the item to search for. * @return the {@link ResourceValue} object or <code>null</code> + * + * @deprecated Use {@link #findItemInTheme(String, boolean)} */ + @Deprecated public ResourceValue findItemInTheme(String itemName) { StyleResourceValue currentTheme = getCurrentTheme(); if (currentTheme != null) { @@ -104,18 +107,52 @@ public class RenderResources { } /** + * Returns the {@link ResourceValue} matching a given attribute in the current theme. If the + * item is not directly available in the theme, the method looks in its parent theme. + * + * @param attrName the name of the attribute to search for. + * @param isFrameworkAttr whether the attribute is a framework attribute + * @return the {@link ResourceValue} object or <code>null</code> + */ + public ResourceValue findItemInTheme(String attrName, boolean isFrameworkAttr) { + StyleResourceValue currentTheme = getCurrentTheme(); + if (currentTheme != null) { + return findItemInStyle(currentTheme, attrName, isFrameworkAttr); + } + + return null; + } + + /** * 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. * * @param style the style to search in * @param itemName the name of the item to search for. * @return the {@link ResourceValue} object or <code>null</code> + * + * @Deprecated Use {@link #findItemInStyle(StyleResourceValue, String, boolean)} */ + @Deprecated public ResourceValue findItemInStyle(StyleResourceValue style, String itemName) { return null; } /** + * Returns the {@link ResourceValue} matching a given attribute in a given style. If the + * item is not directly available in the style, the method looks in its parent style. + * + * @param style the style to search in + * @param attrName the name of the attribute to search for. + * @param isFrameworkAttr whether the attribute is a framework attribute + * @return the {@link ResourceValue} object or <code>null</code> + */ + public ResourceValue findItemInStyle(StyleResourceValue style, String attrName, + boolean isFrameworkAttr) { + return null; + } + + /** * Searches for, and returns a {@link ResourceValue} by its reference. * <p/> * The reference format can be: diff --git a/layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java b/layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java index 2daa7f9..7fdfd6a 100644 --- a/layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java +++ b/layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java @@ -19,6 +19,7 @@ package com.android.ide.common.rendering.api; import com.android.layoutlib.api.IResourceValue; import com.android.layoutlib.api.IStyleResourceValue; import com.android.resources.ResourceType; +import com.android.util.Pair; import java.util.HashMap; @@ -29,7 +30,7 @@ import java.util.HashMap; public final class StyleResourceValue extends ResourceValue implements IStyleResourceValue { private String mParentStyle = null; - private HashMap<String, ResourceValue> mItems = new HashMap<String, ResourceValue>(); + private HashMap<Pair<String, Boolean>, ResourceValue> mItems = new HashMap<Pair<String, Boolean>, ResourceValue>(); public StyleResourceValue(ResourceType type, String name, boolean isFramework) { super(type, name, isFramework); @@ -52,13 +53,24 @@ public final class StyleResourceValue extends ResourceValue implements IStyleRes /** * Finds a value in the list by name * @param name the name of the resource + * + * @deprecated use {@link #findValue(String, boolean)} */ + @Deprecated public ResourceValue findValue(String name) { - return mItems.get(name); + return mItems.get(Pair.of(name, isFramework())); + } + + /** + * Finds a value in the list by name + * @param name the name of the resource + */ + public ResourceValue findValue(String name, boolean isFrameworkAttr) { + return mItems.get(Pair.of(name, isFrameworkAttr)); } - public void addValue(ResourceValue value) { - mItems.put(value.getName(), value); + public void addValue(ResourceValue value, boolean isFrameworkAttr) { + mItems.put(Pair.of(value.getName(), isFrameworkAttr), value); } @Override |