package com.airbnb.lottie.animation.keyframe; import com.airbnb.lottie.L; import com.airbnb.lottie.value.Keyframe; import com.airbnb.lottie.value.LottieValueCallback; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import java.util.ArrayList; import java.util.List; /* loaded from: classes.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 = BitmapDescriptorFactory.HUE_RED; private A cachedGetValue = null; private float cachedStartDelayProgress = -1.0f; private float cachedEndProgress = -1.0f; /* loaded from: classes.dex */ public interface AnimationListener { void onValueChanged(); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public interface KeyframesWrapper { Keyframe getCurrentKeyframe(); float getEndProgress(); float getStartDelayProgress(); boolean isCachedValueEnabled(float f); boolean isEmpty(); boolean isValueChanged(float f); } abstract A getValue(Keyframe keyframe, float f); /* 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) { if (this.keyframesWrapper.isEmpty()) { return; } if (f < getStartDelayProgress()) { f = getStartDelayProgress(); } else if (f > getEndProgress()) { f = getEndProgress(); } if (f == this.progress) { return; } this.progress = f; if (this.keyframesWrapper.isValueChanged(f)) { notifyListeners(); } } public void notifyListeners() { for (int i = 0; i < this.listeners.size(); i++) { this.listeners.get(i).onValueChanged(); } } /* 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 BitmapDescriptorFactory.HUE_RED; } Keyframe currentKeyframe = getCurrentKeyframe(); return currentKeyframe.isStatic() ? BitmapDescriptorFactory.HUE_RED : (this.progress - currentKeyframe.getStartProgress()) / (currentKeyframe.getEndProgress() - currentKeyframe.getStartProgress()); } /* JADX INFO: Access modifiers changed from: protected */ public float getInterpolatedCurrentKeyframeProgress() { Keyframe currentKeyframe = getCurrentKeyframe(); return (currentKeyframe == null || currentKeyframe.isStatic()) ? BitmapDescriptorFactory.HUE_RED : 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: package-private */ /* loaded from: classes.dex */ public static final class EmptyKeyframeWrapper implements KeyframesWrapper { @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final float getEndProgress() { return 1.0f; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final float getStartDelayProgress() { return BitmapDescriptorFactory.HUE_RED; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final boolean isEmpty() { return true; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final boolean isValueChanged(float f) { return false; } private EmptyKeyframeWrapper() { } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final Keyframe getCurrentKeyframe() { throw new IllegalStateException("not implemented"); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final boolean isCachedValueEnabled(float f) { throw new IllegalStateException("not implemented"); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.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 final boolean isEmpty() { return false; } SingleKeyframeWrapper(List> list) { this.keyframe = list.get(0); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final boolean isValueChanged(float f) { return !this.keyframe.isStatic(); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final float getStartDelayProgress() { return this.keyframe.getStartProgress(); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final float getEndProgress() { return this.keyframe.getEndProgress(); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final boolean isCachedValueEnabled(float f) { if (this.cachedInterpolatedProgress == f) { return true; } this.cachedInterpolatedProgress = f; return false; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final Keyframe getCurrentKeyframe() { return this.keyframe; } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static final class KeyframesWrapperImpl implements KeyframesWrapper { private Keyframe cachedCurrentKeyframe = null; private float cachedInterpolatedProgress = -1.0f; private Keyframe currentKeyframe = findKeyframe(BitmapDescriptorFactory.HUE_RED); private final List> keyframes; @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final boolean isEmpty() { return false; } KeyframesWrapperImpl(List> list) { this.keyframes = list; } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final boolean isValueChanged(float f) { if (this.currentKeyframe.containsProgress(f)) { return !this.currentKeyframe.isStatic(); } this.currentKeyframe = findKeyframe(f); return true; } private Keyframe findKeyframe(float f) { Keyframe keyframe = this.keyframes.get(r0.size() - 1); if (f >= keyframe.getStartProgress()) { return keyframe; } for (int size = this.keyframes.size() - 2; size > 0; 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 final float getStartDelayProgress() { return this.keyframes.get(0).getStartProgress(); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final float getEndProgress() { return this.keyframes.get(r0.size() - 1).getEndProgress(); } @Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper public final 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 final Keyframe getCurrentKeyframe() { return this.currentKeyframe; } } public void setIsDiscrete() { this.isDiscrete = true; } public float getProgress() { return this.progress; } }