Search in sources :

Example 66 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project XobotOS by xamarin.

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, com.android.internal.R.styleable.LayerDrawable);
    mOpacityOverride = a.getInt(com.android.internal.R.styleable.LayerDrawable_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, com.android.internal.R.styleable.LayerDrawableItem);
        int left = a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_left, 0);
        int top = a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_top, 0);
        int right = a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_right, 0);
        int bottom = a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_bottom, 0);
        int drawableRes = a.getResourceId(com.android.internal.R.styleable.LayerDrawableItem_drawable, 0);
        int id = a.getResourceId(com.android.internal.R.styleable.LayerDrawableItem_id, View.NO_ID);
        a.recycle();
        Drawable dr;
        if (drawableRes != 0) {
            dr = r.getDrawable(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 = Drawable.createFromXmlInner(r, parser, attrs);
        }
        addLayer(dr, id, left, top, right, bottom);
    }
    ensurePadding();
    onStateChange(getState());
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 67 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project XobotOS by xamarin.

the class LevelListDrawable method inflate.

@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
    super.inflate(r, parser, attrs);
    int type;
    int low = 0;
    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;
        }
        TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LevelListDrawableItem);
        low = a.getInt(com.android.internal.R.styleable.LevelListDrawableItem_minLevel, 0);
        int high = a.getInt(com.android.internal.R.styleable.LevelListDrawableItem_maxLevel, 0);
        int drawableRes = a.getResourceId(com.android.internal.R.styleable.LevelListDrawableItem_drawable, 0);
        a.recycle();
        if (high < 0) {
            throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'maxLevel' attribute");
        }
        Drawable dr;
        if (drawableRes != 0) {
            dr = r.getDrawable(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 = Drawable.createFromXmlInner(r, parser, attrs);
        }
        mLevelListState.addLevel(low, high, dr);
    }
    onLevelChange(getLevel());
}
Also used : TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 68 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project XobotOS by xamarin.

the class NinePatchDrawable method inflate.

@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
    super.inflate(r, parser, attrs);
    TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.NinePatchDrawable);
    final int id = a.getResourceId(com.android.internal.R.styleable.NinePatchDrawable_src, 0);
    if (id == 0) {
        throw new XmlPullParserException(parser.getPositionDescription() + ": <nine-patch> requires a valid src attribute");
    }
    final boolean dither = a.getBoolean(com.android.internal.R.styleable.NinePatchDrawable_dither, DEFAULT_DITHER);
    final BitmapFactory.Options options = new BitmapFactory.Options();
    if (dither) {
        options.inDither = false;
    }
    options.inScreenDensity = DisplayMetrics.DENSITY_DEVICE;
    final Rect padding = new Rect();
    Bitmap bitmap = null;
    try {
        final TypedValue value = new TypedValue();
        final InputStream is = r.openRawResource(id, value);
        bitmap = BitmapFactory.decodeResourceStream(r, value, is, padding, options);
        is.close();
    } catch (IOException e) {
    // Ignore
    }
    if (bitmap == null) {
        throw new XmlPullParserException(parser.getPositionDescription() + ": <nine-patch> requires a valid src attribute");
    } else if (bitmap.getNinePatchChunk() == null) {
        throw new XmlPullParserException(parser.getPositionDescription() + ": <nine-patch> requires a valid 9-patch source image");
    }
    setNinePatchState(new NinePatchState(new NinePatch(bitmap, bitmap.getNinePatchChunk(), "XML 9-patch"), padding, dither), r);
    mNinePatchState.mTargetDensity = mTargetDensity;
    a.recycle();
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) TypedValue(android.util.TypedValue)

Example 69 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project XobotOS by xamarin.

the class XmlUtils method readSetXml.

/**
     * Read a HashSet from an InputStream containing XML. The stream can
     * previously have been written by writeSetXml().
     * 
     * @param in The InputStream from which to read.
     * 
     * @return HashSet The resulting set.
     * 
     * @throws XmlPullParserException
     * @throws java.io.IOException
     * 
     * @see #readValueXml
     * @see #readThisSetXml
     * @see #writeSetXml
     */
public static final HashSet readSetXml(InputStream in) throws XmlPullParserException, java.io.IOException {
    XmlPullParser parser = Xml.newPullParser();
    parser.setInput(in, null);
    return (HashSet) readValueXml(parser, new String[1]);
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) HashSet(java.util.HashSet)

Example 70 with XmlPullParser

use of org.xmlpull.v1.XmlPullParser in project XobotOS by xamarin.

the class XmlUtils method readThisSetXml.

/**
     * Read a HashSet object from an XmlPullParser. The XML data could previously
     * have been generated by writeSetXml(). The XmlPullParser must be positioned
     * <em>after</em> the tag that begins the set.
     * 
     * @param parser The XmlPullParser from which to read the set data.
     * @param endTag Name of the tag that will end the set, usually "set".
     * @param name An array of one string, used to return the name attribute
     *             of the set's tag.
     *
     * @return HashSet The newly generated set.
     * 
     * @throws XmlPullParserException
     * @throws java.io.IOException
     * 
     * @see #readSetXml
     */
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 == parser.START_TAG) {
            Object val = readThisValueXml(parser, name);
            set.add(val);
        //System.out.println("Adding to set: " + val);
        } else if (eventType == parser.END_TAG) {
            if (parser.getName().equals(endTag)) {
                return set;
            }
            throw new XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName());
        }
        eventType = parser.next();
    } while (eventType != parser.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)673 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)623 IOException (java.io.IOException)377 FileInputStream (java.io.FileInputStream)185 FileNotFoundException (java.io.FileNotFoundException)185 File (java.io.File)107 ArrayList (java.util.ArrayList)77 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)45 BridgeXmlBlockParser (com.android.layoutlib.bridge.android.BridgeXmlBlockParser)39 FileReader (java.io.FileReader)36 BufferedInputStream (java.io.BufferedInputStream)30 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)30 RemoteException (android.os.RemoteException)28 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)28