當前位置: 首頁>>代碼示例>>Java>>正文


Java Resources.getXml方法代碼示例

本文整理匯總了Java中android.content.res.Resources.getXml方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getXml方法的具體用法?Java Resources.getXml怎麽用?Java Resources.getXml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.res.Resources的用法示例。


在下文中一共展示了Resources.getXml方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseKeyboardLayoutSet

import android.content.res.Resources; //導入方法依賴的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

示例2: getDeviceData

import android.content.res.Resources; //導入方法依賴的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

示例3: init

import android.content.res.Resources; //導入方法依賴的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

示例4: readScriptId

import android.content.res.Resources; //導入方法依賴的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

示例5: parseAndAdd

import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    // Folder contents come from an external XML resource
    final Partner partner = Partner.get(mPackageManager);
    if (partner != null) {
        final Resources partnerRes = partner.getResources();
        final int resId = partnerRes.getIdentifier(Partner.RES_FOLDER,
                "xml", partner.getPackageName());
        if (resId != 0) {
            final XmlResourceParser partnerParser = partnerRes.getXml(resId);
            beginDocument(partnerParser, TAG_FOLDER);

            FolderParser folderParser = new FolderParser(getFolderElementsMap(partnerRes));
            return folderParser.parseAndAdd(partnerParser);
        }
    }
    return -1;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:20,代碼來源:DefaultLayoutParser.java

示例6: getXmlPullParser

import android.content.res.Resources; //導入方法依賴的package包/類
public static XmlPullParser getXmlPullParser(Resources resources, String packageName, String file) throws XMLNotFoundException, XmlPullParserException {

        XmlPullParser xpp = null;

        int xmlId = resources.getIdentifier(file, DEF_XML, packageName);

        if (xmlId > 0) {
            xpp = resources.getXml(xmlId);
        } else {
            // no resource found, try to open it from assets folder
            try {
                InputStream appfilterstream = resources.getAssets().open(file + EXT_XML);

                XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                factory.setNamespaceAware(true);
                xpp = factory.newPullParser();
                xpp.setInput(appfilterstream, UTF_8);
            } catch (IOException e) {
                throw new XMLNotFoundException(file + EXT_XML, e);
            }
        }
        return xpp;
    }
 
開發者ID:sofakingforever,項目名稱:IconPackParser-Android,代碼行數:24,代碼來源:XmlPullParserGenerator.java

示例7: loadAllDrawables

import android.content.res.Resources; //導入方法依賴的package包/類
private void loadAllDrawables(String packageName) {
    mDrawables.clear();
    XmlPullParser xpp;
    try {
        Resources res = mPackageManager.getResourcesForApplication(packageName);
        mCurrentIconPackRes = res;
        int resource = res.getIdentifier("drawable", "xml", packageName);
        if (resource < 0) {
            return;
        }
        xpp = res.getXml(resource);
        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                if (xpp.getName().equals("item")) {
                    String drawableName = xpp.getAttributeValue(null, "drawable");
                    if (!mDrawables.contains(drawableName) &&
                            getIdentifier(packageName, drawableName, true) > 0) {
                        mDrawables.add(drawableName);
                    }
                }
            }
            eventType = xpp.next();
        }
    } catch (Exception e) {
        e.printStackTrace();
        // fallback onto appfilter if drawable xml fails
        loadIconPack(packageName, true, mContext);
    }
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:31,代碼來源:IconsManager.java

示例8: retrieveSupportedDevices

import android.content.res.Resources; //導入方法依賴的package包/類
private static void retrieveSupportedDevices(final Resources resources) {
    final String tag = "retrieveDeviceData - ";

    if (supportedDevices == null) {
        final List<SupportedDevice> result = new ArrayList<>();
        final XmlResourceParser xml = resources.getXml(R.xml.supported_devices);
        try {
            xml.next();
            int eventType;
            while ((eventType = xml.getEventType()) != XmlPullParser.END_DOCUMENT) {
                switch (eventType) {
                    case XmlPullParser.START_TAG:
                        if (xml.getName().equals("usb-device")) {
                            final AttributeSet as = Xml.asAttributeSet(xml);
                            final Integer vendorId = parseInt(as.getAttributeValue(null, "vendor-id"));
                            final Integer productId = parseInt(as.getAttributeValue(null, "product-id"));

                            // Read description
                            String description=null;
                            xml.next();
                            if (xml.getName().equals("description")) {
                                xml.require(XmlPullParser.START_TAG, null, "description");
                                if (xml.next() == XmlPullParser.TEXT) {
                                    description = xml.getText();
                                    xml.nextTag();
                                }

                                xml.require(XmlPullParser.END_TAG, null, "description");
                            }
                            result.add(new SupportedDevice(new Pair<>(vendorId, productId), description));
                        }
                        break;
                }
                xml.next();
            }
        } catch (XmlPullParserException | IOException e) {
            Log.e(TAG, tag, e);
        }

        supportedDevices = result;
    }
}
 
開發者ID:videgro,項目名稱:Ships,代碼行數:43,代碼來源:UsbUtils.java

示例9: init

import android.content.res.Resources; //導入方法依賴的package包/類
protected boolean init(Resources resources) {
    if (isReadDone()) {
        return true;
    }
    if (resources == null) {
        return false;
    }

    if (mPackageName == null) {
        return false;
    }

    int resId = resources.getIdentifier(IconPackConfig.APPFIlTER,
            IconPackConfig.APPFILTERLOCATION, mPackageName);


    XmlResourceParser parser = resources.getXml(resId);
    try {
        int event = parser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT) {
            if (event == XmlPullParser.START_TAG) {
                if (!IconPackConfig.APPFILTERXMLLABEL.equals(parser.getName())) {
                    event = parser.next();
                    continue;
                }
                IconPackBean bean = new IconPackBean();
                bean.drawable = parser.getAttributeValue(null, IconPackConfig.APPFILTERDRAWABLEELEMENT);
                if (TextUtils.isEmpty(bean.drawable)) {
                    event = parser.next();
                    continue;
                }
                if (bean.drawable.matches(".+?_\\d+")) {
                    bean.drawableNoSeq = bean.drawable.substring(0, bean.drawable.lastIndexOf('_'));
                } else {
                    bean.drawableNoSeq = bean.drawable;
                }
                String component = parser.getAttributeValue(null, IconPackConfig.APPFILTERCOMPONENTELEMENT);
                if (component == null) {
                    event = parser.next();
                    continue;
                }
                Matcher matcher = Pattern.compile("ComponentInfo\\{([^/]+?)/(.+?)\\}").matcher(component);
                if (matcher.matches()) {
                    bean.pkg = matcher.group(1);
                    bean.launcher = matcher.group(2);
                }

                if (!TextUtils.isEmpty(bean.launcher)) {
                    mAppFilterConfigMap.put(bean.launcher, bean);
                }
            }
            event = parser.next();
        }
        isReadDone = true;
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}
 
開發者ID:uchiaitachipro,項目名稱:icon_pack_loader,代碼行數:62,代碼來源:AppFilterReader.java

示例10: init

import android.content.res.Resources; //導入方法依賴的package包/類
protected boolean init(Resources resources) {
    if (isReadDone()) {
        return true;
    }
    if (resources == null) {
        return false;
    }
    int resId = getFilterConfigId();
    XmlResourceParser parser = resources.getXml(resId);
    try {
        int event = parser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT) {
            if (event == XmlPullParser.START_TAG) {
                if (!IconPackConfig.ICONPACKLABEL.equals(parser.getName())) {
                    event = parser.next();
                    continue;
                }
                Intent filter = new Intent();
                String action = parser.getAttributeValue(null,
                        IconPackConfig.ICONPACKACTIONELEMENT);
                if (TextUtils.isEmpty(action)) {
                    event = parser.next();
                    continue;
                }
                filter.setAction(action);
                String category = parser.getAttributeValue(null,
                        IconPackConfig.ICONPACKCATEGORYELEMENT);
                if (TextUtils.isEmpty(category)) {
                    event = parser.next();
                    continue;
                }
                filter.addCategory(category);

                mFilter.add(filter);
            }
            event = parser.next();
        }
        mDone = true;
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
開發者ID:uchiaitachipro,項目名稱:icon_pack_loader,代碼行數:45,代碼來源:IconPackFilterReader.java

示例11: create

import android.content.res.Resources; //導入方法依賴的package包/類
@Nullable
public static VectorDrawableCompat create(@NonNull Resources res, @DrawableRes int resId, @Nullable Theme theme) {
    if (VERSION.SDK_INT >= 21) {
        VectorDrawableCompat drawable = new VectorDrawableCompat();
        drawable.mDelegateDrawable = ResourcesCompat.getDrawable(res, resId, theme);
        drawable.mCachedConstantStateDelegate = new VectorDrawableDelegateState(drawable.mDelegateDrawable.getConstantState());
        return drawable;
    }
    try {
        int type;
        XmlPullParser parser = res.getXml(resId);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        do {
            type = parser.next();
            if (type == 2) {
                break;
            }
        } while (type != 1);
        if (type == 2) {
            return createFromXmlInner(res, parser, attrs, theme);
        }
        throw new XmlPullParserException("No start tag found");
    } catch (XmlPullParserException e) {
        Log.e(LOGTAG, "parser error", e);
        return null;
    } catch (IOException e2) {
        Log.e(LOGTAG, "parser error", e2);
        return null;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:31,代碼來源:VectorDrawableCompat.java

示例12: loadDrawableFromDelegates

import android.content.res.Resources; //導入方法依賴的package包/類
private Drawable loadDrawableFromDelegates(@NonNull Context context, @DrawableRes int resId) {
    if (this.mDelegates == null || this.mDelegates.isEmpty()) {
        return null;
    }
    if (this.mKnownDrawableIdTags != null) {
        String cachedTagName = (String) this.mKnownDrawableIdTags.get(resId);
        if (SKIP_DRAWABLE_TAG.equals(cachedTagName) || (cachedTagName != null && this.mDelegates.get(cachedTagName) == null)) {
            return null;
        }
    }
    this.mKnownDrawableIdTags = new SparseArray();
    if (this.mTypedValue == null) {
        this.mTypedValue = new TypedValue();
    }
    TypedValue tv = this.mTypedValue;
    Resources res = context.getResources();
    res.getValue(resId, tv, true);
    long key = (((long) tv.assetCookie) << 32) | ((long) tv.data);
    Drawable dr = getCachedDelegateDrawable(context, key);
    if (dr != null) {
        return dr;
    }
    if (tv.string != null && tv.string.toString().endsWith(".xml")) {
        try {
            int type;
            XmlPullParser parser = res.getXml(resId);
            AttributeSet attrs = Xml.asAttributeSet(parser);
            do {
                type = parser.next();
                if (type == 2) {
                    break;
                }
            } while (type != 1);
            if (type != 2) {
                throw new XmlPullParserException("No start tag found");
            }
            String tagName = parser.getName();
            this.mKnownDrawableIdTags.append(resId, tagName);
            InflateDelegate delegate = (InflateDelegate) this.mDelegates.get(tagName);
            if (delegate != null) {
                dr = delegate.createFromXmlInner(context, parser, attrs, context.getTheme());
            }
            if (dr != null) {
                dr.setChangingConfigurations(tv.changingConfigurations);
                if (addCachedDelegateDrawable(context, key, dr)) {
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Exception while inflating drawable", e);
        }
    }
    if (dr != null) {
        return dr;
    }
    this.mKnownDrawableIdTags.append(resId, SKIP_DRAWABLE_TAG);
    return dr;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:58,代碼來源:AppCompatDrawableManager.java


注:本文中的android.content.res.Resources.getXml方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。