aboutsummaryrefslogtreecommitdiffstats
path: root/ide_common/src/com/android/ide/common/resources
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2012-03-16 14:49:49 -0700
committerXavier Ducrohet <xav@android.com>2012-03-16 15:13:45 -0700
commit8818ca4db2f1ae396964912bf8035ee88988f4dd (patch)
treeea6af86d983f35246c18489da6bc3e39e58812c4 /ide_common/src/com/android/ide/common/resources
parent45a6d2d3883b33a3a8391c0c491b9d6476b0d2e2 (diff)
downloadsdk-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 'ide_common/src/com/android/ide/common/resources')
-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
2 files changed, 46 insertions, 11 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 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);