discord-jadx/app/src/main/java/com/discord/rlottie/RLottieDrawable.java

580 lines
22 KiB
Java

package com.discord.rlottie;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import androidx.annotation.RawRes;
import d0.g0.c;
import d0.t.k;
import d0.z.d.m;
import java.io.File;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: RLottieDrawable.kt */
public final class RLottieDrawable extends BitmapDrawable implements Animatable {
public static final Handler i = new Handler(Looper.getMainLooper());
public static byte[] j = new byte[65536];
public static final byte[] k = new byte[4096];
public static final ExecutorService l = Executors.newCachedThreadPool();
public static ThreadPoolExecutor m;
public static final Companion n = new Companion(null);
public Runnable A;
public volatile Bitmap B;
public volatile Bitmap C;
public volatile Bitmap D;
public boolean E;
public boolean F;
public boolean G;
public int H;
public boolean I;
public float J;
public float K;
public float L;
public boolean M;
public final Rect N;
public volatile boolean O;
public volatile long P;
public final ArrayList<WeakReference<View>> Q;
public final Runnable R;
public final Runnable S;
public final Runnable T;
public final Runnable U;
public final Runnable V;
public final Runnable W;
public int o;
public int p;
public final int[] q;
public int r;
/* renamed from: s reason: collision with root package name */
public Integer[] f2087s;
public final HashMap<String, Integer> t;
public volatile HashMap<String, Integer> u;
public PlaybackMode v;
public int w;
/* renamed from: x reason: collision with root package name */
public long f2088x;
/* renamed from: y reason: collision with root package name */
public volatile boolean f2089y;
/* renamed from: z reason: collision with root package name */
public Runnable f2090z;
/* compiled from: RLottieDrawable.kt */
public static final class Companion {
public Companion(DefaultConstructorMarker defaultConstructorMarker) {
}
public final native long create(String str, int i, int i2, int[] iArr, boolean z2, int[] iArr2, boolean z3);
public final native void createCache(long j, int i, int i2);
public final native long createWithJson(String str, String str2, int[] iArr, int[] iArr2);
public final native int getFrame(long j, int i, Bitmap bitmap, int i2, int i3, int i4, boolean z2);
public final native void replaceColors(long j, int[] iArr);
public final native void setLayerColor(long j, String str, int i);
}
/* compiled from: RLottieDrawable.kt */
public enum PlaybackMode {
LOOP,
ONCE,
FREEZE
}
/* compiled from: java-style lambda group */
public static final class a implements Runnable {
public final /* synthetic */ int i;
public final /* synthetic */ Object j;
public a(int i, Object obj) {
this.i = i;
this.j = obj;
}
@Override // java.lang.Runnable
public final void run() {
ThreadPoolExecutor threadPoolExecutor;
switch (this.i) {
case 0:
Objects.requireNonNull((RLottieDrawable) this.j);
if (((RLottieDrawable) this.j).P == 0) {
RLottieDrawable.i.post(((RLottieDrawable) this.j).R);
return;
}
if (((RLottieDrawable) this.j).D == null) {
try {
RLottieDrawable rLottieDrawable = (RLottieDrawable) this.j;
rLottieDrawable.D = Bitmap.createBitmap(rLottieDrawable.o, rLottieDrawable.p, Bitmap.Config.ARGB_8888);
} catch (Throwable th) {
Log.e("RLottieDrawable", "Error Loading Frame in Runnable", th);
}
}
if (((RLottieDrawable) this.j).D != null) {
try {
if (!((RLottieDrawable) this.j).u.isEmpty()) {
for (Map.Entry<String, Integer> entry : ((RLottieDrawable) this.j).u.entrySet()) {
RLottieDrawable.n.setLayerColor(((RLottieDrawable) this.j).P, entry.getKey(), entry.getValue().intValue());
}
((RLottieDrawable) this.j).u.clear();
}
} catch (Exception unused) {
}
RLottieDrawable rLottieDrawable2 = (RLottieDrawable) this.j;
Integer[] numArr = rLottieDrawable2.f2087s;
if (numArr != null) {
RLottieDrawable.n.replaceColors(rLottieDrawable2.P, k.toIntArray(numArr));
}
RLottieDrawable rLottieDrawable3 = (RLottieDrawable) this.j;
rLottieDrawable3.f2087s = null;
try {
Companion companion = RLottieDrawable.n;
long j = rLottieDrawable3.P;
RLottieDrawable rLottieDrawable4 = (RLottieDrawable) this.j;
int i = rLottieDrawable4.H;
Bitmap bitmap = rLottieDrawable4.D;
m.checkNotNull(bitmap);
RLottieDrawable rLottieDrawable5 = (RLottieDrawable) this.j;
int i2 = rLottieDrawable5.o;
int i3 = rLottieDrawable5.p;
Bitmap bitmap2 = rLottieDrawable5.D;
m.checkNotNull(bitmap2);
if (companion.getFrame(j, i, bitmap, i2, i3, bitmap2.getRowBytes(), true) == -1) {
RLottieDrawable.i.post(((RLottieDrawable) this.j).R);
return;
}
RLottieDrawable rLottieDrawable6 = (RLottieDrawable) this.j;
int i4 = 2;
if (rLottieDrawable6.q[2] != 0) {
RLottieDrawable.i.post(rLottieDrawable6.V);
((RLottieDrawable) this.j).q[2] = 0;
}
RLottieDrawable rLottieDrawable7 = (RLottieDrawable) this.j;
rLottieDrawable7.C = rLottieDrawable7.D;
RLottieDrawable rLottieDrawable8 = (RLottieDrawable) this.j;
if (!rLottieDrawable8.I) {
i4 = 1;
}
int i5 = rLottieDrawable8.H + i4;
if (i5 >= rLottieDrawable8.q[0]) {
PlaybackMode playbackMode = rLottieDrawable8.v;
if (playbackMode == PlaybackMode.LOOP) {
rLottieDrawable8.H = 0;
rLottieDrawable8.f2089y = false;
} else if (playbackMode == PlaybackMode.ONCE) {
rLottieDrawable8.H = 0;
rLottieDrawable8.f2089y = true;
((RLottieDrawable) this.j).w++;
} else {
rLottieDrawable8.f2089y = true;
}
} else if (rLottieDrawable8.v == PlaybackMode.FREEZE) {
rLottieDrawable8.f2089y = true;
((RLottieDrawable) this.j).w++;
} else {
rLottieDrawable8.H = i5;
rLottieDrawable8.f2089y = false;
}
} catch (Exception e) {
Log.e("RLottieDrawable", "Error loading frame", e);
}
}
RLottieDrawable.i.post(((RLottieDrawable) this.j).T);
return;
case 1:
RLottieDrawable rLottieDrawable9 = (RLottieDrawable) this.j;
rLottieDrawable9.F = true;
rLottieDrawable9.c();
RLottieDrawable.a((RLottieDrawable) this.j);
return;
case 2:
RLottieDrawable rLottieDrawable10 = (RLottieDrawable) this.j;
rLottieDrawable10.f2090z = null;
RLottieDrawable.a(rLottieDrawable10);
return;
case 3:
Objects.requireNonNull((RLottieDrawable) this.j);
Objects.requireNonNull((RLottieDrawable) this.j);
if (!(((RLottieDrawable) this.j).P == 0 || (threadPoolExecutor = RLottieDrawable.m) == null)) {
RLottieDrawable rLottieDrawable11 = (RLottieDrawable) this.j;
Runnable runnable = rLottieDrawable11.U;
rLottieDrawable11.f2090z = runnable;
threadPoolExecutor.execute(runnable);
}
RLottieDrawable.a((RLottieDrawable) this.j);
return;
case 4:
RLottieDrawable rLottieDrawable12 = (RLottieDrawable) this.j;
if (rLottieDrawable12.f2090z != null) {
Companion companion2 = RLottieDrawable.n;
long j2 = rLottieDrawable12.P;
RLottieDrawable rLottieDrawable13 = (RLottieDrawable) this.j;
companion2.createCache(j2, rLottieDrawable13.o, rLottieDrawable13.p);
RLottieDrawable.i.post(((RLottieDrawable) this.j).S);
return;
}
return;
case 5:
throw null;
case 6:
RLottieDrawable rLottieDrawable14 = (RLottieDrawable) this.j;
rLottieDrawable14.A = null;
RLottieDrawable.a(rLottieDrawable14);
return;
default:
throw null;
}
}
}
public RLottieDrawable(Context context, @RawRes int i2, String str, int i3, int i4, float f, boolean z2, int[] iArr) {
m.checkNotNullParameter(context, "context");
m.checkNotNullParameter(str, "name");
this.q = new int[3];
this.t = new HashMap<>();
this.u = new HashMap<>();
this.v = PlaybackMode.LOOP;
this.J = 60.0f;
this.K = 1.0f;
this.L = 1.0f;
this.N = new Rect();
this.Q = new ArrayList<>();
this.R = new a(6, this);
this.S = new a(2, this);
this.T = new a(1, this);
this.U = new a(4, this);
this.V = new a(3, this);
this.W = new a(0, this);
try {
InputStream openRawResource = context.getResources().openRawResource(i2);
m.checkNotNullExpressionValue(openRawResource, "context.resources.openRawResource(rawRes)");
int i5 = 0;
while (true) {
byte[] bArr = k;
int read = openRawResource.read(bArr, 0, bArr.length);
if (read <= 0) {
break;
}
byte[] bArr2 = j;
int i6 = i5 + read;
if (bArr2.length < i6) {
byte[] bArr3 = new byte[(bArr2.length * 2)];
System.arraycopy(bArr2, 0, bArr3, 0, i5);
j = bArr3;
}
System.arraycopy(bArr, 0, j, i5, read);
i5 = i6;
}
String str2 = new String(j, 0, i5, c.a);
openRawResource.close();
this.o = i3;
this.p = i4;
this.J = f;
Paint paint = getPaint();
m.checkNotNullExpressionValue(paint, "paint");
paint.setFlags(2);
this.P = n.createWithJson(str2, str, this.q, iArr);
this.r = Math.max(16, (int) (1000.0f / ((float) this.q[1])));
this.v = PlaybackMode.LOOP;
if (z2) {
e(true);
}
} catch (Throwable th) {
Log.e("RLottieDrawable", "Error Constructing", th);
}
}
public RLottieDrawable(File file, int i2, int i3, boolean z2, boolean z3, float f, int[] iArr, int i4) {
m.checkNotNullParameter(file, "file");
int[] iArr2 = new int[3];
this.q = iArr2;
this.t = new HashMap<>();
this.u = new HashMap<>();
this.v = PlaybackMode.LOOP;
this.J = 60.0f;
this.K = 1.0f;
this.L = 1.0f;
this.N = new Rect();
this.Q = new ArrayList<>();
this.R = new a(6, this);
this.S = new a(2, this);
this.T = new a(1, this);
this.U = new a(4, this);
this.V = new a(3, this);
this.W = new a(0, this);
this.o = i2;
this.p = i3;
this.I = z3;
this.J = f;
Paint paint = getPaint();
m.checkNotNullExpressionValue(paint, "paint");
paint.setFlags(2);
Companion companion = n;
String absolutePath = file.getAbsolutePath();
m.checkNotNullExpressionValue(absolutePath, "file.absolutePath");
this.P = companion.create(absolutePath, i2, i3, iArr2, z2, null, this.I);
if (z2 && m == null) {
m = new ThreadPoolExecutor(1, 1, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue());
}
if (this.P == 0) {
file.delete();
}
if (this.I && iArr2[1] < 60) {
this.I = false;
}
this.r = Math.max(this.I ? 33 : 16, (int) (1000.0f / ((float) iArr2[1])));
}
public static final void a(RLottieDrawable rLottieDrawable) {
if (rLottieDrawable.P == 0) {
if (rLottieDrawable.B != null) {
Bitmap bitmap = rLottieDrawable.B;
m.checkNotNull(bitmap);
bitmap.recycle();
rLottieDrawable.B = null;
}
if (rLottieDrawable.D != null) {
Bitmap bitmap2 = rLottieDrawable.D;
m.checkNotNull(bitmap2);
bitmap2.recycle();
rLottieDrawable.D = null;
return;
}
return;
}
if (!rLottieDrawable.b()) {
rLottieDrawable.O = false;
}
rLottieDrawable.d();
}
public final boolean b() {
if (getCallback() != null) {
return true;
}
for (int size = this.Q.size(); size > 0; size--) {
if (this.Q.get(0).get() != null) {
return true;
}
this.Q.remove(0);
}
return false;
}
public final void c() {
int size = this.Q.size();
int i2 = 0;
while (i2 < size) {
View view = this.Q.get(i2).get();
if (view != null) {
view.invalidate();
} else {
this.Q.remove(i2);
size--;
i2--;
}
i2++;
}
if (getCallback() != null) {
invalidateSelf();
}
}
public final boolean d() {
if (this.A != null || this.C != null || this.P == 0) {
return false;
}
if (!this.O) {
boolean z2 = this.E;
if (!z2) {
return false;
}
if (z2 && this.F) {
return false;
}
}
if (!this.t.isEmpty()) {
this.u.putAll(this.t);
this.t.clear();
}
ExecutorService executorService = l;
Runnable runnable = this.W;
this.A = runnable;
executorService.execute(runnable);
return true;
}
@Override // android.graphics.drawable.BitmapDrawable, android.graphics.drawable.Drawable
public void draw(Canvas canvas) {
boolean z2;
m.checkNotNullParameter(canvas, "canvas");
if (this.P != 0) {
long elapsedRealtime = SystemClock.elapsedRealtime();
long abs = Math.abs(elapsedRealtime - this.f2088x);
float f = (float) 60;
int i2 = this.J <= f ? this.r - 6 : this.r;
if (this.O) {
if (this.B == null && this.C == null) {
d();
} else if (this.C != null && (this.B == null || abs >= ((long) i2))) {
if (getCallback() == null) {
int size = this.Q.size();
while (true) {
if (size <= 0) {
break;
} else if (this.Q.get(0).get() == null) {
this.Q.remove(0);
size--;
} else if (this.Q.get(0).get() != null) {
z2 = false;
}
}
}
z2 = true;
if (z2) {
this.D = this.B;
this.B = this.C;
if (this.f2089y) {
this.O = false;
}
this.A = null;
this.F = true;
this.C = null;
if (this.J > f) {
elapsedRealtime -= Math.min(16L, abs - ((long) i2));
}
this.f2088x = elapsedRealtime;
d();
}
}
} else if ((this.G || (this.E && abs >= ((long) i2))) && this.C != null) {
this.D = this.B;
this.B = this.C;
this.A = null;
this.F = true;
this.C = null;
if (this.J > f) {
elapsedRealtime -= Math.min(16L, abs - ((long) i2));
}
this.f2088x = elapsedRealtime;
if (this.G) {
this.F = false;
this.G = false;
}
d();
}
if (this.B != null) {
if (this.M) {
this.N.set(getBounds());
this.K = ((float) this.N.width()) / ((float) this.o);
this.L = ((float) this.N.height()) / ((float) this.p);
this.M = false;
}
canvas.save();
Rect rect = this.N;
canvas.translate((float) rect.left, (float) rect.top);
canvas.scale(this.K, this.L);
Bitmap bitmap = this.B;
m.checkNotNull(bitmap);
canvas.drawBitmap(bitmap, 0.0f, 0.0f, getPaint());
if (this.O) {
c();
}
canvas.restore();
}
}
}
public final void e(boolean z2) {
this.E = z2;
if (z2) {
d();
}
}
public final void f(PlaybackMode playbackMode) {
m.checkNotNullParameter(playbackMode, "value");
if (this.v != PlaybackMode.ONCE || playbackMode != PlaybackMode.FREEZE || this.H == 0) {
this.v = playbackMode;
}
}
@Override // android.graphics.drawable.BitmapDrawable, android.graphics.drawable.Drawable
public int getIntrinsicHeight() {
return this.p;
}
@Override // android.graphics.drawable.BitmapDrawable, android.graphics.drawable.Drawable
public int getIntrinsicWidth() {
return this.o;
}
@Override // android.graphics.drawable.Drawable
public int getMinimumHeight() {
return this.p;
}
@Override // android.graphics.drawable.Drawable
public int getMinimumWidth() {
return this.o;
}
@Override // android.graphics.drawable.BitmapDrawable, android.graphics.drawable.Drawable
public int getOpacity() {
return -2;
}
@Override // android.graphics.drawable.Animatable
public boolean isRunning() {
return this.O;
}
@Override // android.graphics.drawable.BitmapDrawable, android.graphics.drawable.Drawable
public void onBoundsChange(Rect rect) {
m.checkNotNullParameter(rect, "bounds");
super.onBoundsChange(rect);
this.M = true;
}
@Override // android.graphics.drawable.Animatable
public void start() {
if (this.O) {
return;
}
if (this.v.compareTo(PlaybackMode.ONCE) < 0 || this.w == 0) {
this.O = true;
d();
c();
}
}
@Override // android.graphics.drawable.Animatable
public void stop() {
this.O = false;
}
}