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;
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations