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

Commit fa6a26e2 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Using constant IconShapeInfo instead of calculating it everytime

Bug: 432290550
Flag: EXEMPT bugfix
Test: Verified manually
Change-Id: I551bf70d187b8e1bb85b23eed60f376215f3a374
parent a27e0f34
Loading
Loading
Loading
Loading
+16 −38
Original line number Diff line number Diff line
@@ -24,11 +24,10 @@ import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Outline;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.PathParser;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewOutlineProvider;
@@ -37,6 +36,7 @@ import android.widget.ImageView;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.android.launcher3.icons.DotRenderer;
import com.android.launcher3.icons.DotRenderer.IconShapeInfo;
import com.android.wm.shell.R;
import com.android.wm.shell.shared.animation.Interpolators;

@@ -53,8 +53,6 @@ public class BadgedImageView extends ConstraintLayout {

    /** Same value as Launcher3 dot code */
    public static final float WHITE_SCRIM_ALPHA = 0.54f;
    /** Same as value in Launcher3 IconShape */
    public static final int DEFAULT_PATH_SIZE = 100;

    /**
     * Flags that suppress the visibility of the 'new' dot, for one reason or another. If any of
@@ -84,12 +82,11 @@ public class BadgedImageView extends ConstraintLayout {
    private BubbleViewProvider mBubble;
    private BubblePositioner mPositioner;
    private boolean mBadgeOnLeft;
    private boolean mDotOnLeft;
    private DotRenderer mDotRenderer;
    private DotRenderer.DrawParams mDrawParams;
    private final DotRenderer.DrawParams mDrawParams;
    private int mDotColor;

    private Rect mTempBounds = new Rect();
    private final Rect mTempBounds = new Rect();

    public BadgedImageView(Context context) {
        this(context, null);
@@ -120,6 +117,7 @@ public class BadgedImageView extends ConstraintLayout {
        ta.recycle();

        mDrawParams = new DotRenderer.DrawParams();
        mDrawParams.shapeInfo = IconShapeInfo.DEFAULT_NORMALIZED;

        setFocusable(true);
        setClickable(true);
@@ -140,11 +138,7 @@ public class BadgedImageView extends ConstraintLayout {

    public void initialize(BubblePositioner positioner) {
        mPositioner = positioner;

        Path iconPath = PathParser.createPathFromPathData(
                getResources().getString(com.android.internal.R.string.config_icon_mask));
        mDotRenderer = new DotRenderer(mPositioner.getBubbleSize(),
                iconPath, DEFAULT_PATH_SIZE);
        mDotRenderer = new DotRenderer(mPositioner.getBubbleSize());
    }

    public void showDotAndBadge(boolean onLeft) {
@@ -155,7 +149,7 @@ public class BadgedImageView extends ConstraintLayout {
    public void hideDotAndBadge(boolean onLeft) {
        addDotSuppressionFlag(BadgedImageView.SuppressionFlag.BEHIND_STACK);
        mBadgeOnLeft = onLeft;
        mDotOnLeft = onLeft;
        mDrawParams.leftAlign = onLeft;
        hideBadge();
    }

@@ -172,7 +166,8 @@ public class BadgedImageView extends ConstraintLayout {
            showBadge();
        }
        mDotColor = bubble.getDotColor();
        drawDot(bubble.getDotPath());
        mDrawParams.setDotColor(mDotColor);
        invalidate();
    }

    @Override
@@ -184,10 +179,7 @@ public class BadgedImageView extends ConstraintLayout {
        }

        getDrawingRect(mTempBounds);

        mDrawParams.dotColor = mDotColor;
        mDrawParams.iconBounds = mTempBounds;
        mDrawParams.leftAlign = mDotOnLeft;
        mDrawParams.scale = mDotScale;

        mDotRenderer.draw(canvas, mDrawParams);
@@ -236,15 +228,6 @@ public class BadgedImageView extends ConstraintLayout {
        }
    }

    /**
     * @param iconPath The new icon path to use when calculating dot position.
     */
    void drawDot(Path iconPath) {
        mDotRenderer = new DotRenderer(mPositioner.getBubbleSize(),
                iconPath, DEFAULT_PATH_SIZE);
        invalidate();
    }

    /**
     * How big the dot should be, fraction from 0 to 1.
     */
@@ -257,22 +240,17 @@ public class BadgedImageView extends ConstraintLayout {
     * Whether decorations (badges or dots) are on the left.
     */
    boolean getDotOnLeft() {
        return mDotOnLeft;
        return mDrawParams.leftAlign;
    }

    /**
     * Return dot position relative to bubble view container bounds.
     */
    float[] getDotCenter() {
        float[] dotPosition;
        if (mDotOnLeft) {
            dotPosition = mDotRenderer.getLeftDotPosition();
        } else {
            dotPosition = mDotRenderer.getRightDotPosition();
        }
        PointF dotPosition = mDrawParams.getDotPosition();
        getDrawingRect(mTempBounds);
        float dotCenterX = mTempBounds.width() * dotPosition[0];
        float dotCenterY = mTempBounds.height() * dotPosition[1];
        float dotCenterX = mTempBounds.width() * dotPosition.x;
        float dotCenterY = mTempBounds.height() * dotPosition.y;
        return new float[]{dotCenterX, dotCenterY};
    }

@@ -293,12 +271,12 @@ public class BadgedImageView extends ConstraintLayout {
        if (onLeft != getDotOnLeft()) {
            if (shouldDrawDot()) {
                animateDotScale(0f /* showDot */, () -> {
                    mDotOnLeft = onLeft;
                    mDrawParams.leftAlign = onLeft;
                    invalidate();
                    animateDotScale(1.0f, null /* after */);
                });
            } else {
                mDotOnLeft = onLeft;
                mDrawParams.leftAlign = onLeft;
            }
        }
        mBadgeOnLeft = onLeft;
@@ -309,7 +287,7 @@ public class BadgedImageView extends ConstraintLayout {
    /** Sets the position of the dot and badge. */
    void setDotBadgeOnLeft(boolean onLeft) {
        mBadgeOnLeft = onLeft;
        mDotOnLeft = onLeft;
        mDrawParams.leftAlign = onLeft;
        invalidate();
        showBadge();
    }
+0 −6
Original line number Diff line number Diff line
@@ -557,11 +557,6 @@ public class Bubble implements BubbleViewProvider {
        return mDotColor;
    }

    @Override
    public Path getDotPath() {
        return mDotPath;
    }

    @Nullable
    public String getAppName() {
        return mAppName;
@@ -808,7 +803,6 @@ public class Bubble implements BubbleViewProvider {
        mBubbleBitmap = info.bubbleBitmap;

        mDotColor = info.dotColor;
        mDotPath = info.dotPath;

        if (mExpandedView != null) {
            mExpandedView.update(this /* bubble */);
+1 −24
Original line number Diff line number Diff line
@@ -19,12 +19,9 @@ package com.android.wm.shell.bubbles
import android.app.ActivityTaskManager.INVALID_TASK_ID
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Matrix
import android.graphics.Path
import android.graphics.drawable.AdaptiveIconDrawable
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.InsetDrawable
import android.util.PathParser
import android.view.LayoutInflater
import android.view.View.VISIBLE
import android.widget.FrameLayout
@@ -37,7 +34,6 @@ class BubbleOverflow(private val context: Context, private val positioner: Bubbl
    BubbleViewProvider {

    private lateinit var bitmap: Bitmap
    private lateinit var dotPath: Path

    private var dotColor = 0
    private var showDot = false
@@ -133,24 +129,7 @@ class BubbleOverflow(private val context: Context, private val positioner: Bubbl
        // Update bitmap
        val fg = InsetDrawable(overflowBtn?.iconDrawable, overflowIconInset)
        val drawable = AdaptiveIconDrawable(ColorDrawable(colorAccent), fg)
        val bubbleBitmapScale = FloatArray(1)
        bitmap = iconFactory.getBubbleBitmap(drawable, bubbleBitmapScale)

        // Update dot path
        dotPath =
            PathParser.createPathFromPathData(
                res.getString(com.android.internal.R.string.config_icon_mask)
            )
        val scale = bubbleBitmapScale[0]
        val radius = BadgedImageView.DEFAULT_PATH_SIZE / 2f
        val matrix = Matrix()
        matrix.setScale(
            scale /* x scale */,
            scale /* y scale */,
            radius /* pivot x */,
            radius /* pivot y */
        )
        dotPath.transform(matrix)
        bitmap = iconFactory.getBubbleBitmap(drawable)

        // Attach BubbleOverflow to BadgedImageView
        overflowBtn?.setRenderedBubble(this)
@@ -211,8 +190,6 @@ class BubbleOverflow(private val context: Context, private val positioner: Bubbl

    override fun showDot() = showDot

    override fun getDotPath() = dotPath

    override fun setTaskViewVisibility(visible: Boolean) {
        // Overflow does not have a TaskView.
    }
+2 −18
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.wm.shell.bubbles;

import static com.android.wm.shell.bubbles.BadgedImageView.DEFAULT_PATH_SIZE;
import static com.android.wm.shell.bubbles.BadgedImageView.WHITE_SCRIM_ALPHA;
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_BUBBLES;
import static com.android.wm.shell.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME;
@@ -28,11 +27,8 @@ import android.content.Context;
import android.content.pm.ShortcutInfo;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.PathParser;
import android.view.LayoutInflater;

import com.android.internal.annotations.VisibleForTesting;
@@ -263,7 +259,6 @@ public class BubbleViewInfoTask {
        @Nullable BadgedImageView imageView;
        @Nullable BubbleExpandedView expandedView;
        int dotColor;
        Path dotPath;
        Bubble.FlyoutMessage flyoutMessage;
        Bitmap bubbleBitmap;
        Bitmap badgeBitmap;
@@ -385,19 +380,8 @@ public class BubbleViewInfoTask {
                ? iconFactory.getBadgeBitmap(badgedIcon, false).icon
                : badgeBitmapInfo.icon;

        float[] bubbleBitmapScale = new float[1];
        info.bubbleBitmap = iconFactory.getBubbleBitmap(bubbleDrawable, bubbleBitmapScale);

        // Dot color & placement
        Path iconPath = PathParser.createPathFromPathData(
                c.getResources().getString(com.android.internal.R.string.config_icon_mask));
        Matrix matrix = new Matrix();
        float scale = bubbleBitmapScale[0];
        float radius = DEFAULT_PATH_SIZE / 2f;
        matrix.setScale(scale /* x scale */, scale /* y scale */, radius /* pivot x */,
                radius /* pivot y */);
        iconPath.transform(matrix);
        info.dotPath = iconPath;
        info.bubbleBitmap = iconFactory.getBubbleBitmap(bubbleDrawable);

        info.dotColor = ColorUtils.blendARGB(badgeBitmapInfo.color,
                Color.WHITE, WHITE_SCRIM_ALPHA);
        return true;
+0 −4
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.wm.shell.bubbles;

import android.graphics.Bitmap;
import android.graphics.Path;
import android.view.View;

import androidx.annotation.Nullable;
@@ -68,9 +67,6 @@ public interface BubbleViewProvider {
    /** Base app badge drawable without any markings. */
    @Nullable Bitmap getRawAppBadge();

    /** Path of normalized bubble icon to draw dot on. */
    Path getDotPath();

    int getDotColor();

    boolean showDot();
Loading