summaryrefslogtreecommitdiff
path: root/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
diff options
context:
space:
mode:
Diffstat (limited to 'tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java')
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java42
1 files changed, 11 insertions, 31 deletions
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 90adf5a47644..21e18f21c1f7 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
@@ -24,10 +24,10 @@ import com.android.ide.common.rendering.api.StyleResourceValue;
import com.android.internal.util.XmlUtils;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
+import com.android.layoutlib.bridge.impl.ParserFactory;
import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.resources.ResourceType;
-import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -41,7 +41,6 @@ import android.view.LayoutInflater_Delegate;
import android.view.ViewGroup.LayoutParams;
import java.io.File;
-import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Map;
@@ -211,7 +210,7 @@ public final class BridgeTypedArray extends TypedArray {
Map<String, Integer> map = null;
if (mPlatformStyleable) {
map = Bridge.getEnumValues(mNames[index]);
- } else {
+ } else if (mStyleableName != null) {
// get the styleable matching the resolved name
RenderResources res = mContext.getRenderResources();
ResourceValue styleable = res.getProjectResource(ResourceType.DECLARE_STYLEABLE,
@@ -331,9 +330,7 @@ public final class BridgeTypedArray extends TypedArray {
File f = new File(value);
if (f.isFile()) {
try {
- KXmlParser parser = new KXmlParser();
- parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- parser.setInput(new FileInputStream(f), "UTF-8"); //$NON-NLS-1$);
+ XmlPullParser parser = ParserFactory.create(f);
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(
parser, mContext, resValue.isFramework());
@@ -377,26 +374,7 @@ public final class BridgeTypedArray extends TypedArray {
*/
@Override
public int getInteger(int index, int defValue) {
- if (mResourceData[index] == null) {
- return defValue;
- }
-
- String s = mResourceData[index].getValue();
-
- if (s != null) {
- try {
- return Integer.parseInt(s);
- } catch (NumberFormatException e) {
- Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
- String.format(
- "\"%s\" in attribute \"%2$s\" cannont be converted to an integer.",
- s, mNames[index]), null /*data*/);
-
- // The default value is returned below.
- }
- }
-
- return defValue;
+ return getInt(index, defValue);
}
/**
@@ -434,7 +412,7 @@ public final class BridgeTypedArray extends TypedArray {
return defValue;
}
- if (ResourceHelper.stringToFloat(s, mValue)) {
+ if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) {
return mValue.getDimension(mBridgeResources.mMetrics);
}
@@ -561,7 +539,7 @@ public final class BridgeTypedArray extends TypedArray {
throw new RuntimeException();
}
- if (ResourceHelper.stringToFloat(s, mValue)) {
+ if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) {
float f = mValue.getDimension(mBridgeResources.mMetrics);
final int res = (int)(f+0.5f);
@@ -599,14 +577,15 @@ public final class BridgeTypedArray extends TypedArray {
return defValue;
}
- if (ResourceHelper.stringToFloat(value, mValue)) {
+ if (ResourceHelper.parseFloatAttribute(mNames[index], value, mValue,
+ false /*requireUnit*/)) {
return mValue.getFraction(base, pbase);
}
// looks like we were unable to resolve the fraction value
Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT,
String.format(
- "\"%1$s\" in attribute \"%2$s\" cannont be converted to a fraction.",
+ "\"%1$s\" in attribute \"%2$s\" cannot be converted to a fraction.",
value, mNames[index]), null /*data*/);
return defValue;
@@ -803,7 +782,8 @@ public final class BridgeTypedArray extends TypedArray {
String s = mResourceData[index].getValue();
- return ResourceHelper.stringToFloat(s, outValue);
+ return ResourceHelper.parseFloatAttribute(mNames[index], s, outValue,
+ false /*requireUnit*/);
}
/**