Badging shortcuts with app icons
Change-Id: I3fa005ece20a54b31f823acb28c384ecdf1eafb1
This commit is contained in:
1 parent
a2454ad2d8
commit
79cf718fcd
5 files changed
+143
-27
No files matched your search
@@ -28,7 +28,6 @@ import android.text.TextUtils;
|
||||
|
||||
import com.android.launcher3.LauncherSettings.Favorites;
|
||||
import com.android.launcher3.compat.LauncherActivityInfoCompat;
|
||||
import com.android.launcher3.compat.LauncherAppsCompat;
|
||||
import com.android.launcher3.compat.UserHandleCompat;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.folder.FolderIcon;
|
||||
@@ -295,16 +294,33 @@ public class ShortcutInfo extends ItemInfo {
|
||||
contentDescription = UserManagerCompat.getInstance(context)
|
||||
.getBadgedLabelForUser(label, user);
|
||||
|
||||
// TODO: Use cache for this
|
||||
LauncherAppState launcherAppState = LauncherAppState.getInstance();
|
||||
Drawable unbadgedIcon = launcherAppState.getShortcutManager()
|
||||
Drawable unbadgedDrawable = launcherAppState.getShortcutManager()
|
||||
.getShortcutIconDrawable(shortcutInfo,
|
||||
launcherAppState.getInvariantDeviceProfile().fillResIconDpi);
|
||||
Bitmap icon = unbadgedIcon == null ? null : getBadgedIcon(unbadgedIcon, context);
|
||||
setIcon(icon != null ? icon : launcherAppState.getIconCache().getDefaultIcon(user));
|
||||
|
||||
IconCache cache = launcherAppState.getIconCache();
|
||||
Bitmap unbadgedBitmap = unbadgedDrawable == null
|
||||
? cache.getDefaultIcon(UserHandleCompat.myUserHandle())
|
||||
: Utilities.createScaledBitmapWithoutShadow(unbadgedDrawable, context);
|
||||
setIcon(getBadgedIcon(unbadgedBitmap, shortcutInfo, cache, context));
|
||||
}
|
||||
|
||||
protected Bitmap getBadgedIcon(Drawable unbadgedIcon, Context context) {
|
||||
return Utilities.createBadgedIconBitmapWithShadow(unbadgedIcon, user, context);
|
||||
protected Bitmap getBadgedIcon(Bitmap unbadgedBitmap, ShortcutInfoCompat shortcutInfo,
|
||||
IconCache cache, Context context) {
|
||||
unbadgedBitmap = Utilities.addShadowToIcon(unbadgedBitmap);
|
||||
// Get the app info for the source activity.
|
||||
AppInfo appInfo = new AppInfo();
|
||||
appInfo.user = user;
|
||||
appInfo.componentName = shortcutInfo.getActivity();
|
||||
try {
|
||||
cache.getTitleAndIcon(appInfo, shortcutInfo.getActivityInfo(context), false);
|
||||
} catch (NullPointerException e) {
|
||||
// This may happen when we fail to load the activity info. Worst case ignore badging.
|
||||
return Utilities.badgeIconForUser(unbadgedBitmap, user, context);
|
||||
}
|
||||
return Utilities.badgeWithBitmap(unbadgedBitmap, appInfo.iconBitmap, context);
|
||||
}
|
||||
|
||||
/** Returns the ShortcutInfo id associated with the deep shortcut. */
|
||||
|
||||
Reference in new issue
Block a user