summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2014-10-06 16:23:56 -0700
committerDanesh M <daneshm90@gmail.com>2015-09-27 15:12:53 -0700
commit88699b6191c6e8f75b0cc64cce5313fc31ed1348 (patch)
tree538245db0ac03dcd0787ab8517bbd788eb935f8d
parent19b63da9550dd4734f2df0e663dc8009b29705a0 (diff)
downloadandroid_packages_apps_Trebuchet-88699b6191c6e8f75b0cc64cce5313fc31ed1348.tar.gz
android_packages_apps_Trebuchet-88699b6191c6e8f75b0cc64cce5313fc31ed1348.tar.bz2
android_packages_apps_Trebuchet-88699b6191c6e8f75b0cc64cce5313fc31ed1348.zip
Updating icons for sortcuts when the target app updates.
Bug: 17398260 Change-Id: I055abb971d1f72245e8616ac2ce07bcdf37cdd52
-rw-r--r--src/com/android/launcher3/AllAppsList.java11
-rw-r--r--src/com/android/launcher3/IconCache.java2
-rw-r--r--src/com/android/launcher3/Launcher.java20
-rw-r--r--src/com/android/launcher3/LauncherModel.java67
-rw-r--r--src/com/android/launcher3/Utilities.java21
-rw-r--r--src/com/android/launcher3/Workspace.java22
6 files changed, 111 insertions, 32 deletions
diff --git a/src/com/android/launcher3/AllAppsList.java b/src/com/android/launcher3/AllAppsList.java
index f9900e604..36d0ee78b 100644
--- a/src/com/android/launcher3/AllAppsList.java
+++ b/src/com/android/launcher3/AllAppsList.java
@@ -18,6 +18,7 @@ package com.android.launcher3;
import android.content.ComponentName;
import android.content.Context;
+
import com.android.launcher3.compat.LauncherActivityInfoCompat;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserHandleCompat;
@@ -96,10 +97,8 @@ class AllAppsList {
final List<LauncherActivityInfoCompat> matches = launcherApps.getActivityList(packageName,
user);
- if (matches.size() > 0) {
- for (LauncherActivityInfoCompat info : matches) {
- add(new AppInfo(context, info, user, mIconCache, null));
- }
+ for (LauncherActivityInfoCompat info : matches) {
+ add(new AppInfo(context, info, user, mIconCache, null));
}
}
@@ -144,9 +143,7 @@ class AllAppsList {
// Find enabled activities and add them to the adapter
// Also updates existing activities with new labels/icons
- int count = matches.size();
- for (int i = 0; i < count; i++) {
- final LauncherActivityInfoCompat info = matches.get(i);
+ for (final LauncherActivityInfoCompat info : matches) {
AppInfo applicationInfo = findApplicationInfoLocked(
info.getComponentName().getPackageName(), user,
info.getComponentName().getClassName());
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index 539efa407..72b6d8951 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -122,7 +122,7 @@ public class IconCache {
android.R.mipmap.sym_def_app_icon);
}
- public Drawable getFullResIcon(Resources resources, int iconId) {
+ private Drawable getFullResIcon(Resources resources, int iconId) {
Drawable d;
try {
d = resources.getDrawableForDensity(iconId, mIconDpi);
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index d3be726e6..39386191e 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -5606,6 +5606,26 @@ public class Launcher extends Activity
}
/**
+ * Some shortcuts were updated in the background.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindShortcutsUpdated(final ArrayList<ShortcutInfo> shortcuts) {
+ Runnable r = new Runnable() {
+ public void run() {
+ bindShortcutsUpdated(shortcuts);
+ }
+ };
+ if (waitUntilResume(r)) {
+ return;
+ }
+
+ if (mWorkspace != null) {
+ mWorkspace.updateShortcuts(shortcuts);
+ }
+ }
+
+ /**
* Update the state of a package, typically related to install state.
*
* Implementation of the method from LauncherModel.Callbacks.
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 26bbbe045..ec705aa0e 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -207,6 +207,7 @@ public class LauncherModel extends BroadcastReceiver
ArrayList<AppInfo> addedApps);
public void bindAppsUpdated(ArrayList<AppInfo> apps);
public void bindAppsRestored(ArrayList<AppInfo> apps);
+ public void bindShortcutsUpdated(ArrayList<ShortcutInfo> shortcuts);
public void updatePackageState(ArrayList<PackageInstallInfo> installInfo);
public void updatePackageBadge(String packageName);
public void bindComponentsRemoved(ArrayList<String> packageNames,
@@ -3473,6 +3474,43 @@ public class LauncherModel extends BroadcastReceiver
});
}
+ // Update shortcuts which use an iconResource
+ if (mOp == OP_ADD || mOp == OP_UPDATE) {
+ final ArrayList<ShortcutInfo> iconsChanged = new ArrayList<ShortcutInfo>();
+ HashSet<String> packageSet = new HashSet<String>(Arrays.asList(packages));
+ // We need to iteration over the items here, so that we can avoid new Bitmap
+ // creation on the UI thread.
+ synchronized (sBgLock) {
+ for (ItemInfo info : sBgWorkspaceItems) {
+ if (info instanceof ShortcutInfo && mUser.equals(info.user)) {
+ ShortcutInfo si = (ShortcutInfo) info;
+ if ((si.iconResource != null)
+ && packageSet.contains(si.getTargetComponent().getPackageName())){
+ Bitmap icon = Utilities.createIconBitmap(si.iconResource.packageName,
+ si.iconResource.resourceName, mIconCache, context);
+ if (icon != null) {
+ si.setIcon(icon);
+ si.usingFallbackIcon = false;
+ iconsChanged.add(si);
+ updateItemInDatabase(context, si);
+ }
+ }
+ }
+ }
+ }
+
+ if (!iconsChanged.isEmpty()) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
+ if (callbacks == cb && cb != null) {
+ callbacks.bindShortcutsUpdated(iconsChanged);
+ }
+ }
+ });
+ }
+ }
+
final ArrayList<String> removedPackageNames =
new ArrayList<String>();
if (mOp == OP_REMOVE) {
@@ -3810,19 +3848,9 @@ public class LauncherModel extends BroadcastReceiver
case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
String packageName = c.getString(iconPackageIndex);
String resourceName = c.getString(iconResourceIndex);
- PackageManager packageManager = context.getPackageManager();
info.customIcon = false;
// the resource
- try {
- Resources resources = packageManager.getResourcesForApplication(packageName);
- if (resources != null) {
- final int id = resources.getIdentifier(resourceName, null, null);
- icon = Utilities.createIconBitmap(
- mIconCache.getFullResIcon(resources, id), context);
- }
- } catch (Exception e) {
- // drop this. we have other places to look for icons
- }
+ icon = Utilities.createIconBitmap(packageName, resourceName, mIconCache, context);
// the db
if (icon == null) {
icon = getIconFromCursor(c, iconIndex, context);
@@ -3904,19 +3932,10 @@ public class LauncherModel extends BroadcastReceiver
customIcon = true;
} else {
Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
- if (extra != null && extra instanceof ShortcutIconResource) {
- try {
- iconResource = (ShortcutIconResource) extra;
- final PackageManager packageManager = context.getPackageManager();
- Resources resources = packageManager.getResourcesForApplication(
- iconResource.packageName);
- final int id = resources.getIdentifier(iconResource.resourceName, null, null);
- icon = Utilities.createIconBitmap(
- mIconCache.getFullResIcon(resources, id),
- context);
- } catch (Exception e) {
- Log.w(TAG, "Could not load shortcut icon: " + extra);
- }
+ if (extra instanceof ShortcutIconResource) {
+ iconResource = (ShortcutIconResource) extra;
+ icon = Utilities.createIconBitmap(iconResource.packageName,
+ iconResource.resourceName, mIconCache, context);
}
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index a75ddf6a1..862a96d1e 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -156,6 +156,27 @@ public final class Utilities {
}
/**
+ * Returns a bitmap suitable for the all apps view. If the package or the resource do not
+ * exist, it returns null.
+ */
+ static Bitmap createIconBitmap(String packageName, String resourceName, IconCache cache,
+ Context context) {
+ PackageManager packageManager = context.getPackageManager();
+ // the resource
+ try {
+ Resources resources = packageManager.getResourcesForApplication(packageName);
+ if (resources != null) {
+ final int id = resources.getIdentifier(resourceName, null, null);
+ return createIconBitmap(
+ resources.getDrawableForDensity(id, cache.getFullResIconDpi()), context);
+ }
+ } catch (Exception e) {
+ // Icon not found.
+ }
+ return null;
+ }
+
+ /**
* Returns a bitmap which is of the appropriate size to be displayed as an icon
*/
static Bitmap createIconBitmap(Bitmap icon, Context context) {
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index acb1d3965..5efe8d41c 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -5086,6 +5086,28 @@ public class Workspace extends SmoothPagedView
}
}
+
+ void updateShortcuts(ArrayList<ShortcutInfo> shortcuts) {
+ final HashSet<ShortcutInfo> updates = new HashSet<ShortcutInfo>(shortcuts);
+ mapOverItems(MAP_RECURSE, new ItemOperator() {
+ @Override
+ public boolean evaluate(ItemInfo info, View v, View parent) {
+ if (info instanceof ShortcutInfo && v instanceof BubbleTextView &&
+ updates.contains(info)) {
+ ShortcutInfo shortcutInfo = (ShortcutInfo) info;
+ BubbleTextView shortcut = (BubbleTextView) v;
+ shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, false);
+
+ if (parent != null) {
+ parent.invalidate();
+ }
+ }
+ // process all the shortcuts
+ return false;
+ }
+ });
+ }
+
void updateShortcutsAndWidgets(ArrayList<AppInfo> apps) {
// Break the appinfo list per user
final HashMap<UserHandleCompat, ArrayList<AppInfo>> appsPerUser =