Java Code Examples for android.content.res.XmlResourceParser#START_TAG

The following examples show how to use android.content.res.XmlResourceParser#START_TAG . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TabParser.java    From BottomBar with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: PreferencesXmlParser.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: PackageValidator.java    From PainlessMusicPlayer with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: MainActivity.java    From google-services with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: XmlPreferenceParser.java    From WearPreferenceActivity with Apache License 2.0 5 votes vote down vote up
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();
        }
    }
}
 
Example 6
Source File: BrowserServicePackageValidator.java    From Jockey with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: UENavigationActivity.java    From Auie with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 读取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());
	}
}
 
Example 8
Source File: UENavigationFragmentActivity.java    From Auie with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 读取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());
	}
}
 
Example 9
Source File: Keyboard.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 10
Source File: Keyboard.java    From libcommon with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 11
Source File: SwipeItemParser.java    From SwipeSelector with Apache License 2.0 4 votes vote down vote up
private boolean isAtStartOfNewItem() {
    return currentEventType == XmlResourceParser.START_TAG
            && "item".equals(parser.getName());
}
 
Example 12
Source File: Keyboard.java    From WirelessHid with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 13
Source File: Keyboard.java    From hackerskeyboard with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 14
Source File: ParseLicenseXml.java    From LicenseView with Apache License 2.0 4 votes vote down vote up
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;
}