16
16
17
17
package com .google .android .material .progressindicator ;
18
18
19
- import com .google .android .material .R ;
20
-
21
- import android .animation .TimeInterpolator ;
22
19
import android .animation .ValueAnimator ;
23
20
import android .content .Context ;
24
21
import android .graphics .Canvas ;
31
28
import androidx .dynamicanimation .animation .FloatPropertyCompat ;
32
29
import androidx .dynamicanimation .animation .SpringAnimation ;
33
30
import androidx .dynamicanimation .animation .SpringForce ;
34
- import com .google .android .material .animation .AnimationUtils ;
35
- import com .google .android .material .motion .MotionUtils ;
36
31
import com .google .android .material .progressindicator .DrawingDelegate .ActiveIndicator ;
37
32
38
33
/** This class draws the graphics for determinate mode. */
39
34
public final class DeterminateDrawable <S extends BaseProgressIndicatorSpec >
40
35
extends DrawableWithAnimatedVisibilityChange {
41
36
// Constants for drawing progress.
42
37
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
-
47
38
// The constant for spring force stiffness.
48
39
private static final float SPRING_FORCE_STIFFNESS = SpringForce .STIFFNESS_VERY_LOW ;
49
40
// If the progress is less than 1%, the gap will be proportional to the progress. So that, it
50
41
// draws a full track at 0%.
51
42
static final float GAP_RAMP_DOWN_THRESHOLD = 0.01f ;
52
43
// The duration of repeated initial phase animation in ms. It can be any positive values.
53
44
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 ;
56
45
57
46
// Drawing delegate object.
58
47
private DrawingDelegate <S > drawingDelegate ;
@@ -62,16 +51,10 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
62
51
private final SpringAnimation springAnimation ;
63
52
// Active indicator for the progress.
64
53
private final ActiveIndicator activeIndicator ;
65
- // Fraction of displayed amplitude.
66
- private float targetAmplitudeFraction ;
67
54
// Whether to skip the spring animation on level change event.
68
55
private boolean skipAnimationOnLevelChange = false ;
69
56
70
57
@ 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 ;
75
58
76
59
DeterminateDrawable (
77
60
@ NonNull Context context ,
@@ -104,25 +87,6 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
104
87
});
105
88
phaseAnimator .start ();
106
89
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
-
126
90
setGrowFraction (1f );
127
91
}
128
92
@@ -245,11 +209,9 @@ public void jumpToCurrentState() {
245
209
*/
246
210
@ Override
247
211
protected boolean onLevelChange (int level ) {
248
- float nextAmplitudeFraction = getAmplitudeFractionFromLevel (level );
249
212
if (skipAnimationOnLevelChange ) {
250
213
springAnimation .skipToEnd ();
251
214
setIndicatorFraction ((float ) level / MAX_DRAWABLE_LEVEL );
252
- setAmplitudeFraction (nextAmplitudeFraction );
253
215
} else {
254
216
springAnimation .setStartValue (getIndicatorFraction () * MAX_DRAWABLE_LEVEL );
255
217
springAnimation .animateToFinalPosition (level );
@@ -278,30 +240,6 @@ void setLevelByFraction(float fraction) {
278
240
setLevel ((int ) (MAX_DRAWABLE_LEVEL * fraction ));
279
241
}
280
242
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
-
305
243
// ******************* Drawing methods *******************
306
244
307
245
@ Override
@@ -368,11 +306,6 @@ private void setIndicatorFraction(float indicatorFraction) {
368
306
invalidateSelf ();
369
307
}
370
308
371
- private void setAmplitudeFraction (float amplitudeFraction ) {
372
- this .activeIndicator .amplitudeFraction = amplitudeFraction ;
373
- invalidateSelf ();
374
- }
375
-
376
309
@ NonNull
377
310
DrawingDelegate <S > getDrawingDelegate () {
378
311
return drawingDelegate ;
@@ -394,7 +327,6 @@ public float getValue(DeterminateDrawable<?> drawable) {
394
327
@ Override
395
328
public void setValue (DeterminateDrawable <?> drawable , float value ) {
396
329
drawable .setIndicatorFraction (value / MAX_DRAWABLE_LEVEL );
397
- drawable .maybeStartAmplitudeAnimator ((int ) value );
398
330
}
399
331
};
400
332
}
0 commit comments