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

Commit 270d29c4 authored by Jon Miranda's avatar Jon Miranda
Browse files

Only get drawable on the background thread, everything else on main thread.

Bug: 128259687
Change-Id: I6230bfdc292e9a43ab935cfb6debb7a6fac4d4f7
parent f820d5d8
Loading
Loading
Loading
Loading
+62 −56
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ public class FloatingIconView extends View implements Animator.AnimatorListener,
    private Runnable mStartRunnable;
    private Runnable mEndRunnable;

    private Drawable mDrawable;
    private int mOriginalHeight;
    private final int mBlurSizeOutline;

@@ -191,25 +190,32 @@ public class FloatingIconView extends View implements Animator.AnimatorListener,
    private void getIcon(Launcher launcher, View v, ItemInfo info, boolean useDrawableAsIs,
            float aspectRatio) {
        final LayoutParams lp = (LayoutParams) getLayoutParams();

        Drawable drawable = null;
        boolean supportsAdaptiveIcons = ADAPTIVE_ICON_WINDOW_ANIM.get() && !useDrawableAsIs
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
        if (!supportsAdaptiveIcons && v instanceof BubbleTextView) {
            // Similar to DragView, we simply use the BubbleTextView icon here.
            mDrawable = ((BubbleTextView) v).getIcon();
            drawable = ((BubbleTextView) v).getIcon();
        }
        if (v instanceof ImageView && info instanceof SystemShortcut) {
            mDrawable = ((ImageView) v).getDrawable();
            drawable = ((ImageView) v).getDrawable();
        }
        if (mDrawable == null) {
            mDrawable = Utilities.getFullDrawable(launcher, info, lp.width, lp.height,
        if (drawable == null) {
            drawable = Utilities.getFullDrawable(launcher, info, lp.width, lp.height,
                    useDrawableAsIs, new Object[1]);
        }

        if (supportsAdaptiveIcons && mDrawable instanceof AdaptiveIconDrawable) {
        Drawable finalDrawable = drawable == null ? null
                : drawable.getConstantState().newDrawable();
        boolean isAdaptiveIcon = supportsAdaptiveIcons
                && finalDrawable instanceof AdaptiveIconDrawable;
        int iconOffset = getOffsetForIconBounds(finalDrawable);

        new Handler(Looper.getMainLooper()).post(() -> {
            if (isAdaptiveIcon) {
                mIsAdaptiveIcon = true;

            AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) mDrawable;
                AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) finalDrawable;
                Drawable background = adaptiveIcon.getBackground();
                if (background == null) {
                    background = new ColorDrawable(Color.TRANSPARENT);
@@ -221,8 +227,8 @@ public class FloatingIconView extends View implements Animator.AnimatorListener,
                }
                mForeground = foreground;

            int offset = getOffsetForAdaptiveIconBounds();
            mFinalDrawableBounds.set(offset, offset, lp.width - offset, mOriginalHeight - offset);
                mFinalDrawableBounds.set(iconOffset, iconOffset, lp.width -
                        iconOffset, mOriginalHeight - iconOffset);
                if (mForeground instanceof ShiftedBitmapDrawable && v instanceof FolderIcon) {
                    ShiftedBitmapDrawable sbd = (ShiftedBitmapDrawable) mForeground;
                    ((FolderIcon) v).getPreviewBounds(sTmpRect);
@@ -254,10 +260,9 @@ public class FloatingIconView extends View implements Animator.AnimatorListener,
                });
                setClipToOutline(true);
            } else {
            setBackground(mDrawable);
                setBackground(finalDrawable);
            }

        new Handler(Looper.getMainLooper()).post(() -> {
            invalidate();
            invalidateOutline();
        });
@@ -272,9 +277,10 @@ public class FloatingIconView extends View implements Animator.AnimatorListener,
        mBackground.setBounds(mBgDrawableBounds);
    }

    private int getOffsetForAdaptiveIconBounds() {
    @WorkerThread
    private int getOffsetForIconBounds(Drawable drawable) {
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O ||
                !(mDrawable instanceof AdaptiveIconDrawable)) {
                !(drawable instanceof AdaptiveIconDrawable)) {
            return 0;
        }

@@ -283,7 +289,7 @@ public class FloatingIconView extends View implements Animator.AnimatorListener,
        bounds.inset(mBlurSizeOutline / 2, mBlurSizeOutline / 2);

        try (LauncherIcons li = LauncherIcons.obtain(Launcher.fromContext(getContext()))) {
            Utilities.scaleRectAboutCenter(bounds, li.getNormalizer().getScale(mDrawable, null));
            Utilities.scaleRectAboutCenter(bounds, li.getNormalizer().getScale(drawable, null));
        }

        bounds.inset(