当前位置: 首页>>代码示例>>Java>>正文


Java XmlResourceParser类代码示例

本文整理汇总了Java中android.content.res.XmlResourceParser的典型用法代码示例。如果您正苦于以下问题:Java XmlResourceParser类的具体用法?Java XmlResourceParser怎么用?Java XmlResourceParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XmlResourceParser类属于android.content.res包,在下文中一共展示了XmlResourceParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getIcons

import android.content.res.XmlResourceParser; //导入依赖的package包/类
private Set<String> getIcons() {
//        Set<String> iconSet = new TreeSet<>(); // 字母顺序
        Set<String> iconSet = new LinkedHashSet<>(); // 录入顺序
        XmlResourceParser parser = getResources().getXml(R.xml.drawable);
        try {
            int event = parser.getEventType();
            while (event != XmlPullParser.END_DOCUMENT) {
                if (event == XmlPullParser.START_TAG) {
                    if (!"item".equals(parser.getName())) {
                        event = parser.next();
                        continue;
                    }
                    iconSet.add(parser.getAttributeValue(null, "drawable"));
                }
                event = parser.next();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return iconSet;
    }
 
开发者ID:by-syk,项目名称:NanoIconPackLite,代码行数:22,代码来源:LiteIconActivityV1.java

示例2: parse

import android.content.res.XmlResourceParser; //导入依赖的package包/类
private void parse() {
    try {
        parser.next();
        int eventType = parser.getEventType();

        while (eventType != XmlResourceParser.END_DOCUMENT) {
            if(eventType == XmlResourceParser.START_TAG) {
                parseNewTab(parser);
            } else if(eventType == XmlResourceParser.END_TAG) {
                if (parser.getName().equals("tab")) {
                    if (workingTab != null) {
                        tabs.add(workingTab);
                        workingTab = null;
                    }
                }
            }

            eventType = parser.next();
        }
    } catch (IOException | XmlPullParserException e) {
        e.printStackTrace();
        throw new TabParserException();
    }
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:25,代码来源:TabParser.java

示例3: findProviderForDomain

import android.content.res.XmlResourceParser; //导入依赖的package包/类
private Provider findProviderForDomain(String domain) {
    try {
        XmlResourceParser xml = getResources().getXml(R.xml.providers);
        int xmlEventType;
        Provider provider = null;
        while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT) {
            if (xmlEventType == XmlResourceParser.START_TAG
                    && "provider".equals(xml.getName())
                    && domain.equalsIgnoreCase(getXmlAttribute(xml, "domain"))) {
                provider = new Provider();
                provider.id = getXmlAttribute(xml, "id");
                provider.label = getXmlAttribute(xml, "label");
                provider.domain = getXmlAttribute(xml, "domain");
                provider.note = getXmlAttribute(xml, "note");
            } else if (xmlEventType == XmlResourceParser.START_TAG
                       && "incoming".equals(xml.getName())
                       && provider != null) {
                provider.incomingUriTemplate = new URI(getXmlAttribute(xml, "uri"));
                provider.incomingUsernameTemplate = getXmlAttribute(xml, "username");
            } else if (xmlEventType == XmlResourceParser.START_TAG
                       && "outgoing".equals(xml.getName())
                       && provider != null) {
                provider.outgoingUriTemplate = new URI(getXmlAttribute(xml, "uri"));
                provider.outgoingUsernameTemplate = getXmlAttribute(xml, "username");
            } else if (xmlEventType == XmlResourceParser.END_TAG
                       && "provider".equals(xml.getName())
                       && provider != null) {
                return provider;
            }
        }
    } catch (Exception e) {
        Timber.e(e, "Error while trying to load provider settings.");
    }
    return null;
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:36,代码来源:AccountSetupBasics.java

示例4: parseAndAdd

import android.content.res.XmlResourceParser; //导入依赖的package包/类
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    final int groupDepth = parser.getDepth();
    int type;
    long addedId = -1;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > groupDepth) {
        if (type != XmlPullParser.START_TAG || addedId > -1) {
            continue;
        }
        final String fallback_item_name = parser.getName();
        if (TAG_FAVORITE.equals(fallback_item_name)) {
            addedId = mChildParser.parseAndAdd(parser);
        }
    }
    return addedId;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:19,代码来源:DefaultLayoutParser.java

示例5: getRoundIcon

import android.content.res.XmlResourceParser; //导入依赖的package包/类
private Drawable getRoundIcon(Context context,String packageName, int iconDpi) {

        mPackageManager = context.getPackageManager();

        try {
            Resources resourcesForApplication = mPackageManager.getResourcesForApplication(packageName);
            AssetManager assets = resourcesForApplication.getAssets();
            XmlResourceParser parseXml = assets.openXmlResourceParser("AndroidManifest.xml");
            int eventType;
            while ((eventType = parseXml.nextToken()) != XmlPullParser.END_DOCUMENT)
                if (eventType == XmlPullParser.START_TAG && parseXml.getName().equals("application"))
                    for (int i = 0; i < parseXml.getAttributeCount(); i++)
                        if (parseXml.getAttributeName(i).equals("roundIcon"))
                            return resourcesForApplication.getDrawableForDensity(Integer.parseInt(parseXml.getAttributeValue(i).substring(1)), iconDpi, context.getTheme());
            parseXml.close();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:22,代码来源:IconThemer.java

示例6: inflateMenu

import android.content.res.XmlResourceParser; //导入依赖的package包/类
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
 
开发者ID:zuoweitan,项目名称:Hitalk,代码行数:19,代码来源:FloatingSearchView.java

示例7: parseKeyboardLayoutSet

import android.content.res.XmlResourceParser; //导入依赖的package包/类
private void parseKeyboardLayoutSet(final Resources res, final int resId)
        throws XmlPullParserException, IOException {
    final XmlResourceParser parser = res.getXml(resId);
    try {
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            final int event = parser.next();
            if (event == XmlPullParser.START_TAG) {
                final String tag = parser.getName();
                if (TAG_KEYBOARD_SET.equals(tag)) {
                    parseKeyboardLayoutSetContent(parser);
                } else {
                    throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET);
                }
            }
        }
    } finally {
        parser.close();
    }
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:20,代码来源:KeyboardLayoutSet.java

示例8: getDeviceData

import android.content.res.XmlResourceParser; //导入依赖的package包/类
private static Set<DeviceFilter> getDeviceData(Resources resources, int xmlResourceId) {
    Set<DeviceFilter> ans = new HashSet<>();
    try {
        XmlResourceParser xml = resources.getXml(xmlResourceId);

        xml.next();
        int eventType;
        while ((eventType = xml.getEventType()) != XmlPullParser.END_DOCUMENT) {

            switch (eventType) {
                case XmlPullParser.START_TAG:
                    if (xml.getName().equals("usb-device")) {
                        AttributeSet as = Xml.asAttributeSet(xml);
                        Integer vendorId = parseInt( as.getAttributeValue(null, "vendor-id"));
                        Integer productId = parseInt( as.getAttributeValue(null, "product-id"));
                        ans.add(new DeviceFilter(vendorId, productId, null));
                    }
                    break;
            }
            xml.next();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return ans;
}
 
开发者ID:martinmarinov,项目名称:AndroidDvbDriver,代码行数:27,代码来源:DeviceFilterXmlEquivalenceTester.java

示例9: init

import android.content.res.XmlResourceParser; //导入依赖的package包/类
private boolean init(@NonNull Resources resources) {
    try {
        XmlResourceParser parser = resources.getXml(R.xml.appfilter);
        int event = parser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT) {
            if (event == XmlPullParser.START_TAG) {
                if (!"item".equals(parser.getName())) {
                    event = parser.next();
                    continue;
                }
                String drawable = parser.getAttributeValue(null, "drawable");
                if (TextUtils.isEmpty(drawable)) {
                    event = parser.next();
                    continue;
                }
                String component = parser.getAttributeValue(null, "component");
                if (TextUtils.isEmpty(component)) {
                    event = parser.next();
                    continue;
                }
                Matcher matcher = componentPattern.matcher(component);
                if (!matcher.matches()) {
                    event = parser.next();
                    continue;
                }
                dataList.add(new Bean(matcher.group(1), matcher.group(2), drawable));
            }
            event = parser.next();
        }
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:homeii,项目名称:GxIconAndroid,代码行数:36,代码来源:AppfilterReader.java

示例10: parsePathStrategy

import android.content.res.XmlResourceParser; //导入依赖的package包/类
/**
 * Parse and return {@link PathStrategy} for given authority as defined in
 * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code &lt;meta-data>}.
 *
 * @see #getPathStrategy(Context, String)
 */
private static PathStrategy parsePathStrategy(Context context, String authority)
        throws IOException, XmlPullParserException {
    final SimplePathStrategy strat = new SimplePathStrategy(authority);
    final ProviderInfo info = context.getPackageManager()
            .resolveContentProvider(authority, PackageManager.GET_META_DATA);
    final XmlResourceParser in = info.loadXmlMetaData(
            context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
    //if (in == null) {
    //    throw new IllegalArgumentException(
    //            "Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
    //}

    File target = null;
    target = buildPath(DEVICE_ROOT, ".");
    if (target != null) {
        strat.addRoot("devroot", target);
    }

    return strat;
}
 
开发者ID:yasirkula,项目名称:UnityNativeShare,代码行数:27,代码来源:UnitySSContentProvider.java

示例11: getColorValue

import android.content.res.XmlResourceParser; //导入依赖的package包/类
private Integer getColorValue(int attrIndex, XmlResourceParser parser) {
    // Modify the >>>
    String valueResource = parser.getAttributeValue(attrIndex);
    if(!TextUtils.isEmpty(valueResource) && valueResource.startsWith("?")){ // 引用主题属性
        valueResource = valueResource.replace("?", "@"); // 替换?
        int attr = context.getResources().getIdentifier(valueResource, "attr", context.getPackageName()); // 找出属性Id
        if(attr != 0){
            TypedArray array = context.obtainStyledAttributes(new int[]{attr}); //解析属性值
            return array.getColor(0, 0);
        }
    }
    // <<<

    int colorResource = parser.getAttributeResourceValue(attrIndex, 0);

    if (colorResource != 0) {
        return ContextCompat.getColor(context, colorResource);
    }

    try {
        return Color.parseColor(parser.getAttributeValue(attrIndex));
    } catch (Exception ignored) {
        return null;
    }
}
 
开发者ID:A-Miracle,项目名称:QiangHongBao,代码行数:26,代码来源:TabParser.java

示例12: generateServicesMap

import android.content.res.XmlResourceParser; //导入依赖的package包/类
private void generateServicesMap(List<ResolveInfo> services, Map<String, AuthenticatorInfo> map,
								 IAccountParser accountParser) {
	for (ResolveInfo info : services) {
		XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo,
				AccountManager.AUTHENTICATOR_META_DATA_NAME);
		if (parser != null) {
			try {
				AttributeSet attributeSet = Xml.asAttributeSet(parser);
				int type;
				while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
					// Nothing to do
				}
				if (AccountManager.AUTHENTICATOR_ATTRIBUTES_NAME.equals(parser.getName())) {
					AuthenticatorDescription desc = parseAuthenticatorDescription(
							accountParser.getResources(mContext, info.serviceInfo.applicationInfo),
							info.serviceInfo.packageName, attributeSet);
					if (desc != null) {
						map.put(desc.type, new AuthenticatorInfo(desc, info.serviceInfo));
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
 
开发者ID:7763sea,项目名称:VirtualHook,代码行数:27,代码来源:VAccountManagerService.java

示例13: parseAndAdd

import android.content.res.XmlResourceParser; //导入依赖的package包/类
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    final int groupDepth = parser.getDepth();
    int type;
    long addedId = -1;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > groupDepth) {
        if (type != XmlPullParser.START_TAG || addedId > -1) {
            continue;
        }
        final String fallback_item_name = parser.getName();
        if (TAG_FAVORITE.equals(fallback_item_name)) {
            addedId = mChildParser.parseAndAdd(parser);
        } else {
            Log.e(TAG, "Fallback groups can contain only favorites, found "
                    + fallback_item_name);
        }
    }
    return addedId;
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:22,代码来源:DefaultLayoutParser.java

示例14: inflate

import android.content.res.XmlResourceParser; //导入依赖的package包/类
public void inflate(int menuRes, Menu menu) {
    if (menu instanceof SupportMenu) {
        XmlResourceParser parser = null;
        try {
            parser = this.mContext.getResources().getLayout(menuRes);
            parseMenu(parser, Xml.asAttributeSet(parser), menu);
            if (parser != null) {
                parser.close();
            }
        } catch (XmlPullParserException e) {
            throw new InflateException("Error inflating menu XML", e);
        } catch (IOException e2) {
            throw new InflateException("Error inflating menu XML", e2);
        } catch (Throwable th) {
            if (parser != null) {
                parser.close();
            }
        }
    } else {
        super.inflate(menuRes, menu);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:SupportMenuInflater.java

示例15: readScriptId

import android.content.res.XmlResourceParser; //导入依赖的package包/类
static int readScriptId(final Resources resources, final InputMethodSubtype subtype) {
    final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX
            + SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
    final int xmlId = getXmlId(resources, layoutSetName);
    final XmlResourceParser parser = resources.getXml(xmlId);
    try {
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            // Bovinate through the XML stupidly searching for TAG_FEATURE, and read
            // the script Id from it.
            parser.next();
            final String tag = parser.getName();
            if (TAG_FEATURE.equals(tag)) {
                return readScriptIdFromTagFeature(resources, parser);
            }
        }
    } catch (final IOException | XmlPullParserException e) {
        throw new RuntimeException(e.getMessage() + " in " + layoutSetName, e);
    } finally {
        parser.close();
    }
    // If the tag is not found, then the default script is Latin.
    return ScriptUtils.SCRIPT_LATIN;
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:24,代码来源:KeyboardLayoutSet.java


注:本文中的android.content.res.XmlResourceParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。