package com.airbnb.lottie; import android.content.Context; import android.content.res.Resources; import android.graphics.Rect; import androidx.collection.LongSparseArray; import androidx.collection.SparseArrayCompat; import com.airbnb.lottie.model.Font; import com.airbnb.lottie.model.FontCharacter; import com.airbnb.lottie.model.Marker; import com.airbnb.lottie.model.layer.Layer; import com.airbnb.lottie.parser.moshi.JsonReader; import com.airbnb.lottie.utils.Logger; import com.airbnb.lottie.utils.MiscUtils; import com.airbnb.lottie.utils.Utils; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import org.json.JSONObject; /* loaded from: classes2.dex */ public class LottieComposition { private Rect bounds; private SparseArrayCompat characters; private float endFrame; private Map fonts; private float frameRate; private boolean hasDashPattern; private Map images; private float imagesDpScale; private LongSparseArray layerMap; private List layers; private List markers; private Map> precomps; private float startFrame; private final PerformanceTracker performanceTracker = new PerformanceTracker(); private final HashSet warnings = new HashSet<>(); private int maskAndMatteCount = 0; public Rect getBounds() { return this.bounds; } public SparseArrayCompat getCharacters() { return this.characters; } public float getDurationFrames() { return this.endFrame - this.startFrame; } public float getEndFrame() { return this.endFrame; } public Map getFonts() { return this.fonts; } public float getFrameRate() { return this.frameRate; } public List getLayers() { return this.layers; } public List getMarkers() { return this.markers; } public int getMaskAndMatteCount() { return this.maskAndMatteCount; } public PerformanceTracker getPerformanceTracker() { return this.performanceTracker; } public float getProgressForFrame(float f) { float f2 = this.startFrame; return (f - f2) / (this.endFrame - f2); } public float getStartFrame() { return this.startFrame; } public boolean hasDashPattern() { return this.hasDashPattern; } public void incrementMatteOrMaskCount(int i) { this.maskAndMatteCount += i; } public void init(Rect rect, float f, float f2, float f3, List list, LongSparseArray longSparseArray, Map> map, Map map2, float f4, SparseArrayCompat sparseArrayCompat, Map map3, List list2) { this.bounds = rect; this.startFrame = f; this.endFrame = f2; this.frameRate = f3; this.layers = list; this.layerMap = longSparseArray; this.precomps = map; this.images = map2; this.imagesDpScale = f4; this.characters = sparseArrayCompat; this.fonts = map3; this.markers = list2; } public void setHasDashPattern(boolean z) { this.hasDashPattern = z; } public void addWarning(String str) { Logger.warning(str); this.warnings.add(str); } public ArrayList getWarnings() { HashSet hashSet = this.warnings; return new ArrayList<>(Arrays.asList((String[]) hashSet.toArray(new String[hashSet.size()]))); } public void setPerformanceTrackingEnabled(boolean z) { this.performanceTracker.setEnabled(z); } public Layer layerModelForId(long j) { return this.layerMap.get(j); } public float getDuration() { return (getDurationFrames() / this.frameRate) * 1000.0f; } public float getFrameForProgress(float f) { return MiscUtils.lerp(this.startFrame, this.endFrame, f); } public List getPrecomps(String str) { return this.precomps.get(str); } public Marker getMarker(String str) { int size = this.markers.size(); for (int i = 0; i < size; i++) { Marker marker = this.markers.get(i); if (marker.matchesName(str)) { return marker; } } return null; } public boolean hasImages() { return !this.images.isEmpty(); } public Map getImages() { float dpScale = Utils.dpScale(); if (dpScale != this.imagesDpScale) { this.imagesDpScale = dpScale; for (Map.Entry entry : this.images.entrySet()) { this.images.put(entry.getKey(), entry.getValue().copyWithScale(this.imagesDpScale / dpScale)); } } return this.images; } public String toString() { StringBuilder sb = new StringBuilder("LottieComposition:\n"); Iterator it = this.layers.iterator(); while (it.hasNext()) { sb.append(it.next().toString("\t")); } return sb.toString(); } @Deprecated /* loaded from: classes2.dex */ public static class Factory { private Factory() { } @Deprecated public static Cancellable fromAssetFileName(Context context, String str, OnCompositionLoadedListener onCompositionLoadedListener) { ListenerAdapter listenerAdapter = new ListenerAdapter(onCompositionLoadedListener); LottieCompositionFactory.fromAsset(context, str).addListener(listenerAdapter); return listenerAdapter; } @Deprecated public static Cancellable fromRawFile(Context context, int i, OnCompositionLoadedListener onCompositionLoadedListener) { ListenerAdapter listenerAdapter = new ListenerAdapter(onCompositionLoadedListener); LottieCompositionFactory.fromRawRes(context, i).addListener(listenerAdapter); return listenerAdapter; } @Deprecated public static Cancellable fromInputStream(InputStream inputStream, OnCompositionLoadedListener onCompositionLoadedListener) { ListenerAdapter listenerAdapter = new ListenerAdapter(onCompositionLoadedListener); LottieCompositionFactory.fromJsonInputStream(inputStream, null).addListener(listenerAdapter); return listenerAdapter; } @Deprecated public static Cancellable fromJsonString(String str, OnCompositionLoadedListener onCompositionLoadedListener) { ListenerAdapter listenerAdapter = new ListenerAdapter(onCompositionLoadedListener); LottieCompositionFactory.fromJsonString(str, null).addListener(listenerAdapter); return listenerAdapter; } @Deprecated public static Cancellable fromJsonReader(JsonReader jsonReader, OnCompositionLoadedListener onCompositionLoadedListener) { ListenerAdapter listenerAdapter = new ListenerAdapter(onCompositionLoadedListener); LottieCompositionFactory.fromJsonReader(jsonReader, null).addListener(listenerAdapter); return listenerAdapter; } @Deprecated public static LottieComposition fromFileSync(Context context, String str) { return LottieCompositionFactory.fromAssetSync(context, str).getValue(); } @Deprecated public static LottieComposition fromInputStreamSync(InputStream inputStream) { return LottieCompositionFactory.fromJsonInputStreamSync(inputStream, null).getValue(); } @Deprecated public static LottieComposition fromInputStreamSync(InputStream inputStream, boolean z) { if (z) { Logger.warning("Lottie now auto-closes input stream!"); } return LottieCompositionFactory.fromJsonInputStreamSync(inputStream, null).getValue(); } @Deprecated public static LottieComposition fromJsonSync(Resources resources, JSONObject jSONObject) { return LottieCompositionFactory.fromJsonSync(jSONObject, null).getValue(); } @Deprecated public static LottieComposition fromJsonSync(String str) { return LottieCompositionFactory.fromJsonStringSync(str, null).getValue(); } @Deprecated public static LottieComposition fromJsonSync(JsonReader jsonReader) { return LottieCompositionFactory.fromJsonReaderSync(jsonReader, null).getValue(); } /* loaded from: classes2.dex */ private static final class ListenerAdapter implements LottieListener, Cancellable { private boolean cancelled; private final OnCompositionLoadedListener listener; @Override // com.airbnb.lottie.Cancellable public void cancel() { this.cancelled = true; } private ListenerAdapter(OnCompositionLoadedListener onCompositionLoadedListener) { this.cancelled = false; this.listener = onCompositionLoadedListener; } @Override // com.airbnb.lottie.LottieListener public void onResult(LottieComposition lottieComposition) { if (this.cancelled) { return; } this.listener.onCompositionLoaded(lottieComposition); } } } }