Merge "Updating promise icon's bitmap and label when onBadgingChanged is received" into ub-now-porkchop
This commit is contained in:
@@ -29,6 +29,7 @@ import android.content.res.Resources;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -382,12 +383,15 @@ public class IconCache {
|
|||||||
*/
|
*/
|
||||||
public void cachePackageInstallInfo(String packageName, UserHandleCompat user,
|
public void cachePackageInstallInfo(String packageName, UserHandleCompat user,
|
||||||
Bitmap icon, CharSequence title) {
|
Bitmap icon, CharSequence title) {
|
||||||
|
remove(packageName, user);
|
||||||
|
|
||||||
CacheEntry entry = getEntryForPackage(packageName, user);
|
CacheEntry entry = getEntryForPackage(packageName, user);
|
||||||
if (!TextUtils.isEmpty(title)) {
|
if (!TextUtils.isEmpty(title)) {
|
||||||
entry.title = title;
|
entry.title = title;
|
||||||
}
|
}
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
entry.icon = Utilities.createIconBitmap(icon, mContext);
|
entry.icon = Utilities.createIconBitmap(
|
||||||
|
new BitmapDrawable(mContext.getResources(), icon), mContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4711,6 +4711,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
|
* A package was uninstalled. We take both the super set of packageNames
|
||||||
* in addition to specific applications to remove, the reason being that
|
* in addition to specific applications to remove, the reason being that
|
||||||
|
|||||||
@@ -260,4 +260,11 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks {
|
|||||||
public void setPackageState(ArrayList<PackageInstallInfo> installInfo) {
|
public void setPackageState(ArrayList<PackageInstallInfo> installInfo) {
|
||||||
mModel.setPackageState(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ public class LauncherModel extends BroadcastReceiver
|
|||||||
ArrayList<AppInfo> addedApps);
|
ArrayList<AppInfo> addedApps);
|
||||||
public void bindAppsUpdated(ArrayList<AppInfo> apps);
|
public void bindAppsUpdated(ArrayList<AppInfo> apps);
|
||||||
public void updatePackageState(ArrayList<PackageInstallInfo> installInfo);
|
public void updatePackageState(ArrayList<PackageInstallInfo> installInfo);
|
||||||
|
public void updatePackageBadge(String packageName);
|
||||||
public void bindComponentsRemoved(ArrayList<String> packageNames,
|
public void bindComponentsRemoved(ArrayList<String> packageNames,
|
||||||
ArrayList<AppInfo> appInfos, UserHandleCompat user);
|
ArrayList<AppInfo> appInfos, UserHandleCompat user);
|
||||||
public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts);
|
public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts);
|
||||||
@@ -348,6 +349,19 @@ public class LauncherModel extends BroadcastReceiver
|
|||||||
mHandler.post(r);
|
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<AppInfo> allAppsApps) {
|
public void addAppsToAllApps(final Context ctx, final ArrayList<AppInfo> allAppsApps) {
|
||||||
final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
|
final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
|
||||||
|
|
||||||
|
|||||||
@@ -4921,6 +4921,38 @@ public class Workspace extends SmoothPagedView
|
|||||||
removeItemsByPackageName(packages, user);
|
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<PackageInstallInfo> installInfos) {
|
public void updatePackageState(ArrayList<PackageInstallInfo> installInfos) {
|
||||||
HashSet<String> completedPackages = new HashSet<String>();
|
HashSet<String> completedPackages = new HashSet<String>();
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
|||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
|
|
||||||
private final SparseArray<SessionInfo> mPendingReplays = new SparseArray<SessionInfo>();
|
private final SparseArray<SessionInfo> mPendingReplays = new SparseArray<SessionInfo>();
|
||||||
|
private final HashSet<String> mPendingBadgeUpdates = new HashSet<String>();
|
||||||
private final PackageInstaller mInstaller;
|
private final PackageInstaller mInstaller;
|
||||||
private final IconCache mCache;
|
private final IconCache mCache;
|
||||||
|
|
||||||
@@ -139,18 +140,20 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
|||||||
if (!updates.isEmpty()) {
|
if (!updates.isEmpty()) {
|
||||||
app.setPackageState(updates);
|
app.setPackageState(updates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mPendingBadgeUpdates.isEmpty()) {
|
||||||
|
for (String pkg : mPendingBadgeUpdates) {
|
||||||
|
app.updatePackageBadge(pkg);
|
||||||
|
}
|
||||||
|
mPendingBadgeUpdates.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final SessionCallback mCallback = new SessionCallback() {
|
private final SessionCallback mCallback = new SessionCallback() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreated(int sessionId) {
|
public void onCreated(int sessionId) {
|
||||||
SessionInfo session = mInstaller.getSessionInfo(sessionId);
|
pushSessionBadgeToLauncher(sessionId);
|
||||||
if (session != null) {
|
|
||||||
addSessionInfoToCahce(session, UserHandleCompat.myUserHandle());
|
|
||||||
mPendingReplays.put(sessionId, session);
|
|
||||||
replayUpdates(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -158,6 +161,7 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
|||||||
mPendingReplays.remove(sessionId);
|
mPendingReplays.remove(sessionId);
|
||||||
SessionInfo session = mInstaller.getSessionInfo(sessionId);
|
SessionInfo session = mInstaller.getSessionInfo(sessionId);
|
||||||
if ((session != null) && (session.getAppPackageName() != null)) {
|
if ((session != null) && (session.getAppPackageName() != null)) {
|
||||||
|
mPendingBadgeUpdates.remove(session.getAppPackageName());
|
||||||
// Replay all updates with a one time update for this installed package. No
|
// 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
|
// need to store this record for future updates, as the app list will get
|
||||||
// refreshed on resume.
|
// refreshed on resume.
|
||||||
@@ -179,6 +183,20 @@ public class PackageInstallerCompatVL extends PackageInstallerCompat {
|
|||||||
public void onActiveChanged(int sessionId, boolean active) { }
|
public void onActiveChanged(int sessionId, boolean active) { }
|
||||||
|
|
||||||
@Override
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user