From 6deaaaa5d1f06d631326d480b6bb2500f84f7700 Mon Sep 17 00:00:00 2001 From: pubiqq Date: Thu, 1 May 2025 17:34:01 +0300 Subject: [PATCH] [LoadingIndicator] Teach LoadingIndicatorDrawable to get the animator duration scale --- .../material/loadingindicator/LoadingIndicator.java | 1 - .../loadingindicator/LoadingIndicatorDrawable.java | 13 +++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/java/com/google/android/material/loadingindicator/LoadingIndicator.java b/lib/java/com/google/android/material/loadingindicator/LoadingIndicator.java index 5bd237132d9..244d8956871 100644 --- a/lib/java/com/google/android/material/loadingindicator/LoadingIndicator.java +++ b/lib/java/com/google/android/material/loadingindicator/LoadingIndicator.java @@ -74,7 +74,6 @@ public LoadingIndicator( drawable.setCallback(this); specs = drawable.getDrawingDelegate().specs; - setAnimatorDurationScaleProvider(new AnimatorDurationScaleProvider()); } @Override diff --git a/lib/java/com/google/android/material/loadingindicator/LoadingIndicatorDrawable.java b/lib/java/com/google/android/material/loadingindicator/LoadingIndicatorDrawable.java index 1c5c407d19c..a83da08eda7 100644 --- a/lib/java/com/google/android/material/loadingindicator/LoadingIndicatorDrawable.java +++ b/lib/java/com/google/android/material/loadingindicator/LoadingIndicatorDrawable.java @@ -33,7 +33,6 @@ /** This class draws the graphics for a loading indicator. */ public final class LoadingIndicatorDrawable extends Drawable implements Drawable.Callback { - AnimatorDurationScaleProvider animatorDurationScaleProvider; @NonNull private final Context context; @NonNull private final LoadingIndicatorSpec specs; @@ -41,6 +40,7 @@ public final class LoadingIndicatorDrawable extends Drawable implements Drawable @NonNull private LoadingIndicatorAnimatorDelegate animatorDelegate; @NonNull Paint paint; + @NonNull AnimatorDurationScaleProvider animatorDurationScaleProvider; @IntRange(from = 0, to = 255) int alpha; @@ -68,6 +68,7 @@ public static LoadingIndicatorDrawable create( this.animatorDelegate = animatorDelegate; this.paint = new Paint(); + this.animatorDurationScaleProvider = new AnimatorDurationScaleProvider(); animatorDelegate.registerDrawable(this); setAlpha(255); @@ -187,13 +188,9 @@ public void unscheduleDrawable(@NonNull Drawable who, @NonNull Runnable what) { // ******************* Utility functions ******************* private boolean isSystemAnimatorDisabled() { - if (animatorDurationScaleProvider != null) { - float systemAnimatorDurationScale = - animatorDurationScaleProvider.getSystemAnimatorDurationScale( - context.getContentResolver()); - return systemAnimatorDurationScale == 0; - } - return false; + float systemAnimatorDurationScale = + animatorDurationScaleProvider.getSystemAnimatorDurationScale(context.getContentResolver()); + return systemAnimatorDurationScale == 0; } // ******************* Setter and getter *******************