Search in sources :

Example 16 with AttributeSet

use of android.util.AttributeSet in project HoloEverywhere by Prototik.

the class DrawableCompat method createFromXml.

public static Drawable createFromXml(Resources r, XmlPullParser parser) throws XmlPullParserException, IOException {
    AttributeSet attrs = Xml.asAttributeSet(parser);
    int type;
    while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
    }
    if (type != XmlPullParser.START_TAG) {
        throw new XmlPullParserException("No start tag found");
    }
    Drawable drawable = createFromXmlInner(r, parser, attrs);
    if (drawable == null) {
        throw new RuntimeException("Unknown initial tag: " + parser.getName());
    }
    return drawable;
}
Also used : AttributeSet(android.util.AttributeSet) Drawable(android.graphics.drawable.Drawable) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 17 with AttributeSet

use of android.util.AttributeSet in project RoboBinding by RoboBinding.

the class MockAttributeSet method withAttributes.

public static AttributeSet withAttributes(int numBindingAttributes, int numNonBindingAttributes) {
    AttributeSet attributeSet = mock(AttributeSet.class);
    int attributeCount = numBindingAttributes + numNonBindingAttributes;
    when(attributeSet.getAttributeCount()).thenReturn(attributeCount);
    for (int i = 0; i < numBindingAttributes; i++) {
        String attributeName = "binding_attribute_" + i;
        when(attributeSet.getAttributeName(i)).thenReturn(attributeName);
        when(attributeSet.getAttributeValue(BindingAttributeParser.ROBOBINDING_NAMESPACE, attributeName)).thenReturn("binding_value_" + i);
    }
    for (int i = numBindingAttributes; i < attributeCount; i++) {
        when(attributeSet.getAttributeName(i)).thenReturn("non_binding_attribute_" + i);
    }
    return attributeSet;
}
Also used : AttributeSet(android.util.AttributeSet)

Example 18 with AttributeSet

use of android.util.AttributeSet in project RoboBinding by RoboBinding.

the class MockBindingAttributeSetBuilder method build.

public AttributeSet build() {
    AttributeSet attributeSet = mock(AttributeSet.class);
    when(attributeSet.getAttributeCount()).thenReturn(attributeMap.size());
    int i = 0;
    for (Map.Entry<String, String> attributeEntry : attributeMap.entrySet()) {
        String name = attributeEntry.getKey();
        String value = attributeEntry.getValue();
        when(attributeSet.getAttributeName(i)).thenReturn(name);
        when(attributeSet.getAttributeValue(eq(BindingAttributeParser.ROBOBINDING_NAMESPACE), eq(name))).thenReturn(value);
        i++;
    }
    return attributeSet;
}
Also used : AttributeSet(android.util.AttributeSet) Map(java.util.Map)

Example 19 with AttributeSet

use of android.util.AttributeSet in project ElasticDownload by Tibolte.

the class AnimatedVectorDrawable method create.

public static AnimatedVectorDrawable create(Context c, 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");
        } else if (!ANIMATED_VECTOR.equals(parser.getName())) {
            throw new IllegalArgumentException("root node must start with: " + ANIMATED_VECTOR);
        }
        final AnimatedVectorDrawable drawable = new AnimatedVectorDrawable();
        drawable.inflate(c, resources, parser, attrs, null);
        return drawable;
    } catch (XmlPullParserException e) {
        Log.e(LOG_TAG, "parser error", e);
    } catch (IOException e) {
        Log.e(LOG_TAG, "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)

Example 20 with AttributeSet

use of android.util.AttributeSet in project ElasticDownload by Tibolte.

the class VectorDrawable 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");
        } else if (!SHAPE_VECTOR.equals(parser.getName())) {
            throw new IllegalArgumentException("root node must start with: " + SHAPE_VECTOR);
        }
        final VectorDrawable drawable = new VectorDrawable();
        drawable.inflate(resources, parser, attrs, null);
        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) Paint(android.graphics.Paint)

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