本文整理汇总了Java中android.util.Xml类的典型用法代码示例。如果您正苦于以下问题:Java Xml类的具体用法?Java Xml怎么用?Java Xml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Xml类属于android.util包,在下文中一共展示了Xml类的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: inflate
import android.util.Xml; //导入依赖的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: 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();
}
}
}
}
示例6: parseKeyboardLayoutSetElement
import android.util.Xml; //导入依赖的package包/类
private void parseKeyboardLayoutSetElement(final XmlPullParser parser)
throws XmlPullParserException, IOException {
final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.KeyboardLayoutSet_Element);
try {
XmlParseUtils.checkAttributeExists(a,
R.styleable.KeyboardLayoutSet_Element_elementName, "elementName",
TAG_ELEMENT, parser);
XmlParseUtils.checkAttributeExists(a,
R.styleable.KeyboardLayoutSet_Element_elementKeyboard, "elementKeyboard",
TAG_ELEMENT, parser);
XmlParseUtils.checkEndTag(TAG_ELEMENT, parser);
final ElementParams elementParams = new ElementParams();
final int elementName = a.getInt(
R.styleable.KeyboardLayoutSet_Element_elementName, 0);
elementParams.mKeyboardXmlId = a.getResourceId(
R.styleable.KeyboardLayoutSet_Element_elementKeyboard, 0);
elementParams.mAllowRedundantMoreKeys = a.getBoolean(
R.styleable.KeyboardLayoutSet_Element_allowRedundantMoreKeys, true);
mParams.mKeyboardLayoutSetElementIdToParamsMap.put(elementName, elementParams);
} finally {
a.recycle();
}
}
示例7: 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();
}
}
示例8: parseKey
import android.util.Xml; //导入依赖的package包/类
private void parseKey(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
throws XmlPullParserException, IOException {
if (skip) {
XmlParseUtils.checkEndTag(TAG_KEY, parser);
if (DEBUG) startEndTag("<%s /> skipped", TAG_KEY);
return;
}
final TypedArray keyAttr = mResources.obtainAttributes(
Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
final String keySpec = keyStyle.getString(keyAttr, R.styleable.Keyboard_Key_keySpec);
if (TextUtils.isEmpty(keySpec)) {
throw new ParseException("Empty keySpec", parser);
}
final Key key = new Key(keySpec, keyAttr, keyStyle, mParams, row);
keyAttr.recycle();
if (DEBUG) {
startEndTag("<%s%s %s moreKeys=%s />", TAG_KEY, (key.isEnabled() ? "" : " disabled"),
key, Arrays.toString(key.getMoreKeys()));
}
XmlParseUtils.checkEndTag(TAG_KEY, parser);
endKey(key);
}
示例9: parseSpacer
import android.util.Xml; //导入依赖的package包/类
private void parseSpacer(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
throws XmlPullParserException, IOException {
if (skip) {
XmlParseUtils.checkEndTag(TAG_SPACER, parser);
if (DEBUG) startEndTag("<%s /> skipped", TAG_SPACER);
return;
}
final TypedArray keyAttr = mResources.obtainAttributes(
Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
final Key spacer = new Key.Spacer(keyAttr, keyStyle, mParams, row);
keyAttr.recycle();
if (DEBUG) startEndTag("<%s />", TAG_SPACER);
XmlParseUtils.checkEndTag(TAG_SPACER, parser);
endKey(spacer);
}
示例10: 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);
}
示例11: KeyboardRow
import android.util.Xml; //导入依赖的package包/类
public KeyboardRow(final Resources res, final KeyboardParams params,
final XmlPullParser parser, final int y) {
mParams = params;
final TypedArray keyboardAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard);
mRowHeight = (int)ResourceUtils.getDimensionOrFraction(keyboardAttr,
R.styleable.Keyboard_rowHeight, params.mBaseHeight, params.mDefaultRowHeight);
keyboardAttr.recycle();
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
mRowAttributesStack.push(new RowAttributes(
keyAttr, params.mDefaultKeyWidth, params.mBaseWidth));
keyAttr.recycle();
mCurrentY = y;
mCurrentX = 0.0f;
}
示例12: Parse
import android.util.Xml; //导入依赖的package包/类
public List<RssItem> Parse(@NonNull InputStream inputStream) throws XmlPullParserException, IOException {
try {
XmlPullParser parser = Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(inputStream, null);
parser.nextTag();
return readFeed(parser);
} catch (Exception exception) {
Logger.getInstance().Error(TAG, exception.getMessage());
} finally {
inputStream.close();
}
return null;
}
示例13: FtcSongXml
import android.util.Xml; //导入依赖的package包/类
/**
* Constructor: Create an instance of this object.
*
* @param instanceName specifies the instance name.
* @param input specifies the input stream from which the notated song is read.
*/
public FtcSongXml(String instanceName, InputStream input) throws XmlPullParserException, IOException
{
if (debugEnabled)
{
dbgTrace = new TrcDbgTrace(moduleName + "." + instanceName, tracingEnabled, traceLevel, msgLevel);
}
this.instanceName = instanceName;
try
{
parser = Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(input, null);
parser.nextTag();
parseCollection();
}
finally
{
input.close();
}
}
示例14: parseFromPicasaXml
import android.util.Xml; //导入依赖的package包/类
/**
* Parses photos XML (a list of photo; the contents of an album).
*
* @param xmlStr
* the photo XML
* @return a list of {@link Photo}s
*/
public static List<Photo> parseFromPicasaXml(String xmlStr) {
PicasaPhotosSaxHandler handler = new PicasaPhotosSaxHandler();
try {
// The Parser somehow has some trouble with a plus sign in the
// content. This is a hack to fix this.
// TODO: Maybe we should replace all these special characters with
// XML entities?
xmlStr = xmlStr.replace("+", "+");
Xml.parse(xmlStr, handler);
return handler.getPhotos();
} catch (SAXException e) {
Log.e("Photo", e.getMessage(), e);
}
return new ArrayList<Photo>();
}
示例15: 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();
}
}
}
}