Search in sources :

Example 11 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)

Example 12 with BitmapInfo

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

the class CacheDataUpdatedTaskTest method setup.

@Before
public void setup() throws Exception {
    mModelHelper = new LauncherModelHelper();
    mModelHelper.initializeData("/cache_data_updated_task_data.txt");
    // Add dummy entries in the cache to simulate update
    Context context = RuntimeEnvironment.application;
    IconCache iconCache = LauncherAppState.getInstance(context).getIconCache();
    CachingLogic<ItemInfo> dummyLogic = 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, dummyLogic, 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 13 with BitmapInfo

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

the class TaskIconCache method getBitmapInfo.

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

Example 14 with BitmapInfo

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

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) {
        entry.icon = new FastBitmapDrawable(getBitmapInfo(new BitmapDrawable(mContext.getResources(), icon), key.userId, desc.getPrimaryColor(), false));
    } else {
        activityInfo = PackageManagerWrapper.getInstance().getActivityInfo(key.getComponent(), key.userId);
        if (activityInfo != null) {
            BitmapInfo bitmapInfo = getBitmapInfo(mIconProvider.getIcon(activityInfo, UserHandle.of(key.userId)), key.userId, desc.getPrimaryColor(), activityInfo.applicationInfo.isInstantApp());
            entry.icon = newIcon(mContext, bitmapInfo);
        } 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 = ActivityManagerWrapper.getInstance().getBadgedContentDescription(activityInfo, task.key.userId, task.taskDescription);
        }
    }
    mIconCache.put(task.key, entry);
    return entry;
}
Also used : FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) ActivityInfo(android.content.pm.ActivityInfo) Bitmap(android.graphics.Bitmap) TaskDescription(android.app.ActivityManager.TaskDescription) FastBitmapDrawable(com.android.launcher3.FastBitmapDrawable) 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 15 with BitmapInfo

use of com.android.launcher3.icons.BitmapInfo in project Neo-Launcher by NeoApplications.

the class BaseIconFactory method createBadgedIconBitmap.

/**
 * Creates bitmap using the source drawable and various parameters.
 * The bitmap is visually normalized with other icons and has enough spacing to add shadow.
 *
 * @param icon                   source of the icon
 * @param user                   info can be used for a badge
 * @param shrinkNonAdaptiveIcons {@code true} if non adaptive icons should be treated
 * @param isInstantApp           info can be used for a badge
 * @param scale                  returns the scale result from normalization
 * @return a bitmap suitable for disaplaying as an icon at various system UIs.
 */
public BitmapInfo createBadgedIconBitmap(@NonNull Drawable icon, UserHandle user, boolean shrinkNonAdaptiveIcons, boolean isInstantApp, float[] scale) {
    if (scale == null) {
        scale = new float[1];
    }
    icon = normalizeAndWrapToAdaptiveIcon(icon, shrinkNonAdaptiveIcons, null, scale);
    Bitmap bitmap = createIconBitmap(icon, scale[0]);
    if (ATLEAST_OREO && icon instanceof AdaptiveIconCompat) {
        mCanvas.setBitmap(bitmap);
        getShadowGenerator().recreateIcon(Bitmap.createBitmap(bitmap), mCanvas);
        mCanvas.setBitmap(null);
    }
    if (isInstantApp) {
        badgeWithDrawable(bitmap, mContext.getDrawable(R.drawable.ic_instant_app_badge));
    }
    if (user != null) {
        BitmapDrawable drawable = new FixedSizeBitmapDrawable(bitmap);
        Drawable badged = mPm.getUserBadgedIcon(drawable, user);
        if (badged instanceof BitmapDrawable) {
            bitmap = ((BitmapDrawable) badged).getBitmap();
        } else {
            bitmap = createIconBitmap(badged, 1f);
        }
    }
    return BitmapInfo.fromBitmap(bitmap, mDisableColorExtractor ? null : mColorExtractor);
}
Also used : Bitmap(android.graphics.Bitmap) AdaptiveIconDrawable(android.graphics.drawable.AdaptiveIconDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) AdaptiveIconCompat(com.android.launcher3.AdaptiveIconCompat)

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