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

Commit f9680506 authored by Xiaowen Lei's avatar Xiaowen Lei Committed by Android (Google) Code Review
Browse files

Merge "Draw end dot above the last future segment." into main

parents 59c2ef21 5e397e8a
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -555,6 +555,18 @@ public final class NotificationProgressBar extends ProgressBar implements
        mNotificationProgressDrawable.setParts(p.first);
        mAdjustedProgressFraction =
                (p.second - mTrackerDrawWidth / 2F) / (width - mTrackerDrawWidth);

        mNotificationProgressDrawable.updateEndDotColor(getEndDotColor(fallbackSegments));
    }

    private int getEndDotColor(List<ProgressStyle.Segment> fallbackSegments) {
        if (!mProgressModel.isStyledByProgress()) return Color.TRANSPARENT;
        if (mProgressModel.getProgress() == mProgressModel.getProgressMax()) {
            return Color.TRANSPARENT;
        }

        return fallbackSegments == null ? mProgressModel.getSegments().getLast().getColor()
                : fallbackSegments.getLast().getColor();
    }

    private void updateTrackerAndBarPos(int w, int h) {
+25 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
@@ -74,6 +75,8 @@ public final class NotificationProgressDrawable extends Drawable {
        mFillPaint.setStyle(Paint.Style.FILL);
    }

    private @ColorInt int mEndDotColor = Color.TRANSPARENT;

    private int mAlpha;

    public NotificationProgressDrawable() {
@@ -125,6 +128,16 @@ public final class NotificationProgressDrawable extends Drawable {
        setParts(Arrays.asList(parts));
    }

    /**
     * Update the color of the end dot. If TRANSPARENT, the dot is not drawn.
     */
    public void updateEndDotColor(@ColorInt int endDotColor) {
        if (mEndDotColor != endDotColor) {
            mEndDotColor = endDotColor;
            invalidateSelf();
        }
    }

    @Override
    public void draw(@NonNull Canvas canvas) {
        final float pointRadius = mState.mPointRadius;
@@ -164,6 +177,18 @@ public final class NotificationProgressDrawable extends Drawable {
                canvas.drawRoundRect(mPointRectF, cornerRadius, cornerRadius, mFillPaint);
            }
        }

        if (mEndDotColor != Color.TRANSPARENT) {
            final float right = (float) getBounds().right;
            final float dotRadius = mState.mFadedSegmentHeight / 2F;
            mFillPaint.setColor(mEndDotColor);
            // Use drawRoundRect instead of drawCircle to ensure alignment with the segment below.
            mSegRectF.set(
                    Math.round(right - mState.mFadedSegmentHeight), Math.round(centerY - dotRadius),
                            Math.round(right), Math.round(centerY + dotRadius));
            canvas.drawRoundRect(mSegRectF, mState.mSegmentCornerRadius,
                    mState.mSegmentCornerRadius, mFillPaint);
        }
    }

    @Override