diff options
author | Xavier Ducrohet <xav@android.com> | 2012-02-22 10:49:15 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2012-02-22 10:49:15 -0800 |
commit | 22701ec5b11f6138e6298814fff5f09da82df144 (patch) | |
tree | 2a9d69b0bc57711ea7b1ec2f237935c4cf5af842 /tools | |
parent | fc4215eec9b947628c3ab5b3707711d16da19120 (diff) | |
parent | 503247f213ef2894324a22e7608101e90a7fe8fb (diff) | |
download | frameworks_base-22701ec5b11f6138e6298814fff5f09da82df144.zip frameworks_base-22701ec5b11f6138e6298814fff5f09da82df144.tar.gz frameworks_base-22701ec5b11f6138e6298814fff5f09da82df144.tar.bz2 |
am 503247f2: Merge "Make sure resource references are resolved." into ics-mr1
* commit '503247f213ef2894324a22e7608101e90a7fe8fb':
Make sure resource references are resolved.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java | 191 | ||||
-rw-r--r-- | tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java | 4 |
2 files changed, 176 insertions, 19 deletions
diff --git a/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java index 0a3cdc6..6ac5b02 100644 --- a/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java +++ b/tools/layoutlib/bridge/src/android/util/BridgeXmlPullAttributes.java @@ -18,6 +18,7 @@ package android.util; import com.android.ide.common.rendering.api.RenderResources; import com.android.ide.common.rendering.api.ResourceValue; +import com.android.internal.util.XmlUtils; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.android.BridgeContext; @@ -25,9 +26,6 @@ import com.android.resources.ResourceType; import org.xmlpull.v1.XmlPullParser; -import android.util.AttributeSet; -import android.util.XmlPullAttributes; - /** * A correct implementation of the {@link AttributeSet} interface on top of a XmlPullParser */ @@ -80,21 +78,40 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes { return 0; } - /* - * (non-Javadoc) - * @see android.util.XmlPullAttributes#getAttributeResourceValue(int, int) - */ @Override - public int getAttributeResourceValue(int index, int defaultValue) { - String value = getAttributeValue(index); + public int getAttributeListValue(String namespace, String attribute, + String[] options, int defaultValue) { + String value = getAttributeValue(namespace, attribute); + if (value != null) { + ResourceValue r = getResourceValue(value); - return resolveResourceValue(value, defaultValue); + if (r != null) { + value = r.getValue(); + } + + return XmlUtils.convertValueToList(value, options, defaultValue); + } + + return defaultValue; + } + + @Override + public boolean getAttributeBooleanValue(String namespace, String attribute, + boolean defaultValue) { + String value = getAttributeValue(namespace, attribute); + if (value != null) { + ResourceValue r = getResourceValue(value); + + if (r != null) { + value = r.getValue(); + } + + return XmlUtils.convertValueToBoolean(value, defaultValue); + } + + return defaultValue; } - /* - * (non-Javadoc) - * @see android.util.XmlPullAttributes#getAttributeResourceValue(java.lang.String, java.lang.String, int) - */ @Override public int getAttributeResourceValue(String namespace, String attribute, int defaultValue) { String value = getAttributeValue(namespace, attribute); @@ -102,12 +119,151 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes { return resolveResourceValue(value, defaultValue); } - private int resolveResourceValue(String value, int defaultValue) { + @Override + public int getAttributeIntValue(String namespace, String attribute, + int defaultValue) { + String value = getAttributeValue(namespace, attribute); + if (value != null) { + ResourceValue r = getResourceValue(value); + + if (r != null) { + value = r.getValue(); + } + + return XmlUtils.convertValueToInt(value, defaultValue); + } + + return defaultValue; + } + + @Override + public int getAttributeUnsignedIntValue(String namespace, String attribute, + int defaultValue) { + String value = getAttributeValue(namespace, attribute); + if (value != null) { + ResourceValue r = getResourceValue(value); + + if (r != null) { + value = r.getValue(); + } + + return XmlUtils.convertValueToUnsignedInt(value, defaultValue); + } + + return defaultValue; + } + + @Override + public float getAttributeFloatValue(String namespace, String attribute, + float defaultValue) { + String s = getAttributeValue(namespace, attribute); + if (s != null) { + ResourceValue r = getResourceValue(s); + + if (r != null) { + s = r.getValue(); + } + + return Float.parseFloat(s); + } + + return defaultValue; + } + + @Override + public int getAttributeListValue(int index, + String[] options, int defaultValue) { + return XmlUtils.convertValueToList( + getAttributeValue(index), options, defaultValue); + } + + @Override + public boolean getAttributeBooleanValue(int index, boolean defaultValue) { + String value = getAttributeValue(index); + if (value != null) { + ResourceValue r = getResourceValue(value); + + if (r != null) { + value = r.getValue(); + } + + return XmlUtils.convertValueToBoolean(value, defaultValue); + } + + return defaultValue; + } + + @Override + public int getAttributeResourceValue(int index, int defaultValue) { + String value = getAttributeValue(index); + + return resolveResourceValue(value, defaultValue); + } + + @Override + public int getAttributeIntValue(int index, int defaultValue) { + String value = getAttributeValue(index); + if (value != null) { + ResourceValue r = getResourceValue(value); + + if (r != null) { + value = r.getValue(); + } + + return XmlUtils.convertValueToInt(value, defaultValue); + } + + return defaultValue; + } + + @Override + public int getAttributeUnsignedIntValue(int index, int defaultValue) { + String value = getAttributeValue(index); + if (value != null) { + ResourceValue r = getResourceValue(value); + + if (r != null) { + value = r.getValue(); + } + + return XmlUtils.convertValueToUnsignedInt(value, defaultValue); + } + + return defaultValue; + } + + @Override + public float getAttributeFloatValue(int index, float defaultValue) { + String s = getAttributeValue(index); + if (s != null) { + ResourceValue r = getResourceValue(s); + + if (r != null) { + s = r.getValue(); + } + + return Float.parseFloat(s); + } + + return defaultValue; + } + + // -- private helper methods + + /** + * Returns a resolved {@link ResourceValue} from a given value. + */ + private ResourceValue getResourceValue(String value) { // now look for this particular value RenderResources resources = mContext.getRenderResources(); - ResourceValue resource = resources.resolveResValue( - resources.findResValue(value, mPlatformFile)); + return resources.resolveResValue(resources.findResValue(value, mPlatformFile)); + } + /** + * Resolves and return a value to its associated integer. + */ + private int resolveResourceValue(String value, int defaultValue) { + ResourceValue resource = getResourceValue(value); if (resource != null) { Integer id = null; if (mPlatformFile || resource.isFramework()) { @@ -124,5 +280,4 @@ public class BridgeXmlPullAttributes extends XmlPullAttributes { return defaultValue; } - } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java index 33bf7bc..ff88209 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java @@ -24,8 +24,8 @@ import com.android.ide.common.rendering.api.DrawableParams; import com.android.ide.common.rendering.api.LayoutLog; import com.android.ide.common.rendering.api.RenderSession; import com.android.ide.common.rendering.api.Result; -import com.android.ide.common.rendering.api.SessionParams; import com.android.ide.common.rendering.api.Result.Status; +import com.android.ide.common.rendering.api.SessionParams; import com.android.layoutlib.bridge.impl.FontLoader; import com.android.layoutlib.bridge.impl.RenderDrawable; import com.android.layoutlib.bridge.impl.RenderSessionImpl; @@ -242,6 +242,8 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge { if (fontLoader != null) { Typeface_Delegate.init(fontLoader); } else { + log.error(LayoutLog.TAG_BROKEN, + "Failed create FontLoader in layout lib.", null); return false; } |