Skip to content

Commit c1b1d47

Browse files
pekingmepaulfthomas
authored andcommitted
[ProgressIndicator] Internal revert.
PiperOrigin-RevId: 620344595
1 parent 267cb18 commit c1b1d47

File tree

9 files changed

+5
-122
lines changed

9 files changed

+5
-122
lines changed

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -722,26 +722,6 @@ public void setWavelength(@Px int wavelength) {
722722
}
723723
}
724724

725-
/**
726-
* Returns the speed of the indicator's waveform in pixels.
727-
*
728-
* @see #setSpeed(int)
729-
*/
730-
@Px
731-
public int getSpeed() {
732-
return spec.speed;
733-
}
734-
735-
/**
736-
* Sets the speed of the indicator's waveform in pixels.
737-
*
738-
* @param speed The new speed in pixels.
739-
* @see #getSpeed()
740-
*/
741-
public void setSpeed(@Px int speed) {
742-
spec.speed = speed;
743-
}
744-
745725
/**
746726
* Returns the show animation behavior used in this progress indicator.
747727
*

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ public abstract class BaseProgressIndicatorSpec {
7979
/** The size of the amplitude, if a wave effect is configured. */
8080
@Px public int amplitude;
8181

82-
/** The speed of the waveform, if a wave effect is configured. */
83-
@Px public int speed;
84-
8582
/**
8683
* Instantiates BaseProgressIndicatorSpec.
8784
*
@@ -122,7 +119,6 @@ protected BaseProgressIndicatorSpec(
122119

123120
wavelength = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_wavelength, 0));
124121
amplitude = abs(a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_amplitude, 0));
125-
speed = a.getDimensionPixelSize(R.styleable.BaseProgressIndicator_speed, 0);
126122

127123
loadIndicatorColors(context, a);
128124
loadTrackColor(context, a);

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static androidx.core.math.MathUtils.clamp;
1919
import static com.google.android.material.math.MathUtils.lerp;
2020
import static com.google.android.material.progressindicator.BaseProgressIndicator.HIDE_ESCAPE;
21-
import static java.lang.Math.PI;
2221
import static java.lang.Math.max;
2322
import static java.lang.Math.min;
2423
import static java.lang.Math.toDegrees;
@@ -173,7 +172,6 @@ void fillIndicator(
173172
color,
174173
activeIndicator.gapSize,
175174
activeIndicator.gapSize,
176-
activeIndicator.phaseFraction,
177175
/* shouldDrawActiveIndicator= */ true);
178176
}
179177

@@ -195,7 +193,6 @@ void fillTrack(
195193
color,
196194
gapSize,
197195
gapSize,
198-
/* phaseFraction= */ 0f,
199196
/* shouldDrawActiveIndicator= */ false);
200197
}
201198

@@ -210,7 +207,6 @@ void fillTrack(
210207
* @param paintColor The color used to draw the indicator.
211208
* @param startGapSize The gap size applied to the start (rotating behind) of the drawing part.
212209
* @param endGapSize The gap size applied to the end (rotating ahead) of the drawing part.
213-
* @param phaseFraction The fraction [0, 1] of initial phase in one cycle.
214210
* @param shouldDrawActiveIndicator Whether this part should be drawn as an active indicator.
215211
*/
216212
private void drawArc(
@@ -221,7 +217,6 @@ private void drawArc(
221217
@ColorInt int paintColor,
222218
@Px int startGapSize,
223219
@Px int endGapSize,
224-
float phaseFraction,
225220
boolean shouldDrawActiveIndicator) {
226221
float arcFraction =
227222
endFraction >= startFraction
@@ -242,7 +237,6 @@ private void drawArc(
242237
paintColor,
243238
startGapSize,
244239
/* endGapSize= */ 0,
245-
phaseFraction,
246240
shouldDrawActiveIndicator);
247241
drawArc(
248242
canvas,
@@ -252,7 +246,6 @@ private void drawArc(
252246
paintColor,
253247
/* startGapSize= */ 0,
254248
endGapSize,
255-
phaseFraction,
256249
shouldDrawActiveIndicator);
257250
return;
258251
}
@@ -329,8 +322,7 @@ private void drawArc(
329322
activePathMeasure,
330323
displayedActivePath,
331324
startDegreeWithoutCorners / 360,
332-
arcDegreeWithoutCorners / 360,
333-
phaseFraction);
325+
arcDegreeWithoutCorners / 360);
334326
canvas.drawPath(displayedActivePath, paint);
335327
}
336328

@@ -479,11 +471,7 @@ private void appendCubicPerHalfCycle(
479471

480472
@NonNull
481473
private Pair<PathPoint, PathPoint> getDisplayedPath(
482-
@NonNull PathMeasure pathMeasure,
483-
@NonNull Path displayedPath,
484-
float start,
485-
float span,
486-
float phaseFraction) {
474+
@NonNull PathMeasure pathMeasure, @NonNull Path displayedPath, float start, float span) {
487475
if (adjustedRadius != cachedRadius
488476
|| (pathMeasure == activePathMeasure && displayedAmplitude != cachedAmplitude)) {
489477
cachedAmplitude = displayedAmplitude;
@@ -493,12 +481,6 @@ private Pair<PathPoint, PathPoint> getDisplayedPath(
493481
displayedPath.rewind();
494482
span = clamp(span, 0, 1);
495483
float resultRotation = 0;
496-
if (spec.hasWavyEffect()) {
497-
float cycleCount = (float) (2 * PI * adjustedRadius / adjustedWavelength);
498-
float phaseFractionInOneCycle = phaseFraction / cycleCount;
499-
start += phaseFractionInOneCycle;
500-
resultRotation -= phaseFractionInOneCycle * 360;
501-
}
502484
start %= 1;
503485
float startDistance = start * pathMeasure.getLength() / 2;
504486
float endDistance = (start + span) * pathMeasure.getLength() / 2;

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.google.android.material.progressindicator;
1818

19-
import android.animation.ValueAnimator;
2019
import android.content.Context;
2120
import android.graphics.Canvas;
2221
import android.graphics.Paint.Style;
@@ -40,8 +39,6 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
4039
// If the progress is less than 1%, the gap will be proportional to the progress. So that, it
4140
// draws a full track at 0%.
4241
static final float GAP_RAMP_DOWN_THRESHOLD = 0.01f;
43-
// The duration of repeated initial phase animation in ms. It can be any positive values.
44-
private static final int PHASE_ANIMATION_DURATION_MS = 1000;
4542

4643
// Drawing delegate object.
4744
private DrawingDelegate<S> drawingDelegate;
@@ -54,8 +51,6 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
5451
// Whether to skip the spring animation on level change event.
5552
private boolean skipAnimationOnLevelChange = false;
5653

57-
@NonNull private final ValueAnimator phaseAnimator;
58-
5954
DeterminateDrawable(
6055
@NonNull Context context,
6156
@NonNull BaseProgressIndicatorSpec baseSpec,
@@ -65,7 +60,6 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
6560
setDrawingDelegate(drawingDelegate);
6661
activeIndicator = new ActiveIndicator();
6762

68-
// Initializes a spring animator for progress animation.
6963
springForce = new SpringForce();
7064

7165
springForce.setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
@@ -74,19 +68,6 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
7468
springAnimation = new SpringAnimation(this, INDICATOR_LENGTH_IN_LEVEL);
7569
springAnimation.setSpring(springForce);
7670

77-
// Initializes a linear animator to enforce phase animation when progress is unchanged.
78-
phaseAnimator = new ValueAnimator();
79-
phaseAnimator.setDuration(PHASE_ANIMATION_DURATION_MS);
80-
phaseAnimator.setFloatValues(0, 1);
81-
phaseAnimator.setRepeatCount(ValueAnimator.INFINITE);
82-
phaseAnimator.addUpdateListener(
83-
animation -> {
84-
if (baseSpec.speed != 0 && isVisible()) {
85-
invalidateSelf();
86-
}
87-
});
88-
phaseAnimator.start();
89-
9071
setGrowFraction(1f);
9172
}
9273

@@ -255,8 +236,6 @@ public void draw(@NonNull Canvas canvas) {
255236
drawingDelegate.validateSpecAndAdjustCanvas(
256237
canvas, getBounds(), getGrowFraction(), isShowing(), isHiding());
257238

258-
activeIndicator.phaseFraction = getPhaseFraction();
259-
260239
paint.setStyle(Style.FILL);
261240
paint.setAntiAlias(true);
262241

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
*/
4343
abstract class DrawableWithAnimatedVisibilityChange extends Drawable implements Animatable2Compat {
4444

45-
// Constant for mock values used in testing.
46-
private static final float DEFAULT_MOCK_PHASE_FRACTION = -1f;
47-
4845
// Argument restart used in Drawable setVisible() doesn't matter in implementation.
4946
private static final boolean DEFAULT_DRAWABLE_RESTART = false;
5047

@@ -67,7 +64,6 @@ abstract class DrawableWithAnimatedVisibilityChange extends Drawable implements
6764
private boolean mockShowAnimationRunning;
6865
private boolean mockHideAnimationRunning;
6966
private float mockGrowFraction;
70-
private float mockPhaseFraction = DEFAULT_MOCK_PHASE_FRACTION;
7167

7268
// List of AnimationCallback to be called at the end of show/hide animation.
7369
private List<AnimationCallback> animationCallbacks;
@@ -443,29 +439,6 @@ void setMockHideAnimationRunning(
443439
mockGrowFraction = fraction;
444440
}
445441

446-
@VisibleForTesting
447-
void setMockPhaseFraction(@FloatRange(from = 0.0, to = 1.0) float fraction) {
448-
mockPhaseFraction = fraction;
449-
}
450-
451-
float getPhaseFraction() {
452-
if (mockPhaseFraction > 0) {
453-
return mockPhaseFraction;
454-
}
455-
float phaseFraction = 0f;
456-
if (baseSpec.speed != 0) {
457-
float durationScale =
458-
animatorDurationScaleProvider.getSystemAnimatorDurationScale(
459-
context.getContentResolver());
460-
int cycleInMs = (int) (1000f * baseSpec.wavelength / baseSpec.speed * durationScale);
461-
phaseFraction = (float) (System.currentTimeMillis() % cycleInMs) / cycleInMs;
462-
if (phaseFraction < 0f) {
463-
phaseFraction = (phaseFraction % 1) + 1f;
464-
}
465-
}
466-
return phaseFraction;
467-
}
468-
469442
// ******************* Properties *******************
470443

471444
private static final Property<DrawableWithAnimatedVisibilityChange, Float> GROW_FRACTION =

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ protected static class ActiveIndicator {
168168
// active indicator. But for linear contiguous indeterminate mode, the indicators are connecting
169169
// to each other. Gaps are needed in this case.
170170
@Px int gapSize;
171-
172-
// The fraction [0, 1] of the initial phase [0, 2 * PI] on indicator.
173-
@FloatRange(from = 0.0, to = 1.0)
174-
float phaseFraction;
175171
}
176172

177173
/** An entity class for a point on a path, with the support of fundamental operations. */

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ public void draw(@NonNull Canvas canvas) {
250250
indicatorIndex < animatorDelegate.activeIndicators.size();
251251
indicatorIndex++) {
252252
ActiveIndicator curIndicator = animatorDelegate.activeIndicators.get(indicatorIndex);
253-
curIndicator.phaseFraction = getPhaseFraction();
254253
// Draws indicators.
255254
drawingDelegate.fillIndicator(canvas, paint, curIndicator, getAlpha());
256255

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

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ void fillIndicator(
158158
color,
159159
activeIndicator.gapSize,
160160
activeIndicator.gapSize,
161-
activeIndicator.phaseFraction,
162161
/* drawingActiveIndicator= */ true);
163162
}
164163

@@ -180,7 +179,6 @@ void fillTrack(
180179
color,
181180
gapSize,
182181
gapSize,
183-
/* phaseFraction= */ 0f,
184182
/* drawingActiveIndicator= */ false);
185183
}
186184

@@ -194,7 +192,6 @@ void fillTrack(
194192
* @param paintColor The color used to draw the indicator.
195193
* @param startGapSize The gap size applied to the start (left) of the drawing part.
196194
* @param endGapSize The gap size applied to the end (right) of the drawing part.
197-
* @param phaseFraction The fraction [0, 1] of initial phase in one cycle.
198195
* @param drawingActiveIndicator Whether this part should be drawn as an active indicator.
199196
*/
200197
private void drawLine(
@@ -205,7 +202,6 @@ private void drawLine(
205202
@ColorInt int paintColor,
206203
@Px int startGapSize,
207204
@Px int endGapSize,
208-
float phaseFraction,
209205
boolean drawingActiveIndicator) {
210206
startFraction = clamp(startFraction, 0f, 1f);
211207
endFraction = clamp(endFraction, 0f, 1f);
@@ -274,8 +270,7 @@ private void drawLine(
274270
activePathMeasure,
275271
displayedActivePath,
276272
startBlockCenterX / trackLength,
277-
endBlockCenterX / trackLength,
278-
phaseFraction);
273+
endBlockCenterX / trackLength);
279274
canvas.drawPath(displayedActivePath, paint);
280275
}
281276
if (!useStrokeCap && displayedCornerRadius > 0) {
@@ -359,7 +354,7 @@ void invalidateCachedPaths() {
359354
int cycleCount = (int) (trackLength / spec.wavelength);
360355
adjustedWavelength = trackLength / cycleCount;
361356
float smoothness = SINE_WAVE_FORM_SMOOTHNESS;
362-
for (int i = 0; i <= cycleCount; i++) {
357+
for (int i = 0; i < cycleCount; i++) {
363358
cachedActivePath.cubicTo(2 * i + smoothness, 0, 2 * i + 1 - smoothness, 1, 2 * i + 1, 1);
364359
cachedActivePath.cubicTo(
365360
2 * i + 1 + smoothness, 1, 2 * i + 2 - smoothness, 0, 2 * i + 2, 0);
@@ -378,21 +373,9 @@ void invalidateCachedPaths() {
378373

379374
@NonNull
380375
private Pair<PathPoint, PathPoint> getDisplayedPath(
381-
@NonNull PathMeasure pathMeasure,
382-
@NonNull Path displayedPath,
383-
float start,
384-
float end,
385-
float phaseFraction) {
376+
@NonNull PathMeasure pathMeasure, @NonNull Path displayedPath, float start, float end) {
386377
displayedPath.rewind();
387378
float resultTranslationX = -trackLength / 2;
388-
if (spec.hasWavyEffect()) {
389-
float cycleCount = trackLength / adjustedWavelength;
390-
float phaseFractionInPath = phaseFraction / cycleCount;
391-
float ratio = cycleCount / (cycleCount + 1);
392-
start = (start + phaseFractionInPath) * ratio;
393-
end = (end + phaseFractionInPath) * ratio;
394-
resultTranslationX -= phaseFraction * adjustedWavelength;
395-
}
396379
float startDistance = start * pathMeasure.getLength();
397380
float endDistance = end * pathMeasure.getLength();
398381
pathMeasure.getSegment(startDistance, endDistance, displayedPath, true);

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@
9797
Defines the amplitude (in dp) of the wave effect.
9898
-->
9999
<attr name="amplitude" format="dimension"/>
100-
<!--
101-
Defines the wave speed (in dp/s) of the wavy effect. If positive, wave moves towards 100%; if
102-
negative, wave moves towards 0%.
103-
-->
104-
<attr name="speed" format="dimension"/>
105100
</declare-styleable>
106101

107102
<declare-styleable name="LinearProgressIndicator">

0 commit comments

Comments
 (0)