373 lines
16 KiB
Java
373 lines
16 KiB
Java
|
package com.airbnb.lottie.parser;
|
||
|
|
||
|
import android.graphics.PointF;
|
||
|
import android.view.animation.Interpolator;
|
||
|
import android.view.animation.LinearInterpolator;
|
||
|
import com.airbnb.lottie.LottieComposition;
|
||
|
import com.airbnb.lottie.parser.moshi.JsonReader;
|
||
|
import com.airbnb.lottie.utils.MiscUtils;
|
||
|
import com.airbnb.lottie.utils.Utils;
|
||
|
import com.airbnb.lottie.value.Keyframe;
|
||
|
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||
|
import java.io.IOException;
|
||
|
import java.lang.ref.WeakReference;
|
||
|
import o.C17534xZR;
|
||
|
import o.VOL;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
class KeyframeParser {
|
||
|
private static final float MAX_CP_VALUE = 100.0f;
|
||
|
private static VOL<WeakReference<Interpolator>> pathInterpolatorCache;
|
||
|
private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
|
||
|
static JsonReader.Options NAMES = JsonReader.Options.of("t", "s", "e", "o", "i", "h", "to", "ti");
|
||
|
static JsonReader.Options INTERPOLATOR_NAMES = JsonReader.Options.of("x", "y");
|
||
|
|
||
|
KeyframeParser() {
|
||
|
}
|
||
|
|
||
|
private static VOL<WeakReference<Interpolator>> pathInterpolatorCache() {
|
||
|
if (pathInterpolatorCache == null) {
|
||
|
pathInterpolatorCache = new VOL<>();
|
||
|
}
|
||
|
return pathInterpolatorCache;
|
||
|
}
|
||
|
|
||
|
private static WeakReference<Interpolator> getInterpolator(int i) {
|
||
|
WeakReference<Interpolator> e;
|
||
|
synchronized (KeyframeParser.class) {
|
||
|
e = pathInterpolatorCache().e(i);
|
||
|
}
|
||
|
return e;
|
||
|
}
|
||
|
|
||
|
private static void putInterpolator(int i, WeakReference<Interpolator> weakReference) {
|
||
|
synchronized (KeyframeParser.class) {
|
||
|
pathInterpolatorCache.a(i, weakReference);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public static <T> Keyframe<T> parse(JsonReader jsonReader, LottieComposition lottieComposition, float f, ValueParser<T> valueParser, boolean z, boolean z2) throws IOException {
|
||
|
if (z && z2) {
|
||
|
return parseMultiDimensionalKeyframe(lottieComposition, jsonReader, f, valueParser);
|
||
|
}
|
||
|
if (z) {
|
||
|
return parseKeyframe(lottieComposition, jsonReader, f, valueParser);
|
||
|
}
|
||
|
return parseStaticValue(jsonReader, f, valueParser);
|
||
|
}
|
||
|
|
||
|
private static <T> Keyframe<T> parseKeyframe(LottieComposition lottieComposition, JsonReader jsonReader, float f, ValueParser<T> valueParser) throws IOException {
|
||
|
Interpolator interpolatorFor;
|
||
|
T t;
|
||
|
jsonReader.beginObject();
|
||
|
PointF pointF = null;
|
||
|
float f2 = 0.0f;
|
||
|
boolean z = false;
|
||
|
PointF pointF2 = null;
|
||
|
T t2 = null;
|
||
|
T t3 = null;
|
||
|
PointF pointF3 = null;
|
||
|
PointF pointF4 = null;
|
||
|
while (jsonReader.hasNext()) {
|
||
|
switch (jsonReader.selectName(NAMES)) {
|
||
|
case 0:
|
||
|
f2 = (float) jsonReader.nextDouble();
|
||
|
break;
|
||
|
case 1:
|
||
|
t3 = valueParser.parse(jsonReader, f);
|
||
|
break;
|
||
|
case 2:
|
||
|
t2 = valueParser.parse(jsonReader, f);
|
||
|
break;
|
||
|
case 3:
|
||
|
pointF = JsonUtils.jsonToPoint(jsonReader, 1.0f);
|
||
|
break;
|
||
|
case 4:
|
||
|
pointF2 = JsonUtils.jsonToPoint(jsonReader, 1.0f);
|
||
|
break;
|
||
|
case 5:
|
||
|
if (jsonReader.nextInt() != 1) {
|
||
|
z = false;
|
||
|
break;
|
||
|
} else {
|
||
|
z = true;
|
||
|
break;
|
||
|
}
|
||
|
case 6:
|
||
|
pointF4 = JsonUtils.jsonToPoint(jsonReader, f);
|
||
|
break;
|
||
|
case 7:
|
||
|
pointF3 = JsonUtils.jsonToPoint(jsonReader, f);
|
||
|
break;
|
||
|
default:
|
||
|
jsonReader.skipValue();
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
jsonReader.endObject();
|
||
|
if (z) {
|
||
|
interpolatorFor = LINEAR_INTERPOLATOR;
|
||
|
t = t3;
|
||
|
} else {
|
||
|
interpolatorFor = (pointF == null || pointF2 == null) ? LINEAR_INTERPOLATOR : interpolatorFor(pointF, pointF2);
|
||
|
t = t2;
|
||
|
}
|
||
|
Keyframe<T> keyframe = new Keyframe<>(lottieComposition, t3, t, interpolatorFor, f2, null);
|
||
|
keyframe.pathCp1 = pointF4;
|
||
|
keyframe.pathCp2 = pointF3;
|
||
|
return keyframe;
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Failed to find 'out' block for switch in B:5:0x0024. Please report as an issue. */
|
||
|
private static <T> Keyframe<T> parseMultiDimensionalKeyframe(LottieComposition lottieComposition, JsonReader jsonReader, float f, ValueParser<T> valueParser) throws IOException {
|
||
|
Interpolator interpolator;
|
||
|
Interpolator interpolatorFor;
|
||
|
Interpolator interpolatorFor2;
|
||
|
T t;
|
||
|
T t2;
|
||
|
Keyframe<T> keyframe;
|
||
|
PointF pointF;
|
||
|
PointF pointF2;
|
||
|
PointF pointF3;
|
||
|
PointF pointF4;
|
||
|
jsonReader.beginObject();
|
||
|
PointF pointF5 = null;
|
||
|
PointF pointF6 = null;
|
||
|
boolean z = false;
|
||
|
PointF pointF7 = null;
|
||
|
PointF pointF8 = null;
|
||
|
PointF pointF9 = null;
|
||
|
T t3 = null;
|
||
|
PointF pointF10 = null;
|
||
|
T t4 = null;
|
||
|
PointF pointF11 = null;
|
||
|
float f2 = BitmapDescriptorFactory.HUE_RED;
|
||
|
PointF pointF12 = null;
|
||
|
while (jsonReader.hasNext()) {
|
||
|
T t5 = t4;
|
||
|
switch (jsonReader.selectName(NAMES)) {
|
||
|
case 0:
|
||
|
pointF = pointF5;
|
||
|
pointF2 = pointF6;
|
||
|
f2 = (float) jsonReader.nextDouble();
|
||
|
t4 = t5;
|
||
|
pointF5 = pointF;
|
||
|
pointF6 = pointF2;
|
||
|
break;
|
||
|
case 1:
|
||
|
t3 = valueParser.parse(jsonReader, f);
|
||
|
t4 = t5;
|
||
|
break;
|
||
|
case 2:
|
||
|
t4 = valueParser.parse(jsonReader, f);
|
||
|
break;
|
||
|
case 3:
|
||
|
pointF = pointF5;
|
||
|
pointF2 = pointF6;
|
||
|
if (jsonReader.peek() == JsonReader.Token.BEGIN_OBJECT) {
|
||
|
jsonReader.beginObject();
|
||
|
float f3 = BitmapDescriptorFactory.HUE_RED;
|
||
|
float f4 = BitmapDescriptorFactory.HUE_RED;
|
||
|
float f5 = BitmapDescriptorFactory.HUE_RED;
|
||
|
float f6 = BitmapDescriptorFactory.HUE_RED;
|
||
|
while (jsonReader.hasNext()) {
|
||
|
int selectName = jsonReader.selectName(INTERPOLATOR_NAMES);
|
||
|
if (selectName == 0) {
|
||
|
pointF4 = pointF11;
|
||
|
if (jsonReader.peek() == JsonReader.Token.NUMBER) {
|
||
|
f5 = (float) jsonReader.nextDouble();
|
||
|
f3 = f5;
|
||
|
} else {
|
||
|
jsonReader.beginArray();
|
||
|
f3 = (float) jsonReader.nextDouble();
|
||
|
f5 = jsonReader.peek() == JsonReader.Token.NUMBER ? (float) jsonReader.nextDouble() : f3;
|
||
|
jsonReader.endArray();
|
||
|
}
|
||
|
} else if (selectName == 1) {
|
||
|
if (jsonReader.peek() == JsonReader.Token.NUMBER) {
|
||
|
pointF4 = pointF11;
|
||
|
f6 = (float) jsonReader.nextDouble();
|
||
|
f4 = f6;
|
||
|
} else {
|
||
|
pointF4 = pointF11;
|
||
|
jsonReader.beginArray();
|
||
|
f4 = (float) jsonReader.nextDouble();
|
||
|
f6 = jsonReader.peek() == JsonReader.Token.NUMBER ? (float) jsonReader.nextDouble() : f4;
|
||
|
jsonReader.endArray();
|
||
|
}
|
||
|
} else {
|
||
|
jsonReader.skipValue();
|
||
|
}
|
||
|
pointF11 = pointF4;
|
||
|
}
|
||
|
PointF pointF13 = new PointF(f3, f4);
|
||
|
PointF pointF14 = new PointF(f5, f6);
|
||
|
jsonReader.endObject();
|
||
|
pointF9 = pointF13;
|
||
|
t4 = t5;
|
||
|
pointF6 = pointF2;
|
||
|
pointF10 = pointF14;
|
||
|
pointF5 = pointF;
|
||
|
break;
|
||
|
} else {
|
||
|
pointF7 = JsonUtils.jsonToPoint(jsonReader, f);
|
||
|
t4 = t5;
|
||
|
pointF5 = pointF;
|
||
|
pointF6 = pointF2;
|
||
|
break;
|
||
|
}
|
||
|
case 4:
|
||
|
if (jsonReader.peek() == JsonReader.Token.BEGIN_OBJECT) {
|
||
|
jsonReader.beginObject();
|
||
|
float f7 = BitmapDescriptorFactory.HUE_RED;
|
||
|
float f8 = BitmapDescriptorFactory.HUE_RED;
|
||
|
float f9 = BitmapDescriptorFactory.HUE_RED;
|
||
|
float f10 = BitmapDescriptorFactory.HUE_RED;
|
||
|
while (jsonReader.hasNext()) {
|
||
|
PointF pointF15 = pointF5;
|
||
|
int selectName2 = jsonReader.selectName(INTERPOLATOR_NAMES);
|
||
|
if (selectName2 != 0) {
|
||
|
pointF3 = pointF6;
|
||
|
if (selectName2 == 1) {
|
||
|
if (jsonReader.peek() == JsonReader.Token.NUMBER) {
|
||
|
f10 = (float) jsonReader.nextDouble();
|
||
|
f8 = f10;
|
||
|
} else {
|
||
|
jsonReader.beginArray();
|
||
|
f8 = (float) jsonReader.nextDouble();
|
||
|
f10 = jsonReader.peek() == JsonReader.Token.NUMBER ? (float) jsonReader.nextDouble() : f8;
|
||
|
jsonReader.endArray();
|
||
|
}
|
||
|
} else {
|
||
|
jsonReader.skipValue();
|
||
|
}
|
||
|
} else {
|
||
|
pointF3 = pointF6;
|
||
|
if (jsonReader.peek() == JsonReader.Token.NUMBER) {
|
||
|
f9 = (float) jsonReader.nextDouble();
|
||
|
f7 = f9;
|
||
|
} else {
|
||
|
jsonReader.beginArray();
|
||
|
f7 = (float) jsonReader.nextDouble();
|
||
|
f9 = jsonReader.peek() == JsonReader.Token.NUMBER ? (float) jsonReader.nextDouble() : f7;
|
||
|
jsonReader.endArray();
|
||
|
}
|
||
|
}
|
||
|
pointF5 = pointF15;
|
||
|
pointF6 = pointF3;
|
||
|
}
|
||
|
pointF = pointF5;
|
||
|
pointF2 = pointF6;
|
||
|
PointF pointF16 = new PointF(f7, f8);
|
||
|
PointF pointF17 = new PointF(f9, f10);
|
||
|
jsonReader.endObject();
|
||
|
pointF11 = pointF16;
|
||
|
pointF12 = pointF17;
|
||
|
t4 = t5;
|
||
|
pointF5 = pointF;
|
||
|
pointF6 = pointF2;
|
||
|
break;
|
||
|
} else {
|
||
|
pointF8 = JsonUtils.jsonToPoint(jsonReader, f);
|
||
|
t4 = t5;
|
||
|
break;
|
||
|
}
|
||
|
case 5:
|
||
|
if (jsonReader.nextInt() != 1) {
|
||
|
t4 = t5;
|
||
|
z = false;
|
||
|
break;
|
||
|
} else {
|
||
|
z = true;
|
||
|
t4 = t5;
|
||
|
break;
|
||
|
}
|
||
|
case 6:
|
||
|
pointF6 = JsonUtils.jsonToPoint(jsonReader, f);
|
||
|
t4 = t5;
|
||
|
break;
|
||
|
case 7:
|
||
|
pointF5 = JsonUtils.jsonToPoint(jsonReader, f);
|
||
|
t4 = t5;
|
||
|
break;
|
||
|
default:
|
||
|
jsonReader.skipValue();
|
||
|
t4 = t5;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
PointF pointF18 = pointF5;
|
||
|
PointF pointF19 = pointF6;
|
||
|
T t6 = t4;
|
||
|
PointF pointF20 = pointF11;
|
||
|
jsonReader.endObject();
|
||
|
if (z) {
|
||
|
interpolator = LINEAR_INTERPOLATOR;
|
||
|
t2 = t3;
|
||
|
} else {
|
||
|
if (pointF7 != null && pointF8 != null) {
|
||
|
interpolator = interpolatorFor(pointF7, pointF8);
|
||
|
} else {
|
||
|
if (pointF9 != null && pointF10 != null && pointF20 != null && pointF12 != null) {
|
||
|
interpolatorFor = interpolatorFor(pointF9, pointF20);
|
||
|
interpolatorFor2 = interpolatorFor(pointF10, pointF12);
|
||
|
t = t6;
|
||
|
interpolator = null;
|
||
|
if (interpolatorFor == null && interpolatorFor2 != null) {
|
||
|
keyframe = new Keyframe<>(lottieComposition, t3, t, interpolatorFor, interpolatorFor2, f2, null);
|
||
|
} else {
|
||
|
keyframe = new Keyframe<>(lottieComposition, t3, t, interpolator, f2, null);
|
||
|
}
|
||
|
keyframe.pathCp1 = pointF19;
|
||
|
keyframe.pathCp2 = pointF18;
|
||
|
return keyframe;
|
||
|
}
|
||
|
interpolator = LINEAR_INTERPOLATOR;
|
||
|
}
|
||
|
t2 = t6;
|
||
|
}
|
||
|
t = t2;
|
||
|
interpolatorFor = null;
|
||
|
interpolatorFor2 = null;
|
||
|
if (interpolatorFor == null) {
|
||
|
}
|
||
|
keyframe = new Keyframe<>(lottieComposition, t3, t, interpolator, f2, null);
|
||
|
keyframe.pathCp1 = pointF19;
|
||
|
keyframe.pathCp2 = pointF18;
|
||
|
return keyframe;
|
||
|
}
|
||
|
|
||
|
private static Interpolator interpolatorFor(PointF pointF, PointF pointF2) {
|
||
|
Interpolator linearInterpolator;
|
||
|
pointF.x = MiscUtils.clamp(pointF.x, -1.0f, 1.0f);
|
||
|
pointF.y = MiscUtils.clamp(pointF.y, -100.0f, MAX_CP_VALUE);
|
||
|
pointF2.x = MiscUtils.clamp(pointF2.x, -1.0f, 1.0f);
|
||
|
pointF2.y = MiscUtils.clamp(pointF2.y, -100.0f, MAX_CP_VALUE);
|
||
|
int hashFor = Utils.hashFor(pointF.x, pointF.y, pointF2.x, pointF2.y);
|
||
|
WeakReference<Interpolator> interpolator = getInterpolator(hashFor);
|
||
|
Interpolator interpolator2 = interpolator != null ? interpolator.get() : null;
|
||
|
if (interpolator == null || interpolator2 == null) {
|
||
|
try {
|
||
|
linearInterpolator = C17534xZR.uu_(pointF.x, pointF.y, pointF2.x, pointF2.y);
|
||
|
} catch (IllegalArgumentException e) {
|
||
|
if ("The Path cannot loop back on itself.".equals(e.getMessage())) {
|
||
|
linearInterpolator = C17534xZR.uu_(Math.min(pointF.x, 1.0f), pointF.y, Math.max(pointF2.x, BitmapDescriptorFactory.HUE_RED), pointF2.y);
|
||
|
} else {
|
||
|
linearInterpolator = new LinearInterpolator();
|
||
|
}
|
||
|
}
|
||
|
interpolator2 = linearInterpolator;
|
||
|
try {
|
||
|
putInterpolator(hashFor, new WeakReference(interpolator2));
|
||
|
} catch (ArrayIndexOutOfBoundsException unused) {
|
||
|
}
|
||
|
}
|
||
|
return interpolator2;
|
||
|
}
|
||
|
|
||
|
private static <T> Keyframe<T> parseStaticValue(JsonReader jsonReader, float f, ValueParser<T> valueParser) throws IOException {
|
||
|
return new Keyframe<>(valueParser.parse(jsonReader, f));
|
||
|
}
|
||
|
}
|