• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.airbnb.lottie.utils;
2 
3 import android.animation.Animator;
4 import android.animation.TimeInterpolator;
5 import android.animation.ValueAnimator;
6 import android.os.Build;
7 
8 import java.util.Set;
9 import java.util.concurrent.CopyOnWriteArraySet;
10 
11 public abstract class BaseLottieAnimator extends ValueAnimator {
12   private final Set<ValueAnimator.AnimatorUpdateListener> updateListeners = new CopyOnWriteArraySet<>();
13   private final Set<AnimatorListener> listeners = new CopyOnWriteArraySet<>();
14 
getStartDelay()15   @Override public long getStartDelay() {
16     throw new UnsupportedOperationException("LottieAnimator does not support getStartDelay.");
17   }
18 
setStartDelay(long startDelay)19   @Override public void setStartDelay(long startDelay) {
20     throw new UnsupportedOperationException("LottieAnimator does not support setStartDelay.");
21   }
setDuration(long duration)22   @Override public ValueAnimator setDuration(long duration) {
23     throw new UnsupportedOperationException("LottieAnimator does not support setDuration.");
24   }
25 
setInterpolator(TimeInterpolator value)26   @Override public void setInterpolator(TimeInterpolator value) {
27     throw new UnsupportedOperationException("LottieAnimator does not support setInterpolator.");
28   }
29 
addUpdateListener(ValueAnimator.AnimatorUpdateListener listener)30   public void addUpdateListener(ValueAnimator.AnimatorUpdateListener listener) {
31     updateListeners.add(listener);
32   }
33 
removeUpdateListener(ValueAnimator.AnimatorUpdateListener listener)34   public void removeUpdateListener(ValueAnimator.AnimatorUpdateListener listener) {
35     updateListeners.remove(listener);
36   }
37 
removeAllUpdateListeners()38   public void removeAllUpdateListeners() {
39     updateListeners.clear();
40   }
41 
addListener(ValueAnimator.AnimatorListener listener)42   public void addListener(ValueAnimator.AnimatorListener listener) {
43     listeners.add(listener);
44   }
45 
removeListener(ValueAnimator.AnimatorListener listener)46   public void removeListener(ValueAnimator.AnimatorListener listener) {
47     listeners.remove(listener);
48   }
49 
removeAllListeners()50   public void removeAllListeners() {
51     listeners.clear();
52   }
53 
notifyStart(boolean isReverse)54   void notifyStart(boolean isReverse) {
55     for (Animator.AnimatorListener listener : listeners) {
56       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
57         listener.onAnimationStart(this, isReverse);
58       } else {
59         listener.onAnimationStart(this);
60       }
61     }
62   }
63 
notifyRepeat()64   void notifyRepeat() {
65     for (Animator.AnimatorListener listener : listeners) {
66       listener.onAnimationRepeat(this);
67     }
68   }
69 
notifyEnd(boolean isReverse)70   void notifyEnd(boolean isReverse) {
71     for (Animator.AnimatorListener listener : listeners) {
72       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
73         listener.onAnimationEnd(this, isReverse);
74       } else {
75         listener.onAnimationEnd(this);
76       }
77     }
78   }
79 
notifyCancel()80   void notifyCancel() {
81     for (Animator.AnimatorListener listener : listeners) {
82       listener.onAnimationCancel(this);
83     }
84   }
85 
notifyUpdate()86   void notifyUpdate() {
87     for (ValueAnimator.AnimatorUpdateListener listener : updateListeners) {
88       listener.onAnimationUpdate(this);
89     }
90   }
91 }
92