From 79cf718fcdf39d0e60743b32c6611fbb971ff38c Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 27 Jul 2016 17:32:34 -0700 Subject: Badging shortcuts with app icons Change-Id: I3fa005ece20a54b31f823acb28c384ecdf1eafb1 --- src/com/android/launcher3/ShortcutInfo.java | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/com/android/launcher3/ShortcutInfo.java') diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java index 0cc5a1b92..3a1be0f33 100644 --- a/src/com/android/launcher3/ShortcutInfo.java +++ b/src/com/android/launcher3/ShortcutInfo.java @@ -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. */ -- cgit v1.2.3