return null;
}
- String value = mResourceData[index].getValue();
+ ResourceValue resValue = mResourceData[index];
+ String value = resValue.getValue();
if (value == null) {
return null;
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(new FileReader(f));
- ColorStateList colorStateList = ColorStateList.createFromXml(
- mContext.getResources(),
- // FIXME: we need to know if this resource is platform or not
- new BridgeXmlBlockParser(parser, mContext, false));
- return colorStateList;
+ BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(
+ parser, mContext, resValue.isFramework());
+ try {
+ return ColorStateList.createFromXml(mContext.getResources(), blockParser);
+ } finally {
+ blockParser.ensurePopped();
+ }
} catch (XmlPullParserException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN,
"Failed to configure parser for " + value, e, null /*data*/);
private boolean mStarted = false;
private int mEventType = START_DOCUMENT;
+ private boolean mPopped = true; // default to true in case it's not pushed.
+
/**
* Builds a {@link BridgeXmlBlockParser}.
* @param parser The XmlPullParser to get the content from.
if (mContext != null) {
mContext.pushParser(this);
+ mPopped = false;
}
}
return null;
}
+ public void ensurePopped() {
+ if (mContext != null && mPopped == false) {
+ mContext.popParser();
+ mPopped = true;
+ }
+ }
+
// ------- XmlResourceParser implementation
public void setFeature(String name, boolean state)
}
int ev = mParser.next();
- if (ev == END_TAG && mParser.getDepth() == 1 && mContext != null) {
+ if (ev == END_TAG && mParser.getDepth() == 1) {
// done with parser remove it from the context stack.
- mContext.popParser();
+ ensurePopped();
}
mEventType = ev;
return ev;
"UTF8");
BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(
- parser, (BridgeContext) context, false);
+ parser, (BridgeContext) context, false /*platformFile*/);
- inflater.inflate(bridgeParser, this, true);
+ try {
+ inflater.inflate(bridgeParser, this, true);
+ } finally {
+ bridgeParser.ensurePopped();
+ }
}
private InputStream getIcon(String iconName, Density[] densityInOut, String[] pathOut,
context.setBridgeInflater(mInflater);
mInflater.setFactory2(context);
- mBlockParser = new BridgeXmlBlockParser(params.getLayoutDescription(),
- context, false /* platformResourceFlag */);
+ mBlockParser = new BridgeXmlBlockParser(
+ params.getLayoutDescription(), context, false /* platformResourceFlag */);
return SUCCESS.createResult();
}
BridgeContext context = getContext();
// create a block parser for the XML
- BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(childXml, context,
- false /* platformResourceFlag */);
+ BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(
+ childXml, context, false /* platformResourceFlag */);
// inflate the child without adding it to the root since we want to control where it'll
// get added. We do pass the parentView however to ensure that the layoutParams will
// be created correctly.
final View child = mInflater.inflate(blockParser, parentView, false /*attachToRoot*/);
+ blockParser.ensurePopped();
invalidateRenderingSize();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(new FileReader(f));
- return ColorStateList.createFromXml(context.getResources(),
- new BridgeXmlBlockParser(parser, context, resValue.isFramework()));
+ BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(
+ parser, context, resValue.isFramework());
+ try {
+ return ColorStateList.createFromXml(context.getResources(), blockParser);
+ } finally {
+ blockParser.ensurePopped();
+ }
} catch (XmlPullParserException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN,
"Failed to configure parser for " + value, e, null /*data*/);
* @param context the current context
*/
public static Drawable getDrawable(ResourceValue value, BridgeContext context) {
- Drawable d = null;
-
String stringValue = value.getValue();
if (RenderResources.REFERENCE_NULL.equals(stringValue)) {
return null;
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(new FileReader(f));
- d = Drawable.createFromXml(context.getResources(),
- new BridgeXmlBlockParser(parser, context, value.isFramework()));
- return d;
+ BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(
+ parser, context, value.isFramework());
+ try {
+ return Drawable.createFromXml(context.getResources(), blockParser);
+ } finally {
+ blockParser.ensurePopped();
+ }
} catch (Exception e) {
// this is an error and not warning since the file existence is checked before
// attempting to parse it.