Search in sources :

Example 71 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class VectorDrawablePerformance method create.

public static VectorDrawable create(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");
        }
        final VectorDrawable drawable = new VectorDrawable();
        drawable.inflate(resources, parser, attrs);
        return drawable;
    } catch (XmlPullParserException e) {
        Log.e(LOGCAT, "parser error", e);
    } catch (IOException e) {
        Log.e(LOGCAT, "parser error", e);
    }
    return null;
}
Also used : AttributeSet(android.util.AttributeSet) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) VectorDrawable(android.graphics.drawable.VectorDrawable)

Example 72 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class AnimatedVectorDrawableDupPerf method create.

/** @hide */
public static AnimatedVectorDrawable create(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");
        }
        final AnimatedVectorDrawable drawable = new AnimatedVectorDrawable();
        drawable.inflate(resources, parser, attrs);
        return drawable;
    } catch (XmlPullParserException e) {
        Log.e(LOGTAG, "parser error", e);
    } catch (IOException e) {
        Log.e(LOGTAG, "parser error", e);
    }
    return null;
}
Also used : AttributeSet(android.util.AttributeSet) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 73 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class GenericInflater method inflate.

/**
     * Inflate a new hierarchy from the specified XML node. Throws
     * InflaterException if there is an error.
     * <p>
     * <em><strong>Important</strong></em>&nbsp;&nbsp;&nbsp;For performance
     * reasons, inflation relies heavily on pre-processing of XML files
     * that is done at build time. Therefore, it is not currently possible to
     * use inflater with an XmlPullParser over a plain XML file at runtime.
     * 
     * @param parser XML dom node containing the description of the
     *        hierarchy.
     * @param root Optional to be the parent of the generated hierarchy (if
     *        <em>attachToRoot</em> is true), or else simply an object that
     *        provides a set of values for root of the returned
     *        hierarchy (if <em>attachToRoot</em> is false.)
     * @param attachToRoot Whether the inflated hierarchy should be attached to
     *        the root parameter?
     * @return The root of the inflated hierarchy. If root was supplied and
     *         attachToRoot is true, this is root; otherwise it is the root of
     *         the inflated XML file.
     */
public T inflate(XmlPullParser parser, P root, boolean attachToRoot) {
    synchronized (mConstructorArgs) {
        final AttributeSet attrs = Xml.asAttributeSet(parser);
        mConstructorArgs[0] = mContext;
        T result = (T) root;
        try {
            // Look for the root node.
            int type;
            while ((type = parser.next()) != parser.START_TAG && type != parser.END_DOCUMENT) {
                ;
            }
            if (type != parser.START_TAG) {
                throw new InflateException(parser.getPositionDescription() + ": No start tag found!");
            }
            if (DEBUG) {
                System.out.println("**************************");
                System.out.println("Creating root: " + parser.getName());
                System.out.println("**************************");
            }
            // Temp is the root that was found in the xml
            T xmlRoot = createItemFromTag(parser, parser.getName(), attrs);
            result = (T) onMergeRoots(root, attachToRoot, (P) xmlRoot);
            if (DEBUG) {
                System.out.println("-----> start inflating children");
            }
            // Inflate all children under temp
            rInflate(parser, result, attrs);
            if (DEBUG) {
                System.out.println("-----> done inflating children");
            }
        } catch (InflateException e) {
            throw e;
        } catch (XmlPullParserException e) {
            InflateException ex = new InflateException(e.getMessage());
            ex.initCause(e);
            throw ex;
        } catch (IOException e) {
            InflateException ex = new InflateException(parser.getPositionDescription() + ": " + e.getMessage());
            ex.initCause(e);
            throw ex;
        }
        return result;
    }
}
Also used : AttributeSet(android.util.AttributeSet) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 74 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class OverlayBaseTest method testAppXml.

public void testAppXml() throws Throwable {
    int expected = getExpected(0, 1, 2);
    int actual = -1;
    XmlResourceParser parser = mResources.getXml(R.xml.integer);
    int type = parser.getEventType();
    while (type != XmlResourceParser.END_DOCUMENT && actual == -1) {
        if (type == XmlResourceParser.START_TAG && "integer".equals(parser.getName())) {
            AttributeSet as = Xml.asAttributeSet(parser);
            actual = as.getAttributeIntValue(null, "value", -1);
        }
        type = parser.next();
    }
    parser.close();
    assertEquals(expected, actual);
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet)

Example 75 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class AnimationUtils method createInterpolatorFromXml.

private static Interpolator createInterpolatorFromXml(Resources res, Theme theme, XmlPullParser parser) throws XmlPullParserException, IOException {
    BaseInterpolator interpolator = null;
    // Make sure we are on a start tag.
    int type;
    int depth = parser.getDepth();
    while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        AttributeSet attrs = Xml.asAttributeSet(parser);
        String name = parser.getName();
        if (name.equals("linearInterpolator")) {
            interpolator = new LinearInterpolator();
        } else if (name.equals("accelerateInterpolator")) {
            interpolator = new AccelerateInterpolator(res, theme, attrs);
        } else if (name.equals("decelerateInterpolator")) {
            interpolator = new DecelerateInterpolator(res, theme, attrs);
        } else if (name.equals("accelerateDecelerateInterpolator")) {
            interpolator = new AccelerateDecelerateInterpolator();
        } else if (name.equals("cycleInterpolator")) {
            interpolator = new CycleInterpolator(res, theme, attrs);
        } else if (name.equals("anticipateInterpolator")) {
            interpolator = new AnticipateInterpolator(res, theme, attrs);
        } else if (name.equals("overshootInterpolator")) {
            interpolator = new OvershootInterpolator(res, theme, attrs);
        } else if (name.equals("anticipateOvershootInterpolator")) {
            interpolator = new AnticipateOvershootInterpolator(res, theme, attrs);
        } else if (name.equals("bounceInterpolator")) {
            interpolator = new BounceInterpolator();
        } else if (name.equals("pathInterpolator")) {
            interpolator = new PathInterpolator(res, theme, attrs);
        } else {
            throw new RuntimeException("Unknown interpolator name: " + parser.getName());
        }
    }
    return interpolator;
}
Also used : AttributeSet(android.util.AttributeSet)

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