Java Code Examples for android.content.res.XmlResourceParser

The following are top voted examples for showing how to use android.content.res.XmlResourceParser. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: NanoIconPackLite   File: LiteIconActivityV1.java   View source code 16 votes vote down vote up
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;
    }
 
Example 2
Project: QiangHongBao   File: TabParser.java   View source code 9 votes vote down vote up
private void parse() {
    try {
        parser.next();
        int eventType = parser.getEventType();

        while (eventType != XmlResourceParser.END_DOCUMENT) {
            if(eventType == XmlResourceParser.START_TAG) {
                parseNewTab(parser);
            } else if(eventType == XmlResourceParser.END_TAG) {
                if (parser.getName().equals("tab")) {
                    if (workingTab != null) {
                        tabs.add(workingTab);
                        workingTab = null;
                    }
                }
            }

            eventType = parser.next();
        }
    } catch (IOException | XmlPullParserException e) {
        e.printStackTrace();
        throw new TabParserException();
    }
}
 
Example 3
Project: q-mail   File: AccountSetupBasics.java   View source code 7 votes vote down vote up
private Provider findProviderForDomain(String domain) {
    try {
        XmlResourceParser xml = getResources().getXml(R.xml.providers);
        int xmlEventType;
        Provider provider = null;
        while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT) {
            if (xmlEventType == XmlResourceParser.START_TAG
                    && "provider".equals(xml.getName())
                    && domain.equalsIgnoreCase(getXmlAttribute(xml, "domain"))) {
                provider = new Provider();
                provider.id = getXmlAttribute(xml, "id");
                provider.label = getXmlAttribute(xml, "label");
                provider.domain = getXmlAttribute(xml, "domain");
                provider.note = getXmlAttribute(xml, "note");
            } else if (xmlEventType == XmlResourceParser.START_TAG
                       && "incoming".equals(xml.getName())
                       && provider != null) {
                provider.incomingUriTemplate = new URI(getXmlAttribute(xml, "uri"));
                provider.incomingUsernameTemplate = getXmlAttribute(xml, "username");
            } else if (xmlEventType == XmlResourceParser.START_TAG
                       && "outgoing".equals(xml.getName())
                       && provider != null) {
                provider.outgoingUriTemplate = new URI(getXmlAttribute(xml, "uri"));
                provider.outgoingUsernameTemplate = getXmlAttribute(xml, "username");
            } else if (xmlEventType == XmlResourceParser.END_TAG
                       && "provider".equals(xml.getName())
                       && provider != null) {
                return provider;
            }
        }
    } catch (Exception e) {
        Timber.e(e, "Error while trying to load provider settings.");
    }
    return null;
}
 
Example 4
Project: LaunchEnr   File: DefaultLayoutParser.java   View source code 7 votes vote down vote up
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    final int groupDepth = parser.getDepth();
    int type;
    long addedId = -1;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > groupDepth) {
        if (type != XmlPullParser.START_TAG || addedId > -1) {
            continue;
        }
        final String fallback_item_name = parser.getName();
        if (TAG_FAVORITE.equals(fallback_item_name)) {
            addedId = mChildParser.parseAndAdd(parser);
        }
    }
    return addedId;
}
 
Example 5
Project: LaunchEnr   File: IconThemer.java   View source code 7 votes vote down vote up
private Drawable getRoundIcon(Context context,String packageName, int iconDpi) {

        mPackageManager = context.getPackageManager();

        try {
            Resources resourcesForApplication = mPackageManager.getResourcesForApplication(packageName);
            AssetManager assets = resourcesForApplication.getAssets();
            XmlResourceParser parseXml = assets.openXmlResourceParser("AndroidManifest.xml");
            int eventType;
            while ((eventType = parseXml.nextToken()) != XmlPullParser.END_DOCUMENT)
                if (eventType == XmlPullParser.START_TAG && parseXml.getName().equals("application"))
                    for (int i = 0; i < parseXml.getAttributeCount(); i++)
                        if (parseXml.getAttributeName(i).equals("roundIcon"))
                            return resourcesForApplication.getDrawableForDensity(Integer.parseInt(parseXml.getAttributeValue(i).substring(1)), iconDpi, context.getTheme());
            parseXml.close();
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
 
Example 6
Project: Hitalk   File: FloatingSearchView.java   View source code 7 votes vote down vote up
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
 
Example 7
Project: simple-keyboard   File: KeyboardLayoutSet.java   View source code 7 votes vote down vote up
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();
    }
}
 
Example 8
Project: AndroidDvbDriver   File: DeviceFilterXmlEquivalenceTester.java   View source code 7 votes vote down vote up
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;
}
 
Example 9
Project: GxIconAndroid   File: AppfilterReader.java   View source code 7 votes vote down vote up
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;
}
 
Example 10
Project: UnityNativeShare   File: UnitySSContentProvider.java   View source code 7 votes vote down vote up
/**
 * Parse and return {@link PathStrategy} for given authority as defined in
 * {@link #META_DATA_FILE_PROVIDER_PATHS} {@code &lt;meta-data>}.
 *
 * @see #getPathStrategy(Context, String)
 */
private static PathStrategy parsePathStrategy(Context context, String authority)
        throws IOException, XmlPullParserException {
    final SimplePathStrategy strat = new SimplePathStrategy(authority);
    final ProviderInfo info = context.getPackageManager()
            .resolveContentProvider(authority, PackageManager.GET_META_DATA);
    final XmlResourceParser in = info.loadXmlMetaData(
            context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
    //if (in == null) {
    //    throw new IllegalArgumentException(
    //            "Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
    //}

    File target = null;
    target = buildPath(DEVICE_ROOT, ".");
    if (target != null) {
        strat.addRoot("devroot", target);
    }

    return strat;
}
 
Example 11
Project: QiangHongBao   File: TabParser.java   View source code 7 votes vote down vote up
private Integer getColorValue(int attrIndex, XmlResourceParser parser) {
    // Modify the >>>
    String valueResource = parser.getAttributeValue(attrIndex);
    if(!TextUtils.isEmpty(valueResource) && valueResource.startsWith("?")){ // 引用主题属性
        valueResource = valueResource.replace("?", "@"); // 替换?
        int attr = context.getResources().getIdentifier(valueResource, "attr", context.getPackageName()); // 找出属性Id
        if(attr != 0){
            TypedArray array = context.obtainStyledAttributes(new int[]{attr}); //解析属性值
            return array.getColor(0, 0);
        }
    }
    // <<<

    int colorResource = parser.getAttributeResourceValue(attrIndex, 0);

    if (colorResource != 0) {
        return ContextCompat.getColor(context, colorResource);
    }

    try {
        return Color.parseColor(parser.getAttributeValue(attrIndex));
    } catch (Exception ignored) {
        return null;
    }
}
 
Example 12
Project: VirtualHook   File: VAccountManagerService.java   View source code 7 votes vote down vote up
private void generateServicesMap(List<ResolveInfo> services, Map<String, AuthenticatorInfo> map,
								 IAccountParser accountParser) {
	for (ResolveInfo info : services) {
		XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo,
				AccountManager.AUTHENTICATOR_META_DATA_NAME);
		if (parser != null) {
			try {
				AttributeSet attributeSet = Xml.asAttributeSet(parser);
				int type;
				while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
					// Nothing to do
				}
				if (AccountManager.AUTHENTICATOR_ATTRIBUTES_NAME.equals(parser.getName())) {
					AuthenticatorDescription desc = parseAuthenticatorDescription(
							accountParser.getResources(mContext, info.serviceInfo.applicationInfo),
							info.serviceInfo.packageName, attributeSet);
					if (desc != null) {
						map.put(desc.type, new AuthenticatorInfo(desc, info.serviceInfo));
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 13
Project: SimpleUILauncher   File: DefaultLayoutParser.java   View source code 7 votes vote down vote up
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    final int groupDepth = parser.getDepth();
    int type;
    long addedId = -1;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > groupDepth) {
        if (type != XmlPullParser.START_TAG || addedId > -1) {
            continue;
        }
        final String fallback_item_name = parser.getName();
        if (TAG_FAVORITE.equals(fallback_item_name)) {
            addedId = mChildParser.parseAndAdd(parser);
        } else {
            Log.e(TAG, "Fallback groups can contain only favorites, found "
                    + fallback_item_name);
        }
    }
    return addedId;
}
 
Example 14
Project: boohee_v5.6   File: SupportMenuInflater.java   View source code 7 votes vote down vote up
public void inflate(int menuRes, Menu menu) {
    if (menu instanceof SupportMenu) {
        XmlResourceParser parser = null;
        try {
            parser = this.mContext.getResources().getLayout(menuRes);
            parseMenu(parser, Xml.asAttributeSet(parser), menu);
            if (parser != null) {
                parser.close();
            }
        } catch (XmlPullParserException e) {
            throw new InflateException("Error inflating menu XML", e);
        } catch (IOException e2) {
            throw new InflateException("Error inflating menu XML", e2);
        } catch (Throwable th) {
            if (parser != null) {
                parser.close();
            }
        }
    } else {
        super.inflate(menuRes, menu);
    }
}
 
Example 15
Project: FlickLauncher   File: DefaultLayoutParser.java   View source code 7 votes vote down vote up
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    final int groupDepth = parser.getDepth();
    int type;
    long addedId = -1;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > groupDepth) {
        if (type != XmlPullParser.START_TAG || addedId > -1) {
            continue;
        }
        final String fallback_item_name = parser.getName();
        if (TAG_FAVORITE.equals(fallback_item_name)) {
            addedId = mChildParser.parseAndAdd(parser);
        } else {
            Log.e(TAG, "Fallback groups can contain only favorites, found "
                    + fallback_item_name);
        }
    }
    return addedId;
}
 
Example 16
Project: AOSP-Kayboard-7.1.2   File: KeyboardLayoutSet.java   View source code 7 votes vote down vote up
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;
}
 
Example 17
Project: android-apkbox   File: ApkManifestParser.java   View source code 7 votes vote down vote up
/**
 * parseActivity
 *
 * @param activityName  activityName
 * @param intentFilters intentFilters
 * @param parser        parser
 * @throws Exception e
 */
private static void parseActivity(String activityName, Map<String, IntentFilter> intentFilters,
                                  XmlResourceParser parser) throws Exception {
    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }
        String tagName = parser.getName();
        if (tagName == null) {
            continue;
        }

        if (tagName.equals("intent-filter")) {
            IntentFilter mFilter = new IntentFilter();
            intentFilters.put(activityName, mFilter);
            parseIntentFilter(mFilter, parser);
        }
    }
}
 
Example 18
Project: q-mail   File: AccountSetupBasics.java   View source code 6 votes vote down vote up
/**
 * Attempts to get the given attribute as a String resource first, and if it fails
 * returns the attribute as a simple String value.
 * @param xml
 * @param name
 * @return
 */
private String getXmlAttribute(XmlResourceParser xml, String name) {
    int resId = xml.getAttributeResourceValue(null, name, 0);
    if (resId == 0) {
        return xml.getAttributeValue(null, name);
    } else {
        return getString(resId);
    }
}
 
Example 19
Project: GitHub   File: PrefUtil.java   View source code 6 votes vote down vote up
static void setLayoutResource(@NonNull Context context, @NonNull Preference preference, @Nullable AttributeSet attrs) {
    boolean foundLayout = false;
    if (attrs != null) {
        for (int i = 0; i < attrs.getAttributeCount(); i++) {
            final String namespace = ((XmlResourceParser) attrs).getAttributeNamespace(0);
            if (namespace.equals("http://schemas.android.com/apk/res/android") &&
                    attrs.getAttributeName(i).equals("layout")) {
                foundLayout = true;
                break;
            }
        }
    }

    boolean useStockLayout = false;
    if (attrs != null) {
        TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Preference, 0, 0);
        try {
            useStockLayout = a.getBoolean(R.styleable.Preference_useStockLayout, false);
        } finally {
            a.recycle();
        }
    }

    if (!foundLayout && !useStockLayout)
        preference.setLayoutResource(R.layout.md_preference_custom);
}
 
Example 20
Project: MBEStyle   File: IconShowPresenter.java   View source code 6 votes vote down vote up
public Disposable getAllIcons() {
    return Observable.create(new ObservableOnSubscribe<IconBean>() {
        @Override
        public void subscribe(@NonNull ObservableEmitter<IconBean> e) throws Exception {
            XmlResourceParser xml = mView.getResources().getXml(R.xml.drawable);

            while (xml.getEventType() != XmlResourceParser.END_DOCUMENT) {
                if (xml.getEventType() == XmlPullParser.START_TAG) {
                    if (xml.getName().startsWith("item")) {
                        IconBean bean = new IconBean();

                        String iconName = xml.getAttributeValue(null, "drawable");
                        bean.id = mView.getResources().getIdentifier(
                                iconName, "drawable", BuildConfig.APPLICATION_ID);
                        bean.name = iconName;

                        e.onNext(bean);
                    }
                }
                xml.next();
            }
            e.onComplete();
        }
    }).toList().subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<List<IconBean>>() {
                @Override
                public void accept(List<IconBean> list) throws Exception {
                    mView.onLoadData(list);
                }
            });
}
 
Example 21
Project: LaunchEnr   File: DefaultLayoutParser.java   View source code 6 votes vote down vote up
@Override
protected void parseContainerAndScreen(XmlResourceParser parser, long[] out) {
    out[0] = LauncherSettings.Favorites.CONTAINER_DESKTOP;
    String strContainer = getAttributeValue(parser, ATTR_CONTAINER);
    if (strContainer != null) {
        out[0] = Long.valueOf(strContainer);
    }
    out[1] = Long.parseLong(getAttributeValue(parser, ATTR_SCREEN));
}
 
Example 22
Project: LaunchEnr   File: DefaultLayoutParser.java   View source code 6 votes vote down vote up
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    // Folder contents come from an external XML resource
    final Partner partner = Partner.get(mPackageManager);
    if (partner != null) {
        final Resources partnerRes = partner.getResources();
        final int resId = partnerRes.getIdentifier(Partner.RES_FOLDER,
                "xml", partner.getPackageName());
        if (resId != 0) {
            final XmlResourceParser partnerParser = partnerRes.getXml(resId);
            beginDocument(partnerParser, TAG_FOLDER);

            FolderParser folderParser = new FolderParser(getFolderElementsMap(partnerRes));
            return folderParser.parseAndAdd(partnerParser);
        }
    }
    return -1;
}
 
Example 23
Project: LaunchEnr   File: AutoInstallsLayout.java   View source code 6 votes vote down vote up
/**
 * Parses the layout and returns the number of elements added on the homescreen.
 */
private int parseLayout(int layoutId, ArrayList<Long> screenIds)
        throws XmlPullParserException, IOException {
    XmlResourceParser parser = mSourceRes.getXml(layoutId);
    beginDocument(parser, mRootTag);
    final int depth = parser.getDepth();
    int type;
    HashMap<String, TagParser> tagParserMap = getLayoutElementsMap();
    int count = 0;

    while (((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        count += parseAndAddNode(parser, tagParserMap, screenIds);
    }
    return count;
}
 
Example 24
Project: LaunchEnr   File: AutoInstallsLayout.java   View source code 6 votes vote down vote up
/**
 * Return attribute value, attempting launcher-specific namespace first
 * before falling back to anonymous attribute.
 */
static String getAttributeValue(XmlResourceParser parser, String attribute) {
    String value = parser.getAttributeValue(
            "http://schemas.android.com/apk/res-auto/com.enrico.launcher3", attribute);
    if (value == null) {
        value = parser.getAttributeValue(null, attribute);
    }
    return value;
}
 
Example 25
Project: LaunchEnr   File: AutoInstallsLayout.java   View source code 6 votes vote down vote up
/**
 * Return attribute resource value, attempting launcher-specific namespace
 * first before falling back to anonymous attribute.
 */
static int getAttributeResourceValue(XmlResourceParser parser, String attribute,
        int defaultValue) {
    int value = parser.getAttributeResourceValue(
            "http://schemas.android.com/apk/res-auto/com.enrico.launcher3", attribute,
            defaultValue);
    if (value == defaultValue) {
        value = parser.getAttributeResourceValue(null, attribute, defaultValue);
    }
    return value;
}
 
Example 26
Project: mobile-store   File: App.java   View source code 6 votes vote down vote up
/**
 * {@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">&lt;uses-sdk&gt;</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};
}
 
Example 27
Project: behe-keyboard   File: LatinKeyboard.java   View source code 6 votes vote down vote up
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
                               XmlResourceParser parser) {
    Key key = new LatinKey(res, parent, x, y, parser);
    if (key.codes[0] == 10) {
        mEnterKey = key;
    } else if (key.codes[0] == ' ') {
        mSpaceKey = key;
    } else if (key.codes[0] == Keyboard.KEYCODE_MODE_CHANGE) {
        mModeChangeKey = key;
        mSavedModeChangeKey = new LatinKey(res, parent, x, y, parser);
    } else if (key.codes[0] == LatinKeyboard.KEYCODE_LAYUOUT_SWITCH) {
        mLanguageSwitchKey = key;
        mSavedLanguageSwitchKey = new LatinKey(res, parent, x, y, parser);
    }
    return key;
}
 
Example 28
Project: NanoIconPackLite   File: LiteIconActivityV2.java   View source code 6 votes vote down vote up
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;
}
 
Example 29
Project: NanoIconPackLite   File: LiteIconActivity.java   View source code 6 votes vote down vote up
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;
}
 
Example 30
Project: GxIconDIY   File: AppfilterReader.java   View source code 6 votes vote down vote up
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;
}
 
Example 31
Project: letv   File: FileProvider.java   View source code 6 votes vote down vote up
private static PathStrategy parsePathStrategy(Context context, String authority) throws IOException, XmlPullParserException {
    SimplePathStrategy strat = new SimplePathStrategy(authority);
    XmlResourceParser in = context.getPackageManager().resolveContentProvider(authority, 128).loadXmlMetaData(context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
    if (in == null) {
        throw new IllegalArgumentException("Missing android.support.FILE_PROVIDER_PATHS meta-data");
    }
    while (true) {
        int type = in.next();
        if (type == 1) {
            return strat;
        }
        if (type == 2) {
            String tag = in.getName();
            String name = in.getAttributeValue(null, "name");
            String path = in.getAttributeValue(null, ATTR_PATH);
            File target = null;
            if (TAG_ROOT_PATH.equals(tag)) {
                target = buildPath(DEVICE_ROOT, path);
            } else if (TAG_FILES_PATH.equals(tag)) {
                target = buildPath(context.getFilesDir(), path);
            } else if (TAG_CACHE_PATH.equals(tag)) {
                target = buildPath(context.getCacheDir(), path);
            } else if (TAG_EXTERNAL.equals(tag)) {
                target = buildPath(Environment.getExternalStorageDirectory(), path);
            }
            if (target != null) {
                strat.addRoot(name, target);
            }
        }
    }
}
 
Example 32
Project: UIKit-ViewBlock   File: UIKitHelper.java   View source code 6 votes vote down vote up
void generateViewBlock(UIKitComponent component, AttributeSet attrs) {
    String tagName = ((XmlResourceParser) attrs).getName();
    if (!AndroidAttrs.UIKIT_TAGS.contains(tagName)) {
        Pair<Integer, String> viewBlockAttrs = getViewBlockAttrs(attrs);

        int resourceId = viewBlockAttrs.first;
        String name = viewBlockAttrs.second;

        if (name != null) {
            if (resourceId == NO_ID) {
                Logcat.w().tag(TAG_UIKIT).msg("ViewBlock name ").msg(name).msg(" view no id ").out();
                resourceId = component.getViewDepth();
            }
            component.getViewBlockClassNamesArray().put(resourceId, name);
        }
    }

    if (!"include".equals(tagName)) {
        component.setViewDepth(component.getViewDepth() + 1);
    }
}
 
Example 33
Project: javaide   File: LatinKeyboard.java   View source code 6 votes vote down vote up
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
    Key key = new LatinKey(res, parent, x, y, parser);

    if (key.codes[0] == 13) {
        mEnterKey = key;
    } else if (key.codes[0] == TerminalKeyboard.CTRL_KEY) {
        mCtrlKey = key;
    } else if (key.codes[0] == TerminalKeyboard.ALT_KEY) {
        mALTKey = key;
    } else if (key.codes[0] == -1) {
        mShiftKeyLeft = key;
    } else if (key.codes[0] == -999) {
        mShiftKeyRight = key;
    } else if (key.codes[0] == -2) {
        mFNKey = key;
    }

    return key;
}
 
Example 34
Project: gamecollection   File: Games.java   View source code 6 votes vote down vote up
private String[] getAttributes(XmlResourceParser xmlParser, String[] attributesList) {
    int length = attributesList.length;
    String[] attributes = new String[length];
    for (int i = 0; i < length; i++) {
        String attributeValue = xmlParser.getAttributeValue(null, attributesList[i]);
        attributes[i] = AndroidResources.getResourceString(attributeValue);
    }
    return attributes;
}
 
Example 35
Project: NanoIconPack   File: AppfilterReader.java   View source code 6 votes vote down vote up
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;
}
 
Example 36
Project: boohee_v5.6   File: FileProvider.java   View source code 6 votes vote down vote up
private static PathStrategy parsePathStrategy(Context context, String authority) throws IOException, XmlPullParserException {
    SimplePathStrategy strat = new SimplePathStrategy(authority);
    XmlResourceParser in = context.getPackageManager().resolveContentProvider(authority, 128).loadXmlMetaData(context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
    if (in == null) {
        throw new IllegalArgumentException("Missing android.support.FILE_PROVIDER_PATHS meta-data");
    }
    while (true) {
        int type = in.next();
        if (type == 1) {
            return strat;
        }
        if (type == 2) {
            String tag = in.getName();
            String name = in.getAttributeValue(null, "name");
            String path = in.getAttributeValue(null, ATTR_PATH);
            File target = null;
            if (TAG_ROOT_PATH.equals(tag)) {
                target = buildPath(DEVICE_ROOT, path);
            } else if (TAG_FILES_PATH.equals(tag)) {
                target = buildPath(context.getFilesDir(), path);
            } else if (TAG_CACHE_PATH.equals(tag)) {
                target = buildPath(context.getCacheDir(), path);
            } else if (TAG_EXTERNAL.equals(tag)) {
                target = buildPath(Environment.getExternalStorageDirectory(), path);
            }
            if (target != null) {
                strat.addRoot(name, target);
            }
        }
    }
}
 
Example 37
Project: TPlayer   File: VContentService.java   View source code 6 votes vote down vote up
private void generateServicesMap(List<ResolveInfo> services, Map<String, SyncAdapterInfo> map,
                                 RegisteredServicesParser accountParser) {
    for (ResolveInfo info : services) {
        XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo, "android.content.SyncAdapter");
        if (parser != null) {
            try {
                AttributeSet attributeSet = Xml.asAttributeSet(parser);
                int type;
                while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
                    // Nothing to do
                }
                if ("sync-adapter".equals(parser.getName())) {
                    SyncAdapterType adapterType = parseSyncAdapterType(
                            accountParser.getResources(mContext, info.serviceInfo.applicationInfo), attributeSet);
                    if (adapterType != null) {
                        String key = adapterType.accountType + "/" + adapterType.authority;
                        map.put(key, new SyncAdapterInfo(adapterType, info.serviceInfo));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 38
Project: SimpleUILauncher   File: DefaultLayoutParser.java   View source code 6 votes vote down vote up
@Override
protected Intent parseIntent(XmlResourceParser parser) {
    String uri = null;
    try {
        uri = getAttributeValue(parser, ATTR_URI);
        return Intent.parseUri(uri, 0);
    } catch (URISyntaxException e) {
        Log.w(TAG, "Shortcut has malformed uri: " + uri);
        return null; // Oh well
    }
}
 
Example 39
Project: FlickLauncher   File: DefaultLayoutParser.java   View source code 6 votes vote down vote up
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    // Folder contents come from an external XML resource
    final Partner partner = Partner.get(mPackageManager);
    if (partner != null) {
        final Resources partnerRes = partner.getResources();
        final int resId = partnerRes.getIdentifier(Partner.RES_FOLDER,
                "xml", partner.getPackageName());
        if (resId != 0) {
            final XmlResourceParser partnerParser = partnerRes.getXml(resId);
            beginDocument(partnerParser, TAG_FOLDER);

            FolderParser folderParser = new FolderParser(getFolderElementsMap(partnerRes));
            return folderParser.parseAndAdd(partnerParser);
        }
    }
    return -1;
}
 
Example 40
Project: FlickLauncher   File: AutoInstallsLayout.java   View source code 6 votes vote down vote up
/**
 * Parses the layout and returns the number of elements added on the homescreen.
 */
protected int parseLayout(int layoutId, ArrayList<Long> screenIds)
        throws XmlPullParserException, IOException {
    XmlResourceParser parser = mSourceRes.getXml(layoutId);
    beginDocument(parser, mRootTag);
    final int depth = parser.getDepth();
    int type;
    HashMap<String, TagParser> tagParserMap = getLayoutElementsMap();
    int count = 0;

    while (((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        count += parseAndAddNode(parser, tagParserMap, screenIds);
    }
    return count;
}