本文整理汇总了Java中android.content.res.XmlResourceParser.next方法的典型用法代码示例。如果您正苦于以下问题:Java XmlResourceParser.next方法的具体用法?Java XmlResourceParser.next怎么用?Java XmlResourceParser.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.res.XmlResourceParser
的用法示例。
在下文中一共展示了XmlResourceParser.next方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIcons
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
private Set<String> getIcons() {
// Set<String> iconSet = new TreeSet<>(); // 字母顺序
Set<String> iconSet = new LinkedHashSet<>(); // 录入顺序
XmlResourceParser parser = getResources().getXml(R.xml.drawable);
try {
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
if (!"item".equals(parser.getName())) {
event = parser.next();
continue;
}
iconSet.add(parser.getAttributeValue(null, "drawable"));
}
event = parser.next();
}
} catch (Exception e) {
e.printStackTrace();
}
return iconSet;
}
示例2: generateServicesMap
import android.content.res.XmlResourceParser; //导入方法依赖的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();
}
}
}
}
示例3: parseAndAdd
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
IOException {
final int groupDepth = parser.getDepth();
int type;
long addedId = -1;
while ((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > groupDepth) {
if (type != XmlPullParser.START_TAG || addedId > -1) {
continue;
}
final String fallback_item_name = parser.getName();
if (TAG_FAVORITE.equals(fallback_item_name)) {
addedId = mChildParser.parseAndAdd(parser);
} else {
Log.e(TAG, "Fallback groups can contain only favorites, found "
+ fallback_item_name);
}
}
return addedId;
}
示例4: 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();
}
}
示例5: init
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
private boolean init(@NonNull Resources resources) {
try {
XmlResourceParser parser = resources.getXml(R.xml.appfilter);
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
if (!"item".equals(parser.getName())) {
event = parser.next();
continue;
}
String drawable = parser.getAttributeValue(null, "drawable");
if (TextUtils.isEmpty(drawable)) {
event = parser.next();
continue;
}
String component = parser.getAttributeValue(null, "component");
if (TextUtils.isEmpty(component)) {
event = parser.next();
continue;
}
Matcher matcher = componentPattern.matcher(component);
if (!matcher.matches()) {
event = parser.next();
continue;
}
dataList.add(new Bean(matcher.group(1), matcher.group(2), drawable));
}
event = parser.next();
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例6: generateServicesMap
import android.content.res.XmlResourceParser; //导入方法依赖的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();
}
}
}
}
示例7: parseAndAdd
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
@Override
public long parseAndAdd(XmlResourceParser parser)
throws XmlPullParserException, IOException {
final String packageName = getAttributeValue(parser, ATTR_PACKAGE_NAME);
final String className = getAttributeValue(parser, ATTR_CLASS_NAME);
if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(className)) {
if (LOGD) Log.d(TAG, "Skipping invalid <appwidget> with no component");
return -1;
}
mValues.put(Favorites.SPANX, getAttributeValue(parser, ATTR_SPAN_X));
mValues.put(Favorites.SPANY, getAttributeValue(parser, ATTR_SPAN_Y));
mValues.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET);
// Read the extras
Bundle extras = new Bundle();
int widgetDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > widgetDepth) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (TAG_EXTRA.equals(parser.getName())) {
String key = getAttributeValue(parser, ATTR_KEY);
String value = getAttributeValue(parser, ATTR_VALUE);
if (key != null && value != null) {
extras.putString(key, value);
} else {
throw new RuntimeException("Widget extras must have a key and value");
}
} else {
throw new RuntimeException("Widgets can contain only extras");
}
}
return verifyAndInsert(new ComponentName(packageName, className), extras);
}
示例8: getIcons
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
private List<Cate> getIcons() {
List<Cate> dataList = new ArrayList<>();
Cate defCate = new Cate(null);
XmlResourceParser parser = getResources().getXml(R.xml.drawable);
try {
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
switch (parser.getName()) {
case "category":
dataList.add(new Cate(parser.getAttributeValue(null, "title")));
break;
case "item":
String iconName = parser.getAttributeValue(null, "drawable");
if (dataList.isEmpty()) {
defCate.pushIcon(iconName);
} else {
dataList.get(dataList.size() - 1).pushIcon(iconName);
}
break;
}
}
event = parser.next();
}
if (!defCate.isEmpty()) {
dataList.add(defCate);
}
} catch (Exception e) {
e.printStackTrace();
}
return dataList;
}
示例9: readUuidData
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
private void readUuidData(XmlResourceParser xpp) throws XmlPullParserException, IOException {
xpp.next();
String tagName = null;
String uuid = null;
String descr = null;
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
// do nothing
} else if (eventType == XmlPullParser.START_TAG) {
tagName = xpp.getName();
uuid = xpp.getAttributeValue(null, "uuid");
descr = xpp.getAttributeValue(null, "descr");
} else if (eventType == XmlPullParser.END_TAG) {
// do nothing
} else if (eventType == XmlPullParser.TEXT) {
if (tagName.equalsIgnoreCase("item")) {
if (!uuid.isEmpty()) {
uuid = uuid.replace("0x", "");
mNameMap.put(uuid, xpp.getText());
mDescrMap.put(uuid, descr);
}
}
}
eventType = xpp.next();
}
}
示例10: parseAndAdd
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
@Override
public long parseAndAdd(XmlResourceParser parser)
throws XmlPullParserException, IOException {
final String title;
final int titleResId = getAttributeResourceValue(parser, ATTR_TITLE, 0);
if (titleResId != 0) {
title = mSourceRes.getString(titleResId);
} else {
title = mContext.getResources().getString(R.string.folder_name);
}
mValues.put(Favorites.TITLE, title);
mValues.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_FOLDER);
mValues.put(Favorites.SPANX, 1);
mValues.put(Favorites.SPANY, 1);
mValues.put(Favorites._ID, mCallback.generateNewItemId());
long folderId = mCallback.insertAndCheck(mDb, mValues);
if (folderId < 0) {
if (LOGD) Log.e(TAG, "Unable to add folder");
return -1;
}
final ContentValues myValues = new ContentValues(mValues);
ArrayList<Long> folderItems = new ArrayList<Long>();
int type;
int folderDepth = parser.getDepth();
int rank = 0;
while ((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > folderDepth) {
if (type != XmlPullParser.START_TAG) {
continue;
}
mValues.clear();
mValues.put(Favorites.CONTAINER, folderId);
mValues.put(Favorites.RANK, rank);
TagParser tagParser = mFolderElements.get(parser.getName());
if (tagParser != null) {
final long id = tagParser.parseAndAdd(parser);
if (id >= 0) {
folderItems.add(id);
rank++;
}
} else {
throw new RuntimeException("Invalid folder item " + parser.getName());
}
}
long addedId = folderId;
// We can only have folders with >= 2 items, so we need to remove the
// folder and clean up if less than 2 items were included, or some
// failed to add, and less than 2 were actually added
if (folderItems.size() < 2) {
// Delete the folder
Uri uri = Favorites.getContentUri(folderId);
SqlArguments args = new SqlArguments(uri, null, null);
mDb.delete(args.table, args.where, args.args);
addedId = -1;
// If we have a single item, promote it to where the folder
// would have been.
if (folderItems.size() == 1) {
final ContentValues childValues = new ContentValues();
copyInteger(myValues, childValues, Favorites.CONTAINER);
copyInteger(myValues, childValues, Favorites.SCREEN);
copyInteger(myValues, childValues, Favorites.CELLX);
copyInteger(myValues, childValues, Favorites.CELLY);
addedId = folderItems.get(0);
mDb.update(Favorites.TABLE_NAME, childValues,
Favorites._ID + "=" + addedId, null);
}
}
return addedId;
}
示例11: parseAndAdd
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
@Override
public long parseAndAdd(XmlResourceParser parser)
throws XmlPullParserException, IOException {
final String title;
final int titleResId = getAttributeResourceValue(parser, ATTR_TITLE, 0);
if (titleResId != 0) {
title = mSourceRes.getString(titleResId);
} else {
title = mContext.getResources().getString(R.string.folder_name);
}
mValues.put(Favorites.TITLE, title);
mValues.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_FOLDER);
mValues.put(Favorites.SPANX, 1);
mValues.put(Favorites.SPANY, 1);
mValues.put(Favorites._ID, mCallback.generateNewItemId());
long folderId = mCallback.insertAndCheck(mDb, mValues);
if (folderId < 0) {
return -1;
}
final ContentValues myValues = new ContentValues(mValues);
ArrayList<Long> folderItems = new ArrayList<Long>();
int type;
int folderDepth = parser.getDepth();
int rank = 0;
while ((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > folderDepth) {
if (type != XmlPullParser.START_TAG) {
continue;
}
mValues.clear();
mValues.put(Favorites.CONTAINER, folderId);
mValues.put(Favorites.RANK, rank);
TagParser tagParser = mFolderElements.get(parser.getName());
if (tagParser != null) {
final long id = tagParser.parseAndAdd(parser);
if (id >= 0) {
folderItems.add(id);
rank++;
}
} else {
throw new RuntimeException("Invalid folder item " + parser.getName());
}
}
long addedId = folderId;
// We can only have folders with >= 2 items, so we need to remove the
// folder and clean up if less than 2 items were included, or some
// failed to add, and less than 2 were actually added
if (folderItems.size() < 2) {
// Delete the folder
Uri uri = Favorites.getContentUri(folderId);
SqlArguments args = new SqlArguments(uri, null, null);
mDb.delete(args.table, args.where, args.args);
addedId = -1;
// If we have a single item, promote it to where the folder
// would have been.
if (folderItems.size() == 1) {
final ContentValues childValues = new ContentValues();
copyInteger(myValues, childValues, Favorites.CONTAINER);
copyInteger(myValues, childValues, Favorites.SCREEN);
copyInteger(myValues, childValues, Favorites.CELLX);
copyInteger(myValues, childValues, Favorites.CELLY);
addedId = folderItems.get(0);
mDb.update(Favorites.TABLE_NAME, childValues,
Favorites._ID + "=" + addedId, null);
}
}
return addedId;
}
示例12: init
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
protected boolean init(Resources resources) {
if (isReadDone()) {
return true;
}
if (resources == null) {
return false;
}
if (mPackageName == null) {
return false;
}
int resId = resources.getIdentifier(IconPackConfig.APPFIlTER,
IconPackConfig.APPFILTERLOCATION, mPackageName);
XmlResourceParser parser = resources.getXml(resId);
try {
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
if (!IconPackConfig.APPFILTERXMLLABEL.equals(parser.getName())) {
event = parser.next();
continue;
}
IconPackBean bean = new IconPackBean();
bean.drawable = parser.getAttributeValue(null, IconPackConfig.APPFILTERDRAWABLEELEMENT);
if (TextUtils.isEmpty(bean.drawable)) {
event = parser.next();
continue;
}
if (bean.drawable.matches(".+?_\\d+")) {
bean.drawableNoSeq = bean.drawable.substring(0, bean.drawable.lastIndexOf('_'));
} else {
bean.drawableNoSeq = bean.drawable;
}
String component = parser.getAttributeValue(null, IconPackConfig.APPFILTERCOMPONENTELEMENT);
if (component == null) {
event = parser.next();
continue;
}
Matcher matcher = Pattern.compile("ComponentInfo\\{([^/]+?)/(.+?)\\}").matcher(component);
if (matcher.matches()) {
bean.pkg = matcher.group(1);
bean.launcher = matcher.group(2);
}
if (!TextUtils.isEmpty(bean.launcher)) {
mAppFilterConfigMap.put(bean.launcher, bean);
}
}
event = parser.next();
}
isReadDone = true;
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例13: init
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
protected boolean init(Resources resources) {
if (isReadDone()) {
return true;
}
if (resources == null) {
return false;
}
int resId = getFilterConfigId();
XmlResourceParser parser = resources.getXml(resId);
try {
int event = parser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
if (event == XmlPullParser.START_TAG) {
if (!IconPackConfig.ICONPACKLABEL.equals(parser.getName())) {
event = parser.next();
continue;
}
Intent filter = new Intent();
String action = parser.getAttributeValue(null,
IconPackConfig.ICONPACKACTIONELEMENT);
if (TextUtils.isEmpty(action)) {
event = parser.next();
continue;
}
filter.setAction(action);
String category = parser.getAttributeValue(null,
IconPackConfig.ICONPACKCATEGORYELEMENT);
if (TextUtils.isEmpty(category)) {
event = parser.next();
continue;
}
filter.addCategory(category);
mFilter.add(filter);
}
event = parser.next();
}
mDone = true;
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例14: parsePathStrategy
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
/**
* Parse and return {@link PathStrategy} for given authority as defined in
* {@link #META_DATA_FILE_PROVIDER_PATHS} {@code <meta-data>}.
*
* @see #getPathStrategy(Context, String)
*/
private static PathStrategy parsePathStrategy(Context context, String authority)
throws IOException, XmlPullParserException {
final SimplePathStrategy strat = new SimplePathStrategy(authority);
final ProviderInfo info = context.getPackageManager()
.resolveContentProvider(authority, PackageManager.GET_META_DATA);
final XmlResourceParser in = info.loadXmlMetaData(
context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
if (in == null) {
throw new IllegalArgumentException(
"Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
}
int type;
while ((type = in.next()) != END_DOCUMENT) {
if (type == START_TAG) {
final String tag = in.getName();
final String name = in.getAttributeValue(null, ATTR_NAME);
String path = in.getAttributeValue(null, ATTR_PATH);
File target = null;
if (TAG_ROOT_PATH.equals(tag)) {
target = DEVICE_ROOT;
} else if (TAG_FILES_PATH.equals(tag)) {
target = context.getFilesDir();
} else if (TAG_CACHE_PATH.equals(tag)) {
target = context.getCacheDir();
} else if (TAG_EXTERNAL.equals(tag)) {
target = Environment.getExternalStorageDirectory();
} else if (TAG_EXTERNAL_FILES.equals(tag)) {
File[] externalFilesDirs = getExternalFilesDirs(context, null);
if (externalFilesDirs.length > 0) {
target = externalFilesDirs[0];
}
} else if (TAG_EXTERNAL_CACHE.equals(tag)) {
File[] externalCacheDirs = getExternalCacheDirs(context);
if (externalCacheDirs.length > 0) {
target = externalCacheDirs[0];
}
}
if (target != null) {
strat.addRoot(name, buildPath(target, path));
}
}
}
return strat;
}
示例15: generateServicesMap
import android.content.res.XmlResourceParser; //导入方法依赖的package包/类
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();
}
}
}
}