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


Java XmlResourceParser.close方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: parseValues

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
public void parseValues() {
    XmlResourceParser parser = mSourceRes.getXml(mLayoutId);
    try {
        beginDocument(parser, mRootTag);
        new ResolveParser().parseAndAdd(parser);
    } catch (IOException | XmlPullParserException e) {
        Log.e(TAG, "Unable to parse default app info", e);
    }
    parser.close();
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:11,代碼來源:CommonAppTypeParser.java

示例7: getIntentFilter

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
 * getFilter
 *
 * @param apkPath apkPath
 * @return intent filters
 */
public static Map<String, IntentFilter> getIntentFilter(String apkPath) {
    if (apkPath == null || "".equals(apkPath)) {
        return null;
    }
    Map<String, IntentFilter> intentFilters = new HashMap<String, IntentFilter>();
    AssetManager assetManager = null;
    XmlResourceParser parser = null;
    try {
        assetManager = AssetManager.class.newInstance();
        Method method = AssetManager.class.getDeclaredMethod("addAssetPath", String.class);
        method.invoke(assetManager, apkPath);
        parser = assetManager.openXmlResourceParser(ANDROID_MANIFEST_FILENAME);
        parseManifest(parser, intentFilters);
        parser.close();
        assetManager.close();
        parser = null;
        assetManager = null;
    } catch (Exception e) {
    } finally {
        if (parser != null) {
            parser.close();
            parser = null;
        }
        if (assetManager != null) {
            assetManager.close();
            assetManager = null;
        }
    }
    return intentFilters;
}
 
開發者ID:LiangMaYong,項目名稱:android-apkbox,代碼行數:37,代碼來源:ApkManifestParser.java

示例8: parseIncludeInternal

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private void parseIncludeInternal(final XmlPullParser parser, final KeyboardRow row,
        final boolean skip) throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
        if (DEBUG) startEndTag("</%s> skipped", TAG_INCLUDE);
        return;
    }
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyboardAttr = mResources.obtainAttributes(
            attr, R.styleable.Keyboard_Include);
    final TypedArray includeAttr = mResources.obtainAttributes(
            attr, R.styleable.Keyboard);
    mParams.mDefaultRowHeight = (int)ResourceUtils.getDimensionOrFraction(includeAttr,
            R.styleable.Keyboard_rowHeight, mParams.mBaseHeight, mParams.mDefaultRowHeight);

    final TypedArray keyAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
    int keyboardLayout = 0;
    try {
        XmlParseUtils.checkAttributeExists(
                keyboardAttr, R.styleable.Keyboard_Include_keyboardLayout, "keyboardLayout",
                TAG_INCLUDE, parser);
        keyboardLayout = keyboardAttr.getResourceId(
                R.styleable.Keyboard_Include_keyboardLayout, 0);
        if (row != null) {
            // Override current x coordinate.
            row.setXPos(row.getKeyX(keyAttr));
            // Push current Row attributes and update with new attributes.
            row.pushRowAttributes(keyAttr);
        }
    } finally {
        keyboardAttr.recycle();
        keyAttr.recycle();
        includeAttr.recycle();
    }

    XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
    if (DEBUG) {
        startEndTag("<%s keyboardLayout=%s />",TAG_INCLUDE,
                mResources.getResourceEntryName(keyboardLayout));
    }
    final XmlResourceParser parserForInclude = mResources.getXml(keyboardLayout);
    try {
        parseMerge(parserForInclude, row, skip);
    } finally {
        if (row != null) {
            // Restore Row attributes.
            row.popRowAttributes();
        }
        parserForInclude.close();
    }
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:52,代碼來源:KeyboardBuilder.java

示例9: parseIncludeInternal

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private void parseIncludeInternal(final XmlPullParser parser, final KeyboardRow row,
        final boolean skip) throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
        if (DEBUG) startEndTag("</%s> skipped", TAG_INCLUDE);
        return;
    }
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyboardAttr = mResources.obtainAttributes(
            attr, R.styleable.Keyboard_Include);
    final TypedArray keyAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
    int keyboardLayout = 0;
    try {
        XmlParseUtils.checkAttributeExists(
                keyboardAttr, R.styleable.Keyboard_Include_keyboardLayout, "keyboardLayout",
                TAG_INCLUDE, parser);
        keyboardLayout = keyboardAttr.getResourceId(
                R.styleable.Keyboard_Include_keyboardLayout, 0);
        if (row != null) {
            // Override current x coordinate.
            row.setXPos(row.getKeyX(keyAttr));
            // Push current Row attributes and update with new attributes.
            row.pushRowAttributes(keyAttr);
        }
    } finally {
        keyboardAttr.recycle();
        keyAttr.recycle();
    }

    XmlParseUtils.checkEndTag(TAG_INCLUDE, parser);
    if (DEBUG) {
        startEndTag("<%s keyboardLayout=%s />",TAG_INCLUDE,
                mResources.getResourceEntryName(keyboardLayout));
    }
    final XmlResourceParser parserForInclude = mResources.getXml(keyboardLayout);
    try {
        parseMerge(parserForInclude, row, skip);
    } finally {
        if (row != null) {
            // Restore Row attributes.
            row.popRowAttributes();
        }
        parserForInclude.close();
    }
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:46,代碼來源:KeyboardBuilder.java

示例10: inflate

import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
 * Inflate a new hierarchy from the specified xml resource. Throws
 * InflaterException if there is an error.
 *
 * @param resource ID for an XML resource to load (e.g.,
 *        <code>R.layout.main_page</code>)
 * @param root Optional root to be the parent of the generated hierarchy (if
 *        <em>attachToRoot</em> is true), or else simply an object that
 *        provides a set of values for root of the returned
 *        hierarchy (if <em>attachToRoot</em> is false.)
 * @param attachToRoot Whether the inflated hierarchy should be attached to
 *        the root parameter?
 * @return The root of the inflated hierarchy. If root was supplied and
 *         attachToRoot is true, this is root; otherwise it is the root of
 *         the inflated XML file.
 */
public T inflate(int resource, T root, boolean attachToRoot) {
    if (DEBUG) Log.v(TAG, "INFLATING from resource: " + resource);
    XmlResourceParser parser = getContext().getResources().getXml(resource);
    try {
        return inflate(parser, root, attachToRoot);
    } finally {
        parser.close();
    }
}
 
開發者ID:Trumeet,項目名稱:SetupWizardLibCompat,代碼行數:26,代碼來源:GenericInflater.java


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