package p016f;

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 org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import p001a0.InterfaceC0009d0;
import p016f.C0675b;
import p016f.C0684g;
import p019g.C0724c;
import p019g.C0728g;
import p019g.C0730i;
import p028j.C1230w2;
import p037m.C1449d;
import p037m.C1458h;
import p071y.C1838q;
import p072y0.C1844e;
import p072y0.C1855l;

/* renamed from: f.a */
/* loaded from: classes.dex */
public class C0667a extends C0684g implements InterfaceC0009d0 {

    /* renamed from: r */
    public C0670c f2214r;

    /* renamed from: s */
    public AbstractC0674g f2215s;

    /* renamed from: t */
    public int f2216t;

    /* renamed from: u */
    public int f2217u;

    /* renamed from: v */
    public boolean f2218v;

    /* renamed from: f.a$b */
    /* loaded from: classes.dex */
    public static class C0669b extends AbstractC0674g {

        /* renamed from: a */
        public final Animatable f2219a;

        public C0669b(Animatable animatable) {
            super();
            this.f2219a = animatable;
        }

        @Override // p016f.C0667a.AbstractC0674g
        /* renamed from: c */
        public void mo3159c() {
            this.f2219a.start();
        }

        @Override // p016f.C0667a.AbstractC0674g
        /* renamed from: d */
        public void mo3158d() {
            this.f2219a.stop();
        }
    }

    /* renamed from: f.a$c */
    /* loaded from: classes.dex */
    public static class C0670c extends C0684g.C0685a {

        /* renamed from: K */
        public C1449d<Long> f2220K;

        /* renamed from: L */
        public C1458h<Integer> f2221L;

        public C0670c(C0670c c0670c, C0667a c0667a, Resources resources) {
            super(c0670c, c0667a, resources);
            C1458h<Integer> c1458h;
            if (c0670c != null) {
                this.f2220K = c0670c.f2220K;
                c1458h = c0670c.f2221L;
            } else {
                this.f2220K = new C1449d<>();
                c1458h = new C1458h<>();
            }
            this.f2221L = c1458h;
        }

        /* renamed from: D */
        public static long m3169D(int i, int i2) {
            return i2 | (i << 32);
        }

        /* renamed from: B */
        public int m3171B(int[] iArr, Drawable drawable, int i) {
            int m3110z = super.m3110z(iArr, drawable);
            this.f2221L.m1311h(m3110z, Integer.valueOf(i));
            return m3110z;
        }

        /* renamed from: C */
        public int m3170C(int i, int i2, Drawable drawable, boolean z) {
            int m3145a = super.m3145a(drawable);
            long m3169D = m3169D(i, i2);
            long j = z ? 8589934592L : 0L;
            long j2 = m3145a;
            this.f2220K.m1368a(m3169D, Long.valueOf(j2 | j));
            if (z) {
                this.f2220K.m1368a(m3169D(i2, i), Long.valueOf(4294967296L | j2 | j));
            }
            return m3145a;
        }

        /* renamed from: E */
        public int m3168E(int i) {
            if (i < 0) {
                return 0;
            }
            return this.f2221L.m1313f(i, 0).intValue();
        }

        /* renamed from: F */
        public int m3167F(int[] iArr) {
            int m3113A = super.m3113A(iArr);
            return m3113A >= 0 ? m3113A : super.m3113A(StateSet.WILD_CARD);
        }

        /* renamed from: G */
        public int m3166G(int i, int i2) {
            return (int) this.f2220K.m1363f(m3169D(i, i2), -1L).longValue();
        }

        /* renamed from: H */
        public boolean m3165H(int i, int i2) {
            return (this.f2220K.m1363f(m3169D(i, i2), -1L).longValue() & 4294967296L) != 0;
        }

        /* renamed from: I */
        public boolean m3164I(int i, int i2) {
            return (this.f2220K.m1363f(m3169D(i, i2), -1L).longValue() & 8589934592L) != 0;
        }

        @Override // p016f.C0684g.C0685a, android.graphics.drawable.Drawable.ConstantState
        public Drawable newDrawable() {
            return new C0667a(this, null);
        }

        @Override // p016f.C0684g.C0685a, android.graphics.drawable.Drawable.ConstantState
        public Drawable newDrawable(Resources resources) {
            return new C0667a(this, resources);
        }

        @Override // p016f.C0684g.C0685a, p016f.C0675b.AbstractC0679d
        /* renamed from: r */
        public void mo3111r() {
            this.f2220K = this.f2220K.clone();
            this.f2221L = this.f2221L.clone();
        }
    }

    /* renamed from: f.a$d */
    /* loaded from: classes.dex */
    public static class C0671d extends AbstractC0674g {

        /* renamed from: a */
        public final C1844e f2222a;

        public C0671d(C1844e c1844e) {
            super();
            this.f2222a = c1844e;
        }

        @Override // p016f.C0667a.AbstractC0674g
        /* renamed from: c */
        public void mo3159c() {
            this.f2222a.start();
        }

        @Override // p016f.C0667a.AbstractC0674g
        /* renamed from: d */
        public void mo3158d() {
            this.f2222a.stop();
        }
    }

    /* renamed from: f.a$e */
    /* loaded from: classes.dex */
    public static class C0672e extends AbstractC0674g {

        /* renamed from: a */
        public final ObjectAnimator f2223a;

        /* renamed from: b */
        public final boolean f2224b;

        public C0672e(AnimationDrawable animationDrawable, boolean z, boolean z2) {
            super();
            int numberOfFrames = animationDrawable.getNumberOfFrames();
            int i = z ? numberOfFrames - 1 : 0;
            int i2 = z ? 0 : numberOfFrames - 1;
            C0673f c0673f = new C0673f(animationDrawable, z);
            ObjectAnimator ofInt = ObjectAnimator.ofInt(animationDrawable, "currentIndex", i, i2);
            if (Build.VERSION.SDK_INT >= 18) {
                C0724c.m3052a(ofInt, true);
            }
            ofInt.setDuration(c0673f.m3163a());
            ofInt.setInterpolator(c0673f);
            this.f2224b = z2;
            this.f2223a = ofInt;
        }

        @Override // p016f.C0667a.AbstractC0674g
        /* renamed from: a */
        public boolean mo3161a() {
            return this.f2224b;
        }

        @Override // p016f.C0667a.AbstractC0674g
        /* renamed from: b */
        public void mo3160b() {
            this.f2223a.reverse();
        }

        @Override // p016f.C0667a.AbstractC0674g
        /* renamed from: c */
        public void mo3159c() {
            this.f2223a.start();
        }

        @Override // p016f.C0667a.AbstractC0674g
        /* renamed from: d */
        public void mo3158d() {
            this.f2223a.cancel();
        }
    }

    /* renamed from: f.a$f */
    /* loaded from: classes.dex */
    public static class C0673f implements TimeInterpolator {

        /* renamed from: a */
        public int[] f2225a;

        /* renamed from: b */
        public int f2226b;

        /* renamed from: c */
        public int f2227c;

        public C0673f(AnimationDrawable animationDrawable, boolean z) {
            m3162b(animationDrawable, z);
        }

        /* renamed from: a */
        public int m3163a() {
            return this.f2227c;
        }

        /* renamed from: b */
        public int m3162b(AnimationDrawable animationDrawable, boolean z) {
            int numberOfFrames = animationDrawable.getNumberOfFrames();
            this.f2226b = numberOfFrames;
            int[] iArr = this.f2225a;
            if (iArr == null || iArr.length < numberOfFrames) {
                this.f2225a = new int[numberOfFrames];
            }
            int[] iArr2 = this.f2225a;
            int i = 0;
            for (int i2 = 0; i2 < numberOfFrames; i2++) {
                int duration = animationDrawable.getDuration(z ? (numberOfFrames - i2) - 1 : i2);
                iArr2[i2] = duration;
                i += duration;
            }
            this.f2227c = i;
            return i;
        }

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

    /* renamed from: f.a$g */
    /* loaded from: classes.dex */
    public static abstract class AbstractC0674g {
        public AbstractC0674g() {
        }

        /* renamed from: a */
        public boolean mo3161a() {
            return false;
        }

        /* renamed from: b */
        public void mo3160b() {
        }

        /* renamed from: c */
        public abstract void mo3159c();

        /* renamed from: d */
        public abstract void mo3158d();
    }

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

    public C0667a(C0670c c0670c, Resources resources) {
        super(null);
        this.f2216t = -1;
        this.f2217u = -1;
        mo3116h(new C0670c(c0670c, this, resources));
        onStateChange(getState());
        jumpToCurrentState();
    }

    /* renamed from: m */
    public static C0667a m3179m(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
        String name = xmlPullParser.getName();
        if (name.equals("animated-selector")) {
            C0667a c0667a = new C0667a();
            c0667a.m3178n(context, resources, xmlPullParser, attributeSet, theme);
            return c0667a;
        }
        throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": invalid animated-selector tag " + name);
    }

    @Override // p016f.C0684g, p016f.C0675b
    /* renamed from: h */
    public void mo3116h(C0675b.AbstractC0679d abstractC0679d) {
        super.mo3116h(abstractC0679d);
        if (abstractC0679d instanceof C0670c) {
            this.f2214r = (C0670c) abstractC0679d;
        }
    }

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

    @Override // p016f.C0675b, android.graphics.drawable.Drawable
    public void jumpToCurrentState() {
        super.jumpToCurrentState();
        AbstractC0674g abstractC0674g = this.f2215s;
        if (abstractC0674g != null) {
            abstractC0674g.mo3158d();
            this.f2215s = null;
            m3152g(this.f2216t);
            this.f2216t = -1;
            this.f2217u = -1;
        }
    }

    @Override // p016f.C0684g
    /* renamed from: l */
    public C0670c mo3115j() {
        return new C0670c(this.f2214r, this, null);
    }

    @Override // p016f.C0684g, p016f.C0675b, android.graphics.drawable.Drawable
    public Drawable mutate() {
        if (!this.f2218v && super.mutate() == this) {
            this.f2214r.mo3111r();
            this.f2218v = true;
        }
        return this;
    }

    /* renamed from: n */
    public void m3178n(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
        TypedArray m248k = C1838q.m248k(resources, theme, attributeSet, C0730i.f2306a);
        setVisible(m248k.getBoolean(C0730i.f2308c, true), true);
        m3172t(m248k);
        m3151i(resources);
        m248k.recycle();
        m3177o(context, resources, xmlPullParser, attributeSet, theme);
        m3176p();
    }

    /* renamed from: o */
    public final void m3177o(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
        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")) {
                    m3175q(context, resources, xmlPullParser, attributeSet, theme);
                } else if (xmlPullParser.getName().equals("transition")) {
                    m3174r(context, resources, xmlPullParser, attributeSet, theme);
                }
            }
        }
    }

    @Override // p016f.C0684g, p016f.C0675b, android.graphics.drawable.Drawable
    public boolean onStateChange(int[] iArr) {
        int m3167F = this.f2214r.m3167F(iArr);
        boolean z = m3167F != m3156c() && (m3173s(m3167F) || m3152g(m3167F));
        Drawable current = getCurrent();
        return current != null ? z | current.setState(iArr) : z;
    }

    /* renamed from: p */
    public final void m3176p() {
        onStateChange(getState());
    }

    /* renamed from: q */
    public final int m3175q(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
        int next;
        TypedArray m248k = C1838q.m248k(resources, theme, attributeSet, C0730i.f2313h);
        int resourceId = m248k.getResourceId(C0730i.f2314i, 0);
        int resourceId2 = m248k.getResourceId(C0730i.f2315j, -1);
        Drawable m1825j = resourceId2 > 0 ? C1230w2.m1827h().m1825j(context, resourceId2) : null;
        m248k.recycle();
        int[] m3114k = m3114k(attributeSet);
        if (m1825j == 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");
            }
            m1825j = xmlPullParser.getName().equals("vector") ? C1855l.m198c(resources, xmlPullParser, attributeSet, theme) : Build.VERSION.SDK_INT >= 21 ? C0728g.m3048a(resources, xmlPullParser, attributeSet, theme) : Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet);
        }
        if (m1825j != null) {
            return this.f2214r.m3171B(m3114k, m1825j, resourceId);
        }
        throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or child tag defining a drawable");
    }

    /* renamed from: r */
    public final int m3174r(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) {
        int next;
        TypedArray m248k = C1838q.m248k(resources, theme, attributeSet, C0730i.f2316k);
        int resourceId = m248k.getResourceId(C0730i.f2319n, -1);
        int resourceId2 = m248k.getResourceId(C0730i.f2318m, -1);
        int resourceId3 = m248k.getResourceId(C0730i.f2317l, -1);
        Drawable m1825j = resourceId3 > 0 ? C1230w2.m1827h().m1825j(context, resourceId3) : null;
        boolean z = m248k.getBoolean(C0730i.f2320o, false);
        m248k.recycle();
        if (m1825j == 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");
            }
            m1825j = xmlPullParser.getName().equals("animated-vector") ? C1844e.m232a(context, resources, xmlPullParser, attributeSet, theme) : Build.VERSION.SDK_INT >= 21 ? C0728g.m3048a(resources, xmlPullParser, attributeSet, theme) : Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet);
        }
        if (m1825j == null) {
            throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <transition> tag requires a 'drawable' attribute or child tag defining a drawable");
        } else if (resourceId == -1 || resourceId2 == -1) {
            throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <transition> tag requires 'fromId' & 'toId' attributes");
        } else {
            return this.f2214r.m3170C(resourceId, resourceId2, m1825j, z);
        }
    }

    /* renamed from: s */
    public final boolean m3173s(int i) {
        int m3156c;
        int m3166G;
        AbstractC0674g c0669b;
        AbstractC0674g abstractC0674g = this.f2215s;
        if (abstractC0674g == null) {
            m3156c = m3156c();
        } else if (i == this.f2216t) {
            return true;
        } else {
            if (i == this.f2217u && abstractC0674g.mo3161a()) {
                abstractC0674g.mo3160b();
                this.f2216t = this.f2217u;
                this.f2217u = i;
                return true;
            }
            m3156c = this.f2216t;
            abstractC0674g.mo3158d();
        }
        this.f2215s = null;
        this.f2217u = -1;
        this.f2216t = -1;
        C0670c c0670c = this.f2214r;
        int m3168E = c0670c.m3168E(m3156c);
        int m3168E2 = c0670c.m3168E(i);
        if (m3168E2 == 0 || m3168E == 0 || (m3166G = c0670c.m3166G(m3168E, m3168E2)) < 0) {
            return false;
        }
        boolean m3164I = c0670c.m3164I(m3168E, m3168E2);
        m3152g(m3166G);
        Drawable current = getCurrent();
        if (current instanceof AnimationDrawable) {
            c0669b = new C0672e((AnimationDrawable) current, c0670c.m3165H(m3168E, m3168E2), m3164I);
        } else if (!(current instanceof C1844e)) {
            if (current instanceof Animatable) {
                c0669b = new C0669b((Animatable) current);
            }
            return false;
        } else {
            c0669b = new C0671d((C1844e) current);
        }
        c0669b.mo3159c();
        this.f2215s = c0669b;
        this.f2217u = m3156c;
        this.f2216t = i;
        return true;
    }

    @Override // p016f.C0675b, android.graphics.drawable.Drawable
    public boolean setVisible(boolean z, boolean z2) {
        boolean visible = super.setVisible(z, z2);
        AbstractC0674g abstractC0674g = this.f2215s;
        if (abstractC0674g != null && (visible || z2)) {
            if (z) {
                abstractC0674g.mo3159c();
            } else {
                jumpToCurrentState();
            }
        }
        return visible;
    }

    /* renamed from: t */
    public final void m3172t(TypedArray typedArray) {
        C0670c c0670c = this.f2214r;
        if (Build.VERSION.SDK_INT >= 21) {
            c0670c.f2254d |= C0728g.m3047b(typedArray);
        }
        c0670c.m3124x(typedArray.getBoolean(C0730i.f2309d, c0670c.f2259i));
        c0670c.m3128t(typedArray.getBoolean(C0730i.f2310e, c0670c.f2262l));
        c0670c.m3127u(typedArray.getInt(C0730i.f2311f, c0670c.f2242A));
        c0670c.m3126v(typedArray.getInt(C0730i.f2312g, c0670c.f2243B));
        setDither(typedArray.getBoolean(C0730i.f2307b, c0670c.f2274x));
    }
}