diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java index 791e53bcfc26d..596cbfca2cb3a 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeConstants.java @@ -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"; 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 b0eea4cacb495..fb79473658b97 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 @@ -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. *

- * 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 null. *

* 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 value. + * Returns the {@link ResourceValue} referenced by the value of value. *

- * 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 null. *

@@ -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 null + * @return a {@link ResourceValue} object or null */ 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. *

* The reference format can be: *

@resType/resName
@@ -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 null. + * @return a {@link ResourceValue} or null. */ 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 true, 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 null + * @return the {@link ResourceValue} object or null */ 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(); } 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 2ea52813b9bea..215c5f936628f 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 @@ -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); 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 4fb280d585cd8..d36846bc569c2 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 @@ -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 diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index 55a5bc0848993..d2fef5e04bd48 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -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); } }