package com.airbnb.lottie;

import android.animation.Animator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import android.view.Choreographer;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import defpackage.a65;
import defpackage.el5;
import defpackage.gh5;
import defpackage.gl5;
import defpackage.gp5;
import defpackage.ha1;
import defpackage.hl5;
import defpackage.i05;
import defpackage.i35;
import defpackage.j35;
import defpackage.kk5;
import defpackage.mx5;
import defpackage.n20;
import defpackage.o55;
import defpackage.p55;
import defpackage.ph4;
import defpackage.qh4;
import defpackage.qk9;
import defpackage.sda;
import defpackage.tb5;
import defpackage.uv;
import defpackage.uy7;
import defpackage.vw2;
import defpackage.wk;
import defpackage.xg3;
import defpackage.xk5;
import defpackage.xv7;
import defpackage.y55;
import defpackage.yg3;
import defpackage.zj5;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes.dex */
public class g extends Drawable implements Drawable.Callback, Animatable {
    public static final List av = Arrays.asList("reduced motion", "reduced_motion", "reduced-motion", "reducedmotion");
    public static final ThreadPoolExecutor aw = new ThreadPoolExecutor(0, 2, 35, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new el5());
    public zj5 a;
    public boolean aa;
    public uy7 ab;
    public boolean ac;
    public final Matrix ad;
    public Bitmap ae;
    public Canvas af;
    public Rect ag;
    public RectF ah;
    public p55 ai;
    public Rect aj;
    public Rect ak;
    public RectF al;
    public RectF am;
    public Matrix an;
    public final float[] ao;
    public Matrix ap;
    public boolean aq;
    public uv ar;
    public final Semaphore as;
    public final tb5 at;
    public float au;
    public final gl5 b;
    public final boolean c;
    public boolean d;
    public boolean e;
    public b f;
    public final ArrayList i;
    public qh4 j;
    public String k;
    public ph4 l;
    public yg3 m;
    public Map n;
    public String o;
    public xg3 p;
    public qk9 q;
    public final h r;
    public boolean s;
    public boolean t;
    public ha1 u;
    public int v;
    public boolean w;
    public boolean x;
    public boolean y;
    public boolean z;

    public interface a {
        void run();
    }

    /* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */
    /* JADX WARN: Unknown enum class pattern. Please report as an issue! */
    public static final class b {
        public static final b a;
        public static final b b;
        public static final b c;
        public static final /* synthetic */ b[] d;

        static {
            b bVar = new b("NONE", 0);
            a = bVar;
            b bVar2 = new b("PLAY", 1);
            b = bVar2;
            b bVar3 = new b("RESUME", 2);
            c = bVar3;
            d = new b[]{bVar, bVar2, bVar3};
        }

        public static b valueOf(String str) {
            return (b) Enum.valueOf(b.class, str);
        }

        public static b[] values() {
            return (b[]) d.clone();
        }
    }

    @Retention(RetentionPolicy.SOURCE)
    public @interface c {
    }

    public g() {
        gl5 gl5Var = new gl5();
        gl5Var.d = 1.0f;
        gl5Var.e = false;
        gl5Var.f = 0L;
        gl5Var.i = 0.0f;
        gl5Var.j = 0.0f;
        gl5Var.k = 0;
        gl5Var.l = -2.1474836E9f;
        gl5Var.m = 2.1474836E9f;
        gl5Var.o = false;
        gl5Var.p = false;
        this.b = gl5Var;
        this.c = true;
        this.d = false;
        this.e = false;
        this.f = b.a;
        this.i = new ArrayList();
        this.r = new h();
        this.s = false;
        this.t = true;
        this.v = 255;
        this.aa = false;
        this.ab = uy7.a;
        this.ac = false;
        this.ad = new Matrix();
        this.ao = new float[9];
        this.aq = false;
        n20 n20Var = new n20(this, 4);
        this.as = new Semaphore(1);
        this.at = new tb5(this, 2);
        this.au = -3.4028235E38f;
        gl5Var.addUpdateListener(n20Var);
    }

    public static void f(Rect rect, RectF rectF) {
        rect.set((int) Math.floor(rectF.left), (int) Math.floor(rectF.top), (int) Math.ceil(rectF.right), (int) Math.ceil(rectF.bottom));
    }

    public final void a(final i35 i35Var, final Object obj, final hl5 hl5Var) {
        ha1 ha1Var = this.u;
        if (ha1Var == null) {
            this.i.add(new a() { // from class: com.airbnb.lottie.c
                @Override // com.airbnb.lottie.g.a
                public final void run() {
                    List list = g.av;
                    this.a.a(i35Var, obj, hl5Var);
                }
            });
            return;
        }
        boolean zIsEmpty = true;
        if (i35Var == i35.c) {
            ha1Var.h(hl5Var, obj);
        } else {
            j35 j35Var = i35Var.b;
            if (j35Var != null) {
                j35Var.h(hl5Var, obj);
            } else {
                ArrayList arrayList = new ArrayList();
                this.u.c(i35Var, 0, arrayList, new i35(new String[0]));
                for (int i = 0; i < arrayList.size(); i++) {
                    ((i35) arrayList.get(i)).b.h(hl5Var, obj);
                }
                zIsEmpty = true ^ arrayList.isEmpty();
            }
        }
        if (zIsEmpty) {
            invalidateSelf();
            if (obj == xk5.z) {
                u(this.b.c());
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0024  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean b(Context context) {
        xv7 xv7Var;
        if (this.d) {
            return true;
        }
        if (!this.c) {
            return false;
        }
        xv7 xv7Var2 = xv7.a;
        if (context != null) {
            Matrix matrix = sda.a;
            xv7Var = Settings.Global.getFloat(context.getContentResolver(), "animator_duration_scale", 1.0f) != 0.0f ? xv7Var2 : xv7.b;
        }
        return xv7Var == xv7Var2;
    }

    public final void c() {
        zj5 zj5Var = this.a;
        if (zj5Var == null) {
            return;
        }
        i05.a aVar = a65.a;
        Rect rect = zj5Var.k;
        List list = Collections.EMPTY_LIST;
        ha1 ha1Var = new ha1(this, new y55(list, zj5Var, "__container", -1L, y55.a.a, -1L, null, list, new wk(), 0, 0, 0, 0.0f, 0.0f, rect.width(), rect.height(), null, null, list, y55.b.a, null, false, null, null, o55.a), zj5Var.j, zj5Var);
        this.u = ha1Var;
        if (this.x) {
            ha1Var.q(true);
        }
        this.u.al = this.t;
    }

    public final void d() {
        gl5 gl5Var = this.b;
        if (gl5Var.o) {
            gl5Var.cancel();
            if (!isVisible()) {
                this.f = b.a;
            }
        }
        this.a = null;
        this.u = null;
        this.j = null;
        this.au = -3.4028235E38f;
        gl5Var.n = null;
        gl5Var.l = -2.1474836E9f;
        gl5Var.m = 2.1474836E9f;
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public final void draw(Canvas canvas) {
        zj5 zj5Var;
        ha1 ha1Var = this.u;
        if (ha1Var == null) {
            return;
        }
        uv uvVar = this.ar;
        if (uvVar == null) {
            uvVar = uv.a;
        }
        boolean z = uvVar == uv.b;
        tb5 tb5Var = this.at;
        ThreadPoolExecutor threadPoolExecutor = aw;
        Semaphore semaphore = this.as;
        gl5 gl5Var = this.b;
        if (z) {
            try {
                semaphore.acquire();
            } catch (InterruptedException unused) {
                if (!z) {
                    return;
                }
                semaphore.release();
                if (ha1Var.ak == gl5Var.c()) {
                    return;
                }
            } catch (Throwable th) {
                if (z) {
                    semaphore.release();
                    if (ha1Var.ak != gl5Var.c()) {
                        threadPoolExecutor.execute(tb5Var);
                    }
                }
                throw th;
            }
        }
        if (z && (zj5Var = this.a) != null) {
            float f = this.au;
            float fC = gl5Var.c();
            this.au = fC;
            if (Math.abs(fC - f) * zj5Var.b() >= 50.0f) {
                u(gl5Var.c());
            }
        }
        if (this.e) {
            try {
                if (this.ac) {
                    m(canvas, ha1Var);
                } else {
                    g(canvas);
                }
            } catch (Throwable unused2) {
                gh5.a.getClass();
            }
        } else if (this.ac) {
            m(canvas, ha1Var);
        } else {
            g(canvas);
        }
        this.aq = false;
        if (z) {
            semaphore.release();
            if (ha1Var.ak == gl5Var.c()) {
                return;
            }
            threadPoolExecutor.execute(tb5Var);
        }
    }

    public final void e() {
        zj5 zj5Var = this.a;
        if (zj5Var == null) {
            return;
        }
        uy7 uy7Var = this.ab;
        int i = zj5Var.o;
        int iOrdinal = uy7Var.ordinal();
        boolean z = false;
        if (iOrdinal != 1 && (iOrdinal == 2 || i > 4)) {
            z = true;
        }
        this.ac = z;
    }

    public final void g(Canvas canvas) {
        ha1 ha1Var = this.u;
        zj5 zj5Var = this.a;
        if (ha1Var == null || zj5Var == null) {
            return;
        }
        Matrix matrix = this.ad;
        matrix.reset();
        if (!getBounds().isEmpty()) {
            matrix.preTranslate(r3.left, r3.top);
            matrix.preScale(r3.width() / zj5Var.k.width(), r3.height() / zj5Var.k.height());
        }
        ha1Var.i(canvas, matrix, this.v, null);
    }

    @Override // android.graphics.drawable.Drawable
    public final int getAlpha() {
        return this.v;
    }

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicHeight() {
        zj5 zj5Var = this.a;
        if (zj5Var == null) {
            return -1;
        }
        return zj5Var.k.height();
    }

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicWidth() {
        zj5 zj5Var = this.a;
        if (zj5Var == null) {
            return -1;
        }
        return zj5Var.k.width();
    }

    @Override // android.graphics.drawable.Drawable
    public final int getOpacity() {
        return -3;
    }

    public final Context h() {
        Drawable.Callback callback = getCallback();
        if (callback != null && (callback instanceof View)) {
            return ((View) callback).getContext();
        }
        return null;
    }

    public final yg3 i() {
        if (getCallback() == null) {
            return null;
        }
        if (this.m == null) {
            yg3 yg3Var = new yg3(getCallback(), this.p);
            this.m = yg3Var;
            String str = this.o;
            if (str != null) {
                yg3Var.e = str;
            }
        }
        return this.m;
    }

    @Override // android.graphics.drawable.Drawable.Callback
    public final void invalidateDrawable(Drawable drawable) {
        Drawable.Callback callback = getCallback();
        if (callback == null) {
            return;
        }
        callback.invalidateDrawable(this);
    }

    @Override // android.graphics.drawable.Drawable
    public final void invalidateSelf() {
        if (this.aq) {
            return;
        }
        this.aq = true;
        Drawable.Callback callback = getCallback();
        if (callback != null) {
            callback.invalidateDrawable(this);
        }
    }

    @Override // android.graphics.drawable.Animatable
    public final boolean isRunning() {
        gl5 gl5Var = this.b;
        if (gl5Var == null) {
            return false;
        }
        return gl5Var.o;
    }

    public final boolean j() {
        return this.r.a.contains(kk5.a);
    }

    public final void k() {
        this.i.clear();
        gl5 gl5Var = this.b;
        gl5Var.g(true);
        Iterator it = gl5Var.c.iterator();
        while (it.hasNext()) {
            ((Animator.AnimatorPauseListener) it.next()).onAnimationPause(gl5Var);
        }
        if (isVisible()) {
            return;
        }
        this.f = b.a;
    }

    public final void l() {
        if (this.u == null) {
            this.i.add(new f(this, 1));
            return;
        }
        e();
        boolean zB = b(h());
        b bVar = b.a;
        gl5 gl5Var = this.b;
        if (zB || gl5Var.getRepeatCount() == 0) {
            if (isVisible()) {
                gl5Var.o = true;
                boolean zF = gl5Var.f();
                Iterator it = gl5Var.b.iterator();
                while (it.hasNext()) {
                    ((Animator.AnimatorListener) it.next()).onAnimationStart(gl5Var, zF);
                }
                gl5Var.h((int) (gl5Var.f() ? gl5Var.d() : gl5Var.e()));
                gl5Var.f = 0L;
                gl5Var.k = 0;
                if (gl5Var.o) {
                    gl5Var.g(false);
                    Choreographer.getInstance().postFrameCallback(gl5Var);
                }
                this.f = bVar;
            } else {
                this.f = b.b;
            }
        }
        if (b(h())) {
            return;
        }
        Iterator it2 = av.iterator();
        gp5 gp5VarD = null;
        while (it2.hasNext()) {
            gp5VarD = this.a.d((String) it2.next());
            if (gp5VarD != null) {
                break;
            }
        }
        if (gp5VarD != null) {
            o((int) gp5VarD.b);
        } else {
            o((int) (gl5Var.d < 0.0f ? gl5Var.e() : gl5Var.d()));
        }
        gl5Var.g(true);
        gl5Var.a(gl5Var.f());
        if (isVisible()) {
            return;
        }
        this.f = bVar;
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x00d5  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m(Canvas canvas, ha1 ha1Var) {
        boolean z;
        if (this.a == null || ha1Var == null) {
            return;
        }
        if (this.af == null) {
            this.af = new Canvas();
            this.am = new RectF();
            this.an = new Matrix();
            this.ap = new Matrix();
            this.ag = new Rect();
            this.ah = new RectF();
            this.ai = new p55();
            this.aj = new Rect();
            this.ak = new Rect();
            this.al = new RectF();
        }
        canvas.getMatrix(this.an);
        canvas.getClipBounds(this.ag);
        Rect rect = this.ag;
        this.ah.set(rect.left, rect.top, rect.right, rect.bottom);
        this.an.mapRect(this.ah);
        f(this.ag, this.ah);
        if (this.t) {
            this.am.set(0.0f, 0.0f, getIntrinsicWidth(), getIntrinsicHeight());
        } else {
            ha1Var.e(this.am, null, false);
        }
        this.an.mapRect(this.am);
        Rect bounds = getBounds();
        float fWidth = bounds.width() / getIntrinsicWidth();
        float fHeight = bounds.height() / getIntrinsicHeight();
        RectF rectF = this.am;
        rectF.set(rectF.left * fWidth, rectF.top * fHeight, rectF.right * fWidth, rectF.bottom * fHeight);
        Drawable.Callback callback = getCallback();
        if (callback instanceof View) {
            ViewParent parent = ((View) callback).getParent();
            if (parent instanceof ViewGroup) {
                z = !((ViewGroup) parent).getClipChildren();
            }
        } else {
            z = false;
        }
        if (!z) {
            RectF rectF2 = this.am;
            Rect rect2 = this.ag;
            rectF2.intersect(rect2.left, rect2.top, rect2.right, rect2.bottom);
        }
        int iCeil = (int) Math.ceil(this.am.width());
        int iCeil2 = (int) Math.ceil(this.am.height());
        if (iCeil <= 0 || iCeil2 <= 0) {
            return;
        }
        Bitmap bitmap = this.ae;
        if (bitmap == null || bitmap.getWidth() < iCeil || this.ae.getHeight() < iCeil2) {
            Bitmap bitmapCreateBitmap = Bitmap.createBitmap(iCeil, iCeil2, Bitmap.Config.ARGB_8888);
            this.ae = bitmapCreateBitmap;
            this.af.setBitmap(bitmapCreateBitmap);
            this.aq = true;
        } else if (this.ae.getWidth() > iCeil || this.ae.getHeight() > iCeil2) {
            Bitmap bitmapCreateBitmap2 = Bitmap.createBitmap(this.ae, 0, 0, iCeil, iCeil2);
            this.ae = bitmapCreateBitmap2;
            this.af.setBitmap(bitmapCreateBitmap2);
            this.aq = true;
        }
        if (this.aq) {
            Matrix matrix = this.an;
            float[] fArr = this.ao;
            matrix.getValues(fArr);
            float f = fArr[0];
            float f2 = fArr[4];
            Matrix matrix2 = this.an;
            Matrix matrix3 = this.ad;
            matrix3.set(matrix2);
            matrix3.preScale(fWidth, fHeight);
            RectF rectF3 = this.am;
            matrix3.postTranslate(-rectF3.left, -rectF3.top);
            matrix3.postScale(1.0f / f, 1.0f / f2);
            this.ae.eraseColor(0);
            this.af.setMatrix(sda.a);
            this.af.scale(f, f2);
            ha1Var.i(this.af, matrix3, this.v, null);
            this.an.invert(this.ap);
            this.ap.mapRect(this.al, this.am);
            f(this.ak, this.al);
        }
        this.aj.set(0, 0, iCeil, iCeil2);
        canvas.drawBitmap(this.ae, this.aj, this.ak, this.ai);
    }

    public final void n() {
        if (this.u == null) {
            this.i.add(new f(this, 0));
            return;
        }
        e();
        boolean zB = b(h());
        b bVar = b.a;
        gl5 gl5Var = this.b;
        if (zB || gl5Var.getRepeatCount() == 0) {
            if (isVisible()) {
                gl5Var.o = true;
                gl5Var.g(false);
                Choreographer.getInstance().postFrameCallback(gl5Var);
                gl5Var.f = 0L;
                if (gl5Var.f() && gl5Var.j == gl5Var.e()) {
                    gl5Var.h(gl5Var.d());
                } else if (!gl5Var.f() && gl5Var.j == gl5Var.d()) {
                    gl5Var.h(gl5Var.e());
                }
                Iterator it = gl5Var.c.iterator();
                while (it.hasNext()) {
                    ((Animator.AnimatorPauseListener) it.next()).onAnimationResume(gl5Var);
                }
                this.f = bVar;
            } else {
                this.f = b.c;
            }
        }
        if (b(h())) {
            return;
        }
        o((int) (gl5Var.d < 0.0f ? gl5Var.e() : gl5Var.d()));
        gl5Var.g(true);
        gl5Var.a(gl5Var.f());
        if (isVisible()) {
            return;
        }
        this.f = bVar;
    }

    public final void o(int i) {
        if (this.a != null) {
            this.b.h(i);
        } else {
            this.i.add(new com.airbnb.lottie.b(this, i, 2));
        }
    }

    public final void p(int i) {
        if (this.a == null) {
            this.i.add(new com.airbnb.lottie.b(this, i, 0));
        } else {
            gl5 gl5Var = this.b;
            gl5Var.i(gl5Var.l, i + 0.99f);
        }
    }

    public final void q(String str) {
        zj5 zj5Var = this.a;
        if (zj5Var == null) {
            this.i.add(new com.airbnb.lottie.a(this, str, 1));
        } else {
            gp5 gp5VarD = zj5Var.d(str);
            if (gp5VarD == null) {
                throw new IllegalArgumentException(vw2.ab("Cannot find marker with name ", str, "."));
            }
            p((int) (gp5VarD.b + gp5VarD.c));
        }
    }

    public final void r(String str) {
        zj5 zj5Var = this.a;
        ArrayList arrayList = this.i;
        if (zj5Var == null) {
            arrayList.add(new com.airbnb.lottie.a(this, str, 0));
            return;
        }
        gp5 gp5VarD = zj5Var.d(str);
        if (gp5VarD == null) {
            throw new IllegalArgumentException(vw2.ab("Cannot find marker with name ", str, "."));
        }
        int i = (int) gp5VarD.b;
        int i2 = ((int) gp5VarD.c) + i;
        if (this.a == null) {
            arrayList.add(new e(this, i, i2));
        } else {
            this.b.i(i, i2 + 0.99f);
        }
    }

    public final void s(int i) {
        if (this.a == null) {
            this.i.add(new com.airbnb.lottie.b(this, i, 1));
        } else {
            this.b.i(i, (int) r0.m);
        }
    }

    @Override // android.graphics.drawable.Drawable.Callback
    public final void scheduleDrawable(Drawable drawable, Runnable runnable, long j) {
        Drawable.Callback callback = getCallback();
        if (callback == null) {
            return;
        }
        callback.scheduleDrawable(this, runnable, j);
    }

    @Override // android.graphics.drawable.Drawable
    public final void setAlpha(int i) {
        this.v = i;
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public final void setColorFilter(ColorFilter colorFilter) {
        gh5.b("Use addColorFilter instead.");
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean setVisible(boolean z, boolean z2) {
        boolean zIsVisible = isVisible();
        boolean visible = super.setVisible(z, z2);
        b bVar = b.c;
        if (z) {
            b bVar2 = this.f;
            if (bVar2 == b.b) {
                l();
                return visible;
            }
            if (bVar2 == bVar) {
                n();
                return visible;
            }
        } else {
            if (this.b.o) {
                k();
                this.f = bVar;
                return visible;
            }
            if (zIsVisible) {
                this.f = b.a;
            }
        }
        return visible;
    }

    @Override // android.graphics.drawable.Animatable
    public final void start() {
        Drawable.Callback callback = getCallback();
        if ((callback instanceof View) && ((View) callback).isInEditMode()) {
            return;
        }
        l();
    }

    @Override // android.graphics.drawable.Animatable
    public final void stop() {
        this.i.clear();
        gl5 gl5Var = this.b;
        gl5Var.g(true);
        gl5Var.a(gl5Var.f());
        if (isVisible()) {
            return;
        }
        this.f = b.a;
    }

    public final void t(String str) {
        zj5 zj5Var = this.a;
        if (zj5Var == null) {
            this.i.add(new com.airbnb.lottie.a(this, str, 2));
        } else {
            gp5 gp5VarD = zj5Var.d(str);
            if (gp5VarD == null) {
                throw new IllegalArgumentException(vw2.ab("Cannot find marker with name ", str, "."));
            }
            s((int) gp5VarD.b);
        }
    }

    public final void u(float f) {
        zj5 zj5Var = this.a;
        if (zj5Var == null) {
            this.i.add(new d(this, f, 2));
        } else {
            this.b.h(mx5.f(zj5Var.l, zj5Var.m, f));
        }
    }

    @Override // android.graphics.drawable.Drawable.Callback
    public final void unscheduleDrawable(Drawable drawable, Runnable runnable) {
        Drawable.Callback callback = getCallback();
        if (callback == null) {
            return;
        }
        callback.unscheduleDrawable(this, runnable);
    }
}
