package e;

import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.StateSet;
import androidx.appcompat.widget.q0;
import androidx.core.content.res.k;
import e.b;
import e.d;
import j.h;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: compiled from: AnimatedStateListDrawableCompat.java */
/* JADX INFO: loaded from: classes.dex */
public class a extends e.d implements androidx.core.graphics.drawable.b {

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    private c f4544s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    private g f4545t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    private int f4546u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    private int f4547v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    private boolean f4548w;

    /* JADX INFO: compiled from: AnimatedStateListDrawableCompat.java */
    private static class b extends g {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final Animatable f4549a;

        b(Animatable animatable) {
            super();
            this.f4549a = animatable;
        }

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

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

    /* JADX INFO: compiled from: AnimatedStateListDrawableCompat.java */
    static class c extends d.a {
        j.d<Long> K;
        h<Integer> L;

        c(c cVar, a aVar, Resources resources) {
            super(cVar, aVar, resources);
            if (cVar != null) {
                this.K = cVar.K;
                this.L = cVar.L;
            } else {
                this.K = new j.d<>();
                this.L = new h<>();
            }
        }

        private static long E(int i3, int i4) {
            return ((long) i4) | (((long) i3) << 32);
        }

        int C(int[] iArr, Drawable drawable, int i3) {
            int iA = super.A(iArr, drawable);
            this.L.i(iA, Integer.valueOf(i3));
            return iA;
        }

        int D(int i3, int i4, Drawable drawable, boolean z2) {
            int iA = super.a(drawable);
            long jE = E(i3, i4);
            long j3 = z2 ? 8589934592L : 0L;
            long j4 = iA;
            this.K.a(jE, Long.valueOf(j4 | j3));
            if (z2) {
                this.K.a(E(i4, i3), Long.valueOf(4294967296L | j4 | j3));
            }
            return iA;
        }

        int F(int i3) {
            if (i3 < 0) {
                return 0;
            }
            return this.L.f(i3, 0).intValue();
        }

        int G(int[] iArr) {
            int iB = super.B(iArr);
            return iB >= 0 ? iB : super.B(StateSet.WILD_CARD);
        }

        int H(int i3, int i4) {
            return (int) this.K.f(E(i3, i4), -1L).longValue();
        }

        boolean I(int i3, int i4) {
            return (this.K.f(E(i3, i4), -1L).longValue() & 4294967296L) != 0;
        }

        boolean J(int i3, int i4) {
            return (this.K.f(E(i3, i4), -1L).longValue() & 8589934592L) != 0;
        }

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

        @Override // e.d.a, e.b.d
        void s() {
            this.K = this.K.clone();
            this.L = this.L.clone();
        }

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

    /* JADX INFO: compiled from: AnimatedStateListDrawableCompat.java */
    private static class d extends g {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final androidx.vectordrawable.graphics.drawable.b f4550a;

        d(androidx.vectordrawable.graphics.drawable.b bVar) {
            super();
            this.f4550a = bVar;
        }

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

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

    /* JADX INFO: compiled from: AnimatedStateListDrawableCompat.java */
    private static class e extends g {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final ObjectAnimator f4551a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final boolean f4552b;

        e(AnimationDrawable animationDrawable, boolean z2, boolean z3) {
            super();
            int numberOfFrames = animationDrawable.getNumberOfFrames();
            int i3 = z2 ? numberOfFrames - 1 : 0;
            int i4 = z2 ? 0 : numberOfFrames - 1;
            f fVar = new f(animationDrawable, z2);
            ObjectAnimator objectAnimatorOfInt = ObjectAnimator.ofInt(animationDrawable, "currentIndex", i3, i4);
            if (Build.VERSION.SDK_INT >= 18) {
                f.b.a(objectAnimatorOfInt, true);
            }
            objectAnimatorOfInt.setDuration(fVar.a());
            objectAnimatorOfInt.setInterpolator(fVar);
            this.f4552b = z3;
            this.f4551a = objectAnimatorOfInt;
        }

        @Override // e.a.g
        public boolean a() {
            return this.f4552b;
        }

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

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

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

    /* JADX INFO: compiled from: AnimatedStateListDrawableCompat.java */
    private static class f implements TimeInterpolator {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private int[] f4553a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private int f4554b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private int f4555c;

        f(AnimationDrawable animationDrawable, boolean z2) {
            b(animationDrawable, z2);
        }

        int a() {
            return this.f4555c;
        }

        int b(AnimationDrawable animationDrawable, boolean z2) {
            int numberOfFrames = animationDrawable.getNumberOfFrames();
            this.f4554b = numberOfFrames;
            int[] iArr = this.f4553a;
            if (iArr == null || iArr.length < numberOfFrames) {
                this.f4553a = new int[numberOfFrames];
            }
            int[] iArr2 = this.f4553a;
            int i3 = 0;
            for (int i4 = 0; i4 < numberOfFrames; i4++) {
                int duration = animationDrawable.getDuration(z2 ? (numberOfFrames - i4) - 1 : i4);
                iArr2[i4] = duration;
                i3 += duration;
            }
            this.f4555c = i3;
            return i3;
        }

        @Override // android.animation.TimeInterpolator
        public float getInterpolation(float f3) {
            int i3 = (int) ((f3 * this.f4555c) + 0.5f);
            int i4 = this.f4554b;
            int[] iArr = this.f4553a;
            int i5 = 0;
            while (i5 < i4 && i3 >= iArr[i5]) {
                i3 -= iArr[i5];
                i5++;
            }
            return (i5 / i4) + (i5 < i4 ? i3 / this.f4555c : 0.0f);
        }
    }

    /* JADX INFO: compiled from: AnimatedStateListDrawableCompat.java */
    private static abstract class g {
        private g() {
        }

        public boolean a() {
            return false;
        }

        public void b() {
        }

        public abstract void c();

        public abstract void d();
    }

    public a() {
        this(null, null);
    }

    public static a l(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException {
        String name = xmlPullParser.getName();
        if (name.equals("animated-selector")) {
            a aVar = new a();
            aVar.m(context, resources, xmlPullParser, attributeSet, theme);
            return aVar;
        }
        throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": invalid animated-selector tag " + name);
    }

    private void n(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException {
        int depth = xmlPullParser.getDepth() + 1;
        while (true) {
            int next = xmlPullParser.next();
            if (next == 1) {
                return;
            }
            int depth2 = xmlPullParser.getDepth();
            if (depth2 < depth && next == 3) {
                return;
            }
            if (next == 2 && depth2 <= depth) {
                if (xmlPullParser.getName().equals("item")) {
                    p(context, resources, xmlPullParser, attributeSet, theme);
                } else if (xmlPullParser.getName().equals("transition")) {
                    q(context, resources, xmlPullParser, attributeSet, theme);
                }
            }
        }
    }

    private void o() {
        onStateChange(getState());
    }

    private int p(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException {
        int next;
        TypedArray typedArrayK = k.k(resources, theme, attributeSet, f.e.f4613h);
        int resourceId = typedArrayK.getResourceId(f.e.f4614i, 0);
        int resourceId2 = typedArrayK.getResourceId(f.e.f4615j, -1);
        Drawable drawableJ = resourceId2 > 0 ? q0.h().j(context, resourceId2) : null;
        typedArrayK.recycle();
        int[] iArrJ = j(attributeSet);
        if (drawableJ == null) {
            do {
                next = xmlPullParser.next();
            } while (next == 4);
            if (next != 2) {
                throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or child tag defining a drawable");
            }
            drawableJ = xmlPullParser.getName().equals("vector") ? androidx.vectordrawable.graphics.drawable.h.c(resources, xmlPullParser, attributeSet, theme) : Build.VERSION.SDK_INT >= 21 ? f.c.a(resources, xmlPullParser, attributeSet, theme) : Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet);
        }
        if (drawableJ != null) {
            return this.f4544s.C(iArrJ, drawableJ, resourceId);
        }
        throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or child tag defining a drawable");
    }

    private int q(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException {
        int next;
        TypedArray typedArrayK = k.k(resources, theme, attributeSet, f.e.f4616k);
        int resourceId = typedArrayK.getResourceId(f.e.f4619n, -1);
        int resourceId2 = typedArrayK.getResourceId(f.e.f4618m, -1);
        int resourceId3 = typedArrayK.getResourceId(f.e.f4617l, -1);
        Drawable drawableJ = resourceId3 > 0 ? q0.h().j(context, resourceId3) : null;
        boolean z2 = typedArrayK.getBoolean(f.e.f4620o, false);
        typedArrayK.recycle();
        if (drawableJ == null) {
            do {
                next = xmlPullParser.next();
            } while (next == 4);
            if (next != 2) {
                throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <transition> tag requires a 'drawable' attribute or child tag defining a drawable");
            }
            drawableJ = xmlPullParser.getName().equals("animated-vector") ? androidx.vectordrawable.graphics.drawable.b.a(context, resources, xmlPullParser, attributeSet, theme) : Build.VERSION.SDK_INT >= 21 ? f.c.a(resources, xmlPullParser, attributeSet, theme) : Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet);
        }
        if (drawableJ == null) {
            throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <transition> tag requires a 'drawable' attribute or child tag defining a drawable");
        }
        if (resourceId != -1 && resourceId2 != -1) {
            return this.f4544s.D(resourceId, resourceId2, drawableJ, z2);
        }
        throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <transition> tag requires 'fromId' & 'toId' attributes");
    }

    private boolean r(int i3) {
        int iC;
        int iH;
        g bVar;
        g gVar = this.f4545t;
        if (gVar == null) {
            iC = c();
        } else {
            if (i3 == this.f4546u) {
                return true;
            }
            if (i3 == this.f4547v && gVar.a()) {
                gVar.b();
                this.f4546u = this.f4547v;
                this.f4547v = i3;
                return true;
            }
            iC = this.f4546u;
            gVar.d();
        }
        this.f4545t = null;
        this.f4547v = -1;
        this.f4546u = -1;
        c cVar = this.f4544s;
        int iF = cVar.F(iC);
        int iF2 = cVar.F(i3);
        if (iF2 == 0 || iF == 0 || (iH = cVar.H(iF, iF2)) < 0) {
            return false;
        }
        boolean zJ = cVar.J(iF, iF2);
        f(iH);
        Object current = getCurrent();
        if (current instanceof AnimationDrawable) {
            bVar = new e((AnimationDrawable) current, cVar.I(iF, iF2), zJ);
        } else {
            if (!(current instanceof androidx.vectordrawable.graphics.drawable.b)) {
                if (current instanceof Animatable) {
                    bVar = new b((Animatable) current);
                }
                return false;
            }
            bVar = new d((androidx.vectordrawable.graphics.drawable.b) current);
        }
        bVar.c();
        this.f4545t = bVar;
        this.f4547v = iC;
        this.f4546u = i3;
        return true;
    }

    private void s(TypedArray typedArray) {
        c cVar = this.f4544s;
        if (Build.VERSION.SDK_INT >= 21) {
            cVar.f4573d |= f.c.b(typedArray);
        }
        cVar.y(typedArray.getBoolean(f.e.f4609d, cVar.f4578i));
        cVar.u(typedArray.getBoolean(f.e.f4610e, cVar.f4581l));
        cVar.v(typedArray.getInt(f.e.f4611f, cVar.A));
        cVar.w(typedArray.getInt(f.e.f4612g, cVar.B));
        setDither(typedArray.getBoolean(f.e.f4607b, cVar.f4593x));
    }

    @Override // e.d, e.b
    void clearMutated() {
        super.clearMutated();
        this.f4548w = false;
    }

    @Override // e.d, e.b
    void g(b.d dVar) {
        super.g(dVar);
        if (dVar instanceof c) {
            this.f4544s = (c) dVar;
        }
    }

    @Override // e.d, android.graphics.drawable.Drawable
    public boolean isStateful() {
        return true;
    }

    @Override // e.b, android.graphics.drawable.Drawable
    public void jumpToCurrentState() {
        super.jumpToCurrentState();
        g gVar = this.f4545t;
        if (gVar != null) {
            gVar.d();
            this.f4545t = null;
            f(this.f4546u);
            this.f4546u = -1;
            this.f4547v = -1;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    @Override // e.d
    /* JADX INFO: renamed from: k, reason: merged with bridge method [inline-methods] */
    public c b() {
        return new c(this.f4544s, this, null);
    }

    public void m(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException {
        TypedArray typedArrayK = k.k(resources, theme, attributeSet, f.e.f4606a);
        setVisible(typedArrayK.getBoolean(f.e.f4608c, true), true);
        s(typedArrayK);
        h(resources);
        typedArrayK.recycle();
        n(context, resources, xmlPullParser, attributeSet, theme);
        o();
    }

    @Override // e.d, e.b, android.graphics.drawable.Drawable
    public Drawable mutate() {
        if (!this.f4548w && super.mutate() == this) {
            this.f4544s.s();
            this.f4548w = true;
        }
        return this;
    }

    @Override // e.d, e.b, android.graphics.drawable.Drawable
    protected boolean onStateChange(int[] iArr) {
        int iG = this.f4544s.G(iArr);
        boolean z2 = iG != c() && (r(iG) || f(iG));
        Drawable current = getCurrent();
        return current != null ? z2 | current.setState(iArr) : z2;
    }

    @Override // e.b, android.graphics.drawable.Drawable
    public boolean setVisible(boolean z2, boolean z3) {
        boolean visible = super.setVisible(z2, z3);
        g gVar = this.f4545t;
        if (gVar != null && (visible || z3)) {
            if (z2) {
                gVar.c();
            } else {
                jumpToCurrentState();
            }
        }
        return visible;
    }

    a(c cVar, Resources resources) {
        super(null);
        this.f4546u = -1;
        this.f4547v = -1;
        g(new c(cVar, this, resources));
        onStateChange(getState());
        jumpToCurrentState();
    }
}
