Java Code Examples for android.content.pm.PackageManager.getActivityIcon()

The following are Jave code examples for showing how to use getActivityIcon() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: FlickLauncher   File: IconCache.java   View Source Code Vote up 6 votes
/**
 * Pre-load an icon into the persistent cache.
 *
 * <P>Queries for a component that does not exist in the package manager
 * will be answered by the persistent cache.
 *
 * @param componentName the icon should be returned for this component
 * @param icon the icon to be persisted
 * @param dpi the native density of the icon
 */
public void preloadIcon(ComponentName componentName, Bitmap icon, int dpi, String label,
        long userSerial, InvariantDeviceProfile idp) {
    // TODO rescale to the correct native DPI
    try {
        PackageManager packageManager = mContext.getPackageManager();
        packageManager.getActivityIcon(componentName);
        // component is present on the system already, do nothing
        return;
    } catch (PackageManager.NameNotFoundException e) {
        // pass
    }

    icon = Bitmap.createScaledBitmap(icon, idp.iconBitmapSize, idp.iconBitmapSize, true);
    Bitmap lowResIcon = generateLowResIcon(icon, Color.TRANSPARENT);
    ContentValues values = newContentValues(icon, lowResIcon, label,
            componentName.getPackageName());
    values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString());
    values.put(IconDB.COLUMN_USER, userSerial);
    mIconDb.insertOrReplace(values);
}
 
Example 2
Project: SimpleUILauncher   File: IconCache.java   View Source Code Vote up 6 votes
/**
 * Pre-load an icon into the persistent cache.
 *
 * <P>Queries for a component that does not exist in the package manager
 * will be answered by the persistent cache.
 *
 * @param componentName the icon should be returned for this component
 * @param icon the icon to be persisted
 * @param dpi the native density of the icon
 */
public void preloadIcon(ComponentName componentName, Bitmap icon, int dpi, String label,
        long userSerial, InvariantDeviceProfile idp) {
    // TODO rescale to the correct native DPI
    try {
        PackageManager packageManager = mContext.getPackageManager();
        packageManager.getActivityIcon(componentName);
        // component is present on the system already, do nothing
        return;
    } catch (PackageManager.NameNotFoundException e) {
        // pass
    }

    icon = Bitmap.createScaledBitmap(icon, idp.iconBitmapSize, idp.iconBitmapSize, true);
    Bitmap lowResIcon = generateLowResIcon(icon, Color.TRANSPARENT);
    ContentValues values = newContentValues(icon, lowResIcon, label,
            componentName.getPackageName());
    values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString());
    values.put(IconDB.COLUMN_USER, userSerial);
    mIconDb.insertOrReplace(values);
}