Example usage for android.app Activity getApplicationInfo

List of usage examples for android.app Activity getApplicationInfo

Introduction

In this page you can find the example usage for android.app Activity getApplicationInfo.

Prototype

@Override
    public ApplicationInfo getApplicationInfo() 

Source Link

Usage

From source file:Main.java

public static String getAppName(Activity activity) {
    return activity.getApplicationInfo().loadLabel(activity.getPackageManager()).toString();
}

From source file:Main.java

/**
 * Overrides whatever theme the activity currently has with either
 * Theme_Holo_Light or Theme_Light, depending on OS support.
 *
 * @param activity/*ww  w.j  av a 2s  .c om*/
 * @param useApplicationTheme
 */

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static void setActivityTheme(Activity activity, boolean useApplicationTheme) {

    if (useApplicationTheme && 0 != activity.getApplicationInfo().theme) {
        activity.setTheme(activity.getApplicationInfo().theme);
    } else if (holoSupported()) {
        activity.setTheme(android.R.style.Theme_Holo_Light);
    } else {
        activity.setTheme(android.R.style.Theme_Light);
    }
}

From source file:Main.java

public static String getPackageName(Activity instance) {
    PackageManager pManager = instance.getPackageManager();
    return pManager.getApplicationLabel(instance.getApplicationInfo()).toString();
}

From source file:com.google.samples.apps.iosched.util.RecentTasksStyler.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void styleRecentTasksEntry(Activity activity) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return;/* www . ja v  a  2 s. co  m*/
    }

    final String label = activity.getString(activity.getApplicationInfo().labelRes);
    final int colorPrimary = UIUtils.getThemeColor(activity, R.attr.colorPrimary, R.color.theme_primary);
    if (sIcon == null) {
        // Cache to avoid decoding the same bitmap on every Activity change
        sIcon = UIUtils.vectorToBitmap(activity, R.drawable.ic_recents_logo);
    }
    activity.setTaskDescription(new ActivityManager.TaskDescription(label, sIcon, colorPrimary));
}

From source file:net.sf.sprockets.app.NavigationDrawerToggle.java

/**
 * Manage the Activity's ActionBar and listen for navigation drawer events on the DrawerLayout.
 *//*from  w w w .  j  a  va2  s  .c om*/
public NavigationDrawerToggle(Activity activity, DrawerLayout layout) {
    super(activity, layout, R.drawable.ic_drawer, R.string.open_navigation_drawer,
            R.string.close_navigation_drawer);
    mActivity = activity;
    mLayout = layout;
    mApp = activity.getPackageManager().getApplicationLabel(activity.getApplicationInfo());
    mActionBar = activity.getActionBar();
    mActionBar.setDisplayHomeAsUpEnabled(true);
    layout.setDrawerShadow(R.drawable.drawer_shadow, START);
    layout.setDrawerListener(this);
}

From source file:com.actionbarsherlock.internal.ActionBarSherlockCompat.java

private static int loadUiOptionsFromManifest(Activity activity) {
    int uiOptions = 0;
    try {/*www  . j  av  a2 s . c  om*/
        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;
}

From source file:com.platform.APIClient.java

private APIClient(Activity context) {
    ctx = context;/*from  w ww.ja  v a  2 s. c  o  m*/
    if (0 != (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) {
        BREAD_BUY = "bread-buy-staging";
    }
}

From source file:com.actionbarsherlock.internal.widget.ActionBarView.java

/**
 * 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.//from   ww w.  jav  a 2s. co  m
 * @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;
}

From source file:org.appcelerator.titanium.view.TiDrawableReference.java

public TiDrawableReference(Activity activity, DrawableReferenceType type) {
    this.type = type;
    softActivity = new SoftReference<Activity>(activity);
    ApplicationInfo appInfo;//  w  w  w.  j av  a 2 s .  co m

    if (activity != null) {
        appInfo = activity.getApplicationInfo();
    } else {
        appInfo = TiApplication.getInstance().getApplicationInfo();
    }
    anyDensityFalse = (appInfo.flags & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) == 0;
}