Merge changes Idbb70f53,I10426a3f into honeycomb-mr2

* changes:
  Merge 06942bc4 from hc-mr1.
  Merge 988eeeb5 from hc-mr1.
This commit is contained in:
Xavier Ducrohet
2011-06-09 10:12:40 -07:00
committed by Android (Google) Code Review
3 changed files with 58 additions and 20 deletions

View File

@@ -78,6 +78,8 @@ import java.util.IdentityHashMap;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Map.Entry; 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. * Custom implementation of Context/Activity to handle non compiled resources.
@@ -299,12 +301,17 @@ public final class BridgeContext extends Activity {
public Pair<View, Boolean> inflateView(ResourceReference resource, ViewGroup parent, public Pair<View, Boolean> inflateView(ResourceReference resource, ViewGroup parent,
boolean attachToRoot, boolean skipCallbackParser) { boolean attachToRoot, boolean skipCallbackParser) {
String layoutName = resource.getName();
boolean isPlatformLayout = resource.isFramework(); boolean isPlatformLayout = resource.isFramework();
if (isPlatformLayout == false && skipCallbackParser == false) { if (isPlatformLayout == false && skipCallbackParser == false) {
// check if the project callback can provide us with a custom parser. // check if the project callback can provide us with a custom parser.
ILayoutPullParser parser = mProjectCallback.getParser(layoutName); ILayoutPullParser parser;
if (resource instanceof ResourceValue) {
parser = mProjectCallback.getParser((ResourceValue) resource);
} else {
parser = mProjectCallback.getParser(resource.getName());
}
if (parser != null) { if (parser != null) {
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser, BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(parser,
this, resource.isFramework()); this, resource.isFramework());
@@ -372,7 +379,7 @@ public final class BridgeContext extends Activity {
} else { } else {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, Bridge.getLog().error(LayoutLog.TAG_BROKEN,
String.format("Layout %s%s does not exist.", isPlatformLayout ? "android:" : "", String.format("Layout %s%s does not exist.", isPlatformLayout ? "android:" : "",
layoutName), null); resource.getName()), null);
} }
return Pair.of(null, false); return Pair.of(null, false);
@@ -507,11 +514,12 @@ public final class BridgeContext extends Activity {
return null; return null;
} }
boolean[] frameworkAttributes = new boolean[1]; AtomicBoolean frameworkAttributes = new AtomicBoolean();
TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes); AtomicReference<String> attrName = new AtomicReference<String>();
TreeMap<Integer, String> styleNameMap = searchAttrs(attrs, frameworkAttributes, attrName);
BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length, BridgeTypedArray ta = ((BridgeResources) mSystemResources).newTypeArray(attrs.length,
isPlatformFile); isPlatformFile, frameworkAttributes.get(), attrName.get());
// look for a custom style. // look for a custom style.
String customStyle = null; String customStyle = null;
@@ -602,7 +610,7 @@ public final class BridgeContext extends Activity {
} }
String namespace = BridgeConstants.NS_RESOURCES; String namespace = BridgeConstants.NS_RESOURCES;
if (frameworkAttributes[0] == false) { if (frameworkAttributes.get() == false) {
// need to use the application namespace // need to use the application namespace
namespace = mProjectCallback.getNamespace(); namespace = mProjectCallback.getNamespace();
} }
@@ -679,10 +687,12 @@ public final class BridgeContext extends Activity {
*/ */
private BridgeTypedArray createStyleBasedTypedArray(StyleResourceValue style, int[] attrs) private BridgeTypedArray createStyleBasedTypedArray(StyleResourceValue style, int[] attrs)
throws Resources.NotFoundException { 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, 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 // loop through all the values in the style map, and init the TypedArray with
// the style we got from the dynamic id // the style we got from the dynamic id
@@ -714,10 +724,13 @@ public final class BridgeContext extends Activity {
* that is used to reference the attribute later in the TypedArray. * that is used to reference the attribute later in the TypedArray.
* *
* @param attrs An attribute array reference given to obtainStyledAttributes. * @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 * @return A sorted map Attribute-Value to Attribute-Name for all attributes declared by the
* attribute array. Returns null if nothing is found. * 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 // get the name of the array from the framework resources
String arrayName = Bridge.resolveResourceId(attrs); String arrayName = Bridge.resolveResourceId(attrs);
if (arrayName != null) { if (arrayName != null) {
@@ -734,7 +747,10 @@ public final class BridgeContext extends Activity {
} }
if (outFrameworkFlag != null) { if (outFrameworkFlag != null) {
outFrameworkFlag[0] = true; outFrameworkFlag.set(true);
}
if (outAttrName != null) {
outAttrName.set(arrayName);
} }
return attributes; return attributes;
@@ -756,7 +772,10 @@ public final class BridgeContext extends Activity {
} }
if (outFrameworkFlag != null) { if (outFrameworkFlag != null) {
outFrameworkFlag[0] = false; outFrameworkFlag.set(false);
}
if (outAttrName != null) {
outAttrName.set(arrayName);
} }
return attributes; return attributes;

View File

@@ -125,8 +125,10 @@ public final class BridgeResources extends Resources {
mProjectCallback = projectCallback; mProjectCallback = projectCallback;
} }
public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile) { public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile,
return new BridgeTypedArray(this, mContext, numEntries, platformFile); boolean platformStyleable, String styleableName) {
return new BridgeTypedArray(this, mContext, numEntries, platformFile,
platformStyleable, styleableName);
} }
private ResourceValue getResourceValue(int id, boolean[] platformResFlag_out) { private ResourceValue getResourceValue(int id, boolean[] platformResFlag_out) {
@@ -232,7 +234,7 @@ public final class BridgeResources extends Resources {
try { try {
// check if the current parser can provide us with a custom parser. // check if the current parser can provide us with a custom parser.
if (mPlatformResourceFlag[0] == false) { if (mPlatformResourceFlag[0] == false) {
parser = mProjectCallback.getParser(value.getName()); parser = mProjectCallback.getParser(value);
} }
// create a new one manually if needed. // create a new one manually if needed.

View File

@@ -16,6 +16,7 @@
package com.android.layoutlib.bridge.android; 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.LayoutLog;
import com.android.ide.common.rendering.api.RenderResources; import com.android.ide.common.rendering.api.RenderResources;
import com.android.ide.common.rendering.api.ResourceValue; import com.android.ide.common.rendering.api.ResourceValue;
@@ -49,18 +50,23 @@ import java.util.Map;
*/ */
public final class BridgeTypedArray extends TypedArray { public final class BridgeTypedArray extends TypedArray {
private BridgeResources mBridgeResources; private final BridgeResources mBridgeResources;
private BridgeContext mContext; private final BridgeContext mContext;
private final boolean mPlatformFile;
private final boolean mPlatformStyleable;
private final String mStyleableName;
private ResourceValue[] mResourceData; private ResourceValue[] mResourceData;
private String[] mNames; private String[] mNames;
private final boolean mPlatformFile;
public BridgeTypedArray(BridgeResources resources, BridgeContext context, int len, public BridgeTypedArray(BridgeResources resources, BridgeContext context, int len,
boolean platformFile) { boolean platformFile, boolean platformStyleable, String styleableName) {
super(null, null, null, 0); super(null, null, null, 0);
mBridgeResources = resources; mBridgeResources = resources;
mContext = context; mContext = context;
mPlatformFile = platformFile; mPlatformFile = platformFile;
mPlatformStyleable = platformStyleable;
mStyleableName = styleableName;
mResourceData = new ResourceValue[len]; mResourceData = new ResourceValue[len];
mNames = new String[len]; mNames = new String[len];
} }
@@ -202,7 +208,18 @@ public final class BridgeTypedArray extends TypedArray {
// Field is not null and is not an integer. // Field is not null and is not an integer.
// Check for possible constants and try to find them. // Check for possible constants and try to find them.
// Get the map of attribute-constant -> IntegerValue // 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) { if (map != null) {
// accumulator to store the value of the 1+ constants. // accumulator to store the value of the 1+ constants.