Skip to content

Commit a55f3b8

Browse files
pekingmedsn5ft
authored andcommitted
[LinearProgressIndicator] Fixed the transparent strip drawn at the ends of the indicator.
Resolves #1947 PiperOrigin-RevId: 388966812
1 parent 456abd5 commit a55f3b8

File tree

1 file changed

+15
-90
lines changed

1 file changed

+15
-90
lines changed

lib/java/com/google/android/material/progressindicator/LinearDrawingDelegate.java

Lines changed: 15 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -122,49 +122,25 @@ public void fillIndicator(
122122

123123
// Horizontal position of the start adjusted based on the rounded corner radius.
124124
float adjustedStartX =
125-
-trackLength / 2
126-
+ displayedCornerRadius
127-
+ startFraction * (trackLength - 2 * displayedCornerRadius);
125+
-trackLength / 2 + startFraction * (trackLength - 2 * displayedCornerRadius);
128126
// Horizontal position of the end adjusted based on the rounded corner radius.
129127
float adjustedEndX =
130128
-trackLength / 2
131-
+ displayedCornerRadius
132-
+ endFraction * (trackLength - 2 * displayedCornerRadius);
129+
+ endFraction * (trackLength - 2 * displayedCornerRadius)
130+
+ 2 * displayedCornerRadius;
133131

134132
// Sets up the paint.
135133
paint.setStyle(Style.FILL);
136134
paint.setAntiAlias(true);
137135
paint.setColor(color);
138136

139-
// Draws the rectangle as the indicator and the rounded corners.
140-
canvas.drawRect(
141-
adjustedStartX,
142-
-displayedTrackThickness / 2,
143-
adjustedEndX,
144-
displayedTrackThickness / 2,
145-
paint);
146-
RectF cornerPatternRectBound =
137+
RectF indicatorBound =
147138
new RectF(
148-
-displayedCornerRadius,
149-
-displayedCornerRadius,
150-
displayedCornerRadius,
151-
displayedCornerRadius);
152-
drawRoundedEnd(
153-
canvas,
154-
paint,
155-
displayedTrackThickness,
156-
displayedCornerRadius,
157-
adjustedStartX,
158-
true,
159-
cornerPatternRectBound);
160-
drawRoundedEnd(
161-
canvas,
162-
paint,
163-
displayedTrackThickness,
164-
displayedCornerRadius,
165-
adjustedEndX,
166-
false,
167-
cornerPatternRectBound);
139+
adjustedStartX,
140+
-displayedTrackThickness / 2,
141+
adjustedEndX,
142+
displayedTrackThickness / 2);
143+
canvas.drawRoundRect(indicatorBound, displayedCornerRadius, displayedCornerRadius, paint);
168144
}
169145

170146
/**
@@ -176,69 +152,18 @@ public void fillIndicator(
176152
@Override
177153
void fillTrack(@NonNull Canvas canvas, @NonNull Paint paint) {
178154
int trackColor = MaterialColors.compositeARGBWithAlpha(spec.trackColor, drawable.getAlpha());
179-
float adjustedStartX = -trackLength / 2 + displayedCornerRadius;
180-
float adjustedEndX = -adjustedStartX;
181155

182156
// Sets up the paint.
183157
paint.setStyle(Style.FILL);
184158
paint.setAntiAlias(true);
185159
paint.setColor(trackColor);
186160

187-
canvas.drawRect(
188-
adjustedStartX,
189-
-displayedTrackThickness / 2,
190-
adjustedEndX,
191-
displayedTrackThickness / 2,
192-
paint);
193-
RectF cornerPatternRectBound =
161+
RectF trackBound =
194162
new RectF(
195-
-displayedCornerRadius,
196-
-displayedCornerRadius,
197-
displayedCornerRadius,
198-
displayedCornerRadius);
199-
drawRoundedEnd(
200-
canvas,
201-
paint,
202-
displayedTrackThickness,
203-
displayedCornerRadius,
204-
adjustedStartX,
205-
true,
206-
cornerPatternRectBound);
207-
drawRoundedEnd(
208-
canvas,
209-
paint,
210-
displayedTrackThickness,
211-
displayedCornerRadius,
212-
adjustedEndX,
213-
false,
214-
cornerPatternRectBound);
215-
}
216-
217-
// The rounded corners are drawn in steps, since drawRoundRect() is only available in Api 21+.
218-
private static void drawRoundedEnd(
219-
Canvas canvas,
220-
Paint paint,
221-
float trackSize,
222-
float cornerRadius,
223-
float x,
224-
boolean isStartPosition,
225-
RectF cornerPatternRectBound) {
226-
canvas.save();
227-
canvas.translate(x, 0);
228-
if (!isStartPosition) {
229-
canvas.rotate(180);
230-
}
231-
// Draws the tiny rectangle between the two corners.
232-
canvas.drawRect(
233-
-cornerRadius, -trackSize / 2 + cornerRadius, 0, trackSize / 2 - cornerRadius, paint);
234-
// Draws the upper corner.
235-
canvas.save();
236-
canvas.translate(0, -trackSize / 2 + cornerRadius);
237-
canvas.drawArc(cornerPatternRectBound, 180, 90, true, paint);
238-
canvas.restore();
239-
// Draws the lower corner.
240-
canvas.translate(0, trackSize / 2 - cornerRadius);
241-
canvas.drawArc(cornerPatternRectBound, 180, -90, true, paint);
242-
canvas.restore();
163+
-trackLength / 2,
164+
-displayedTrackThickness / 2,
165+
trackLength / 2,
166+
displayedTrackThickness / 2);
167+
canvas.drawRoundRect(trackBound, displayedCornerRadius, displayedCornerRadius, paint);
243168
}
244169
}

0 commit comments

Comments
 (0)