本文整理匯總了Java中android.content.res.XmlResourceParser.getEventType方法的典型用法代碼示例。如果您正苦於以下問題:Java XmlResourceParser.getEventType方法的具體用法?Java XmlResourceParser.getEventType怎麽用?Java XmlResourceParser.getEventType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.XmlResourceParser
的用法示例。
在下文中一共展示了XmlResourceParser.getEventType方法的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: 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();
}
}
示例3: getDeviceData
import android.content.res.XmlResourceParser; //導入方法依賴的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;
}
示例4: 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;
}
示例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: getMinTargetMaxSdkVersions
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
* {@link PackageManager} doesn't give us {@code minSdkVersion}, {@code targetSdkVersion},
* and {@code maxSdkVersion}, so we have to parse it straight from {@code <uses-sdk>} in
* {@code AndroidManifest.xml}. If {@code targetSdkVersion} is not set, then it is
* equal to {@code minSdkVersion}
*
* @see <a href="https://developer.android.com/guide/topics/manifest/uses-sdk-element.html"><uses-sdk></a>
*/
private static int[] getMinTargetMaxSdkVersions(Context context, String packageName) {
int minSdkVersion = Apk.SDK_VERSION_MIN_VALUE;
int targetSdkVersion = Apk.SDK_VERSION_MIN_VALUE;
int maxSdkVersion = Apk.SDK_VERSION_MAX_VALUE;
try {
AssetManager am = context.createPackageContext(packageName, 0).getAssets();
XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG && "uses-sdk".equals(xml.getName())) {
for (int j = 0; j < xml.getAttributeCount(); j++) {
if (xml.getAttributeName(j).equals("minSdkVersion")) {
minSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
} else if (xml.getAttributeName(j).equals("targetSdkVersion")) {
targetSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
} else if (xml.getAttributeName(j).equals("maxSdkVersion")) {
maxSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
}
}
break;
}
eventType = xml.nextToken();
}
} catch (PackageManager.NameNotFoundException | IOException | XmlPullParserException e) {
Log.e(TAG, "Could not get min/max sdk version", e);
}
if (targetSdkVersion < minSdkVersion) {
targetSdkVersion = minSdkVersion;
}
return new int[]{minSdkVersion, targetSdkVersion, maxSdkVersion};
}
示例7: 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;
}
示例8: 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();
}
}
示例9: retrieveSupportedDevices
import android.content.res.XmlResourceParser; //導入方法依賴的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;
}
}
示例10: loadUiOptionsFromManifest
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private static int loadUiOptionsFromManifest(Activity activity) {
int uiOptions = 0;
try {
final String thisPackage = activity.getClass().getName();
if (ActionBarSherlock.DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);
final String packageName = activity.getApplicationInfo().packageName;
final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
String name = xml.getName();
if ("application".equals(name)) {
//Check if the <application> has the attribute
if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
if ("uiOptions".equals(xml.getAttributeName(i))) {
uiOptions = xml.getAttributeIntValue(i, 0);
break; //out of for loop
}
}
} else if ("activity".equals(name)) {
//Check if the <activity> is us and has the attribute
if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <activity>");
Integer activityUiOptions = null;
String activityPackage = null;
boolean isOurActivity = false;
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
//We need both uiOptions and name attributes
String attrName = xml.getAttributeName(i);
if ("uiOptions".equals(attrName)) {
activityUiOptions = xml.getAttributeIntValue(i, 0);
} else if ("name".equals(attrName)) {
activityPackage = cleanActivityName(packageName, xml.getAttributeValue(i));
if (!thisPackage.equals(activityPackage)) {
break; //out of for loop
}
isOurActivity = true;
}
//Make sure we have both attributes before processing
if ((activityUiOptions != null) && (activityPackage != null)) {
//Our activity, uiOptions specified, override with our value
uiOptions = activityUiOptions.intValue();
}
}
if (isOurActivity) {
//If we matched our activity but it had no logo don't
//do any more processing of the manifest
break;
}
}
}
eventType = xml.nextToken();
}
} catch (Exception e) {
e.printStackTrace();
}
if (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(uiOptions));
return uiOptions;
}
示例11: loadLogoFromManifest
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
* Attempt to programmatically load the logo from the manifest file of an
* activity by using an XML pull parser. This should allow us to read the
* logo attribute regardless of the platform it is being run on.
*
* @param activity Activity instance.
* @return Logo resource ID.
*/
private static int loadLogoFromManifest(Activity activity) {
int logo = 0;
try {
final String thisPackage = activity.getClass().getName();
if (DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);
final String packageName = activity.getApplicationInfo().packageName;
final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
String name = xml.getName();
if ("application".equals(name)) {
//Check if the <application> has the attribute
if (DEBUG) Log.d(TAG, "Got <application>");
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
if ("logo".equals(xml.getAttributeName(i))) {
logo = xml.getAttributeResourceValue(i, 0);
break; //out of for loop
}
}
} else if ("activity".equals(name)) {
//Check if the <activity> is us and has the attribute
if (DEBUG) Log.d(TAG, "Got <activity>");
Integer activityLogo = null;
String activityPackage = null;
boolean isOurActivity = false;
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
//We need both uiOptions and name attributes
String attrName = xml.getAttributeName(i);
if ("logo".equals(attrName)) {
activityLogo = xml.getAttributeResourceValue(i, 0);
} else if ("name".equals(attrName)) {
activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
if (!thisPackage.equals(activityPackage)) {
break; //on to the next
}
isOurActivity = true;
}
//Make sure we have both attributes before processing
if ((activityLogo != null) && (activityPackage != null)) {
//Our activity, logo specified, override with our value
logo = activityLogo.intValue();
}
}
if (isOurActivity) {
//If we matched our activity but it had no logo don't
//do any more processing of the manifest
break;
}
}
}
eventType = xml.nextToken();
}
} catch (Exception e) {
e.printStackTrace();
}
if (DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo));
return logo;
}
示例12: loadLogoFromManifest
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
/**
* Attempt to programmatically load the logo from the manifest file of an
* activity by using an XML pull parser. This should allow us to read the
* logo attribute regardless of the platform it is being run on.
*
* @param activity Activity instance.
* @return Logo resource ID.
*/
public static int loadLogoFromManifest(Activity activity) {
int logo = 0;
try {
final String thisPackage = activity.getClass().getName();
if (ActionBarSherlock.DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage);
final String packageName = activity.getApplicationInfo().packageName;
final AssetManager am = activity.createPackageContext(packageName, 0).getAssets();
final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml");
int eventType = xml.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
String name = xml.getName();
if ("application".equals(name)) {
//Check if the <application> has the attribute
if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
if ("logo".equals(xml.getAttributeName(i))) {
logo = xml.getAttributeResourceValue(i, 0);
break; //out of for loop
}
}
} else if ("activity".equals(name)) {
//Check if the <activity> is us and has the attribute
if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <activity>");
Integer activityLogo = null;
String activityPackage = null;
boolean isOurActivity = false;
for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));
//We need both uiOptions and name attributes
String attrName = xml.getAttributeName(i);
if ("logo".equals(attrName)) {
activityLogo = xml.getAttributeResourceValue(i, 0);
} else if ("name".equals(attrName)) {
activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
if (!thisPackage.equals(activityPackage)) {
break; //on to the next
}
isOurActivity = true;
}
//Make sure we have both attributes before processing
if ((activityLogo != null) && (activityPackage != null)) {
//Our activity, logo specified, override with our value
logo = activityLogo.intValue();
}
}
if (isOurActivity) {
//If we matched our activity but it had no logo don't
//do any more processing of the manifest
break;
}
}
}
eventType = xml.nextToken();
}
} catch (Exception e) {
e.printStackTrace();
}
if (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo));
return logo;
}
示例13: 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;
}
示例14: 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;
}
示例15: loadFromXml
import android.content.res.XmlResourceParser; //導入方法依賴的package包/類
private void loadFromXml(int resourceId) {
XmlResourceParser parser = getContext().getResources().getXml(
resourceId);
try {
int eventType = parser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
} else if (eventType == XmlPullParser.START_TAG) {
String name = parser.getName();
if (!TextUtils.isEmpty(name) && name.equals("animation-list")) {
int size = parser.getAttributeCount();
for (int i = 0; i < size; i++) {
if (parser.getAttributeName(i).equals(
"oneshot")) {
mLoop = !parser.getAttributeBooleanValue(
i, true);
}
}
}
if (parser.getName().equals("item")) {
for (int i = 0; i < parser.getAttributeCount(); i++) {
if (parser.getAttributeName(i).equals(
"drawable")) {
int resId = Integer.parseInt(parser
.getAttributeValue(i)
.substring(1));
if (resId != 0)
mRes.add(resId);
} else if (parser.getAttributeName(i)
.equals("duration")) {
duration = parser.getAttributeIntValue(
i, 1000);
}
}
}
} else if (eventType == XmlPullParser.END_TAG) {
} else if (eventType == XmlPullParser.TEXT) {
}
eventType = parser.next();
}
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e2) {
e2.printStackTrace();
}
}