Search in sources :

Example 86 with XmlPullParserException

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;
}
Also used : Context(android.content.Context) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 87 with XmlPullParserException

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();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 88 with XmlPullParserException

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);
    }
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 89 with XmlPullParserException

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());
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 90 with XmlPullParserException

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());
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Aggregations

XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1071 IOException (java.io.IOException)630 XmlPullParser (org.xmlpull.v1.XmlPullParser)440 FileNotFoundException (java.io.FileNotFoundException)187 XmlResourceParser (android.content.res.XmlResourceParser)186 FileInputStream (java.io.FileInputStream)182 AttributeSet (android.util.AttributeSet)159 TypedArray (android.content.res.TypedArray)156 Resources (android.content.res.Resources)101 File (java.io.File)101 ArrayList (java.util.ArrayList)99 PackageManager (android.content.pm.PackageManager)62 HashMap (java.util.HashMap)58 ComponentName (android.content.ComponentName)57 InputStream (java.io.InputStream)57 Intent (android.content.Intent)54 XmlSerializer (org.xmlpull.v1.XmlSerializer)54 AtomicFile (android.util.AtomicFile)50 BufferedInputStream (java.io.BufferedInputStream)44 TypedValue (android.util.TypedValue)43