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