aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java3
-rw-r--r--ide_common/src/com/android/ide/common/resources/ResourceResolver.java38
-rw-r--r--ide_common/src/com/android/ide/common/resources/ValueResourceParser.java19
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/Bridge.java2
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/DeclareStyleableResourceValue.java5
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/RenderResources.java37
-rw-r--r--layoutlib_api/src/com/android/ide/common/rendering/api/StyleResourceValue.java20
7 files changed, 108 insertions, 16 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
index e8fbadb..0f556f9 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/build/BuildHelper.java
@@ -1083,6 +1083,9 @@ public class BuildHelper {
public void err(String line) {
if (line != null) {
results.add(line);
+ if (BuildVerbosity.VERBOSE == AdtPrefs.getPrefs().getBuildVerbosity()) {
+ AdtPlugin.printErrorToConsole(project, line);
+ }
}
}
});
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 c847e99..43416e7 100644
--- a/ide_common/src/com/android/ide/common/resources/ResourceResolver.java
+++ b/ide_common/src/com/android/ide/common/resources/ResourceResolver.java
@@ -166,8 +166,9 @@ public class ResourceResolver extends RenderResources {
}
@Override
+ @Deprecated
public ResourceValue findItemInStyle(StyleResourceValue style, String itemName) {
- ResourceValue item = style.findValue(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) {
@@ -181,6 +182,22 @@ public class ResourceResolver extends RenderResources {
}
@Override
+ public ResourceValue findItemInStyle(StyleResourceValue style, String itemName,
+ boolean isFrameworkAttr) {
+ ResourceValue item = style.findValue(itemName, isFrameworkAttr);
+
+ // 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, isFrameworkAttr);
+ }
+ }
+
+ return item;
+ }
+
+ @Override
public ResourceValue findResValue(String reference, boolean forceFrameworkOnly) {
if (reference == null) {
return null;
@@ -230,13 +247,8 @@ public class ResourceResolver extends RenderResources {
}
// Now look for the item in the theme, starting with the current one.
- ResourceValue item;
- if (frameworkOnly) {
- // FIXME for now we do the same as if it didn't specify android:
- item = findItemInStyle(mTheme, referenceName);
- } else {
- item = findItemInStyle(mTheme, referenceName);
- }
+ ResourceValue item = findItemInStyle(mTheme, referenceName,
+ forceFrameworkOnly || frameworkOnly);
if (item == null && mLogger != null) {
mLogger.warning(LayoutLog.TAG_RESOURCES_RESOLVE_THEME_ATTR,
@@ -329,6 +341,16 @@ public class ResourceResolver extends RenderResources {
return resValue;
}
+ // detect potential loop due to mishandled namespace in attributes
+ if (resValue == resolvedResValue) {
+ if (mLogger != null) {
+ mLogger.error(LayoutLog.TAG_BROKEN,
+ String.format("Potential stackoverflow trying to resolve '%s'. Render may not be accurate.", value),
+ null);
+ }
+ return resValue;
+ }
+
// otherwise, we attempt to resolve this new value as well
return resolveResValue(resolvedResValue);
}
diff --git a/ide_common/src/com/android/ide/common/resources/ValueResourceParser.java b/ide_common/src/com/android/ide/common/resources/ValueResourceParser.java
index 3a5a6a3..7c11dd7 100644
--- a/ide_common/src/com/android/ide/common/resources/ValueResourceParser.java
+++ b/ide_common/src/com/android/ide/common/resources/ValueResourceParser.java
@@ -129,16 +129,29 @@ public final class ValueResourceParser extends DefaultHandler {
if (name != null) {
if (mCurrentStyle != null) {
- // the name can, in some cases, contain a prefix! we remove it.
+ // is the attribute in the android namespace?
+ boolean isFrameworkAttr = mIsFramework;
if (name.startsWith(DEFAULT_NS_PREFIX)) {
name = name.substring(DEFAULT_NS_PREFIX_LEN);
+ isFrameworkAttr = true;
}
mCurrentValue = new ResourceValue(null, name, mIsFramework);
- mCurrentStyle.addValue(mCurrentValue);
+ mCurrentStyle.addValue(mCurrentValue, isFrameworkAttr);
} else if (mCurrentDeclareStyleable != null) {
- mCurrentAttr = new AttrResourceValue(ResourceType.ATTR, name, mIsFramework);
+ // is the attribute in the android namespace?
+ boolean isFramework = mIsFramework;
+ if (name.startsWith(DEFAULT_NS_PREFIX)) {
+ name = name.substring(DEFAULT_NS_PREFIX_LEN);
+ isFramework = true;
+ }
+
+ mCurrentAttr = new AttrResourceValue(ResourceType.ATTR, name, isFramework);
mCurrentDeclareStyleable.addValue(mCurrentAttr);
+
+ // also add it to the repository.
+ mRepository.addResourceValue(mCurrentAttr);
+
} else if (mCurrentAttr != null) {
// get the enum/flag value
String value = attributes.getValue(ATTR_VALUE);
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