summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2011-06-07 17:03:10 -0700
committerXavier Ducrohet <xav@android.com>2011-06-08 17:09:37 -0700
commit98e134eb7e0c9313777454c7e926da06dedff481 (patch)
treedd0aee9c1cb85a19dd0fcb8c941c0b3a6948cf54
parent1222031fc46b2def6d1fda9b8308fb8e770650b4 (diff)
downloadbase-98e134eb7e0c9313777454c7e926da06dedff481.tar.gz
CherryPick 988eeeb5 from hc-mr1. do not merge.
Support for custom declare-styleable attr with enum/flag in layoutlib. Change-Id: I462c550ae6c684a374b1e783cf3f348012a02759
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java32
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java6
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java27
3 files changed, 49 insertions, 16 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index b8db573e51ad..9f0a9bec320c 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -76,6 +76,8 @@ import java.util.IdentityHashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Custom implementation of Context/Activity to handle non compiled resources.
@@ -502,11 +504,12 @@ public final class BridgeContext extends Activity {
return null;
}
- boolean[] frameworkAttributes = new boolean[1];
- TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes);
+ AtomicBoolean frameworkAttributes = new AtomicBoolean();
+ AtomicReference<String> attrName = new AtomicReference<String>();
+ TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes, attrName);
BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length,
- isPlatformFile);
+ isPlatformFile, frameworkAttributes.get(), attrName.get());
// look for a custom style.
String customStyle = null;
@@ -597,7 +600,7 @@ public final class BridgeContext extends Activity {
}
String namespace = BridgeConstants.NS_RESOURCES;
- if (frameworkAttributes[0] == false) {
+ if (frameworkAttributes.get() == false) {
// need to use the application namespace
namespace = mProjectCallback.getNamespace();
}
@@ -674,10 +677,12 @@ public final class BridgeContext extends Activity {
*/
private BridgeTypedArray createStyleBasedTypedArray(StyleResourceValue style, int[] attrs)
throws Resources.NotFoundException {
- TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, null);
+ AtomicBoolean frameworkAttributes = new AtomicBoolean();
+ AtomicReference<String> attrName = new AtomicReference<String>();
+ TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes, attrName);
BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length,
- false /* platformResourceFlag */);
+ style.isFramework(), frameworkAttributes.get(), attrName.get());
// loop through all the values in the style map, and init the TypedArray with
// the style we got from the dynamic id
@@ -709,10 +714,13 @@ public final class BridgeContext extends Activity {
* that is used to reference the attribute later in the TypedArray.
*
* @param attrs An attribute array reference given to obtainStyledAttributes.
+ * @param outFrameworkFlag out value indicating if the attr array is a framework value
+ * @param outAttrName out value for the resolved attr name.
* @return A sorted map Attribute-Value to Attribute-Name for all attributes declared by the
* attribute array. Returns null if nothing is found.
*/
- private TreeMap<Integer,String> searchAttrs(int[] attrs, boolean[] outFrameworkFlag) {
+ private TreeMap<Integer,String> searchAttrs(int[] attrs, AtomicBoolean outFrameworkFlag,
+ AtomicReference<String> outAttrName) {
// get the name of the array from the framework resources
String arrayName = Bridge.resolveResourceId(attrs);
if (arrayName != null) {
@@ -729,7 +737,10 @@ public final class BridgeContext extends Activity {
}
if (outFrameworkFlag != null) {
- outFrameworkFlag[0] = true;
+ outFrameworkFlag.set(true);
+ }
+ if (outAttrName != null) {
+ outAttrName.set(arrayName);
}
return attributes;
@@ -751,7 +762,10 @@ public final class BridgeContext extends Activity {
}
if (outFrameworkFlag != null) {
- outFrameworkFlag[0] = false;
+ outFrameworkFlag.set(false);
+ }
+ if (outAttrName != null) {
+ outAttrName.set(arrayName);
}
return attributes;
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
index bc8abc2bcbc9..e0745522e0b2 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
@@ -125,8 +125,10 @@ public final class BridgeResources extends Resources {
mProjectCallback = projectCallback;
}
- public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile) {
- return new BridgeTypedArray(this, mContext, numEntries, platformFile);
+ public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile,
+ boolean platformStyleable, String styleableName) {
+ return new BridgeTypedArray(this, mContext, numEntries, platformFile,
+ platformStyleable, styleableName);
}
private ResourceValue getResourceValue(int id, boolean[] platformResFlag_out) {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
index e2a90ef3fb96..90adf5a47644 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
@@ -16,6 +16,7 @@
package com.android.layoutlib.bridge.android;
+import com.android.ide.common.rendering.api.DeclareStyleableResourceValue;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.RenderResources;
import com.android.ide.common.rendering.api.ResourceValue;
@@ -49,18 +50,23 @@ import java.util.Map;
*/
public final class BridgeTypedArray extends TypedArray {
- private BridgeResources mBridgeResources;
- private BridgeContext mContext;
+ private final BridgeResources mBridgeResources;
+ private final BridgeContext mContext;
+ private final boolean mPlatformFile;
+ private final boolean mPlatformStyleable;
+ private final String mStyleableName;
+
private ResourceValue[] mResourceData;
private String[] mNames;
- private final boolean mPlatformFile;
public BridgeTypedArray(BridgeResources resources, BridgeContext context, int len,
- boolean platformFile) {
+ boolean platformFile, boolean platformStyleable, String styleableName) {
super(null, null, null, 0);
mBridgeResources = resources;
mContext = context;
mPlatformFile = platformFile;
+ mPlatformStyleable = platformStyleable;
+ mStyleableName = styleableName;
mResourceData = new ResourceValue[len];
mNames = new String[len];
}
@@ -202,7 +208,18 @@ public final class BridgeTypedArray extends TypedArray {
// Field is not null and is not an integer.
// Check for possible constants and try to find them.
// Get the map of attribute-constant -> IntegerValue
- Map<String, Integer> map = Bridge.getEnumValues(mNames[index]);
+ Map<String, Integer> map = null;
+ if (mPlatformStyleable) {
+ map = Bridge.getEnumValues(mNames[index]);
+ } else {
+ // get the styleable matching the resolved name
+ RenderResources res = mContext.getRenderResources();
+ ResourceValue styleable = res.getProjectResource(ResourceType.DECLARE_STYLEABLE,
+ mStyleableName);
+ if (styleable instanceof DeclareStyleableResourceValue) {
+ map = ((DeclareStyleableResourceValue) styleable).getAttributeValues(mNames[index]);
+ }
+ }
if (map != null) {
// accumulator to store the value of the 1+ constants.