use of org.xmlpull.v1.XmlPullParserException in project cw-omnibus by commonsguy.
the class MenuInflater method inflate.
/**
* Inflate a menu hierarchy from the specified XML resource. Throws
* {@link InflateException} if there is an error.
*
* @param menuRes Resource ID for an XML layout resource to load (e.g.,
* <code>R.menu.main_activity</code>)
* @param menu The Menu to inflate into. The items and submenus will be
* added to this Menu.
*/
public void inflate(int menuRes, Menu menu) {
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(parser, attrs, menu);
} catch (XmlPullParserException e) {
throw new InflateException("Error inflating menu XML", e);
} catch (IOException e) {
throw new InflateException("Error inflating menu XML", e);
} finally {
if (parser != null)
parser.close();
}
}
use of org.xmlpull.v1.XmlPullParserException in project material-icon-lib by code-mc.
the class MaterialMenuInflater method afterInflate.
private void afterInflate(int menuRes, Menu menu) {
IconData root = new IconData(0, 0, 0);
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(parser, attrs, root);
} catch (XmlPullParserException e) {
throw new InflateException("Error inflating menu XML", e);
} catch (IOException e) {
throw new InflateException("Error inflating menu XML", e);
} finally {
if (parser != null)
parser.close();
// populate the menu with the parsed icons
populateIcons(menu, root, mDefaultColor);
}
}
use of org.xmlpull.v1.XmlPullParserException in project GreenDroid by cyrilmottier.
the class ItemAdapter method createFromXml.
/**
* Creates an ItemAdapter from a given XML document. Called on a parser
* positioned at a tag in an XML document, tries to create an ItemAdapter
* from that tag.
*
* @param context The Context in which the ItemAdapter will be used in
* @param parser The XmlPullParser
* @return a new ItemAdapter constructed with the content of the file
* pointed by <em>xmlId</em>
* @throws XmlPullParserException
* @throws IOException
*/
public static ItemAdapter createFromXml(Context context, XmlPullParser parser) throws XmlPullParserException, IOException {
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");
}
if (!parser.getName().equals("item-array")) {
throw new XmlPullParserException("Unknown start tag. Should be 'item-array'");
}
final List<Item> items = new ArrayList<Item>();
final int innerDepth = parser.getDepth() + 1;
final Resources r = context.getResources();
int depth;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth) {
continue;
}
String name = parser.getName();
Item item;
if (name.equals("text-item")) {
item = new TextItem();
} else if (name.equals("longtext-item")) {
item = new LongTextItem();
} else if (name.equals("description-item")) {
item = new DescriptionItem();
} else if (name.equals("separator-item")) {
item = new SeparatorItem();
} else if (name.equals("progress-item")) {
item = new ProgressItem();
} else if (name.equals("drawable-item")) {
item = new DrawableItem();
} else if (name.equals("subtitle-item")) {
item = new SubtitleItem();
} else if (name.equals("subtext-item")) {
item = new SubtextItem();
} else if (name.equals("thumbnail-item")) {
item = new ThumbnailItem();
} else {
// ItemAdapter and creates our own items via XML?
throw new XmlPullParserException(parser.getPositionDescription() + ": invalid item tag " + name);
}
if (item != null) {
item.inflate(r, parser, attrs);
items.add(item);
}
}
return new ItemAdapter(context, items);
}
use of org.xmlpull.v1.XmlPullParserException in project Libraries-for-Android-Developers by eoecn.
the class MenuInflater method inflate.
/**
* Inflate a menu hierarchy from the specified XML resource. Throws
* {@link InflateException} if there is an error.
*
* @param menuRes Resource ID for an XML layout resource to load (e.g.,
* <code>R.menu.main_activity</code>)
* @param menu The Menu to inflate into. The items and submenus will be
* added to this Menu.
*/
public void inflate(int menuRes, Menu menu) {
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(parser, attrs, menu);
} catch (XmlPullParserException e) {
throw new InflateException("Error inflating menu XML", e);
} catch (IOException e) {
throw new InflateException("Error inflating menu XML", e);
} finally {
if (parser != null)
parser.close();
}
}
use of org.xmlpull.v1.XmlPullParserException in project android-job by evernote.
the class XmlUtils method readThisLongArrayXml.
/**
* Read a long[] object from an XmlPullParser. The XML data could
* previously have been generated by writeLongArrayXml(). The XmlPullParser
* must be positioned <em>after</em> the tag that begins the list.
*
* @param parser The XmlPullParser from which to read the list data.
* @param endTag Name of the tag that will end the list, usually "list".
* @param name An array of one string, used to return the name attribute
* of the list's tag.
*
* @return Returns a newly generated long[].
*
* @see #readListXml
*/
public static final long[] readThisLongArrayXml(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 long-array");
} catch (NumberFormatException e) {
throw new XmlPullParserException("Not a number in num attribute in long-array");
}
parser.next();
long[] array = new long[num];
int i = 0;
int eventType = parser.getEventType();
do {
if (eventType == parser.START_TAG) {
if (parser.getName().equals("item")) {
try {
array[i] = Long.parseLong(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 == parser.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 != parser.END_DOCUMENT);
throw new XmlPullParserException("Document ended before " + endTag + " end tag");
}
Aggregations