package com.google.android.material.shape;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
import android.util.StateSet;
import android.util.Xml;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleableRes;
import java.io.IOException;
import java.util.Objects;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: loaded from: classes2.dex */
public final class n0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final int f23127a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final s f23128b;

    @Nullable
    final l0 bottomLeftCornerSizeOverride;

    @Nullable
    final l0 bottomRightCornerSizeOverride;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final int[][] f23129c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final s[] f23130d;

    @Nullable
    final l0 topLeftCornerSizeOverride;

    @Nullable
    final l0 topRightCornerSizeOverride;

    public n0(m0 m0Var) {
        this.f23127a = m0Var.f23121a;
        this.f23128b = m0Var.f23122b;
        this.f23129c = m0Var.f23123c;
        this.f23130d = m0Var.f23124d;
        this.topLeftCornerSizeOverride = m0Var.topLeftCornerSizeOverride;
        this.topRightCornerSizeOverride = m0Var.topRightCornerSizeOverride;
        this.bottomLeftCornerSizeOverride = m0Var.bottomLeftCornerSizeOverride;
        this.bottomRightCornerSizeOverride = m0Var.bottomRightCornerSizeOverride;
    }

    @Nullable
    public static n0 create(@NonNull Context context, @NonNull TypedArray typedArray, @StyleableRes int i10) {
        XmlResourceParser xml;
        int next;
        int resourceId = typedArray.getResourceId(i10, 0);
        if (resourceId == 0 || !Objects.equals(context.getResources().getResourceTypeName(resourceId), "xml")) {
            return null;
        }
        m0 m0Var = new m0();
        m0Var.f();
        try {
            xml = context.getResources().getXml(resourceId);
        } catch (Resources.NotFoundException | IOException | XmlPullParserException unused) {
            m0Var.f();
        }
        try {
            AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(xml);
            do {
                next = xml.next();
                if (next == 2) {
                    break;
                }
            } while (next != 1);
            if (next != 2) {
                throw new XmlPullParserException("No start tag found");
            }
            if (xml.getName().equals("selector")) {
                loadShapeAppearanceModelsFromItems(m0Var, context, xml, attributeSetAsAttributeSet, context.getTheme());
            }
            xml.close();
            return m0Var.build();
        } catch (Throwable th) {
            if (xml != null) {
                try {
                    xml.close();
                } catch (Throwable th2) {
                    th.addSuppressed(th2);
                }
            }
            throw th;
        }
    }

    private static void loadShapeAppearanceModelsFromItems(@NonNull m0 m0Var, @NonNull Context context, @NonNull XmlPullParser xmlPullParser, @NonNull AttributeSet attributeSet, @Nullable 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 && xmlPullParser.getName().equals("item")) {
                TypedArray typedArrayObtainAttributes = theme == null ? context.getResources().obtainAttributes(attributeSet, x8.m.MaterialShape) : theme.obtainStyledAttributes(attributeSet, x8.m.MaterialShape, 0, 0);
                s sVarA = s.a(context, typedArrayObtainAttributes.getResourceId(x8.m.MaterialShape_shapeAppearance, 0), typedArrayObtainAttributes.getResourceId(x8.m.MaterialShape_shapeAppearanceOverlay, 0)).a();
                typedArrayObtainAttributes.recycle();
                int attributeCount = attributeSet.getAttributeCount();
                int[] iArr = new int[attributeCount];
                int i10 = 0;
                for (int i11 = 0; i11 < attributeCount; i11++) {
                    int attributeNameResource = attributeSet.getAttributeNameResource(i11);
                    if (attributeNameResource != x8.c.shapeAppearance && attributeNameResource != x8.c.shapeAppearanceOverlay) {
                        int i12 = i10 + 1;
                        if (!attributeSet.getAttributeBooleanValue(i11, false)) {
                            attributeNameResource = -attributeNameResource;
                        }
                        iArr[i10] = attributeNameResource;
                        i10 = i12;
                    }
                }
                m0Var.e(StateSet.trimStateSet(iArr, i10), sVarA);
            }
        }
    }

    public final s a() {
        l0 l0Var = this.topLeftCornerSizeOverride;
        s sVar = this.f23128b;
        if (l0Var == null && this.topRightCornerSizeOverride == null && this.bottomLeftCornerSizeOverride == null && this.bottomRightCornerSizeOverride == null) {
            return sVar;
        }
        q qVarH = sVar.h();
        l0 l0Var2 = this.topLeftCornerSizeOverride;
        if (l0Var2 != null) {
            qVarH.f23138e = l0Var2.f23111b;
        }
        l0 l0Var3 = this.topRightCornerSizeOverride;
        if (l0Var3 != null) {
            qVarH.f23139f = l0Var3.f23111b;
        }
        l0 l0Var4 = this.bottomLeftCornerSizeOverride;
        if (l0Var4 != null) {
            qVarH.f23141h = l0Var4.f23111b;
        }
        l0 l0Var5 = this.bottomRightCornerSizeOverride;
        if (l0Var5 != null) {
            qVarH.f23140g = l0Var5.f23111b;
        }
        return qVarH.a();
    }

    public final boolean b() {
        if (this.f23127a > 1) {
            return true;
        }
        l0 l0Var = this.topLeftCornerSizeOverride;
        if (l0Var != null && l0Var.f23110a > 1) {
            return true;
        }
        l0 l0Var2 = this.topRightCornerSizeOverride;
        if (l0Var2 != null && l0Var2.f23110a > 1) {
            return true;
        }
        l0 l0Var3 = this.bottomLeftCornerSizeOverride;
        if (l0Var3 != null && l0Var3.f23110a > 1) {
            return true;
        }
        l0 l0Var4 = this.bottomRightCornerSizeOverride;
        return l0Var4 != null && l0Var4.f23110a > 1;
    }
}
