Skip to content

Commit dadbfa4

Browse files
pubiqqpaulfthomas
authored andcommitted
[LinearProgressIndicator] Fix stop indicator size when changing track thickness
Resolves #4669 - 249bbb3 by pubiqq <[email protected]> PiperOrigin-RevId: 769738304
1 parent f843ab0 commit dadbfa4

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

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

Lines changed: 5 additions & 4 deletions
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);
@@ -386,9 +387,9 @@ void drawStopIndicator(
386387
paint,
387388
new PathPoint(
388389
new float[] {trackLength / 2 - stopIndicatorCenterX, 0}, new float[] {1, 0}),
389-
spec.trackStopIndicatorSize,
390-
spec.trackStopIndicatorSize,
391-
displayedCornerRadius * spec.trackStopIndicatorSize / displayedTrackThickness);
390+
trackStopIndicatorSize,
391+
trackStopIndicatorSize,
392+
displayedCornerRadius * trackStopIndicatorSize / displayedTrackThickness);
392393
}
393394
}
394395

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858
* developer guidance</a> and <a
5959
* href="https://material.io/components/progress-indicators/overview">design guidelines</a>.
6060
*/
61-
public class LinearProgressIndicator
62-
extends BaseProgressIndicator<LinearProgressIndicatorSpec> {
61+
public class LinearProgressIndicator extends BaseProgressIndicator<LinearProgressIndicatorSpec> {
6362
public static final int DEF_STYLE_RES = R.style.Widget_MaterialComponents_LinearProgressIndicator;
6463

6564
/**
@@ -122,11 +121,11 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
122121
int contentHeight = h - (getPaddingTop() + getPaddingBottom());
123122
Drawable drawable = getIndeterminateDrawable();
124123
if (drawable != null) {
125-
drawable.setBounds(/*left=*/ 0, /*top=*/ 0, contentWidth, contentHeight);
124+
drawable.setBounds(/* left= */ 0, /* top= */ 0, contentWidth, contentHeight);
126125
}
127126
drawable = getProgressDrawable();
128127
if (drawable != null) {
129-
drawable.setBounds(/*left=*/ 0, /*top=*/ 0, contentWidth, contentHeight);
128+
drawable.setBounds(/* left= */ 0, /* top= */ 0, contentWidth, contentHeight);
130129
}
131130
}
132131

@@ -244,7 +243,7 @@ public int getTrackStopIndicatorSize() {
244243
*/
245244
public void setTrackStopIndicatorSize(@Px int trackStopIndicatorSize) {
246245
if (spec.trackStopIndicatorSize != trackStopIndicatorSize) {
247-
spec.trackStopIndicatorSize = min(trackStopIndicatorSize, spec.trackThickness);
246+
spec.trackStopIndicatorSize = trackStopIndicatorSize;
248247
spec.validateSpec();
249248
invalidate();
250249
}

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

Lines changed: 7 additions & 4 deletions
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
/** The padding of the stop indicator at the end of the track. */
@@ -102,9 +102,7 @@ public LinearProgressIndicatorSpec(
102102
R.styleable.LinearProgressIndicator_indicatorDirectionLinear,
103103
LinearProgressIndicator.INDICATOR_DIRECTION_LEFT_TO_RIGHT);
104104
trackStopIndicatorSize =
105-
min(
106-
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorSize, 0),
107-
trackThickness);
105+
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorSize, 0);
108106
if (a.hasValue(R.styleable.LinearProgressIndicator_trackStopIndicatorPadding)) {
109107
trackStopIndicatorPadding =
110108
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorPadding, 0);
@@ -143,6 +141,11 @@ public int getTrackInnerCornerRadiusInPx() {
143141
: trackInnerCornerRadius;
144142
}
145143

144+
@Px
145+
int getActualTrackStopIndicatorSize() {
146+
return min(trackStopIndicatorSize, trackThickness);
147+
}
148+
146149
@Override
147150
public boolean useStrokeCap() {
148151
return super.useStrokeCap() && getTrackInnerCornerRadiusInPx() == getTrackCornerRadiusInPx();

0 commit comments

Comments
 (0)