summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Xiaowen Lei <xilei@google.com> 2024-11-07 23:34:23 +0000
committer Xiaowen Lei <xilei@google.com> 2024-11-07 23:52:29 +0000
commita118f93679b97f494ea99b6536ed9a9c17d64e5c (patch)
tree7ea86e32925632465373c25a5c9d82dd5c5e6557
parent9839809ab22f26fd868e4edadbb1a974938eb41c (diff)
Handle the cases where the segment isn't long enough.
1. When the segment has a negative length (after subtracting gaps and caps). 2. When the segment isn't long enough for drawing the caps (after subtracting gaps). Also fixed: 1. For dashed segments, there is no caps. Therefore we should draw from `start` to `end`, rather than from `start + capWidth` to `end - capWidth`. 2. Set `mPointRectF` directly from values rather than from `mPointRect`. Flag: android.app.api_rich_ongoing Fix: 376491336 Bug: 376488208 Bug: 376487227 Bug: 376492598 Test: Post ProgressStyle notifs (as defined in the bugs) and observe the notification. Change-Id: I6a0a45db4b136e024f41ee5a99e2eb8d27d43799
-rw-r--r--core/java/com/android/internal/widget/NotificationProgressDrawable.java49
1 files changed, 35 insertions, 14 deletions
diff --git a/core/java/com/android/internal/widget/NotificationProgressDrawable.java b/core/java/com/android/internal/widget/NotificationProgressDrawable.java
index 30deb499594c..fb6937c94a3e 100644
--- a/core/java/com/android/internal/widget/NotificationProgressDrawable.java
+++ b/core/java/com/android/internal/widget/NotificationProgressDrawable.java
@@ -63,6 +63,7 @@ public final class NotificationProgressDrawable extends Drawable {
private final ArrayList<Part> mParts = new ArrayList<>();
+ private final RectF mSegRectF = new RectF();
private final Rect mPointRect = new Rect();
private final RectF mPointRectF = new RectF();
@@ -198,22 +199,42 @@ public final class NotificationProgressDrawable extends Drawable {
mState.mSegSegGap, x + segWidth, totalWidth);
final float end = x + segWidth - endOffset;
- // Transparent is not allowed (and also is the default in the data), so use that
- // as a sentinel to be replaced by default
- mStrokePaint.setColor(segment.mColor != Color.TRANSPARENT ? segment.mColor
- : mState.mStrokeColor);
- mDashedStrokePaint.setColor(segment.mColor != Color.TRANSPARENT ? segment.mColor
- : mState.mFadedStrokeColor);
-
- // Leave space for the rounded line cap which extends beyond start/end.
- final float capWidth = mStrokePaint.getStrokeWidth() / 2F;
-
- canvas.drawLine(start + capWidth, centerY, end - capWidth, centerY,
- segment.mDashed ? mDashedStrokePaint : mStrokePaint);
-
// Advance the current position to account for the segment's fraction of the total
// width (ignoring offset and padding)
x += segWidth;
+
+ // No space left to draw the segment
+ if (start > end) continue;
+
+ if (segment.mDashed) {
+ // No caps when the segment is dashed.
+
+ mDashedStrokePaint.setColor(segment.mColor != Color.TRANSPARENT ? segment.mColor
+ : mState.mFadedStrokeColor);
+ canvas.drawLine(start, centerY, end, centerY, mDashedStrokePaint);
+ } else if (end - start < mState.mStrokeWidth) {
+ // Not enough segment length to draw the caps
+
+ final float rad = (end - start) / 2F;
+ final float capWidth = mStrokePaint.getStrokeWidth() / 2F;
+
+ mFillPaint.setColor(segment.mColor != Color.TRANSPARENT ? segment.mColor
+ : mState.mStrokeColor);
+
+ mSegRectF.set(start, centerY - capWidth, end, centerY + capWidth);
+ canvas.drawRoundRect(mSegRectF, rad, rad, mFillPaint);
+ } else {
+ // Leave space for the rounded line cap which extends beyond start/end.
+ final float capWidth = mStrokePaint.getStrokeWidth() / 2F;
+
+ // Transparent is not allowed (and also is the default in the data), so use that
+ // as a sentinel to be replaced by default
+ mStrokePaint.setColor(segment.mColor != Color.TRANSPARENT ? segment.mColor
+ : mState.mStrokeColor);
+
+ canvas.drawLine(start + capWidth, centerY, end - capWidth, centerY,
+ mStrokePaint);
+ }
} else if (part instanceof Point point) {
final float pointWidth = 2 * pointRadius;
float start = x - pointRadius;
@@ -232,7 +253,7 @@ public final class NotificationProgressDrawable extends Drawable {
} else {
// TODO: b/367804171 - actually use a vector asset for the default point
// rather than drawing it as a box?
- mPointRectF.set(mPointRect);
+ mPointRectF.set(start, centerY - pointRadius, end, centerY + pointRadius);
final float inset = mState.mPointRectInset;
final float cornerRadius = mState.mPointRectCornerRadius;
mPointRectF.inset(inset, inset);