Java Code Examples for android.content.res.XmlResourceParser#getPositionDescription()

The following examples show how to use android.content.res.XmlResourceParser#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: AbstractInflater.java    From xdroid with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 2
Source File: TableList.java    From brailleback with Apache License 2.0 4 votes vote down vote up
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));
    }
}
 
Example 3
Source File: TagFlowLayout.java    From support with Apache License 2.0 4 votes vote down vote up
/**
 * 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!");
        }
    }
}