@@ -121,9 +121,6 @@ public class ProgressIndicator extends ProgressBar {
121121
122122 private long lastShowStartTime = -1L ;
123123
124- /** The scale of the animation speed combining system setting and debug parameters. */
125- private float systemAnimationScale = 1f ;
126-
127124 private AnimatorDurationScaleProvider animatorDurationScaleProvider ;
128125
129126 // ******************** Interfaces **********************
@@ -270,14 +267,15 @@ private void initializeDrawables() {
270267 isLinearSeamless ()
271268 ? new LinearIndeterminateSeamlessAnimatorDelegate ()
272269 : new LinearIndeterminateNonSeamlessAnimatorDelegate (getContext ());
273- setIndeterminateDrawable (new IndeterminateDrawable (spec , drawingDelegate , animatorDelegate ));
274- setProgressDrawable (new DeterminateDrawable (spec , drawingDelegate ));
270+ setIndeterminateDrawable (
271+ new IndeterminateDrawable (getContext (), spec , drawingDelegate , animatorDelegate ));
272+ setProgressDrawable (new DeterminateDrawable (getContext (), spec , drawingDelegate ));
275273 } else {
276274 DrawingDelegate drawingDelegate = new CircularDrawingDelegate ();
277275 setIndeterminateDrawable (
278276 new IndeterminateDrawable (
279- spec , drawingDelegate , new CircularIndeterminateAnimatorDelegate ()));
280- setProgressDrawable (new DeterminateDrawable (spec , drawingDelegate ));
277+ getContext (), spec , drawingDelegate , new CircularIndeterminateAnimatorDelegate ()));
278+ setProgressDrawable (new DeterminateDrawable (getContext (), spec , drawingDelegate ));
281279 }
282280
283281 applyNewVisibility ();
@@ -343,17 +341,6 @@ private void unregisterAnimationCallbacks() {
343341 }
344342 }
345343
346- private void updateAnimationScale () {
347- systemAnimationScale =
348- animatorDurationScaleProvider .getSystemAnimatorDurationScale (
349- getContext ().getContentResolver ());
350- if (systemAnimationScale > 0 ) {
351- if (getProgressDrawable () != null ) {
352- getProgressDrawable ().invalidateAnimationScale (systemAnimationScale );
353- }
354- }
355- }
356-
357344 // ******************** Visibility control **********************
358345
359346 /**
@@ -394,13 +381,12 @@ public void hide() {
394381 */
395382 private void internalHide () {
396383 // Hides animation should be used if it's visible to user and potentially can be hidden with
397- // animation, unless animators are disabled actively.
398- boolean shouldHideAnimated =
399- visibleToUser () && spec .growMode != GROW_MODE_NONE && !isAnimatorDisabled ();
384+ // animation.
385+ boolean shouldHideAnimated = visibleToUser () && spec .growMode != GROW_MODE_NONE ;
400386
401387 getCurrentDrawable ().setVisible (false , shouldHideAnimated );
402388
403- if (! shouldHideAnimated ) {
389+ if (isNoLongerNeedToBeVisible () ) {
404390 setVisibility (INVISIBLE );
405391 }
406392 }
@@ -426,14 +412,12 @@ private void applyNewVisibility() {
426412 return ;
427413 }
428414
429- updateAnimationScale ();
430-
431415 boolean visibleToUser = visibleToUser ();
432416
433417 // Sets the drawable to visible/invisible if the component is currently visible/invisible. Only
434418 // show animation should be started (when the component is currently visible). Hide animation
435419 // should have already ended or is not necessary at this point.
436- getCurrentDrawable ().setVisible (visibleToUser , visibleToUser && ! isAnimatorDisabled () );
420+ getCurrentDrawable ().setVisible (visibleToUser , visibleToUser );
437421 }
438422
439423 @ Override
@@ -550,14 +534,17 @@ public DrawingDelegate getCurrentDrawingDelegate() {
550534 */
551535 @ Override
552536 public void setProgressDrawable (Drawable drawable ) {
553- if (drawable == null || drawable instanceof DeterminateDrawable ) {
537+ if (drawable == null ) {
538+ super .setProgressDrawable (null );
539+ return ;
540+ }
541+ if (drawable instanceof DeterminateDrawable ) {
542+ drawable .setVisible (false , false );
554543 super .setProgressDrawable (drawable );
555544 // Every time ProgressBar sets progress drawable, it refreshes the drawable's level with
556545 // progress then secondary progress. Since secondary progress is not used here. We need to set
557546 // the level actively to overcome the affects from secondary progress.
558- if (drawable != null ) {
559- ((DeterminateDrawable ) drawable ).setLevelByFraction ((float ) getProgress () / getMax ());
560- }
547+ ((DeterminateDrawable ) drawable ).setLevelByFraction ((float ) getProgress () / getMax ());
561548 } else {
562549 throw new IllegalArgumentException ("Cannot set framework drawable as progress drawable." );
563550 }
@@ -570,7 +557,12 @@ public void setProgressDrawable(Drawable drawable) {
570557 */
571558 @ Override
572559 public void setIndeterminateDrawable (Drawable drawable ) {
573- if (drawable == null || drawable instanceof IndeterminateDrawable ) {
560+ if (drawable == null ) {
561+ super .setIndeterminateDrawable (null );
562+ return ;
563+ }
564+ if (drawable instanceof IndeterminateDrawable ) {
565+ drawable .setVisible (false , false );
574566 super .setIndeterminateDrawable (drawable );
575567 } else {
576568 throw new IllegalArgumentException (
@@ -644,9 +636,13 @@ private void updateColorsInDrawables() {
644636 getIndeterminateDrawable ().getAnimatorDelegate ().invalidateSpecValues ();
645637 }
646638
647- /** Returns whether the animators are disabled passively (by system settings). */
648- private boolean isAnimatorDisabled () {
649- return systemAnimationScale == 0 ;
639+ /**
640+ * Returns {@code true} if both drawables are either null or not visible; {@code false},
641+ * otherwise.
642+ */
643+ private boolean isNoLongerNeedToBeVisible () {
644+ return (getProgressDrawable () == null || !getProgressDrawable ().isVisible ())
645+ && (getIndeterminateDrawable () == null || !getIndeterminateDrawable ().isVisible ());
650646 }
651647
652648 // ******************** Getters and setters **********************
@@ -991,33 +987,35 @@ public void setProgressCompat(int progress, boolean animated) {
991987 storedProgress = progress ;
992988 storedProgressAnimated = animated ;
993989
994- updateAnimationScale ();
995-
996- if ( isAnimatorDisabled () ) {
990+ if ( animatorDurationScaleProvider . getSystemAnimatorDurationScale (
991+ getContext (). getContentResolver ())
992+ == 0 ) {
997993 switchIndeterminateModeCallback .onAnimationEnd (getIndeterminateDrawable ());
998994 } else {
999995 getIndeterminateDrawable ().getAnimatorDelegate ().requestCancelAnimatorAfterCurrentCycle ();
1000996 }
1001997 return ;
1002998 }
1003999
1004- // When no progress animation is needed, it will notify the drawable to skip animation on the
1005- // next level change.
1006- if (getProgressDrawable () != null
1007- && getProgress () != progress
1008- && (!animated || isAnimatorDisabled ())) {
1009- getProgressDrawable ().skipNextLevelChange ();
1010- }
1011-
10121000 // Calls ProgressBar setProgress(int) to update the progress value and level. We don't rely on
10131001 // it to draw or animate the indicator.
10141002 super .setProgress (progress );
1003+ // Fast forward to the final state of the determinate animation.
1004+ if (getProgressDrawable () != null && !animated ) {
1005+ getProgressDrawable ().jumpToCurrentState ();
1006+ }
10151007 }
10161008
10171009 @ VisibleForTesting
10181010 public void setAnimatorDurationScaleProvider (
10191011 @ NonNull AnimatorDurationScaleProvider animatorDurationScaleProvider ) {
10201012 this .animatorDurationScaleProvider = animatorDurationScaleProvider ;
1013+ if (getProgressDrawable () != null ) {
1014+ getProgressDrawable ().animatorDurationScaleProvider = animatorDurationScaleProvider ;
1015+ }
1016+ if (getIndeterminateDrawable () != null ) {
1017+ getIndeterminateDrawable ().animatorDurationScaleProvider = animatorDurationScaleProvider ;
1018+ }
10211019 }
10221020
10231021 // ************************ In-place defined parameters ****************************
0 commit comments