本文整理汇总了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;
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
}