Skip to content

Commit 267cb18

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

File tree

4 files changed

+6
-94
lines changed

4 files changed

+6
-94
lines changed

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ void fillIndicator(
173173
color,
174174
activeIndicator.gapSize,
175175
activeIndicator.gapSize,
176-
activeIndicator.amplitudeFraction,
177176
activeIndicator.phaseFraction,
178177
/* shouldDrawActiveIndicator= */ true);
179178
}
@@ -196,7 +195,6 @@ void fillTrack(
196195
color,
197196
gapSize,
198197
gapSize,
199-
/* amplitudeFraction= */ 0f,
200198
/* phaseFraction= */ 0f,
201199
/* shouldDrawActiveIndicator= */ false);
202200
}
@@ -212,7 +210,6 @@ void fillTrack(
212210
* @param paintColor The color used to draw the indicator.
213211
* @param startGapSize The gap size applied to the start (rotating behind) of the drawing part.
214212
* @param endGapSize The gap size applied to the end (rotating ahead) of the drawing part.
215-
* @param amplitudeFraction The fraction [0, 1] of amplitude applied to the part.
216213
* @param phaseFraction The fraction [0, 1] of initial phase in one cycle.
217214
* @param shouldDrawActiveIndicator Whether this part should be drawn as an active indicator.
218215
*/
@@ -224,7 +221,6 @@ private void drawArc(
224221
@ColorInt int paintColor,
225222
@Px int startGapSize,
226223
@Px int endGapSize,
227-
float amplitudeFraction,
228224
float phaseFraction,
229225
boolean shouldDrawActiveIndicator) {
230226
float arcFraction =
@@ -246,7 +242,6 @@ private void drawArc(
246242
paintColor,
247243
startGapSize,
248244
/* endGapSize= */ 0,
249-
amplitudeFraction,
250245
phaseFraction,
251246
shouldDrawActiveIndicator);
252247
drawArc(
@@ -257,7 +252,6 @@ private void drawArc(
257252
paintColor,
258253
/* startGapSize= */ 0,
259254
endGapSize,
260-
amplitudeFraction,
261255
phaseFraction,
262256
shouldDrawActiveIndicator);
263257
return;
@@ -288,8 +282,7 @@ private void drawArc(
288282
return;
289283
}
290284

291-
boolean shouldDrawWavyPath =
292-
spec.hasWavyEffect() && shouldDrawActiveIndicator && amplitudeFraction > 0f;
285+
boolean shouldDrawWavyPath = spec.hasWavyEffect() && shouldDrawActiveIndicator;
293286

294287
// Sets up the paint.
295288
paint.setAntiAlias(true);
@@ -337,7 +330,6 @@ private void drawArc(
337330
displayedActivePath,
338331
startDegreeWithoutCorners / 360,
339332
arcDegreeWithoutCorners / 360,
340-
amplitudeFraction,
341333
phaseFraction);
342334
canvas.drawPath(displayedActivePath, paint);
343335
}
@@ -428,7 +420,7 @@ void invalidateCachedPaths() {
428420
cachedActivePath.transform(transform);
429421
if (spec.hasWavyEffect()) {
430422
activePathMeasure.setPath(cachedActivePath, false);
431-
createWavyPath(activePathMeasure, cachedActivePath, cachedAmplitude);
423+
createWavyPath(activePathMeasure, cachedActivePath, displayedAmplitude);
432424
}
433425
activePathMeasure.setPath(cachedActivePath, false);
434426
}
@@ -491,12 +483,10 @@ private Pair<PathPoint, PathPoint> getDisplayedPath(
491483
@NonNull Path displayedPath,
492484
float start,
493485
float span,
494-
float amplitudeFraction,
495486
float phaseFraction) {
496487
if (adjustedRadius != cachedRadius
497-
|| (pathMeasure == activePathMeasure
498-
&& displayedAmplitude * amplitudeFraction != cachedAmplitude)) {
499-
cachedAmplitude = displayedAmplitude * amplitudeFraction;
488+
|| (pathMeasure == activePathMeasure && displayedAmplitude != cachedAmplitude)) {
489+
cachedAmplitude = displayedAmplitude;
500490
cachedRadius = adjustedRadius;
501491
invalidateCachedPaths();
502492
}

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

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

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

19-
import com.google.android.material.R;
20-
21-
import android.animation.TimeInterpolator;
2219
import android.animation.ValueAnimator;
2320
import android.content.Context;
2421
import android.graphics.Canvas;
@@ -31,28 +28,20 @@
3128
import androidx.dynamicanimation.animation.FloatPropertyCompat;
3229
import androidx.dynamicanimation.animation.SpringAnimation;
3330
import androidx.dynamicanimation.animation.SpringForce;
34-
import com.google.android.material.animation.AnimationUtils;
35-
import com.google.android.material.motion.MotionUtils;
3631
import com.google.android.material.progressindicator.DrawingDelegate.ActiveIndicator;
3732

3833
/** This class draws the graphics for determinate mode. */
3934
public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
4035
extends DrawableWithAnimatedVisibilityChange {
4136
// Constants for drawing progress.
4237
private static final int MAX_DRAWABLE_LEVEL = 10000;
43-
// Constants for amplitude animation.
44-
private static final float FULL_AMPLITUDE_FRACTION_MIN = 0.1f;
45-
private static final float FULL_AMPLITUDE_FRACTION_MAX = 0.9f;
46-
4738
// The constant for spring force stiffness.
4839
private static final float SPRING_FORCE_STIFFNESS = SpringForce.STIFFNESS_VERY_LOW;
4940
// If the progress is less than 1%, the gap will be proportional to the progress. So that, it
5041
// draws a full track at 0%.
5142
static final float GAP_RAMP_DOWN_THRESHOLD = 0.01f;
5243
// The duration of repeated initial phase animation in ms. It can be any positive values.
5344
private static final int PHASE_ANIMATION_DURATION_MS = 1000;
54-
// The duration of amplitude ramping animation in ms.
55-
private static final int AMPLITUDE_ANIMATION_DURATION_MS = 500;
5645

5746
// Drawing delegate object.
5847
private DrawingDelegate<S> drawingDelegate;
@@ -62,16 +51,10 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
6251
private final SpringAnimation springAnimation;
6352
// Active indicator for the progress.
6453
private final ActiveIndicator activeIndicator;
65-
// Fraction of displayed amplitude.
66-
private float targetAmplitudeFraction;
6754
// Whether to skip the spring animation on level change event.
6855
private boolean skipAnimationOnLevelChange = false;
6956

7057
@NonNull private final ValueAnimator phaseAnimator;
71-
@NonNull private final ValueAnimator amplitudeAnimator;
72-
private TimeInterpolator amplitudeInterpolator;
73-
@NonNull private final TimeInterpolator amplitudeOnInterpolator;
74-
@NonNull private final TimeInterpolator amplitudeOffInterpolator;
7558

7659
DeterminateDrawable(
7760
@NonNull Context context,
@@ -104,25 +87,6 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
10487
});
10588
phaseAnimator.start();
10689

107-
// Initializes a linear animator to turn on/off wave amplitude.
108-
amplitudeOnInterpolator =
109-
MotionUtils.resolveThemeInterpolator(
110-
context, R.attr.motionEasingStandardInterpolator, AnimationUtils.LINEAR_INTERPOLATOR);
111-
amplitudeOffInterpolator =
112-
MotionUtils.resolveThemeInterpolator(
113-
context,
114-
R.attr.motionEasingEmphasizedAccelerateInterpolator,
115-
AnimationUtils.LINEAR_INTERPOLATOR);
116-
amplitudeAnimator = new ValueAnimator();
117-
amplitudeAnimator.setDuration(AMPLITUDE_ANIMATION_DURATION_MS);
118-
amplitudeAnimator.setFloatValues(0, 1);
119-
amplitudeAnimator.setInterpolator(null);
120-
amplitudeAnimator.addUpdateListener(
121-
animation -> {
122-
activeIndicator.amplitudeFraction =
123-
amplitudeInterpolator.getInterpolation(amplitudeAnimator.getAnimatedFraction());
124-
});
125-
12690
setGrowFraction(1f);
12791
}
12892

@@ -245,11 +209,9 @@ public void jumpToCurrentState() {
245209
*/
246210
@Override
247211
protected boolean onLevelChange(int level) {
248-
float nextAmplitudeFraction = getAmplitudeFractionFromLevel(level);
249212
if (skipAnimationOnLevelChange) {
250213
springAnimation.skipToEnd();
251214
setIndicatorFraction((float) level / MAX_DRAWABLE_LEVEL);
252-
setAmplitudeFraction(nextAmplitudeFraction);
253215
} else {
254216
springAnimation.setStartValue(getIndicatorFraction() * MAX_DRAWABLE_LEVEL);
255217
springAnimation.animateToFinalPosition(level);
@@ -278,30 +240,6 @@ void setLevelByFraction(float fraction) {
278240
setLevel((int) (MAX_DRAWABLE_LEVEL * fraction));
279241
}
280242

281-
private float getAmplitudeFractionFromLevel(int level) {
282-
return level >= FULL_AMPLITUDE_FRACTION_MIN * MAX_DRAWABLE_LEVEL
283-
&& level <= FULL_AMPLITUDE_FRACTION_MAX * MAX_DRAWABLE_LEVEL
284-
? 1f
285-
: 0f;
286-
}
287-
288-
private void maybeStartAmplitudeAnimator(int level) {
289-
float newAmplitudeFraction = getAmplitudeFractionFromLevel(level);
290-
if (newAmplitudeFraction != targetAmplitudeFraction) {
291-
if (amplitudeAnimator.isRunning()) {
292-
amplitudeAnimator.cancel();
293-
}
294-
targetAmplitudeFraction = newAmplitudeFraction;
295-
if (targetAmplitudeFraction == 1f) {
296-
amplitudeInterpolator = amplitudeOnInterpolator;
297-
amplitudeAnimator.start();
298-
} else {
299-
amplitudeInterpolator = amplitudeOffInterpolator;
300-
amplitudeAnimator.reverse();
301-
}
302-
}
303-
}
304-
305243
// ******************* Drawing methods *******************
306244

307245
@Override
@@ -368,11 +306,6 @@ private void setIndicatorFraction(float indicatorFraction) {
368306
invalidateSelf();
369307
}
370308

371-
private void setAmplitudeFraction(float amplitudeFraction) {
372-
this.activeIndicator.amplitudeFraction = amplitudeFraction;
373-
invalidateSelf();
374-
}
375-
376309
@NonNull
377310
DrawingDelegate<S> getDrawingDelegate() {
378311
return drawingDelegate;
@@ -394,7 +327,6 @@ public float getValue(DeterminateDrawable<?> drawable) {
394327
@Override
395328
public void setValue(DeterminateDrawable<?> drawable, float value) {
396329
drawable.setIndicatorFraction(value / MAX_DRAWABLE_LEVEL);
397-
drawable.maybeStartAmplitudeAnimator((int) value);
398330
}
399331
};
400332
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ protected static class ActiveIndicator {
169169
// to each other. Gaps are needed in this case.
170170
@Px int gapSize;
171171

172-
// The fraction [0, 1] of the amplitude on indicator.
173-
@FloatRange(from = 0.0, to = 1.0)
174-
float amplitudeFraction = 1;
175-
176172
// The fraction [0, 1] of the initial phase [0, 2 * PI] on indicator.
177173
@FloatRange(from = 0.0, to = 1.0)
178174
float phaseFraction;

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

Lines changed: 2 additions & 8 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.amplitudeFraction,
162161
activeIndicator.phaseFraction,
163162
/* drawingActiveIndicator= */ true);
164163
}
@@ -181,7 +180,6 @@ void fillTrack(
181180
color,
182181
gapSize,
183182
gapSize,
184-
/* amplitudeFraction= */ 0f,
185183
/* phaseFraction= */ 0f,
186184
/* drawingActiveIndicator= */ false);
187185
}
@@ -196,7 +194,6 @@ void fillTrack(
196194
* @param paintColor The color used to draw the indicator.
197195
* @param startGapSize The gap size applied to the start (left) of the drawing part.
198196
* @param endGapSize The gap size applied to the end (right) of the drawing part.
199-
* @param amplitudeFraction The fraction [0, 1] of amplitude applied to the part.
200197
* @param phaseFraction The fraction [0, 1] of initial phase in one cycle.
201198
* @param drawingActiveIndicator Whether this part should be drawn as an active indicator.
202199
*/
@@ -208,7 +205,6 @@ private void drawLine(
208205
@ColorInt int paintColor,
209206
@Px int startGapSize,
210207
@Px int endGapSize,
211-
float amplitudeFraction,
212208
float phaseFraction,
213209
boolean drawingActiveIndicator) {
214210
startFraction = clamp(startFraction, 0f, 1f);
@@ -234,7 +230,7 @@ private void drawLine(
234230
// Adjusts start/end X so the progress indicator will start from 0 when startFraction == 0.
235231
float originX = -trackLength / 2;
236232

237-
boolean drawWavyPath = spec.hasWavyEffect() && drawingActiveIndicator && amplitudeFraction > 0f;
233+
boolean drawWavyPath = spec.hasWavyEffect() && drawingActiveIndicator;
238234

239235
// No need to draw on track if start and end are out of visible range.
240236
if (startPx <= endPx) {
@@ -279,7 +275,6 @@ private void drawLine(
279275
displayedActivePath,
280276
startBlockCenterX / trackLength,
281277
endBlockCenterX / trackLength,
282-
amplitudeFraction,
283278
phaseFraction);
284279
canvas.drawPath(displayedActivePath, paint);
285280
}
@@ -387,7 +382,6 @@ private Pair<PathPoint, PathPoint> getDisplayedPath(
387382
@NonNull Path displayedPath,
388383
float start,
389384
float end,
390-
float amplitudeFraction,
391385
float phaseFraction) {
392386
displayedPath.rewind();
393387
float resultTranslationX = -trackLength / 2;
@@ -413,7 +407,7 @@ private Pair<PathPoint, PathPoint> getDisplayedPath(
413407
startPoint.translate(resultTranslationX, 0);
414408
endPoint.translate(resultTranslationX, 0);
415409
if (spec.hasWavyEffect()) {
416-
float scaleY = displayedAmplitude * amplitudeFraction;
410+
float scaleY = displayedAmplitude;
417411
transform.postScale(1, scaleY);
418412
startPoint.scale(1, scaleY);
419413
endPoint.scale(1, scaleY);

0 commit comments

Comments
 (0)