package l;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
import android.view.InflateException;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.SubMenu;
import java.io.IOException;
import m.MenuC1147h;
import n.S;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: loaded from: classes.dex */
public final class e extends MenuInflater {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final Class[] f14246e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final Class[] f14247f;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object[] f14248a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object[] f14249b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Object f14251d;

    static {
        Class[] clsArr = {Context.class};
        f14246e = clsArr;
        f14247f = clsArr;
    }

    public e(Context context) {
        super(context);
        this.f14250c = context;
        Object[] objArr = {context};
        this.f14248a = objArr;
        this.f14249b = objArr;
    }

    public static Object a(Object obj) {
        return (!(obj instanceof Activity) && (obj instanceof ContextWrapper)) ? a(((ContextWrapper) obj).getBaseContext()) : obj;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r16v0, types: [l.e] */
    /* JADX WARN: Type inference failed for: r3v15, types: [android.content.res.TypedArray] */
    /* JADX WARN: Type inference failed for: r4v0 */
    /* JADX WARN: Type inference failed for: r4v1, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r4v58 */
    /* JADX WARN: Type inference failed for: r8v1 */
    /* JADX WARN: Type inference failed for: r8v10 */
    /* JADX WARN: Type inference failed for: r8v11 */
    /* JADX WARN: Type inference failed for: r8v13 */
    /* JADX WARN: Type inference failed for: r8v2 */
    /* JADX WARN: Type inference failed for: r8v5 */
    /* JADX WARN: Type inference failed for: r8v7 */
    /* JADX WARN: Type inference failed for: r8v8 */
    /* JADX WARN: Type inference failed for: r8v9 */
    public final void b(XmlResourceParser xmlResourceParser, AttributeSet attributeSet, Menu menu) throws XmlPullParserException, IOException {
        ?? r42;
        int i;
        XmlResourceParser xmlResourceParser2;
        ?? r8;
        ColorStateList colorStateList;
        int resourceId;
        d dVar = new d(this, menu);
        int eventType = xmlResourceParser.getEventType();
        while (true) {
            r42 = 1;
            i = 2;
            if (eventType == 2) {
                String name = xmlResourceParser.getName();
                if (!name.equals("menu")) {
                    throw new RuntimeException("Expecting menu, got ".concat(name));
                }
                eventType = xmlResourceParser.next();
            } else {
                eventType = xmlResourceParser.next();
                if (eventType == 1) {
                    break;
                }
            }
        }
        boolean z8 = false;
        boolean z9 = false;
        String str = null;
        while (!z8) {
            if (eventType == r42) {
                throw new RuntimeException("Unexpected end of document");
            }
            if (eventType != i) {
                if (eventType != 3) {
                    xmlResourceParser2 = xmlResourceParser;
                    r8 = r42;
                    z8 = z8;
                } else {
                    String name2 = xmlResourceParser.getName();
                    if (z9 && name2.equals(str)) {
                        xmlResourceParser2 = xmlResourceParser;
                        r8 = r42;
                        z9 = false;
                        str = null;
                    } else {
                        if (name2.equals("group")) {
                            dVar.f14222b = 0;
                            dVar.f14223c = 0;
                            dVar.f14224d = 0;
                            dVar.f14225e = 0;
                            dVar.f14226f = r42;
                            dVar.f14227g = r42;
                        } else if (name2.equals("item")) {
                            if (!dVar.f14228h) {
                                dVar.f14228h = r42;
                                dVar.b(dVar.f14221a.add(dVar.f14222b, dVar.i, dVar.f14229j, dVar.f14230k));
                            }
                        } else if (name2.equals("menu")) {
                            xmlResourceParser2 = xmlResourceParser;
                            ?? r82 = r42;
                            z8 = r82 == true ? 1 : 0;
                            r8 = r82;
                        }
                        xmlResourceParser2 = xmlResourceParser;
                        r8 = r42;
                        z8 = z8;
                    }
                }
                eventType = xmlResourceParser2.next();
                r42 = r8;
                i = 2;
                z8 = z8;
                z9 = z9;
            } else {
                if (!z9) {
                    String name3 = xmlResourceParser.getName();
                    boolean zEquals = name3.equals("group");
                    e eVar = dVar.D;
                    if (zEquals) {
                        ?? ObtainStyledAttributes = eVar.f14250c.obtainStyledAttributes(attributeSet, h.a.f13016m);
                        dVar.f14222b = ObtainStyledAttributes.getResourceId(r42, 0);
                        dVar.f14223c = ObtainStyledAttributes.getInt(3, 0);
                        dVar.f14224d = ObtainStyledAttributes.getInt(4, 0);
                        dVar.f14225e = ObtainStyledAttributes.getInt(5, 0);
                        dVar.f14226f = ObtainStyledAttributes.getBoolean(2, r42);
                        dVar.f14227g = ObtainStyledAttributes.getBoolean(0, r42);
                        ObtainStyledAttributes.recycle();
                    } else {
                        if (name3.equals("item")) {
                            Context context = eVar.f14250c;
                            TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, h.a.f13017n);
                            dVar.i = typedArrayObtainStyledAttributes.getResourceId(2, 0);
                            dVar.f14229j = (typedArrayObtainStyledAttributes.getInt(5, dVar.f14223c) & (-65536)) | (typedArrayObtainStyledAttributes.getInt(6, dVar.f14224d) & 65535);
                            dVar.f14230k = typedArrayObtainStyledAttributes.getText(7);
                            dVar.f14231l = typedArrayObtainStyledAttributes.getText(8);
                            dVar.f14232m = typedArrayObtainStyledAttributes.getResourceId(0, 0);
                            String string = typedArrayObtainStyledAttributes.getString(9);
                            dVar.f14233n = string == null ? (char) 0 : string.charAt(0);
                            dVar.f14234o = typedArrayObtainStyledAttributes.getInt(16, 4096);
                            String string2 = typedArrayObtainStyledAttributes.getString(10);
                            dVar.f14235p = string2 == null ? (char) 0 : string2.charAt(0);
                            dVar.f14236q = typedArrayObtainStyledAttributes.getInt(20, 4096);
                            if (typedArrayObtainStyledAttributes.hasValue(11)) {
                                dVar.f14237r = typedArrayObtainStyledAttributes.getBoolean(11, false) ? 1 : 0;
                            } else {
                                dVar.f14237r = dVar.f14225e;
                            }
                            dVar.f14238s = typedArrayObtainStyledAttributes.getBoolean(3, false);
                            dVar.f14239t = typedArrayObtainStyledAttributes.getBoolean(4, dVar.f14226f);
                            dVar.f14240u = typedArrayObtainStyledAttributes.getBoolean(1, dVar.f14227g);
                            dVar.f14241v = typedArrayObtainStyledAttributes.getInt(21, -1);
                            dVar.f14244y = typedArrayObtainStyledAttributes.getString(12);
                            dVar.f14242w = typedArrayObtainStyledAttributes.getResourceId(13, 0);
                            dVar.f14243x = typedArrayObtainStyledAttributes.getString(15);
                            String string3 = typedArrayObtainStyledAttributes.getString(14);
                            boolean z10 = string3 != null;
                            if (z10 && dVar.f14242w == 0 && dVar.f14243x == null) {
                                if (dVar.a(string3, f14247f, eVar.f14249b) != null) {
                                    throw new ClassCastException();
                                }
                            } else if (z10) {
                                Log.w("SupportMenuInflater", "Ignoring attribute 'actionProviderClass'. Action view already specified.");
                            }
                            dVar.f14245z = typedArrayObtainStyledAttributes.getText(17);
                            dVar.f14218A = typedArrayObtainStyledAttributes.getText(22);
                            if (typedArrayObtainStyledAttributes.hasValue(19)) {
                                dVar.f14220C = S.b(typedArrayObtainStyledAttributes.getInt(19, -1), dVar.f14220C);
                            } else {
                                dVar.f14220C = null;
                            }
                            if (typedArrayObtainStyledAttributes.hasValue(18)) {
                                if (!typedArrayObtainStyledAttributes.hasValue(18) || (resourceId = typedArrayObtainStyledAttributes.getResourceId(18, 0)) == 0 || (colorStateList = s7.d.p(context, resourceId)) == null) {
                                    colorStateList = typedArrayObtainStyledAttributes.getColorStateList(18);
                                }
                                dVar.f14219B = colorStateList;
                            } else {
                                dVar.f14219B = null;
                            }
                            typedArrayObtainStyledAttributes.recycle();
                            dVar.f14228h = false;
                            xmlResourceParser2 = xmlResourceParser;
                            r8 = 1;
                        } else if (name3.equals("menu")) {
                            r8 = 1;
                            dVar.f14228h = true;
                            SubMenu subMenuAddSubMenu = dVar.f14221a.addSubMenu(dVar.f14222b, dVar.i, dVar.f14229j, dVar.f14230k);
                            dVar.b(subMenuAddSubMenu.getItem());
                            xmlResourceParser2 = xmlResourceParser;
                            b(xmlResourceParser2, attributeSet, subMenuAddSubMenu);
                        } else {
                            xmlResourceParser2 = xmlResourceParser;
                            r8 = 1;
                            str = name3;
                            z9 = true;
                        }
                        eventType = xmlResourceParser2.next();
                        r42 = r8;
                        i = 2;
                        z8 = z8;
                        z9 = z9;
                    }
                }
                xmlResourceParser2 = xmlResourceParser;
                r8 = r42;
                z8 = z8;
            }
            eventType = xmlResourceParser2.next();
            r42 = r8;
            i = 2;
            z8 = z8;
            z9 = z9;
        }
    }

    @Override // android.view.MenuInflater
    public final void inflate(int i, Menu menu) {
        if (!(menu instanceof MenuC1147h)) {
            super.inflate(i, menu);
            return;
        }
        XmlResourceParser layout = null;
        try {
            try {
                try {
                    layout = this.f14250c.getResources().getLayout(i);
                    b(layout, Xml.asAttributeSet(layout), menu);
                    layout.close();
                } catch (IOException e8) {
                    throw new InflateException("Error inflating menu XML", e8);
                }
            } catch (XmlPullParserException e9) {
                throw new InflateException("Error inflating menu XML", e9);
            }
        } catch (Throwable th) {
            if (layout != null) {
                layout.close();
            }
            throw th;
        }
    }
}
