Search in sources :

Example 6 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by AOSPA.

the class ModelUtils method fromLegacyShortcutIntent.

/**
 * Creates a workspace item info for the legacy shortcut intent
 */
@SuppressWarnings("deprecation")
public static WorkspaceItemInfo fromLegacyShortcutIntent(Context context, Intent data) {
    if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class) || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.class)) || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON, Bitmap.class))) {
        Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }
    Intent launchIntent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String label = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (launchIntent == null || label == null) {
        Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }
    final WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.user = Process.myUserHandle();
    BitmapInfo iconInfo = null;
    try (LauncherIcons li = LauncherIcons.obtain(context)) {
        Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
        if (bitmap != null) {
            iconInfo = li.createIconBitmap(bitmap);
        } else {
            info.iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            if (info.iconResource != null) {
                iconInfo = li.createIconBitmap(info.iconResource);
            }
        }
    }
    if (iconInfo == null) {
        Log.e(TAG, "Invalid icon by the app");
        return null;
    }
    info.bitmap = iconInfo;
    info.contentDescription = info.title = Utilities.trim(label);
    info.intent = launchIntent;
    return info;
}
Also used : Bitmap(android.graphics.Bitmap) LauncherIcons(com.android.launcher3.icons.LauncherIcons) Intent(android.content.Intent) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 7 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by AOSPA.

the class IconRequestInfo method loadWorkspaceIcon.

/**
 * Loads
 */
public boolean loadWorkspaceIcon(Context context) {
    if (!(itemInfo instanceof WorkspaceItemInfo)) {
        throw new IllegalStateException("loadWorkspaceIcon should only be use for a WorkspaceItemInfos: " + itemInfo);
    }
    try (LauncherIcons li = LauncherIcons.obtain(context)) {
        WorkspaceItemInfo info = (WorkspaceItemInfo) itemInfo;
        if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
            if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
                info.iconResource = new Intent.ShortcutIconResource();
                info.iconResource.packageName = packageName;
                info.iconResource.resourceName = resourceName;
                BitmapInfo iconInfo = li.createIconBitmap(info.iconResource);
                if (iconInfo != null) {
                    info.bitmap = iconInfo;
                    return true;
                }
            }
        }
        // Failed to load from resource, try loading from DB.
        try {
            if (iconBlob == null) {
                return false;
            }
            info.bitmap = li.createIconBitmap(decodeByteArray(iconBlob, 0, iconBlob.length));
            return true;
        } catch (Exception e) {
            Log.e(TAG, "Failed to decode byte array for info " + info, e);
            return false;
        }
    }
}
Also used : LauncherIcons(com.android.launcher3.icons.LauncherIcons) Intent(android.content.Intent) BitmapInfo(com.android.launcher3.icons.BitmapInfo)

Example 8 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by AOSPA.

the class TaskIconCache method getCacheEntry.

@WorkerThread
private TaskCacheEntry getCacheEntry(Task task) {
    TaskCacheEntry entry = mIconCache.getAndInvalidateIfModified(task.key);
    if (entry != null) {
        return entry;
    }
    TaskDescription desc = task.taskDescription;
    TaskKey key = task.key;
    ActivityInfo activityInfo = null;
    // Create new cache entry
    entry = new TaskCacheEntry();
    // Load icon
    // TODO: Load icon resource (b/143363444)
    Bitmap icon = TaskDescriptionCompat.getIcon(desc, key.userId);
    if (icon != null) {
        /* isInstantApp */
        entry.icon = getBitmapInfo(new BitmapDrawable(mContext.getResources(), icon), key.userId, desc.getPrimaryColor(), false).newIcon(mContext);
    } else {
        activityInfo = PackageManagerWrapper.getInstance().getActivityInfo(key.getComponent(), key.userId);
        if (activityInfo != null) {
            BitmapInfo bitmapInfo = getBitmapInfo(mIconProvider.getIcon(activityInfo), key.userId, desc.getPrimaryColor(), activityInfo.applicationInfo.isInstantApp());
            entry.icon = bitmapInfo.newIcon(mContext);
        } else {
            entry.icon = getDefaultIcon(key.userId);
        }
    }
    // Loading content descriptions if accessibility or low RAM recents is enabled.
    if (GO_LOW_RAM_RECENTS_ENABLED || mAccessibilityManager.isEnabled()) {
        // Skip loading the content description if the activity no longer exists
        if (activityInfo == null) {
            activityInfo = PackageManagerWrapper.getInstance().getActivityInfo(key.getComponent(), key.userId);
        }
        if (activityInfo != null) {
            entry.contentDescription = getBadgedContentDescription(activityInfo, task.key.userId, task.taskDescription);
        }
    }
    mIconCache.put(task.key, entry);
    return entry;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) Bitmap(android.graphics.Bitmap) TaskDescription(android.app.ActivityManager.TaskDescription) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TaskKey(com.android.systemui.shared.recents.model.Task.TaskKey) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkerThread(androidx.annotation.WorkerThread)

Example 9 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by AOSPA.

the class TaskIconCache method getBitmapInfo.

@WorkerThread
private BitmapInfo getBitmapInfo(Drawable drawable, int userId, int primaryColor, boolean isInstantApp) {
    try (BaseIconFactory bif = getIconFactory()) {
        bif.disableColorExtraction();
        bif.setWrapperBackgroundColor(primaryColor);
        // User version code O, so that the icon is always wrapped in an adaptive icon container
        return bif.createBadgedIconBitmap(drawable, UserHandle.of(userId), Build.VERSION_CODES.O, isInstantApp);
    }
}
Also used : BaseIconFactory(com.android.launcher3.icons.BaseIconFactory) WorkerThread(androidx.annotation.WorkerThread)

Example 10 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Launcher3 by AOSPA.

the class IconCache method getShortcutInfoBadge.

/**
 * Returns the badging info for the shortcut
 */
public BitmapInfo getShortcutInfoBadge(ShortcutInfo shortcutInfo) {
    ComponentName cn = shortcutInfo.getActivity();
    if (cn != null) {
        // Get the app info for the source activity.
        AppInfo appInfo = new AppInfo();
        appInfo.user = shortcutInfo.getUserHandle();
        appInfo.componentName = cn;
        appInfo.intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(cn);
        getTitleAndIcon(appInfo, false);
        return appInfo.bitmap;
    } else {
        PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage(), shortcutInfo.getUserHandle());
        getTitleAndIconForApp(pkgInfo, false);
        return pkgInfo.bitmap;
    }
}
Also used : PackageItemInfo(com.android.launcher3.model.data.PackageItemInfo) ComponentName(android.content.ComponentName) Intent(android.content.Intent) AppInfo(com.android.launcher3.model.data.AppInfo)

Aggregations

BitmapInfo (com.android.launcher3.icons.BitmapInfo)33 LauncherIcons (com.android.launcher3.icons.LauncherIcons)21 Intent (android.content.Intent)18 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)18 Bitmap (android.graphics.Bitmap)15 ComponentName (android.content.ComponentName)14 Context (android.content.Context)14 IconCache (com.android.launcher3.icons.IconCache)13 WorkerThread (androidx.annotation.WorkerThread)11 ItemInfo (com.android.launcher3.model.data.ItemInfo)11 List (java.util.List)9 ShortcutInfo (android.content.pm.ShortcutInfo)8 PackageInfo (android.content.pm.PackageInfo)7 BitmapDrawable (android.graphics.drawable.BitmapDrawable)6 TaskDescription (android.app.ActivityManager.TaskDescription)5 ActivityInfo (android.content.pm.ActivityInfo)5 LauncherApps (android.content.pm.LauncherApps)5 UserManager (android.os.UserManager)5 R (com.android.launcher3.R)5 BaseIconFactory (com.android.launcher3.icons.BaseIconFactory)5