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

Commit 0207df87 authored by Jon Miranda's avatar Jon Miranda
Browse files

Revert "Remove shadows from launcher icons."

Make ShadowGenerator a no-op class instead.

This reverts commit 2fcecf5b.

Test: manual, verify no shadows on icons
Bug: 175329686
Change-Id: I4832224f81037f7d3ea00a00fd6ce31ab88a8845
parent d324a449
Loading
Loading
Loading
Loading
+4 −25
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ public class BaseIconFactory implements AutoCloseable {

    /**
     * Creates bitmap using the source drawable and various parameters.
     * The bitmap is visually normalized with other icons.
     * The bitmap is visually normalized with other icons and has enough spacing to add shadow.
     *
     * @param icon                      source of the icon
     * @param user                      info can be used for a badge
@@ -211,37 +211,16 @@ public class BaseIconFactory implements AutoCloseable {
     */
    public BitmapInfo createBadgedIconBitmap(@NonNull Drawable icon, UserHandle user,
            boolean shrinkNonAdaptiveIcons, boolean isInstantApp, float[] scale) {
        return createBadgedIconBitmap(icon, user, shrinkNonAdaptiveIcons, isInstantApp, scale,
                false /* addShadow */);
    }

    /**
     * Creates bitmap using the source drawable and various parameters.
     * The bitmap is visually normalized with other icons and has enough spacing to add shadow.
     *
     * @param icon                      source of the icon
     * @param user                      info can be used for a badge
     * @param shrinkNonAdaptiveIcons    {@code true} if non adaptive icons should be treated
     * @param isInstantApp              info can be used for a badge
     * @param scale                     returns the scale result from normalization
     * @param addShadow                 If true, adds a shadow under the icon.
     * @return a bitmap suitable for disaplaying as an icon at various system UIs.
     */
    private BitmapInfo createBadgedIconBitmap(@NonNull Drawable icon, UserHandle user,
            boolean shrinkNonAdaptiveIcons, boolean isInstantApp, float[] scale,
            boolean addShadow) {
        if (scale == null) {
            scale = new float[1];
        }
        icon = normalizeAndWrapToAdaptiveIcon(icon, shrinkNonAdaptiveIcons, null, scale);
        Bitmap bitmap = createIconBitmap(icon, scale[0]);
        if (ATLEAST_OREO && icon instanceof AdaptiveIconDrawable) {
            if (addShadow) {
            mCanvas.setBitmap(bitmap);
            getShadowGenerator().recreateIcon(Bitmap.createBitmap(bitmap), mCanvas);
            mCanvas.setBitmap(null);
        }
        }

        if (isInstantApp) {
            badgeWithDrawable(bitmap, mContext.getDrawable(R.drawable.ic_instant_app_badge));
+45 −29
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ import android.graphics.RectF;
 * Utility class to add shadows to bitmaps.
 */
public class ShadowGenerator {

    public static final boolean ENABLE_SHADOWS = false;

    public static final float BLUR_FACTOR = 0.5f/48;

    // Percent of actual icon size
@@ -60,6 +63,7 @@ public class ShadowGenerator {

    public synchronized void recreateIcon(Bitmap icon, BlurMaskFilter blurMaskFilter,
            int ambientAlpha, int keyAlpha, Canvas out) {
        if (ENABLE_SHADOWS) {
            int[] offset = new int[2];
            mBlurPaint.setMaskFilter(blurMaskFilter);
            Bitmap shadow = icon.extractAlpha(mBlurPaint, offset);
@@ -70,7 +74,9 @@ public class ShadowGenerator {

            // Draw key shadow
            mDrawPaint.setAlpha(keyAlpha);
        out.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize, mDrawPaint);
            out.drawBitmap(shadow, offset[0], offset[1] + KEY_SHADOW_DISTANCE * mIconSize,
                    mDrawPaint);
        }

        // Draw the icon
        mDrawPaint.setAlpha(255);
@@ -84,6 +90,7 @@ public class ShadowGenerator {
    public static float getScaleForBounds(RectF bounds) {
        float scale = 1;

        if (ENABLE_SHADOWS) {
            // For top, left & right, we need same space.
            float minSide = Math.min(Math.min(bounds.left, bounds.right), bounds.top);
            if (minSide < BLUR_FACTOR) {
@@ -92,7 +99,9 @@ public class ShadowGenerator {

            float bottomSpace = BLUR_FACTOR + KEY_SHADOW_DISTANCE;
            if (bounds.bottom < bottomSpace) {
            scale = Math.min(scale, (HALF_DISTANCE - bottomSpace) / (HALF_DISTANCE - bounds.bottom));
                scale = Math.min(scale,
                        (HALF_DISTANCE - bottomSpace) / (HALF_DISTANCE - bounds.bottom));
            }
        }
        return scale;
    }
@@ -115,8 +124,13 @@ public class ShadowGenerator {
        }

        public Builder setupBlurForSize(int height) {
            if (ENABLE_SHADOWS) {
                shadowBlur = height * 1f / 24;
                keyShadowDistance = height * 1f / 16;
            } else {
                shadowBlur = 0;
                keyShadowDistance = 0;
            }
            return this;
        }

@@ -141,6 +155,7 @@ public class ShadowGenerator {
            Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
            p.setColor(color);

            if (ENABLE_SHADOWS) {
                // Key shadow
                p.setShadowLayer(shadowBlur, 0, keyShadowDistance,
                        setColorAlphaBound(Color.BLACK, keyShadowAlpha));
@@ -150,6 +165,7 @@ public class ShadowGenerator {
                p.setShadowLayer(shadowBlur, 0, 0,
                        setColorAlphaBound(Color.BLACK, ambientShadowAlpha));
                c.drawRoundRect(bounds, radius, radius, p);
            }

            if (Color.alpha(color) < 255) {
                // Clear any content inside the pill-rect for translucent fill.
+1 −1
Original line number Diff line number Diff line
@@ -510,7 +510,7 @@ public abstract class BaseIconCache {
     * Cache class to store the actual entries on disk
     */
    public static final class IconDB extends SQLiteCacheHelper {
        private static final int RELEASE_VERSION = 28;
        private static final int RELEASE_VERSION = 29;

        public static final String TABLE_NAME = "icons";
        public static final String COLUMN_ROWID = "rowid";