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
This commit is contained in:
Tony 2017-07-28 16:11:36 -07:00
parent 2ed276eb13
commit a8ccf09597
3 changed files with 18 additions and 4 deletions

View File

@ -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<Bitmap> fallbackIconProvider = new Provider<Bitmap>() {
@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<Bitmap> fallbackIconProvider) {
LauncherAppState app = LauncherAppState.getInstance(context);

View File

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

View File

@ -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;
}