2727import android .content .res .TypedArray ;
2828import android .graphics .Canvas ;
2929import android .graphics .drawable .Drawable ;
30- import android .os .Build .VERSION ;
3130import android .os .SystemClock ;
32- import android .provider .Settings .Global ;
33- import android .provider .Settings .System ;
3431import androidx .core .view .ViewCompat ;
3532import android .util .AttributeSet ;
3633import android .view .View ;
@@ -124,11 +121,11 @@ public class ProgressIndicator extends ProgressBar {
124121
125122 private long lastShowStartTime = -1L ;
126123
127- private boolean animatorDisabled = false ;
128-
129124 /** The scale of the animation speed combining system setting and debug parameters. */
130125 private float systemAnimationScale = 1f ;
131126
127+ private AnimatorDurationScaleProvider animatorDurationScaleProvider ;
128+
132129 // ******************** Interfaces **********************
133130
134131 /** The type of the progress indicator. */
@@ -159,6 +156,7 @@ public ProgressIndicator(
159156 public ProgressIndicator (
160157 @ NonNull Context context , @ Nullable AttributeSet attrs , int defStyleAttr , int defStyleRes ) {
161158 super (wrap (context , attrs , defStyleAttr , DEF_STYLE_RES ), attrs , defStyleAttr );
159+ animatorDurationScaleProvider = new AnimatorDurationScaleProvider ();
162160 isParentDoneInitializing = true ;
163161 // Ensure we are using the correctly themed context rather than the context was passed in.
164162 context = getContext ();
@@ -346,7 +344,9 @@ private void unregisterAnimationCallbacks() {
346344 }
347345
348346 private void updateAnimationScale () {
349- systemAnimationScale = getSystemAnimatorDurationScale ();
347+ systemAnimationScale =
348+ animatorDurationScaleProvider .getSystemAnimatorDurationScale (
349+ getContext ().getContentResolver ());
350350 if (systemAnimationScale > 0 ) {
351351 if (getProgressDrawable () != null ) {
352352 getProgressDrawable ().invalidateAnimationScale (systemAnimationScale );
@@ -356,15 +356,6 @@ private void updateAnimationScale() {
356356
357357 // ******************** Visibility control **********************
358358
359- /**
360- * This method sets a flag to prevent using any animators. It should be called before being
361- * visible.
362- */
363- @ VisibleForTesting
364- public void disableAnimatorsForTesting () {
365- animatorDisabled = true ;
366- }
367-
368359 /**
369360 * Sets the visibility to {@code VISIBLE}. If this changes the visibility it will invoke {@code
370361 * onVisibilityChanged} and handle the visibility with animation of the drawables.
@@ -653,23 +644,9 @@ private void updateColorsInDrawables() {
653644 getIndeterminateDrawable ().getAnimatorDelegate ().invalidateSpecValues ();
654645 }
655646
656- /** Returns the animator duration scale from developer options setting. */
657- private float getSystemAnimatorDurationScale () {
658- if (VERSION .SDK_INT >= 17 ) {
659- return Global .getFloat (getContext ().getContentResolver (), Global .ANIMATOR_DURATION_SCALE , 1f );
660- }
661- if (VERSION .SDK_INT == 16 ) {
662- return System .getFloat (getContext ().getContentResolver (), System .ANIMATOR_DURATION_SCALE , 1f );
663- }
664- return 1f ;
665- }
666-
667- /**
668- * Returns whether the animators are disabled passively (by system settings) or actively (for
669- * testings).
670- */
647+ /** Returns whether the animators are disabled passively (by system settings). */
671648 private boolean isAnimatorDisabled () {
672- return animatorDisabled || systemAnimationScale == 0 ;
649+ return systemAnimationScale == 0 ;
673650 }
674651
675652 // ******************** Getters and setters **********************
@@ -1037,6 +1014,12 @@ && getProgress() != progress
10371014 super .setProgress (progress );
10381015 }
10391016
1017+ @ VisibleForTesting
1018+ public void setAnimatorDurationScaleProvider (
1019+ @ NonNull AnimatorDurationScaleProvider animatorDurationScaleProvider ) {
1020+ this .animatorDurationScaleProvider = animatorDurationScaleProvider ;
1021+ }
1022+
10401023 // ************************ In-place defined parameters ****************************
10411024
10421025 /**
0 commit comments