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

The following examples show how to use android.content.res.XmlResourceParser#getAttributeCount() . 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: IconThemer.java    From LaunchEnr with GNU General Public License v3.0 6 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 2
Source File: ResourceDump.java    From AppTroy with Apache License 2.0 6 votes vote down vote up
private void getAttributes(StringBuilder sb, XmlResourceParser parser) throws XmlPullParserException {
    int count = parser.getAttributeCount();
    for (int i = 0; i < count; i++) {
        sb.append(" ");
        String namespace = parser.getAttributeNamespace(i);
        if (namespace != null) {
            int index = namespace.lastIndexOf("/");
            if (index > 0) {
                namespace = namespace.substring(index + 1);
            }
            sb.append(namespace);
            sb.append(":");
        }
        sb.append(parser.getAttributeName(i));
        sb.append("=");
        sb.append(parser.getAttributeValue(i));
    }
}
 
Example 3
Source File: TrustManagerBuilder.java    From cwac-netsecurity with Apache License 2.0 5 votes vote down vote up
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 4
Source File: App.java    From fdroidclient with GNU General Public License v3.0 5 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
            | NumberFormatException e) {
        Log.e(TAG, "Could not get min/max sdk version", e);
    }
    if (targetSdkVersion < minSdkVersion) {
        targetSdkVersion = minSdkVersion;
    }
    return new int[]{minSdkVersion, targetSdkVersion, maxSdkVersion};
}
 
Example 5
Source File: StreamProvider.java    From cwac-provider with Apache License 2.0 4 votes vote down vote up
private CompositeStreamStrategy parseStreamStrategy(final CompositeStreamStrategy result,
                                                    Context context,
                                                    String authority)
  throws IOException, XmlPullParserException {
  final ProviderInfo info=
    context.getPackageManager()
      .resolveContentProvider(authority,
        PackageManager.GET_META_DATA);

  useLegacyCursorWrapper=info.metaData.getBoolean(META_DATA_USE_LEGACY_CURSOR_WRAPPER, true);
  useUriForDataColumn=info.metaData.getBoolean(META_DATA_USE_URI_FOR_DATA_COLUMN, false);

  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");
  }

  int type;

  while ((type=in.next()) != org.xmlpull.v1.XmlPullParser.END_DOCUMENT) {
    if (type == org.xmlpull.v1.XmlPullParser.START_TAG) {
      final String tag=in.getName();

      if (!"paths".equals(tag)) {
        final String name=in.getAttributeValue(null, ATTR_NAME);

        if (TextUtils.isEmpty(name)) {
          throw new IllegalArgumentException("Name must not be empty");
        }

        String path=in.getAttributeValue(null, ATTR_PATH);
        boolean readOnly=allReadOnly ||
          Boolean.parseBoolean(in.getAttributeValue(null, ATTR_READ_ONLY));
        HashMap<String, String> attrs=new HashMap<String, String>();

        for (int i=0;i<in.getAttributeCount();i++) {
          attrs.put(in.getAttributeName(i), in.getAttributeValue(i));
        }

        StreamStrategy strategy=
          buildStrategy(context, tag, name, path, readOnly, attrs);

        if (strategy != null) {
          result.add(name, strategy);
        }
        else {
          throw new IllegalArgumentException("Could not build strategy for "
            + tag);
        }
      }
    }
  }

  return(result);
}
 
Example 6
Source File: XmlConfigSource.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
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 7
Source File: ResourcesCompat.java    From zhangshangwuda with Apache License 2.0 4 votes vote down vote up
/**
 * 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 8
Source File: ActionBarSherlockCompat.java    From Libraries-for-Android-Developers with MIT License 4 votes vote down vote up
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 9
Source File: ResourcesCompat.java    From zen4android with MIT License 4 votes vote down vote up
/**
 * 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 10
Source File: ActionBarSherlockCompat.java    From zen4android with MIT License 4 votes vote down vote up
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 11
Source File: ActionBarView.java    From android-apps with MIT License 4 votes vote down vote up
/**
 * 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 12
Source File: ActionBarSherlockCompat.java    From android-apps with MIT License 4 votes vote down vote up
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 13
Source File: DateSpinner.java    From ReminderDatePicker with Apache License 2.0 4 votes vote down vote up
@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 14
Source File: TimeSpinner.java    From ReminderDatePicker with Apache License 2.0 4 votes vote down vote up
@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 15
Source File: ResourcesCompat.java    From Libraries-for-Android-Developers with MIT License 4 votes vote down vote up
/**
 * 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 16
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 17
Source File: XmlConfigSource.java    From cwac-netsecurity with Apache License 2.0 4 votes vote down vote up
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 18
Source File: ResourcesCompat.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 19
Source File: Utility4.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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 20
Source File: ActionBarSherlockCompat.java    From CSipSimple with GNU General Public License v3.0 4 votes vote down vote up
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;
}