Java Code Examples for org.xmlpull.v1.XmlPullParser#getPositionDescription()

The following examples show how to use org.xmlpull.v1.XmlPullParser#getPositionDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorStateListUtils.java    From MagicaSakura with Apache License 2.0 5 votes vote down vote up
static ColorStateList createFromXmlInner(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {

        final String name = parser.getName();
        if (!name.equals("selector")) {
            throw new XmlPullParserException(
                    parser.getPositionDescription() + ": invalid color state list tag " + name);
        }

        return inflateColorStateList(context, parser, attrs);
    }
 
Example 2
Source File: ColorStateListUtils.java    From timecat with Apache License 2.0 5 votes vote down vote up
static ColorStateList createFromXmlInner(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {

        final String name = parser.getName();
        if (!name.equals("selector")) {
            throw new XmlPullParserException(parser.getPositionDescription() + ": invalid color state list tag " + name);
        }

        return inflateColorStateList(context, parser, attrs);
    }
 
Example 3
Source File: CrossProfileIntentFilter.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
String getStringFromXml(XmlPullParser parser, String attribute, String defaultValue) {
    String value = parser.getAttributeValue(null, attribute);
    if (value == null) {
        String msg = "Missing element under " + TAG +": " + attribute + " at " +
                parser.getPositionDescription();
        PackageManagerService.reportSettingsProblem(Log.WARN, msg);
        return defaultValue;
    } else {
        return value;
    }
}
 
Example 4
Source File: SearchEngineParser.java    From firefox-echo-show with Mozilla Public License 2.0 5 votes vote down vote up
private static void readSearchPlugin(XmlPullParser parser, SearchEngine searchEngine) throws XmlPullParserException, IOException {
    if (XmlPullParser.START_TAG != parser.getEventType()) {
        throw new XmlPullParserException("Expected start tag: " + parser.getPositionDescription());
    }

    final String name = parser.getName();
    if (!"SearchPlugin".equals(name) && !"OpenSearchDescription".equals(name)) {
        throw new XmlPullParserException("Expected <SearchPlugin> or <OpenSearchDescription> as root tag: "
                + parser.getPositionDescription());
    }

    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }

        final String tag = parser.getName();

        if (tag.equals("ShortName")) {
            readShortName(parser, searchEngine);
        } else if (tag.equals("Url")) {
            readUrl(parser, searchEngine);
        } else if (tag.equals("Image")) {
            readImage(parser, searchEngine);
        } else {
            skip(parser);
        }
    }
}
 
Example 5
Source File: LayerDrawable.java    From RippleDrawable with MIT License 5 votes vote down vote up
/**
 * Inflates child layers using the specified parser.
 */
private void inflateLayers(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme) throws XmlPullParserException, IOException {
    final LayerState state = mLayerState;

    final int innerDepth = parser.getDepth() + 1;
    int type;
    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;
        }

        final ChildDrawable layer = new ChildDrawable();
        final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawableItem);
        updateLayerFromTypedArray(theme, null, layer, a);
        a.recycle();

        if (layer.mDrawable == null) {
            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");
            }
            layer.mDrawable = LollipopDrawablesCompat.createFromXmlInner(r, parser, attrs, theme);
        }

        if (layer.mDrawable != null) {
            state.mChildrenChangingConfigurations |= layer.mDrawable.getChangingConfigurations();
            layer.mDrawable.setCallback(this);
        }

        addLayer(layer);
    }
}
 
Example 6
Source File: IntentFilterVerificationInfo.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
int getIntFromXml(XmlPullParser parser, String attribute, int defaultValue) {
    String value = parser.getAttributeValue(null, attribute);
    if (TextUtils.isEmpty(value)) {
        String msg = "Missing element under " + TAG +": " + attribute + " at " +
                parser.getPositionDescription();
        Log.w(TAG, msg);
        return defaultValue;
    } else {
        return Integer.parseInt(value);
    }
}
 
Example 7
Source File: ColorStateList.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Create from inside an XML document. Called on a parser positioned at a
 * tag in an XML document, tries to create a ColorStateList from that tag.
 *
 * @throws XmlPullParserException if the current tag is not &lt;selector>
 * @return A new color state list for the current tag.
 */
@NonNull
static ColorStateList createFromXmlInner(@NonNull Resources r,
        @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme)
        throws XmlPullParserException, IOException {
    final String name = parser.getName();
    if (!name.equals("selector")) {
        throw new XmlPullParserException(
                parser.getPositionDescription() + ": invalid color state list tag " + name);
    }

    final ColorStateList colorStateList = new ColorStateList();
    colorStateList.inflate(r, parser, attrs, theme);
    return colorStateList;
}
 
Example 8
Source File: GradientColor.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Create from inside an XML document. Called on a parser positioned at a
 * tag in an XML document, tries to create a GradientColor from that tag.
 *
 * @return A new GradientColor for the current tag.
 * @throws XmlPullParserException if the current tag is not &lt;gradient>
 */
@NonNull
static GradientColor createFromXmlInner(@NonNull Resources r,
        @NonNull XmlPullParser parser, @NonNull AttributeSet attrs, @Nullable Theme theme)
        throws XmlPullParserException, IOException {
    final String name = parser.getName();
    if (!name.equals("gradient")) {
        throw new XmlPullParserException(
                parser.getPositionDescription() + ": invalid gradient color tag " + name);
    }

    final GradientColor gradientColor = new GradientColor();
    gradientColor.inflate(r, parser, attrs, theme);
    return gradientColor;
}
 
Example 9
Source File: XmlParseUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
public ParseException(final String msg, final XmlPullParser parser) {
    super(msg + " at " + parser.getPositionDescription());
}
 
Example 10
Source File: XmlParseUtils.java    From simple-keyboard with Apache License 2.0 4 votes vote down vote up
public ParseException(final String msg, final XmlPullParser parser) {
    super(msg + " at " + parser.getPositionDescription());
}
 
Example 11
Source File: XmlParseUtils.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
public ParseException(final String msg, final XmlPullParser parser) {
    super(msg + " at " + parser.getPositionDescription());
}
 
Example 12
Source File: XmlParseUtils.java    From LokiBoard-Android-Keylogger with Apache License 2.0 4 votes vote down vote up
public ParseException(final String msg, final XmlPullParser parser) {
    super(msg + " at " + parser.getPositionDescription());
}
 
Example 13
Source File: XmlParseUtils.java    From openboard with GNU General Public License v3.0 4 votes vote down vote up
public ParseException(final String msg, final XmlPullParser parser) {
    super(msg + " at " + parser.getPositionDescription());
}
 
Example 14
Source File: GradientColor.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Inflates child elements "item"s for each color stop.
 *
 * Note that at root level, we need to save ThemeAttrs for theme applied later.
 * Here similarly, at each child item, we need to save the theme's attributes, and apply theme
 * later as applyItemsAttrsTheme().
 */
private void inflateChildElements(@NonNull Resources r, @NonNull XmlPullParser parser,
        @NonNull AttributeSet attrs, @NonNull Theme theme)
        throws XmlPullParserException, IOException {
    final int innerDepth = parser.getDepth() + 1;
    int type;
    int depth;

    // Pre-allocate the array with some size, for better performance.
    float[] offsetList = new float[20];
    int[] colorList = new int[offsetList.length];
    int[][] themeAttrsList = new int[offsetList.length][];

    int listSize = 0;
    boolean hasUnresolvedAttrs = false;
    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;
        }

        final TypedArray a = Resources.obtainAttributes(r, theme, attrs,
                R.styleable.GradientColorItem);
        boolean hasColor = a.hasValue(R.styleable.GradientColorItem_color);
        boolean hasOffset = a.hasValue(R.styleable.GradientColorItem_offset);
        if (!hasColor || !hasOffset) {
            throw new XmlPullParserException(
                    parser.getPositionDescription()
                            + ": <item> tag requires a 'color' attribute and a 'offset' "
                            + "attribute!");
        }

        final int[] themeAttrs = a.extractThemeAttrs();
        int color = a.getColor(R.styleable.GradientColorItem_color, 0);
        float offset = a.getFloat(R.styleable.GradientColorItem_offset, 0);

        if (DBG_GRADIENT) {
            Log.v(TAG, "new item color " + color + " " + Integer.toHexString(color));
            Log.v(TAG, "offset" + offset);
        }
        mChangingConfigurations |= a.getChangingConfigurations();
        a.recycle();

        if (themeAttrs != null) {
            hasUnresolvedAttrs = true;
        }

        colorList = GrowingArrayUtils.append(colorList, listSize, color);
        offsetList = GrowingArrayUtils.append(offsetList, listSize, offset);
        themeAttrsList = GrowingArrayUtils.append(themeAttrsList, listSize, themeAttrs);
        listSize++;
    }
    if (listSize > 0) {
        if (hasUnresolvedAttrs) {
            mItemsThemeAttrs = new int[listSize][];
            System.arraycopy(themeAttrsList, 0, mItemsThemeAttrs, 0, listSize);
        } else {
            mItemsThemeAttrs = null;
        }

        mItemColors = new int[listSize];
        mItemOffsets = new float[listSize];
        System.arraycopy(colorList, 0, mItemColors, 0, listSize);
        System.arraycopy(offsetList, 0, mItemOffsets, 0, listSize);
    }
}
 
Example 15
Source File: LayerDrawable.java    From Carbon with Apache License 2.0 4 votes vote down vote up
/**
 * Inflates child layers using the specified parser.
 */
private void inflateLayers(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
        throws XmlPullParserException, IOException {
    final LayerState state = mLayerState;

    final int innerDepth = parser.getDepth() + 1;
    int type;
    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;
        }

        final ChildDrawable layer = new ChildDrawable();
        final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawableItem);
        updateLayerFromTypedArray(layer, a);
        a.recycle();

        // If the layer doesn't have a drawable or unresolved theme
        // attribute for a drawable, attempt to parse one from the child
        // element.
        if (layer.mDrawable == null && (layer.mThemeAttrs == null ||
                layer.mThemeAttrs[R.styleable.LayerDrawableItem_android_drawable] == 0)) {
            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");
            }
            layer.mDrawable = LollipopDrawablesCompat.createFromXmlInner(r, parser, attrs, theme);
        }

        if (layer.mDrawable != null) {
            state.mChildrenChangingConfigurations |=
                    layer.mDrawable.getChangingConfigurations();
            layer.mDrawable.setCallback(this);
        }

        addLayer(layer);
    }
}
 
Example 16
Source File: XmlConfigSource.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public ParserException(XmlPullParser parser, String message, Throwable cause) {
    super(message + " at: " + parser.getPositionDescription(), cause);
}
 
Example 17
Source File: XmlParserBase.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private String pathForLocation(XmlPullParser xpp) {
	return xpp.getPositionDescription();
}
 
Example 18
Source File: FrameDrawable.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void inflateFrames(Resources resources, XmlPullParser parser, AttributeSet attrs,
                           Resources.Theme theme) throws XmlPullParserException, IOException {
    final int innerDepth = parser.getDepth() + 1;
    int type;
    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;
        final TypedArray custom = DrawableHelper.obtainAttributes(resources, theme, attrs,
                R.styleable.FrameDrawableItem);
        final int width = custom.getLayoutDimension(
                R.styleable.FrameDrawableItem_android_layout_width, "layout_width");
        final int height = custom.getLayoutDimension(
                R.styleable.FrameDrawableItem_android_layout_height, "layout_height");
        int marginStart = 0;
        int marginTop = 0;
        int marginEnd = 0;
        int marginBottom = 0;
        if (custom.hasValue(R.styleable.FrameDrawableItem_android_layout_margin)) {
            final int margin = custom.getDimensionPixelSize(
                    R.styleable.FrameDrawableItem_android_layout_margin, 0);
            marginStart = marginTop = marginEnd = marginBottom = margin;
        }
        if (custom.hasValue(R.styleable.FrameDrawableItem_android_layout_marginStart))
            marginStart = custom.getDimensionPixelSize(
                    R.styleable.FrameDrawableItem_android_layout_marginStart, marginStart);
        if (custom.hasValue(R.styleable.FrameDrawableItem_android_layout_marginTop))
            marginTop = custom.getDimensionPixelSize(
                    R.styleable.FrameDrawableItem_android_layout_marginTop, marginTop);
        if (custom.hasValue(R.styleable.FrameDrawableItem_android_layout_marginEnd))
            marginEnd = custom.getDimensionPixelSize(
                    R.styleable.FrameDrawableItem_android_layout_marginEnd, marginEnd);
        if (custom.hasValue(R.styleable.FrameDrawableItem_android_layout_marginBottom))
            marginBottom = custom.getDimensionPixelSize(
                    R.styleable.FrameDrawableItem_android_layout_marginBottom, marginBottom);
        final int gravity = custom.getInteger(R.styleable.FrameDrawableItem_android_gravity,
                Gravity.NO_GRAVITY);
        final int id = custom.getResourceId(R.styleable.FrameDrawableItem_android_id,
                View.NO_ID);
        final Drawable dr = custom.getDrawable(R.styleable.FrameDrawableItem_android_drawable);
        if (dr != null) {
            dr.setCallback(this);
            mItems.add(new ChildDrawable(dr, width, height, gravity, id,
                    marginStart, marginTop, marginEnd, marginBottom));
        }
        custom.recycle();
        if (dr == null) {
            //noinspection StatementWithEmptyBody
            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");
            final Drawable item = Drawable.createFromXmlInner(resources, parser, attrs, theme);
            item.setCallback(this);
            mItems.add(new ChildDrawable(item, width, height, gravity, id,
                    marginStart, marginTop, marginEnd, marginBottom));
        }
    }
}
 
Example 19
Source File: XmlParserBase.java    From org.hl7.fhir.core with Apache License 2.0 4 votes vote down vote up
private String pathForLocation(XmlPullParser xpp) {
	return xpp.getPositionDescription();
}
 
Example 20
Source File: XmlConfigSource.java    From cwac-netsecurity with Apache License 2.0 4 votes vote down vote up
public ParserException(XmlPullParser parser, String message, Throwable cause) {
    super(message + " at: " + parser.getPositionDescription(), cause);
}