package com.airbnb.lottie.animation.keyframe; import com.airbnb.lottie.L; import com.airbnb.lottie.value.Keyframe; import com.airbnb.lottie.value.LottieValueCallback; import java.util.ArrayList; import java.util.List; /* loaded from: classes2.dex */ public abstract class BaseKeyframeAnimation { private final KeyframesWrapper keyframesWrapper; protected LottieValueCallback valueCallback; final List listeners = new ArrayList(1); private boolean isDiscrete = false; protected float progress = 0.0f; private A cachedGetValue = null; private float cachedStartDelayProgress = -1.0f; private float cachedEndProgress = -1.0f; /* loaded from: classes2.dex */ public interface AnimationListener { void onValueChanged(); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public interface KeyframesWrapper { Keyframe getCurrentKeyframe(); float getEndProgress(); float getStartDelayProgress(); boolean isCachedValueEnabled(float f); boolean isEmpty(); boolean isValueChanged(float f); } public float getProgress() { return this.progress; } abstract A getValue(Keyframe keyframe, float f); public boolean hasValueCallback() { return this.valueCallback != null; } public void setIsDiscrete() { this.isDiscrete = true; } /* JADX INFO: Access modifiers changed from: package-private */ public BaseKeyframeAnimation(List> list) { this.keyframesWrapper = wrap(list); } public void addUpdateListener(AnimationListener animationListener) { this.listeners.add(animationListener); } public void setProgress(float f) { L.beginSection("BaseKeyframeAnimation#setProgress"); if (this.keyframesWrapper.isEmpty()) { L.endSection("BaseKeyframeAnimation#setProgress"); return; } if (f < getStartDelayProgress()) { f = getStartDelayProgress(); } else if (f > getEndProgress()) { f = getEndProgress(); } if (f == this.progress) { L.endSection("BaseKeyframeAnimation#setProgress"); return; } this.progress = f; if (this.keyframesWrapper.isValueChanged(f)) { notifyListeners(); } L.endSection("BaseKeyframeAnimation#setProgress"); } public void notifyListeners() { L.beginSection("BaseKeyframeAnimation#notifyListeners"); for (int i = 0; i < this.listeners.size(); i++) { this.listeners.get(i).onValueChanged(); } L.endSection("BaseKeyframeAnimation#notifyListeners"); } /* JADX INFO: Access modifiers changed from: protected */ public Keyframe getCurrentKeyframe() { L.beginSection("BaseKeyframeAnimation#getCurrentKeyframe"); Keyframe currentKeyframe = this.keyframesWrapper.getCurrentKeyframe(); L.endSection("BaseKeyframeAnimation#getCurrentKeyframe"); return currentKeyframe; } /* JADX INFO: Access modifiers changed from: package-private */ public float getLinearCurrentKeyframeProgress() { if (this.isDiscrete) { return 0.0f; } Keyframe currentKeyframe = getCurrentKeyframe(); if (currentKeyframe.isStatic()) { return 0.0f; } return (this.progress - currentKeyframe.getStartProgress()) / (currentKeyframe.getEndProgress() - currentKeyframe.getStartProgress()); } /* JADX INFO: Access modifiers changed from: protected */ public float getInterpolatedCurrentKeyframeProgress() { Keyframe currentKeyframe = getCurrentKeyframe(); if (currentKeyframe == null || currentKeyframe.isStatic()) { return 0.0f; } return currentKeyframe.interpolator.getInterpolation(getLinearCurrentKeyframeProgress()); } private float getStartDelayProgress() { if (this.cachedStartDelayProgress == -1.0f) { this.cachedStartDelayProgress = this.keyframesWrapper.getStartDelayProgress(); } return this.cachedStartDelayProgress; } float getEndProgress() { if (this.cachedEndProgress == -1.0f) { this.cachedEndProgress = this.keyframesWrapper.getEndProgress(); } return this.cachedEndProgress; } public A getValue() { A value; float linearCurrentKeyframeProgress = getLinearCurrentKeyframeProgress(); if (this.valueCallback == null && this.keyframesWrapper.isCachedValueEnabled(linearCurrentKeyframeProgress)) { return this.cachedGetValue; } Keyframe currentKeyframe = getCurrentKeyframe(); if (currentKeyframe.xInterpolator != null && currentKeyframe.yInterpolator != null) { value = getValue(currentKeyframe, linearCurrentKeyframeProgress, currentKeyframe.xInterpolator.getInterpolation(linearCurrentKeyframeProgress), currentKeyframe.yInterpolator.getInterpolation(linearCurrentKeyframeProgress)); } else { value = getValue(currentKeyframe, getInterpolatedCurrentKeyframeProgress()); } this.cachedGetValue = value; return value; } public void setValueCallback(LottieValueCallback lottieValueCallback) { LottieValueCallback lottieValueCallback2 = this.valueCallback; if (lottieValueCallback2 != null) { lottieValueCallback2.setAnimation(null); } this.valueCallback = lottieValueCallback; if (lottieValueCallback != null) { lottieValueCallback.setAnimation(this); } } protected A getValue(Keyframe keyframe, float f, float f2, float f3) { throw new UnsupportedOperationException("This animation does not support split dimensions!"); } private static KeyframesWrapper wrap(List> list) { if (list.isEmpty()) { return new EmptyKeyframeWrapper(); } if (list.size() == 1) { return new SingleKeyframeWrapper(list); } return new KeyframesWrapperImpl(list); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static final class EmptyKeyframeWrapper implements KeyframesWrapper { @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public float getEndProgress() { return 1.0f; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public float getStartDelayProgress() { return 0.0f; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public boolean isEmpty() { return true; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public boolean isValueChanged(float f) { return false; } private EmptyKeyframeWrapper() { } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public Keyframe getCurrentKeyframe() { throw new IllegalStateException("not implemented"); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public boolean isCachedValueEnabled(float f) { throw new IllegalStateException("not implemented"); } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static final class SingleKeyframeWrapper implements KeyframesWrapper { private float cachedInterpolatedProgress = -1.0f; private final Keyframe keyframe; @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public Keyframe getCurrentKeyframe() { return this.keyframe; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public boolean isCachedValueEnabled(float f) { if (this.cachedInterpolatedProgress == f) { return true; } this.cachedInterpolatedProgress = f; return false; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public boolean isEmpty() { return false; } SingleKeyframeWrapper(List> list) { this.keyframe = list.get(0); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public boolean isValueChanged(float f) { return !this.keyframe.isStatic(); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public float getStartDelayProgress() { return this.keyframe.getStartProgress(); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public float getEndProgress() { return this.keyframe.getEndProgress(); } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static final class KeyframesWrapperImpl implements KeyframesWrapper { private Keyframe cachedCurrentKeyframe = null; private float cachedInterpolatedProgress = -1.0f; private Keyframe currentKeyframe = findKeyframe(0.0f); private final List> keyframes; @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public Keyframe getCurrentKeyframe() { return this.currentKeyframe; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public boolean isCachedValueEnabled(float f) { Keyframe keyframe = this.cachedCurrentKeyframe; Keyframe keyframe2 = this.currentKeyframe; if (keyframe == keyframe2 && this.cachedInterpolatedProgress == f) { return true; } this.cachedCurrentKeyframe = keyframe2; this.cachedInterpolatedProgress = f; return false; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public boolean isEmpty() { return false; } KeyframesWrapperImpl(List> list) { this.keyframes = list; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public boolean isValueChanged(float f) { if (this.currentKeyframe.containsProgress(f)) { return !this.currentKeyframe.isStatic(); } this.currentKeyframe = findKeyframe(f); return true; } private Keyframe findKeyframe(float f) { List> list = this.keyframes; Keyframe keyframe = list.get(list.size() - 1); if (f >= keyframe.getStartProgress()) { return keyframe; } for (int size = this.keyframes.size() - 2; size >= 1; size--) { Keyframe keyframe2 = this.keyframes.get(size); if (this.currentKeyframe != keyframe2 && keyframe2.containsProgress(f)) { return keyframe2; } } return this.keyframes.get(0); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public float getStartDelayProgress() { return this.keyframes.get(0).getStartProgress(); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public float getEndProgress() { return this.keyframes.get(r1.size() - 1).getEndProgress(); } } }