From b70b03da810274c30ed7c7f8c2ebfa14b5ae2206 Mon Sep 17 00:00:00 2001 From: Pranay Airan Date: Tue, 3 Sep 2024 14:54:42 -0700 Subject: [PATCH] adding null check for context adding null check for context --- lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java | 2 +- .../configurations/reducemotion/ReducedMotionOption.java | 3 ++- .../reducemotion/SystemReducedMotionOption.java | 5 +++-- lottie/src/main/java/com/airbnb/lottie/utils/Utils.java | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java index 38abec2684..2ef5259b03 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java @@ -1245,7 +1245,7 @@ boolean isAnimatingOrWillAnimateOnVisible() { } } - public boolean animationsEnabled(Context context) { + public boolean animationsEnabled(@Nullable Context context) { if (ignoreSystemAnimationsDisabled) { return true; } diff --git a/lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/ReducedMotionOption.java b/lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/ReducedMotionOption.java index 85d1ae2a24..7ecdee3945 100644 --- a/lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/ReducedMotionOption.java +++ b/lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/ReducedMotionOption.java @@ -1,11 +1,12 @@ package com.airbnb.lottie.configurations.reducemotion; import android.content.Context; +import androidx.annotation.Nullable; public interface ReducedMotionOption { /** * Returns the current reduced motion mode. */ - ReducedMotionMode getCurrentReducedMotionMode(Context context); + ReducedMotionMode getCurrentReducedMotionMode(@Nullable Context context); } diff --git a/lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/SystemReducedMotionOption.java b/lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/SystemReducedMotionOption.java index d69f55efa4..f182a5f5e7 100644 --- a/lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/SystemReducedMotionOption.java +++ b/lottie/src/main/java/com/airbnb/lottie/configurations/reducemotion/SystemReducedMotionOption.java @@ -1,6 +1,7 @@ package com.airbnb.lottie.configurations.reducemotion; import android.content.Context; +import androidx.annotation.Nullable; import com.airbnb.lottie.utils.Utils; /** @@ -18,8 +19,8 @@ public class SystemReducedMotionOption implements ReducedMotionOption { @Override - public ReducedMotionMode getCurrentReducedMotionMode(Context context) { - if (Utils.getAnimationScale(context) != 0f) { + public ReducedMotionMode getCurrentReducedMotionMode(@Nullable Context context) { + if (context == null || Utils.getAnimationScale(context) != 0f) { return ReducedMotionMode.STANDARD_MOTION; } else { return ReducedMotionMode.REDUCED_MOTION; diff --git a/lottie/src/main/java/com/airbnb/lottie/utils/Utils.java b/lottie/src/main/java/com/airbnb/lottie/utils/Utils.java index 68a09dcace..c48a6d32ae 100644 --- a/lottie/src/main/java/com/airbnb/lottie/utils/Utils.java +++ b/lottie/src/main/java/com/airbnb/lottie/utils/Utils.java @@ -14,6 +14,7 @@ import android.os.Build; import android.provider.Settings; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.airbnb.lottie.L; @@ -262,7 +263,7 @@ public static float dpScale() { return Resources.getSystem().getDisplayMetrics().density; } - public static float getAnimationScale(Context context) { + public static float getAnimationScale(@NonNull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { return Settings.Global.getFloat(context.getContentResolver(), Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f);