package p016f;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.StateSet;
import p016f.C0675b;

/* renamed from: f.g */
/* loaded from: classes.dex */
public class C0684g extends C0675b {

    /* renamed from: p */
    public C0685a f2278p;

    /* renamed from: q */
    public boolean f2279q;

    /* renamed from: f.g$a */
    /* loaded from: classes.dex */
    public static class C0685a extends C0675b.AbstractC0679d {

        /* renamed from: J */
        public int[][] f2280J;

        public C0685a(C0685a c0685a, C0684g c0684g, Resources resources) {
            super(c0685a, c0684g, resources);
            if (c0685a != null) {
                this.f2280J = c0685a.f2280J;
            } else {
                this.f2280J = new int[m3140f()];
            }
        }

        /* renamed from: A */
        public int m3113A(int[] iArr) {
            int[][] iArr2 = this.f2280J;
            int m3138h = m3138h();
            for (int i = 0; i < m3138h; i++) {
                if (StateSet.stateSetMatches(iArr2[i], iArr)) {
                    return i;
                }
            }
            return -1;
        }

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

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

        @Override // p016f.C0675b.AbstractC0679d
        /* renamed from: o */
        public void mo3112o(int i, int i2) {
            super.mo3112o(i, i2);
            int[][] iArr = new int[i2];
            System.arraycopy(this.f2280J, 0, iArr, 0, i);
            this.f2280J = iArr;
        }

        @Override // p016f.C0675b.AbstractC0679d
        /* renamed from: r */
        public void mo3111r() {
            int[][] iArr = this.f2280J;
            int[][] iArr2 = new int[iArr.length];
            for (int length = iArr.length - 1; length >= 0; length--) {
                int[] iArr3 = this.f2280J[length];
                iArr2[length] = iArr3 != null ? (int[]) iArr3.clone() : null;
            }
            this.f2280J = iArr2;
        }

        /* renamed from: z */
        public int m3110z(int[] iArr, Drawable drawable) {
            int m3145a = m3145a(drawable);
            this.f2280J[m3145a] = iArr;
            return m3145a;
        }
    }

    public C0684g(C0685a c0685a) {
        if (c0685a != null) {
            mo3116h(c0685a);
        }
    }

    public C0684g(C0685a c0685a, Resources resources) {
        mo3116h(new C0685a(c0685a, this, resources));
        onStateChange(getState());
    }

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

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

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

    @Override // p016f.C0675b
    /* renamed from: j */
    public C0685a mo3117b() {
        return new C0685a(this.f2278p, this, null);
    }

    /* renamed from: k */
    public int[] m3114k(AttributeSet attributeSet) {
        int attributeCount = attributeSet.getAttributeCount();
        int[] iArr = new int[attributeCount];
        int i = 0;
        for (int i2 = 0; i2 < attributeCount; i2++) {
            int attributeNameResource = attributeSet.getAttributeNameResource(i2);
            if (attributeNameResource != 0 && attributeNameResource != 16842960 && attributeNameResource != 16843161) {
                int i3 = i + 1;
                if (!attributeSet.getAttributeBooleanValue(i2, false)) {
                    attributeNameResource = -attributeNameResource;
                }
                iArr[i] = attributeNameResource;
                i = i3;
            }
        }
        return StateSet.trimStateSet(iArr, i);
    }

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

    @Override // p016f.C0675b, android.graphics.drawable.Drawable
    public boolean onStateChange(int[] iArr) {
        boolean onStateChange = super.onStateChange(iArr);
        int m3113A = this.f2278p.m3113A(iArr);
        if (m3113A < 0) {
            m3113A = this.f2278p.m3113A(StateSet.WILD_CARD);
        }
        return m3152g(m3113A) || onStateChange;
    }
}