323 lines
15 KiB
Java
323 lines
15 KiB
Java
package com.airbnb.lottie.animation.content;
|
|
|
|
import android.graphics.BlurMaskFilter;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.ColorFilter;
|
|
import android.graphics.LinearGradient;
|
|
import android.graphics.Matrix;
|
|
import android.graphics.Paint;
|
|
import android.graphics.Path;
|
|
import android.graphics.PointF;
|
|
import android.graphics.RadialGradient;
|
|
import android.graphics.RectF;
|
|
import android.graphics.Shader;
|
|
import com.airbnb.lottie.L;
|
|
import com.airbnb.lottie.LottieDrawable;
|
|
import com.airbnb.lottie.LottieProperty;
|
|
import com.airbnb.lottie.animation.LPaint;
|
|
import com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation;
|
|
import com.airbnb.lottie.animation.keyframe.DropShadowKeyframeAnimation;
|
|
import com.airbnb.lottie.animation.keyframe.ValueCallbackKeyframeAnimation;
|
|
import com.airbnb.lottie.model.KeyPath;
|
|
import com.airbnb.lottie.model.content.GradientColor;
|
|
import com.airbnb.lottie.model.content.GradientFill;
|
|
import com.airbnb.lottie.model.content.GradientType;
|
|
import com.airbnb.lottie.model.layer.BaseLayer;
|
|
import com.airbnb.lottie.utils.MiscUtils;
|
|
import com.airbnb.lottie.value.LottieValueCallback;
|
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import o.C0667Ltg;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class GradientFillContent implements DrawingContent, BaseKeyframeAnimation.AnimationListener, KeyPathElementContent {
|
|
private static final int CACHE_STEPS_MS = 32;
|
|
private BaseKeyframeAnimation<Float, Float> blurAnimation;
|
|
float blurMaskFilterRadius;
|
|
private final RectF boundsRect;
|
|
private final int cacheSteps;
|
|
private final BaseKeyframeAnimation<GradientColor, GradientColor> colorAnimation;
|
|
private ValueCallbackKeyframeAnimation colorCallbackAnimation;
|
|
private BaseKeyframeAnimation<ColorFilter, ColorFilter> colorFilterAnimation;
|
|
private DropShadowKeyframeAnimation dropShadowAnimation;
|
|
private final BaseKeyframeAnimation<PointF, PointF> endPointAnimation;
|
|
private final boolean hidden;
|
|
private final BaseLayer layer;
|
|
private final LottieDrawable lottieDrawable;
|
|
private final String name;
|
|
private final BaseKeyframeAnimation<Integer, Integer> opacityAnimation;
|
|
private final Paint paint;
|
|
private final Path path;
|
|
private final List<PathContent> paths;
|
|
private final BaseKeyframeAnimation<PointF, PointF> startPointAnimation;
|
|
private final GradientType type;
|
|
private final C0667Ltg<LinearGradient> linearGradientCache = new C0667Ltg<>();
|
|
private final C0667Ltg<RadialGradient> radialGradientCache = new C0667Ltg<>();
|
|
|
|
public GradientFillContent(LottieDrawable lottieDrawable, BaseLayer baseLayer, GradientFill gradientFill) {
|
|
Path path = new Path();
|
|
this.path = path;
|
|
this.paint = new LPaint(1);
|
|
this.boundsRect = new RectF();
|
|
this.paths = new ArrayList();
|
|
this.blurMaskFilterRadius = BitmapDescriptorFactory.HUE_RED;
|
|
this.layer = baseLayer;
|
|
this.name = gradientFill.getName();
|
|
this.hidden = gradientFill.isHidden();
|
|
this.lottieDrawable = lottieDrawable;
|
|
this.type = gradientFill.getGradientType();
|
|
path.setFillType(gradientFill.getFillType());
|
|
this.cacheSteps = (int) (lottieDrawable.getComposition().getDuration() / 32.0f);
|
|
BaseKeyframeAnimation<GradientColor, GradientColor> createAnimation = gradientFill.getGradientColor().createAnimation();
|
|
this.colorAnimation = createAnimation;
|
|
createAnimation.addUpdateListener(this);
|
|
baseLayer.addAnimation(createAnimation);
|
|
BaseKeyframeAnimation<Integer, Integer> createAnimation2 = gradientFill.getOpacity().createAnimation();
|
|
this.opacityAnimation = createAnimation2;
|
|
createAnimation2.addUpdateListener(this);
|
|
baseLayer.addAnimation(createAnimation2);
|
|
BaseKeyframeAnimation<PointF, PointF> createAnimation3 = gradientFill.getStartPoint().createAnimation();
|
|
this.startPointAnimation = createAnimation3;
|
|
createAnimation3.addUpdateListener(this);
|
|
baseLayer.addAnimation(createAnimation3);
|
|
BaseKeyframeAnimation<PointF, PointF> createAnimation4 = gradientFill.getEndPoint().createAnimation();
|
|
this.endPointAnimation = createAnimation4;
|
|
createAnimation4.addUpdateListener(this);
|
|
baseLayer.addAnimation(createAnimation4);
|
|
if (baseLayer.getBlurEffect() != null) {
|
|
BaseKeyframeAnimation<Float, Float> createAnimation5 = baseLayer.getBlurEffect().getBlurriness().createAnimation();
|
|
this.blurAnimation = createAnimation5;
|
|
createAnimation5.addUpdateListener(this);
|
|
baseLayer.addAnimation(this.blurAnimation);
|
|
}
|
|
if (baseLayer.getDropShadowEffect() != null) {
|
|
this.dropShadowAnimation = new DropShadowKeyframeAnimation(this, baseLayer, baseLayer.getDropShadowEffect());
|
|
}
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation.AnimationListener
|
|
public void onValueChanged() {
|
|
this.lottieDrawable.invalidateSelf();
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.animation.content.Content
|
|
public void setContents(List<Content> list, List<Content> list2) {
|
|
for (int i = 0; i < list2.size(); i++) {
|
|
Content content = list2.get(i);
|
|
if (content instanceof PathContent) {
|
|
this.paths.add((PathContent) content);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.animation.content.DrawingContent
|
|
public void draw(Canvas canvas, Matrix matrix, int i) {
|
|
Shader radialGradient;
|
|
if (this.hidden) {
|
|
return;
|
|
}
|
|
L.beginSection("GradientFillContent#draw");
|
|
this.path.reset();
|
|
for (int i2 = 0; i2 < this.paths.size(); i2++) {
|
|
this.path.addPath(this.paths.get(i2).getPath(), matrix);
|
|
}
|
|
this.path.computeBounds(this.boundsRect, false);
|
|
if (this.type == GradientType.LINEAR) {
|
|
radialGradient = getLinearGradient();
|
|
} else {
|
|
radialGradient = getRadialGradient();
|
|
}
|
|
radialGradient.setLocalMatrix(matrix);
|
|
this.paint.setShader(radialGradient);
|
|
BaseKeyframeAnimation<ColorFilter, ColorFilter> baseKeyframeAnimation = this.colorFilterAnimation;
|
|
if (baseKeyframeAnimation != null) {
|
|
this.paint.setColorFilter(baseKeyframeAnimation.getValue());
|
|
}
|
|
BaseKeyframeAnimation<Float, Float> baseKeyframeAnimation2 = this.blurAnimation;
|
|
if (baseKeyframeAnimation2 != null) {
|
|
float floatValue = baseKeyframeAnimation2.getValue().floatValue();
|
|
if (floatValue == BitmapDescriptorFactory.HUE_RED) {
|
|
this.paint.setMaskFilter(null);
|
|
} else if (floatValue != this.blurMaskFilterRadius) {
|
|
this.paint.setMaskFilter(new BlurMaskFilter(floatValue, BlurMaskFilter.Blur.NORMAL));
|
|
}
|
|
this.blurMaskFilterRadius = floatValue;
|
|
}
|
|
DropShadowKeyframeAnimation dropShadowKeyframeAnimation = this.dropShadowAnimation;
|
|
if (dropShadowKeyframeAnimation != null) {
|
|
dropShadowKeyframeAnimation.applyTo(this.paint);
|
|
}
|
|
this.paint.setAlpha(MiscUtils.clamp((int) ((((i / 255.0f) * this.opacityAnimation.getValue().intValue()) / 100.0f) * 255.0f), 0, 255));
|
|
canvas.drawPath(this.path, this.paint);
|
|
L.endSection("GradientFillContent#draw");
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.animation.content.DrawingContent
|
|
public void getBounds(RectF rectF, Matrix matrix, boolean z) {
|
|
this.path.reset();
|
|
for (int i = 0; i < this.paths.size(); i++) {
|
|
this.path.addPath(this.paths.get(i).getPath(), matrix);
|
|
}
|
|
this.path.computeBounds(rectF, false);
|
|
rectF.set(rectF.left - 1.0f, rectF.top - 1.0f, rectF.right + 1.0f, rectF.bottom + 1.0f);
|
|
}
|
|
|
|
private LinearGradient getLinearGradient() {
|
|
long gradientHash = getGradientHash();
|
|
LinearGradient c = this.linearGradientCache.c(gradientHash);
|
|
if (c != null) {
|
|
return c;
|
|
}
|
|
PointF value = this.startPointAnimation.getValue();
|
|
PointF value2 = this.endPointAnimation.getValue();
|
|
GradientColor value3 = this.colorAnimation.getValue();
|
|
LinearGradient linearGradient = new LinearGradient(value.x, value.y, value2.x, value2.y, applyDynamicColorsIfNeeded(value3.getColors()), value3.getPositions(), Shader.TileMode.CLAMP);
|
|
this.linearGradientCache.c(gradientHash, linearGradient);
|
|
return linearGradient;
|
|
}
|
|
|
|
private RadialGradient getRadialGradient() {
|
|
long gradientHash = getGradientHash();
|
|
RadialGradient c = this.radialGradientCache.c(gradientHash);
|
|
if (c != null) {
|
|
return c;
|
|
}
|
|
PointF value = this.startPointAnimation.getValue();
|
|
PointF value2 = this.endPointAnimation.getValue();
|
|
GradientColor value3 = this.colorAnimation.getValue();
|
|
int[] applyDynamicColorsIfNeeded = applyDynamicColorsIfNeeded(value3.getColors());
|
|
float[] positions = value3.getPositions();
|
|
float f = value.x;
|
|
float f2 = value.y;
|
|
float hypot = (float) Math.hypot(value2.x - f, value2.y - f2);
|
|
if (hypot <= BitmapDescriptorFactory.HUE_RED) {
|
|
hypot = 0.001f;
|
|
}
|
|
RadialGradient radialGradient = new RadialGradient(f, f2, hypot, applyDynamicColorsIfNeeded, positions, Shader.TileMode.CLAMP);
|
|
this.radialGradientCache.c(gradientHash, radialGradient);
|
|
return radialGradient;
|
|
}
|
|
|
|
private int getGradientHash() {
|
|
int round = Math.round(this.startPointAnimation.getProgress() * this.cacheSteps);
|
|
int round2 = Math.round(this.endPointAnimation.getProgress() * this.cacheSteps);
|
|
int round3 = Math.round(this.colorAnimation.getProgress() * this.cacheSteps);
|
|
int i = round != 0 ? round * 527 : 17;
|
|
if (round2 != 0) {
|
|
i = i * 31 * round2;
|
|
}
|
|
return round3 != 0 ? i * 31 * round3 : i;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
private int[] applyDynamicColorsIfNeeded(int[] iArr) {
|
|
ValueCallbackKeyframeAnimation valueCallbackKeyframeAnimation = this.colorCallbackAnimation;
|
|
if (valueCallbackKeyframeAnimation != null) {
|
|
Integer[] numArr = (Integer[]) valueCallbackKeyframeAnimation.getValue();
|
|
int i = 0;
|
|
if (iArr.length == numArr.length) {
|
|
while (i < iArr.length) {
|
|
iArr[i] = numArr[i].intValue();
|
|
i++;
|
|
}
|
|
} else {
|
|
iArr = new int[numArr.length];
|
|
while (i < numArr.length) {
|
|
iArr[i] = numArr[i].intValue();
|
|
i++;
|
|
}
|
|
}
|
|
}
|
|
return iArr;
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.model.KeyPathElement
|
|
public void resolveKeyPath(KeyPath keyPath, int i, List<KeyPath> list, KeyPath keyPath2) {
|
|
MiscUtils.resolveKeyPath(keyPath, i, list, keyPath2, this);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.airbnb.lottie.model.KeyPathElement
|
|
public <T> void addValueCallback(T t, LottieValueCallback<T> lottieValueCallback) {
|
|
DropShadowKeyframeAnimation dropShadowKeyframeAnimation;
|
|
DropShadowKeyframeAnimation dropShadowKeyframeAnimation2;
|
|
DropShadowKeyframeAnimation dropShadowKeyframeAnimation3;
|
|
DropShadowKeyframeAnimation dropShadowKeyframeAnimation4;
|
|
DropShadowKeyframeAnimation dropShadowKeyframeAnimation5;
|
|
if (t == LottieProperty.OPACITY) {
|
|
this.opacityAnimation.setValueCallback(lottieValueCallback);
|
|
return;
|
|
}
|
|
if (t == LottieProperty.COLOR_FILTER) {
|
|
BaseKeyframeAnimation<ColorFilter, ColorFilter> baseKeyframeAnimation = this.colorFilterAnimation;
|
|
if (baseKeyframeAnimation != null) {
|
|
this.layer.removeAnimation(baseKeyframeAnimation);
|
|
}
|
|
if (lottieValueCallback == null) {
|
|
this.colorFilterAnimation = null;
|
|
return;
|
|
}
|
|
ValueCallbackKeyframeAnimation valueCallbackKeyframeAnimation = new ValueCallbackKeyframeAnimation(lottieValueCallback);
|
|
this.colorFilterAnimation = valueCallbackKeyframeAnimation;
|
|
valueCallbackKeyframeAnimation.addUpdateListener(this);
|
|
this.layer.addAnimation(this.colorFilterAnimation);
|
|
return;
|
|
}
|
|
if (t == LottieProperty.GRADIENT_COLOR) {
|
|
ValueCallbackKeyframeAnimation valueCallbackKeyframeAnimation2 = this.colorCallbackAnimation;
|
|
if (valueCallbackKeyframeAnimation2 != null) {
|
|
this.layer.removeAnimation(valueCallbackKeyframeAnimation2);
|
|
}
|
|
if (lottieValueCallback == null) {
|
|
this.colorCallbackAnimation = null;
|
|
return;
|
|
}
|
|
this.linearGradientCache.b();
|
|
this.radialGradientCache.b();
|
|
ValueCallbackKeyframeAnimation valueCallbackKeyframeAnimation3 = new ValueCallbackKeyframeAnimation(lottieValueCallback);
|
|
this.colorCallbackAnimation = valueCallbackKeyframeAnimation3;
|
|
valueCallbackKeyframeAnimation3.addUpdateListener(this);
|
|
this.layer.addAnimation(this.colorCallbackAnimation);
|
|
return;
|
|
}
|
|
if (t == LottieProperty.BLUR_RADIUS) {
|
|
BaseKeyframeAnimation<Float, Float> baseKeyframeAnimation2 = this.blurAnimation;
|
|
if (baseKeyframeAnimation2 != null) {
|
|
baseKeyframeAnimation2.setValueCallback(lottieValueCallback);
|
|
return;
|
|
}
|
|
ValueCallbackKeyframeAnimation valueCallbackKeyframeAnimation4 = new ValueCallbackKeyframeAnimation(lottieValueCallback);
|
|
this.blurAnimation = valueCallbackKeyframeAnimation4;
|
|
valueCallbackKeyframeAnimation4.addUpdateListener(this);
|
|
this.layer.addAnimation(this.blurAnimation);
|
|
return;
|
|
}
|
|
if (t == LottieProperty.DROP_SHADOW_COLOR && (dropShadowKeyframeAnimation5 = this.dropShadowAnimation) != null) {
|
|
dropShadowKeyframeAnimation5.setColorCallback(lottieValueCallback);
|
|
return;
|
|
}
|
|
if (t == LottieProperty.DROP_SHADOW_OPACITY && (dropShadowKeyframeAnimation4 = this.dropShadowAnimation) != null) {
|
|
dropShadowKeyframeAnimation4.setOpacityCallback(lottieValueCallback);
|
|
return;
|
|
}
|
|
if (t == LottieProperty.DROP_SHADOW_DIRECTION && (dropShadowKeyframeAnimation3 = this.dropShadowAnimation) != null) {
|
|
dropShadowKeyframeAnimation3.setDirectionCallback(lottieValueCallback);
|
|
return;
|
|
}
|
|
if (t == LottieProperty.DROP_SHADOW_DISTANCE && (dropShadowKeyframeAnimation2 = this.dropShadowAnimation) != null) {
|
|
dropShadowKeyframeAnimation2.setDistanceCallback(lottieValueCallback);
|
|
} else {
|
|
if (t != LottieProperty.DROP_SHADOW_RADIUS || (dropShadowKeyframeAnimation = this.dropShadowAnimation) == null) {
|
|
return;
|
|
}
|
|
dropShadowKeyframeAnimation.setRadiusCallback(lottieValueCallback);
|
|
}
|
|
}
|
|
|
|
@Override // com.airbnb.lottie.animation.content.Content
|
|
public String getName() {
|
|
return this.name;
|
|
}
|
|
}
|