Search in sources :

Example 21 with AttributeSet

use of android.util.AttributeSet in project Carbon by ZieIony.

the class CarbonResources method createFromXml.

/**
     * Create a drawable from an XML document using an optional {@link Resources.Theme}.
     * For more information on how to create resources in XML, see
     * <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.
     */
public Drawable createFromXml(XmlPullParser parser, Resources.Theme theme) 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");
    }
    Drawable drawable = createFromXmlInner(parser, attrs, theme);
    if (drawable == null) {
        throw new RuntimeException("Unknown initial tag: " + parser.getName());
    }
    return drawable;
}
Also used : AttributeSet(android.util.AttributeSet) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) VectorDrawable(carbon.drawable.VectorDrawable) LollipopDrawable(carbon.drawable.ripple.LollipopDrawable) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 22 with AttributeSet

use of android.util.AttributeSet in project remusic by aa112901.

the class ColorStateListUtils method createColorStateList.

static ColorStateList createColorStateList(Context context, int resId) {
    if (resId <= 0)
        return null;
    TypedValue value = new TypedValue();
    context.getResources().getValue(resId, value, true);
    ColorStateList cl = null;
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        //Assume that "color/theme_color_primary" and "color/theme_color_profile" have the same color value;
        //However, "color/theme_color_primary" need to replace by themeId, "color/theme_color_profile" not.
        //If use value.data may cause "color/theme_color_profile" still been replaced by themeId
        cl = ColorStateList.valueOf(ThemeUtils.replaceColorById(context, value.resourceId));
    } else {
        final String file = value.string.toString();
        try {
            if (file.endsWith("xml")) {
                final XmlResourceParser rp = context.getResources().getAssets().openXmlResourceParser(value.assetCookie, file);
                final AttributeSet attrs = Xml.asAttributeSet(rp);
                int type;
                while ((type = rp.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
                // Seek parser to start tag.
                }
                if (type != XmlPullParser.START_TAG) {
                    throw new XmlPullParserException("No start tag found");
                }
                cl = createFromXmlInner(context, rp, attrs);
                rp.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }
    }
    return cl;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) ColorStateList(android.content.res.ColorStateList) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) TypedValue(android.util.TypedValue)

Example 23 with AttributeSet

use of android.util.AttributeSet in project SmartAndroidSource by jaychou2012.

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) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 24 with AttributeSet

use of android.util.AttributeSet in project httpclient by pixmob.

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) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 25 with AttributeSet

use of android.util.AttributeSet in project FloatingSearchView by renaudcerrato.

the class FloatingSearchView method inflateMenu.

public void inflateMenu(@MenuRes int menuRes) {
    if (menuRes == 0)
        return;
    if (isInEditMode())
        return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());
    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Aggregations

AttributeSet (android.util.AttributeSet)262 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)160 IOException (java.io.IOException)125 XmlResourceParser (android.content.res.XmlResourceParser)113 TypedArray (android.content.res.TypedArray)78 Resources (android.content.res.Resources)46 Test (org.junit.Test)42 TypedValue (android.util.TypedValue)34 InflateException (android.view.InflateException)28 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)24 PackageManager (android.content.pm.PackageManager)22 Context (android.content.Context)20 ComponentName (android.content.ComponentName)18 XmlPullParser (org.xmlpull.v1.XmlPullParser)17 Intent (android.content.Intent)11 RemoteException (android.os.RemoteException)11 Bundle (android.os.Bundle)9 ArrayList (java.util.ArrayList)9 ActivityInfo (android.content.pm.ActivityInfo)7 ApplicationInfo (android.content.pm.ApplicationInfo)7