本文整理汇总了Java中android.util.Xml.asAttributeSet方法的典型用法代码示例。如果您正苦于以下问题:Java Xml.asAttributeSet方法的具体用法?Java Xml.asAttributeSet怎么用?Java Xml.asAttributeSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.util.Xml
的用法示例。
在下文中一共展示了Xml.asAttributeSet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inflateMenu
import android.util.Xml; //导入方法依赖的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();
}
}
示例2: getDeviceData
import android.util.Xml; //导入方法依赖的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;
}
示例3: generateServicesMap
import android.util.Xml; //导入方法依赖的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();
}
}
}
}
示例4: generateServicesMap
import android.util.Xml; //导入方法依赖的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();
}
}
}
}
示例5: parseRowAttributes
import android.util.Xml; //导入方法依赖的package包/类
private KeyboardRow parseRowAttributes(final XmlPullParser parser)
throws XmlPullParserException {
final AttributeSet attr = Xml.asAttributeSet(parser);
final TypedArray keyboardAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard);
try {
if (keyboardAttr.hasValue(R.styleable.Keyboard_horizontalGap)) {
throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "horizontalGap");
}
if (keyboardAttr.hasValue(R.styleable.Keyboard_verticalGap)) {
throw new XmlParseUtils.IllegalAttribute(parser, TAG_ROW, "verticalGap");
}
return new KeyboardRow(mResources, mParams, parser, mCurrentY);
} finally {
keyboardAttr.recycle();
}
}
示例6: parseKeyStyle
import android.util.Xml; //导入方法依赖的package包/类
private void parseKeyStyle(final XmlPullParser parser, final boolean skip)
throws XmlPullParserException, IOException {
final AttributeSet attr = Xml.asAttributeSet(parser);
final TypedArray keyStyleAttr = mResources.obtainAttributes(
attr, R.styleable.Keyboard_KeyStyle);
final TypedArray keyAttrs = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
try {
if (!keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_styleName)) {
throw new XmlParseUtils.ParseException("<" + TAG_KEY_STYLE
+ "/> needs styleName attribute", parser);
}
if (DEBUG) {
startEndTag("<%s styleName=%s />%s", TAG_KEY_STYLE,
keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName),
skip ? " skipped" : "");
}
if (!skip) {
mParams.mKeyStyles.parseKeyStyleAttributes(keyStyleAttr, keyAttrs, parser);
}
} finally {
keyStyleAttr.recycle();
keyAttrs.recycle();
}
XmlParseUtils.checkEndTag(TAG_KEY_STYLE, parser);
}
示例7: generateServicesMap
import android.util.Xml; //导入方法依赖的package包/类
private void generateServicesMap(List<ResolveInfo> services, Map<String, SyncAdapterInfo> map,
RegisteredServicesParser accountParser) {
for (ResolveInfo info : services) {
XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo, "android.content.SyncAdapter");
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 ("sync-adapter".equals(parser.getName())) {
SyncAdapterType adapterType = parseSyncAdapterType(
accountParser.getResources(mContext, info.serviceInfo.applicationInfo), attributeSet);
if (adapterType != null) {
String key = adapterType.accountType + "/" + adapterType.authority;
map.put(key, new SyncAdapterInfo(adapterType, info.serviceInfo));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
示例8: parse
import android.util.Xml; //导入方法依赖的package包/类
public void parse(int xmlRes) {
String nameSpace = mContext.getResources().getString(R.string.bean_name_space);
try {
XmlResourceParser parser = mContext.getResources().getXml(xmlRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG &&
parser.getName().equals(nameSpace)) {
final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.bean);
int id = a.getResourceId(R.styleable.bean_identify, 0);
String name = a.getString(R.styleable.bean_nickname);
String clz = a.getString(R.styleable.bean_clz);
if (clz != null) {
onCreateBeanItem(new BeanItem(id, name, clz));
}
a.recycle();
}
eventType = parser.next();
}
} catch (Exception e) {
Log.e(LOG_TAG, "Received exception parsing bean xml:" + Log.getStackTraceString(e));
}
}
示例9: inflateMenu
import android.util.Xml; //导入方法依赖的package包/类
public void inflateMenu(@MenuRes int menuRes) {
if (menuRes == 0) 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();
}
}
示例10: parse
import android.util.Xml; //导入方法依赖的package包/类
public void parse(int xmlRes) {
String nameSpace = mContext.getResources().getString(R.string.processor_ns);
try {
XmlResourceParser parser = mContext.getResources().getXml(xmlRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG &&
parser.getName().equals(nameSpace)) {
final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.processor);
String scope = a.getString(R.styleable.processor_scope);
String clz = a.getString(R.styleable.processor_clazz);
Preconditions.checkNotNull(scope);
Preconditions.checkNotNull(clz);
onCreateItem(new ProcessorItem(clz, scope));
a.recycle();
}
eventType = parser.next();
}
} catch (Exception e) {
LoggerManager.getLogger(getClass()).error("Received exception parsing bean xml:" + Log.getStackTraceString(e));
}
}
示例11: retrieveSupportedDevices
import android.util.Xml; //导入方法依赖的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;
}
}
示例12: parseIncludeInternal
import android.util.Xml; //导入方法依赖的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();
}
}
示例13: fromXml
import android.util.Xml; //导入方法依赖的package包/类
public static AttributeSet fromXml(final Context context, final int xmlResId) {
final XmlPullParser parser = context.getResources().getXml(xmlResId);
try {
for (int type = 0;
(type != XmlPullParser.END_DOCUMENT) && (type != XmlPullParser.START_TAG);
type = parser.next()) {}
} catch (final Exception e) {
throw new RuntimeException("Could not parse XML.", e);
}
return Xml.asAttributeSet(parser);
}
示例14: create
import android.util.Xml; //导入方法依赖的package包/类
@Nullable
public static AnimatedVectorDrawableCompat create(@NonNull Context context, @DrawableRes int resId) {
if (VERSION.SDK_INT >= 21) {
AnimatedVectorDrawableCompat drawable = new AnimatedVectorDrawableCompat(context);
drawable.mDelegateDrawable = ResourcesCompat.getDrawable(context.getResources(), resId, context.getTheme());
drawable.mDelegateDrawable.setCallback(drawable.mCallback);
drawable.mCachedConstantStateDelegate = new AnimatedVectorDrawableDelegateState(drawable.mDelegateDrawable.getConstantState());
return drawable;
}
try {
int type;
XmlPullParser parser = context.getResources().getXml(resId);
AttributeSet attrs = Xml.asAttributeSet(parser);
do {
type = parser.next();
if (type == 2) {
break;
}
} while (type != 1);
if (type == 2) {
return createFromXmlInner(context, context.getResources(), parser, attrs, context.getTheme());
}
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;
}
}
示例15: create
import android.util.Xml; //导入方法依赖的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;
}
}