aboutsummaryrefslogtreecommitdiffstats
path: root/ide_common
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-06-07 16:25:12 -0700
committerXavier Ducrohet <xav@android.com>2011-06-07 16:58:12 -0700
commit917373c1e375c76edba08a0936ddee7253dd5527 (patch)
tree0d1d0015bdac89abb1d58594446c856d3017c68c /ide_common
parent08f09e9f14c7b594b630c95ad8484666a54ea62c (diff)
downloadsdk-917373c1e375c76edba08a0936ddee7253dd5527.tar.gz
sdk-917373c1e375c76edba08a0936ddee7253dd5527.tar.bz2
sdk-917373c1e375c76edba08a0936ddee7253dd5527.zip
Add proper styleable support.
Change-Id: I2dc79e71521f93d798fd4a9b33aa59979bef379d
Diffstat (limited to 'ide_common')
-rw-r--r--ide_common/src/com/android/ide/common/resources/ResourceResolver.java19
-rw-r--r--ide_common/src/com/android/ide/common/resources/ValueResourceParser.java60
2 files changed, 55 insertions, 24 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 938a6ef8d..c847e9974 100644
--- a/ide_common/src/com/android/ide/common/resources/ResourceResolver.java
+++ b/ide_common/src/com/android/ide/common/resources/ResourceResolver.java
@@ -310,26 +310,27 @@ public class ResourceResolver extends RenderResources {
}
@Override
- public ResourceValue resolveResValue(ResourceValue value) {
- if (value == null) {
+ public ResourceValue resolveResValue(ResourceValue resValue) {
+ if (resValue == null) {
return null;
}
- // if the resource value is a style, we simply return it.
- if (value instanceof StyleResourceValue) {
- return value;
+ // if the resource value is null, we simply return it.
+ String value = resValue.getValue();
+ if (value == null) {
+ return resValue;
}
// else attempt to find another ResourceValue referenced by this one.
- ResourceValue resolvedValue = findResValue(value.getValue(), value.isFramework());
+ ResourceValue resolvedResValue = findResValue(value, resValue.isFramework());
// if the value did not reference anything, then we simply return the input value
- if (resolvedValue == null) {
- return value;
+ if (resolvedResValue == null) {
+ return resValue;
}
// otherwise, we attempt to resolve this new value as well
- return resolveResValue(resolvedValue);
+ return resolveResValue(resolvedResValue);
}
// ---- Private helper methods.
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 cda658771..e52c026e1 100644
--- a/ide_common/src/com/android/ide/common/resources/ValueResourceParser.java
+++ b/ide_common/src/com/android/ide/common/resources/ValueResourceParser.java
@@ -16,6 +16,7 @@
package com.android.ide.common.resources;
+import com.android.ide.common.rendering.api.DeclareStyleableResourceValue;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.ide.common.rendering.api.StyleResourceValue;
import com.android.resources.ResourceType;
@@ -35,6 +36,7 @@ public final class ValueResourceParser extends DefaultHandler {
private final static String ATTR_NAME = "name";
private final static String ATTR_TYPE = "type";
private final static String ATTR_PARENT = "parent";
+ private final static String ATTR_VALUE = "value";
private final static String DEFAULT_NS_PREFIX = "android:";
private final static int DEFAULT_NS_PREFIX_LEN = DEFAULT_NS_PREFIX.length();
@@ -45,8 +47,10 @@ public final class ValueResourceParser extends DefaultHandler {
private boolean inResources = false;
private int mDepth = 0;
- private StyleResourceValue mCurrentStyle = null;
private ResourceValue mCurrentValue = null;
+ private StyleResourceValue mCurrentStyle = null;
+ private DeclareStyleableResourceValue mCurrentDeclareStyleable = null;
+ private String mCurrentAttribute = null;
private IValueResourceRepository mRepository;
private final boolean mIsFramework;
@@ -66,8 +70,10 @@ public final class ValueResourceParser extends DefaultHandler {
} else if (mDepth == 2) {
mCurrentValue = null;
mCurrentStyle = null;
+ mCurrentDeclareStyleable = null;
} else if (mDepth == 3) {
mCurrentValue = null;
+ mCurrentAttribute = null;
}
mDepth--;
@@ -101,29 +107,53 @@ public final class ValueResourceParser extends DefaultHandler {
// get the resource name
String name = attributes.getValue(ATTR_NAME);
if (name != null) {
- if (type == ResourceType.STYLE) {
- String parent = attributes.getValue(ATTR_PARENT);
- mCurrentStyle = new StyleResourceValue(type, name, parent,
- mIsFramework);
- mRepository.addResourceValue(type, mCurrentStyle);
- } else {
- mCurrentValue = new ResourceValue(type, name, mIsFramework);
- mRepository.addResourceValue(type, mCurrentValue);
+ switch (type) {
+ case STYLE:
+ String parent = attributes.getValue(ATTR_PARENT);
+ mCurrentStyle = new StyleResourceValue(type, name, parent,
+ mIsFramework);
+ mRepository.addResourceValue(type, mCurrentStyle);
+ break;
+ case DECLARE_STYLEABLE:
+ mCurrentDeclareStyleable = new DeclareStyleableResourceValue(
+ type, name, mIsFramework);
+ mRepository.addResourceValue(type, mCurrentDeclareStyleable);
+ break;
+ default:
+ mCurrentValue = new ResourceValue(type, name, mIsFramework);
+ mRepository.addResourceValue(type, mCurrentValue);
+ break;
}
}
}
}
- } else if (mDepth == 3 && mCurrentStyle != null) {
+ } else if (mDepth == 3) {
// get the resource name
String name = attributes.getValue(ATTR_NAME);
if (name != null) {
- // the name can, in some cases, contain a prefix! we remove it.
- if (name.startsWith(DEFAULT_NS_PREFIX)) {
- name = name.substring(DEFAULT_NS_PREFIX_LEN);
+
+ if (mCurrentStyle != null) {
+ // the name can, in some cases, contain a prefix! we remove it.
+ if (name.startsWith(DEFAULT_NS_PREFIX)) {
+ name = name.substring(DEFAULT_NS_PREFIX_LEN);
+ }
+
+ mCurrentValue = new ResourceValue(null, name, mIsFramework);
+ mCurrentStyle.addValue(mCurrentValue);
+ } else if (mCurrentDeclareStyleable != null) {
+ mCurrentAttribute = name;
}
+ }
+ } else if (mDepth == 4 && mCurrentDeclareStyleable != null) {
+ // get the enum/flag name
+ String name = attributes.getValue(ATTR_NAME);
+ String value = attributes.getValue(ATTR_VALUE);
- mCurrentValue = new ResourceValue(null, name, mIsFramework);
- mCurrentStyle.addValue(mCurrentValue);
+ try {
+ mCurrentDeclareStyleable.addValue(mCurrentAttribute,
+ name, Integer.decode(value));
+ } catch (NumberFormatException e) {
+ // pass, we'll just ignore this value
}
}
} finally {