android.content.res.XmlResourceParser#getEventType()源码实例Demo

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

源代码1 项目: trekarta   文件: WhatsNewDialog.java
private void readRelease(XmlResourceParser parser) throws XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, null, TAG_RELEASE);
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        if (name.equals(TAG_CHANGE)) {
            parser.require(XmlPullParser.START_TAG, null, TAG_CHANGE);
            String variant = parser.getAttributeValue(null, ATTRIBUTE_VARIANT);
            ChangeListItem changeItem = new ChangeListItem();
            changeItem.change = readText(parser);
            if (BuildConfig.FULL_VERSION || !"full".equals(variant))
                mChangelog.add(changeItem);
            parser.require(XmlPullParser.END_TAG, null, TAG_CHANGE);
        } else {
            skip(parser);
        }
    }
    parser.require(XmlPullParser.END_TAG, null, TAG_RELEASE);
}
 
源代码2 项目: openboard   文件: KeyboardLayoutSet.java
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 项目: GeometricWeather   文件: XmlHelper.java
@NonNull
public static Map<String, String> getFilterMap(XmlResourceParser parser)
        throws XmlPullParserException, IOException {
    Map<String, String> map = new HashMap<>();

    for (int type = parser.getEventType(); type != XmlPullParser.END_DOCUMENT; type = parser.next()) {
        if (type == XmlPullParser.START_TAG && Constants.FILTER_TAG_ITEM.equals(parser.getName())) {
            map.put(
                    parser.getAttributeValue(null, Constants.FILTER_TAG_NAME),
                    parser.getAttributeValue(null, Constants.FILTER_TAG_VALUE)
            );
        }
    }

    return map;
}
 
源代码4 项目: NanoIconPackLite   文件: LiteIconActivityV1.java
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;
    }
 
源代码5 项目: AOSP-Kayboard-7.1.2   文件: KeyboardLayoutSet.java
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 项目: AOSP-Kayboard-7.1.2   文件: KeyboardLayoutSet.java
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();
    }
}
 
源代码7 项目: cwac-netsecurity   文件: TrustManagerBuilder.java
private void validateConfig(Context ctxt, int resourceId,
                            boolean isUserAllowed) {
  XmlResourceParser xpp=ctxt.getResources().getXml(resourceId);
  RuntimeException result=null;

  try {
    while (xpp.getEventType()!=XmlPullParser.END_DOCUMENT) {
      if (xpp.getEventType()==XmlPullParser.START_TAG) {
        if ("certificates".equals(xpp.getName())) {
          for (int i=0; i<xpp.getAttributeCount(); i++) {
            String name=xpp.getAttributeName(i);

            if ("src".equals(name)) {
              String src=xpp.getAttributeValue(i);

              if ("user".equals(src)) {
                if (isUserAllowed) {
                  Log.w("CWAC-NetSecurity", "requested <certificates src=\"user\">, treating as <certificates src=\"system\">");
                }
                else {
                  result=new RuntimeException(
                    "requested <certificates src=\"user\">, not supported");
                }
              }
            }
          }
        }
      }

      xpp.next();
    }
  }
  catch (Exception e) {
    throw new RuntimeException("Could not parse config XML", e);
  }

  if (result!=null) {
    throw result;
  }
}
 
源代码8 项目: iBeebo   文件: SettingChangeLogDialog.java
private String ParseReleaseTag(XmlResourceParser aXml) throws XmlPullParserException, IOException {
    String _Result = "<h1>Release: " + aXml.getAttributeValue(null, "version") + "</h1><ul>";
    int eventType = aXml.getEventType();
    while ((eventType != XmlPullParser.END_TAG) || (aXml.getName().equals("change"))) {
        if ((eventType == XmlPullParser.START_TAG) && (aXml.getName().equals("change"))) {
            eventType = aXml.next();
            _Result = _Result + "<li>" + aXml.getText() + "</li>";
        }
        eventType = aXml.next();
    }
    _Result = _Result + "</ul>";
    return _Result;
}
 
源代码9 项目: iBeebo   文件: ChangeLogDialog.java
private String ParseReleaseTag(XmlResourceParser aXml) throws XmlPullParserException, IOException {
    String _Result = "<h1>版本: " + aXml.getAttributeValue(null, "version") + "</h1><ul>";
    int eventType = aXml.getEventType();
    while ((eventType != XmlPullParser.END_TAG) || (aXml.getName().equals("change"))) {
        if ((eventType == XmlPullParser.START_TAG) && (aXml.getName().equals("change"))) {
            eventType = aXml.next();
            _Result = _Result + "<li>" + aXml.getText() + "</li>";
        }
        eventType = aXml.next();
    }
    _Result = _Result + "</ul>";
    return _Result;
}
 
源代码10 项目: 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());
	}
}
 
源代码11 项目: 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());
	}
}
 
源代码12 项目: NanoIconPack   文件: AppfilterReader.java
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;
}
 
源代码13 项目: iBeebo   文件: ChangeLogDialog.java
private String ParseReleaseTag(XmlResourceParser aXml) throws XmlPullParserException, IOException {
    String _Result = "<h1>版本: " + aXml.getAttributeValue(null, "version") + "</h1><ul>";
    int eventType = aXml.getEventType();
    while ((eventType != XmlPullParser.END_TAG) || (aXml.getName().equals("change"))) {
        if ((eventType == XmlPullParser.START_TAG) && (aXml.getName().equals("change"))) {
            eventType = aXml.next();
            _Result = _Result + "<li>" + aXml.getText() + "</li>";
        }
        eventType = aXml.next();
    }
    _Result = _Result + "</ul>";
    return _Result;
}
 
private static String addIntentFilter(HashMap<String, ArrayList<PluginIntentFilter>> map, String packageName, String namespace,
                                         XmlResourceParser parser, String endTagName) throws XmlPullParserException, IOException {
	int eventType = parser.getEventType();
	String activityName = parser.getAttributeValue(namespace, "name");
	activityName = getName(activityName, packageName);

	ArrayList<PluginIntentFilter> filters = map.get(activityName);
	if (filters == null) {
		filters = new ArrayList<PluginIntentFilter>();
           map.put(activityName, filters);
	}
	
	PluginIntentFilter intentFilter = new PluginIntentFilter();
	do {
		switch (eventType) {
			case XmlPullParser.START_TAG: {
				String tag = parser.getName();
				if ("intent-filter".equals(tag)) {
					intentFilter = new PluginIntentFilter();
					filters.add(intentFilter);
				} else {
					intentFilter.readFromXml(tag, namespace, parser);
				}
			}
		}
		eventType = parser.next();
	} while (!endTagName.equals(parser.getName()));//再次到达,表示一个标签结束了

       return activityName;
}
 
源代码15 项目: smartcard-reader   文件: ApduParser.java
@SuppressWarnings("unchecked")
static Apdu7816 readTag(Class<? extends Apdu7816> clazz,
        XmlResourceParser xml) throws Exception {
    if (xml.getEventType() != START_TAG)
        return null;

    final String thisTag = xml.getName();
    final String testTag = (String) clazz.getDeclaredField("TAG").get(null);
    if (!thisTag.equalsIgnoreCase(testTag))
        return null;

    final String apduName = xml.getAttributeValue(null, "name");
    final String apduVal = xml.getAttributeValue(null, "val");
    final ArrayList<Apdu7816> list = new ArrayList<Apdu7816>();

    final Object child = clazz.getDeclaredField("SUB").get(null);
    while (true) {
        int event = xml.next();
        if (event == END_DOCUMENT)
            break;

        if (event == END_TAG && thisTag.equalsIgnoreCase(xml.getName()))
            break;

        if (child != null) {
            Apdu7816 apdu = readTag((Class<? extends Apdu7816>) child, xml);
            if (apdu != null)
                list.add(apdu);
        }
    }

    final Apdu7816[] sub;
    if (list.isEmpty())
        sub = null;
    else
        sub = list.toArray(new Apdu7816[list.size()]);

    final Apdu7816 ret = clazz.newInstance();

    ret.init(parseValue(apduVal), apduName, sub);

    return ret;
}
 
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;
}
 
源代码17 项目: tilt-game-android   文件: DataService.java
private void loadLevels(Intent intent) {
    XmlResourceParser parser = getResources().getXml(R.xml.levels);

    String levelPackage = "";
    String controllerPackage = "";
    List<LevelVO> newLevels = new ArrayList<>();

    try {
        parser.next();
        int eventType = parser.getEventType();

        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                switch (parser.getName()) {
                    case "levels":
                        levelPackage = parser.getAttributeValue(null, "levelpackage");
                        controllerPackage = parser.getAttributeValue(null, "controllerpackage");
                        break;
                    case "level":
                        newLevels.add(LevelVO.createFromXML(parser, levelPackage, controllerPackage));
                        break;
                }
            }
            eventType = parser.next();
        }
    } catch (XmlPullParserException | IOException e) {
        e.printStackTrace();
    }

    List<LevelVO> allLevels = new ArrayList<>(newLevels);

    if (newLevels.size() > 0) {
        // retrieve current set of stored levels
        List<LevelVO> oldLevels = cupboard().withContext(this).query(LevelVO.URI, LevelVO.class).list();

        for (LevelVO oldLevelVO : oldLevels) {
            LevelVO newLevelVO = getLevelById(newLevels, oldLevelVO.id);
            if (newLevelVO != null) {
                newLevelVO.unlocked = oldLevelVO.unlocked;
            }
        }

        cupboard().withContext(this).put(LevelVO.URI, LevelVO.class, newLevels);

        // determine if there are new levels
        boolean hasNewLevels = (oldLevels.size() == 0) || newLevels.removeAll(oldLevels);

        // insert empty LevelResultVO instances into database for new levels
        if (hasNewLevels) {
            List<LevelResultVO> newResults = new ArrayList<>();
            for (LevelVO levelVO : newLevels) {
                newResults.add(new LevelResultVO(levelVO.id));
            }
            cupboard().withContext(this).put(LevelResultVO.URI, LevelResultVO.class, newResults);
        }
    }

    List<LevelResultVO> results = cupboard().withContext(this).query(LevelResultVO.URI, LevelResultVO.class).list();

    LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_LOAD_LEVELS)
            .putParcelableArrayListExtra(KEY_LEVELS, (ArrayList<? extends Parcelable>) allLevels)
            .putParcelableArrayListExtra(KEY_LEVEL_RESULTS, (ArrayList<? extends Parcelable>) results));
}
 
/**
 * 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;
}
 
源代码19 项目: candybar-library   文件: IconsHelper.java
@NonNull
public static List<Icon> getIconsList(@NonNull Context context) throws Exception {
    XmlResourceParser parser = context.getResources().getXml(R.xml.drawable);
    int eventType = parser.getEventType();
    String sectionTitle = "";
    List<Icon> icons = new ArrayList<>();
    List<Icon> sections = new ArrayList<>();

    int count = 0;
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("category")) {
                String title = parser.getAttributeValue(null, "title");
                if (!sectionTitle.equals(title)) {
                    if (sectionTitle.length() > 0) {
                        count += icons.size();
                        sections.add(new Icon(sectionTitle, icons));
                    }
                }
                sectionTitle = title;
                icons = new ArrayList<>();
            } else if (parser.getName().equals("item")) {
                String name = parser.getAttributeValue(null, "drawable");
                int id = getResourceId(context, name);
                if (id > 0) {
                    icons.add(new Icon(name, id));
                }
            }
        }

        eventType = parser.next();
    }
    count += icons.size();
    CandyBarMainActivity.sIconsCount = count;
    if (!CandyBarApplication.getConfiguration().isAutomaticIconsCountEnabled() &&
            CandyBarApplication.getConfiguration().getCustomIconsCount() == 0) {
        CandyBarApplication.getConfiguration().setCustomIconsCount(count);
    }
    sections.add(new Icon(sectionTitle, icons));
    parser.close();
    return sections;
}
 
源代码20 项目: zen4android   文件: ActionBarSherlockCompat.java
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;
}