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

Commit 6dfa3128 authored by Jon Miranda's avatar Jon Miranda
Browse files

Preloads the icon drawable for app open to reduce latency b/w swapping views.

For app close, we already load the icon as soon as we can.

Bug: 135130011
Change-Id: Ia2c45737cf24d1ab5911b222ae097d7a1f9d6a31
parent 3d6e96d5
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -59,6 +59,7 @@ import android.view.View;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.util.MultiValueAlpha;
import com.android.launcher3.util.MultiValueAlpha;
@@ -182,6 +183,12 @@ public abstract class QuickstepAppTransitionManagerImpl extends LauncherAppTrans
        mDeviceProfile = dp;
        mDeviceProfile = dp;
    }
    }


    @Override
    public boolean supportsAdaptiveIconAnimation() {
        return hasControlRemoteAppTransitionPermission()
                && FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM.get();
    }

    /**
    /**
     * @return ActivityOptions with remote animations that controls how the window of the opening
     * @return ActivityOptions with remote animations that controls how the window of the opening
     *         targets are displayed.
     *         targets are displayed.
+4 −0
Original line number Original line Diff line number Diff line
@@ -51,4 +51,8 @@ public class LauncherAppTransitionManager implements ResourceBasedOverride {
        }
        }
        return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
        return ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
    }
    }

    public boolean supportsAdaptiveIconAnimation() {
        return false;
    }
}
}
+5 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.views.FloatingIconView;
import com.android.launcher3.widget.PendingAppWidgetHostView;
import com.android.launcher3.widget.PendingAppWidgetHostView;
import com.android.launcher3.widget.WidgetAddFlowHandler;
import com.android.launcher3.widget.WidgetAddFlowHandler;


@@ -259,6 +260,10 @@ public class ItemClickHandler {
                intent.setPackage(null);
                intent.setPackage(null);
            }
            }
        }
        }
        if (v != null && launcher.getAppTransitionManager().supportsAdaptiveIconAnimation()) {
            // Preload the icon to reduce latency b/w swapping the floating view with the original.
            FloatingIconView.fetchIcon(launcher, v, item, true /* isOpening */);
        }
        launcher.startActivitySafely(v, intent, item, sourceContainer);
        launcher.startActivitySafely(v, intent, item, sourceContainer);
    }
    }
}
}
+239 −135
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@ package com.android.launcher3.views;


import static com.android.launcher3.LauncherAnimUtils.DRAWABLE_ALPHA;
import static com.android.launcher3.LauncherAnimUtils.DRAWABLE_ALPHA;
import static com.android.launcher3.Utilities.getBadge;
import static com.android.launcher3.Utilities.getBadge;
import static com.android.launcher3.Utilities.getFullDrawable;
import static com.android.launcher3.Utilities.mapToRange;
import static com.android.launcher3.Utilities.mapToRange;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM;
import static com.android.launcher3.config.FeatureFlags.ADAPTIVE_ICON_WINDOW_ANIM;
@@ -42,6 +43,7 @@ import android.os.Build;
import android.os.CancellationSignal;
import android.os.CancellationSignal;
import android.os.Handler;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.ViewOutlineProvider;
@@ -65,6 +67,7 @@ import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.shortcuts.DeepShortcutView;


import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.annotation.WorkerThread;
import androidx.annotation.WorkerThread;
import androidx.dynamicanimation.animation.FloatPropertyCompat;
import androidx.dynamicanimation.animation.FloatPropertyCompat;
import androidx.dynamicanimation.animation.SpringAnimation;
import androidx.dynamicanimation.animation.SpringAnimation;
@@ -77,6 +80,11 @@ import androidx.dynamicanimation.animation.SpringForce;
public class FloatingIconView extends View implements
public class FloatingIconView extends View implements
        Animator.AnimatorListener, ClipPathView, OnGlobalLayoutListener {
        Animator.AnimatorListener, ClipPathView, OnGlobalLayoutListener {


    private static final String TAG = FloatingIconView.class.getSimpleName();

    // Manages loading the icon on a worker thread
    private static @Nullable IconLoadResult sIconLoadResult;

    public static final float SHAPE_PROGRESS_DURATION = 0.10f;
    public static final float SHAPE_PROGRESS_DURATION = 0.10f;
    private static final int FADE_DURATION_MS = 200;
    private static final int FADE_DURATION_MS = 200;
    private static final Rect sTmpRect = new Rect();
    private static final Rect sTmpRect = new Rect();
@@ -126,6 +134,8 @@ public class FloatingIconView extends View implements
    private boolean mIsAdaptiveIcon = false;
    private boolean mIsAdaptiveIcon = false;
    private boolean mIsOpening;
    private boolean mIsOpening;


    private IconLoadResult mIconLoadResult;

    private @Nullable Drawable mBadge;
    private @Nullable Drawable mBadge;
    private @Nullable Drawable mForeground;
    private @Nullable Drawable mForeground;
    private @Nullable Drawable mBackground;
    private @Nullable Drawable mBackground;
@@ -299,8 +309,8 @@ public class FloatingIconView extends View implements
     * @param v The view to copy
     * @param v The view to copy
     * @param positionOut Rect that will hold the size and position of v.
     * @param positionOut Rect that will hold the size and position of v.
     */
     */
    private void matchPositionOf(View v, RectF positionOut) {
    private void matchPositionOf(Launcher launcher, View v, boolean isOpening, RectF positionOut) {
        float rotation = getLocationBoundsForView(v, positionOut);
        float rotation = getLocationBoundsForView(launcher, v, isOpening, positionOut);
        final LayoutParams lp = new LayoutParams(
        final LayoutParams lp = new LayoutParams(
                Math.round(positionOut.width()),
                Math.round(positionOut.width()),
                Math.round(positionOut.height()));
                Math.round(positionOut.height()));
@@ -328,8 +338,9 @@ public class FloatingIconView extends View implements
     * - For DeepShortcutView, we return the bounds of the icon view.
     * - For DeepShortcutView, we return the bounds of the icon view.
     * - For BubbleTextView, we return the icon bounds.
     * - For BubbleTextView, we return the icon bounds.
     */
     */
    private float getLocationBoundsForView(View v, RectF outRect) {
    private static float getLocationBoundsForView(Launcher launcher, View v, boolean isOpening,
        boolean ignoreTransform = !mIsOpening;
            RectF outRect) {
        boolean ignoreTransform = !isOpening;
        if (v instanceof DeepShortcutView) {
        if (v instanceof DeepShortcutView) {
            v = ((DeepShortcutView) v).getBubbleText();
            v = ((DeepShortcutView) v).getBubbleText();
            ignoreTransform = false;
            ignoreTransform = false;
@@ -353,7 +364,7 @@ public class FloatingIconView extends View implements
        float[] points = new float[] {iconBounds.left, iconBounds.top, iconBounds.right,
        float[] points = new float[] {iconBounds.left, iconBounds.top, iconBounds.right,
                iconBounds.bottom};
                iconBounds.bottom};
        float[] rotation = new float[] {0};
        float[] rotation = new float[] {0};
        Utilities.getDescendantCoordRelativeToAncestor(v, mLauncher.getDragLayer(), points,
        Utilities.getDescendantCoordRelativeToAncestor(v, launcher.getDragLayer(), points,
                false, ignoreTransform, rotation);
                false, ignoreTransform, rotation);
        outRect.set(
        outRect.set(
                Math.min(points[0], points[2]),
                Math.min(points[0], points[2]),
@@ -363,60 +374,89 @@ public class FloatingIconView extends View implements
        return rotation[0];
        return rotation[0];
    }
    }


    /**
     * Loads the icon and saves the results to {@link #sIconLoadResult}.
     * Runs onIconLoaded callback (if any), which signifies that the FloatingIconView is
     * ready to display the icon. Otherwise, the FloatingIconView will grab the results when its
     * initialized.
     *
     * @param originalView The View that the FloatingIconView will replace.
     * @param info ItemInfo of the originalView
     * @param pos The position of the view.
     */
    @WorkerThread
    @WorkerThread
    @SuppressWarnings("WrongThread")
    @SuppressWarnings("WrongThread")
    private void getIcon(View v, ItemInfo info, boolean isOpening,
    private static void getIconResult(Launcher l, View originalView, ItemInfo info, RectF pos,
            Runnable onIconLoadedRunnable, CancellationSignal loadIconSignal) {
            IconLoadResult iconLoadResult) {
        final LayoutParams lp = (LayoutParams) getLayoutParams();
        Drawable drawable = null;
        Drawable drawable = null;
        Drawable badge = null;
        boolean supportsAdaptiveIcons = ADAPTIVE_ICON_WINDOW_ANIM.get()
        boolean supportsAdaptiveIcons = ADAPTIVE_ICON_WINDOW_ANIM.get()
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
        Drawable btvIcon = v instanceof BubbleTextView ? ((BubbleTextView) v).getIcon() : null;
        Drawable btvIcon = originalView instanceof BubbleTextView
                ? ((BubbleTextView) originalView).getIcon() : null;
        if (info instanceof SystemShortcut) {
        if (info instanceof SystemShortcut) {
            if (v instanceof ImageView) {
            if (originalView instanceof ImageView) {
                drawable = ((ImageView) v).getDrawable();
                drawable = ((ImageView) originalView).getDrawable();
            } else if (v instanceof DeepShortcutView) {
            } else if (originalView instanceof DeepShortcutView) {
                drawable = ((DeepShortcutView) v).getIconView().getBackground();
                drawable = ((DeepShortcutView) originalView).getIconView().getBackground();
            } else {
            } else {
                drawable = v.getBackground();
                drawable = originalView.getBackground();
            }
            }
        } else {
        } else {
            boolean isFolderIcon = v instanceof FolderIcon;
            boolean isFolderIcon = originalView instanceof FolderIcon;
            int width = isFolderIcon ? v.getWidth() : lp.width;
            int width = isFolderIcon ? originalView.getWidth() : (int) pos.width();
            int height = isFolderIcon ? v.getHeight() : lp.height;
            int height = isFolderIcon ? originalView.getHeight() : (int) pos.height();
            if (supportsAdaptiveIcons) {
            if (supportsAdaptiveIcons) {
                drawable = Utilities.getFullDrawable(mLauncher, info, width, height, false,
                drawable = getFullDrawable(l, info, width, height, false, sTmpObjArray);
                        sTmpObjArray);
                if (drawable instanceof AdaptiveIconDrawable) {
                if (drawable instanceof AdaptiveIconDrawable) {
                    mBadge = getBadge(mLauncher, info, sTmpObjArray[0]);
                    badge = getBadge(l, info, sTmpObjArray[0]);
                } else {
                } else {
                    // The drawable we get back is not an adaptive icon, so we need to use the
                    // The drawable we get back is not an adaptive icon, so we need to use the
                    // BubbleTextView icon that is already legacy treated.
                    // BubbleTextView icon that is already legacy treated.
                    drawable = btvIcon;
                    drawable = btvIcon;
                }
                }
            } else {
            } else {
                if (v instanceof BubbleTextView) {
                if (originalView instanceof BubbleTextView) {
                    // Similar to DragView, we simply use the BubbleTextView icon here.
                    // Similar to DragView, we simply use the BubbleTextView icon here.
                    drawable = btvIcon;
                    drawable = btvIcon;
                } else {
                } else {
                    drawable = Utilities.getFullDrawable(mLauncher, info, width, height, false,
                    drawable = getFullDrawable(l, info, width, height, false, sTmpObjArray);
                            sTmpObjArray);
                }
                }
            }
            }
        }
        }


        Drawable finalDrawable = drawable == null ? null
        drawable = drawable == null ? null : drawable.getConstantState().newDrawable();
                : drawable.getConstantState().newDrawable();
        int iconOffset = getOffsetForIconBounds(l, drawable, pos);
        boolean isAdaptiveIcon = supportsAdaptiveIcons
        synchronized (iconLoadResult) {
                && finalDrawable instanceof AdaptiveIconDrawable;
            iconLoadResult.drawable = drawable;
        int iconOffset = getOffsetForIconBounds(finalDrawable);
            iconLoadResult.badge = badge;
            iconLoadResult.iconOffset = iconOffset;
            if (iconLoadResult.onIconLoaded != null) {
                l.getMainExecutor().execute(iconLoadResult.onIconLoaded);
                iconLoadResult.onIconLoaded = null;
            }
            iconLoadResult.isIconLoaded = true;
        }
    }


        mLauncher.getMainExecutor().execute(() -> {
    /**
            if (isAdaptiveIcon) {
     * Sets the drawables of the {@param originalView} onto this view.
                mIsAdaptiveIcon = true;
     *
                boolean isFolderIcon = finalDrawable instanceof FolderAdaptiveIcon;
     * @param originalView The View that the FloatingIconView will replace.
     * @param drawable The drawable of the original view.
     * @param badge The badge of the original view.
     * @param iconOffset The amount of offset needed to match this view with the original view.
     */
    @UiThread
    private void setIcon(View originalView, @Nullable Drawable drawable, @Nullable Drawable badge,
            int iconOffset) {
        mBadge = badge;

        mIsAdaptiveIcon = drawable instanceof AdaptiveIconDrawable;
        if (mIsAdaptiveIcon) {
            boolean isFolderIcon = drawable instanceof FolderAdaptiveIcon;


                AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) finalDrawable;
            AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) drawable;
            Drawable background = adaptiveIcon.getBackground();
            Drawable background = adaptiveIcon.getBackground();
            if (background == null) {
            if (background == null) {
                background = new ColorDrawable(Color.TRANSPARENT);
                background = new ColorDrawable(Color.TRANSPARENT);
@@ -428,11 +468,13 @@ public class FloatingIconView extends View implements
            }
            }
            mForeground = foreground;
            mForeground = foreground;


            final LayoutParams lp = (LayoutParams) getLayoutParams();
            final int originalHeight = lp.height;
            final int originalHeight = lp.height;
            final int originalWidth = lp.width;
            final int originalWidth = lp.width;


            int blurMargin = mBlurSizeOutline / 2;
            int blurMargin = mBlurSizeOutline / 2;
            mFinalDrawableBounds.set(0, 0, originalWidth, originalHeight);
            mFinalDrawableBounds.set(0, 0, originalWidth, originalHeight);

            if (!isFolderIcon) {
            if (!isFolderIcon) {
                mFinalDrawableBounds.inset(iconOffset - blurMargin, iconOffset - blurMargin);
                mFinalDrawableBounds.inset(iconOffset - blurMargin, iconOffset - blurMargin);
            }
            }
@@ -443,14 +485,14 @@ public class FloatingIconView extends View implements


            if (mBadge != null) {
            if (mBadge != null) {
                mBadge.setBounds(mStartRevealRect);
                mBadge.setBounds(mStartRevealRect);
                    if (!isOpening && !isFolderIcon) {
                if (!mIsOpening && !isFolderIcon) {
                    DRAWABLE_ALPHA.set(mBadge, 0);
                    DRAWABLE_ALPHA.set(mBadge, 0);
                }
                }
            }
            }


            if (isFolderIcon) {
            if (isFolderIcon) {
                    ((FolderIcon) v).getPreviewBounds(sTmpRect);
                ((FolderIcon) originalView).getPreviewBounds(sTmpRect);
                    float bgStroke = ((FolderIcon) v).getBackgroundStrokeWidth();
                float bgStroke = ((FolderIcon) originalView).getBackgroundStrokeWidth();
                if (mForeground instanceof ShiftedBitmapDrawable) {
                if (mForeground instanceof ShiftedBitmapDrawable) {
                    ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground;
                    ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground;
                    sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
                    sbd.setShiftX(sbd.getShiftX() - sTmpRect.left - bgStroke);
@@ -478,7 +520,7 @@ public class FloatingIconView extends View implements
            float scale = Math.max((float) lp.height / originalHeight,
            float scale = Math.max((float) lp.height / originalHeight,
                    (float) lp.width / originalWidth);
                    (float) lp.width / originalWidth);
            float bgDrawableStartScale;
            float bgDrawableStartScale;
                if (isOpening) {
            if (mIsOpening) {
                bgDrawableStartScale = 1f;
                bgDrawableStartScale = 1f;
                mOutline.set(0, 0, originalWidth, originalHeight);
                mOutline.set(0, 0, originalWidth, originalHeight);
            } else {
            } else {
@@ -495,16 +537,54 @@ public class FloatingIconView extends View implements
            });
            });
            setClipToOutline(true);
            setClipToOutline(true);
        } else {
        } else {
                setBackground(finalDrawable);
            setBackground(drawable);
            setClipToOutline(false);
            setClipToOutline(false);
        }
        }


            if (!loadIconSignal.isCanceled()) {
                onIconLoadedRunnable.run();
            }
        invalidate();
        invalidate();
        invalidateOutline();
        invalidateOutline();
        });
    }

    /**
     * Checks if the icon result is loaded. If true, we set the icon immediately. Else, we add a
     * callback to set the icon once the icon result is loaded.
     */
    private void checkIconResult(View originalView, boolean isOpening) {
        CancellationSignal cancellationSignal = new CancellationSignal();
        if (!isOpening) {
            // Hide immediately since the floating view starts at a different location.
            originalView.setVisibility(INVISIBLE);
            cancellationSignal.setOnCancelListener(() -> originalView.setVisibility(VISIBLE));
        }

        if (mIconLoadResult == null) {
            Log.w(TAG, "No icon load result found in checkIconResult");
            return;
        }

        synchronized (mIconLoadResult) {
            if (mIconLoadResult.isIconLoaded) {
                setIcon(originalView, mIconLoadResult.drawable, mIconLoadResult.badge,
                        mIconLoadResult.iconOffset);
                if (isOpening) {
                    originalView.setVisibility(INVISIBLE);
                }
            } else {
                mIconLoadResult.onIconLoaded = () -> {
                    if (cancellationSignal.isCanceled()) {
                        return;
                    }
                    if (mIconLoadResult.isIconLoaded) {
                        setIcon(originalView, mIconLoadResult.drawable, mIconLoadResult.badge,
                                mIconLoadResult.iconOffset);
                    }
                    // Delay swapping views until the icon is loaded to prevent a flash.
                    setVisibility(VISIBLE);
                    originalView.setVisibility(INVISIBLE);
                };
            }
        }
        mLoadIconSignal = cancellationSignal;
    }
    }


    private void setBackgroundDrawableBounds(float scale) {
    private void setBackgroundDrawableBounds(float scale) {
@@ -521,17 +601,19 @@ public class FloatingIconView extends View implements


    @WorkerThread
    @WorkerThread
    @SuppressWarnings("WrongThread")
    @SuppressWarnings("WrongThread")
    private int getOffsetForIconBounds(Drawable drawable) {
    private static int getOffsetForIconBounds(Launcher l, Drawable drawable, RectF position) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ||
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ||
                !(drawable instanceof AdaptiveIconDrawable)) {
                !(drawable instanceof AdaptiveIconDrawable)) {
            return 0;
            return 0;
        }
        }
        int blurSizeOutline =
                l.getResources().getDimensionPixelSize(R.dimen.blur_size_medium_outline);


        final LayoutParams lp = (LayoutParams) getLayoutParams();
        Rect bounds = new Rect(0, 0, (int) position.width() + blurSizeOutline,
        Rect bounds = new Rect(0, 0, lp.width + mBlurSizeOutline, lp.height + mBlurSizeOutline);
                (int) position.height() + blurSizeOutline);
        bounds.inset(mBlurSizeOutline / 2, mBlurSizeOutline / 2);
        bounds.inset(blurSizeOutline / 2, blurSizeOutline / 2);


        try (LauncherIcons li = LauncherIcons.obtain(mLauncher)) {
        try (LauncherIcons li = LauncherIcons.obtain(l)) {
            Utilities.scaleRectAboutCenter(bounds, li.getNormalizer().getScale(drawable, null,
            Utilities.scaleRectAboutCenter(bounds, li.getNormalizer().getScale(drawable, null,
                    null, null));
                    null, null));
        }
        }
@@ -587,7 +669,11 @@ public class FloatingIconView extends View implements
    }
    }


    @Override
    @Override
    public void onAnimationStart(Animator animator) {}
    public void onAnimationStart(Animator animator) {
        if (mIconLoadResult != null && mIconLoadResult.isIconLoaded) {
            setVisibility(View.VISIBLE);
        }
    }


    @Override
    @Override
    public void onAnimationCancel(Animator animator) {}
    public void onAnimationCancel(Animator animator) {}
@@ -598,7 +684,8 @@ public class FloatingIconView extends View implements
    @Override
    @Override
    public void onGlobalLayout() {
    public void onGlobalLayout() {
        if (mOriginalIcon.isAttachedToWindow() && mPositionOut != null) {
        if (mOriginalIcon.isAttachedToWindow() && mPositionOut != null) {
            float rotation = getLocationBoundsForView(mOriginalIcon, sTmpRectF);
            float rotation = getLocationBoundsForView(mLauncher, mOriginalIcon, mIsOpening,
                    sTmpRectF);
            if (rotation != mRotation || !sTmpRectF.equals(mPositionOut)) {
            if (rotation != mRotation || !sTmpRectF.equals(mPositionOut)) {
                updatePosition(rotation, sTmpRectF, (LayoutParams) getLayoutParams());
                updatePosition(rotation, sTmpRectF, (LayoutParams) getLayoutParams());
                if (mOnTargetChangeRunnable != null) {
                if (mOnTargetChangeRunnable != null) {
@@ -612,6 +699,22 @@ public class FloatingIconView extends View implements
        mOnTargetChangeRunnable = onTargetChangeListener;
        mOnTargetChangeRunnable = onTargetChangeListener;
    }
    }


    /**
     * Loads the icon drawable on a worker thread to reduce latency between swapping views.
     */
    @UiThread
    public static IconLoadResult fetchIcon(Launcher l, View v, ItemInfo info, boolean isOpening) {
        IconLoadResult result = new IconLoadResult();
        new Handler(LauncherModel.getWorkerLooper()).postAtFrontOfQueue(() -> {
            RectF position = new RectF();
            getLocationBoundsForView(l, v, isOpening, position);
            getIconResult(l, v, info, position, result);
        });

        sIconLoadResult = result;
        return result;
    }

    /**
    /**
     * Creates a floating icon view for {@param originalView}.
     * Creates a floating icon view for {@param originalView}.
     * @param originalView The view to copy
     * @param originalView The view to copy
@@ -624,38 +727,30 @@ public class FloatingIconView extends View implements
            boolean hideOriginal, RectF positionOut, boolean isOpening) {
            boolean hideOriginal, RectF positionOut, boolean isOpening) {
        final DragLayer dragLayer = launcher.getDragLayer();
        final DragLayer dragLayer = launcher.getDragLayer();
        ViewGroup parent = (ViewGroup) dragLayer.getParent();
        ViewGroup parent = (ViewGroup) dragLayer.getParent();

        FloatingIconView view = launcher.getViewCache().getView(R.layout.floating_icon_view,
        FloatingIconView view = launcher.getViewCache().getView(R.layout.floating_icon_view,
                launcher, parent);
                launcher, parent);
        view.recycle();
        view.recycle();


        // Get the drawable on the background thread
        boolean shouldLoadIcon = originalView.getTag() instanceof ItemInfo && hideOriginal;
        view.mIconLoadResult = sIconLoadResult;
        if (shouldLoadIcon && view.mIconLoadResult == null) {
            view.mIconLoadResult = fetchIcon(launcher, originalView,
                    (ItemInfo) originalView.getTag(), isOpening);
        }
        sIconLoadResult = null;

        view.mIsVerticalBarLayout = launcher.getDeviceProfile().isVerticalBarLayout();
        view.mIsVerticalBarLayout = launcher.getDeviceProfile().isVerticalBarLayout();
        view.mIsOpening = isOpening;
        view.mIsOpening = isOpening;

        view.mOriginalIcon = originalView;
        view.mOriginalIcon = originalView;
        view.mPositionOut = positionOut;
        view.mPositionOut = positionOut;

        // Match the position of the original view.
        // Match the position of the original view.
        view.matchPositionOf(originalView, positionOut);
        view.matchPositionOf(launcher, originalView, isOpening, positionOut);


        // Get the drawable on the background thread
        // Must be called after matchPositionOf so that we know what size to load.
        // Must be called after matchPositionOf so that we know what size to load.
        if (originalView.getTag() instanceof ItemInfo && hideOriginal) {
        if (shouldLoadIcon) {
            view.mLoadIconSignal = new CancellationSignal();
            view.checkIconResult(originalView, isOpening);
            Runnable onIconLoaded = () -> {
                // Delay swapping views until the icon is loaded to prevent a flash.
                view.setVisibility(VISIBLE);
                originalView.setVisibility(INVISIBLE);
            };
            if (!isOpening) {
                // Hide immediately since the floating view starts at a different location.
                originalView.setVisibility(INVISIBLE);
                view.mLoadIconSignal.setOnCancelListener(() -> originalView.setVisibility(VISIBLE));
            }
            CancellationSignal loadIconSignal = view.mLoadIconSignal;
            new Handler(LauncherModel.getWorkerLooper()).postAtFrontOfQueue(() -> {
                view.getIcon(originalView, (ItemInfo) originalView.getTag(), isOpening,
                        onIconLoaded, loadIconSignal);
            });
        }
        }


        // We need to add it to the overlay, but keep it invisible until animation starts..
        // We need to add it to the overlay, but keep it invisible until animation starts..
@@ -779,5 +874,14 @@ public class FloatingIconView extends View implements
        mFgSpringY.cancel();
        mFgSpringY.cancel();
        mBadge = null;
        mBadge = null;
        sTmpObjArray[0] = null;
        sTmpObjArray[0] = null;
        mIconLoadResult = null;
    }

    private static class IconLoadResult {
        Drawable drawable;
        Drawable badge;
        int iconOffset;
        Runnable onIconLoaded;
        boolean isIconLoaded;
    }
    }
}
}