diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 8a3c3193b8..bb71d776ca 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -29,6 +29,7 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; +import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.text.TextUtils; import android.util.Log; @@ -382,12 +383,15 @@ public class IconCache { */ public void cachePackageInstallInfo(String packageName, UserHandleCompat user, Bitmap icon, CharSequence title) { + remove(packageName, user); + CacheEntry entry = getEntryForPackage(packageName, user); if (!TextUtils.isEmpty(title)) { entry.title = title; } if (icon != null) { - entry.icon = Utilities.createIconBitmap(icon, mContext); + entry.icon = Utilities.createIconBitmap( + new BitmapDrawable(mContext.getResources(), icon), mContext); } } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 1b95c2b3f1..da1afaa140 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -4709,6 +4709,18 @@ public class Launcher extends Activity } } + /** + * Update the label and icon of all the icons in a package + * + * Implementation of the method from LauncherModel.Callbacks. + */ + @Override + public void updatePackageBadge(String packageName) { + if (mWorkspace != null) { + mWorkspace.updatePackageBadge(packageName, UserHandleCompat.myUserHandle()); + } + } + /** * A package was uninstalled. We take both the super set of packageNames * in addition to specific applications to remove, the reason being that diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index b6144f4ac2..246278fa25 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -260,4 +260,11 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks { public void setPackageState(ArrayList installInfo) { mModel.setPackageState(installInfo); } + + /** + * Updates the icons and label of all icons for the provided package name. + */ + public void updatePackageBadge(String packageName) { + mModel.updatePackageBadge(packageName); + } } diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 29cd9e36a3..c372b47d12 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -198,6 +198,7 @@ public class LauncherModel extends BroadcastReceiver ArrayList addedApps); public void bindAppsUpdated(ArrayList apps); public void updatePackageState(ArrayList installInfo); + public void updatePackageBadge(String packageName); public void bindComponentsRemoved(ArrayList packageNames, ArrayList appInfos, UserHandleCompat user); public void bindPackagesUpdated(ArrayList widgetsAndShortcuts); @@ -347,6 +348,19 @@ public class LauncherModel extends BroadcastReceiver mHandler.post(r); } + public void updatePackageBadge(final String packageName) { + // Process the updated package badge + Runnable r = new Runnable() { + public void run() { + Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null; + if (callbacks != null) { + callbacks.updatePackageBadge(packageName); + } + } + }; + mHandler.post(r); + } + public void addAppsToAllApps(final Context ctx, final ArrayList allAppsApps) { final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 909cf5f8c8..7b4e432d33 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -4921,6 +4921,38 @@ public class Workspace extends SmoothPagedView removeItemsByPackageName(packages, user); } + public void updatePackageBadge(final String packageName, final UserHandleCompat user) { + mapOverItems(MAP_RECURSE, new ItemOperator() { + @Override + public boolean evaluate(ItemInfo info, View v, View parent) { + if (info instanceof ShortcutInfo && v instanceof BubbleTextView) { + ShortcutInfo shortcutInfo = (ShortcutInfo) info; + ComponentName cn = shortcutInfo.getTargetComponent(); + if (user.equals(shortcutInfo.user) && cn != null + && shortcutInfo.isPromise() + && packageName.equals(cn.getPackageName())) { + if (shortcutInfo.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) { + // For auto install apps update the icon as well as label. + mIconCache.getTitleAndIcon(shortcutInfo, + shortcutInfo.promisedIntent, user, true); + } else { + // Only update the icon for restored apps. + shortcutInfo.updateIcon(mIconCache); + } + BubbleTextView shortcut = (BubbleTextView) v; + shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, false); + + if (parent != null) { + parent.invalidate(); + } + } + } + // process all the shortcuts + return false; + } + }); + } + public void updatePackageState(ArrayList installInfos) { HashSet completedPackages = new HashSet(); diff --git a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java index 2d56adf917..557a9a3213 100644 --- a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java +++ b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java @@ -27,6 +27,7 @@ import com.android.launcher3.IconCache; import com.android.launcher3.LauncherAppState; import java.util.ArrayList; +import java.util.HashSet; public class PackageInstallerCompatVL extends PackageInstallerCompat { @@ -34,6 +35,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat { private static final boolean DEBUG = false; private final SparseArray mPendingReplays = new SparseArray(); + private final HashSet mPendingBadgeUpdates = new HashSet(); private final PackageInstaller mInstaller; private final IconCache mCache; @@ -133,18 +135,20 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat { if (!updates.isEmpty()) { app.setPackageState(updates); } + + if (!mPendingBadgeUpdates.isEmpty()) { + for (String pkg : mPendingBadgeUpdates) { + app.updatePackageBadge(pkg); + } + mPendingBadgeUpdates.clear(); + } } private final SessionCallback mCallback = new SessionCallback() { @Override public void onCreated(int sessionId) { - SessionInfo session = mInstaller.getSessionInfo(sessionId); - if (session != null) { - addSessionInfoToCahce(session, UserHandleCompat.myUserHandle()); - mPendingReplays.put(sessionId, session); - replayUpdates(null); - } + pushSessionBadgeToLauncher(sessionId); } @Override @@ -152,6 +156,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat { mPendingReplays.remove(sessionId); SessionInfo session = mInstaller.getSessionInfo(sessionId); if ((session != null) && (session.getAppPackageName() != null)) { + mPendingBadgeUpdates.remove(session.getAppPackageName()); // Replay all updates with a one time update for this installed package. No // need to store this record for future updates, as the app list will get // refreshed on resume. @@ -173,6 +178,20 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat { public void onActiveChanged(int sessionId, boolean active) { } @Override - public void onBadgingChanged(int sessionId) { } + public void onBadgingChanged(int sessionId) { + pushSessionBadgeToLauncher(sessionId); + } + + private void pushSessionBadgeToLauncher(int sessionId) { + SessionInfo session = mInstaller.getSessionInfo(sessionId); + if (session != null) { + addSessionInfoToCahce(session, UserHandleCompat.myUserHandle()); + if (session.getAppPackageName() != null) { + mPendingBadgeUpdates.add(session.getAppPackageName()); + } + mPendingReplays.put(sessionId, session); + replayUpdates(null); + } + } }; }