Search in sources :

Example 16 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 17 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 18 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)

Example 19 with BitmapInfo

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

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 20 with BitmapInfo

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

the class CacheDataUpdatedTaskTest method setup.

@Before
public void setup() throws Exception {
    mModelHelper = new LauncherModelHelper();
    mModelHelper.initializeData("cache_data_updated_task_data");
    // Add placeholder entries in the cache to simulate update
    Context context = mModelHelper.sandboxContext;
    IconCache iconCache = LauncherAppState.getInstance(context).getIconCache();
    CachingLogic<ItemInfo> placeholderLogic = new CachingLogic<ItemInfo>() {

        @Override
        public ComponentName getComponent(ItemInfo info) {
            return info.getTargetComponent();
        }

        @Override
        public UserHandle getUser(ItemInfo info) {
            return info.user;
        }

        @Override
        public CharSequence getLabel(ItemInfo info) {
            return NEW_LABEL_PREFIX + info.id;
        }

        @NonNull
        @Override
        public BitmapInfo loadIcon(Context context, ItemInfo info) {
            return BitmapInfo.of(Bitmap.createBitmap(1, 1, Config.ARGB_8888), Color.RED);
        }
    };
    UserManager um = context.getSystemService(UserManager.class);
    for (ItemInfo info : mModelHelper.getBgDataModel().itemsIdMap) {
        iconCache.addIconToDBAndMemCache(info, placeholderLogic, new PackageInfo(), um.getSerialNumberForUser(info.user), true);
    }
}
Also used : Context(android.content.Context) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserManager(android.os.UserManager) PackageInfo(android.content.pm.PackageInfo) LauncherModelHelper(com.android.launcher3.util.LauncherModelHelper) IconCache(com.android.launcher3.icons.IconCache) CachingLogic(com.android.launcher3.icons.cache.CachingLogic) Before(org.junit.Before)

Aggregations

BitmapInfo (com.android.launcher3.icons.BitmapInfo)28 LauncherIcons (com.android.launcher3.icons.LauncherIcons)18 Intent (android.content.Intent)15 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)15 Bitmap (android.graphics.Bitmap)13 ComponentName (android.content.ComponentName)12 Context (android.content.Context)12 IconCache (com.android.launcher3.icons.IconCache)11 WorkerThread (androidx.annotation.WorkerThread)9 ItemInfo (com.android.launcher3.model.data.ItemInfo)9 ShortcutInfo (android.content.pm.ShortcutInfo)7 PackageInfo (android.content.pm.PackageInfo)6 List (java.util.List)6 LauncherApps (android.content.pm.LauncherApps)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)5 AppInfo (com.android.launcher3.model.data.AppInfo)5 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)5 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)5 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)5 FlagOp (com.android.launcher3.util.FlagOp)5