Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2d7cca1e authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Updating PendingAppWidgetHostView to load icon on the background thread

Bug: 21325319
Change-Id: I0886eec5a3f36f5e1ac18020c54891a56bdb5ed2
parent a167a6e0
Loading
Loading
Loading
Loading
+6 −16
Original line number Diff line number Diff line
@@ -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<Theme> sPreloaderThemes = new SparseArray<Theme>(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);
+14 −19
Original line number Diff line number Diff line
@@ -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<LauncherActivityInfoCompat> infoProfider,
            @NonNull Provider<LauncherActivityInfoCompat> 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);
    }
}
+13 −7
Original line number Diff line number Diff line
@@ -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() {
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ public class PackageItemInfo extends ItemInfoWithIcon {
     */
    public String packageName;

    PackageItemInfo(String packageName) {
    public PackageItemInfo(String packageName) {
        this.packageName = packageName;
    }