package e;

import android.annotation.SuppressLint;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.StateSet;
import e.b;

/* JADX INFO: compiled from: StateListDrawable.java */
/* JADX INFO: loaded from: classes.dex */
@SuppressLint({"RestrictedAPI"})
class d extends b {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private a f4597q;

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

    /* JADX INFO: compiled from: StateListDrawable.java */
    static class a extends b.d {
        int[][] J;

        a(a aVar, d dVar, Resources resources) {
            super(aVar, dVar, resources);
            if (aVar != null) {
                this.J = aVar.J;
            } else {
                this.J = new int[g()][];
            }
        }

        int A(int[] iArr, Drawable drawable) {
            int iA = a(drawable);
            this.J[iA] = iArr;
            return iA;
        }

        int B(int[] iArr) {
            int[][] iArr2 = this.J;
            int i3 = i();
            for (int i4 = 0; i4 < i3; i4++) {
                if (StateSet.stateSetMatches(iArr2[i4], iArr)) {
                    return i4;
                }
            }
            return -1;
        }

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

        @Override // e.b.d
        public void p(int i3, int i4) {
            super.p(i3, i4);
            int[][] iArr = new int[i4][];
            System.arraycopy(this.J, 0, iArr, 0, i3);
            this.J = iArr;
        }

        @Override // e.b.d
        void s() {
            int[][] iArr = this.J;
            int[][] iArr2 = new int[iArr.length][];
            for (int length = iArr.length - 1; length >= 0; length--) {
                int[][] iArr3 = this.J;
                iArr2[length] = iArr3[length] != null ? (int[]) iArr3[length].clone() : null;
            }
            this.J = iArr2;
        }

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

    d(a aVar, Resources resources) {
        g(new a(aVar, this, resources));
        onStateChange(getState());
    }

    @Override // e.b, android.graphics.drawable.Drawable
    public void applyTheme(Resources.Theme theme) {
        super.applyTheme(theme);
        onStateChange(getState());
    }

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

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

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

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

    int[] j(AttributeSet attributeSet) {
        int attributeCount = attributeSet.getAttributeCount();
        int[] iArr = new int[attributeCount];
        int i3 = 0;
        for (int i4 = 0; i4 < attributeCount; i4++) {
            int attributeNameResource = attributeSet.getAttributeNameResource(i4);
            if (attributeNameResource != 0 && attributeNameResource != 16842960 && attributeNameResource != 16843161) {
                int i5 = i3 + 1;
                if (!attributeSet.getAttributeBooleanValue(i4, false)) {
                    attributeNameResource = -attributeNameResource;
                }
                iArr[i3] = attributeNameResource;
                i3 = i5;
            }
        }
        return StateSet.trimStateSet(iArr, i3);
    }

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

    @Override // e.b, android.graphics.drawable.Drawable
    protected boolean onStateChange(int[] iArr) {
        boolean zOnStateChange = super.onStateChange(iArr);
        int iB = this.f4597q.B(iArr);
        if (iB < 0) {
            iB = this.f4597q.B(StateSet.WILD_CARD);
        }
        return f(iB) || zOnStateChange;
    }

    d(a aVar) {
        if (aVar != null) {
            g(aVar);
        }
    }
}
