Search in sources :

Example 36 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser 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 37 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project HoloEverywhere by Prototik.

the class LayerDrawable method inflate.

@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
    super.inflate(r, parser, attrs);
    int type;
    TypedArray a = r.obtainAttributes(attrs, R.styleable.LayerDrawable);
    mOpacityOverride = a.getInt(R.styleable.LayerDrawable_android_opacity, PixelFormat.UNKNOWN);
    a.recycle();
    final int innerDepth = parser.getDepth() + 1;
    int depth;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        if (depth > innerDepth || !parser.getName().equals("item")) {
            continue;
        }
        a = r.obtainAttributes(attrs, R.styleable.LayerDrawableItem);
        int left = a.getDimensionPixelOffset(R.styleable.LayerDrawableItem_android_left, 0);
        int top = a.getDimensionPixelOffset(R.styleable.LayerDrawableItem_android_top, 0);
        int right = a.getDimensionPixelOffset(R.styleable.LayerDrawableItem_android_right, 0);
        int bottom = a.getDimensionPixelOffset(R.styleable.LayerDrawableItem_android_bottom, 0);
        int drawableRes = a.getResourceId(R.styleable.LayerDrawableItem_android_drawable, 0);
        int id = a.getResourceId(R.styleable.LayerDrawableItem_android_id, View.NO_ID);
        a.recycle();
        Drawable dr;
        if (drawableRes != 0) {
            dr = DrawableCompat.getDrawable(r, drawableRes);
        } else {
            while ((type = parser.next()) == XmlPullParser.TEXT) {
            }
            if (type != XmlPullParser.START_TAG) {
                throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
            }
            dr = DrawableCompat.createFromXmlInner(r, parser, attrs);
        }
        addLayer(dr, id, left, top, right, bottom);
    }
    ensurePadding();
    onStateChange(getState());
}
Also used : TypedArray(android.content.res.TypedArray) Drawable(android.graphics.drawable.Drawable) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 38 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project HoloEverywhere by Prototik.

the class XmlUtils method readListXml.

public static final ArrayList readListXml(InputStream in) throws XmlPullParserException, java.io.IOException {
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(in, null);
    return (ArrayList) XmlUtils.readValueXml(parser, new String[1]);
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) ArrayList(java.util.ArrayList)

Example 39 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project HoloEverywhere by Prototik.

the class XmlUtils method readThisListXml.

public static final ArrayList readThisListXml(XmlPullParser parser, String endTag, String[] name) throws XmlPullParserException, java.io.IOException {
    ArrayList list = new ArrayList();
    int eventType = parser.getEventType();
    do {
        if (eventType == XmlPullParser.START_TAG) {
            Object val = XmlUtils.readThisValueXml(parser, name);
            list.add(val);
        // System.out.println("Adding to list: " + val);
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals(endTag)) {
                return list;
            }
            throw new XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName());
        }
        eventType = parser.next();
    } while (eventType != XmlPullParser.END_DOCUMENT);
    throw new XmlPullParserException("Document ended before " + endTag + " end tag");
}
Also used : ArrayList(java.util.ArrayList) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 40 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project HoloEverywhere by Prototik.

the class XmlUtils method readThisSetXml.

public static final HashSet readThisSetXml(XmlPullParser parser, String endTag, String[] name) throws XmlPullParserException, java.io.IOException {
    HashSet set = new HashSet();
    int eventType = parser.getEventType();
    do {
        if (eventType == XmlPullParser.START_TAG) {
            Object val = XmlUtils.readThisValueXml(parser, name);
            set.add(val);
        // System.out.println("Adding to set: " + val);
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals(endTag)) {
                return set;
            }
            throw new XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName());
        }
        eventType = parser.next();
    } while (eventType != XmlPullParser.END_DOCUMENT);
    throw new XmlPullParserException("Document ended before " + endTag + " end tag");
}
Also used : XmlPullParserException(org.xmlpull.v1.XmlPullParserException) HashSet(java.util.HashSet)

Aggregations

XmlPullParser (org.xmlpull.v1.XmlPullParser)665 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)614 IOException (java.io.IOException)376 FileNotFoundException (java.io.FileNotFoundException)185 FileInputStream (java.io.FileInputStream)184 File (java.io.File)107 ArrayList (java.util.ArrayList)75 StringReader (java.io.StringReader)65 AttributeSet (android.util.AttributeSet)61 Test (org.junit.Test)57 TypedArray (android.content.res.TypedArray)56 InputStream (java.io.InputStream)48 AtomicFile (android.util.AtomicFile)47 HashMap (java.util.HashMap)42 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)39 FileReader (java.io.FileReader)36 BufferedInputStream (java.io.BufferedInputStream)30 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)29 RemoteException (android.os.RemoteException)28 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)28