1818
1919import com .google .android .material .R ;
2020
21- import static java .lang .Math .min ;
22-
2321import android .animation .TimeInterpolator ;
2422import android .animation .ValueAnimator ;
2523import android .content .Context ;
@@ -59,6 +57,7 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
5957 private DrawingDelegate <S > drawingDelegate ;
6058
6159 // Animation.
60+ private final SpringForce springForce ;
6261 private final SpringAnimation springAnimation ;
6362 // Active indicator for the progress.
6463 private final ActiveIndicator activeIndicator ;
@@ -84,11 +83,13 @@ public final class DeterminateDrawable<S extends BaseProgressIndicatorSpec>
8483 activeIndicator .isDeterminate = true ;
8584
8685 // Initializes a spring animator for progress animation.
86+ springForce = new SpringForce ();
87+
88+ springForce .setDampingRatio (SpringForce .DAMPING_RATIO_NO_BOUNCY );
89+ springForce .setStiffness (SPRING_FORCE_STIFFNESS );
90+
8791 springAnimation = new SpringAnimation (this , INDICATOR_LENGTH_IN_LEVEL );
88- springAnimation .setSpring (
89- new SpringForce ()
90- .setDampingRatio (SpringForce .DAMPING_RATIO_NO_BOUNCY )
91- .setStiffness (SPRING_FORCE_STIFFNESS ));
92+ springAnimation .setSpring (springForce );
9293
9394 // Initializes a linear animator to enforce phase animation when progress is unchanged.
9495 phaseAnimator = new ValueAnimator ();
@@ -230,9 +231,7 @@ boolean setVisibleInternal(boolean visible, boolean restart, boolean animate) {
230231 skipAnimationOnLevelChange = true ;
231232 } else {
232233 skipAnimationOnLevelChange = false ;
233- springAnimation
234- .getSpring ()
235- .setStiffness (SPRING_FORCE_STIFFNESS / systemAnimatorDurationScale );
234+ springForce .setStiffness (SPRING_FORCE_STIFFNESS / systemAnimatorDurationScale );
236235 }
237236
238237 return changed ;
@@ -261,31 +260,12 @@ protected boolean onLevelChange(int level) {
261260 setIndicatorFraction ((float ) level / MAX_DRAWABLE_LEVEL );
262261 setAmplitudeFraction (nextAmplitudeFraction );
263262 } else {
264- // Update min visible change to the recommended value.
265- updateSpringMinVisibleChange ();
266263 springAnimation .setStartValue (getIndicatorFraction () * MAX_DRAWABLE_LEVEL );
267264 springAnimation .animateToFinalPosition (level );
268265 }
269266 return true ;
270267 }
271268
272- /**
273- * Updates the minimum visible change of the spring animation controlling the indicator length
274- * (progress) to the recommended value based on the track's length.
275- */
276- private void updateSpringMinVisibleChange () {
277- int width = getBounds ().width ();
278- int height = getBounds ().height ();
279- if (drawingDelegate instanceof LinearDrawingDelegate ) {
280- // Track length is the width of the drawable.
281- springAnimation .setMinimumVisibleChange ((float ) MAX_DRAWABLE_LEVEL / width );
282- } else {
283- // Track length is the perimeter of the circle fit in the drawable.
284- springAnimation .setMinimumVisibleChange (
285- (float ) (MAX_DRAWABLE_LEVEL / (min (height , width ) * Math .PI )));
286- }
287- }
288-
289269 @ Override
290270 public int getIntrinsicWidth () {
291271 return drawingDelegate .getPreferredWidth ();
@@ -296,17 +276,6 @@ public int getIntrinsicHeight() {
296276 return drawingDelegate .getPreferredHeight ();
297277 }
298278
299- /** Returns the spring force of the spring animation for the progress. */
300- @ NonNull
301- public SpringForce getSpringForce () {
302- return springAnimation .getSpring ();
303- }
304-
305- /** Sets the spring force of the spring animation for the progress. */
306- public void setSpringForce (@ NonNull SpringForce spring ) {
307- springAnimation .setSpring (spring );
308- }
309-
310279 /**
311280 * Sets the drawable level with a fraction [0,1] of the progress. Note: this function is not used
312281 * to force updating the level in opposite to the automatic level updates by framework {@link
0 commit comments