use of org.xmlpull.v1.XmlPullParserException in project XobotOS by xamarin.
the class SearchableInfo method getActivityMetaData.
/**
* Get the metadata for a given activity
*
* @param context runtime context
* @param xml XML parser for reading attributes
* @param cName The component name of the searchable activity
*
* @result A completely constructed SearchableInfo, or null if insufficient XML data for it
*/
private static SearchableInfo getActivityMetaData(Context context, XmlPullParser xml, final ComponentName cName) {
SearchableInfo result = null;
Context activityContext = createActivityContext(context, cName);
if (activityContext == null)
return null;
// forward through the file until it's reading the tag of interest.
try {
int tagType = xml.next();
while (tagType != XmlPullParser.END_DOCUMENT) {
if (tagType == XmlPullParser.START_TAG) {
if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE)) {
AttributeSet attr = Xml.asAttributeSet(xml);
if (attr != null) {
try {
result = new SearchableInfo(activityContext, attr, cName);
} catch (IllegalArgumentException ex) {
Log.w(LOG_TAG, "Invalid searchable metadata for " + cName.flattenToShortString() + ": " + ex.getMessage());
return null;
}
}
} else if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY)) {
if (result == null) {
// Can't process an embedded element if we haven't seen the enclosing
return null;
}
AttributeSet attr = Xml.asAttributeSet(xml);
if (attr != null) {
try {
result.addActionKey(new ActionKeyInfo(activityContext, attr));
} catch (IllegalArgumentException ex) {
Log.w(LOG_TAG, "Invalid action key for " + cName.flattenToShortString() + ": " + ex.getMessage());
return null;
}
}
}
}
tagType = xml.next();
}
} catch (XmlPullParserException e) {
Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
return null;
} catch (IOException e) {
Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
return null;
}
return result;
}
use of org.xmlpull.v1.XmlPullParserException in project XobotOS by xamarin.
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 XobotOS by xamarin.
the class InsetDrawable method inflate.
@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
int type;
TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.InsetDrawable);
super.inflateWithAttributes(r, parser, a, com.android.internal.R.styleable.InsetDrawable_visible);
int drawableRes = a.getResourceId(com.android.internal.R.styleable.InsetDrawable_drawable, 0);
int inLeft = a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetLeft, 0);
int inTop = a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetTop, 0);
int inRight = a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetRight, 0);
int inBottom = a.getDimensionPixelOffset(com.android.internal.R.styleable.InsetDrawable_insetBottom, 0);
a.recycle();
Drawable dr;
if (drawableRes != 0) {
dr = r.getDrawable(drawableRes);
} else {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription() + ": <inset> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
}
dr = Drawable.createFromXmlInner(r, parser, attrs);
}
if (dr == null) {
Log.w("drawable", "No drawable specified for <inset>");
}
mInsetState.mDrawable = dr;
mInsetState.mInsetLeft = inLeft;
mInsetState.mInsetRight = inRight;
mInsetState.mInsetTop = inTop;
mInsetState.mInsetBottom = inBottom;
if (dr != null) {
dr.setCallback(this);
}
}
use of org.xmlpull.v1.XmlPullParserException in project XobotOS by xamarin.
the class LayerDrawable method inflate.
@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
super.inflate(r, parser, attrs);
int type;
TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LayerDrawable);
mOpacityOverride = a.getInt(com.android.internal.R.styleable.LayerDrawable_opacity, PixelFormat.UNKNOWN);
a.recycle();
final int innerDepth = parser.getDepth() + 1;
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 || !parser.getName().equals("item")) {
continue;
}
a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LayerDrawableItem);
int left = a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_left, 0);
int top = a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_top, 0);
int right = a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_right, 0);
int bottom = a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_bottom, 0);
int drawableRes = a.getResourceId(com.android.internal.R.styleable.LayerDrawableItem_drawable, 0);
int id = a.getResourceId(com.android.internal.R.styleable.LayerDrawableItem_id, View.NO_ID);
a.recycle();
Drawable dr;
if (drawableRes != 0) {
dr = r.getDrawable(drawableRes);
} else {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
}
dr = Drawable.createFromXmlInner(r, parser, attrs);
}
addLayer(dr, id, left, top, right, bottom);
}
ensurePadding();
onStateChange(getState());
}
use of org.xmlpull.v1.XmlPullParserException in project XobotOS by xamarin.
the class LevelListDrawable method inflate.
@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
super.inflate(r, parser, attrs);
int type;
int low = 0;
final int innerDepth = parser.getDepth() + 1;
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 || !parser.getName().equals("item")) {
continue;
}
TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LevelListDrawableItem);
low = a.getInt(com.android.internal.R.styleable.LevelListDrawableItem_minLevel, 0);
int high = a.getInt(com.android.internal.R.styleable.LevelListDrawableItem_maxLevel, 0);
int drawableRes = a.getResourceId(com.android.internal.R.styleable.LevelListDrawableItem_drawable, 0);
a.recycle();
if (high < 0) {
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'maxLevel' attribute");
}
Drawable dr;
if (drawableRes != 0) {
dr = r.getDrawable(drawableRes);
} else {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
}
dr = Drawable.createFromXmlInner(r, parser, attrs);
}
mLevelListState.addLevel(low, high, dr);
}
onLevelChange(getLevel());
}
Aggregations