當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。