Skip to content

[LinearProgressIndicator] Fix stop indicator size when changing track thickness #4669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ void drawStopIndicator(
@IntRange(from = 0, to = 255) int drawableAlpha) {
int paintColor = MaterialColors.compositeARGBWithAlpha(color, drawableAlpha);
drawingDeterminateIndicator = false;
if (spec.trackStopIndicatorSize > 0 && paintColor != Color.TRANSPARENT) {
int trackStopIndicatorSize = spec.getActualTrackStopIndicatorSize();
if (trackStopIndicatorSize > 0 && paintColor != Color.TRANSPARENT) {
// Draws the stop indicator at the end of the track if needed.
paint.setStyle(Style.FILL);
paint.setColor(paintColor);
Expand All @@ -386,9 +387,9 @@ void drawStopIndicator(
paint,
new PathPoint(
new float[] {trackLength / 2 - stopIndicatorCenterX, 0}, new float[] {1, 0}),
spec.trackStopIndicatorSize,
spec.trackStopIndicatorSize,
displayedCornerRadius * spec.trackStopIndicatorSize / displayedTrackThickness);
trackStopIndicatorSize,
trackStopIndicatorSize,
displayedCornerRadius * trackStopIndicatorSize / displayedTrackThickness);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public int getTrackStopIndicatorSize() {
*/
public void setTrackStopIndicatorSize(@Px int trackStopIndicatorSize) {
if (spec.trackStopIndicatorSize != trackStopIndicatorSize) {
spec.trackStopIndicatorSize = min(trackStopIndicatorSize, spec.trackThickness);
spec.trackStopIndicatorSize = trackStopIndicatorSize;
spec.validateSpec();
invalidate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class LinearProgressIndicatorSpec extends BaseProgressIndicatorSpec

boolean drawHorizontallyInverse;

/** The size of the stop indicator at the end of the track. */
/** The desired size of the stop indicator at the end of the track. */
@Px public int trackStopIndicatorSize;

/** The padding of the stop indicator at the end of the track. */
Expand Down Expand Up @@ -102,9 +102,7 @@ public LinearProgressIndicatorSpec(
R.styleable.LinearProgressIndicator_indicatorDirectionLinear,
LinearProgressIndicator.INDICATOR_DIRECTION_LEFT_TO_RIGHT);
trackStopIndicatorSize =
min(
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorSize, 0),
trackThickness);
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorSize, 0);
if (a.hasValue(R.styleable.LinearProgressIndicator_trackStopIndicatorPadding)) {
trackStopIndicatorPadding =
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorPadding, 0);
Expand Down Expand Up @@ -143,6 +141,11 @@ public int getTrackInnerCornerRadiusInPx() {
: trackInnerCornerRadius;
}

@Px
int getActualTrackStopIndicatorSize() {
return min(trackStopIndicatorSize, trackThickness);
}

@Override
public boolean useStrokeCap() {
return super.useStrokeCap() && getTrackInnerCornerRadiusInPx() == getTrackCornerRadiusInPx();
Expand Down