package z8;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Xml;
import androidx.annotation.AttrRes;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.annotation.XmlRes;
import com.google.android.material.internal.q0;
import java.io.IOException;
import java.util.Locale;
import org.xmlpull.v1.XmlPullParserException;
import q9.g;
import x8.j;
import x8.k;
import x8.l;
import x8.m;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final b f37102b = new b();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final float f37103c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final float f37104d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final float f37105e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final float f37106f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final float f37107g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final float f37108h;

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

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f37112l;

    public c(Context context, @XmlRes int i10, @AttrRes int i11, @StyleRes int i12, @Nullable b bVar) {
        AttributeSet attributeSet;
        int styleAttribute;
        int next;
        bVar = bVar == null ? new b() : bVar;
        if (i10 != 0) {
            bVar.f37083a = i10;
        }
        int i13 = bVar.f37083a;
        boolean z10 = true;
        if (i13 != 0) {
            try {
                XmlResourceParser xml = context.getResources().getXml(i13);
                do {
                    next = xml.next();
                    if (next == 2) {
                        break;
                    }
                } while (next != 1);
                if (next != 2) {
                    throw new XmlPullParserException("No start tag found");
                }
                if (!TextUtils.equals(xml.getName(), "badge")) {
                    throw new XmlPullParserException("Must have a <" + ((Object) "badge") + "> start tag");
                }
                AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(xml);
                styleAttribute = attributeSetAsAttributeSet.getStyleAttribute();
                attributeSet = attributeSetAsAttributeSet;
            } catch (IOException | XmlPullParserException e10) {
                Resources.NotFoundException notFoundException = new Resources.NotFoundException("Can't load badge resource ID #0x" + Integer.toHexString(i13));
                notFoundException.initCause(e10);
                throw notFoundException;
            }
        } else {
            attributeSet = null;
            styleAttribute = 0;
        }
        TypedArray typedArrayC = q0.c(context, attributeSet, m.Badge, i11, styleAttribute == 0 ? i12 : styleAttribute, new int[0]);
        Resources resources = context.getResources();
        this.f37103c = typedArrayC.getDimensionPixelSize(m.Badge_badgeRadius, -1);
        this.f37109i = context.getResources().getDimensionPixelSize(x8.e.mtrl_badge_horizontal_edge_offset);
        this.f37110j = context.getResources().getDimensionPixelSize(x8.e.mtrl_badge_text_horizontal_edge_offset);
        this.f37104d = typedArrayC.getDimensionPixelSize(m.Badge_badgeWithTextRadius, -1);
        int i14 = m.Badge_badgeWidth;
        int i15 = x8.e.m3_badge_size;
        this.f37105e = typedArrayC.getDimension(i14, resources.getDimension(i15));
        int i16 = m.Badge_badgeWithTextWidth;
        int i17 = x8.e.m3_badge_with_text_size;
        this.f37107g = typedArrayC.getDimension(i16, resources.getDimension(i17));
        this.f37106f = typedArrayC.getDimension(m.Badge_badgeHeight, resources.getDimension(i15));
        this.f37108h = typedArrayC.getDimension(m.Badge_badgeWithTextHeight, resources.getDimension(i17));
        this.f37111k = typedArrayC.getInt(m.Badge_offsetAlignmentMode, 1);
        this.f37112l = typedArrayC.getInt(m.Badge_badgeFixedEdge, 0);
        b bVar2 = this.f37102b;
        int i18 = bVar.f37096i;
        bVar2.f37096i = i18 == -2 ? 255 : i18;
        int i19 = bVar.f37097j;
        if (i19 != -2) {
            bVar2.f37097j = i19;
        } else {
            int i20 = m.Badge_number;
            if (typedArrayC.hasValue(i20)) {
                this.f37102b.f37097j = typedArrayC.getInt(i20, 0);
            } else {
                this.f37102b.f37097j = -1;
            }
        }
        if (bVar.text != null) {
            this.f37102b.text = bVar.text;
        } else {
            int i21 = m.Badge_badgeText;
            if (typedArrayC.hasValue(i21)) {
                this.f37102b.text = typedArrayC.getString(i21);
            }
        }
        this.f37102b.contentDescriptionForText = bVar.contentDescriptionForText;
        this.f37102b.contentDescriptionNumberless = bVar.contentDescriptionNumberless == null ? context.getString(k.mtrl_badge_numberless_content_description) : bVar.contentDescriptionNumberless;
        b bVar3 = this.f37102b;
        int i22 = bVar.Q;
        bVar3.Q = i22 == 0 ? j.mtrl_badge_content_description : i22;
        int i23 = bVar.R;
        bVar3.R = i23 == 0 ? k.mtrl_exceed_max_badge_number_content_description : i23;
        Boolean bool = bVar.T;
        if (bool != null && !bool.booleanValue()) {
            z10 = false;
        }
        bVar3.T = Boolean.valueOf(z10);
        b bVar4 = this.f37102b;
        int i24 = bVar.f37098k;
        bVar4.f37098k = i24 == -2 ? typedArrayC.getInt(m.Badge_maxCharacterCount, -2) : i24;
        b bVar5 = this.f37102b;
        int i25 = bVar.f37099l;
        bVar5.f37099l = i25 == -2 ? typedArrayC.getInt(m.Badge_maxNumber, -2) : i25;
        b bVar6 = this.f37102b;
        Integer num = bVar.f37091e;
        bVar6.f37091e = Integer.valueOf(num == null ? typedArrayC.getResourceId(m.Badge_badgeShapeAppearance, l.ShapeAppearance_M3_Sys_Shape_Corner_Full) : num.intValue());
        b bVar7 = this.f37102b;
        Integer num2 = bVar.f37093f;
        bVar7.f37093f = Integer.valueOf(num2 == null ? typedArrayC.getResourceId(m.Badge_badgeShapeAppearanceOverlay, 0) : num2.intValue());
        b bVar8 = this.f37102b;
        Integer num3 = bVar.f37094g;
        bVar8.f37094g = Integer.valueOf(num3 == null ? typedArrayC.getResourceId(m.Badge_badgeWithTextShapeAppearance, l.ShapeAppearance_M3_Sys_Shape_Corner_Full) : num3.intValue());
        b bVar9 = this.f37102b;
        Integer num4 = bVar.f37095h;
        bVar9.f37095h = Integer.valueOf(num4 == null ? typedArrayC.getResourceId(m.Badge_badgeWithTextShapeAppearanceOverlay, 0) : num4.intValue());
        b bVar10 = this.f37102b;
        Integer num5 = bVar.f37085b;
        bVar10.f37085b = Integer.valueOf(num5 == null ? q9.d.getColorStateList(context, typedArrayC, m.Badge_backgroundColor).getDefaultColor() : num5.intValue());
        b bVar11 = this.f37102b;
        Integer num6 = bVar.f37089d;
        bVar11.f37089d = Integer.valueOf(num6 == null ? typedArrayC.getResourceId(m.Badge_badgeTextAppearance, l.TextAppearance_MaterialComponents_Badge) : num6.intValue());
        Integer num7 = bVar.f37087c;
        if (num7 != null) {
            this.f37102b.f37087c = num7;
        } else {
            int i26 = m.Badge_badgeTextColor;
            if (typedArrayC.hasValue(i26)) {
                this.f37102b.f37087c = Integer.valueOf(q9.d.getColorStateList(context, typedArrayC, i26).getDefaultColor());
            } else {
                this.f37102b.f37087c = Integer.valueOf(new g(context, this.f37102b.f37089d.intValue()).getTextColor().getDefaultColor());
            }
        }
        b bVar12 = this.f37102b;
        Integer num8 = bVar.S;
        bVar12.S = Integer.valueOf(num8 == null ? typedArrayC.getInt(m.Badge_badgeGravity, 8388661) : num8.intValue());
        b bVar13 = this.f37102b;
        Integer num9 = bVar.U;
        bVar13.U = Integer.valueOf(num9 == null ? typedArrayC.getDimensionPixelSize(m.Badge_badgeWidePadding, resources.getDimensionPixelSize(x8.e.mtrl_badge_long_text_horizontal_padding)) : num9.intValue());
        b bVar14 = this.f37102b;
        Integer num10 = bVar.V;
        bVar14.V = Integer.valueOf(num10 == null ? typedArrayC.getDimensionPixelSize(m.Badge_badgeVerticalPadding, resources.getDimensionPixelSize(x8.e.m3_badge_with_text_vertical_padding)) : num10.intValue());
        b bVar15 = this.f37102b;
        Integer num11 = bVar.W;
        bVar15.W = Integer.valueOf(num11 == null ? typedArrayC.getDimensionPixelOffset(m.Badge_horizontalOffset, 0) : num11.intValue());
        b bVar16 = this.f37102b;
        Integer num12 = bVar.X;
        bVar16.X = Integer.valueOf(num12 == null ? typedArrayC.getDimensionPixelOffset(m.Badge_verticalOffset, 0) : num12.intValue());
        b bVar17 = this.f37102b;
        Integer num13 = bVar.Y;
        bVar17.Y = Integer.valueOf(num13 == null ? typedArrayC.getDimensionPixelOffset(m.Badge_horizontalOffsetWithText, bVar17.W.intValue()) : num13.intValue());
        b bVar18 = this.f37102b;
        Integer num14 = bVar.Z;
        bVar18.Z = Integer.valueOf(num14 == null ? typedArrayC.getDimensionPixelOffset(m.Badge_verticalOffsetWithText, bVar18.X.intValue()) : num14.intValue());
        b bVar19 = this.f37102b;
        Integer num15 = bVar.f37088c0;
        bVar19.f37088c0 = Integer.valueOf(num15 == null ? typedArrayC.getDimensionPixelOffset(m.Badge_largeFontVerticalOffsetAdjustment, 0) : num15.intValue());
        b bVar20 = this.f37102b;
        Integer num16 = bVar.f37084a0;
        bVar20.f37084a0 = Integer.valueOf(num16 == null ? 0 : num16.intValue());
        b bVar21 = this.f37102b;
        Integer num17 = bVar.f37086b0;
        bVar21.f37086b0 = Integer.valueOf(num17 == null ? 0 : num17.intValue());
        b bVar22 = this.f37102b;
        Boolean bool2 = bVar.f37090d0;
        bVar22.f37090d0 = Boolean.valueOf(bool2 == null ? typedArrayC.getBoolean(m.Badge_autoAdjustToWithinGrandparentBounds, false) : bool2.booleanValue());
        typedArrayC.recycle();
        Locale locale = bVar.f37100m;
        if (locale == null) {
            this.f37102b.f37100m = Locale.getDefault(Locale.Category.FORMAT);
        } else {
            this.f37102b.f37100m = locale;
        }
        this.f37101a = bVar;
    }

    public final boolean a() {
        return this.f37102b.text != null;
    }
}
