From 2d7cca1e052b982a1fd1d28c0174ad4e6f2d22d3 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 3 Jan 2017 16:52:43 -0800 Subject: Updating PendingAppWidgetHostView to load icon on the background thread Bug: 21325319 Change-Id: I0886eec5a3f36f5e1ac18020c54891a56bdb5ed2 --- src/com/android/launcher3/BubbleTextView.java | 22 ++++----------- src/com/android/launcher3/IconCache.java | 33 +++++++++------------- .../launcher3/PendingAppWidgetHostView.java | 20 ++++++++----- .../android/launcher3/model/PackageItemInfo.java | 2 +- 4 files changed, 34 insertions(+), 43 deletions(-) (limited to 'src/com/android/launcher3') diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 5e9e7e207..b8b43c9c3 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -38,6 +38,7 @@ import android.view.ViewParent; import android.widget.TextView; import com.android.launcher3.IconCache.IconLoadRequest; +import com.android.launcher3.IconCache.ItemInfoUpdateReceiver; import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.graphics.DrawableFactory; import com.android.launcher3.graphics.HolographicOutlineHelper; @@ -51,7 +52,7 @@ import java.text.NumberFormat; * too aggressive. */ public class BubbleTextView extends TextView - implements BaseRecyclerViewFastScrollBar.FastScrollFocusableView { + implements BaseRecyclerViewFastScrollBar.FastScrollFocusableView, ItemInfoUpdateReceiver { private static SparseArray sPreloaderThemes = new SparseArray(2); @@ -540,7 +541,8 @@ public class BubbleTextView extends TextView /** * Applies the item info if it is same as what the view is pointing to currently. */ - public void reapplyItemInfo(final ItemInfo info) { + @Override + public void reapplyItemInfo(ItemInfoWithIcon info) { if (getTag() == info) { FastBitmapDrawable.State prevState = FastBitmapDrawable.State.NORMAL; if (mIcon instanceof FastBitmapDrawable) { @@ -582,20 +584,8 @@ public class BubbleTextView extends TextView mIconLoadRequest.cancel(); mIconLoadRequest = null; } - if (getTag() instanceof AppInfo) { - AppInfo info = (AppInfo) getTag(); - if (info.usingLowResIcon) { - mIconLoadRequest = LauncherAppState.getInstance().getIconCache() - .updateIconInBackground(BubbleTextView.this, info); - } - } else if (getTag() instanceof ShortcutInfo) { - ShortcutInfo info = (ShortcutInfo) getTag(); - if (info.usingLowResIcon) { - mIconLoadRequest = LauncherAppState.getInstance().getIconCache() - .updateIconInBackground(BubbleTextView.this, info); - } - } else if (getTag() instanceof PackageItemInfo) { - PackageItemInfo info = (PackageItemInfo) getTag(); + if (getTag() instanceof ItemInfoWithIcon) { + ItemInfoWithIcon info = (ItemInfoWithIcon) getTag(); if (info.usingLowResIcon) { mIconLoadRequest = LauncherAppState.getInstance().getIconCache() .updateIconInBackground(BubbleTextView.this, info); diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index b22cb7c1a..7c50a5c2a 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -406,13 +406,14 @@ public class IconCache { * Fetches high-res icon for the provided ItemInfo and updates the caller when done. * @return a request ID that can be used to cancel the request. */ - public IconLoadRequest updateIconInBackground(final BubbleTextView caller, final ItemInfo info) { + public IconLoadRequest updateIconInBackground(final ItemInfoUpdateReceiver caller, + final ItemInfoWithIcon info) { Runnable request = new Runnable() { @Override public void run() { if (info instanceof AppInfo || info instanceof ShortcutInfo) { - getTitleAndIcon((ItemInfoWithIcon) info, false); + getTitleAndIcon(info, false); } else if (info instanceof PackageItemInfo) { getTitleAndIconForApp((PackageItemInfo) info, false); } @@ -429,20 +430,6 @@ public class IconCache { return new IconLoadRequest(request, mWorkerHandler); } - /** - * Returns a high res icon for the given intent and user - */ - public synchronized Bitmap getIcon(Intent intent, UserHandle 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); - } - return cacheLocked(component, new ActivityInfoProvider(intent, user), - user, true, false /* useLowRes */).icon; - } - /** * Updates {@param application} only if a valid entry is found. */ @@ -528,7 +515,7 @@ public class IconCache { */ protected CacheEntry cacheLocked( @NonNull ComponentName componentName, - @NonNull Provider infoProfider, + @NonNull Provider infoProvider, UserHandle user, boolean usePackageIcon, boolean useLowResIcon) { ComponentKey cacheKey = new ComponentKey(componentName, user); CacheEntry entry = mCache.get(cacheKey); @@ -541,7 +528,7 @@ public class IconCache { boolean providerFetchedOnce = false; if (!getEntryFromDB(cacheKey, entry, useLowResIcon) || DEBUG_IGNORE_CACHE) { - info = infoProfider.get(); + info = infoProvider.get(); providerFetchedOnce = true; if (info != null) { @@ -570,7 +557,7 @@ public class IconCache { if (TextUtils.isEmpty(entry.title)) { if (info == null && !providerFetchedOnce) { - info = infoProfider.get(); + info = infoProvider.get(); providerFetchedOnce = true; } if (info != null) { @@ -868,4 +855,12 @@ public class IconCache { return mLauncherApps.resolveActivity(mIntent, mUser); } } + + /** + * Interface for receiving itemInfo with high-res icon. + */ + public interface ItemInfoUpdateReceiver { + + void reapplyItemInfo(ItemInfoWithIcon info); + } } diff --git a/src/com/android/launcher3/PendingAppWidgetHostView.java b/src/com/android/launcher3/PendingAppWidgetHostView.java index 2976807a4..3256df6fe 100644 --- a/src/com/android/launcher3/PendingAppWidgetHostView.java +++ b/src/com/android/launcher3/PendingAppWidgetHostView.java @@ -17,7 +17,6 @@ package com.android.launcher3; import android.content.Context; -import android.content.Intent; import android.content.res.Resources.Theme; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -35,8 +34,11 @@ import android.view.View; import android.view.View.OnClickListener; import com.android.launcher3.graphics.DrawableFactory; +import com.android.launcher3.IconCache.ItemInfoUpdateReceiver; +import com.android.launcher3.model.PackageItemInfo; -public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implements OnClickListener { +public class PendingAppWidgetHostView extends LauncherAppWidgetHostView + implements OnClickListener, ItemInfoUpdateReceiver { private static final float SETUP_ICON_SIZE_FACTOR = 2f / 5; private static final float MIN_SATUNATION = 0.7f; @@ -47,7 +49,6 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen private OnClickListener mClickListener; private final LauncherAppWidgetInfo mInfo; private final int mStartState; - private final Intent mIconLookupIntent; private final boolean mDisabledForSafeMode; private Launcher mLauncher; @@ -68,7 +69,6 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen mLauncher = Launcher.getLauncher(context); mInfo = info; mStartState = info.restoreStatus; - mIconLookupIntent = new Intent().setComponent(info.providerName); mDisabledForSafeMode = disabledForSafeMode; mPaint = new TextPaint(); @@ -79,9 +79,13 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen setWillNotDraw(false); setElevation(getResources().getDimension(R.dimen.pending_widget_elevation)); - updateIcon(cache); updateAppWidget(null); setOnClickListener(mLauncher); + + // Load icon + PackageItemInfo item = new PackageItemInfo(info.providerName.getPackageName()); + item.user = info.user; + cache.updateIconInBackground(this, item); } @Override @@ -117,8 +121,9 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen mDrawableSizeChanged = true; } - private void updateIcon(IconCache cache) { - Bitmap icon = cache.getIcon(mIconLookupIntent, mInfo.user); + @Override + public void reapplyItemInfo(ItemInfoWithIcon info) { + Bitmap icon = info.iconBitmap; if (mIcon == icon) { return; } @@ -157,6 +162,7 @@ public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implemen } mDrawableSizeChanged = true; } + invalidate(); } private void updateSettingColor() { diff --git a/src/com/android/launcher3/model/PackageItemInfo.java b/src/com/android/launcher3/model/PackageItemInfo.java index e05bf1e90..baeaa9492 100644 --- a/src/com/android/launcher3/model/PackageItemInfo.java +++ b/src/com/android/launcher3/model/PackageItemInfo.java @@ -28,7 +28,7 @@ public class PackageItemInfo extends ItemInfoWithIcon { */ public String packageName; - PackageItemInfo(String packageName) { + public PackageItemInfo(String packageName) { this.packageName = packageName; } -- cgit v1.2.3