本文整理了Java中android.util.Xml.asAttributeSet()
方法的一些代码示例,展示了Xml.asAttributeSet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Xml.asAttributeSet()
方法的具体详情如下:
包路径:android.util.Xml
类名称:Xml
方法名:asAttributeSet
暂无
代码示例来源:origin: ZieIony/Carbon
/**
* Create a drawable from an XML document using an optional {@link Resources.Theme}. For more
* information on how to create resources in XML, see
* <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.
*/
public static Drawable createFromXml(Resources r, XmlPullParser parser, Resources.Theme theme) throws XmlPullParserException, IOException {
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Empty loop
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
Drawable drawable = createFromXmlInner(r, parser, attrs, theme);
if (drawable == null) {
throw new RuntimeException("Unknown initial tag: " + parser.getName());
}
return drawable;
}
代码示例来源:origin: ZieIony/Carbon
/**
* Create a drawable from an XML document using an optional {@link Resources.Theme}. For more
* information on how to create resources in XML, see
* <a href="{@docRoot}guide/topics/resources/drawable-resource.html">Drawable Resources</a>.
*/
public Drawable createFromXml(XmlPullParser parser, Resources.Theme theme) throws XmlPullParserException, IOException {
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Empty loop
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
Drawable drawable = createFromXmlInner(parser, attrs, theme);
if (drawable == null) {
throw new RuntimeException("Unknown initial tag: " + parser.getName());
}
return drawable;
}
代码示例来源:origin: mikepenz/Android-Iconics
/**
* Uses the styleable tags to get the iconics data of menu items. Useful for set icons into
* {@code BottomNavigationView}
* <p>
* By default, menus don't show icons for sub menus, but this can be enabled via reflection
* So use this function if you want that sub menu icons are checked as well
*/
public static void parseXmlAndSetIconicsDrawables(@NonNull Context context,
int menuId,
@NonNull Menu menu,
boolean checkSubMenus) {
try {
XmlResourceParser parser = context.getResources().getXml(menuId);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(context, attrs, parser, menu, checkSubMenus);
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: android-hacker/VirtualXposed
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();
}
}
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void obtainAttributes_shouldReturnValuesFromResources() throws Exception {
XmlPullParser parser = resources.getXml(R.xml.xml_attrs);
parser.next();
parser.next();
AttributeSet attributes = Xml.asAttributeSet(parser);
TypedArray typedArray = resources
.obtainAttributes(attributes, new int[]{android.R.attr.title, android.R.attr.scrollbarFadeDuration});
assertThat(typedArray.getString(0)).isEqualTo("Android Title");
assertThat(typedArray.getInt(1, 0)).isEqualTo(1111);
typedArray.recycle();
}
代码示例来源:origin: android-hacker/VirtualXposed
private void generateServicesMap(List<ResolveInfo> services, Map<String, AuthenticatorInfo> map,
RegisteredServicesParser 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();
}
}
}
}
代码示例来源:origin: aa112901/remusic
final XmlResourceParser rp = context.getResources().getAssets().openXmlResourceParser(
value.assetCookie, file);
final AttributeSet attrs = Xml.asAttributeSet(rp);
int type;
代码示例来源:origin: aa112901/remusic
if (typedValue.string != null && typedValue.string.toString().endsWith("xml")) {
final XmlResourceParser rp = res.getXml(resId);
final AttributeSet attrs = Xml.asAttributeSet(rp);
int type;
代码示例来源:origin: cgeo/cgeo
private static Animator createAnimatorFromXml(Context c, XmlPullParser parser,
AttributeSet attrs, AnimatorSet parent, int sequenceOrdering)
throws XmlPullParserException, IOException {
Animator anim = null;
ArrayList<Animator> childAnims = null;
// Make sure we are on a start tag.
int type;
int depth = parser.getDepth();
while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
&& type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("objectAnimator")) {
anim = loadObjectAnimator(c, attrs);
} else if (name.equals("animator")) {
anim = loadAnimator(c, attrs, null);
} else if (name.equals("set")) {
anim = new AnimatorSet();
TypedArray a = c.obtainStyledAttributes(attrs,
/*com.android.internal.R.styleable.*/AnimatorSet);
TypedValue orderingValue = new TypedValue();
代码示例来源:origin: andkulikov/Transitions-Everywhere
/**
* Loads a {@link TransitionManager} object from a resource
*
* @param resource The resource id of the transition manager to load
* @return The loaded TransitionManager object
* @throws android.content.res.Resources.NotFoundException when the
* transition manager cannot be loaded
*/
@Nullable
public TransitionManager inflateTransitionManager(int resource, @NonNull ViewGroup sceneRoot) {
XmlResourceParser parser = mContext.getResources().getXml(resource);
try {
return createTransitionManagerFromXml(parser, Xml.asAttributeSet(parser), sceneRoot);
} catch (XmlPullParserException e) {
InflateException ex = new InflateException(e.getMessage());
ex.initCause(e);
throw ex;
} catch (IOException e) {
InflateException ex = new InflateException(
parser.getPositionDescription()
+ ": " + e.getMessage());
ex.initCause(e);
throw ex;
} finally {
parser.close();
}
}
代码示例来源:origin: robolectric/robolectric
private XmlResourceParser getFirstElementAttrSet(int resId) throws Exception {
XmlResourceParser xml = resources.getXml(resId);
assertThat(xml.next()).isEqualTo(XmlPullParser.START_DOCUMENT);
assertThat(xml.nextTag()).isEqualTo(XmlPullParser.START_TAG);
return (XmlResourceParser) Xml.asAttributeSet(xml);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void obtainStyledAttributes_shouldCheckXmlFirst_fromXmlLoadedFromResources() throws Exception {
// This simulates a ResourceProvider built from a 21+ SDK as viewportHeight / viewportWidth were introduced in API 21
// but the public ID values they are assigned clash with private com.android.internal.R values on older SDKs. This
// test ensures that even on older SDKs, on calls to obtainStyledAttributes() Robolectric will first check for matching
// resource ID values in the AttributeSet before checking the theme.
XmlResourceParser xml = context.getResources().getXml(R.drawable.vector);
xml.next();
xml.next();
AttributeSet attributeSet = Xml.asAttributeSet(xml);
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attributeSet, new int[] {
android.R.attr.viewportWidth,
android.R.attr.viewportHeight
}, 0, 0);
assertThat(typedArray.getFloat(0, 0)).isEqualTo(12.0f);
assertThat(typedArray.getFloat(1, 0)).isEqualTo(24.0f);
typedArray.recycle();
}
代码示例来源:origin: code-mc/material-icon-lib
private void afterInflate(int menuRes, Menu menu){
IconData root = new IconData(0, 0, 0);
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(parser, attrs, root);
} catch (XmlPullParserException e) {
throw new InflateException("Error inflating menu XML", e);
} catch (IOException e) {
throw new InflateException("Error inflating menu XML", e);
} finally {
if (parser != null) parser.close();
// populate the menu with the parsed icons
populateIcons(menu, root, mDefaultColor);
}
}
代码示例来源:origin: andkulikov/Transitions-Everywhere
/**
* Loads a {@link Transition} object from a resource
*
* @param resource The resource id of the transition to load
* @return The loaded Transition object
* @throws android.content.res.Resources.NotFoundException when the
* transition cannot be loaded
*/
@Nullable
public Transition inflateTransition(int resource) {
XmlResourceParser parser = mContext.getResources().getXml(resource);
try {
return createTransitionFromXml(parser, Xml.asAttributeSet(parser), null);
} catch (XmlPullParserException e) {
InflateException ex = new InflateException(e.getMessage());
ex.initCause(e);
throw ex;
} catch (IOException e) {
InflateException ex = new InflateException(
parser.getPositionDescription()
+ ": " + e.getMessage());
ex.initCause(e);
throw ex;
} finally {
parser.close();
}
}
代码示例来源:origin: com.nineoldandroids/library
private static Animator createAnimatorFromXml(Context c, XmlPullParser parser,
AttributeSet attrs, AnimatorSet parent, int sequenceOrdering)
throws XmlPullParserException, IOException {
Animator anim = null;
ArrayList<Animator> childAnims = null;
// Make sure we are on a start tag.
int type;
int depth = parser.getDepth();
while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)
&& type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("objectAnimator")) {
anim = loadObjectAnimator(c, attrs);
} else if (name.equals("animator")) {
anim = loadAnimator(c, attrs, null);
} else if (name.equals("set")) {
anim = new AnimatorSet();
TypedArray a = c.obtainStyledAttributes(attrs,
/*com.android.internal.R.styleable.*/AnimatorSet);
TypedValue orderingValue = new TypedValue();
代码示例来源:origin: LuckSiege/CustomView
private static Animation createAnimationFromXml(Context c, XmlPullParser parser)
throws XmlPullParserException, IOException {
return createAnimationFromXml(c, parser, null, Xml.asAttributeSet(parser));
}
代码示例来源:origin: LuckSiege/PictureSelectorLight
private static Animation createAnimationFromXml(Context c, XmlPullParser parser)
throws XmlPullParserException, IOException {
return createAnimationFromXml(c, parser, null, Xml.asAttributeSet(parser));
}
代码示例来源:origin: hcs-xph/RetrofitUtils
private static Animation createAnimationFromXml(Context c, XmlPullParser parser)
throws XmlPullParserException, IOException {
return createAnimationFromXml(c, parser, null, Xml.asAttributeSet(parser));
}
代码示例来源:origin: hamidness/restring
private Map<Integer, MenuItemStrings> getMenuItemsStrings(Resources resources, int resId) {
XmlResourceParser parser = resources.getLayout(resId);
AttributeSet attrs = Xml.asAttributeSet(parser);
try {
return parseMenu(parser, attrs);
} catch (XmlPullParserException | IOException e) {
e.printStackTrace();
return new HashMap<>();
}
}
代码示例来源:origin: crvv/android_wubi_input
private void parseKeyboardLayoutSetFeature(final XmlPullParser parser)
throws XmlPullParserException, IOException {
final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.KeyboardLayoutSet_Feature);
try {
final int scriptId = a.getInt(
R.styleable.KeyboardLayoutSet_Feature_supportedScript,
ScriptUtils.SCRIPT_LATIN);
XmlParseUtils.checkEndTag(TAG_FEATURE, parser);
setScriptId(scriptId);
} finally {
a.recycle();
}
}
内容来源于网络,如有侵权,请联系作者删除!