package i0;

import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.util.AttributeSet;
import android.util.StateSet;
import android.util.TypedValue;
import android.util.Xml;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.XmlRes;
import java.io.IOException;
import java.lang.reflect.Array;
import kotlinx.coroutines.y;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: loaded from: classes.dex */
public abstract class c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final ThreadLocal f26486a = new ThreadLocal();

    @NonNull
    public static ColorStateList createFromXml(@NonNull Resources resources, @NonNull XmlPullParser xmlPullParser, @Nullable Resources.Theme theme) throws XmlPullParserException, IOException {
        int next;
        AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(xmlPullParser);
        do {
            next = xmlPullParser.next();
            if (next == 2) {
                break;
            }
        } while (next != 1);
        if (next == 2) {
            return createFromXmlInner(resources, xmlPullParser, attributeSetAsAttributeSet, theme);
        }
        throw new XmlPullParserException("No start tag found");
    }

    @NonNull
    public static ColorStateList createFromXmlInner(@NonNull Resources resources, @NonNull XmlPullParser xmlPullParser, @NonNull AttributeSet attributeSet, @Nullable Resources.Theme theme) throws XmlPullParserException, IOException {
        String name = xmlPullParser.getName();
        if (name.equals("selector")) {
            return inflate(resources, xmlPullParser, attributeSet, theme);
        }
        throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": invalid color state list tag " + name);
    }

    @Nullable
    public static ColorStateList inflate(@NonNull Resources resources, @XmlRes int i10, @Nullable Resources.Theme theme) {
        try {
            return createFromXml(resources, resources.getXml(i10), theme);
        } catch (Exception unused) {
            return null;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:31:0x0083  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00b7  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private static ColorStateList inflate(@NonNull Resources resources, @NonNull XmlPullParser xmlPullParser, @NonNull AttributeSet attributeSet, @Nullable Resources.Theme theme) throws XmlPullParserException, IOException {
        int depth;
        TypedArray typedArrayObtainStyledAttributes;
        int color;
        float f10;
        float f11;
        Resources resources2 = resources;
        boolean z10 = true;
        int depth2 = xmlPullParser.getDepth() + 1;
        Object[] objArr = new int[20][];
        int[] iArr = new int[20];
        int i10 = 0;
        int i11 = 0;
        while (true) {
            int next = xmlPullParser.next();
            if (next == z10 || ((depth = xmlPullParser.getDepth()) < depth2 && next == 3)) {
                break;
            }
            if (next == 2 && depth <= depth2 && xmlPullParser.getName().equals("item")) {
                int[] iArr2 = e0.h.ColorStateListItem;
                if (theme == null) {
                    typedArrayObtainStyledAttributes = resources2.obtainAttributes(attributeSet, iArr2);
                } else {
                    typedArrayObtainStyledAttributes = theme.obtainStyledAttributes(attributeSet, iArr2, i10, i10);
                }
                int i12 = e0.h.ColorStateListItem_android_color;
                int resourceId = typedArrayObtainStyledAttributes.getResourceId(i12, -1);
                if (resourceId != -1) {
                    ThreadLocal threadLocal = f26486a;
                    TypedValue typedValue = (TypedValue) threadLocal.get();
                    if (typedValue == null) {
                        typedValue = new TypedValue();
                        threadLocal.set(typedValue);
                    }
                    resources2.getValue(resourceId, typedValue, z10);
                    int i13 = typedValue.type;
                    if (i13 < 28 || i13 > 31) {
                        try {
                            color = createFromXml(resources2, resources2.getXml(resourceId), theme).getDefaultColor();
                        } catch (Exception unused) {
                            color = typedArrayObtainStyledAttributes.getColor(e0.h.ColorStateListItem_android_color, -65281);
                        }
                    } else {
                        color = typedArrayObtainStyledAttributes.getColor(i12, -65281);
                    }
                    int i14 = e0.h.ColorStateListItem_android_alpha;
                    if (typedArrayObtainStyledAttributes.hasValue(i14)) {
                        f10 = typedArrayObtainStyledAttributes.getFloat(i14, 1.0f);
                    } else {
                        int i15 = e0.h.ColorStateListItem_alpha;
                        f10 = typedArrayObtainStyledAttributes.hasValue(i15) ? typedArrayObtainStyledAttributes.getFloat(i15, 1.0f) : 1.0f;
                    }
                    if (Build.VERSION.SDK_INT >= 31) {
                        int i16 = e0.h.ColorStateListItem_android_lStar;
                        if (typedArrayObtainStyledAttributes.hasValue(i16)) {
                            f11 = typedArrayObtainStyledAttributes.getFloat(i16, -1.0f);
                        } else {
                            f11 = typedArrayObtainStyledAttributes.getFloat(e0.h.ColorStateListItem_lStar, -1.0f);
                        }
                        typedArrayObtainStyledAttributes.recycle();
                        int attributeCount = attributeSet.getAttributeCount();
                        int[] iArr3 = new int[attributeCount];
                        int i17 = i10;
                        for (int i18 = i17; i18 < attributeCount; i18++) {
                            int attributeNameResource = attributeSet.getAttributeNameResource(i18);
                            if (attributeNameResource != 16843173 && attributeNameResource != 16843551 && attributeNameResource != e0.a.alpha && attributeNameResource != e0.a.lStar) {
                                int i19 = i17 + 1;
                                if (!attributeSet.getAttributeBooleanValue(i18, false)) {
                                    attributeNameResource = -attributeNameResource;
                                }
                                iArr3[i17] = attributeNameResource;
                                i17 = i19;
                            }
                        }
                        int[] iArrTrimStateSet = StateSet.trimStateSet(iArr3, i17);
                        boolean z11 = f11 >= 0.0f && f11 <= 100.0f;
                        if (f10 != 1.0f || z11) {
                            int iH = y.h((int) ((Color.alpha(color) * f10) + 0.5f), 0, 255);
                            if (z11) {
                                a aVarA = a.a(color);
                                color = a.c(aVarA.f26476a, aVarA.f26477b, f11);
                            }
                            color = (16777215 & color) | (iH << 24);
                        }
                        int i20 = i11 + 1;
                        if (i20 > iArr.length) {
                            int[] iArr4 = new int[i11 <= 4 ? 8 : i11 * 2];
                            System.arraycopy(iArr, 0, iArr4, 0, i11);
                            iArr = iArr4;
                        }
                        iArr[i11] = color;
                        if (i20 > objArr.length) {
                            Object[] objArr2 = (Object[]) Array.newInstance(objArr.getClass().getComponentType(), i11 > 4 ? i11 * 2 : 8);
                            System.arraycopy(objArr, 0, objArr2, 0, i11);
                            objArr = objArr2;
                        }
                        objArr[i11] = iArrTrimStateSet;
                        objArr = (int[][]) objArr;
                        resources2 = resources;
                        i11 = i20;
                    }
                }
            } else {
                resources2 = resources;
            }
            z10 = true;
            i10 = 0;
        }
        int[] iArr5 = new int[i11];
        int[][] iArr6 = new int[i11][];
        System.arraycopy(iArr, 0, iArr5, 0, i11);
        System.arraycopy(objArr, 0, iArr6, 0, i11);
        return new ColorStateList(iArr6, iArr5);
    }
}
