Merge "LayoutLib: fix some issue with resource resolution." into honeycomb

This commit is contained in:
Xavier Ducrohet
2011-01-11 10:42:37 -08:00
committed by Android (Google) Code Review
5 changed files with 37 additions and 30 deletions

View File

@@ -48,6 +48,8 @@ public class BridgeConstants {
public final static String PREFIX_ANDROID = "android:";
public final static String RES_ANIM = "anim";
public final static String RES_ANIMATOR = "animator";
public final static String RES_STYLE = "style";
public final static String RES_ATTR = "attr";
public final static String RES_DIMEN = "dimen";

View File

@@ -493,12 +493,12 @@ public final class BridgeContext extends Activity {
/**
* Resolves the value of a resource, if the value references a theme or resource value.
* <p/>
* This method ensures that it returns a {@link IResourceValue} object that does not
* This method ensures that it returns a {@link ResourceValue} object that does not
* reference another resource.
* If the resource cannot be resolved, it returns <code>null</code>.
* <p/>
* If a value that does not need to be resolved is given, the method will return a new
* instance of IResourceValue that contains the input value.
* instance of {@link ResourceValue} that contains the input value.
*
* @param type the type of the resource
* @param name the name of the attribute containing this value.
@@ -510,11 +510,11 @@ public final class BridgeContext extends Activity {
return null;
}
// get the IResourceValue referenced by this value
// get the ResourceValue referenced by this value
ResourceValue resValue = findResValue(value, false /*forceFrameworkOnly*/);
// if resValue is null, but value is not null, this means it was not a reference.
// we return the name/value wrapper in a IResourceValue. the isFramework flag doesn't
// we return the name/value wrapper in a ResourceValue. the isFramework flag doesn't
// matter.
if (resValue == null) {
return new ResourceValue(type, name, value, false /*isFramework*/);
@@ -525,9 +525,9 @@ public final class BridgeContext extends Activity {
}
/**
* Returns the {@link IResourceValue} referenced by the value of <var>value</var>.
* Returns the {@link ResourceValue} referenced by the value of <var>value</var>.
* <p/>
* This method ensures that it returns a {@link IResourceValue} object that does not
* This method ensures that it returns a {@link ResourceValue} object that does not
* reference another resource.
* If the resource cannot be resolved, it returns <code>null</code>.
* <p/>
@@ -535,7 +535,7 @@ public final class BridgeContext extends Activity {
* value.
*
* @param value the value containing the reference to resolve.
* @return a {@link IResourceValue} object or <code>null</code>
* @return a {@link ResourceValue} object or <code>null</code>
*/
public ResourceValue resolveResValue(ResourceValue value) {
if (value == null) {
@@ -547,7 +547,7 @@ public final class BridgeContext extends Activity {
return value;
}
// else attempt to find another IResourceValue referenced by this one.
// else attempt to find another ResourceValue referenced by this one.
ResourceValue resolvedValue = findResValue(value.getValue(), value.isFramework());
// if the value did not reference anything, then we simply return the input value
@@ -560,7 +560,7 @@ public final class BridgeContext extends Activity {
}
/**
* Searches for, and returns a {@link IResourceValue} by its reference.
* Searches for, and returns a {@link ResourceValue} by its reference.
* <p/>
* The reference format can be:
* <pre>@resType/resName</pre>
@@ -577,7 +577,7 @@ public final class BridgeContext extends Activity {
* @param reference the resource reference to search for.
* @param forceFrameworkOnly if true all references are considered to be toward framework
* resource even if the reference does not include the android: prefix.
* @return a {@link IResourceValue} or <code>null</code>.
* @return a {@link ResourceValue} or <code>null</code>.
*/
ResourceValue findResValue(String reference, boolean forceFrameworkOnly) {
if (reference == null) {
@@ -670,7 +670,7 @@ public final class BridgeContext extends Activity {
}
/**
* Searches for, and returns a {@link IResourceValue} by its name, and type.
* Searches for, and returns a {@link ResourceValue} by its name, and type.
* @param resType the type of the resource
* @param resName the name of the resource
* @param frameworkOnly if <code>true</code>, the method does not search in the
@@ -746,11 +746,11 @@ public final class BridgeContext extends Activity {
}
/**
* Returns the {@link IResourceValue} matching a given name in a given style. If the
* 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 IResourceValue} object or <code>null</code>
* @return the {@link ResourceValue} object or <code>null</code>
*/
public ResourceValue findItemInStyle(StyleResourceValue style, String itemName) {
ResourceValue item = style.findValue(itemName);
@@ -878,8 +878,8 @@ public final class BridgeContext extends Activity {
return null;
}
int getFrameworkIdValue(String idName, int defValue) {
Integer value = Bridge.getResourceValue(BridgeConstants.RES_ID, idName);
int getFrameworkResourceValue(String resType, String resName, int defValue) {
Integer value = Bridge.getResourceValue(resType, resName);
if (value != null) {
return value.intValue();
}
@@ -887,9 +887,9 @@ public final class BridgeContext extends Activity {
return defValue;
}
int getProjectIdValue(String idName, int defValue) {
int getProjectResourceValue(String resType, String resName, int defValue) {
if (mProjectCallback != null) {
Integer value = mProjectCallback.getResourceValue(BridgeConstants.RES_ID, idName);
Integer value = mProjectCallback.getResourceValue(resType, resName);
if (value != null) {
return value.intValue();
}

View File

@@ -294,7 +294,6 @@ public final class BridgeResources extends Resources {
return null;
}
@Override
public TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
return mContext.obtainStyledAttributes(set, attrs);

View File

@@ -577,19 +577,21 @@ public final class BridgeTypedArray extends TypedArray {
return mContext.getDynamicIdByStyle((StyleResourceValue)resValue);
}
// if the attribute was a reference to an id, and not a declaration of an id (@+id), then
// the xml attribute value was "resolved" which leads us to a ResourceValue with
// getType() returning "id" and getName() returning the id name
// if the attribute was a reference to a resource, and not a declaration of an id (@+id),
// then the xml attribute value was "resolved" which leads us to a ResourceValue with a
// valid getType() and getName() returning a resource name.
// (and getValue() returning null!). We need to handle this!
if (resValue.getType() != null && resValue.getType().equals(BridgeConstants.RES_ID)) {
if (resValue.getType() != null && resValue.getType().startsWith("@+") == false) {
// if this is a framework id
if (mPlatformFile || resValue.isFramework()) {
// look for idName in the android R classes
return mContext.getFrameworkIdValue(resValue.getName(), defValue);
return mContext.getFrameworkResourceValue(
resValue.getType(), resValue.getName(), defValue);
}
// look for idName in the project R class.
return mContext.getProjectIdValue(resValue.getName(), defValue);
return mContext.getProjectResourceValue(
resValue.getType(), resValue.getName(), defValue);
}
// else, try to get the value, and resolve it somehow.
@@ -626,11 +628,11 @@ public final class BridgeTypedArray extends TypedArray {
// if this is a framework id
if (mPlatformFile || value.startsWith("@android") || value.startsWith("@+android")) {
// look for idName in the android R classes
return mContext.getFrameworkIdValue(idName, defValue);
return mContext.getFrameworkResourceValue(BridgeConstants.RES_ID, idName, defValue);
}
// look for idName in the project R class.
return mContext.getProjectIdValue(idName, defValue);
return mContext.getProjectResourceValue(BridgeConstants.RES_ID, idName, defValue);
}
// not a direct id valid reference? resolve it

View File

@@ -505,14 +505,18 @@ public class RenderSessionImpl {
ResourceValue animationResource = null;
int animationId = 0;
if (isFrameworkAnimation) {
animationResource = mContext.getFrameworkResource("anim", animationName);
animationResource = mContext.getFrameworkResource(BridgeConstants.RES_ANIM,
animationName);
if (animationResource != null) {
animationId = Bridge.getResourceValue("anim", animationName);
animationId = Bridge.getResourceValue(BridgeConstants.RES_ANIM,
animationName);
}
} else {
animationResource = mContext.getProjectResource("anim", animationName);
animationResource = mContext.getProjectResource(BridgeConstants.RES_ANIM,
animationName);
if (animationResource != null) {
animationId = mContext.getProjectCallback().getResourceValue("anim", animationName);
animationId = mContext.getProjectCallback().getResourceValue(
BridgeConstants.RES_ANIM, animationName);
}
}