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

Commit cc5126a6 authored by Lyn Han's avatar Lyn Han Committed by Android (Google) Code Review
Browse files

Merge "Re-draw bubble dot after theme change" into qt-r1-bubbles-dev

parents 0d37ba14 0e82a3ef
Loading
Loading
Loading
Loading
+28 −22
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.ImageView;
@@ -33,10 +32,10 @@ import com.android.systemui.R;
 */
public class BadgedImageView extends ImageView {

    private DotRenderer mDotRenderer;
    private Rect mTempBounds = new Rect();
    private Point mTempPoint = new Point();

    private DotRenderer mDotRenderer;
    private DotRenderer.DrawParams mDrawParams;
    private int mIconBitmapSize;
    private int mDotColor;
    private float mDotScale = 0f;
@@ -62,11 +61,7 @@ public class BadgedImageView extends ImageView {
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mIconBitmapSize = getResources().getDimensionPixelSize(R.dimen.bubble_icon_bitmap_size);

        Path iconShapePath = new Path();
        float radius = DEFAULT_PATH_SIZE * 0.5f;
        iconShapePath.addCircle(radius /* x */, radius /* y */, radius, Path.Direction.CW);
        mDotRenderer = new DotRenderer(mIconBitmapSize, iconShapePath, DEFAULT_PATH_SIZE);
        mDrawParams = new DotRenderer.DrawParams();

        TypedArray ta = context.obtainStyledAttributes(
                new int[]{android.R.attr.colorBackgroundFloating});
@@ -76,16 +71,23 @@ public class BadgedImageView extends ImageView {
    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (mShowDot) {
        if (!mShowDot) {
            return;
        }
        getDrawingRect(mTempBounds);
            mTempPoint.set((getWidth() - mIconBitmapSize) / 2, getPaddingTop());
            DotRenderer.DrawParams params = new DotRenderer.DrawParams();
            params.color = mDotColor;
            params.iconBounds = mTempBounds;
            params.leftAlign = mOnLeft;
            params.scale = mDotScale;
            mDotRenderer.draw(canvas, params);

        mDrawParams.color = mDotColor;
        mDrawParams.iconBounds = mTempBounds;
        mDrawParams.leftAlign = mOnLeft;
        mDrawParams.scale = mDotScale;

        if (mDotRenderer == null) {
            Path circlePath = new Path();
            float radius = DEFAULT_PATH_SIZE * 0.5f;
            circlePath.addCircle(radius /* x */, radius /* y */, radius, Path.Direction.CW);
            mDotRenderer = new DotRenderer(mIconBitmapSize, circlePath, DEFAULT_PATH_SIZE);
        }
        mDotRenderer.draw(canvas, mDrawParams);
    }

    /**
@@ -123,6 +125,14 @@ public class BadgedImageView extends ImageView {
        invalidate();
    }

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

    /**
     * How big the dot should be, fraction from 0 to 1.
     */
@@ -130,8 +140,4 @@ public class BadgedImageView extends ImageView {
        mDotScale = fraction;
        invalidate();
    }

    public float getDotScale() {
        return mDotScale;
    }
}
+6 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.app.Notification;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
@@ -223,7 +224,10 @@ public class BubbleView extends FrameLayout {

        Drawable iconDrawable = ic.loadDrawable(mContext);
        if (needsTint) {
            iconDrawable = buildIconWithTint(iconDrawable, n.color);
            AdaptiveIconDrawable adaptiveIconDrawable = buildIconWithTint(iconDrawable, n.color);
            Path iconPath = adaptiveIconDrawable.getIconMask();
            mBadgedImageView.drawDot(iconPath);
            iconDrawable = adaptiveIconDrawable;
        }
        BitmapInfo bitmapInfo = mBubbleIconFactory.createBadgedIconBitmap(iconDrawable,
                null /* user */,
@@ -240,7 +244,7 @@ public class BubbleView extends FrameLayout {
        return mBadgeColor;
    }

    private Drawable buildIconWithTint(Drawable iconDrawable, int backgroundColor) {
    private AdaptiveIconDrawable buildIconWithTint(Drawable iconDrawable, int backgroundColor) {
        iconDrawable = checkTint(iconDrawable, backgroundColor);
        InsetDrawable foreground = new InsetDrawable(iconDrawable, mIconInset);
        ColorDrawable background = new ColorDrawable(backgroundColor);