Java Code Examples for android.content.res.XmlResourceParser#getAttributeBooleanValue()

The following examples show how to use android.content.res.XmlResourceParser#getAttributeBooleanValue() . 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: XmlConfigSource.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private Domain parseDomain(XmlResourceParser parser, Set<String> seenDomains)
        throws IOException, XmlPullParserException, ParserException {
    boolean includeSubdomains =
            parser.getAttributeBooleanValue(null, "includeSubdomains", false);
    if (parser.next() != XmlPullParser.TEXT) {
        throw new ParserException(parser, "Domain name missing");
    }
    String domain = parser.getText().trim().toLowerCase(Locale.US);
    if (parser.next() != XmlPullParser.END_TAG) {
        throw new ParserException(parser, "domain contains additional elements");
    }
    // Domains are matched using a most specific match, so don't allow duplicates.
    // includeSubdomains isn't relevant here, both android.com + subdomains and android.com
    // match for android.com equally. Do not allow any duplicates period.
    if (!seenDomains.add(domain)) {
        throw new ParserException(parser, domain + " has already been specified");
    }
    return new Domain(domain, includeSubdomains);
}
 
Example 2
Source File: XmlConfigSource.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private CertificatesEntryRef parseCertificatesEntry(XmlResourceParser parser,
        boolean defaultOverridePins)
        throws IOException, XmlPullParserException, ParserException {
    boolean overridePins =
            parser.getAttributeBooleanValue(null, "overridePins", defaultOverridePins);
    int sourceId = parser.getAttributeResourceValue(null, "src", -1);
    String sourceString = parser.getAttributeValue(null, "src");
    CertificateSource source = null;
    if (sourceString == null) {
        throw new ParserException(parser, "certificates element missing src attribute");
    }
    if (sourceId != -1) {
        // TODO: Cache ResourceCertificateSources by sourceId
        source = new ResourceCertificateSource(sourceId, mContext);
    } else if ("system".equals(sourceString)) {
        source = SystemCertificateSource.getInstance();
    } else if ("user".equals(sourceString)) {
        source = UserCertificateSource.getInstance();
    } else {
        throw new ParserException(parser, "Unknown certificates src. "
                + "Should be one of system|user|@resourceVal");
    }
    XmlUtils.skipCurrentTag(parser);
    return new CertificatesEntryRef(source, overridePins);
}
 
Example 3
Source File: XmlConfigSource.java    From cwac-netsecurity with Apache License 2.0 6 votes vote down vote up
private Domain parseDomain(XmlResourceParser parser, Set<String> seenDomains)
        throws IOException, XmlPullParserException, ParserException {
    boolean includeSubdomains =
            parser.getAttributeBooleanValue(null, "includeSubdomains", false);
    if (parser.next() != XmlPullParser.TEXT) {
        throw new ParserException(parser, "Domain name missing");
    }
    String domain = parser.getText().trim().toLowerCase(Locale.US);
    if (parser.next() != XmlPullParser.END_TAG) {
        throw new ParserException(parser, "domain contains additional elements");
    }
    // Domains are matched using a most specific match, so don't allow duplicates.
    // includeSubdomains isn't relevant here, both android.com + subdomains and android.com
    // match for android.com equally. Do not allow any duplicates period.
    if (!seenDomains.add(domain)) {
        throw new ParserException(parser, domain + " has already been specified");
    }
    return new Domain(domain, includeSubdomains);
}
 
Example 4
Source File: XmlConfigSource.java    From cwac-netsecurity with Apache License 2.0 6 votes vote down vote up
private CertificatesEntryRef parseCertificatesEntry(XmlResourceParser parser,
            boolean defaultOverridePins)
            throws IOException, XmlPullParserException, ParserException {
        boolean overridePins =
                parser.getAttributeBooleanValue(null, "overridePins", defaultOverridePins);
        int sourceId = parser.getAttributeResourceValue(null, "src", -1);
        String sourceString = parser.getAttributeValue(null, "src");
        CertificateSource source = null;
        if (sourceString == null) {
            throw new ParserException(parser, "certificates element missing src attribute");
        }
        if (sourceId != -1) {
            // TODO: Cache ResourceCertificateSources by sourceId
            source = new ResourceCertificateSource(sourceId, mContext);
        } else if ("system".equals(sourceString) || "user".equals(sourceString)) {
            // MLM treat user as system
            source = SystemCertificateSource.getInstance();
//        } else if ("user".equals(sourceString)) {
//            source = UserCertificateSource.getInstance();
        } else {
            throw new ParserException(parser, "Unknown certificates src. "
                    + "Should be one of system|user|@resourceVal");
        }
        XmlUtils.skipCurrentTag(parser);
        return new CertificatesEntryRef(source, overridePins);
    }
 
Example 5
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 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: FrameVO.java    From tilt-game-android with MIT License 5 votes vote down vote up
public FrameVO(XmlResourceParser parser) {
	int x, y, width, height;

	x = parser.getAttributeIntValue(null, "x", 0);
	y = parser.getAttributeIntValue(null, "y", 0);
	width = parser.getAttributeIntValue(null, "width", 0);
	height = parser.getAttributeIntValue(null, "height", 0);
	_bounds = new Rect(x, y, x + width, y + height);

	x = -parser.getAttributeIntValue(null, "frameX", 0);
	y = -parser.getAttributeIntValue(null, "frameY", 0);
	_frame = new Rect(x, y, x + width, y + height);

	_rotated = parser.getAttributeBooleanValue(null, "rotated", false);
}
 
Example 8
Source File: AndroidFont.java    From CrossMobile with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("UseSpecificCatch")
private static Map<String, Map<String, FontInfo>> fonts() {
    if (font_map != null)
        return font_map;

    font_map = new LinkedHashMap<>();

    Map<String, FontInfo> family = new LinkedHashMap<>();
    family.put("Sans Serif Regular", new FontInfo(false, false, Typeface.SANS_SERIF));
    family.put("Sans Serif Italic", new FontInfo(false, true, Typeface.SANS_SERIF));
    family.put("Sans Serif Bold", new FontInfo(true, false, Typeface.SANS_SERIF));
    family.put("Sans Serif Bold Italic", new FontInfo(true, true, Typeface.SANS_SERIF));
    font_map.put("Sans Serif", family);

    family = new LinkedHashMap<>();
    family.put("Serif", new FontInfo(false, false, Typeface.SERIF));
    font_map.put("Serif", family);

    family = new LinkedHashMap<>();
    family.put("Monospace", new FontInfo(false, false, Typeface.MONOSPACE));
    font_map.put("Monospace", family);

    XmlResourceParser parser = MainActivity.current.getResources().getXml(AndroidFileBridge.getResourceID("xml", "fontlist"));
    try {
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            switch (eventType) {
                case XmlPullParser.START_TAG:
                    if (parser.getName().equals("font")) {
                        String file = parser.getAttributeValue(null, "file");
                        String familyname = parser.getAttributeValue(null, "family");
                        String name = parser.getAttributeValue(null, "name");
                        boolean bold = parser.getAttributeBooleanValue(null, "bold", false);
                        boolean italic = parser.getAttributeBooleanValue(null, "italic", false);
                        family = font_map.get(familyname);
                        if (family == null) {
                            family = new LinkedHashMap<>();
                            font_map.put(familyname, family);
                        }
                        family.put(name, new FontInfo(bold, italic, file));
                    }
                    break;
                default:
                    break;
            }
            eventType = parser.next();
        }
        parser.close();
    } catch (Exception e) {
    }
    return font_map;
}
 
Example 9
Source File: EmailProvider.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
static List<EmailProvider> loadProfiles(Context context) {
    List<EmailProvider> result = null;
    try {
        EmailProvider provider = null;
        XmlResourceParser xml = context.getResources().getXml(R.xml.providers);
        int eventType = xml.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                String name = xml.getName();
                if ("providers".equals(name))
                    result = new ArrayList<>();
                else if ("provider".equals(name)) {
                    provider = new EmailProvider();
                    provider.id = xml.getAttributeValue(null, "id");
                    provider.name = xml.getAttributeValue(null, "name");
                    String domain = xml.getAttributeValue(null, "domain");
                    if (domain != null)
                        provider.domain = Arrays.asList(domain.split(","));
                    provider.order = xml.getAttributeIntValue(null, "order", Integer.MAX_VALUE);
                    provider.keepalive = xml.getAttributeIntValue(null, "keepalive", 0);
                    provider.partial = xml.getAttributeBooleanValue(null, "partial", true);
                    provider.useip = xml.getAttributeBooleanValue(null, "useip", true);
                    provider.appPassword = xml.getAttributeBooleanValue(null, "appPassword", false);
                    provider.link = xml.getAttributeValue(null, "link");
                    provider.type = xml.getAttributeValue(null, "type");
                    String user = xml.getAttributeValue(null, "user");
                    if ("local".equals(user))
                        provider.user = UserType.LOCAL;
                    else if ("email".equals(user))
                        provider.user = UserType.EMAIL;
                } else if ("imap".equals(name)) {
                    provider.imap.host = xml.getAttributeValue(null, "host");
                    provider.imap.port = xml.getAttributeIntValue(null, "port", 0);
                    provider.imap.starttls = xml.getAttributeBooleanValue(null, "starttls", false);
                } else if ("smtp".equals(name)) {
                    provider.smtp.host = xml.getAttributeValue(null, "host");
                    provider.smtp.port = xml.getAttributeIntValue(null, "port", 0);
                    provider.smtp.starttls = xml.getAttributeBooleanValue(null, "starttls", false);
                } else if ("oauth".equals(name)) {
                    provider.oauth = new OAuth();
                    provider.oauth.enabled = xml.getAttributeBooleanValue(null, "enabled", false);
                    provider.oauth.askAccount = xml.getAttributeBooleanValue(null, "askAccount", false);
                    provider.oauth.clientId = xml.getAttributeValue(null, "clientId");
                    provider.oauth.clientSecret = xml.getAttributeValue(null, "clientSecret");
                    provider.oauth.scopes = xml.getAttributeValue(null, "scopes").split(",");
                    provider.oauth.authorizationEndpoint = xml.getAttributeValue(null, "authorizationEndpoint");
                    provider.oauth.tokenEndpoint = xml.getAttributeValue(null, "tokenEndpoint");
                    provider.oauth.redirectUri = xml.getAttributeValue(null, "redirectUri");
                } else
                    throw new IllegalAccessException(name);
            } else if (eventType == XmlPullParser.END_TAG) {
                if ("provider".equals(xml.getName())) {
                    result.add(provider);
                    provider = null;
                }
            }

            eventType = xml.next();
        }
    } catch (Throwable ex) {
        Log.e(ex);
    }
    final Collator collator = Collator.getInstance(Locale.getDefault());
    collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc

    Collections.sort(result, new Comparator<EmailProvider>() {
        @Override
        public int compare(EmailProvider p1, EmailProvider p2) {
            int o = Integer.compare(p1.order, p2.order);
            if (o == 0)
                return collator.compare(p1.name, p2.name);
            else
                return o;
        }
    });

    return result;
}
 
Example 10
Source File: ResourceUtils.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
public static Map<String,String> getHashMapResource(Context c, int hashMapResId) {
    Map<String,String> map = null;
    XmlResourceParser parser = c.getResources().getXml(hashMapResId);

    String key = null, value = null;

    try {
        int eventType = parser.getEventType();

        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_DOCUMENT) {
                Log.d("utils","Start document");
            } else if (eventType == XmlPullParser.START_TAG) {
                if (parser.getName().equals("map")) {
                    boolean isLinked = parser.getAttributeBooleanValue(null, "linked", false);

                    map = isLinked ? new LinkedHashMap<String, String>() : new HashMap<String, String>();
                } else if (parser.getName().equals("entry")) {
                    key = parser.getAttributeValue(null, "key");

                    if (null == key) {
                        parser.close();
                        return null;
                    }
                }
            } else if (eventType == XmlPullParser.END_TAG) {
                if (parser.getName().equals("entry")) {
                    map.put(key, value);
                    key = null;
                    value = null;
                }
            } else if (eventType == XmlPullParser.TEXT) {
                if (null != key) {
                    value = parser.getText();
                }
            }
            eventType = parser.next();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    return map;
}
 
Example 11
Source File: TabParser.java    From BottomBar with Apache License 2.0 4 votes vote down vote up
@NonNull
private BottomBarTab parseNewTab(@NonNull XmlResourceParser parser, @IntRange(from = 0) int containerPosition) {
    BottomBarTab workingTab = tabWithDefaults();
    workingTab.setIndexInContainer(containerPosition);

    final int numberOfAttributes = parser.getAttributeCount();
    for (int i = 0; i < numberOfAttributes; i++) {
        @TabAttribute
        String attrName = parser.getAttributeName(i);
        switch (attrName) {
            case ID:
                workingTab.setId(parser.getIdAttributeResourceValue(i));
                break;
            case ICON:
                workingTab.setIconResId(parser.getAttributeResourceValue(i, RESOURCE_NOT_FOUND));
                break;
            case TITLE:
                workingTab.setTitle(getTitleValue(parser, i));
                break;
            case INACTIVE_COLOR:
                int inactiveColor = getColorValue(parser, i);
                if (inactiveColor == COLOR_NOT_SET) continue;
                workingTab.setInActiveColor(inactiveColor);
                break;
            case ACTIVE_COLOR:
                int activeColor = getColorValue(parser, i);
                if (activeColor == COLOR_NOT_SET) continue;
                workingTab.setActiveColor(activeColor);
                break;
            case BAR_COLOR_WHEN_SELECTED:
                int barColorWhenSelected = getColorValue(parser, i);
                if (barColorWhenSelected == COLOR_NOT_SET) continue;
                workingTab.setBarColorWhenSelected(barColorWhenSelected);
                break;
            case BADGE_BACKGROUND_COLOR:
                int badgeBackgroundColor = getColorValue(parser, i);
                if (badgeBackgroundColor == COLOR_NOT_SET) continue;
                workingTab.setBadgeBackgroundColor(badgeBackgroundColor);
                break;
            case BADGE_HIDES_WHEN_ACTIVE:
                boolean badgeHidesWhenActive = parser.getAttributeBooleanValue(i, true);
                workingTab.setBadgeHidesWhenActive(badgeHidesWhenActive);
                break;
            case IS_TITLELESS:
                boolean isTitleless = parser.getAttributeBooleanValue(i, false);
                workingTab.setIsTitleless(isTitleless);
                break;
        }
    }

    return workingTab;
}
 
Example 12
Source File: XmlHelper.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
@NonNull
public static Config getConfig(XmlResourceParser parser)
        throws XmlPullParserException, IOException {
    Config config = new Config();

    for (int type = parser.getEventType(); type != XmlPullParser.END_DOCUMENT; type = parser.next()) {
        if (type == XmlPullParser.START_TAG && Constants.FILTER_TAG_CONFIG.equals(parser.getName())) {
            config.hasWeatherIcons = parser.getAttributeBooleanValue(
                    null,
                    Constants.CONFIG_HAS_WEATHER_ICONS,
                    config.hasWeatherIcons
            );

            config.hasWeatherAnimators = parser.getAttributeBooleanValue(
                    null,
                    Constants.CONFIG_HAS_WEATHER_ANIMATORS,
                    config.hasWeatherIcons
            );

            config.hasMinimalIcons = parser.getAttributeBooleanValue(
                    null,
                    Constants.CONFIG_HAS_MINIMAL_ICONS,
                    config.hasMinimalIcons
            );

            config.hasShortcutIcons = parser.getAttributeBooleanValue(
                    null,
                    Constants.CONFIG_HAS_SHORTCUT_ICONS,
                    config.hasShortcutIcons
            );

            config.hasSunMoonDrawables = parser.getAttributeBooleanValue(
                    null,
                    Constants.CONFIG_HAS_SUN_MOON_DRAWABLES,
                    config.hasSunMoonDrawables
            );
        }
    }

    return config;
}