Search in sources :

Example 1 with BitmapInfo

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

the class LoaderCursor method loadIcon.

/**
 * Loads the icon from the cursor and updates the {@param info} if the icon is an app resource.
 */
protected boolean loadIcon(WorkspaceItemInfo info) {
    try (LauncherIcons li = LauncherIcons.obtain(mContext)) {
        if (itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
            String packageName = getString(iconPackageIndex);
            String resourceName = getString(iconResourceIndex);
            if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
                info.iconResource = new 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.
        byte[] data = getBlob(iconIndex);
        try {
            info.bitmap = li.createIconBitmap(decodeByteArray(data, 0, data.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) ShortcutIconResource(android.content.Intent.ShortcutIconResource) BitmapInfo(com.android.launcher3.icons.BitmapInfo) URISyntaxException(java.net.URISyntaxException) InvalidParameterException(java.security.InvalidParameterException)

Example 2 with BitmapInfo

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

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

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

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

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

the class CacheDataUpdatedTaskTest method setup.

@Before
public void setup() throws Exception {
    mModelHelper = new LauncherModelHelper();
    mModelHelper.initializeData("/cache_data_updated_task_data.txt");
    // Add placeholder entries in the cache to simulate update
    Context context = RuntimeEnvironment.application;
    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)

Example 5 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project android_packages_apps_Trebuchet by LineageOS.

the class InstallShortcutReceiver method createWorkspaceItemInfo.

private static WorkspaceItemInfo createWorkspaceItemInfo(Intent data, UserHandle user, LauncherAppState app) {
    if (data == null) {
        Log.e(TAG, "Can't construct WorkspaceItemInfo with null data");
        return null;
    }
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    if (intent == null) {
        // If the intent is null, return null as we can't construct a valid WorkspaceItemInfo
        Log.e(TAG, "Can't construct WorkspaceItemInfo with null intent");
        return null;
    }
    final WorkspaceItemInfo info = new WorkspaceItemInfo();
    info.user = user;
    BitmapInfo iconInfo = null;
    LauncherIcons li = LauncherIcons.obtain(app.getContext());
    if (bitmap instanceof Bitmap) {
        iconInfo = li.createIconBitmap((Bitmap) bitmap);
    } else {
        Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (extra instanceof Intent.ShortcutIconResource) {
            info.iconResource = (Intent.ShortcutIconResource) extra;
            iconInfo = li.createIconBitmap(info.iconResource);
        }
    }
    li.recycle();
    if (iconInfo == null) {
        iconInfo = app.getIconCache().getDefaultIcon(info.user);
    }
    info.bitmap = iconInfo;
    info.title = Utilities.trim(name);
    info.contentDescription = app.getContext().getPackageManager().getUserBadgedLabel(info.title, info.user);
    info.intent = intent;
    return info;
}
Also used : Bitmap(android.graphics.Bitmap) LauncherIcons(com.android.launcher3.icons.LauncherIcons) Intent(android.content.Intent) Parcelable(android.os.Parcelable) BitmapInfo(com.android.launcher3.icons.BitmapInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

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