diff options
17 files changed, 85 insertions, 145 deletions
diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java index 3b22f46f2..23e288242 100644 --- a/src/com/android/launcher3/AppInfo.java +++ b/src/com/android/launcher3/AppInfo.java @@ -81,8 +81,14 @@ public class AppInfo extends ItemInfo { public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user, IconCache iconCache, boolean quietModeEnabled) { + this(context, info, user, iconCache, quietModeEnabled, true /* useLowResIcon */); + } + + public AppInfo(Context context, LauncherActivityInfoCompat info, UserHandleCompat user, + IconCache iconCache, boolean quietModeEnabled, boolean useLowResIcon) { this.componentName = info.getComponentName(); this.container = ItemInfo.NO_ID; + this.user = user; if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) { isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED; } @@ -90,9 +96,8 @@ public class AppInfo extends ItemInfo { isDisabled |= ShortcutInfo.FLAG_DISABLED_QUIET_USER; } - iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */); + iconCache.getTitleAndIcon(this, info, useLowResIcon); intent = makeLaunchIntent(context, info, user); - this.user = user; } public AppInfo(AppInfo info) { diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 51cd0527f..0c1a156ad 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -155,13 +155,12 @@ public class BubbleTextView extends TextView setAccessibilityDelegate(mLauncher.getAccessibilityDelegate()); } - public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) { - applyFromShortcutInfo(info, iconCache, false); + public void applyFromShortcutInfo(ShortcutInfo info) { + applyFromShortcutInfo(info, false); } - public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache, - boolean promiseStateChanged) { - applyIconAndLabel(info.getIcon(iconCache), info); + public void applyFromShortcutInfo(ShortcutInfo info, boolean promiseStateChanged) { + applyIconAndLabel(info.iconBitmap, info); setTag(info); if (promiseStateChanged || info.isPromise()) { applyState(promiseStateChanged); @@ -557,8 +556,7 @@ public class BubbleTextView extends TextView if (info instanceof AppInfo) { applyFromApplicationInfo((AppInfo) info); } else if (info instanceof ShortcutInfo) { - applyFromShortcutInfo((ShortcutInfo) info, - LauncherAppState.getInstance().getIconCache()); + applyFromShortcutInfo((ShortcutInfo) info); if ((info.rank < FolderIcon.NUM_ITEMS_IN_PREVIEW) && (info.container >= 0)) { View folderIcon = mLauncher.getWorkspace().getHomescreenIconByItemId(info.container); diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 4b09bf82d..9f332a450 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -490,7 +490,7 @@ public class IconCache { // 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.iconBitmap = getDefaultIcon(user); shortcutInfo.title = ""; shortcutInfo.contentDescription = ""; shortcutInfo.usingLowResIcon = false; @@ -507,7 +507,7 @@ public class IconCache { ShortcutInfo shortcutInfo, ComponentName component, LauncherActivityInfoCompat info, UserHandleCompat user, boolean usePkgIcon, boolean useLowResIcon) { CacheEntry entry = cacheLocked(component, info, user, usePkgIcon, useLowResIcon); - shortcutInfo.setIcon(getNonNullIcon(entry, user)); + shortcutInfo.iconBitmap = getNonNullIcon(entry, user); shortcutInfo.title = Utilities.trim(entry.title); shortcutInfo.contentDescription = entry.contentDescription; shortcutInfo.usingLowResIcon = entry.isLowResIcon; diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java index 46bc3b3cd..2f92201e1 100644 --- a/src/com/android/launcher3/InstallShortcutReceiver.java +++ b/src/com/android/launcher3/InstallShortcutReceiver.java @@ -433,7 +433,10 @@ public class InstallShortcutReceiver extends BroadcastReceiver { public ItemInfo getItemInfo() { if (activityInfo != null) { - return new ShortcutInfo(activityInfo, mContext); + return new AppInfo(mContext, activityInfo, user, + LauncherAppState.getInstance().getIconCache(), + UserManagerCompat.getInstance(mContext).isQuietModeEnabled(user), + false /* useLowResIcon */).makeShortcut(); } else if (shortcutInfo != null) { return new ShortcutInfo(shortcutInfo, mContext); } else if (providerInfo != null) { diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 75534b2f5..85e6a77fb 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1424,7 +1424,7 @@ public class Launcher extends Activity public View createShortcut(ViewGroup parent, ShortcutInfo info) { BubbleTextView favorite = (BubbleTextView) getLayoutInflater().inflate(R.layout.app_icon, parent, false); - favorite.applyFromShortcutInfo(info, mIconCache); + favorite.applyFromShortcutInfo(info); favorite.setCompoundDrawablePadding(mDeviceProfile.iconDrawablePaddingPx); favorite.setOnClickListener(this); favorite.setOnFocusChangeListener(mFocusHandler); @@ -2108,8 +2108,7 @@ public class Launcher extends Activity cellX, cellY); // Create the view - FolderIcon newFolder = - FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); + FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo); mWorkspace.addInScreen(newFolder, folderInfo); // Force measure the new folder icon CellLayout parent = mWorkspace.getParentCellLayoutForView(newFolder); @@ -3337,7 +3336,7 @@ public class Launcher extends Activity case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: { view = FolderIcon.fromXml(R.layout.folder_icon, this, (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), - (FolderInfo) item, mIconCache); + (FolderInfo) item); break; } case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: { @@ -4028,13 +4027,6 @@ public class Launcher extends Activity return new AppInfo(this, activityInfo, user, mIconCache); } - // TODO: This method should be a part of LauncherSearchCallback - public ItemInfo createShortcutDragInfo(Intent shortcutIntent, CharSequence caption, - Bitmap icon) { - return new ShortcutInfo(shortcutIntent, caption, caption, icon, - UserHandleCompat.myUserHandle()); - } - protected void moveWorkspaceToDefaultScreen() { mWorkspace.moveToDefaultScreen(false); } diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index cc56d439f..2a6f56bf0 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -1792,8 +1792,10 @@ public class LauncherModel extends BroadcastReceiver Collections.sort(folder.contents, Folder.ITEM_POS_COMPARATOR); int pos = 0; for (ShortcutInfo info : folder.contents) { - if (info.usingLowResIcon) { - info.updateIcon(mIconCache, false); + if (info.usingLowResIcon && + info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { + mIconCache.getTitleAndIcon( + info, info.getPromisedIntent(), info.user, false); } pos ++; if (pos >= FolderIcon.NUM_ITEMS_IN_PREVIEW) { @@ -2518,13 +2520,10 @@ public class LauncherModel extends BroadcastReceiver int promiseType, int itemType, CursorIconInfo iconInfo) { final ShortcutInfo info = new ShortcutInfo(); info.user = UserHandleCompat.myUserHandle(); - - Bitmap icon = iconInfo.loadIcon(c, info); + info.iconBitmap = iconInfo.loadIcon(c, info); // the fallback icon - if (icon == null) { + if (info.iconBitmap == null) { mIconCache.getTitleAndIcon(info, intent, info.user, false /* useLowResIcon */); - } else { - info.setIcon(icon); } if ((promiseType & ShortcutInfo.FLAG_RESTORED_ICON) != 0) { @@ -2595,9 +2594,9 @@ public class LauncherModel extends BroadcastReceiver final ShortcutInfo info = new ShortcutInfo(); mIconCache.getTitleAndIcon(info, componentName, lai, user, false, useLowResIcon); - if (mIconCache.isDefaultIcon(info.getIcon(mIconCache), user) && c != null) { + if (mIconCache.isDefaultIcon(info.iconBitmap, user) && c != null) { Bitmap icon = iconInfo.loadIcon(c); - info.setIcon(icon == null ? mIconCache.getDefaultIcon(user) : icon); + info.iconBitmap = icon != null ? icon : mIconCache.getDefaultIcon(user); } if (lai != null && PackageManagerHelper.isAppSuspended(lai.getApplicationInfo())) { @@ -2640,12 +2639,11 @@ public class LauncherModel extends BroadcastReceiver */ public void loadInfoFromCursor(ShortcutInfo info, Cursor c, CursorIconInfo iconInfo) { info.title = iconInfo.getTitle(c); - Bitmap icon = iconInfo.loadIcon(c, info); + info.iconBitmap = iconInfo.loadIcon(c, info); // the fallback icon - if (icon == null) { - icon = mIconCache.getDefaultIcon(info.user); + if (info.iconBitmap == null) { + info.iconBitmap = mIconCache.getDefaultIcon(info.user); } - info.setIcon(icon); } ShortcutInfo infoFromShortcutIntent(Context context, Intent data) { @@ -2659,34 +2657,28 @@ public class LauncherModel extends BroadcastReceiver return null; } - Bitmap icon = null; - ShortcutIconResource iconResource = null; + final ShortcutInfo info = new ShortcutInfo(); + + // Only support intents for current user for now. Intents sent from other + // users wouldn't get here without intent forwarding anyway. + info.user = UserHandleCompat.myUserHandle(); if (bitmap instanceof Bitmap) { - icon = LauncherIcons.createIconBitmap((Bitmap) bitmap, context); + info.iconBitmap = LauncherIcons.createIconBitmap((Bitmap) bitmap, context); } else { Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (extra instanceof ShortcutIconResource) { - iconResource = (ShortcutIconResource) extra; - icon = LauncherIcons.createIconBitmap(iconResource.packageName, - iconResource.resourceName, context); + info.iconResource = (ShortcutIconResource) extra; + info.iconBitmap = LauncherIcons.createIconBitmap(info.iconResource, context); } } - - final ShortcutInfo info = new ShortcutInfo(); - - // Only support intents for current user for now. Intents sent from other - // users wouldn't get here without intent forwarding anyway. - info.user = UserHandleCompat.myUserHandle(); - if (icon == null) { - icon = mIconCache.getDefaultIcon(info.user); + if (info.iconBitmap == null) { + info.iconBitmap = mIconCache.getDefaultIcon(info.user); } - info.setIcon(icon); info.title = Utilities.trim(name); info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user); info.intent = intent; - info.iconResource = iconResource; return info; } diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java index d6d03d36c..fd6533706 100644 --- a/src/com/android/launcher3/ShortcutInfo.java +++ b/src/com/android/launcher3/ShortcutInfo.java @@ -26,10 +26,8 @@ import android.os.Build; import android.text.TextUtils; import com.android.launcher3.LauncherSettings.Favorites; -import com.android.launcher3.compat.LauncherActivityInfoCompat; import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.compat.UserManagerCompat; -import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.graphics.LauncherIcons; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.ShortcutInfoCompat; @@ -80,7 +78,7 @@ public class ShortcutInfo extends ItemInfo { /** * Indicates whether we're using a low res icon */ - boolean usingLowResIcon; + public boolean usingLowResIcon; /** * If isShortcut=true and customIcon=false, this contains a reference to the @@ -91,7 +89,7 @@ public class ShortcutInfo extends ItemInfo { /** * The application icon. */ - private Bitmap mIcon; + public Bitmap iconBitmap; /** * Indicates that the icon is disabled due to safe mode restrictions. @@ -163,22 +161,12 @@ public class ShortcutInfo extends ItemInfo { return promisedIntent != null ? promisedIntent : intent; } - ShortcutInfo(Intent intent, CharSequence title, CharSequence contentDescription, - Bitmap icon, UserHandleCompat user) { - this(); - this.intent = intent; - this.title = Utilities.trim(title); - this.contentDescription = contentDescription; - mIcon = icon; - this.user = user; - } - public ShortcutInfo(ShortcutInfo info) { super(info); title = info.title; intent = new Intent(info.intent); iconResource = info.iconResource; - mIcon = info.mIcon; // TODO: should make a copy here. maybe we don't need this ctor at all + iconBitmap = info.iconBitmap; status = info.status; mInstallProgress = info.mInstallProgress; isDisabled = info.isDisabled; @@ -190,15 +178,8 @@ public class ShortcutInfo extends ItemInfo { title = Utilities.trim(info.title); intent = new Intent(info.intent); isDisabled = info.isDisabled; - } - - public ShortcutInfo(LauncherActivityInfoCompat info, Context context) { - user = info.getUser(); - title = Utilities.trim(info.getLabel()); - contentDescription = UserManagerCompat.getInstance(context) - .getBadgedLabelForUser(info.getLabel(), info.getUser()); - intent = AppInfo.makeLaunchIntent(context, info, info.getUser()); - itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; + iconBitmap = info.iconBitmap; + usingLowResIcon = info.usingLowResIcon; } /** @@ -211,28 +192,6 @@ public class ShortcutInfo extends ItemInfo { updateFromDeepShortcutInfo(shortcutInfo, context); } - public void setIcon(Bitmap b) { - mIcon = b; - } - - public Bitmap getIcon(IconCache iconCache) { - if (mIcon == null) { - updateIcon(iconCache); - } - return mIcon; - } - - public void updateIcon(IconCache iconCache, boolean useLowRes) { - if (itemType == Favorites.ITEM_TYPE_APPLICATION) { - iconCache.getTitleAndIcon(this, promisedIntent != null ? promisedIntent : intent, user, - useLowRes); - } - } - - public void updateIcon(IconCache iconCache) { - updateIcon(iconCache, shouldUseLowResIcon()); - } - @Override void onAddToDatabase(ContentWriter writer) { super.onAddToDatabase(writer); @@ -241,7 +200,7 @@ public class ShortcutInfo extends ItemInfo { .put(LauncherSettings.Favorites.RESTORED, status); if (!usingLowResIcon) { - writer.putIcon(mIcon, user); + writer.putIcon(iconBitmap, user); } if (iconResource != null) { writer.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE, iconResource.packageName) @@ -251,7 +210,7 @@ public class ShortcutInfo extends ItemInfo { } public ComponentName getTargetComponent() { - return promisedIntent != null ? promisedIntent.getComponent() : intent.getComponent(); + return getPromisedIntent().getComponent(); } public boolean hasStatusFlag(int flag) { @@ -272,10 +231,6 @@ public class ShortcutInfo extends ItemInfo { status |= FLAG_INSTALL_SESSION_ACTIVE; } - public boolean shouldUseLowResIcon() { - return usingLowResIcon && container >= 0 && rank >= FolderIcon.NUM_ITEMS_IN_PREVIEW; - } - public void updateFromDeepShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) { // {@link ShortcutInfoCompat#getActivity} can change during an update. Recreate the intent intent = shortcutInfo.makeIntent(context); @@ -304,7 +259,7 @@ public class ShortcutInfo extends ItemInfo { Bitmap unbadgedBitmap = unbadgedDrawable == null ? cache.getDefaultIcon(UserHandleCompat.myUserHandle()) : LauncherIcons.createScaledBitmapWithoutShadow(unbadgedDrawable, context); - setIcon(getBadgedIcon(unbadgedBitmap, shortcutInfo, cache, context)); + iconBitmap = getBadgedIcon(unbadgedBitmap, shortcutInfo, cache, context); } protected Bitmap getBadgedIcon(Bitmap unbadgedBitmap, ShortcutInfoCompat shortcutInfo, diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index ee21b422e..ab9836757 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -170,7 +170,6 @@ public class Workspace extends PagedView private CellLayout mDropToLayout = null; @Thunk Launcher mLauncher; - @Thunk IconCache mIconCache; @Thunk DragController mDragController; // These are temporary variables to prevent having to allocate a new object just to @@ -514,9 +513,7 @@ public class Workspace extends PagedView */ protected void initWorkspace() { mCurrentPage = getDefaultPage(); - LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = mLauncher.getDeviceProfile(); - mIconCache = app.getIconCache(); setWillNotDraw(false); setClipChildren(false); setClipToPadding(false); @@ -3391,7 +3388,7 @@ public class Workspace extends PagedView break; case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, cellLayout, - (FolderInfo) info, mIconCache); + (FolderInfo) info); break; default: throw new IllegalStateException("Unknown item type: " + info.itemType); @@ -3999,8 +3996,7 @@ public class Workspace extends PagedView Drawable oldIcon = getTextViewIcon(shortcut); boolean oldPromiseState = (oldIcon instanceof PreloadIconDrawable) && ((PreloadIconDrawable) oldIcon).hasNotCompleted(); - shortcut.applyFromShortcutInfo(si, mIconCache, - si.isPromise() != oldPromiseState); + shortcut.applyFromShortcutInfo(si, si.isPromise() != oldPromiseState); } // process all the shortcuts return false; diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index 37453232b..973245b92 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -146,7 +146,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { } public static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group, - FolderInfo folderInfo, IconCache iconCache) { + FolderInfo folderInfo) { @SuppressWarnings("all") // suppress dead code warning final boolean error = INITIAL_ITEM_ANIMATION_DURATION >= DROP_IN_ANIMATION_DURATION; if (error) { diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java index 650ca1931..4c1203281 100644 --- a/src/com/android/launcher3/folder/FolderPagedView.java +++ b/src/com/android/launcher3/folder/FolderPagedView.java @@ -31,7 +31,6 @@ import com.android.launcher3.BubbleTextView; import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; import com.android.launcher3.FocusHelper.PagedFolderKeyEventListener; -import com.android.launcher3.IconCache; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; @@ -73,7 +72,6 @@ public class FolderPagedView extends PagedView { public final boolean mIsRtl; private final LayoutInflater mInflater; - private final IconCache mIconCache; private final ViewGroupFocusHelper mFocusIndicatorHelper; @Thunk final HashMap<View, Runnable> mPendingAnimations = new HashMap<>(); @@ -107,7 +105,6 @@ public class FolderPagedView extends PagedView { mMaxItemsPerPage = mMaxCountX * mMaxCountY; mInflater = LayoutInflater.from(context); - mIconCache = app.getIconCache(); mIsRtl = Utilities.isRtl(getResources()); setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); @@ -231,7 +228,7 @@ public class FolderPagedView extends PagedView { public View createNewView(ShortcutInfo item) { final BubbleTextView textView = (BubbleTextView) mInflater.inflate( R.layout.folder_application, null, false); - textView.applyFromShortcutInfo(item, mIconCache); + textView.applyFromShortcutInfo(item); textView.setOnClickListener(mFolder); textView.setOnLongClickListener(mFolder); textView.setOnFocusChangeListener(mFocusIndicatorHelper); diff --git a/src/com/android/launcher3/graphics/LauncherIcons.java b/src/com/android/launcher3/graphics/LauncherIcons.java index 9f3f3571d..6f9f7ffc9 100644 --- a/src/com/android/launcher3/graphics/LauncherIcons.java +++ b/src/com/android/launcher3/graphics/LauncherIcons.java @@ -18,6 +18,7 @@ package com.android.launcher3.graphics; import android.annotation.TargetApi; import android.content.Context; +import android.content.Intent.ShortcutIconResource; import android.content.pm.PackageManager; import android.content.res.Resources; import android.database.Cursor; @@ -66,14 +67,13 @@ public class LauncherIcons { * Returns a bitmap suitable for the all apps view. If the package or the resource do not * exist, it returns null. */ - public static Bitmap createIconBitmap(String packageName, String resourceName, - Context context) { + public static Bitmap createIconBitmap(ShortcutIconResource iconRes, Context context) { PackageManager packageManager = context.getPackageManager(); // the resource try { - Resources resources = packageManager.getResourcesForApplication(packageName); + Resources resources = packageManager.getResourcesForApplication(iconRes.packageName); if (resources != null) { - final int id = resources.getIdentifier(resourceName, null, null); + final int id = resources.getIdentifier(iconRes.resourceName, null, null); return createIconBitmap( resources.getDrawableForDensity(id, LauncherAppState.getInstance() .getInvariantDeviceProfile().fillResIconDpi), context); diff --git a/src/com/android/launcher3/model/CacheDataUpdatedTask.java b/src/com/android/launcher3/model/CacheDataUpdatedTask.java index 9f24e9035..64771d530 100644 --- a/src/com/android/launcher3/model/CacheDataUpdatedTask.java +++ b/src/com/android/launcher3/model/CacheDataUpdatedTask.java @@ -25,6 +25,7 @@ import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherModel.CallbackTask; import com.android.launcher3.LauncherModel.Callbacks; import com.android.launcher3.LauncherSettings; +import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.ShortcutInfo; import com.android.launcher3.compat.UserHandleCompat; @@ -61,9 +62,10 @@ public class CacheDataUpdatedTask extends ExtendedModelTask { if (info instanceof ShortcutInfo && mUser.equals(info.user)) { ShortcutInfo si = (ShortcutInfo) info; ComponentName cn = si.getTargetComponent(); - if (isValidShortcut(si) && - cn != null && mPackages.contains(cn.getPackageName())) { - si.updateIcon(iconCache); + if (si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION + && isValidShortcut(si) && cn != null + && mPackages.contains(cn.getPackageName())) { + iconCache.getTitleAndIcon(si, si.getPromisedIntent(), si.user, si.usingLowResIcon); updatedShortcuts.add(si); } } @@ -85,7 +87,7 @@ public class CacheDataUpdatedTask extends ExtendedModelTask { public boolean isValidShortcut(ShortcutInfo si) { switch (mOp) { case OP_CACHE_UPDATE: - return si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; + return true; case OP_SESSION_UPDATE: return si.isPromise(); default: diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java index 176e8ea25..aae3490a7 100644 --- a/src/com/android/launcher3/model/PackageUpdatedTask.java +++ b/src/com/android/launcher3/model/PackageUpdatedTask.java @@ -34,6 +34,7 @@ import com.android.launcher3.LauncherModel; import com.android.launcher3.LauncherModel.CallbackTask; import com.android.launcher3.LauncherModel.Callbacks; import com.android.launcher3.LauncherSettings; +import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.ShortcutInfo; import com.android.launcher3.Utilities; import com.android.launcher3.compat.LauncherAppsCompat; @@ -209,11 +210,9 @@ public class PackageUpdatedTask extends ExtendedModelTask { // Update shortcuts which use iconResource. if ((si.iconResource != null) && packageSet.contains(si.iconResource.packageName)) { - Bitmap icon = LauncherIcons.createIconBitmap( - si.iconResource.packageName, - si.iconResource.resourceName, context); + Bitmap icon = LauncherIcons.createIconBitmap(si.iconResource, context); if (icon != null) { - si.setIcon(icon); + si.iconBitmap = icon; infoUpdated = true; } } @@ -251,14 +250,16 @@ public class PackageUpdatedTask extends ExtendedModelTask { si.promisedIntent = null; si.status = ShortcutInfo.DEFAULT; infoUpdated = true; - si.updateIcon(iconCache); + if (si.itemType == Favorites.ITEM_TYPE_APPLICATION) { + iconCache.getTitleAndIcon(si, si.getPromisedIntent(), + si.user, si.usingLowResIcon); + } } if (appInfo != null && Intent.ACTION_MAIN.equals(si.intent.getAction()) && si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { - si.updateIcon(iconCache); - si.title = Utilities.trim(appInfo.title); - si.contentDescription = appInfo.contentDescription; + iconCache.getTitleAndIcon( + si, si.getPromisedIntent(), si.user, si.usingLowResIcon); infoUpdated = true; } diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutView.java b/src/com/android/launcher3/shortcuts/DeepShortcutView.java index e7fc41512..679613789 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java @@ -26,9 +26,7 @@ import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; -import com.android.launcher3.IconCache; import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherAppState; import com.android.launcher3.LogAccelerateInterpolator; import com.android.launcher3.R; import com.android.launcher3.ShortcutInfo; @@ -95,8 +93,7 @@ public class DeepShortcutView extends FrameLayout implements ValueAnimator.Anima /** package private **/ void applyShortcutInfo(UnbadgedShortcutInfo info, DeepShortcutsContainer container) { mInfo = info; - IconCache cache = LauncherAppState.getInstance().getIconCache(); - mBubbleText.applyFromShortcutInfo(info, cache); + mBubbleText.applyFromShortcutInfo(info); mIconView.setBackground(mBubbleText.getIcon()); // Use the long label as long as it exists and fits. diff --git a/src/com/android/launcher3/util/CursorIconInfo.java b/src/com/android/launcher3/util/CursorIconInfo.java index 6603ee765..3bc4eabc5 100644 --- a/src/com/android/launcher3/util/CursorIconInfo.java +++ b/src/com/android/launcher3/util/CursorIconInfo.java @@ -60,7 +60,7 @@ public class CursorIconInfo { info.iconResource = new ShortcutIconResource(); info.iconResource.packageName = packageName; info.iconResource.resourceName = resourceName; - icon = LauncherIcons.createIconBitmap(packageName, resourceName, mContext); + icon = LauncherIcons.createIconBitmap(info.iconResource, mContext); } if (icon == null) { // Failed to load from resource, try loading from DB. diff --git a/src/com/android/launcher3/util/ManagedProfileHeuristic.java b/src/com/android/launcher3/util/ManagedProfileHeuristic.java index 817a38ad5..6b4021f31 100644 --- a/src/com/android/launcher3/util/ManagedProfileHeuristic.java +++ b/src/com/android/launcher3/util/ManagedProfileHeuristic.java @@ -19,7 +19,9 @@ package com.android.launcher3.util; import android.content.Context; import android.content.SharedPreferences; +import com.android.launcher3.AppInfo; import com.android.launcher3.FolderInfo; +import com.android.launcher3.IconCache; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherFiles; @@ -65,11 +67,13 @@ public class ManagedProfileHeuristic { private final Context mContext; private final LauncherModel mModel; private final UserHandleCompat mUser; + private final IconCache mIconCache; private ManagedProfileHeuristic(Context context, UserHandleCompat user) { mContext = context; mUser = user; mModel = LauncherAppState.getInstance().getModel(); + mIconCache = LauncherAppState.getInstance().getIconCache(); } public void processPackageRemoved(String[] packages) { @@ -108,10 +112,12 @@ public class ManagedProfileHeuristic { long folderCreationTime = mUserManager.getUserCreationTime(user) + AUTO_ADD_TO_FOLDER_DURATION; + boolean quietModeEnabled = UserManagerCompat.getInstance(mContext) + .isQuietModeEnabled(user); for (int i = 0; i < count; i++) { LauncherActivityInstallInfo info = apps.get(i); - - ShortcutInfo si = new ShortcutInfo(info.info, mContext); + ShortcutInfo si = new AppInfo(mContext, info.info, user, mIconCache, + quietModeEnabled, false /* useLowResIcon */).makeShortcut(); ((info.installTime <= folderCreationTime) ? workFolderApps : homescreenApps).add(si); } diff --git a/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java b/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java index 25b8df933..646ef2794 100644 --- a/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java +++ b/tests/src/com/android/launcher3/model/CacheDataUpdatedTaskTest.java @@ -1,15 +1,12 @@ package com.android.launcher3.model; import com.android.launcher3.AppInfo; -import com.android.launcher3.IconCache; import com.android.launcher3.ItemInfo; import com.android.launcher3.ShortcutInfo; import java.util.Arrays; import java.util.HashSet; -import static org.mockito.Mockito.mock; - /** * Tests for {@link CacheDataUpdatedTask} */ @@ -67,14 +64,13 @@ public class CacheDataUpdatedTaskTest extends BaseModelUpdateTaskTestCase { private void verifyUpdate(Long... idsUpdated) { HashSet<Long> updates = new HashSet<>(Arrays.asList(idsUpdated)); - IconCache noOpIconCache = mock(IconCache.class); for (ItemInfo info : bgDataModel.itemsIdMap) { if (updates.contains(info.id)) { assertEquals(NEW_LABEL_PREFIX + info.id, info.title); - assertNotNull(((ShortcutInfo) info).getIcon(noOpIconCache)); + assertNotNull(((ShortcutInfo) info).iconBitmap); } else { assertNotSame(NEW_LABEL_PREFIX + info.id, info.title); - assertNull(((ShortcutInfo) info).getIcon(noOpIconCache)); + assertNull(((ShortcutInfo) info).iconBitmap); } } } |