START_TAG源码实例Demo

android.content.res.XmlResourceParser#START_TAG源码实例Demo

下面列出了android.content.res.XmlResourceParser#START_TAG 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: BottomBar   文件: TabParser.java
@CheckResult
@NonNull
public List<BottomBarTab> parseTabs() {
    if (tabs == null) {
        tabs = new ArrayList<>(AVG_NUMBER_OF_TABS);
        try {
            int eventType;
            do {
                eventType = parser.next();
                if (eventType == XmlResourceParser.START_TAG && TAB_TAG.equals(parser.getName())) {
                    BottomBarTab bottomBarTab = parseNewTab(parser, tabs.size());
                    tabs.add(bottomBarTab);
                }
            } while (eventType != XmlResourceParser.END_DOCUMENT);
        } catch (IOException | XmlPullParserException e) {
            e.printStackTrace();
            throw new TabParserException();
        }
    }

    return tabs;
}
 
源代码2 项目: aptoide-client-v8   文件: PreferencesXmlParser.java
public List<String[]> parse(XmlResourceParser parser) throws IOException, XmlPullParserException {
  ArrayList<String[]> data = new ArrayList<>();
  while (eventType != XmlResourceParser.END_DOCUMENT) {
    if (eventType == XmlResourceParser.START_TAG) {
      String defaultValue = parser.getAttributeValue(NAMESPACE, DEFAULT_VALUE);
      String key = parser.getAttributeValue(NAMESPACE, KEY);
      if (defaultValue != null) {
        String[] keyValue = new String[2];
        keyValue[0] = key;
        keyValue[1] = defaultValue;
        data.add(keyValue);
      }
    }
    eventType = parser.next();
  }
  return data;
}
 
源代码3 项目: PainlessMusicPlayer   文件: PackageValidator.java
private Map<String, List<CallerInfo>> readValidCertificates(XmlResourceParser parser) {
    HashMap<String, List<CallerInfo>> validCertificates = new HashMap<>();
    try {
        int eventType = parser.next();
        while (eventType != XmlResourceParser.END_DOCUMENT) {
            if (eventType == XmlResourceParser.START_TAG
                    && parser.getName().equals("signing_certificate")) {

                String name = parser.getAttributeValue(null, "name");
                String packageName = parser.getAttributeValue(null, "package");
                boolean isRelease = parser.getAttributeBooleanValue(null, "release", false);
                String certificate = parser.nextText().replaceAll("\\s|\\n", "");

                CallerInfo info = new CallerInfo(name, packageName, isRelease);

                List<CallerInfo> infos = validCertificates.get(certificate);
                if (infos == null) {
                    infos = new ArrayList<>();
                    validCertificates.put(certificate, infos);
                }
                if (Log.logVEnabled()) {
                    Log.v(TAG, "Adding allowed caller: " + info.name
                            + " package=" + info.packageName + " release=" + info.release
                            + " certificate=" + certificate);
                }
                infos.add(info);
            }
            eventType = parser.next();
        }
    } catch (XmlPullParserException | IOException e) {
        Log.w(TAG, "Could not read allowed callers from XML", e);
    }
    return validCertificates;
}
 
源代码4 项目: google-services   文件: MainActivity.java
/**
 * Check to make sure global_tracker.xml was configured correctly (this function only needed
 * for sample apps).
 */
private boolean checkConfiguration() {
  XmlResourceParser parser = getResources().getXml(R.xml.global_tracker);

  boolean foundTag = false;
  try {
    while (parser.getEventType() != XmlResourceParser.END_DOCUMENT) {
      if (parser.getEventType() == XmlResourceParser.START_TAG) {
        String tagName = parser.getName();
        String nameAttr = parser.getAttributeValue(null, "name");

        foundTag = "string".equals(tagName) && "ga_trackingId".equals(nameAttr);
      }

      if (parser.getEventType() == XmlResourceParser.TEXT) {
        if (foundTag && parser.getText().contains("REPLACE_ME")) {
          return false;
        }
      }

      parser.next();
    }
  } catch (Exception e) {
    Log.w(TAG, "checkConfiguration", e);
    return false;
  }

  return true;
}
 
private void parsePreferences(@NonNull final Context context, @NonNull final XmlResourceParser parser, @NonNull final WearPreferenceScreen screen)
        throws XmlPullParserException, IOException {

    if(parser.getEventType() == XmlResourceParser.START_TAG) {
        parser.next();
        while(parser.getEventType() != XmlResourceParser.END_TAG) {
            parseItem(context, parser, screen);
            parser.next();
        }
    }
}
 
源代码6 项目: Jockey   文件: BrowserServicePackageValidator.java
private Map<String, ArrayList<CallerInfo>> readValidCertificates(XmlResourceParser parser) {
    HashMap<String, ArrayList<CallerInfo>> validCertificates = new HashMap<>();
    try {
        int eventType = parser.next();
        while (eventType != XmlResourceParser.END_DOCUMENT) {
            if (eventType == XmlResourceParser.START_TAG
                    && parser.getName().equals("signing_certificate")) {

                String name = parser.getAttributeValue(null, "name");
                String packageName = parser.getAttributeValue(null, "package");
                boolean isRelease = parser.getAttributeBooleanValue(null, "release", false);
                String certificate = parser.nextText().replaceAll("\\s|\\n", "");

                CallerInfo info = new CallerInfo(name, packageName, isRelease);

                ArrayList<CallerInfo> infos = validCertificates.get(certificate);
                if (infos == null) {
                    infos = new ArrayList<>();
                    validCertificates.put(certificate, infos);
                }
                Timber.v("Adding allowed caller: %s package=%s release=%b certificate=%s",
                        info.name, info.packageName, info.release, certificate);
                infos.add(info);
            }
            eventType = parser.next();
        }
    } catch (XmlPullParserException | IOException e) {
        Timber.e(e, "Could not read allowed callers from XML.");
    }

    return validCertificates;
}
 
源代码7 项目: Auie   文件: UENavigationActivity.java
/**
 * 读取XML配置文件
 * @param id 配置文件索引
 */
private void readXML(int id){
	String name;
	String className = getClass().getSimpleName();
	XmlResourceParser xrp = getResources().getXml(id);
	try {
		while(xrp.getEventType() != XmlResourceParser.END_DOCUMENT){
			if (xrp.getEventType() == XmlResourceParser.START_TAG) {
				name = xrp.getName();
				if (name.equals("BackgroundColor")) {
					mNavigationView.setBackgroundColor(xrp.getAttributeIntValue(0, mNavigationView.getBackgroundColor()));
				}
				if (name.equals("StatusType")) {
					mNavigationView.setStatusType(xrp.getAttributeIntValue(0, mNavigationView.getStatusType()));
				}
				if (name.equals("TitleColor")) {
					mNavigationView.setTitleColor(xrp.getAttributeIntValue(0, mNavigationView.getTitleColor()));
				}
				if (name.equals("LineBackgroundColor")) {
					mNavigationView.setLineBackgroundColor(xrp.getAttributeIntValue(0, mNavigationView.getTitleColor()));
				}
				if (name.equals("NavigationTextColor")) {
					mNavigationView.setNavigationTextColor(xrp.getAttributeIntValue(0, mNavigationView.getNavigationTextColor()));
				}
				if (name.equals("Title") && xrp.getAttributeValue(0).equals(className)) {
					mNavigationView.setTitle(xrp.getAttributeValue(1));
				}
			}
			xrp.next();
		}
	} catch (Exception e) {
		Log.d(UE.TAG, "UEConfig配置出错"+e.toString());
	}
}
 
源代码8 项目: Auie   文件: UENavigationFragmentActivity.java
/**
 * 读取XML配置文件
 * @param id 配置文件索引
 */
private void readXML(int id){
	String name;
	String className = getClass().getSimpleName();
	XmlResourceParser xrp = getResources().getXml(id);
	try {
		while(xrp.getEventType() != XmlResourceParser.END_DOCUMENT){
			if (xrp.getEventType() == XmlResourceParser.START_TAG) {
				name = xrp.getName();
				if (name.equals("BackgroundColor")) {
					mNavigationView.setBackgroundColor(xrp.getAttributeIntValue(0, mNavigationView.getBackgroundColor()));
				}
				if (name.equals("StatusType")) {
					mNavigationView.setStatusType(xrp.getAttributeIntValue(0, mNavigationView.getStatusType()));
				}
				if (name.equals("TitleColor")) {
					mNavigationView.setTitleColor(xrp.getAttributeIntValue(0, mNavigationView.getTitleColor()));
				}
				if (name.equals("LineBackgroundColor")) {
					mNavigationView.setLineBackgroundColor(xrp.getAttributeIntValue(0, mNavigationView.getTitleColor()));
				}
				if (name.equals("NavigationTextColor")) {
					mNavigationView.setNavigationTextColor(xrp.getAttributeIntValue(0, mNavigationView.getNavigationTextColor()));
				}
				if (name.equals("Title") && xrp.getAttributeValue(0).equals(className)) {
					mNavigationView.setTitle(xrp.getAttributeValue(1));
				}
			}
			xrp.next();
		}
	} catch (Exception e) {
		Log.d(UE.TAG, "UEConfig配置出错"+e.toString());
	}
}
 
源代码9 项目: android_9.0.0_r45   文件: Keyboard.java
private void loadKeyboard(Context context, XmlResourceParser parser) {
    boolean inKey = false;
    boolean inRow = false;
    boolean leftMostKey = false;
    int row = 0;
    int x = 0;
    int y = 0;
    Key key = null;
    Row currentRow = null;
    Resources res = context.getResources();
    boolean skipRow = false;

    try {
        int event;
        while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
            if (event == XmlResourceParser.START_TAG) {
                String tag = parser.getName();
                if (TAG_ROW.equals(tag)) {
                    inRow = true;
                    x = 0;
                    currentRow = createRowFromXml(res, parser);
                    rows.add(currentRow);
                    skipRow = currentRow.mode != 0 && currentRow.mode != mKeyboardMode;
                    if (skipRow) {
                        skipToEndOfRow(parser);
                        inRow = false;
                    }
               } else if (TAG_KEY.equals(tag)) {
                    inKey = true;
                    key = createKeyFromXml(res, currentRow, x, y, parser);
                    mKeys.add(key);
                    if (key.codes[0] == KEYCODE_SHIFT) {
                        // Find available shift key slot and put this shift key in it
                        for (int i = 0; i < mShiftKeys.length; i++) {
                            if (mShiftKeys[i] == null) {
                                mShiftKeys[i] = key;
                                mShiftKeyIndices[i] = mKeys.size()-1;
                                break;
                            }
                        }
                        mModifierKeys.add(key);
                    } else if (key.codes[0] == KEYCODE_ALT) {
                        mModifierKeys.add(key);
                    }
                    currentRow.mKeys.add(key);
                } else if (TAG_KEYBOARD.equals(tag)) {
                    parseKeyboardAttributes(res, parser);
                }
            } else if (event == XmlResourceParser.END_TAG) {
                if (inKey) {
                    inKey = false;
                    x += key.gap + key.width;
                    if (x > mTotalWidth) {
                        mTotalWidth = x;
                    }
                } else if (inRow) {
                    inRow = false;
                    y += currentRow.verticalGap;
                    y += currentRow.defaultHeight;
                    row++;
                } else {
                    // TODO: error or extend?
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Parse error:" + e);
        e.printStackTrace();
    }
    mTotalHeight = y - mDefaultVerticalGap;
}
 
源代码10 项目: libcommon   文件: Keyboard.java
private void loadKeyboard(Context context, XmlResourceParser parser) {
	if (DEBUG) Log.v(TAG, "loadKeyboard:");
	boolean inKey = false;
	boolean inRow = false;
	boolean leftMostKey = false;
	int row = 0;
	int x = 0;
	int y = 0;
	Key key = null;
	Row currentRow = null;
	Resources res = context.getResources();
	boolean skipRow = false;

	try {
		int event;
		while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
			if (event == XmlResourceParser.START_TAG) {
				String tag = parser.getName();
				if (TAG_ROW.equals(tag)) {
					inRow = true;
					x = 0;
					currentRow = createRowFromXml(res, parser);
					rows.add(currentRow);
					skipRow = currentRow.mode != 0 && currentRow.mode != mKeyboardMode;
					if (skipRow) {
						skipToEndOfRow(parser);
						inRow = false;
					}
				} else if (TAG_KEY.equals(tag)) {
					inKey = true;
					key = createKeyFromXml(res, currentRow, x, y, parser);
					Log.d(TAG, "loadKeyboard:key=" + key);
					mKeys.add(key);
					if (key.codes[0] == KEYCODE_SHIFT) {
						// Find available shift key slot and put this shift key in it
						for (int i = 0; i < mShiftKeys.length; i++) {
							if (mShiftKeys[i] == null) {
								mShiftKeys[i] = key;
								mShiftKeyIndices[i] = mKeys.size() - 1;
								break;
							}
						}
						mModifierKeys.add(key);
					} else if (key.codes[0] == KEYCODE_ALT) {
						mModifierKeys.add(key);
					}
					currentRow.mKeys.add(key);
				} else if (TAG_KEYBOARD.equals(tag)) {
					parseKeyboardAttributes(res, parser);
				}
			} else if (event == XmlResourceParser.END_TAG) {
				if (inKey) {
					inKey = false;
					x += key.gap + key.width;
					if (x > mTotalWidth) {
						mTotalWidth = x;
					}
				} else if (inRow) {
					inRow = false;
					y += currentRow.verticalGap;
					y += currentRow.defaultHeight;
					row++;
				} else {
					// TODO: error or extend?
				}
			}
		}
	} catch (Exception e) {
		Log.e(TAG, "Parse error:" + e);
		e.printStackTrace();
	}
	mTotalHeight = y - mDefaultVerticalGap;
}
 
源代码11 项目: SwipeSelector   文件: SwipeItemParser.java
private boolean isAtStartOfNewItem() {
    return currentEventType == XmlResourceParser.START_TAG
            && "item".equals(parser.getName());
}
 
源代码12 项目: WirelessHid   文件: Keyboard.java
private LinearLayout parseKeyLayout(Context context, XmlResourceParser xmlParser)
        throws XmlPullParserException, IOException {
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setLayoutParams(new LayoutParams(
            xmlParser.getAttributeIntValue(null, "width", LayoutParams.MATCH_PARENT),
            xmlParser.getAttributeIntValue(null, "height", 0),
            xmlParser.getAttributeFloatValue(null, "weight", 1.0f)));
    linearLayout.setOrientation(xmlParser.getAttributeIntValue(null, "orientation",
            LinearLayout.HORIZONTAL));

    String tag;
    do {
        xmlParser.next();
        tag = xmlParser.getName();

        if (xmlParser.getEventType() == XmlResourceParser.START_TAG) {
            if (tag.equals(XML_TAG_LAYOUT)) {
                linearLayout.addView(parseKeyLayout(context, xmlParser));
            } else if (tag.equals(XML_TAG_KEY)) {
                Key.KeyAttributes attrs = new Key.KeyAttributes();
                attrs.keyFunction = getStringAttributeValue(xmlParser, "keyFunc", "");
                attrs.mainLabel = getStringAttributeValue(xmlParser, "keyLabel", "");
                attrs.shiftLabel = getStringAttributeValue(xmlParser, "shiftLabel", "");
                attrs.keyCode = xmlParser.getAttributeIntValue(null, "keyCode", 0);

                Key key = new Key(context, attrs);
                key.setLayoutParams(new LayoutParams(
                        xmlParser.getAttributeIntValue(null, "width", 0),
                        xmlParser.getAttributeIntValue(null, "height",
                                LayoutParams.MATCH_PARENT),
                        xmlParser.getAttributeFloatValue(null, "weight", 1)));
                key.setVisibility(xmlParser.getAttributeBooleanValue(null, "visible", true) ?
                    VISIBLE : INVISIBLE);
                key.setKeyListener(this);

                if (attrs.shiftLabel != null & attrs.shiftLabel.length() > 0) {
                    mKeysWithShiftLabel.add(key);
                }

                linearLayout.addView(key);
            }
        }
    } while (xmlParser.getEventType() != XmlResourceParser.END_TAG
            || !tag.equals(XML_TAG_LAYOUT));

    return linearLayout;
}
 
源代码13 项目: hackerskeyboard   文件: Keyboard.java
private void loadKeyboard(Context context, XmlResourceParser parser) {
    boolean inKey = false;
    boolean inRow = false;
    float x = 0;
    int y = 0;
    Key key = null;
    Row currentRow = null;
    Resources res = context.getResources();
    boolean skipRow = false;
    mRowCount = 0;

    try {
        int event;
        Key prevKey = null;
        while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
            if (event == XmlResourceParser.START_TAG) {
                String tag = parser.getName();
                if (TAG_ROW.equals(tag)) {
                    inRow = true;
                    x = 0;
                    currentRow = createRowFromXml(res, parser);
                    skipRow = currentRow.mode != 0 && currentRow.mode != mKeyboardMode;
                    if (currentRow.extension) {
                        if (mUseExtension) {
                            ++mExtensionRowCount;
                        } else {
                            skipRow = true;
                        }
                    }
                    if (skipRow) {
                        skipToEndOfRow(parser);
                        inRow = false;
                    }
               } else if (TAG_KEY.equals(tag)) {
                    inKey = true;
                    key = createKeyFromXml(res, currentRow, Math.round(x), y, parser);
                    key.realX = x;
                    if (key.codes == null) {
                      // skip this key, adding its width to the previous one
                      if (prevKey != null) {
                          prevKey.width += key.width;
                      }
                    } else {
                      mKeys.add(key);
                      prevKey = key;
                      if (key.codes[0] == KEYCODE_SHIFT) {
                          if (mShiftKeyIndex == -1) {
                              mShiftKey = key;
                              mShiftKeyIndex = mKeys.size()-1;
                          }
                          mModifierKeys.add(key);
                      } else if (key.codes[0] == KEYCODE_ALT_SYM) {
                          mModifierKeys.add(key);
                      } else if (key.codes[0] == LatinKeyboardView.KEYCODE_CTRL_LEFT) {
                          mCtrlKey = key;
                      } else if (key.codes[0] == LatinKeyboardView.KEYCODE_ALT_LEFT) {
                          mAltKey = key;
                      } else if (key.codes[0] == LatinKeyboardView.KEYCODE_META_LEFT) {
                          mMetaKey = key;
                      }
                    }
                } else if (TAG_KEYBOARD.equals(tag)) {
                    parseKeyboardAttributes(res, parser);
                }
            } else if (event == XmlResourceParser.END_TAG) {
                if (inKey) {
                    inKey = false;
                    x += key.realGap + key.realWidth;
                    if (x > mTotalWidth) {
                        mTotalWidth = Math.round(x);
                    }
                } else if (inRow) {
                    inRow = false;
                    y += currentRow.verticalGap;
                    y += currentRow.defaultHeight;
                    mRowCount++;
                } else {
                    // TODO: error or extend?
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Parse error:" + e);
        e.printStackTrace();
    }
    mTotalHeight = y - mDefaultVerticalGap;
}
 
源代码14 项目: LicenseView   文件: ParseLicenseXml.java
public static List<License> Parse(XmlResourceParser parser)
		throws XmlPullParserException, IOException {
	List<License> licenses = new ArrayList<License>();
	int event = parser.getEventType();

	String name = null;
	String type = null;
	String license = null;

	while (event != XmlResourceParser.END_DOCUMENT) {
		if (event == XmlResourceParser.START_TAG) {
			if (!parser.getName().equals(TAG_ROOT)
					&& !parser.getName().equals(TAG_CHILD))
				throw new XmlPullParserException(
						"Error in xml: tag isn't '" + TAG_ROOT + "' or '"
								+ TAG_CHILD + "' at line:"
								+ parser.getLineNumber());
			name = parser.getAttributeValue(null, ATTR_NAME);
			type = parser.getAttributeValue(null, ATTR_TYPE);
		} else if (event == XmlResourceParser.TEXT) {
			license = parser.getText();
		} else if (event == XmlResourceParser.END_TAG) {
			if (name != null && type != null && license != null
					&& !parser.getName().equals(TAG_ROOT)) {
				if (type.equals(VALUE_FILE)) {
					licenses.add(new License(name, License.TYPE_FILE,
							license));
					System.out.println(name);
				} else if (type.equals(VALUE_LIBRARY)) {
					licenses.add(new License(name, License.TYPE_LIBRARY,
							license));
					System.out.println(name);
				} else {
					throw new XmlPullParserException(
							"Error in xml: 'type' isn't valid at line:"
									+ parser.getLineNumber());
				}
			} else if (name == null) {
				throw new XmlPullParserException(
						"Error in xml: doesn't contain a 'name' at line:"
								+ parser.getLineNumber());
			} else if (type == null) {
				throw new XmlPullParserException(
						"Error in xml: doesn't contain a 'type' at line:"
								+ parser.getLineNumber());
			} else if (license == null){
				throw new XmlPullParserException(
						"Error in xml: doesn't contain a 'license text' at line:"
								+ parser.getLineNumber());
			}
		}
		event = parser.next();
	}
	parser.close();
	return licenses;
}