summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/IconCache.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2014-08-29 17:20:55 -0700
committerSunny Goyal <sunnygoyal@google.com>2014-09-04 08:18:33 -0700
commit349426234e8c5a0e5bcf2c8d94dbb9844b5f724a (patch)
tree7959007f77fe9293898b72b57b4b28c87b90527e /src/com/android/launcher3/IconCache.java
parent6a2c77856f1cfa402363cfbb04b5718b431bbc6e (diff)
downloadandroid_packages_apps_Trebuchet-349426234e8c5a0e5bcf2c8d94dbb9844b5f724a.tar.gz
android_packages_apps_Trebuchet-349426234e8c5a0e5bcf2c8d94dbb9844b5f724a.tar.bz2
android_packages_apps_Trebuchet-349426234e8c5a0e5bcf2c8d94dbb9844b5f724a.zip
Handling label and icon from SessionInfo.
> The ShortcutInfo stores state as bit flags and not as ints > Intents of auto-install shortcut are automatically updated upon installation > Icons/titles for active sessions are cached in IconCache Change-Id: I2047849f67d4a8aaf2bc346b58110325bb4807d4
Diffstat (limited to 'src/com/android/launcher3/IconCache.java')
-rw-r--r--src/com/android/launcher3/IconCache.java52
1 files changed, 47 insertions, 5 deletions
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index 76a85caae..75be83638 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -30,6 +30,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
+import android.text.TextUtils;
import android.util.Log;
import com.android.launcher3.compat.LauncherActivityInfoCompat;
@@ -254,18 +255,16 @@ public class IconCache {
return getIcon(intent, null, user, true);
}
- public Bitmap getIcon(Intent intent, String title, UserHandleCompat user, boolean usePkgIcon) {
+ private Bitmap getIcon(Intent intent, String title, UserHandleCompat user, boolean usePkgIcon) {
synchronized (mCache) {
- LauncherActivityInfoCompat launcherActInfo =
- mLauncherApps.resolveActivity(intent, user);
ComponentName component = intent.getComponent();
-
// null info means not installed, but if we have a component from the intent then
// we should still look in the cache for restored app icons.
if (component == null) {
return getDefaultIcon(user);
}
+ LauncherActivityInfoCompat launcherActInfo = mLauncherApps.resolveActivity(intent, user);
CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, usePkgIcon);
if (title != null) {
entry.title = title;
@@ -275,6 +274,32 @@ public class IconCache {
}
}
+ /**
+ * Fill in "shortcutInfo" with the icon and label for "info."
+ */
+ public void getTitleAndIcon(ShortcutInfo shortcutInfo, Intent intent, UserHandleCompat user,
+ boolean usePkgIcon) {
+ synchronized (mCache) {
+ ComponentName component = intent.getComponent();
+ // null info means not installed, but if we have a component from the intent then
+ // we should still look in the cache for restored app icons.
+ if (component == null) {
+ shortcutInfo.setIcon(getDefaultIcon(user));
+ shortcutInfo.title = "";
+ shortcutInfo.usingFallbackIcon = true;
+ } else {
+ LauncherActivityInfoCompat launcherActInfo =
+ mLauncherApps.resolveActivity(intent, user);
+ CacheEntry entry = cacheLocked(component, launcherActInfo, null, user, usePkgIcon);
+
+ shortcutInfo.setIcon(entry.icon);
+ shortcutInfo.title = entry.title;
+ shortcutInfo.usingFallbackIcon = isDefaultIcon(entry.icon, user);
+ }
+ }
+ }
+
+
public Bitmap getDefaultIcon(UserHandleCompat user) {
if (!mDefaultIcons.containsKey(user)) {
mDefaultIcons.put(user, makeDefaultIcon(user));
@@ -332,10 +357,11 @@ public class IconCache {
if (usePackageIcon) {
CacheEntry packageEntry = getEntryForPackage(
componentName.getPackageName(), user);
- if (packageEntry != null && packageEntry.icon != null) {
+ if (packageEntry != null) {
if (DEBUG) Log.d(TAG, "using package default icon for " +
componentName.toShortString());
entry.icon = packageEntry.icon;
+ entry.title = packageEntry.title;
}
}
if (entry.icon == null) {
@@ -350,6 +376,21 @@ public class IconCache {
}
/**
+ * Adds a default package entry in the cache. This entry is not persisted and will be removed
+ * when the cache is flushed.
+ */
+ public void cachePackageInstallInfo(String packageName, UserHandleCompat user,
+ Bitmap icon, CharSequence title) {
+ CacheEntry entry = getEntryForPackage(packageName, user);
+ if (!TextUtils.isEmpty(title)) {
+ entry.title = title;
+ }
+ if (icon != null) {
+ entry.icon = Utilities.createIconBitmap(icon, mContext);
+ }
+ }
+
+ /**
* Gets an entry for the package, which can be used as a fallback entry for various components.
*/
private CacheEntry getEntryForPackage(String packageName, UserHandleCompat user) {
@@ -358,6 +399,7 @@ public class IconCache {
CacheEntry entry = mCache.get(cacheKey);
if (entry == null) {
entry = new CacheEntry();
+ entry.title = "";
mCache.put(cacheKey, entry);
try {