what-the-bank/sources/com/airbnb/lottie/model/layer/CompositionLayer.java

241 lines
9.8 KiB
Java

package com.airbnb.lottie.model.layer;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RectF;
import com.airbnb.lottie.L;
import com.airbnb.lottie.LottieComposition;
import com.airbnb.lottie.LottieDrawable;
import com.airbnb.lottie.LottieProperty;
import com.airbnb.lottie.animation.keyframe.BaseKeyframeAnimation;
import com.airbnb.lottie.animation.keyframe.ValueCallbackKeyframeAnimation;
import com.airbnb.lottie.model.KeyPath;
import com.airbnb.lottie.model.animatable.AnimatableFloatValue;
import com.airbnb.lottie.model.layer.Layer;
import com.airbnb.lottie.utils.Utils;
import com.airbnb.lottie.value.LottieValueCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import o.C0667Ltg;
/* loaded from: classes.dex */
public class CompositionLayer extends BaseLayer {
private boolean clipToCompositionBounds;
private Boolean hasMasks;
private Boolean hasMatte;
private final Paint layerPaint;
private final List<BaseLayer> layers;
private final RectF newClipRect;
private final RectF rect;
private BaseKeyframeAnimation<Float, Float> timeRemapping;
public CompositionLayer(LottieDrawable lottieDrawable, Layer layer, List<Layer> list, LottieComposition lottieComposition) {
super(lottieDrawable, layer);
int i;
BaseLayer baseLayer;
this.layers = new ArrayList();
this.rect = new RectF();
this.newClipRect = new RectF();
this.layerPaint = new Paint();
this.clipToCompositionBounds = true;
AnimatableFloatValue timeRemapping = layer.getTimeRemapping();
if (timeRemapping != null) {
BaseKeyframeAnimation<Float, Float> createAnimation = timeRemapping.createAnimation();
this.timeRemapping = createAnimation;
addAnimation(createAnimation);
this.timeRemapping.addUpdateListener(this);
} else {
this.timeRemapping = null;
}
C0667Ltg c0667Ltg = new C0667Ltg(lottieComposition.getLayers().size());
int size = list.size() - 1;
BaseLayer baseLayer2 = null;
while (true) {
i = 0;
if (size < 0) {
break;
}
Layer layer2 = list.get(size);
BaseLayer forModel = BaseLayer.forModel(this, layer2, lottieDrawable, lottieComposition);
if (forModel != null) {
c0667Ltg.c(forModel.getLayerModel().getId(), forModel);
if (baseLayer2 != null) {
baseLayer2.setMatteLayer(forModel);
baseLayer2 = null;
} else {
this.layers.add(0, forModel);
int i2 = AnonymousClass1.$SwitchMap$com$airbnb$lottie$model$layer$Layer$MatteType[layer2.getMatteType().ordinal()];
if (i2 == 1 || i2 == 2) {
baseLayer2 = forModel;
}
}
}
size--;
}
while (true) {
if (c0667Ltg.b) {
c0667Ltg.c();
}
if (i >= c0667Ltg.a) {
return;
}
if (c0667Ltg.b) {
c0667Ltg.c();
}
BaseLayer baseLayer3 = (BaseLayer) c0667Ltg.c(c0667Ltg.e[i]);
if (baseLayer3 != null && (baseLayer = (BaseLayer) c0667Ltg.c(baseLayer3.getLayerModel().getParentId())) != null) {
baseLayer3.setParentLayer(baseLayer);
}
i++;
}
}
/* renamed from: com.airbnb.lottie.model.layer.CompositionLayer$1, reason: invalid class name */
/* loaded from: classes.dex */
static /* synthetic */ class AnonymousClass1 {
static final int[] $SwitchMap$com$airbnb$lottie$model$layer$Layer$MatteType;
static {
int[] iArr = new int[Layer.MatteType.values().length];
$SwitchMap$com$airbnb$lottie$model$layer$Layer$MatteType = iArr;
try {
iArr[Layer.MatteType.ADD.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$airbnb$lottie$model$layer$Layer$MatteType[Layer.MatteType.INVERT.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
}
}
@Override // com.airbnb.lottie.model.layer.BaseLayer
public void setOutlineMasksAndMattes(boolean z) {
super.setOutlineMasksAndMattes(z);
Iterator<BaseLayer> it = this.layers.iterator();
while (it.hasNext()) {
it.next().setOutlineMasksAndMattes(z);
}
}
@Override // com.airbnb.lottie.model.layer.BaseLayer
void drawLayer(Canvas canvas, Matrix matrix, int i) {
L.beginSection("CompositionLayer#draw");
this.newClipRect.set(BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, this.layerModel.getPreCompWidth(), this.layerModel.getPreCompHeight());
matrix.mapRect(this.newClipRect);
boolean z = this.lottieDrawable.isApplyingOpacityToLayersEnabled() && this.layers.size() > 1 && i != 255;
if (z) {
this.layerPaint.setAlpha(i);
Utils.saveLayerCompat(canvas, this.newClipRect, this.layerPaint);
} else {
canvas.save();
}
if (z) {
i = 255;
}
for (int size = this.layers.size() - 1; size >= 0; size--) {
if ((!this.clipToCompositionBounds && "__container".equals(this.layerModel.getName())) || this.newClipRect.isEmpty() || canvas.clipRect(this.newClipRect)) {
this.layers.get(size).draw(canvas, matrix, i);
}
}
canvas.restore();
L.endSection("CompositionLayer#draw");
}
@Override // com.airbnb.lottie.model.layer.BaseLayer, com.airbnb.lottie.animation.content.DrawingContent
public void getBounds(RectF rectF, Matrix matrix, boolean z) {
super.getBounds(rectF, matrix, z);
for (int size = this.layers.size() - 1; size >= 0; size--) {
this.rect.set(BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED);
this.layers.get(size).getBounds(this.rect, this.boundsMatrix, true);
rectF.union(this.rect);
}
}
@Override // com.airbnb.lottie.model.layer.BaseLayer
public void setProgress(float f) {
super.setProgress(f);
if (this.timeRemapping != null) {
f = ((this.timeRemapping.getValue().floatValue() * this.layerModel.getComposition().getFrameRate()) - this.layerModel.getComposition().getStartFrame()) / (this.lottieDrawable.getComposition().getDurationFrames() + 0.01f);
}
if (this.timeRemapping == null) {
f -= this.layerModel.getStartProgress();
}
if (this.layerModel.getTimeStretch() != BitmapDescriptorFactory.HUE_RED && !"__container".equals(this.layerModel.getName())) {
f /= this.layerModel.getTimeStretch();
}
for (int size = this.layers.size() - 1; size >= 0; size--) {
this.layers.get(size).setProgress(f);
}
}
public boolean hasMasks() {
if (this.hasMasks == null) {
for (int size = this.layers.size() - 1; size >= 0; size--) {
BaseLayer baseLayer = this.layers.get(size);
if (baseLayer instanceof ShapeLayer) {
if (baseLayer.hasMasksOnThisLayer()) {
this.hasMasks = Boolean.TRUE;
return true;
}
} else if ((baseLayer instanceof CompositionLayer) && ((CompositionLayer) baseLayer).hasMasks()) {
this.hasMasks = Boolean.TRUE;
return true;
}
}
this.hasMasks = Boolean.FALSE;
}
return this.hasMasks.booleanValue();
}
public boolean hasMatte() {
if (this.hasMatte == null) {
if (hasMatteOnThisLayer()) {
this.hasMatte = Boolean.TRUE;
return true;
}
for (int size = this.layers.size() - 1; size >= 0; size--) {
if (this.layers.get(size).hasMatteOnThisLayer()) {
this.hasMatte = Boolean.TRUE;
return true;
}
}
this.hasMatte = Boolean.FALSE;
}
return this.hasMatte.booleanValue();
}
@Override // com.airbnb.lottie.model.layer.BaseLayer
protected void resolveChildKeyPath(KeyPath keyPath, int i, List<KeyPath> list, KeyPath keyPath2) {
for (int i2 = 0; i2 < this.layers.size(); i2++) {
this.layers.get(i2).resolveKeyPath(keyPath, i, list, keyPath2);
}
}
@Override // com.airbnb.lottie.model.layer.BaseLayer, com.airbnb.lottie.model.KeyPathElement
public <T> void addValueCallback(T t, LottieValueCallback<T> lottieValueCallback) {
super.addValueCallback(t, lottieValueCallback);
if (t == LottieProperty.TIME_REMAP) {
if (lottieValueCallback == null) {
BaseKeyframeAnimation<Float, Float> baseKeyframeAnimation = this.timeRemapping;
if (baseKeyframeAnimation != null) {
baseKeyframeAnimation.setValueCallback(null);
return;
}
return;
}
ValueCallbackKeyframeAnimation valueCallbackKeyframeAnimation = new ValueCallbackKeyframeAnimation(lottieValueCallback);
this.timeRemapping = valueCallbackKeyframeAnimation;
valueCallbackKeyframeAnimation.addUpdateListener(this);
addAnimation(this.timeRemapping);
}
}
public void setClipToCompositionBounds(boolean z) {
this.clipToCompositionBounds = z;
}
}