package c.l.a; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.view.animation.AnimationUtils; import androidx.annotation.IntRange; import androidx.annotation.VisibleForTesting; import androidx.annotation.WorkerThread; import androidx.vectordrawable.graphics.drawable.Animatable2Compat; import com.linecorp.apng.decoder.Apng; import com.linecorp.apng.decoder.ApngException; import d0.t.k; import d0.z.d.m; import d0.z.d.o; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import kotlin.jvm.functions.Function0; /* compiled from: ApngDrawable.kt */ public final class a extends Drawable implements Animatable2Compat { @IntRange(from = 0, to = 2147483647L) public final int i; @IntRange(from = 1, to = 2147483647L) public final int j; public final List k = k.toList(this.w.a.getFrameDurations()); @IntRange(from = 0, to = 2147483647L) public final int l = this.w.a.getByteCount(); @IntRange(from = -1, to = 2147483647L) public int m; public final Paint n; public final List o; public final List p; public final int[] q; public int r; /* renamed from: s reason: collision with root package name */ public int f1460s; public boolean t; public long u; public Long v; public C0152a w; /* compiled from: ApngDrawable.kt */ /* renamed from: c.l.a.a$a reason: collision with other inner class name */ public static final class C0152a extends Drawable.ConstantState { public final Apng a; public final int b; /* renamed from: c reason: collision with root package name */ public final int f1461c; public final int d; public final Function0 e; /* compiled from: ApngDrawable.kt */ /* renamed from: c.l.a.a$a$a reason: collision with other inner class name */ public static final class C0153a extends o implements Function0 { public static final C0153a i = new C0153a(); public C0153a() { super(0); } /* Return type fixed from 'java.lang.Object' to match base method */ @Override // kotlin.jvm.functions.Function0 /* renamed from: invoke */ public Long mo1invoke() { return Long.valueOf(AnimationUtils.currentAnimationTimeMillis()); } } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public C0152a(C0152a aVar) { this(aVar.a.copy(), aVar.b, aVar.f1461c, aVar.d, aVar.e); m.checkNotNullParameter(aVar, "apngState"); } public C0152a(Apng apng, @IntRange(from = 1, to = 2147483647L) int i, @IntRange(from = 1, to = 2147483647L) int i2, int i3, Function0 function0) { m.checkNotNullParameter(apng, "apng"); m.checkNotNullParameter(function0, "currentTimeProvider"); this.a = apng; this.b = i; this.f1461c = i2; this.d = i3; this.e = function0; } @Override // android.graphics.drawable.Drawable.ConstantState public int getChangingConfigurations() { return 0; } @Override // android.graphics.drawable.Drawable.ConstantState public Drawable newDrawable() { return new a(new C0152a(this)); } } @VisibleForTesting public a(C0152a aVar) { m.checkNotNullParameter(aVar, "apngState"); this.w = aVar; this.i = aVar.a.getDuration(); int frameCount = this.w.a.getFrameCount(); this.j = frameCount; this.w.a.getAllFrameByteCount(); this.m = this.w.a.getLoopCount(); this.w.a.isRecycled(); this.n = new Paint(6); this.o = new ArrayList(); this.p = new ArrayList(); this.q = new int[frameCount]; C0152a aVar2 = this.w; this.r = aVar2.b; this.f1460s = aVar2.f1461c; for (int i = 1; i < frameCount; i++) { int[] iArr = this.q; int i2 = i - 1; iArr[i] = iArr[i2] + this.w.a.getFrameDurations()[i2]; } Rect bounds = getBounds(); C0152a aVar3 = this.w; bounds.set(0, 0, aVar3.b, aVar3.f1461c); } @WorkerThread public static final a a(InputStream inputStream, @IntRange(from = 1, to = 2147483647L) Integer num, @IntRange(from = 1, to = 2147483647L) Integer num2) throws ApngException { m.checkNotNullParameter(inputStream, "stream"); boolean z2 = true; if (!((num == null) ^ (num2 == null))) { if (num == null || num.intValue() > 0) { if (num2 != null && num2.intValue() <= 0) { z2 = false; } if (z2) { int i = (num == null && num2 == null) ? 160 : 0; Apng decode = Apng.Companion.decode(inputStream); return new a(new C0152a(decode, num != null ? num.intValue() : decode.getWidth(), num2 != null ? num2.intValue() : decode.getHeight(), i, C0152a.C0153a.i)); } throw new IllegalArgumentException(("Can not specify 0 or negative as height value. height = " + num2).toString()); } throw new IllegalArgumentException(("Can not specify 0 or negative as width value. width = " + num).toString()); } throw new IllegalArgumentException(("Can not specify only one side of size. width = " + num + ", height = " + num2).toString()); } public final boolean b() { return this.m != 0 && d() > this.m - 1; } public final int c() { int i; int i2 = 0; long j = (this.u % ((long) this.i)) + ((long) (b() ? this.i : 0)); int i3 = this.j - 1; while (true) { i = (i2 + i3) / 2; int[] iArr = this.q; int i4 = i + 1; if (iArr.length > i4 && j >= ((long) iArr[i4])) { i2 = i4; } else if (i2 == i3 || j >= ((long) iArr[i])) { break; } else { i3 = i; } } return i; } @Override // androidx.vectordrawable.graphics.drawable.Animatable2Compat public void clearAnimationCallbacks() { this.o.clear(); } public final int d() { return (int) (this.u / ((long) this.i)); } @Override // android.graphics.drawable.Drawable public void draw(Canvas canvas) { m.checkNotNullParameter(canvas, "canvas"); if (this.t) { int c2 = c(); long longValue = this.w.e.mo1invoke().longValue(); Long l = this.v; this.u = l == null ? this.u : (this.u + longValue) - l.longValue(); this.v = Long.valueOf(longValue); boolean z2 = c() != c2; if (this.t) { if (c() == 0) { if ((d() == 0) && l == null) { for (Animatable2Compat.AnimationCallback animationCallback : this.o) { animationCallback.onAnimationStart(this); } } } if (c() == this.j - 1) { if ((this.m == 0 || d() < this.m - 1) && z2) { for (b bVar : this.p) { bVar.b(this, d() + 2); bVar.a(this, d() + 1); } } } } if (b()) { this.t = false; for (Animatable2Compat.AnimationCallback animationCallback2 : this.o) { animationCallback2.onAnimationEnd(this); } } } Apng apng = this.w.a; int c3 = c(); Rect bounds = getBounds(); m.checkNotNullExpressionValue(bounds, "bounds"); apng.drawWithIndex(c3, canvas, null, bounds, this.n); if (this.t) { invalidateSelf(); } } @Override // android.graphics.drawable.Drawable public Drawable.ConstantState getConstantState() { return this.w; } @Override // android.graphics.drawable.Drawable public int getIntrinsicHeight() { return this.f1460s; } @Override // android.graphics.drawable.Drawable public int getIntrinsicWidth() { return this.r; } @Override // android.graphics.drawable.Drawable public int getOpacity() { return -2; } @Override // android.graphics.drawable.Animatable public boolean isRunning() { return this.t; } @Override // android.graphics.drawable.Drawable public Drawable mutate() { this.w = new C0152a(this.w); return this; } @Override // androidx.vectordrawable.graphics.drawable.Animatable2Compat public void registerAnimationCallback(Animatable2Compat.AnimationCallback animationCallback) { m.checkNotNullParameter(animationCallback, "callback"); this.o.add(animationCallback); } @Override // android.graphics.drawable.Drawable public void setAlpha(int i) { this.n.setAlpha(i); } @Override // android.graphics.drawable.Drawable public void setColorFilter(ColorFilter colorFilter) { this.n.setColorFilter(colorFilter); } @Override // android.graphics.drawable.Animatable public void start() { this.t = true; this.v = null; invalidateSelf(); } @Override // android.graphics.drawable.Animatable public void stop() { this.t = false; invalidateSelf(); } @Override // androidx.vectordrawable.graphics.drawable.Animatable2Compat public boolean unregisterAnimationCallback(Animatable2Compat.AnimationCallback animationCallback) { m.checkNotNullParameter(animationCallback, "callback"); return this.o.remove(animationCallback); } }