Search in sources :

Example 51 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 52 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 53 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 54 with AttributeSet

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

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 55 with AttributeSet

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

the class ColorStateList method createFromXml.

/**
     * Create a ColorStateList from an XML document, given a set of {@link Resources}.
     */
public static ColorStateList 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");
    }
    return createFromXmlInner(r, parser, attrs);
}
Also used : AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

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