diff --git a/catalog/java/io/material/catalog/progressindicator/ProgressIndicatorWaveDemoFragment.java b/catalog/java/io/material/catalog/progressindicator/ProgressIndicatorWaveDemoFragment.java index 419f81f36dd..77294a32b89 100644 --- a/catalog/java/io/material/catalog/progressindicator/ProgressIndicatorWaveDemoFragment.java +++ b/catalog/java/io/material/catalog/progressindicator/ProgressIndicatorWaveDemoFragment.java @@ -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); } }); diff --git a/docs/components/ProgressIndicator.md b/docs/components/ProgressIndicator.md index f6198fa67d1..2f6e293840b 100644 --- a/docs/components/ProgressIndicator.md +++ b/docs/components/ProgressIndicator.md @@ -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`
`getTrackThickness` | `4dp` | -| **Indicator color** | `app:indicatorColor` | `setIndicatorColor`
`getIndicatorColor` | `colorPrimary` | -| **Track color** | `app:trackColor` | `setTrackColor`
`getTrackColor` | `colorPrimaryContainer` (linear)
`@android:color/transparent` (circular) | -| **Track corner radius** | `app:trackCornerRadius` | `setTrackCornerRadius`
`getTrackCornerRadius` | `2dp` | -| **Indicator track gap size** | `app:indicatorTrackGapSize` | `setIndicatorTrackGapSize`
`getIndicatorTrackGapSize` | `4dp` | -| **Show animation behavior** | `app:showAnimationBehavior` | `setShowAnimationBehavior`
`getShowAnimationBehavior` | `none` | -| **Hide animation behavior** | `app:hideAnimationBehavior` | `setHideAnimationBehavior`
`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`
`getTrackThickness` | `4dp` +**Indicator color** | `app:indicatorColor` | `setIndicatorColor`
`getIndicatorColor` | `colorPrimary` +**Track color** | `app:trackColor` | `setTrackColor`
`getTrackColor` | `colorPrimaryContainer` (linear)
`@android:color/transparent` (circular) +**Track corner radius** | `app:trackCornerRadius` | `setTrackCornerRadius`
`getTrackCornerRadius` | `2dp` +**Indicator track gap size** | `app:indicatorTrackGapSize` | `setIndicatorTrackGapSize`
`getIndicatorTrackGapSize` | `4dp` +**Show animation behavior** | `app:showAnimationBehavior` | `setShowAnimationBehavior`
`getShowAnimationBehavior` | `none` +**Hide animation behavior** | `app:hideAnimationBehavior` | `setHideAnimationBehavior`
`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`
`getWavelenthDeterminate` | `wavelength` +**Wavelength in indeterminate mode** | `app:wavelengthIndeterminate` | `setWavelengthIndeterminate`
`getWavelengthIndeterminate` | `wavelength` +**Wave amplitude** | `app:waveAmplitude` | `setWaveAmplitude`
`getWaveAmplitude` | 0 +**Wave speed** | `app:waveSpeed` | `setWaveSpeed`
`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`
`getIndeterminateAnimationType` | `disjoint` | -| **Indicator direction** | `app:indicatorDirectionLinear` | `setIndicatorDirection`
`getIndicatorDirection` | `leftToRight` | -| **Track stop indicator size** | `app:trackStopIndicatorSize` | `setTrackStopIndicatorSize`
`getTrackStopIndicatorSize` | `4dp` | +Element | Attribute | Related method(s) | Default value +-------------------------------- | -------------------------------- | ------------------------------------------------------------------- | ------------- +**Indeterminate animation type** | `app:indeterminateAnimationType` | `setIndeterminateAnimationType`
`getIndeterminateAnimationType` | `disjoint` +**Indicator direction** | `app:indicatorDirectionLinear` | `setIndicatorDirection`
`getIndicatorDirection` | `leftToRight` +**Track stop indicator size** | `app:trackStopIndicatorSize` | `setTrackStopIndicatorSize`
`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`
`getIndicatorSize` | `40dp` -**Inset** | `app:indicatorInset` | `setIndicatorInset`
`getIndicatorInset` | `4dp` -**Indicator direction** | `app:indicatorDirectionCircular` | `setIndicatorDirection`
`getIndicatorDirection` | `clockwise` +Element | Attribute | Related method(s) | Default value +--------------------------------- | ---------------------------------------- | ------------------------------------------------------------------- | ------------- +**Spinner size (outer diameter)** | `app:indicatorSize` | `setIndicatorSize`
`getIndicatorSize` | `40dp` +**Inset** | `app:indicatorInset` | `setIndicatorInset`
`getIndicatorInset` | `4dp` +**Indicator direction** | `app:indicatorDirectionCircular` | `setIndicatorDirection`
`getIndicatorDirection` | `clockwise` +**Indeterminate animation type** | `app:indeterminateAnimationTypeCircular` | `setIndeterminateAnimationType`
`getIndeterminateAnimationType` | `advance` #### Styles diff --git a/lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java b/lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java index 7918124c6f1..8de4b0d1f80 100644 --- a/lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java +++ b/lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java @@ -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); } /** diff --git a/lib/java/com/google/android/material/progressindicator/BaseProgressIndicatorSpec.java b/lib/java/com/google/android/material/progressindicator/BaseProgressIndicatorSpec.java index fce9375b7ae..91312f2db78 100644 --- a/lib/java/com/google/android/material/progressindicator/BaseProgressIndicatorSpec.java +++ b/lib/java/com/google/android/material/progressindicator/BaseProgressIndicatorSpec.java @@ -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. @@ -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); @@ -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 diff --git a/lib/java/com/google/android/material/progressindicator/CircularDrawingDelegate.java b/lib/java/com/google/android/material/progressindicator/CircularDrawingDelegate.java index 8f26005748d..f896ed89cdf 100644 --- a/lib/java/com/google/android/material/progressindicator/CircularDrawingDelegate.java +++ b/lib/java/com/google/android/material/progressindicator/CircularDrawingDelegate.java @@ -57,9 +57,11 @@ final class CircularDrawingDelegate extends DrawingDelegate 0f; + spec.hasWavyEffect(drawingDeterminateIndicator) + && shouldDrawActiveIndicator + && amplitudeFraction > 0f; // Sets up the paint. paint.setAntiAlias(true); @@ -448,7 +454,7 @@ void invalidateCachedPaths() { Matrix transform = new Matrix(); transform.setScale(adjustedRadius, adjustedRadius); cachedActivePath.transform(transform); - if (spec.hasWavyEffect()) { + if (spec.hasWavyEffect(drawingDeterminateIndicator)) { activePathMeasure.setPath(cachedActivePath, false); createWavyPath(activePathMeasure, cachedActivePath, cachedAmplitude); } @@ -460,7 +466,9 @@ private void createWavyPath( outPath.rewind(); // Calculates anchor points. float basePathLength = basePathMeasure.getLength(); - int cycleCountInPath = 2 * max(3, (int) (basePathLength / spec.wavelength / 2)); + int wavelength = + drawingDeterminateIndicator ? spec.wavelengthDeterminate : spec.wavelengthIndeterminate; + int cycleCountInPath = 2 * max(3, (int) (basePathLength / wavelength / 2)); adjustedWavelength = basePathLength / cycleCountInPath; // For each cycle, there will be 2 cubic beziers, which need 3 anchors (startAnchor and // midAnchor for the 1st cubic bezier; midAnchor and startAnchor of the next cycle for the 2nd @@ -516,16 +524,20 @@ private Pair getDisplayedPath( float amplitudeFraction, float phaseFraction) { float amplitude = displayedAmplitude * amplitudeFraction; + int wavelength = + drawingDeterminateIndicator ? spec.wavelengthDeterminate : spec.wavelengthIndeterminate; if (adjustedRadius != cachedRadius - || (pathMeasure == activePathMeasure && amplitude != cachedAmplitude)) { + || (pathMeasure == activePathMeasure + && (amplitude != cachedAmplitude || wavelength != cachedWavelength))) { cachedAmplitude = amplitude; + cachedWavelength = wavelength; cachedRadius = adjustedRadius; invalidateCachedPaths(); } displayedPath.rewind(); span = clamp(span, 0, 1); float resultRotation = 0; - if (spec.hasWavyEffect()) { + if (spec.hasWavyEffect(drawingDeterminateIndicator)) { float cycleCount = (float) (2 * PI * adjustedRadius / adjustedWavelength); float phaseFractionInOneCycle = phaseFraction / cycleCount; start += phaseFractionInOneCycle; diff --git a/lib/java/com/google/android/material/progressindicator/DeterminateDrawable.java b/lib/java/com/google/android/material/progressindicator/DeterminateDrawable.java index 14500cd56f0..e60e6f6516b 100644 --- a/lib/java/com/google/android/material/progressindicator/DeterminateDrawable.java +++ b/lib/java/com/google/android/material/progressindicator/DeterminateDrawable.java @@ -99,11 +99,13 @@ public final class DeterminateDrawable phaseAnimator.setRepeatCount(ValueAnimator.INFINITE); phaseAnimator.addUpdateListener( animation -> { - if (baseSpec.hasWavyEffect() && baseSpec.speed != 0 && isVisible()) { + if (baseSpec.hasWavyEffect(/* isDeterminate= */ true) + && baseSpec.waveSpeed != 0 + && isVisible()) { invalidateSelf(); } }); - if (baseSpec.hasWavyEffect() && baseSpec.speed != 0) { + if (baseSpec.hasWavyEffect(/* isDeterminate= */ true) && baseSpec.waveSpeed != 0) { phaseAnimator.start(); } @@ -294,7 +296,7 @@ private float getAmplitudeFractionFromLevel(int level) { } private void maybeStartAmplitudeAnimator(int level) { - if (!baseSpec.hasWavyEffect()) { + if (!baseSpec.hasWavyEffect(/* isDeterminate= */ true)) { return; } maybeInitializeAmplitudeAnimator(); diff --git a/lib/java/com/google/android/material/progressindicator/DrawableWithAnimatedVisibilityChange.java b/lib/java/com/google/android/material/progressindicator/DrawableWithAnimatedVisibilityChange.java index f6992aa3c93..c73d6036e86 100644 --- a/lib/java/com/google/android/material/progressindicator/DrawableWithAnimatedVisibilityChange.java +++ b/lib/java/com/google/android/material/progressindicator/DrawableWithAnimatedVisibilityChange.java @@ -220,12 +220,12 @@ public boolean isHiding() { /** Hides the drawable immediately without triggering animation callbacks. */ public boolean hideNow() { - return setVisible(/*visible=*/ false, /*restart=*/ false, /*animate=*/ false); + return setVisible(/* visible= */ false, /* restart= */ false, /* animate= */ false); } @Override public boolean setVisible(boolean visible, boolean restart) { - return setVisible(visible, restart, /*animate=*/ true); + return setVisible(visible, restart, /* animate= */ true); } /** @@ -453,12 +453,16 @@ float getPhaseFraction() { } float phaseFraction = 0f; - if (baseSpec.hasWavyEffect() && baseSpec.speed != 0) { + if (baseSpec.hasWavyEffect(isDeterminateDrawable()) && baseSpec.waveSpeed != 0) { float durationScale = animatorDurationScaleProvider.getSystemAnimatorDurationScale( context.getContentResolver()); if (durationScale > 0f) { - int cycleInMs = (int) (1000f * baseSpec.wavelength / baseSpec.speed * durationScale); + int wavelength = + isDeterminateDrawable() + ? baseSpec.wavelengthDeterminate + : baseSpec.wavelengthIndeterminate; + int cycleInMs = (int) (1000f * wavelength / baseSpec.waveSpeed * durationScale); phaseFraction = (float) (System.currentTimeMillis() % cycleInMs) / cycleInMs; if (phaseFraction < 0f) { phaseFraction = (phaseFraction % 1) + 1f; @@ -468,6 +472,10 @@ float getPhaseFraction() { return phaseFraction; } + private boolean isDeterminateDrawable() { + return this instanceof DeterminateDrawable; + } + // ******************* Properties ******************* private static final Property GROW_FRACTION = diff --git a/lib/java/com/google/android/material/progressindicator/IndeterminateDrawable.java b/lib/java/com/google/android/material/progressindicator/IndeterminateDrawable.java index 7b92c24a8a9..e53751cb980 100644 --- a/lib/java/com/google/android/material/progressindicator/IndeterminateDrawable.java +++ b/lib/java/com/google/android/material/progressindicator/IndeterminateDrawable.java @@ -207,7 +207,8 @@ public void draw(@NonNull Canvas canvas) { baseSpec instanceof LinearProgressIndicatorSpec || (baseSpec instanceof CircularProgressIndicatorSpec && ((CircularProgressIndicatorSpec) baseSpec).indeterminateTrackVisible); - boolean drawFullTrack = drawTrack && gapSize == 0 && !baseSpec.hasWavyEffect(); + boolean drawFullTrack = + drawTrack && gapSize == 0 && !baseSpec.hasWavyEffect(/* isDeterminate= */ false); if (drawFullTrack) { drawingDelegate.fillTrack( diff --git a/lib/java/com/google/android/material/progressindicator/LinearDrawingDelegate.java b/lib/java/com/google/android/material/progressindicator/LinearDrawingDelegate.java index 98cf60fbddc..57bf56e6148 100644 --- a/lib/java/com/google/android/material/progressindicator/LinearDrawingDelegate.java +++ b/lib/java/com/google/android/material/progressindicator/LinearDrawingDelegate.java @@ -54,7 +54,9 @@ final class LinearDrawingDelegate extends DrawingDelegate 0f; + boolean drawWavyPath = + spec.hasWavyEffect(drawingDeterminateIndicator) + && drawingActiveIndicator + && amplitudeFraction > 0f; // No need to draw on track if start and end are out of visible range. if (startPx <= endPx) { @@ -304,6 +311,7 @@ void drawStopIndicator( @ColorInt int color, @IntRange(from = 0, to = 255) int drawableAlpha) { int paintColor = MaterialColors.compositeARGBWithAlpha(color, drawableAlpha); + drawingDeterminateIndicator = false; if (spec.trackStopIndicatorSize > 0 && paintColor != Color.TRANSPARENT) { // Draws the stop indicator at the end of the track if needed. paint.setStyle(Style.FILL); @@ -360,8 +368,10 @@ private void drawRoundedBlock( @Override void invalidateCachedPaths() { cachedActivePath.rewind(); - if (spec.hasWavyEffect()) { - int cycleCount = (int) (trackLength / spec.wavelength); + if (spec.hasWavyEffect(drawingDeterminateIndicator)) { + int wavelength = + drawingDeterminateIndicator ? spec.wavelengthDeterminate : spec.wavelengthIndeterminate; + int cycleCount = (int) (trackLength / wavelength); adjustedWavelength = trackLength / cycleCount; float smoothness = WAVE_SMOOTHNESS; for (int i = 0; i <= cycleCount; i++) { @@ -389,9 +399,16 @@ private Pair getDisplayedPath( float end, float amplitudeFraction, float phaseFraction) { + int wavelength = + drawingDeterminateIndicator ? spec.wavelengthDeterminate : spec.wavelengthIndeterminate; + if (pathMeasure == activePathMeasure && wavelength != cachedWavelength) { + cachedWavelength = wavelength; + invalidateCachedPaths(); + } displayedPath.rewind(); float resultTranslationX = -trackLength / 2; - if (spec.hasWavyEffect()) { + boolean hasWavyEffect = spec.hasWavyEffect(drawingDeterminateIndicator); + if (hasWavyEffect) { float cycleCount = trackLength / adjustedWavelength; float phaseFractionInPath = phaseFraction / cycleCount; float ratio = cycleCount / (cycleCount + 1); @@ -412,7 +429,7 @@ private Pair getDisplayedPath( transform.setTranslate(resultTranslationX, 0); startPoint.translate(resultTranslationX, 0); endPoint.translate(resultTranslationX, 0); - if (spec.hasWavyEffect()) { + if (hasWavyEffect) { float scaleY = displayedAmplitude * amplitudeFraction; transform.postScale(1, scaleY); startPoint.scale(1, scaleY); diff --git a/lib/java/com/google/android/material/progressindicator/res-public/values/public.xml b/lib/java/com/google/android/material/progressindicator/res-public/values/public.xml index 9c9f3381022..cb4773df130 100644 --- a/lib/java/com/google/android/material/progressindicator/res-public/values/public.xml +++ b/lib/java/com/google/android/material/progressindicator/res-public/values/public.xml @@ -27,19 +27,28 @@ + + + + + + + + + + - diff --git a/lib/java/com/google/android/material/progressindicator/res/values/attrs.xml b/lib/java/com/google/android/material/progressindicator/res/values/attrs.xml index 9dfc9d53527..71639dd2f45 100644 --- a/lib/java/com/google/android/material/progressindicator/res/values/attrs.xml +++ b/lib/java/com/google/android/material/progressindicator/res/values/attrs.xml @@ -93,15 +93,25 @@ Defines the wavelength (in dp) of the wave effect. --> + + + + - + - + @@ -109,8 +119,7 @@