what-the-bank/sources/com/airbnb/lottie/utils/Utils.java

236 lines
8.7 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.airbnb.lottie.utils;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.graphics.PointF;
import android.graphics.RectF;
import android.provider.Settings;
import com.airbnb.lottie.L;
import com.airbnb.lottie.animation.LPaint;
import com.airbnb.lottie.animation.content.TrimPathContent;
import com.airbnb.lottie.animation.keyframe.FloatKeyframeAnimation;
import java.io.Closeable;
import java.io.InterruptedIOException;
import java.net.ProtocolException;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.net.UnknownServiceException;
import java.nio.channels.ClosedChannelException;
import javax.net.ssl.SSLException;
/* loaded from: classes.dex */
public final class Utils {
public static final int SECOND_IN_NANOS = 1000000000;
private static final ThreadLocal<PathMeasure> threadLocalPathMeasure = new ThreadLocal<PathMeasure>() { // from class: com.airbnb.lottie.utils.Utils.1
/* JADX INFO: Access modifiers changed from: protected */
/* JADX WARN: Can't rename method to resolve collision */
@Override // java.lang.ThreadLocal
public PathMeasure initialValue() {
return new PathMeasure();
}
};
private static final ThreadLocal<Path> threadLocalTempPath = new ThreadLocal<Path>() { // from class: com.airbnb.lottie.utils.Utils.2
/* JADX INFO: Access modifiers changed from: protected */
/* JADX WARN: Can't rename method to resolve collision */
@Override // java.lang.ThreadLocal
public Path initialValue() {
return new Path();
}
};
private static final ThreadLocal<Path> threadLocalTempPath2 = new ThreadLocal<Path>() { // from class: com.airbnb.lottie.utils.Utils.3
/* JADX INFO: Access modifiers changed from: protected */
/* JADX WARN: Can't rename method to resolve collision */
@Override // java.lang.ThreadLocal
public Path initialValue() {
return new Path();
}
};
private static final ThreadLocal<float[]> threadLocalPoints = new ThreadLocal<float[]>() { // from class: com.airbnb.lottie.utils.Utils.4
/* JADX INFO: Access modifiers changed from: protected */
@Override // java.lang.ThreadLocal
public float[] initialValue() {
return new float[4];
}
};
private static final float INV_SQRT_2 = (float) (Math.sqrt(2.0d) / 2.0d);
public static int hashFor(float f, float f2, float f3, float f4) {
int i = f != 0.0f ? (int) (f * 527.0f) : 17;
if (f2 != 0.0f) {
i = (int) (i * 31 * f2);
}
if (f3 != 0.0f) {
i = (int) (i * 31 * f3);
}
return f4 != 0.0f ? (int) (i * 31 * f4) : i;
}
public static boolean isAtLeastVersion(int i, int i2, int i3, int i4, int i5, int i6) {
if (i < i4) {
return false;
}
if (i > i4) {
return true;
}
if (i2 < i5) {
return false;
}
return i2 > i5 || i3 >= i6;
}
private Utils() {
}
public static Path createPath(PointF pointF, PointF pointF2, PointF pointF3, PointF pointF4) {
Path path = new Path();
path.moveTo(pointF.x, pointF.y);
if (pointF3 != null && pointF4 != null && (pointF3.length() != 0.0f || pointF4.length() != 0.0f)) {
path.cubicTo(pointF3.x + pointF.x, pointF.y + pointF3.y, pointF2.x + pointF4.x, pointF2.y + pointF4.y, pointF2.x, pointF2.y);
} else {
path.lineTo(pointF2.x, pointF2.y);
}
return path;
}
public static void closeQuietly(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (RuntimeException e) {
throw e;
} catch (Exception unused) {
}
}
}
public static float getScale(Matrix matrix) {
float[] fArr = threadLocalPoints.get();
fArr[0] = 0.0f;
fArr[1] = 0.0f;
float f = INV_SQRT_2;
fArr[2] = f;
fArr[3] = f;
matrix.mapPoints(fArr);
return (float) Math.hypot(fArr[2] - fArr[0], fArr[3] - fArr[1]);
}
public static boolean hasZeroScaleAxis(Matrix matrix) {
float[] fArr = threadLocalPoints.get();
fArr[0] = 0.0f;
fArr[1] = 0.0f;
fArr[2] = 37394.73f;
fArr[3] = 39575.234f;
matrix.mapPoints(fArr);
return fArr[0] == fArr[2] || fArr[1] == fArr[3];
}
public static void applyTrimPathIfNeeded(Path path, TrimPathContent trimPathContent) {
if (trimPathContent == null || trimPathContent.isHidden()) {
return;
}
applyTrimPathIfNeeded(path, ((FloatKeyframeAnimation) trimPathContent.getStart()).getFloatValue() / 100.0f, ((FloatKeyframeAnimation) trimPathContent.getEnd()).getFloatValue() / 100.0f, ((FloatKeyframeAnimation) trimPathContent.getOffset()).getFloatValue() / 360.0f);
}
public static void applyTrimPathIfNeeded(Path path, float f, float f2, float f3) {
L.beginSection("applyTrimPathIfNeeded");
PathMeasure pathMeasure = threadLocalPathMeasure.get();
Path path2 = threadLocalTempPath.get();
Path path3 = threadLocalTempPath2.get();
pathMeasure.setPath(path, false);
float length = pathMeasure.getLength();
if (f == 1.0f && f2 == 0.0f) {
L.endSection("applyTrimPathIfNeeded");
return;
}
if (length < 1.0f || Math.abs((f2 - f) - 1.0f) < 0.01d) {
L.endSection("applyTrimPathIfNeeded");
return;
}
float f4 = f * length;
float f5 = f2 * length;
float f6 = f3 * length;
float min = Math.min(f4, f5) + f6;
float max = Math.max(f4, f5) + f6;
if (min >= length && max >= length) {
min = MiscUtils.floorMod(min, length);
max = MiscUtils.floorMod(max, length);
}
if (min < 0.0f) {
min = MiscUtils.floorMod(min, length);
}
if (max < 0.0f) {
max = MiscUtils.floorMod(max, length);
}
if (min == max) {
path.reset();
L.endSection("applyTrimPathIfNeeded");
return;
}
if (min >= max) {
min -= length;
}
path2.reset();
pathMeasure.getSegment(min, max, path2, true);
if (max > length) {
path3.reset();
pathMeasure.getSegment(0.0f, max % length, path3, true);
path2.addPath(path3);
} else if (min < 0.0f) {
path3.reset();
pathMeasure.getSegment(min + length, length, path3, true);
path2.addPath(path3);
}
path.set(path2);
L.endSection("applyTrimPathIfNeeded");
}
public static float dpScale() {
return Resources.getSystem().getDisplayMetrics().density;
}
public static float getAnimationScale(Context context) {
return Settings.Global.getFloat(context.getContentResolver(), "animator_duration_scale", 1.0f);
}
public static Bitmap resizeBitmapIfNeeded(Bitmap bitmap, int i, int i2) {
if (bitmap.getWidth() == i && bitmap.getHeight() == i2) {
return bitmap;
}
Bitmap createScaledBitmap = Bitmap.createScaledBitmap(bitmap, i, i2, true);
bitmap.recycle();
return createScaledBitmap;
}
public static boolean isNetworkException(Throwable th) {
return (th instanceof SocketException) || (th instanceof ClosedChannelException) || (th instanceof InterruptedIOException) || (th instanceof ProtocolException) || (th instanceof SSLException) || (th instanceof UnknownHostException) || (th instanceof UnknownServiceException);
}
public static void saveLayerCompat(Canvas canvas, RectF rectF, Paint paint) {
saveLayerCompat(canvas, rectF, paint, 31);
}
public static void saveLayerCompat(Canvas canvas, RectF rectF, Paint paint, int i) {
L.beginSection("Utils#saveLayer");
canvas.saveLayer(rectF, paint);
L.endSection("Utils#saveLayer");
}
public static Bitmap renderPath(Path path) {
RectF rectF = new RectF();
path.computeBounds(rectF, false);
Bitmap createBitmap = Bitmap.createBitmap((int) rectF.right, (int) rectF.bottom, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(createBitmap);
LPaint lPaint = new LPaint();
lPaint.setAntiAlias(true);
lPaint.setColor(-16776961);
canvas.drawPath(path, lPaint);
return createBitmap;
}
}