diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java index 57e113ee47..eef601268a 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieAnimationView.java @@ -219,6 +219,13 @@ private void init(@Nullable AttributeSet attrs, @AttrRes int defStyleAttr) { setRenderMode(RenderMode.values()[renderModeOrdinal]); } + setIgnoreDisabledSystemAnimations( + ta.getBoolean( + R.styleable.LottieAnimationView_lottie_ignoreDisabledSystemAnimations, + false + ) + ); + ta.recycle(); lottieDrawable.setSystemAnimationsAreEnabled(Utils.getAnimationScale(getContext()) != 0f); @@ -353,6 +360,17 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) { super.onDetachedFromWindow(); } + /** + * Allows ignoring system animations settings, therefore allowing animations to run even if they are disabled. + * + * Defaults to false. + * + * @param ignore if true animations will run even when they are disabled in the system settings. + */ + public void setIgnoreDisabledSystemAnimations(boolean ignore) { + lottieDrawable.setIgnoreDisabledSystemAnimations(ignore); + } + /** * Enable this to get merge path support for devices running KitKat (19) and above. * diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java index 007acba712..ce5cd47f1f 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java @@ -59,7 +59,11 @@ private interface LazyCompositionTask { private LottieComposition composition; private final LottieValueAnimator animator = new LottieValueAnimator(); private float scale = 1f; + + //Call animationsEnabled() instead of using these fields directly private boolean systemAnimationsEnabled = true; + private boolean ignoreSystemAnimationsDisabled = false; + private boolean safeMode = false; private final ArrayList lazyCompositionTasks = new ArrayList<>(); @@ -445,10 +449,10 @@ public void run(LottieComposition composition) { return; } - if (systemAnimationsEnabled || getRepeatCount() == 0) { + if (animationsEnabled() || getRepeatCount() == 0) { animator.playAnimation(); } - if (!systemAnimationsEnabled) { + if (!animationsEnabled()) { setFrame((int) (getSpeed() < 0 ? getMinFrame() : getMaxFrame())); animator.endAnimation(); } @@ -476,10 +480,10 @@ public void run(LottieComposition composition) { return; } - if (systemAnimationsEnabled || getRepeatCount() == 0) { + if (animationsEnabled() || getRepeatCount() == 0) { animator.resumeAnimation(); } - if (!systemAnimationsEnabled) { + if (!animationsEnabled()) { setFrame((int) (getSpeed() < 0 ? getMinFrame() : getMaxFrame())); animator.endAnimation(); } @@ -866,12 +870,27 @@ public boolean isAnimating() { return animator.isRunning(); } + private boolean animationsEnabled() { + return systemAnimationsEnabled || ignoreSystemAnimationsDisabled; + } + void setSystemAnimationsAreEnabled(Boolean areEnabled) { systemAnimationsEnabled = areEnabled; } // + /** + * Allows ignoring system animations settings, therefore allowing animations to run even if they are disabled. + * + * Defaults to false. + * + * @param ignore if true animations will run even when they are disabled in the system settings. + */ + public void setIgnoreDisabledSystemAnimations(boolean ignore) { + ignoreSystemAnimationsDisabled = ignore; + } + /** * Set the scale on the current composition. The only cost of this function is re-rendering the * current frame so you may call it frequent to scale something up or down. diff --git a/lottie/src/main/res/values/attrs.xml b/lottie/src/main/res/values/attrs.xml index 31e7dba8a7..1e8f30eed2 100644 --- a/lottie/src/main/res/values/attrs.xml +++ b/lottie/src/main/res/values/attrs.xml @@ -21,6 +21,7 @@ +