Skip to content

Commit bbb2dbe

Browse files
committed
[LinearProgressIndicator] Fix stop indicator size when changing track thickness
1 parent 6f41625 commit bbb2dbe

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ void drawStopIndicator(
373373
@IntRange(from = 0, to = 255) int drawableAlpha) {
374374
int paintColor = MaterialColors.compositeARGBWithAlpha(color, drawableAlpha);
375375
drawingDeterminateIndicator = false;
376-
if (spec.trackStopIndicatorSize > 0 && paintColor != Color.TRANSPARENT) {
376+
int trackStopIndicatorSize = spec.getActualTrackStopIndicatorSize();
377+
if (trackStopIndicatorSize > 0 && paintColor != Color.TRANSPARENT) {
377378
// Draws the stop indicator at the end of the track if needed.
378379
paint.setStyle(Style.FILL);
379380
paint.setColor(paintColor);
@@ -382,9 +383,9 @@ void drawStopIndicator(
382383
paint,
383384
new PathPoint(
384385
new float[] {trackLength / 2 - displayedTrackThickness / 2, 0}, new float[] {1, 0}),
385-
spec.trackStopIndicatorSize,
386-
spec.trackStopIndicatorSize,
387-
displayedCornerRadius * spec.trackStopIndicatorSize / displayedTrackThickness);
386+
trackStopIndicatorSize,
387+
trackStopIndicatorSize,
388+
displayedCornerRadius * trackStopIndicatorSize / displayedTrackThickness);
388389
}
389390
}
390391

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public int getTrackStopIndicatorSize() {
243243
*/
244244
public void setTrackStopIndicatorSize(@Px int trackStopIndicatorSize) {
245245
if (spec.trackStopIndicatorSize != trackStopIndicatorSize) {
246-
spec.trackStopIndicatorSize = min(trackStopIndicatorSize, spec.trackThickness);
246+
spec.trackStopIndicatorSize = trackStopIndicatorSize;
247247
spec.validateSpec();
248248
invalidate();
249249
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public final class LinearProgressIndicatorSpec extends BaseProgressIndicatorSpec
4848

4949
boolean drawHorizontallyInverse;
5050

51-
/** The size of the stop indicator at the end of the track. */
51+
/** The desired size of the stop indicator at the end of the track. */
5252
@Px public int trackStopIndicatorSize;
5353

5454
@Px public int trackInnerCornerRadius;
@@ -99,9 +99,7 @@ public LinearProgressIndicatorSpec(
9999
R.styleable.LinearProgressIndicator_indicatorDirectionLinear,
100100
LinearProgressIndicator.INDICATOR_DIRECTION_LEFT_TO_RIGHT);
101101
trackStopIndicatorSize =
102-
min(
103-
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorSize, 0),
104-
trackThickness);
102+
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorSize, 0);
105103
TypedValue trackInnerCornerRadiusValue =
106104
a.peekValue(R.styleable.LinearProgressIndicator_trackInnerCornerRadius);
107105
if (trackInnerCornerRadiusValue != null) {
@@ -136,6 +134,11 @@ public int getTrackInnerCornerRadiusInPx() {
136134
: trackInnerCornerRadius;
137135
}
138136

137+
@Px
138+
int getActualTrackStopIndicatorSize() {
139+
return min(trackStopIndicatorSize, trackThickness);
140+
}
141+
139142
@Override
140143
public boolean useStrokeCap() {
141144
return super.useStrokeCap() && getTrackInnerCornerRadiusInPx() == getTrackCornerRadiusInPx();

0 commit comments

Comments
 (0)