package defpackage;

import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.content.res.Resources;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.util.StateSet;
import defpackage.if2;
import defpackage.k49;
import defpackage.k81;

/* JADX INFO: loaded from: classes.dex */
public class el extends k49 implements bp9 {
    public c r;
    public g s;
    public int t = -1;
    public int u = -1;
    public boolean v;

    public static class b extends g {
        public final Animatable a;

        public b(Animatable animatable) {
            this.a = animatable;
        }

        @Override // el.g
        public final void c() {
            this.a.start();
        }

        @Override // el.g
        public final void d() {
            this.a.stop();
        }
    }

    public static class c extends k49.a {
        public hj5 aj;
        public wy8 ak;

        public c(c cVar, el elVar, Resources resources) {
            super(cVar, elVar, resources);
            if (cVar != null) {
                this.aj = cVar.aj;
                this.ak = cVar.ak;
            } else {
                this.aj = new hj5();
                this.ak = new wy8();
            }
        }

        @Override // k49.a, if2.c
        public final void d() {
            this.aj = this.aj.clone();
            this.ak = this.ak.clone();
        }

        public final int f(int i) {
            Object obj;
            if (i < 0) {
                return 0;
            }
            wy8 wy8Var = this.ak;
            Object obj2 = 0;
            int iA = C0611ld1.a(wy8Var.d, i, wy8Var.b);
            if (iA >= 0 && (obj = wy8Var.c[iA]) != C0746xy8.a) {
                obj2 = obj;
            }
            return ((Integer) obj2).intValue();
        }

        @Override // k49.a, android.graphics.drawable.Drawable.ConstantState
        public final Drawable newDrawable() {
            return new el(this, null);
        }

        @Override // k49.a, android.graphics.drawable.Drawable.ConstantState
        public final Drawable newDrawable(Resources resources) {
            return new el(this, resources);
        }
    }

    public static class d extends g {
        public final fl a;

        public d(fl flVar) {
            this.a = flVar;
        }

        @Override // el.g
        public final void c() {
            this.a.start();
        }

        @Override // el.g
        public final void d() {
            this.a.stop();
        }
    }

    public static class e extends g {
        public final ObjectAnimator a;
        public final boolean b;

        public e(AnimationDrawable animationDrawable, boolean z, boolean z2) {
            int numberOfFrames = animationDrawable.getNumberOfFrames();
            int i = z ? numberOfFrames - 1 : 0;
            int i2 = z ? 0 : numberOfFrames - 1;
            f fVar = new f();
            int numberOfFrames2 = animationDrawable.getNumberOfFrames();
            fVar.b = numberOfFrames2;
            int[] iArr = fVar.a;
            if (iArr == null || iArr.length < numberOfFrames2) {
                fVar.a = new int[numberOfFrames2];
            }
            int[] iArr2 = fVar.a;
            int i3 = 0;
            for (int i4 = 0; i4 < numberOfFrames2; i4++) {
                int duration = animationDrawable.getDuration(z ? (numberOfFrames2 - i4) - 1 : i4);
                iArr2[i4] = duration;
                i3 += duration;
            }
            fVar.c = i3;
            ObjectAnimator objectAnimatorOfInt = ObjectAnimator.ofInt(animationDrawable, "currentIndex", i, i2);
            k81.b.a(objectAnimatorOfInt, true);
            objectAnimatorOfInt.setDuration(fVar.c);
            objectAnimatorOfInt.setInterpolator(fVar);
            this.b = z2;
            this.a = objectAnimatorOfInt;
        }

        @Override // el.g
        public final boolean a() {
            return this.b;
        }

        @Override // el.g
        public final void b() {
            this.a.reverse();
        }

        @Override // el.g
        public final void c() {
            this.a.start();
        }

        @Override // el.g
        public final void d() {
            this.a.cancel();
        }
    }

    public static class f implements TimeInterpolator {
        public int[] a;
        public int b;
        public int c;

        @Override // android.animation.TimeInterpolator
        public final float getInterpolation(float f) {
            int i = (int) ((f * this.c) + 0.5f);
            int i2 = this.b;
            int[] iArr = this.a;
            int i3 = 0;
            while (i3 < i2) {
                int i4 = iArr[i3];
                if (i < i4) {
                    break;
                }
                i -= i4;
                i3++;
            }
            return (i3 / i2) + (i3 < i2 ? i / this.c : 0.0f);
        }
    }

    public static abstract class g {
        public boolean a() {
            return false;
        }

        public void b() {
        }

        public abstract void c();

        public abstract void d();
    }

    public el(c cVar, Resources resources) {
        e(new c(cVar, this, resources));
        onStateChange(getState());
        jumpToCurrentState();
    }

    @Override // defpackage.k49, defpackage.if2
    public final if2.c b() {
        return new c(this.r, this, null);
    }

    @Override // defpackage.k49, defpackage.if2
    public final void e(if2.c cVar) {
        super.e(cVar);
        if (cVar instanceof c) {
            this.r = (c) cVar;
        }
    }

    @Override // defpackage.k49
    /* JADX INFO: renamed from: f */
    public final k49.a b() {
        return new c(this.r, this, null);
    }

    @Override // defpackage.if2, android.graphics.drawable.Drawable
    public final void jumpToCurrentState() {
        super.jumpToCurrentState();
        g gVar = this.s;
        if (gVar != null) {
            gVar.d();
            this.s = null;
            d(this.t);
            this.t = -1;
            this.u = -1;
        }
    }

    @Override // defpackage.k49, defpackage.if2, android.graphics.drawable.Drawable
    public final Drawable mutate() {
        if (!this.v) {
            super.mutate();
            this.r.d();
            this.v = true;
        }
        return this;
    }

    /* JADX WARN: Removed duplicated region for block: B:43:0x00cb  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00d1  */
    @Override // defpackage.k49, defpackage.if2, android.graphics.drawable.Drawable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean onStateChange(int[] iArr) {
        int iF;
        g bVar;
        c cVar = this.r;
        int iE = cVar.e(iArr);
        if (iE < 0) {
            iE = cVar.e(StateSet.WILD_CARD);
        }
        int i = this.i;
        if (iE != i) {
            g gVar = this.s;
            if (gVar == null) {
                this.s = null;
                this.u = -1;
                this.t = -1;
                c cVar2 = this.r;
                int iF2 = cVar2.f(i);
                iF = cVar2.f(iE);
                if (iF == 0 && iF2 != 0) {
                    long j = ((long) iF) | (((long) iF2) << 32);
                    int iLongValue = (int) ((Long) cVar2.aj.d(j)).longValue();
                    if (iLongValue >= 0) {
                        boolean z = (((Long) cVar2.aj.d(j)).longValue() & 8589934592L) != 0;
                        d(iLongValue);
                        Object obj = this.c;
                        if (obj instanceof AnimationDrawable) {
                            bVar = new e((AnimationDrawable) obj, (((Long) cVar2.aj.d(j)).longValue() & 4294967296L) != 0, z);
                        } else if (obj instanceof fl) {
                            bVar = new d((fl) obj);
                        } else {
                            if (obj instanceof Animatable) {
                                bVar = new b((Animatable) obj);
                            }
                            if (d(iE)) {
                            }
                        }
                        bVar.c();
                        this.s = bVar;
                        this.u = i;
                        this.t = iE;
                        z = true;
                    }
                } else if (d(iE)) {
                    z = true;
                }
            } else {
                if (iE != this.t) {
                    if (iE == this.u && gVar.a()) {
                        gVar.b();
                        this.t = this.u;
                        this.u = iE;
                    } else {
                        i = this.t;
                        gVar.d();
                        this.s = null;
                        this.u = -1;
                        this.t = -1;
                        c cVar22 = this.r;
                        int iF22 = cVar22.f(i);
                        iF = cVar22.f(iE);
                        if (iF == 0) {
                            if (d(iE)) {
                            }
                        }
                    }
                }
                z = true;
            }
        }
        Drawable drawable = this.c;
        return drawable != null ? drawable.setState(iArr) | z : z;
    }

    @Override // defpackage.if2, android.graphics.drawable.Drawable
    public final boolean setVisible(boolean z, boolean z2) {
        boolean visible = super.setVisible(z, z2);
        g gVar = this.s;
        if (gVar != null && (visible || z2)) {
            if (z) {
                gVar.c();
                return visible;
            }
            jumpToCurrentState();
        }
        return visible;
    }
}
