313 lines
12 KiB
Java
313 lines
12 KiB
Java
|
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<K, A> {
|
||
|
private final KeyframesWrapper<K> keyframesWrapper;
|
||
|
protected LottieValueCallback<A> valueCallback;
|
||
|
final List<AnimationListener> 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<T> {
|
||
|
Keyframe<T> getCurrentKeyframe();
|
||
|
|
||
|
float getEndProgress();
|
||
|
|
||
|
float getStartDelayProgress();
|
||
|
|
||
|
boolean isCachedValueEnabled(float f);
|
||
|
|
||
|
boolean isEmpty();
|
||
|
|
||
|
boolean isValueChanged(float f);
|
||
|
}
|
||
|
|
||
|
abstract A getValue(Keyframe<K> keyframe, float f);
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public BaseKeyframeAnimation(List<? extends Keyframe<K>> 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<K> getCurrentKeyframe() {
|
||
|
L.beginSection("BaseKeyframeAnimation#getCurrentKeyframe");
|
||
|
Keyframe<K> 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<K> 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<K> 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<K> 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<A> lottieValueCallback) {
|
||
|
LottieValueCallback<A> lottieValueCallback2 = this.valueCallback;
|
||
|
if (lottieValueCallback2 != null) {
|
||
|
lottieValueCallback2.setAnimation(null);
|
||
|
}
|
||
|
this.valueCallback = lottieValueCallback;
|
||
|
if (lottieValueCallback != null) {
|
||
|
lottieValueCallback.setAnimation(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected A getValue(Keyframe<K> keyframe, float f, float f2, float f3) {
|
||
|
throw new UnsupportedOperationException("This animation does not support split dimensions!");
|
||
|
}
|
||
|
|
||
|
private static <T> KeyframesWrapper<T> wrap(List<? extends Keyframe<T>> 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<T> implements KeyframesWrapper<T> {
|
||
|
@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<T> 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<T> implements KeyframesWrapper<T> {
|
||
|
private float cachedInterpolatedProgress = -1.0f;
|
||
|
private final Keyframe<T> keyframe;
|
||
|
|
||
|
@Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper
|
||
|
public final boolean isEmpty() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
SingleKeyframeWrapper(List<? extends Keyframe<T>> 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<T> getCurrentKeyframe() {
|
||
|
return this.keyframe;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* loaded from: classes.dex */
|
||
|
public static final class KeyframesWrapperImpl<T> implements KeyframesWrapper<T> {
|
||
|
private Keyframe<T> cachedCurrentKeyframe = null;
|
||
|
private float cachedInterpolatedProgress = -1.0f;
|
||
|
private Keyframe<T> currentKeyframe = findKeyframe(BitmapDescriptorFactory.HUE_RED);
|
||
|
private final List<? extends Keyframe<T>> keyframes;
|
||
|
|
||
|
@Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.KeyframesWrapper
|
||
|
public final boolean isEmpty() {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
KeyframesWrapperImpl(List<? extends Keyframe<T>> 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<T> findKeyframe(float f) {
|
||
|
Keyframe<T> keyframe = this.keyframes.get(r0.size() - 1);
|
||
|
if (f >= keyframe.getStartProgress()) {
|
||
|
return keyframe;
|
||
|
}
|
||
|
for (int size = this.keyframes.size() - 2; size > 0; size--) {
|
||
|
Keyframe<T> 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<T> keyframe = this.cachedCurrentKeyframe;
|
||
|
Keyframe<T> 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<T> getCurrentKeyframe() {
|
||
|
return this.currentKeyframe;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void setIsDiscrete() {
|
||
|
this.isDiscrete = true;
|
||
|
}
|
||
|
|
||
|
public float getProgress() {
|
||
|
return this.progress;
|
||
|
}
|
||
|
}
|