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

Commit 45abb0b3 authored by wilsonshih's avatar wilsonshih
Browse files

Using BaseIconFactory to draw legacy icon.

Use the shared launcher library to draw legacy icon.

Bug: 193780874
Test: launch app which still using legacy icon from Launcher.
Change-Id: Id8ccb5b6c532880ff207526fd754e92fdd08e284
parent 6b43ea0a
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
@@ -57,6 +58,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.palette.Palette;
import com.android.internal.graphics.palette.Quantizer;
import com.android.internal.graphics.palette.VariationalKMeansQuantizer;
import com.android.launcher3.icons.BaseIconFactory;
import com.android.launcher3.icons.IconProvider;
import com.android.wm.shell.common.TransactionPool;

@@ -368,8 +370,14 @@ public class SplashscreenContentDrawer {
                    if (DEBUG) {
                        Slog.d(TAG, "The icon is not an AdaptiveIconDrawable");
                    }
                    // TODO process legacy icon(bitmap)
                    createIconDrawable(iconDrawable, true);
                    Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "legacy_icon_factory");
                    final ShapeIconFactory factory = new ShapeIconFactory(
                            SplashscreenContentDrawer.this.mContext,
                            scaledIconDpi, mFinalIconSize);
                    final Bitmap bitmap = factory.createScaledBitmapWithoutShadow(
                            iconDrawable, true /* shrinkNonAdaptiveIcons */);
                    Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
                    createIconDrawable(new BitmapDrawable(bitmap), true);
                }
                animationDuration = 0;
            }
@@ -377,11 +385,15 @@ public class SplashscreenContentDrawer {
            return fillViewWithIcon(mFinalIconSize, mFinalIconDrawable, animationDuration);
        }

        private class ShapeIconFactory extends BaseIconFactory {
            protected ShapeIconFactory(Context context, int fillResIconDpi, int iconBitmapSize) {
                super(context, fillResIconDpi, iconBitmapSize, true /* shapeDetection */);
            }
        }

        private void createIconDrawable(Drawable iconDrawable, boolean legacy) {
            if (legacy) {
                mFinalIconDrawable = SplashscreenIconDrawableFactory.makeLegacyIconDrawable(
                        mTmpAttrs.mIconBgColor != Color.TRANSPARENT
                                ? mTmpAttrs.mIconBgColor : Color.WHITE,
                        iconDrawable, mDefaultIconSize, mFinalIconSize, mSplashscreenWorkerHandler);
            } else {
                mFinalIconDrawable = SplashscreenIconDrawableFactory.makeIconDrawable(
+4 −64
Original line number Diff line number Diff line
@@ -64,11 +64,10 @@ public class SplashscreenIconDrawableFactory {
        }
    }

    static Drawable makeLegacyIconDrawable(@ColorInt int backgroundColor,
            @NonNull Drawable foregroundDrawable, int srcIconSize, int iconSize,
            Handler splashscreenWorkerHandler) {
        return new ImmobileIconDrawable(new LegacyIconDrawable(backgroundColor,
                foregroundDrawable), srcIconSize, iconSize, splashscreenWorkerHandler);
    static Drawable makeLegacyIconDrawable(@NonNull Drawable iconDrawable, int srcIconSize,
            int iconSize, Handler splashscreenWorkerHandler) {
        return new ImmobileIconDrawable(iconDrawable, srcIconSize, iconSize,
                splashscreenWorkerHandler);
    }

    private static class ImmobileIconDrawable extends Drawable {
@@ -179,65 +178,6 @@ public class SplashscreenIconDrawableFactory {
        }
    }

    private static class LegacyIconDrawable extends MaskBackgroundDrawable {
        // reference FixedScaleDrawable
        // iconBounds = 0.7 * X * outerBounds, X is the scale of diagonal
        private static final float LEGACY_ICON_SCALE = .7f * .8f;
        private final Drawable mForegroundDrawable;
        private float mScaleX, mScaleY, mTransX, mTransY;

        LegacyIconDrawable(@ColorInt int backgroundColor, Drawable foregroundDrawable) {
            super(backgroundColor);
            mForegroundDrawable = foregroundDrawable;
            mScaleX = LEGACY_ICON_SCALE;
            mScaleY = LEGACY_ICON_SCALE;
        }

        @Override
        protected void updateLayerBounds(Rect bounds) {
            super.updateLayerBounds(bounds);

            if (mForegroundDrawable == null) {
                return;
            }
            float outerBoundsWidth = bounds.width();
            float outerBoundsHeight = bounds.height();
            float h = mForegroundDrawable.getIntrinsicHeight();
            float w = mForegroundDrawable.getIntrinsicWidth();
            mScaleX = LEGACY_ICON_SCALE;
            mScaleY = LEGACY_ICON_SCALE;
            if (h > w && w > 0) {
                mScaleX *= w / h;
            } else if (w > h && h > 0) {
                mScaleY *= h / w;
            }
            int innerBoundsWidth = (int) (0.5 + outerBoundsWidth * mScaleX);
            int innerBoundsHeight = (int) (0.5 + outerBoundsHeight * mScaleY);
            final Rect rect = new Rect(0, 0, innerBoundsWidth, innerBoundsHeight);
            mForegroundDrawable.setBounds(rect);
            mTransX = (outerBoundsWidth - innerBoundsWidth) / 2;
            mTransY = (outerBoundsHeight - innerBoundsHeight) / 2;
            invalidateSelf();
        }

        @Override
        public void draw(Canvas canvas) {
            super.draw(canvas);
            int saveCount = canvas.save();
            canvas.translate(mTransX, mTransY);
            if (mForegroundDrawable != null) {
                mForegroundDrawable.draw(canvas);
            }
            canvas.restoreToCount(saveCount);
        }

        @Override
        public void setColorFilter(ColorFilter colorFilter) {
            if (mForegroundDrawable != null) {
                mForegroundDrawable.setColorFilter(colorFilter);
            }
        }
    }
    /**
     * A lightweight AdaptiveIconDrawable which support foreground to be Animatable, and keep this
     * drawable masked by config_icon_mask.