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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations