use of org.xmlpull.v1.XmlPullParser in project HoloEverywhere by Prototik.
the class XmlUtils method readSetXml.
public static final HashSet readSetXml(InputStream in) throws XmlPullParserException, java.io.IOException {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, null);
return (HashSet) XmlUtils.readValueXml(parser, new String[1]);
}
use of org.xmlpull.v1.XmlPullParser in project HoloEverywhere by Prototik.
the class XmlUtils method readThisIntArrayXml.
public static final int[] readThisIntArrayXml(XmlPullParser parser, String endTag, String[] name) throws XmlPullParserException, java.io.IOException {
int num;
try {
num = Integer.parseInt(parser.getAttributeValue(null, "num"));
} catch (NullPointerException e) {
throw new XmlPullParserException("Need num attribute in byte-array");
} catch (NumberFormatException e) {
throw new XmlPullParserException("Not a number in num attribute in byte-array");
}
int[] array = new int[num];
int i = 0;
int eventType = parser.getEventType();
do {
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
try {
array[i] = Integer.parseInt(parser.getAttributeValue(null, "value"));
} catch (NullPointerException e) {
throw new XmlPullParserException("Need value attribute in item");
} catch (NumberFormatException e) {
throw new XmlPullParserException("Not a number in value attribute in item");
}
} else {
throw new XmlPullParserException("Expected item tag at: " + parser.getName());
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(endTag)) {
return array;
} else if (parser.getName().equals("item")) {
i++;
} else {
throw new XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName());
}
}
eventType = parser.next();
} while (eventType != XmlPullParser.END_DOCUMENT);
throw new XmlPullParserException("Document ended before " + endTag + " end tag");
}
use of org.xmlpull.v1.XmlPullParser in project DesignLibrary by StylingAndroid.
the class SaRssParser method newInstance.
public static SaRssParser newInstance(InputStream inputStream) {
XmlPullParserFactory factory;
XmlPullParser parser = null;
try {
factory = XmlPullParserFactory.newInstance();
parser = factory.newPullParser();
parser.setInput(inputStream, DEFAULT_CHARSET);
} catch (XmlPullParserException e) {
e.printStackTrace();
}
return new SaRssParser(parser);
}
use of org.xmlpull.v1.XmlPullParser in project ElasticDownload by Tibolte.
the class AnimatedVectorDrawable method create.
public static AnimatedVectorDrawable create(Context c, Resources resources, int rid) {
try {
final XmlPullParser parser = resources.getXml(rid);
final AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Empty loop
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
} else if (!ANIMATED_VECTOR.equals(parser.getName())) {
throw new IllegalArgumentException("root node must start with: " + ANIMATED_VECTOR);
}
final AnimatedVectorDrawable drawable = new AnimatedVectorDrawable();
drawable.inflate(c, resources, parser, attrs, null);
return drawable;
} catch (XmlPullParserException e) {
Log.e(LOG_TAG, "parser error", e);
} catch (IOException e) {
Log.e(LOG_TAG, "parser error", e);
}
return null;
}
use of org.xmlpull.v1.XmlPullParser in project ElasticDownload by Tibolte.
the class VectorDrawable method inflateInternal.
private void inflateInternal(Resources res, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
final VectorDrawableState state = mVectorState;
final VPathRenderer pathRenderer = state.mVPathRenderer;
boolean noPathTag = true;
// Use a stack to help to build the group tree.
// The top of the stack is always the current group.
final Stack<VGroup> groupStack = new Stack<VGroup>();
groupStack.push(pathRenderer.mRootGroup);
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
final String tagName = parser.getName();
final VGroup currentGroup = groupStack.peek();
if (SHAPE_PATH.equals(tagName)) {
final VFullPath path = new VFullPath();
path.inflate(res, attrs, theme);
currentGroup.mChildren.add(path);
if (path.getPathName() != null) {
pathRenderer.mVGTargetsMap.put(path.getPathName(), path);
}
noPathTag = false;
state.mChangingConfigurations |= path.mChangingConfigurations;
} else if (SHAPE_CLIP_PATH.equals(tagName)) {
final VClipPath path = new VClipPath();
path.inflate(res, attrs, theme);
currentGroup.mChildren.add(path);
if (path.getPathName() != null) {
pathRenderer.mVGTargetsMap.put(path.getPathName(), path);
}
state.mChangingConfigurations |= path.mChangingConfigurations;
} else if (SHAPE_GROUP.equals(tagName)) {
VGroup newChildGroup = new VGroup();
newChildGroup.inflate(res, attrs, theme);
currentGroup.mChildren.add(newChildGroup);
groupStack.push(newChildGroup);
if (newChildGroup.getGroupName() != null) {
pathRenderer.mVGTargetsMap.put(newChildGroup.getGroupName(), newChildGroup);
}
state.mChangingConfigurations |= newChildGroup.mChangingConfigurations;
}
} else if (eventType == XmlPullParser.END_TAG) {
final String tagName = parser.getName();
if (SHAPE_GROUP.equals(tagName)) {
groupStack.pop();
}
}
eventType = parser.next();
}
// Print the tree out for debug.
if (DBG_VECTOR_DRAWABLE) {
printGroupTree(pathRenderer.mRootGroup, 0);
}
if (noPathTag) {
final StringBuffer tag = new StringBuffer();
if (tag.length() > 0) {
tag.append(" or ");
}
tag.append(SHAPE_PATH);
throw new XmlPullParserException("no " + tag + " defined");
}
}
Aggregations