Skip to content

Commit

Permalink
[ProgressIndicator] Added APIs to support different wavelength for de…
Browse files Browse the repository at this point in the history
…terminate and indeterminate modes; and renamed confusing APIs.

PiperOrigin-RevId: 651565924
  • Loading branch information
pekingme authored and paulfthomas committed Jul 22, 2024
1 parent 5d85d6b commit af95f45
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,29 @@ public void initDemoControls(@NonNull View view) {
amplitudeSlider.addOnChangeListener(
(slider, value, fromUser) -> {
int newAmplitude = (int) (value * pixelsInDp);
if (linearIndicator.getAmplitude() != newAmplitude) {
linearIndicator.setAmplitude(newAmplitude);
if (linearIndicator.getWaveAmplitude() != newAmplitude) {
linearIndicator.setWaveAmplitude(newAmplitude);
}
if (circularIndicator.getAmplitude() != newAmplitude) {
circularIndicator.setAmplitude((int) (value * pixelsInDp));
if (circularIndicator.getWaveAmplitude() != newAmplitude) {
circularIndicator.setWaveAmplitude((int) (value * pixelsInDp));
}
});
Slider waveLengthSlider = view.findViewById(R.id.wavelength_slider);
waveLengthSlider.addOnChangeListener(
(slider, value, fromUser) -> {
int newWaveLength = (int) (value * pixelsInDp);
if (linearIndicator.getWavelength() != newWaveLength) {
linearIndicator.setWavelength(newWaveLength);
}
if (circularIndicator.getWavelength() != newWaveLength) {
circularIndicator.setWavelength(newWaveLength);
}
linearIndicator.setWavelength(newWaveLength);
circularIndicator.setWavelength(newWaveLength);
});
Slider speedSlider = view.findViewById(R.id.speed_slider);
speedSlider.addOnChangeListener(
(slider, value, fromUser) -> {
int newSpeed = (int) (value * pixelsInDp);
if (linearIndicator.getSpeed() != newSpeed) {
linearIndicator.setSpeed(newSpeed);
if (linearIndicator.getWaveSpeed() != newSpeed) {
linearIndicator.setWaveSpeed(newSpeed);
}
if (circularIndicator.getSpeed() != newSpeed) {
circularIndicator.setSpeed(newSpeed);
if (circularIndicator.getWaveSpeed() != newSpeed) {
circularIndicator.setWaveSpeed(newSpeed);
}
});

Expand Down
48 changes: 27 additions & 21 deletions docs/components/ProgressIndicator.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,37 +280,43 @@ A progress indicator consists of a track and an indicator.
The following attributes are shared between linear and circular progress
indicators:

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

#### Linear type specific attributes

Linear type progress indicators also have the following attributes:

| Element | Attribute | Related method(s) | Default value |
|----------------------------------|----------------------------------|---------------------------------------------------------------------|---------------|
| **Indeterminate animation type** | `app:indeterminateAnimationType` | `setIndeterminateAnimationType`</br>`getIndeterminateAnimationType` | `disjoint` |
| **Indicator direction** | `app:indicatorDirectionLinear` | `setIndicatorDirection`</br>`getIndicatorDirection` | `leftToRight` |
| **Track stop indicator size** | `app:trackStopIndicatorSize` | `setTrackStopIndicatorSize`</br>`getTrackStopIndicatorSize` | `4dp` |
Element | Attribute | Related method(s) | Default value
-------------------------------- | -------------------------------- | ------------------------------------------------------------------- | -------------
**Indeterminate animation type** | `app:indeterminateAnimationType` | `setIndeterminateAnimationType`</br>`getIndeterminateAnimationType` | `disjoint`
**Indicator direction** | `app:indicatorDirectionLinear` | `setIndicatorDirection`</br>`getIndicatorDirection` | `leftToRight`
**Track stop indicator size** | `app:trackStopIndicatorSize` | `setTrackStopIndicatorSize`</br>`getTrackStopIndicatorSize` | `4dp`

#### Circular type specific attributes

Circular type progress indicators also have the following attributes:

Element | Attribute | Related method(s) | Default value
--------------------------------- | -------------------------------- | --------------------------------------------------- | -------------
**Spinner size (outer diameter)** | `app:indicatorSize` | `setIndicatorSize`</br>`getIndicatorSize` | `40dp`
**Inset** | `app:indicatorInset` | `setIndicatorInset`</br>`getIndicatorInset` | `4dp`
**Indicator direction** | `app:indicatorDirectionCircular` | `setIndicatorDirection`</br>`getIndicatorDirection` | `clockwise`
Element | Attribute | Related method(s) | Default value
--------------------------------- | ---------------------------------------- | ------------------------------------------------------------------- | -------------
**Spinner size (outer diameter)** | `app:indicatorSize` | `setIndicatorSize`</br>`getIndicatorSize` | `40dp`
**Inset** | `app:indicatorInset` | `setIndicatorInset`</br>`getIndicatorInset` | `4dp`
**Indicator direction** | `app:indicatorDirectionCircular` | `setIndicatorDirection`</br>`getIndicatorDirection` | `clockwise`
**Indeterminate animation type** | `app:indeterminateAnimationTypeCircular` | `setIndeterminateAnimationType`</br>`getIndeterminateAnimationType` | `advance`

#### Styles

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,69 +681,109 @@ public void setIndicatorTrackGapSize(@Px int indicatorTrackGapSize) {
/**
* Returns the amplitude of the indicator's amplitude in pixels.
*
* @see #setAmplitude(int)
* @see #setWaveAmplitude(int)
*/
@Px
public int getAmplitude() {
return spec.amplitude;
public int getWaveAmplitude() {
return spec.waveAmplitude;
}

/**
* Sets the amplitude of the indicator's amplitude in pixels.
*
* @param amplitude The new amplitude in pixels.
* @see #getAmplitude()
* @param waveAmplitude The new amplitude in pixels.
* @see #getWaveAmplitude()
*/
public void setAmplitude(@Px int amplitude) {
if (spec.amplitude != amplitude) {
spec.amplitude = abs(amplitude);
public void setWaveAmplitude(@Px int waveAmplitude) {
if (spec.waveAmplitude != waveAmplitude) {
spec.waveAmplitude = abs(waveAmplitude);
requestLayout();
}
}

/**
* Returns the wavelength of the indicator's waveform in pixels.
* Returns the wavelength, in pixels, of the indicator's waveform in determinate mode.
*
* @see #setWavelengthDeterminate(int)
* @see #setWavelength(int)
*/
@Px
public int getWavelength() {
return spec.wavelength;
public int getWavelengthDeterminate() {
return spec.wavelengthDeterminate;
}

/**
* Sets the wavelength of the indicator's waveform in pixels.
* Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.
*
* @param wavelength The new wavelength in pixels. No waves are drawn, if it equals to 0 with a
* non-zero amplitude.
* @see #getWavelength()
* @param wavelength The new wavelength in pixels. No waves are drawn when wavelength is zero.
* @see #getWavelengthDeterminate()
*/
public void setWavelength(@Px int wavelength) {
if (spec.wavelength != wavelength) {
spec.wavelength = abs(wavelength);
requestLayout();
public void setWavelengthDeterminate(@Px int wavelength) {
if (spec.wavelengthDeterminate != wavelength) {
spec.wavelengthDeterminate = abs(wavelength);
if (!isIndeterminate()) {
requestLayout();
}
}
}

/**
* Returns the wavelength, in pixels, of the indicator's waveform in indeterminate mode.
*
* @see #setWavelengthIndeterminate(int)
* @see #setWavelength(int)
*/
@Px
public int getWavelengthIndeterminate() {
return spec.wavelengthIndeterminate;
}

/**
* Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.
*
* @param wavelength The new wavelength in pixels. No waves are drawn when wavelength is zero.
* @see #getWavelengthIndeterminate()
*/
public void setWavelengthIndeterminate(@Px int wavelength) {
if (spec.wavelengthIndeterminate != wavelength) {
spec.wavelengthIndeterminate = abs(wavelength);
if (isIndeterminate()) {
requestLayout();
}
}
}

/**
* Sets the wavelength of the indicator's determinate and indeterminate waveform in pixels.
*
* @param wavelength The new wavelength in pixels. No waves are drawn, if it equals to 0.
* @see #getWavelengthDeterminate()
* @see #getWavelengthIndeterminate()
*/
public void setWavelength(@Px int wavelength) {
setWavelengthDeterminate(wavelength);
setWavelengthIndeterminate(wavelength);
}

/**
* Returns the speed of the indicator's waveform in pixels.
*
* @see #setSpeed(int)
* @see #setWaveSpeed(int)
*/
@Px
public int getSpeed() {
return spec.speed;
public int getWaveSpeed() {
return spec.waveSpeed;
}

/**
* Sets the speed of the indicator's waveform in pixels.
*
* @param speed The new speed in pixels.
* @see #getSpeed()
* @param waveSpeed The new speed in pixels.
* @see #getWaveSpeed()
*/
public void setSpeed(@Px int speed) {
spec.speed = speed;
getProgressDrawable().setEnforcedDrawing(spec.speed != 0);
public void setWaveSpeed(@Px int waveSpeed) {
spec.waveSpeed = waveSpeed;
getProgressDrawable().setEnforcedDrawing(spec.waveSpeed != 0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ public abstract class BaseProgressIndicatorSpec {
/** The size of the gap between the indicator and the rest of the track. */
@Px public int indicatorTrackGapSize;

/** The size of the wavelength, if a wave effect is configured. */
@Px public int wavelength;
/** The size of the wavelength in determinate mode, if a wave effect is configured. */
@Px public int wavelengthDeterminate;

/** The size of the wavelength in indeterminate mode, if a wave effect is configured. */
@Px public int wavelengthIndeterminate;

/** The size of the amplitude, if a wave effect is configured. */
@Px public int amplitude;
@Px public int waveAmplitude;

/** The speed of the waveform, if a wave effect is configured. */
@Px public int speed;
@Px public int waveSpeed;

/**
* Instantiates BaseProgressIndicatorSpec.
Expand Down Expand Up @@ -120,9 +123,18 @@ protected BaseProgressIndicatorSpec(
indicatorTrackGapSize =
a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_indicatorTrackGapSize, 0);

wavelength = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_wavelength, 0));
amplitude = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_amplitude, 0));
speed = a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_speed, 0);
int wavelength = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_wavelength, 0));
wavelengthDeterminate =
abs(
a.getDimensionPixelSize(
R.styleable.BaseProgressIndicator_wavelengthDeterminate, wavelength));
wavelengthIndeterminate =
abs(
a.getDimensionPixelSize(
R.styleable.BaseProgressIndicator_wavelengthIndeterminate, wavelength));
waveAmplitude =
abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_waveAmplitude, 0));
waveSpeed = a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_waveSpeed, 0);

loadIndicatorColors(context, a);
loadTrackColor(context, a);
Expand Down Expand Up @@ -198,8 +210,10 @@ public boolean isHideAnimationEnabled() {
return hideAnimationBehavior != BaseProgressIndicator.HIDE_NONE;
}

public boolean hasWavyEffect() {
return amplitude > 0 && wavelength > 0;
public boolean hasWavyEffect(boolean isDeterminate) {
return waveAmplitude > 0
&& ((!isDeterminate && wavelengthIndeterminate > 0)
|| (isDeterminate && wavelengthDeterminate > 0));
}

@CallSuper
Expand Down
Loading

1 comment on commit af95f45

@AndroidDeveloperLB
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are missing from the release notes, to show that some functions were replaced...
Specifically about the "wave" functions.

Please sign in to comment.