From a8ccf0959754907de6aec63a41db5dc442047b80 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 28 Jul 2017 16:11:36 -0700 Subject: Use deep shortcuts' icons as a fallback when updating We already do this when loading, but now we also do it when getting callbacks that potentially change the shortcut icon. These callbacks first check the pinned shortcut info, but if there is no icon there we now fall back to the current icon instead of the default icon. Bug: 62814533 Change-Id: I777adedf4b7f93dbaddb98a993eda34d59dcc173 --- src/com/android/launcher3/graphics/LauncherIcons.java | 13 +++++++++++++ src/com/android/launcher3/model/ShortcutsChangedTask.java | 6 +++--- .../android/launcher3/model/UserLockStateChangedTask.java | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src/com') diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java index 739eb04bd..d95567492 100644 --- a/src/com/android/launcher3/graphics/LauncherIcons.java +++ b/src/com/android/launcher3/graphics/LauncherIcons.java @@ -320,6 +320,19 @@ public class LauncherIcons { return createShortcutIcon(shortcutInfo, context, badged, null); } + public static Bitmap createShortcutIcon(ShortcutInfoCompat shortcutInfo, Context context, + final Bitmap fallbackIcon) { + Provider fallbackIconProvider = new Provider() { + @Override + public Bitmap get() { + // If the shortcut is pinned but no longer has an icon in the system, + // keep the current icon instead of reverting to the default icon. + return fallbackIcon; + } + }; + return createShortcutIcon(shortcutInfo, context, true, fallbackIconProvider); + } + public static Bitmap createShortcutIcon(ShortcutInfoCompat shortcutInfo, Context context, boolean badged, @Nullable Provider fallbackIconProvider) { LauncherAppState app = LauncherAppState.getInstance(context); diff --git a/src/com/android/launcher3/model/ShortcutsChangedTask.java b/src/com/android/launcher3/model/ShortcutsChangedTask.java index 6f325858d..17cc238d4 100644 --- a/src/com/android/launcher3/model/ShortcutsChangedTask.java +++ b/src/com/android/launcher3/model/ShortcutsChangedTask.java @@ -85,10 +85,10 @@ public class ShortcutsChangedTask extends BaseModelUpdateTask { removedShortcutInfos.addAll(shortcutInfos); continue; } - for (ShortcutInfo shortcutInfo : shortcutInfos) { + for (final ShortcutInfo shortcutInfo : shortcutInfos) { shortcutInfo.updateFromDeepShortcutInfo(fullDetails, context); - shortcutInfo.iconBitmap = - LauncherIcons.createShortcutIcon(fullDetails, context); + shortcutInfo.iconBitmap = LauncherIcons.createShortcutIcon(fullDetails, context, + shortcutInfo.iconBitmap); updatedShortcutInfos.add(shortcutInfo); } } diff --git a/src/com/android/launcher3/model/UserLockStateChangedTask.java b/src/com/android/launcher3/model/UserLockStateChangedTask.java index 568200646..802771f04 100644 --- a/src/com/android/launcher3/model/UserLockStateChangedTask.java +++ b/src/com/android/launcher3/model/UserLockStateChangedTask.java @@ -85,7 +85,8 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask { } si.isDisabled &= ~ShortcutInfo.FLAG_DISABLED_LOCKED_USER; si.updateFromDeepShortcutInfo(shortcut, context); - si.iconBitmap = LauncherIcons.createShortcutIcon(shortcut, context); + si.iconBitmap = LauncherIcons.createShortcutIcon(shortcut, context, + si.iconBitmap); } else { si.isDisabled |= ShortcutInfo.FLAG_DISABLED_LOCKED_USER; } -- cgit v1.2.3