Java Code Examples for android.content.res.XmlResourceParser#getAttributeName()
The following examples show how to use
android.content.res.XmlResourceParser#getAttributeName() .
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: PackageLite.java From ACDD with MIT License | 6 votes |
/** * parser ManifestAttribute such package name and so on * @param xmlResourceParser * @param mPackageLite */ private static void parserManifestAttribute( XmlResourceParser xmlResourceParser, PackageLite mPackageLite) { for (int i = 0; i < xmlResourceParser.getAttributeCount(); i++) { String value = xmlResourceParser.getAttributeName(i); if (value.equalsIgnoreCase("package")) { mPackageLite.packageName = xmlResourceParser .getAttributeValue(i); } if (value.equals("versionCode")) { mPackageLite.versionCode = xmlResourceParser .getAttributeIntValue(i, 0); } else if (value.equals("versionName")) { mPackageLite.versionName = xmlResourceParser .getAttributeValue(i); } } }
Example 2
Source File: TrustManagerBuilder.java From cwac-netsecurity with Apache License 2.0 | 5 votes |
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; } }
Example 3
Source File: DateSpinner.java From ReminderDatePicker with Apache License 2.0 | 4 votes |
@Override protected @Nullable TwinTextItem parseItemFromXmlTag(@NonNull XmlResourceParser parser) { if(!parser.getName().equals(XML_TAG_DATEITEM)) { Log.d("DateSpinner", "Unknown xml tag name: " + parser.getName()); return null; } // parse the DateItem, possible values are String text = null; @StringRes int textResource = NO_ID, id = NO_ID; Calendar date = Calendar.getInstance(); for(int i=parser.getAttributeCount()-1; i>=0; i--) { String attrName = parser.getAttributeName(i); switch (attrName) { case XML_ATTR_ID: id = parser.getIdAttributeResourceValue(NO_ID); break; case XML_ATTR_TEXT: text = parser.getAttributeValue(i); // try to get a resource value, the string is retrieved below if(text != null && text.startsWith("@")) textResource = parser.getAttributeResourceValue(i, NO_ID); break; case XML_ATTR_ABSDAYOFYEAR: final int absDayOfYear = parser.getAttributeIntValue(i, -1); if(absDayOfYear > 0) date.set(Calendar.DAY_OF_YEAR, absDayOfYear); break; case XML_ATTR_ABSDAYOFMONTH: final int absDayOfMonth = parser.getAttributeIntValue(i, -1); if(absDayOfMonth > 0) date.set(Calendar.DAY_OF_MONTH, absDayOfMonth); break; case XML_ATTR_ABSMONTH: final int absMonth = parser.getAttributeIntValue(i, -1); if(absMonth >= 0) date.set(Calendar.MONTH, absMonth); break; case XML_ATTR_ABSYEAR: final int absYear = parser.getAttributeIntValue(i, -1); if(absYear >= 0) date.set(Calendar.YEAR, absYear); break; case XML_ATTR_RELDAY: final int relDay = parser.getAttributeIntValue(i, 0); date.add(Calendar.DAY_OF_YEAR, relDay); break; case XML_ATTR_RELMONTH: final int relMonth = parser.getAttributeIntValue(i, 0); date.add(Calendar.MONTH, relMonth); break; case XML_ATTR_RELYEAR: final int relYear = parser.getAttributeIntValue(i, 0); date.add(Calendar.YEAR, relYear); break; default: Log.d("DateSpinner", "Skipping unknown attribute tag parsing xml resource: " + attrName + ", maybe a typo?"); } }// end for attr // now construct the date item from the attributes // check if we got a textResource earlier and parse that string together with the weekday if(textResource != NO_ID) text = getWeekDay(date.get(Calendar.DAY_OF_WEEK), textResource); // when no text is given, format the date to have at least something to show if(text == null || text.equals("")) text = formatDate(date); return new DateItem(text, date, id); }
Example 4
Source File: ResourcesCompat.java From Libraries-for-Android-Developers with MIT License | 4 votes |
/** * 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; }
Example 5
Source File: ActionBarSherlockCompat.java From Libraries-for-Android-Developers with MIT License | 4 votes |
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; }
Example 6
Source File: ResourcesCompat.java From zhangshangwuda with Apache License 2.0 | 4 votes |
/** * 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; }
Example 7
Source File: ActionBarSherlockCompat.java From zhangshangwuda with Apache License 2.0 | 4 votes |
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; }
Example 8
Source File: ResourcesCompat.java From zen4android with MIT License | 4 votes |
/** * 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; }
Example 9
Source File: ActionBarSherlockCompat.java From zen4android with MIT License | 4 votes |
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; }
Example 10
Source File: ActionBarView.java From android-apps with MIT License | 4 votes |
/** * 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. */ private static int loadLogoFromManifest(Activity activity) { int logo = 0; try { final String thisPackage = activity.getClass().getName(); if (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 (DEBUG) Log.d(TAG, "Got <application>"); for (int i = xml.getAttributeCount() - 1; i >= 0; i--) { if (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 (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 (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 (DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo)); return logo; }
Example 11
Source File: ActionBarSherlockCompat.java From android-apps with MIT License | 4 votes |
private static int loadUiOptionsFromManifest(Activity activity) { int uiOptions = 0; try { final String thisPackage = activity.getClass().getName(); if (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 (DEBUG) Log.d(TAG, "Got <application>"); for (int i = xml.getAttributeCount() - 1; i >= 0; i--) { if (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 (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 (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 (DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(uiOptions)); return uiOptions; }
Example 12
Source File: XmlConfigSource.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private List<Pair<NetworkSecurityConfig.Builder, Set<Domain>>> parseConfigEntry( XmlResourceParser parser, Set<String> seenDomains, NetworkSecurityConfig.Builder parentBuilder, int configType) throws IOException, XmlPullParserException, ParserException { List<Pair<NetworkSecurityConfig.Builder, Set<Domain>>> builders = new ArrayList<>(); NetworkSecurityConfig.Builder builder = new NetworkSecurityConfig.Builder(); builder.setParent(parentBuilder); Set<Domain> domains = new ArraySet<>(); boolean seenPinSet = false; boolean seenTrustAnchors = false; boolean defaultOverridePins = configType == CONFIG_DEBUG; String configName = parser.getName(); int outerDepth = parser.getDepth(); // Add this builder now so that this builder occurs before any of its children. This // makes the final build pass easier. builders.add(new Pair<>(builder, domains)); // Parse config attributes. Only set values that are present, config inheritence will // handle the rest. for (int i = 0; i < parser.getAttributeCount(); i++) { String name = parser.getAttributeName(i); if ("hstsEnforced".equals(name)) { builder.setHstsEnforced( parser.getAttributeBooleanValue(i, NetworkSecurityConfig.DEFAULT_HSTS_ENFORCED)); } else if ("cleartextTrafficPermitted".equals(name)) { builder.setCleartextTrafficPermitted( parser.getAttributeBooleanValue(i, NetworkSecurityConfig.DEFAULT_CLEARTEXT_TRAFFIC_PERMITTED)); } } // Parse the config elements. while (XmlUtils.nextElementWithin(parser, outerDepth)) { String tagName = parser.getName(); if ("domain".equals(tagName)) { if (configType != CONFIG_DOMAIN) { throw new ParserException(parser, "domain element not allowed in " + getConfigString(configType)); } Domain domain = parseDomain(parser, seenDomains); domains.add(domain); } else if ("trust-anchors".equals(tagName)) { if (seenTrustAnchors) { throw new ParserException(parser, "Multiple trust-anchor elements not allowed"); } builder.addCertificatesEntryRefs( parseTrustAnchors(parser, defaultOverridePins)); seenTrustAnchors = true; } else if ("pin-set".equals(tagName)) { if (configType != CONFIG_DOMAIN) { throw new ParserException(parser, "pin-set element not allowed in " + getConfigString(configType)); } if (seenPinSet) { throw new ParserException(parser, "Multiple pin-set elements not allowed"); } builder.setPinSet(parsePinSet(parser)); seenPinSet = true; } else if ("domain-config".equals(tagName)) { if (configType != CONFIG_DOMAIN) { throw new ParserException(parser, "Nested domain-config not allowed in " + getConfigString(configType)); } builders.addAll(parseConfigEntry(parser, seenDomains, builder, configType)); } else { XmlUtils.skipCurrentTag(parser); } } if (configType == CONFIG_DOMAIN && domains.isEmpty()) { throw new ParserException(parser, "No domain elements in domain-config"); } return builders; }
Example 13
Source File: TimeSpinner.java From ReminderDatePicker with Apache License 2.0 | 4 votes |
@Override protected @Nullable TwinTextItem parseItemFromXmlTag(@NonNull XmlResourceParser parser) { if(!parser.getName().equals(XML_TAG_TIMEITEM)) { Log.d("TimeSpinner", "Unknown xml tag name: " + parser.getName()); return null; } // parse the TimeItem, possible values are String text = null; @StringRes int textResource = NO_ID, id = NO_ID; int hour = 0, minute = 0; for(int i=parser.getAttributeCount()-1; i>=0; i--) { String attrName = parser.getAttributeName(i); switch (attrName) { case XML_ATTR_ID: id = parser.getIdAttributeResourceValue(NO_ID); break; case XML_ATTR_TEXT: text = parser.getAttributeValue(i); // try to get a resource value, the string is retrieved below if(text != null && text.startsWith("@")) textResource = parser.getAttributeResourceValue(i, NO_ID); break; case XML_ATTR_ABSHOUR: hour = parser.getAttributeIntValue(i, -1); break; case XML_ATTR_ABSMINUTE: minute = parser.getAttributeIntValue(i, -1); break; case XML_ATTR_RELHOUR: hour += parser.getAttributeIntValue(i, 0); break; case XML_ATTR_RELMINUTE: minute += parser.getAttributeIntValue(i, 0); break; default: Log.d("TimeSpinner", "Skipping unknown attribute tag parsing xml resource: " + attrName + ", maybe a typo?"); } }// end for attr // now construct the time item from the attributes if(textResource != NO_ID) text = getResources().getString(textResource); // when no text is given, format the date to have at least something to show if(text == null || text.equals("")) text = formatTime(hour, minute); return new TimeItem(text, formatTime(hour, minute), hour, minute, id); }
Example 14
Source File: TabParser.java From BottomBar with Apache License 2.0 | 4 votes |
@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 15
Source File: XmlConfigSource.java From cwac-netsecurity with Apache License 2.0 | 4 votes |
private List<Pair<NetworkSecurityConfig.Builder, Set<Domain>>> parseConfigEntry( XmlResourceParser parser, Set<String> seenDomains, NetworkSecurityConfig.Builder parentBuilder, int configType) throws IOException, XmlPullParserException, ParserException { List<Pair<NetworkSecurityConfig.Builder, Set<Domain>>> builders = new ArrayList<>(); NetworkSecurityConfig.Builder builder = new NetworkSecurityConfig.Builder(); builder.setParent(parentBuilder); Set<Domain> domains = new HashSet<>(); boolean seenPinSet = false; boolean seenTrustAnchors = false; boolean defaultOverridePins = configType == CONFIG_DEBUG; String configName = parser.getName(); int outerDepth = parser.getDepth(); // Add this builder now so that this builder occurs before any of its children. This // makes the final build pass easier. builders.add(new Pair<>(builder, domains)); // Parse config attributes. Only set values that are present, config inheritence will // handle the rest. for (int i = 0; i < parser.getAttributeCount(); i++) { String name = parser.getAttributeName(i); if ("hstsEnforced".equals(name)) { builder.setHstsEnforced( parser.getAttributeBooleanValue(i, NetworkSecurityConfig.DEFAULT_HSTS_ENFORCED)); } else if ("cleartextTrafficPermitted".equals(name)) { builder.setCleartextTrafficPermitted( parser.getAttributeBooleanValue(i, NetworkSecurityConfig.DEFAULT_CLEARTEXT_TRAFFIC_PERMITTED)); } } // Parse the config elements. while (XmlUtils.nextElementWithin(parser, outerDepth)) { String tagName = parser.getName(); if ("domain".equals(tagName)) { if (configType != CONFIG_DOMAIN) { throw new ParserException(parser, "domain element not allowed in " + getConfigString(configType)); } Domain domain = parseDomain(parser, seenDomains); domains.add(domain); } else if ("trust-anchors".equals(tagName)) { if (seenTrustAnchors) { throw new ParserException(parser, "Multiple trust-anchor elements not allowed"); } builder.addCertificatesEntryRefs( parseTrustAnchors(parser, defaultOverridePins)); seenTrustAnchors = true; } else if ("pin-set".equals(tagName)) { if (configType != CONFIG_DOMAIN) { throw new ParserException(parser, "pin-set element not allowed in " + getConfigString(configType)); } if (seenPinSet) { throw new ParserException(parser, "Multiple pin-set elements not allowed"); } builder.setPinSet(parsePinSet(parser)); seenPinSet = true; } else if ("domain-config".equals(tagName)) { if (configType != CONFIG_DOMAIN) { throw new ParserException(parser, "Nested domain-config not allowed in " + getConfigString(configType)); } builders.addAll(parseConfigEntry(parser, seenDomains, builder, configType)); } else { XmlUtils.skipCurrentTag(parser); } } if (configType == CONFIG_DOMAIN && domains.isEmpty()) { throw new ParserException(parser, "No domain elements in domain-config"); } return builders; }
Example 16
Source File: ResourcesCompat.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
/** * 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; }
Example 17
Source File: Utility4.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
/** * 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. */ private static int loadLogoFromManifest(Activity activity) { int logo = 0; try { final String thisPackage = activity.getClass().getName(); if (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 (DEBUG) Log.d(TAG, "Got <application>"); for (int i = xml.getAttributeCount() - 1; i >= 0; i--) { if (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 (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 (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 (DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo)); return logo; }
Example 18
Source File: ActionBarSherlockCompat.java From CSipSimple with GNU General Public License v3.0 | 4 votes |
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; }