Skip to content

Commit d57d054

Browse files
pekingmewcshi
authored andcommitted
[ProgressIndicator] Renamed some attributes.
PiperOrigin-RevId: 343299956 (cherry picked from commit 9d7ae04)
1 parent 4ac0fe0 commit d57d054

17 files changed

+163
-161
lines changed

catalog/java/io/material/catalog/progressindicator/ProgressIndicatorStandaloneDemoFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public View onCreateDemoView(
5151
CircularProgressIndicatorSpec spec =
5252
new CircularProgressIndicatorSpec(getContext(), /*attrs=*/ null);
5353
spec.indicatorInset = 0; // No inset.
54-
spec.indicatorRadius = (int) ViewUtils.dpToPx(getContext(), 10); // Circular radius is 10 dp.
55-
IndeterminateDrawable progressIndicatorDrawable =
54+
spec.indicatorSize = (int) ViewUtils.dpToPx(getContext(), 22); // Circular radius is 10 dp.
55+
IndeterminateDrawable<CircularProgressIndicatorSpec> progressIndicatorDrawable =
5656
IndeterminateDrawable.createCircularDrawable(getContext(), spec);
5757

5858
Chip chip = view.findViewById(R.id.cat_progress_indicator_chip);

catalog/java/io/material/catalog/progressindicator/res/layout/cat_progress_indicator_determinate_fragment.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
android:layout_width="match_parent"
4141
android:layout_height="wrap_content"
4242
app:indicatorDirectionLinear="endToStart"
43-
app:indicatorCornerRadius="@dimen/mtrl_progress_indicator_full_rounded_corner_radius"/>
43+
app:trackCornerRadius="@dimen/mtrl_progress_indicator_full_rounded_corner_radius"/>
4444

4545
<TextView
4646
android:layout_width="wrap_content"
@@ -103,7 +103,7 @@
103103
android:layout_gravity="center"
104104
style="@style/Widget.MaterialComponents.CircularProgressIndicator"
105105
app:indicatorDirectionCircular="counterclockwise"
106-
app:indicatorCornerRadius="@dimen/mtrl_progress_indicator_full_rounded_corner_radius"/>
106+
app:trackCornerRadius="@dimen/mtrl_progress_indicator_full_rounded_corner_radius"/>
107107
</LinearLayout>
108108

109109
<LinearLayout

catalog/java/io/material/catalog/progressindicator/res/layout/cat_progress_indicator_indeterminate_indicators.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
android:layout_height="wrap_content"
3838
android:indeterminate="true"
3939
app:indicatorDirectionLinear="endToStart"
40-
app:indicatorCornerRadius="@dimen/mtrl_progress_indicator_full_rounded_corner_radius"/>
40+
app:trackCornerRadius="@dimen/mtrl_progress_indicator_full_rounded_corner_radius"/>
4141

4242
<TextView
4343
android:layout_width="wrap_content"
@@ -103,7 +103,7 @@
103103
android:indeterminate="true"
104104
style="@style/Widget.MaterialComponents.CircularProgressIndicator"
105105
app:indicatorDirectionCircular="counterclockwise"
106-
app:indicatorCornerRadius="@dimen/mtrl_progress_indicator_full_rounded_corner_radius"/>
106+
app:trackCornerRadius="@dimen/mtrl_progress_indicator_full_rounded_corner_radius"/>
107107
</LinearLayout>
108108

109109
<LinearLayout

docs/components/ProgressIndicator.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ LinearProgressIndicator indicator = new LinearProgressIndicator(getContext());
4848
### Default style
4949

5050
The default style `Widget.MaterialComponents.LinearProgressIndicator` will
51-
configure the indicator to draw a linear strip with the track width of 4dp. The
52-
indicator will swipe or grow from `start` to `end` regarding the layout
51+
configure the indicator to draw a linear strip with the track thickness of 4dp.
52+
The indicator will swipe or grow from `start` to `end` regarding the layout
5353
direction. No animation will be used while showing or hiding.
5454

5555
### Custom styling
@@ -69,8 +69,8 @@ regardless the number of indicator colors used.
6969

7070
#### Size and layout
7171

72-
`LinearProgressIndicator` can configure its height by adjusting `indicatorSize`.
73-
`indicatorSize` sets the width of the track/indicator; in the linear type case,
72+
`LinearProgressIndicator` can configure its height by adjusting `trackThickness`.
73+
`trackThickness` sets the width of the track/indicator; in the linear type case,
7474
it's the height of the strip.
7575

7676
Note: The width of strip depends on the view and its layout.
@@ -104,11 +104,11 @@ By setting the `showAnimationBehavior` and `hideAnimationBehavior`, the indicato
104104
have different animation effects as follows:
105105

106106
<table>
107-
<tr><td colspan=2>showAnimationBehavior<td></tr>
107+
<tr><td colspan=2>showAnimationBehavior</td></tr>
108108
<tr><td>none</td><td>Appear immediately</td></tr>
109109
<tr><td>upward</td><td>Expanding from the bottom edge</td></tr>
110110
<tr><td>downward</td><td>Expanding from the top edge</td></tr>
111-
<tr><td colspan=2>hideAnimationBehavior<td></tr>
111+
<tr><td colspan=2>hideAnimationBehavior</td></tr>
112112
<tr><td>none</td><td>Disappear immediately</td></tr>
113113
<tr><td>upward</td><td>Collapsing to the top edge</td></tr>
114114
<tr><td>downward</td><td>Collapsing to the bottom edge</td></tr>
@@ -155,10 +155,10 @@ CircularProgressIndicator indicator = new CircularProgressIndicator(getContext()
155155

156156
The default style `Widget.MaterialComponents.CircularProgressIndicator` will
157157
configure the indicator to draw a circular (or partial) ring with the track
158-
width of 4dp. The radius is 18dp measured from the axial line (or the circular
159-
between the inner and outer edges). There is also 4dp inset added on all sides.
160-
The indicator will spin or grow clockwise regardless the layout direction. No
161-
animation will be used while showing or hiding.
158+
thickness of 4dp. The indicator size is 40dp measured as the outer edge. There
159+
is also 4dp inset added on all sides. The indicator will spin or grow clockwise
160+
regardless the layout direction. No animation will be used while showing or
161+
hiding.
162162

163163
### Custom styling
164164

@@ -171,13 +171,13 @@ Same as `LinearProgressIndicator`.
171171

172172
#### Size and layout
173173

174-
`CircularProgressIndicator` can configure its size by adjusting `indicatorSize`,
175-
`indicatorRadius`, and `indicatorInset`. `indicatorSize` sets the width of the
176-
track/indicator. `indicatorRadius` sets the size of the ring by the radius
177-
measured from the axial line. `indicatorInset` gives an extra space between the
178-
outer edge to the drawable's bounds.
174+
`CircularProgressIndicator` can configure its size by adjusting
175+
`trackThickness`, `indicatorSize`, and `indicatorInset`. `trackThickness` sets
176+
the thickness of the track/indicator. `indicatorSize` sets the size of the ring
177+
by the diameter of the outer edge. `indicatorInset` gives an extra space between
178+
the outer edge to the drawable's bounds.
179179

180-
Note: If half of the `indicatorSize` is greater than the `indicatorRadius`,
180+
Note: If the `trackThickness` is greater than the half of the `indicatorSize`,
181181
`IllegalArgumentException` will be thrown during initialization.
182182

183183
#### Showing and hiding with animations
@@ -209,11 +209,11 @@ By setting the `showAnimationBehavior` and `hideAnimationBehavior`, the indicato
209209
can have different animation effects as follows:
210210

211211
<table>
212-
<tr><td colspan=2>showAnimationBehavior<td></tr>
212+
<tr><td colspan=2>showAnimationBehavior</td></tr>
213213
<tr><td>none</td><td>Appear immediately</td></tr>
214214
<tr><td>inward</td><td>Expanding from the outer edge</td></tr>
215215
<tr><td>outward</td><td>Expanding from the inner edge</td></tr>
216-
<tr><td colspan=2>hideAnimationBehavior<td></tr>
216+
<tr><td colspan=2>hideAnimationBehavior</td></tr>
217217
<tr><td>none</td><td>Disappear immediately</td></tr>
218218
<tr><td>inward</td><td>Collapsing to the inner edge</td></tr>
219219
<tr><td>outward</td><td>Collapsing to the outer edge</td></tr>

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@
5252
* is an abstract class which is not meant for directly use.
5353
*
5454
* <p>With the default style {@link R.style#Widget_MaterialComponents_ProgressIndicator}, 4dp
55-
* indicator/track size and no animation is used for visibility change. Without customization,
55+
* indicator/track thickness and no animation is used for visibility change. Without customization,
5656
* primaryColor will be used as the indicator color; the indicator color applying disabledAlpha will
5757
* be used as the track color. The following attributes can be used to customize the progress
5858
* indicator's appearance:
5959
*
6060
* <ul>
61-
* <li>{@code indicatorSize}: the stroke width of the indicator and track.
61+
* <li>{@code trackThickness}: the thickness of the indicator and track.
6262
* <li>{@code indicatorColor}: the color of the indicator.
6363
* <li>{@code trackColor}: the color of the track.
64-
* <li>{@code indicatorCornerRadius}: the radius of the rounded corner of the indicator stroke.
64+
* <li>{@code trackCornerRadius}: the radius of the rounded corner of the indicator and track.
6565
* <li>{@code showAnimationBehavior}: the animation direction to show the indicator and track.
6666
* <li>{@code hideAnimationBehavior}: the animation direction to hide the indicator and track.
6767
* </ul>
@@ -524,28 +524,28 @@ public synchronized void setIndeterminate(boolean indeterminate) {
524524
}
525525

526526
/**
527-
* Returns the indicator size of this progress indicator in pixels.
527+
* Returns the track thickness of this progress indicator in pixels.
528528
*
529-
* @see #setIndicatorSize(int)
529+
* @see #setTrackThickness(int)
530530
* @attr ref
531-
* com.google.android.material.progressindicator.R.stylable#BaseProgressIndicator_indicatorSize
531+
* com.google.android.material.progressindicator.R.stylable#BaseProgressIndicator_trackThickness
532532
*/
533533
@Px
534-
public int getIndicatorSize() {
535-
return spec.indicatorSize;
534+
public int getTrackThickness() {
535+
return spec.trackThickness;
536536
}
537537

538538
/**
539-
* Sets the indicator size of this progress indicator.
539+
* Sets the track thickness of this progress indicator.
540540
*
541-
* @param indicatorSize The new indicator size in pixel.
542-
* @see #getIndicatorSize()
541+
* @param trackThickness The new indicator size in pixel.
542+
* @see #getTrackThickness()
543543
* @attr ref
544-
* com.google.android.material.progressindicator.R.stylable#BaseProgressIndicator_indicatorSize
544+
* com.google.android.material.progressindicator.R.stylable#BaseProgressIndicator_trackThickness
545545
*/
546-
public void setIndicatorSize(@Px int indicatorSize) {
547-
if (spec.indicatorSize != indicatorSize) {
548-
spec.indicatorSize = indicatorSize;
546+
public void setTrackThickness(@Px int trackThickness) {
547+
if (spec.trackThickness != trackThickness) {
548+
spec.trackThickness = trackThickness;
549549
requestLayout();
550550
}
551551
}
@@ -610,28 +610,28 @@ public void setTrackColor(@ColorInt int trackColor) {
610610
}
611611

612612
/**
613-
* Returns the corner radius for progress indicator with rounded corners in pixels.
613+
* Returns the radius of the rounded corner for the indicator and track in pixels.
614614
*
615-
* @see #setIndicatorCornerRadius(int)
615+
* @see #setTrackCornerRadius(int)
616616
* @attr ref
617-
* com.google.android.material.progressindicator.R.stylable#BaseProgressIndicator_indicatorCornerRadius
617+
* com.google.android.material.progressindicator.R.stylable#BaseProgressIndicator_trackCornerRadius
618618
*/
619619
@Px
620-
public int getIndicatorCornerRadius() {
621-
return spec.indicatorCornerRadius;
620+
public int getTrackCornerRadius() {
621+
return spec.trackCornerRadius;
622622
}
623623

624624
/**
625-
* Sets the corner radius for progress indicator with rounded corners in pixels.
625+
* Sets the radius of the rounded corner for the indicator and track in pixels.
626626
*
627-
* @param indicatorCornerRadius The new corner radius in pixels.
628-
* @see #getIndicatorCornerRadius()
627+
* @param trackCornerRadius The new corner radius in pixels.
628+
* @see #getTrackCornerRadius()
629629
* @attr ref
630-
* com.google.android.material.progressindicator.R.stylable#BaseProgressIndicator_indicatorCornerRadius
630+
* com.google.android.material.progressindicator.R.stylable#BaseProgressIndicator_trackCornerRadius
631631
*/
632-
public void setIndicatorCornerRadius(@Px int indicatorCornerRadius) {
633-
if (spec.indicatorCornerRadius != indicatorCornerRadius) {
634-
spec.indicatorCornerRadius = min(indicatorCornerRadius, spec.indicatorSize / 2);
632+
public void setTrackCornerRadius(@Px int trackCornerRadius) {
633+
if (spec.trackCornerRadius != trackCornerRadius) {
634+
spec.trackCornerRadius = min(trackCornerRadius, spec.trackThickness / 2);
635635
}
636636
}
637637

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
* reflect the attributes defined in {@link R.styleable#BaseProgressIndicator}.
4141
*/
4242
public abstract class BaseProgressIndicatorSpec {
43-
/** The size of the progress track and indicator. */
44-
@Px public int indicatorSize;
43+
/** The thickness of the progress track and indicator. */
44+
@Px public int trackThickness;
4545

4646
/**
4747
* When this is greater than 0, the corners of both the track and the indicator will be rounded
4848
* with this radius. If the radius is greater than half of the track width, an {@code
4949
* IllegalArgumentException} will be thrown during initialization.
5050
*/
51-
@Px public int indicatorCornerRadius;
51+
@Px public int trackCornerRadius;
5252

5353
/**
5454
* The color array of the progress stroke. In determinate mode and single color indeterminate
@@ -85,22 +85,22 @@ protected BaseProgressIndicatorSpec(
8585
private void loadBaseSpecFromAttributes(
8686
@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes final int defStyleAttr) {
8787
int defaultIndicatorSize =
88-
context.getResources().getDimensionPixelSize(R.dimen.mtrl_progress_indicator_size);
88+
context.getResources().getDimensionPixelSize(R.dimen.mtrl_progress_track_thickness);
8989
TypedArray a =
9090
ThemeEnforcement.obtainStyledAttributes(
9191
context,
9292
attrs,
9393
R.styleable.BaseProgressIndicator,
9494
defStyleAttr,
9595
BaseProgressIndicator.DEF_STYLE_RES);
96-
indicatorSize =
96+
trackThickness =
9797
getDimensionPixelSize(
98-
context, a, R.styleable.BaseProgressIndicator_indicatorSize, defaultIndicatorSize);
99-
indicatorCornerRadius =
98+
context, a, R.styleable.BaseProgressIndicator_trackThickness, defaultIndicatorSize);
99+
trackCornerRadius =
100100
min(
101101
getDimensionPixelSize(
102-
context, a, R.styleable.BaseProgressIndicator_indicatorCornerRadius, 0),
103-
indicatorSize / 2);
102+
context, a, R.styleable.BaseProgressIndicator_trackCornerRadius, 0),
103+
trackThickness / 2);
104104
showAnimationBehavior =
105105
a.getInt(
106106
R.styleable.BaseProgressIndicator_showAnimationBehavior,

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

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class CircularDrawingDelegate extends DrawingDelegate<CircularProgressIndi
3131
// This is a factor effecting the positive direction to draw the arc. +1 for clockwise; -1 for
3232
// counter-clockwise.
3333
private int arcDirectionFactor = 1;
34-
private float displayedIndicatorSize;
34+
private float displayedTrackThickness;
3535
private float displayedCornerRadius;
3636
private float adjustedRadius;
3737

@@ -53,18 +53,17 @@ public int getPreferredHeight() {
5353
/**
5454
* Adjusts the canvas for drawing circular progress indicator. It rotates the canvas -90 degrees
5555
* to keep the 0 at the top. The canvas is clipped to a square with the size just includes the
56-
* inset. It will also pre-calculate the bound for drawing the arc based on the indicate radius
57-
* and current indicator size.
56+
* inset. It will also pre-calculate the bound for drawing the arc based on the spinner radius and
57+
* current track thickness.
5858
*
5959
* @param canvas Canvas to draw.
60-
* @param indicatorSizeFraction A fraction representing how much portion of the indicator size
61-
* should be used in the drawing.
60+
* @param trackThicknessFraction A fraction representing how much portion of the track thickness
61+
* should be used in the drawing.
6262
*/
6363
@Override
6464
public void adjustCanvas(
65-
@NonNull Canvas canvas,
66-
@FloatRange(from = 0.0, to = 1.0) float indicatorSizeFraction) {
67-
int outerRadiusWithInset = spec.indicatorRadius + spec.indicatorSize / 2 + spec.indicatorInset;
65+
@NonNull Canvas canvas, @FloatRange(from = 0.0, to = 1.0) float trackThicknessFraction) {
66+
float outerRadiusWithInset = spec.indicatorSize / 2f + spec.indicatorInset;
6867
canvas.translate(outerRadiusWithInset, outerRadiusWithInset);
6968
// Rotates canvas so that arc starts at top.
7069
canvas.rotate(-90f);
@@ -77,23 +76,25 @@ public void adjustCanvas(
7776
// These are used when drawing the indicator and track.
7877
arcDirectionFactor =
7978
spec.indicatorDirection == CircularProgressIndicator.INDICATOR_DIRECTION_CLOCKWISE ? 1 : -1;
80-
displayedIndicatorSize = spec.indicatorSize * indicatorSizeFraction;
81-
displayedCornerRadius = spec.indicatorCornerRadius * indicatorSizeFraction;
82-
adjustedRadius = spec.indicatorRadius;
79+
displayedTrackThickness = spec.trackThickness * trackThicknessFraction;
80+
displayedCornerRadius = spec.trackCornerRadius * trackThicknessFraction;
81+
adjustedRadius = (spec.indicatorSize - spec.trackThickness) / 2f;
8382
if ((drawable.isShowing()
8483
&& spec.showAnimationBehavior == CircularProgressIndicator.SHOW_INWARD)
8584
|| (drawable.isHiding()
8685
&& spec.hideAnimationBehavior == CircularProgressIndicator.HIDE_OUTWARD)) {
87-
// Increases the radius by half of the full size, then reduces it half way of the displayed
88-
// size to match the outer edges of the displayed indicator and the full indicator.
89-
adjustedRadius += (1 - indicatorSizeFraction) * spec.indicatorSize / 2;
86+
// Increases the radius by half of the full thickness, then reduces it half way of the
87+
// displayed thickness to match the outer edges of the displayed indicator and the full
88+
// indicator.
89+
adjustedRadius += (1 - trackThicknessFraction) * spec.trackThickness / 2;
9090
} else if ((drawable.isShowing()
9191
&& spec.showAnimationBehavior == CircularProgressIndicator.SHOW_OUTWARD)
9292
|| (drawable.isHiding()
9393
&& spec.hideAnimationBehavior == CircularProgressIndicator.HIDE_INWARD)) {
94-
// Decreases the radius by half of the full size, then raises it half way of the displayed
95-
// size to match the inner edges of the displayed indicator and the full indicator.
96-
adjustedRadius -= (1 - indicatorSizeFraction) * spec.indicatorSize / 2;
94+
// Decreases the radius by half of the full thickness, then raises it half way of the
95+
// displayed thickness to match the inner edges of the displayed indicator and the full
96+
// indicator.
97+
adjustedRadius -= (1 - trackThicknessFraction) * spec.trackThickness / 2;
9798
}
9899
}
99100

@@ -125,7 +126,7 @@ void fillIndicator(
125126
paint.setStrokeCap(Cap.BUTT);
126127
paint.setAntiAlias(true);
127128
paint.setColor(color);
128-
paint.setStrokeWidth(displayedIndicatorSize);
129+
paint.setStrokeWidth(displayedTrackThickness);
129130

130131
// Calculates the start and end in degrees.
131132
float startDegree = startFraction * 360 * arcDirectionFactor;
@@ -150,15 +151,15 @@ void fillIndicator(
150151
drawRoundedEnd(
151152
canvas,
152153
paint,
153-
displayedIndicatorSize,
154+
displayedTrackThickness,
154155
displayedCornerRadius,
155156
startDegree,
156157
true,
157158
cornerPatternRectBound);
158159
drawRoundedEnd(
159160
canvas,
160161
paint,
161-
displayedIndicatorSize,
162+
displayedTrackThickness,
162163
displayedCornerRadius,
163164
startDegree + arcDegree,
164165
false,
@@ -181,14 +182,14 @@ void fillTrack(@NonNull Canvas canvas, @NonNull Paint paint) {
181182
paint.setStrokeCap(Cap.BUTT);
182183
paint.setAntiAlias(true);
183184
paint.setColor(trackColor);
184-
paint.setStrokeWidth(displayedIndicatorSize);
185+
paint.setStrokeWidth(displayedTrackThickness);
185186

186187
RectF arcBound = new RectF(-adjustedRadius, -adjustedRadius, adjustedRadius, adjustedRadius);
187188
canvas.drawArc(arcBound, 0, 360, false, paint);
188189
}
189190

190191
private int getSize() {
191-
return spec.indicatorRadius * 2 + spec.indicatorSize + spec.indicatorInset * 2;
192+
return spec.indicatorSize + spec.indicatorInset * 2;
192193
}
193194

194195
private void drawRoundedEnd(

0 commit comments

Comments
 (0)