Skip to content

Commit af95f45

Browse files
pekingmepaulfthomas
authored andcommitted
[ProgressIndicator] Added APIs to support different wavelength for determinate and indeterminate modes; and renamed confusing APIs.
PiperOrigin-RevId: 651565924
1 parent 5d85d6b commit af95f45

File tree

11 files changed

+214
-100
lines changed

11 files changed

+214
-100
lines changed

catalog/java/io/material/catalog/progressindicator/ProgressIndicatorWaveDemoFragment.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,29 @@ public void initDemoControls(@NonNull View view) {
8181
amplitudeSlider.addOnChangeListener(
8282
(slider, value, fromUser) -> {
8383
int newAmplitude = (int) (value * pixelsInDp);
84-
if (linearIndicator.getAmplitude() != newAmplitude) {
85-
linearIndicator.setAmplitude(newAmplitude);
84+
if (linearIndicator.getWaveAmplitude() != newAmplitude) {
85+
linearIndicator.setWaveAmplitude(newAmplitude);
8686
}
87-
if (circularIndicator.getAmplitude() != newAmplitude) {
88-
circularIndicator.setAmplitude((int) (value * pixelsInDp));
87+
if (circularIndicator.getWaveAmplitude() != newAmplitude) {
88+
circularIndicator.setWaveAmplitude((int) (value * pixelsInDp));
8989
}
9090
});
9191
Slider waveLengthSlider = view.findViewById(R.id.wavelength_slider);
9292
waveLengthSlider.addOnChangeListener(
9393
(slider, value, fromUser) -> {
9494
int newWaveLength = (int) (value * pixelsInDp);
95-
if (linearIndicator.getWavelength() != newWaveLength) {
96-
linearIndicator.setWavelength(newWaveLength);
97-
}
98-
if (circularIndicator.getWavelength() != newWaveLength) {
99-
circularIndicator.setWavelength(newWaveLength);
100-
}
95+
linearIndicator.setWavelength(newWaveLength);
96+
circularIndicator.setWavelength(newWaveLength);
10197
});
10298
Slider speedSlider = view.findViewById(R.id.speed_slider);
10399
speedSlider.addOnChangeListener(
104100
(slider, value, fromUser) -> {
105101
int newSpeed = (int) (value * pixelsInDp);
106-
if (linearIndicator.getSpeed() != newSpeed) {
107-
linearIndicator.setSpeed(newSpeed);
102+
if (linearIndicator.getWaveSpeed() != newSpeed) {
103+
linearIndicator.setWaveSpeed(newSpeed);
108104
}
109-
if (circularIndicator.getSpeed() != newSpeed) {
110-
circularIndicator.setSpeed(newSpeed);
105+
if (circularIndicator.getWaveSpeed() != newSpeed) {
106+
circularIndicator.setWaveSpeed(newSpeed);
111107
}
112108
});
113109

docs/components/ProgressIndicator.md

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -280,37 +280,43 @@ A progress indicator consists of a track and an indicator.
280280
The following attributes are shared between linear and circular progress
281281
indicators:
282282

283-
| Element | Attribute | Related method(s) | Default value |
284-
|-------------------------------|-----------------------------|-----------------------------------------------------------|------------------------------------------------------------------------------|
285-
| **Track thickness** | `app:trackThickness` | `setTrackThickness`</br>`getTrackThickness` | `4dp` |
286-
| **Indicator color** | `app:indicatorColor` | `setIndicatorColor`</br>`getIndicatorColor` | `colorPrimary` |
287-
| **Track color** | `app:trackColor` | `setTrackColor`</br>`getTrackColor` | `colorPrimaryContainer` (linear)</br>`@android:color/transparent` (circular) |
288-
| **Track corner radius** | `app:trackCornerRadius` | `setTrackCornerRadius`</br>`getTrackCornerRadius` | `2dp` |
289-
| **Indicator track gap size** | `app:indicatorTrackGapSize` | `setIndicatorTrackGapSize`</br>`getIndicatorTrackGapSize` | `4dp` |
290-
| **Show animation behavior** | `app:showAnimationBehavior` | `setShowAnimationBehavior`</br>`getShowAnimationBehavior` | `none` |
291-
| **Hide animation behavior** | `app:hideAnimationBehavior` | `setHideAnimationBehavior`</br>`getHideAnimationBehavior` | `none` |
292-
| **Delay (in ms) to show** | `app:showDelay` | N/A | 0 |
293-
| **Min delay (in ms) to hide** | `app:minHideDelay` | N/A | 0 |
283+
Element | Attribute | Related method(s) | Default value
284+
------------------------------------ | ----------------------------- | ------------------------------------------------------------- | -------------
285+
**Track thickness** | `app:trackThickness` | `setTrackThickness`</br>`getTrackThickness` | `4dp`
286+
**Indicator color** | `app:indicatorColor` | `setIndicatorColor`</br>`getIndicatorColor` | `colorPrimary`
287+
**Track color** | `app:trackColor` | `setTrackColor`</br>`getTrackColor` | `colorPrimaryContainer` (linear)</br>`@android:color/transparent` (circular)
288+
**Track corner radius** | `app:trackCornerRadius` | `setTrackCornerRadius`</br>`getTrackCornerRadius` | `2dp`
289+
**Indicator track gap size** | `app:indicatorTrackGapSize` | `setIndicatorTrackGapSize`</br>`getIndicatorTrackGapSize` | `4dp`
290+
**Show animation behavior** | `app:showAnimationBehavior` | `setShowAnimationBehavior`</br>`getShowAnimationBehavior` | `none`
291+
**Hide animation behavior** | `app:hideAnimationBehavior` | `setHideAnimationBehavior`</br>`getHideAnimationBehavior` | `none`
292+
**Delay (in ms) to show** | `app:showDelay` | N/A | 0
293+
**Min delay (in ms) to hide** | `app:minHideDelay` | N/A | 0
294+
**Wavelength** | `app:wavelength` | `setWavelength` | 0
295+
**Wavelength in determinate mode** | `app:wavelengthDeterminate` | `setWavelengthDeterminate`</br>`getWavelenthDeterminate` | `wavelength`
296+
**Wavelength in indeterminate mode** | `app:wavelengthIndeterminate` | `setWavelengthIndeterminate`</br>`getWavelengthIndeterminate` | `wavelength`
297+
**Wave amplitude** | `app:waveAmplitude` | `setWaveAmplitude`</br>`getWaveAmplitude` | 0
298+
**Wave speed** | `app:waveSpeed` | `setWaveSpeed`</br>`getWaveSpeed` | 0
294299

295300
#### Linear type specific attributes
296301

297302
Linear type progress indicators also have the following attributes:
298303

299-
| Element | Attribute | Related method(s) | Default value |
300-
|----------------------------------|----------------------------------|---------------------------------------------------------------------|---------------|
301-
| **Indeterminate animation type** | `app:indeterminateAnimationType` | `setIndeterminateAnimationType`</br>`getIndeterminateAnimationType` | `disjoint` |
302-
| **Indicator direction** | `app:indicatorDirectionLinear` | `setIndicatorDirection`</br>`getIndicatorDirection` | `leftToRight` |
303-
| **Track stop indicator size** | `app:trackStopIndicatorSize` | `setTrackStopIndicatorSize`</br>`getTrackStopIndicatorSize` | `4dp` |
304+
Element | Attribute | Related method(s) | Default value
305+
-------------------------------- | -------------------------------- | ------------------------------------------------------------------- | -------------
306+
**Indeterminate animation type** | `app:indeterminateAnimationType` | `setIndeterminateAnimationType`</br>`getIndeterminateAnimationType` | `disjoint`
307+
**Indicator direction** | `app:indicatorDirectionLinear` | `setIndicatorDirection`</br>`getIndicatorDirection` | `leftToRight`
308+
**Track stop indicator size** | `app:trackStopIndicatorSize` | `setTrackStopIndicatorSize`</br>`getTrackStopIndicatorSize` | `4dp`
304309

305310
#### Circular type specific attributes
306311

307312
Circular type progress indicators also have the following attributes:
308313

309-
Element | Attribute | Related method(s) | Default value
310-
--------------------------------- | -------------------------------- | --------------------------------------------------- | -------------
311-
**Spinner size (outer diameter)** | `app:indicatorSize` | `setIndicatorSize`</br>`getIndicatorSize` | `40dp`
312-
**Inset** | `app:indicatorInset` | `setIndicatorInset`</br>`getIndicatorInset` | `4dp`
313-
**Indicator direction** | `app:indicatorDirectionCircular` | `setIndicatorDirection`</br>`getIndicatorDirection` | `clockwise`
314+
Element | Attribute | Related method(s) | Default value
315+
--------------------------------- | ---------------------------------------- | ------------------------------------------------------------------- | -------------
316+
**Spinner size (outer diameter)** | `app:indicatorSize` | `setIndicatorSize`</br>`getIndicatorSize` | `40dp`
317+
**Inset** | `app:indicatorInset` | `setIndicatorInset`</br>`getIndicatorInset` | `4dp`
318+
**Indicator direction** | `app:indicatorDirectionCircular` | `setIndicatorDirection`</br>`getIndicatorDirection` | `clockwise`
319+
**Indeterminate animation type** | `app:indeterminateAnimationTypeCircular` | `setIndeterminateAnimationType`</br>`getIndeterminateAnimationType` | `advance`
314320

315321
#### Styles
316322

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

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -681,69 +681,109 @@ public void setIndicatorTrackGapSize(@Px int indicatorTrackGapSize) {
681681
/**
682682
* Returns the amplitude of the indicator's amplitude in pixels.
683683
*
684-
* @see #setAmplitude(int)
684+
* @see #setWaveAmplitude(int)
685685
*/
686686
@Px
687-
public int getAmplitude() {
688-
return spec.amplitude;
687+
public int getWaveAmplitude() {
688+
return spec.waveAmplitude;
689689
}
690690

691691
/**
692692
* Sets the amplitude of the indicator's amplitude in pixels.
693693
*
694-
* @param amplitude The new amplitude in pixels.
695-
* @see #getAmplitude()
694+
* @param waveAmplitude The new amplitude in pixels.
695+
* @see #getWaveAmplitude()
696696
*/
697-
public void setAmplitude(@Px int amplitude) {
698-
if (spec.amplitude != amplitude) {
699-
spec.amplitude = abs(amplitude);
697+
public void setWaveAmplitude(@Px int waveAmplitude) {
698+
if (spec.waveAmplitude != waveAmplitude) {
699+
spec.waveAmplitude = abs(waveAmplitude);
700700
requestLayout();
701701
}
702702
}
703703

704704
/**
705-
* Returns the wavelength of the indicator's waveform in pixels.
705+
* Returns the wavelength, in pixels, of the indicator's waveform in determinate mode.
706706
*
707+
* @see #setWavelengthDeterminate(int)
707708
* @see #setWavelength(int)
708709
*/
709710
@Px
710-
public int getWavelength() {
711-
return spec.wavelength;
711+
public int getWavelengthDeterminate() {
712+
return spec.wavelengthDeterminate;
712713
}
713714

714715
/**
715-
* Sets the wavelength of the indicator's waveform in pixels.
716+
* Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.
716717
*
717-
* @param wavelength The new wavelength in pixels. No waves are drawn, if it equals to 0 with a
718-
* non-zero amplitude.
719-
* @see #getWavelength()
718+
* @param wavelength The new wavelength in pixels. No waves are drawn when wavelength is zero.
719+
* @see #getWavelengthDeterminate()
720720
*/
721-
public void setWavelength(@Px int wavelength) {
722-
if (spec.wavelength != wavelength) {
723-
spec.wavelength = abs(wavelength);
724-
requestLayout();
721+
public void setWavelengthDeterminate(@Px int wavelength) {
722+
if (spec.wavelengthDeterminate != wavelength) {
723+
spec.wavelengthDeterminate = abs(wavelength);
724+
if (!isIndeterminate()) {
725+
requestLayout();
726+
}
725727
}
726728
}
727729

730+
/**
731+
* Returns the wavelength, in pixels, of the indicator's waveform in indeterminate mode.
732+
*
733+
* @see #setWavelengthIndeterminate(int)
734+
* @see #setWavelength(int)
735+
*/
736+
@Px
737+
public int getWavelengthIndeterminate() {
738+
return spec.wavelengthIndeterminate;
739+
}
740+
741+
/**
742+
* Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.
743+
*
744+
* @param wavelength The new wavelength in pixels. No waves are drawn when wavelength is zero.
745+
* @see #getWavelengthIndeterminate()
746+
*/
747+
public void setWavelengthIndeterminate(@Px int wavelength) {
748+
if (spec.wavelengthIndeterminate != wavelength) {
749+
spec.wavelengthIndeterminate = abs(wavelength);
750+
if (isIndeterminate()) {
751+
requestLayout();
752+
}
753+
}
754+
}
755+
756+
/**
757+
* Sets the wavelength of the indicator's determinate and indeterminate waveform in pixels.
758+
*
759+
* @param wavelength The new wavelength in pixels. No waves are drawn, if it equals to 0.
760+
* @see #getWavelengthDeterminate()
761+
* @see #getWavelengthIndeterminate()
762+
*/
763+
public void setWavelength(@Px int wavelength) {
764+
setWavelengthDeterminate(wavelength);
765+
setWavelengthIndeterminate(wavelength);
766+
}
767+
728768
/**
729769
* Returns the speed of the indicator's waveform in pixels.
730770
*
731-
* @see #setSpeed(int)
771+
* @see #setWaveSpeed(int)
732772
*/
733773
@Px
734-
public int getSpeed() {
735-
return spec.speed;
774+
public int getWaveSpeed() {
775+
return spec.waveSpeed;
736776
}
737777

738778
/**
739779
* Sets the speed of the indicator's waveform in pixels.
740780
*
741-
* @param speed The new speed in pixels.
742-
* @see #getSpeed()
781+
* @param waveSpeed The new speed in pixels.
782+
* @see #getWaveSpeed()
743783
*/
744-
public void setSpeed(@Px int speed) {
745-
spec.speed = speed;
746-
getProgressDrawable().setEnforcedDrawing(spec.speed != 0);
784+
public void setWaveSpeed(@Px int waveSpeed) {
785+
spec.waveSpeed = waveSpeed;
786+
getProgressDrawable().setEnforcedDrawing(spec.waveSpeed != 0);
747787
}
748788

749789
/**

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ public abstract class BaseProgressIndicatorSpec {
7373
/** The size of the gap between the indicator and the rest of the track. */
7474
@Px public int indicatorTrackGapSize;
7575

76-
/** The size of the wavelength, if a wave effect is configured. */
77-
@Px public int wavelength;
76+
/** The size of the wavelength in determinate mode, if a wave effect is configured. */
77+
@Px public int wavelengthDeterminate;
78+
79+
/** The size of the wavelength in indeterminate mode, if a wave effect is configured. */
80+
@Px public int wavelengthIndeterminate;
7881

7982
/** The size of the amplitude, if a wave effect is configured. */
80-
@Px public int amplitude;
83+
@Px public int waveAmplitude;
8184

8285
/** The speed of the waveform, if a wave effect is configured. */
83-
@Px public int speed;
86+
@Px public int waveSpeed;
8487

8588
/**
8689
* Instantiates BaseProgressIndicatorSpec.
@@ -120,9 +123,18 @@ protected BaseProgressIndicatorSpec(
120123
indicatorTrackGapSize =
121124
a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_indicatorTrackGapSize, 0);
122125

123-
wavelength = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_wavelength, 0));
124-
amplitude = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_amplitude, 0));
125-
speed = a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_speed, 0);
126+
int wavelength = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_wavelength, 0));
127+
wavelengthDeterminate =
128+
abs(
129+
a.getDimensionPixelSize(
130+
R.styleable.BaseProgressIndicator_wavelengthDeterminate, wavelength));
131+
wavelengthIndeterminate =
132+
abs(
133+
a.getDimensionPixelSize(
134+
R.styleable.BaseProgressIndicator_wavelengthIndeterminate, wavelength));
135+
waveAmplitude =
136+
abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_waveAmplitude, 0));
137+
waveSpeed = a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_waveSpeed, 0);
126138

127139
loadIndicatorColors(context, a);
128140
loadTrackColor(context, a);
@@ -198,8 +210,10 @@ public boolean isHideAnimationEnabled() {
198210
return hideAnimationBehavior != BaseProgressIndicator.HIDE_NONE;
199211
}
200212

201-
public boolean hasWavyEffect() {
202-
return amplitude > 0 && wavelength > 0;
213+
public boolean hasWavyEffect(boolean isDeterminate) {
214+
return waveAmplitude > 0
215+
&& ((!isDeterminate && wavelengthIndeterminate > 0)
216+
|| (isDeterminate && wavelengthDeterminate > 0));
203217
}
204218

205219
@CallSuper

0 commit comments

Comments
 (0)