Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding null check for context before calling Utils.getAnimationScale #2546

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ boolean isAnimatingOrWillAnimateOnVisible() {
}
}

public boolean animationsEnabled(Context context) {
public boolean animationsEnabled(@Nullable Context context) {
if (ignoreSystemAnimationsDisabled) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.airbnb.lottie.configurations.reducemotion;

import android.content.Context;
import androidx.annotation.Nullable;
import com.airbnb.lottie.utils.Utils;

/**
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lottie/src/main/java/com/airbnb/lottie/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading