android.content.res.XmlResourceParser#getPositionDescription()源码实例Demo

下面列出了android.content.res.XmlResourceParser#getPositionDescription() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xdroid   文件: AbstractInflater.java
public T inflate(Context context, int xmlId) {
    XmlResourceParser parser = context.getResources().getXml(xmlId);
    if (parser == null) {
        throw new InflateException(String.valueOf(xmlId));
    }

    try {
        int type;
        do {
            type = parser.next();
        } while (type != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT);

        if (type != XmlPullParser.START_TAG) {
            throw new InflateException(parser.getPositionDescription());
        }

        T result = notNull(createFromTag(context, parser, null, parser));

        if (mCompositeClazz.isInstance(result)) {
            inflateRec(context, parser, mCompositeClazz.cast(result), parser);
        }

        return result;
    } catch (XmlPullParserException | IOException ex) {
        throw new InflateException(parser.getPositionDescription(), ex);
    }
}
 
源代码2 项目: brailleback   文件: TableList.java
private void parseTable(XmlResourceParser p) {
    Locale locale = parseLocale(p.getAttributeValue(null, ATTR_LOCALE));
    if (locale == null) {
        throw new RuntimeException(p.getPositionDescription()
                + ": Locale must be specified");
    }
    int dots = p.getAttributeIntValue(null, ATTR_DOTS, -1);
    int grade = p.getAttributeIntValue(null, ATTR_GRADE, -1);
    if (dots < 0 && grade < 0) {
        throw new RuntimeException(p.getPositionDescription()
                + ": neither dots nor grade was specified");
    }
    if (grade >= 0 && dots < 0) {
        dots = 6;
    }
    switch (dots) {
        case 6:
            if (grade < 0) {
                grade = 1;
            }
            break;
        case 8:
            if (grade >= 0) {
                throw new RuntimeException(p.getPositionDescription()
                        + ": grade must not be specified for 8 dot "
                        + "braille");
            }
            break;
        default:
            throw new RuntimeException(p.getPositionDescription()
                    + ": dots must be either 6 or 8");
    }
    String id = p.getAttributeValue(null, ATTR_ID);
    if (id == null) {
        throw new RuntimeException(p.getPositionDescription()
                + ": missing id attribute");
    }
    String variant = p.getAttributeValue(null, ATTR_VARIANT);
    String fileName = p.getAttributeValue(null, ATTR_FILE_NAME);
    if (fileName == null) {
        throw new RuntimeException(p.getPositionDescription()
                + ": missing fileName attribute");
    }
    mTableInfos.add(new TableInfo(locale, dots == 8, grade, id, variant));
    mTableFileNames.put(id, fileName);
    if (DBG) {
        Log.v(LOG_TAG, String.format("Table %s: locale=%s, dots=%d, "
                        + "grade=%d, variant=%s,fileName=%s",
                        id, locale.getDisplayName(), dots, grade,
                        variant, fileName));
    }
}
 
源代码3 项目: support   文件: TagFlowLayout.java
/**
 * Make sure the input EditView looks like TextView label
 */
private void setInnerAttribute()
        throws XmlPullParserException, IOException, ClassNotFoundException {
    mInputView.setTextSize(mDecorator.getTextSize());
    if (mDecorator.getMaxLength() != INVALID_VALUE) {
        InputFilter maxLengthFilter = new InputFilter.LengthFilter(mDecorator.getMaxLength());
        mInputView.setFilters(new InputFilter[]{maxLengthFilter});
    }
    if (mDecorator.getTextColor() != null && mDecorator.getTextColor().length > 1) {
        mInputView.setTextColor(mDecorator.getTextColor()[0]);
    }
    if (mDecorator.getLayout() != INVALID_VALUE) {
        XmlResourceParser parser = getResources().getLayout(mDecorator.getLayout());
        final AttributeSet set = Xml.asAttributeSet(parser);
        int type = 0;
        while ((type = parser.next()) != XmlPullParser.START_TAG &&
                type != XmlPullParser.END_DOCUMENT) {
            // Empty
        }
        if (type != XmlPullParser.START_TAG) {
            throw new InflateException(parser.getPositionDescription()
                    + ": No start tag found!");
        }
        final String name = parser.getName();
        if ("TextView".equals(name) || Class.forName(name).isInstance(TextView.class)) {
            int[] attr = new int[]{
                    android.R.attr.layout_width,
                    android.R.attr.layout_height,
            };
            TypedArray array = getContext().obtainStyledAttributes(set, attr);
            final int height = array.getDimensionPixelSize(1, 0);
            if (height != 0) {
                MarginLayoutParams layoutParams = (MarginLayoutParams) mInputView
                        .getLayoutParams();
                layoutParams.height = height;
            }
            //TODO other useful attribute
            array.recycle();
        } else {
            throw new InflateException(parser.getPositionDescription()
                    + ": Only TextView or subclass of TextView is supported!");
        }
    }
}