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

Commit ad7e199e authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Clone the drawable lazily instead of on the UI thread while initializing" into tm-dev

parents ecea734d 0d88d008
Loading
Loading
Loading
Loading
+17 −8
Original line number Original line Diff line number Diff line
@@ -58,6 +58,8 @@ import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.popup.SystemShortcut;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.shortcuts.DeepShortcutView;


import java.util.function.Supplier;

/**
/**
 * A view that is created to look like another view with the purpose of creating fluid animations.
 * A view that is created to look like another view with the purpose of creating fluid animations.
 */
 */
@@ -295,9 +297,11 @@ public class FloatingIconView extends FrameLayout implements


        drawable = drawable == null ? null : drawable.getConstantState().newDrawable();
        drawable = drawable == null ? null : drawable.getConstantState().newDrawable();
        int iconOffset = getOffsetForIconBounds(l, drawable, pos);
        int iconOffset = getOffsetForIconBounds(l, drawable, pos);
        // Clone right away as we are on the background thread instead of blocking the
        // main thread later
        Drawable btvClone = btvIcon == null ? null : btvIcon.getConstantState().newDrawable();
        synchronized (outIconLoadResult) {
        synchronized (outIconLoadResult) {
            outIconLoadResult.btvDrawable = btvIcon == null || drawable == btvIcon
            outIconLoadResult.btvDrawable = () -> btvClone;
                    ? null : btvIcon.getConstantState().newDrawable();
            outIconLoadResult.drawable = drawable;
            outIconLoadResult.drawable = drawable;
            outIconLoadResult.badge = badge;
            outIconLoadResult.badge = badge;
            outIconLoadResult.iconOffset = iconOffset;
            outIconLoadResult.iconOffset = iconOffset;
@@ -318,7 +322,7 @@ public class FloatingIconView extends FrameLayout implements
     */
     */
    @UiThread
    @UiThread
    private void setIcon(@Nullable Drawable drawable, @Nullable Drawable badge,
    private void setIcon(@Nullable Drawable drawable, @Nullable Drawable badge,
            @Nullable Drawable btvIcon, int iconOffset) {
            @Nullable Supplier<Drawable> btvIcon, int iconOffset) {
        final DeviceProfile dp = mLauncher.getDeviceProfile();
        final DeviceProfile dp = mLauncher.getDeviceProfile();
        final InsettableFrameLayout.LayoutParams lp =
        final InsettableFrameLayout.LayoutParams lp =
                (InsettableFrameLayout.LayoutParams) getLayoutParams();
                (InsettableFrameLayout.LayoutParams) getLayoutParams();
@@ -361,9 +365,9 @@ public class FloatingIconView extends FrameLayout implements
     *
     *
     * Allows nullable as this may be cleared when drawing is deferred to ClipIconView.
     * Allows nullable as this may be cleared when drawing is deferred to ClipIconView.
     */
     */
    private void setOriginalDrawableBackground(@Nullable Drawable btvIcon) {
    private void setOriginalDrawableBackground(@Nullable Supplier<Drawable> btvIcon) {
        if (!mIsOpening) {
        if (!mIsOpening) {
            mBtvDrawable.setBackground(btvIcon);
            mBtvDrawable.setBackground(btvIcon == null ? null : btvIcon.get());
        }
        }
    }
    }


@@ -518,21 +522,26 @@ public class FloatingIconView extends FrameLayout implements
        getLocationBoundsForView(l, v, isOpening, position);
        getLocationBoundsForView(l, v, isOpening, position);


        final FastBitmapDrawable btvIcon;
        final FastBitmapDrawable btvIcon;
        final Supplier<Drawable> btvDrawableSupplier;
        if (v instanceof BubbleTextView) {
        if (v instanceof BubbleTextView) {
            BubbleTextView btv = (BubbleTextView) v;
            BubbleTextView btv = (BubbleTextView) v;
            if (info instanceof ItemInfoWithIcon
            if (info instanceof ItemInfoWithIcon
                    && (((ItemInfoWithIcon) info).runtimeStatusFlags
                    && (((ItemInfoWithIcon) info).runtimeStatusFlags
                    & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK) != 0) {
                    & ItemInfoWithIcon.FLAG_SHOW_DOWNLOAD_PROGRESS_MASK) != 0) {
                btvIcon = btv.makePreloadIcon();
                btvIcon = btv.makePreloadIcon();
                btvDrawableSupplier = () -> btvIcon;
            } else {
            } else {
                btvIcon = (FastBitmapDrawable) btv.getIcon().getConstantState().newDrawable();
                btvIcon = btv.getIcon();
                // Clone when needed
                btvDrawableSupplier = () -> btvIcon.getConstantState().newDrawable();
            }
            }
        } else {
        } else {
            btvIcon = null;
            btvIcon = null;
            btvDrawableSupplier = null;
        }
        }


        IconLoadResult result = new IconLoadResult(info, btvIcon != null && btvIcon.isThemed());
        IconLoadResult result = new IconLoadResult(info, btvIcon != null && btvIcon.isThemed());
        result.btvDrawable = btvIcon;
        result.btvDrawable = btvDrawableSupplier;


        final long fetchIconId = sFetchIconId++;
        final long fetchIconId = sFetchIconId++;
        MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() -> {
        MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(() -> {
@@ -647,7 +656,7 @@ public class FloatingIconView extends FrameLayout implements
    private static class IconLoadResult {
    private static class IconLoadResult {
        final ItemInfo itemInfo;
        final ItemInfo itemInfo;
        final boolean isThemed;
        final boolean isThemed;
        Drawable btvDrawable;
        Supplier<Drawable> btvDrawable;
        Drawable drawable;
        Drawable drawable;
        Drawable badge;
        Drawable badge;
        int iconOffset;
        int iconOffset;