Skip to content

Commit 0b89ef4

Browse files
pekingmedsn5ft
authored andcommitted
[ProgressIndicator] Added the customization of setting the stop inidcator padding.
PiperOrigin-RevId: 738518813
1 parent a822f4f commit 0b89ef4

File tree

6 files changed

+47
-1
lines changed

6 files changed

+47
-1
lines changed

docs/components/ProgressIndicator.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ Element | Attribute | Related me
309309
**Indeterminate animation type** | `app:indeterminateAnimationType` | `setIndeterminateAnimationType`<br>`getIndeterminateAnimationType` | `disjoint`
310310
**Indicator direction** | `app:indicatorDirectionLinear` | `setIndicatorDirection`<br>`getIndicatorDirection` | `leftToRight`
311311
**Track stop indicator size** | `app:trackStopIndicatorSize` | `setTrackStopIndicatorSize`<br>`getTrackStopIndicatorSize` | `4dp`
312+
**Track stop indicator padding** | `app:trackStopIndicatorPadding` | `setTrackStopIndicatorPadding`<br>`getTrackStopIndicatorPadding` | `none`
312313
**Track inner corner radius** | `app:trackInnerCornerRadius` | `setTrackInnerCornerRadius`<br>`setTrackInnerCornerRadiusFraction`<br>`getTrackInnerCornerRadius` | `none` (use `trackCornerRadius`)
313314

314315
#### Circular type specific attributes

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,15 @@ void drawStopIndicator(
377377
// Draws the stop indicator at the end of the track if needed.
378378
paint.setStyle(Style.FILL);
379379
paint.setColor(paintColor);
380+
float stopIndicatorCenterX =
381+
spec.trackStopIndicatorPadding != null
382+
? spec.trackStopIndicatorPadding.floatValue() + spec.trackStopIndicatorSize / 2f
383+
: displayedTrackThickness / 2;
380384
drawRoundedBlock(
381385
canvas,
382386
paint,
383387
new PathPoint(
384-
new float[] {trackLength / 2 - displayedTrackThickness / 2, 0}, new float[] {1, 0}),
388+
new float[] {trackLength / 2 - stopIndicatorCenterX, 0}, new float[] {1, 0}),
385389
spec.trackStopIndicatorSize,
386390
spec.trackStopIndicatorSize,
387391
displayedCornerRadius * spec.trackStopIndicatorSize / displayedTrackThickness);

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import androidx.annotation.RestrictTo.Scope;
3434
import java.lang.annotation.Retention;
3535
import java.lang.annotation.RetentionPolicy;
36+
import java.util.Objects;
3637

3738
/**
3839
* This class implements the linear type progress indicators.
@@ -249,6 +250,33 @@ public void setTrackStopIndicatorSize(@Px int trackStopIndicatorSize) {
249250
}
250251
}
251252

253+
/**
254+
* Returns the padding of the stop indicator at the end of the track in pixels.
255+
*
256+
* @see #setTrackStopIndicatorPadding(int)
257+
* @attr ref
258+
* com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_trackStopIndicatorPadding
259+
*/
260+
@Nullable
261+
public Integer getTrackStopIndicatorPadding() {
262+
return spec.trackStopIndicatorPadding;
263+
}
264+
265+
/**
266+
* Sets the padding of the stop indicator at the end of the track in pixels.
267+
*
268+
* @param trackStopIndicatorPadding The new stop indicator padding in pixels.
269+
* @see #getTrackStopIndicatorPadding()
270+
* @attr ref
271+
* com.google.android.material.progressindicator.R.styleable#LinearProgressIndicator_trackStopIndicatorPadding
272+
*/
273+
public void setTrackStopIndicatorPadding(@Nullable Integer trackStopIndicatorPadding) {
274+
if (!Objects.equals(spec.trackStopIndicatorPadding, trackStopIndicatorPadding)) {
275+
spec.trackStopIndicatorPadding = trackStopIndicatorPadding;
276+
invalidate();
277+
}
278+
}
279+
252280
/**
253281
* Returns the type of indeterminate animation of this progress indicator.
254282
*

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public final class LinearProgressIndicatorSpec extends BaseProgressIndicatorSpec
5151
/** The size of the stop indicator at the end of the track. */
5252
@Px public int trackStopIndicatorSize;
5353

54+
/** The padding of the stop indicator at the end of the track. */
55+
@Nullable public Integer trackStopIndicatorPadding;
56+
5457
@Px public int trackInnerCornerRadius;
5558
public float trackInnerCornerRadiusFraction;
5659
public boolean useRelativeTrackInnerCornerRadius;
@@ -102,6 +105,10 @@ public LinearProgressIndicatorSpec(
102105
min(
103106
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorSize, 0),
104107
trackThickness);
108+
if (a.hasValue(R.styleable.LinearProgressIndicator_trackStopIndicatorPadding)) {
109+
trackStopIndicatorPadding =
110+
a.getDimensionPixelSize(R.styleable.LinearProgressIndicator_trackStopIndicatorPadding, 0);
111+
}
105112
TypedValue trackInnerCornerRadiusValue =
106113
a.peekValue(R.styleable.LinearProgressIndicator_trackInnerCornerRadius);
107114
if (trackInnerCornerRadiusValue != null) {

lib/java/com/google/android/material/progressindicator/res-public/values/public.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<public name="indeterminateAnimationType" type="attr"/>
3838
<public name="indicatorDirectionLinear" type="attr"/>
3939
<public name="trackInnerCornerRadius" type="attr"/>
40+
<public name="trackStopIndicatorPadding" type="attr"/>
4041

4142
<!-- CircularProgressIndicator attributes -->
4243
<public name="indicatorInset" type="attr"/>

lib/java/com/google/android/material/progressindicator/res/values/attrs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@
163163
The radius of corners between the track and the indicator.
164164
-->
165165
<attr name="trackInnerCornerRadius" format="dimension|fraction" />
166+
167+
<!--
168+
The padding of the stop indicator in the track.
169+
-->
170+
<attr name="trackStopIndicatorPadding" format="dimension" />
166171
</declare-styleable>
167172

168173
<declare-styleable name="CircularProgressIndicator">

0 commit comments

Comments
 (0)