ColorPreset.java 文件源码

java
阅读 41 收藏 0 点赞 0 评论 0

项目:SimpleWatchface 作者:
public static ColorPreset fromXml(Context context, @XmlRes int xmlResId) throws IOException, XmlPullParserException {
    ColorPreset res = new ColorPreset();
    XmlResourceParser xmlResourceParser = context.getResources().getXml(xmlResId);
    String name = null;
    int eventType;
    while ((eventType = xmlResourceParser.next()) != XmlPullParser.END_DOCUMENT) {
        switch (eventType) {
            case XmlPullParser.START_TAG:
                String tagName = xmlResourceParser.getName();
                if ("color".equals(tagName)) {
                    name = xmlResourceParser.getAttributeValue(null, "name");
                }
                break;

            case XmlPullParser.TEXT:
                String colorStr = xmlResourceParser.getText().trim();
                int color = Color.parseColor(colorStr);
                switch (name) {
                    case "background":
                        res.background = color;
                        break;
                    case "hourMinutes":
                        res.hourMinutes = color;
                        break;
                    case "seconds":
                        res.seconds = color;
                        break;
                    case "amPm":
                        res.amPm = color;
                        break;
                    case "date":
                        res.date = color;
                        break;
                }
        }
    }
    xmlResourceParser.close();

    return res;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号