package defpackage;

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.Xml;
import android.view.InflateException;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.SubMenu;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* renamed from: ʿʽ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C0368 extends MenuInflater {

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public static final Class[] f2141;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public static final Class[] f2142;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final Context f2143;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final Object[] f2144;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final Object[] f2145;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public Object f2146;

    static {
        Class[] clsArr = {Context.class};
        f2141 = clsArr;
        f2142 = clsArr;
    }

    public C0368(Context context) {
        super(context);
        this.f2143 = context;
        Object[] objArr = {context};
        this.f2144 = objArr;
        this.f2145 = objArr;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public static Object m1804(Object obj) {
        return (!(obj instanceof Activity) && (obj instanceof ContextWrapper)) ? m1804(((ContextWrapper) obj).getBaseContext()) : obj;
    }

    @Override // android.view.MenuInflater
    public final void inflate(int i, Menu menu) {
        if (!(menu instanceof MenuC2418)) {
            super.inflate(i, menu);
            return;
        }
        XmlResourceParser layout = null;
        boolean z = false;
        try {
            try {
                layout = this.f2143.getResources().getLayout(i);
                AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(layout);
                if (menu instanceof MenuC2418) {
                    MenuC2418 menuC2418 = (MenuC2418) menu;
                    if (!menuC2418.f9421) {
                        menuC2418.m6190();
                        z = true;
                    }
                }
                m1805(layout, attributeSetAsAttributeSet, menu);
                if (z) {
                    ((MenuC2418) menu).m6192();
                }
                layout.close();
            } catch (IOException e) {
                throw new InflateException("Error inflating menu XML", e);
            } catch (XmlPullParserException e2) {
                throw new InflateException("Error inflating menu XML", e2);
            }
        } catch (Throwable th) {
            if (z) {
                ((MenuC2418) menu).m6192();
            }
            if (layout != null) {
                layout.close();
            }
            throw th;
        }
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final void m1805(XmlPullParser xmlPullParser, AttributeSet attributeSet, Menu menu) throws XmlPullParserException, IllegalAccessException, IOException, IllegalArgumentException, InvocationTargetException {
        int i;
        XmlPullParser xmlPullParser2;
        ColorStateList colorStateList;
        int resourceId;
        C2311 c2311 = new C2311(this, menu);
        int eventType = xmlPullParser.getEventType();
        while (true) {
            i = 2;
            if (eventType == 2) {
                String name = xmlPullParser.getName();
                if (!name.equals("menu")) {
                    C1260.m3816("Expecting menu, got ".concat(name));
                    return;
                }
                eventType = xmlPullParser.next();
            } else {
                eventType = xmlPullParser.next();
                if (eventType == 1) {
                    break;
                }
            }
        }
        boolean z = false;
        boolean z2 = false;
        String str = null;
        while (!z) {
            if (eventType == 1) {
                C1260.m3816("Unexpected end of document");
                return;
            }
            Menu menu2 = c2311.f9038;
            if (eventType != i) {
                if (eventType != 3) {
                    xmlPullParser2 = xmlPullParser;
                    z = z;
                } else {
                    String name2 = xmlPullParser.getName();
                    if (z2 && name2.equals(str)) {
                        xmlPullParser2 = xmlPullParser;
                        z2 = false;
                        str = null;
                    } else {
                        if (name2.equals("group")) {
                            c2311.f9044 = 0;
                            c2311.f9028 = 0;
                            c2311.f9049 = 0;
                            c2311.f9022 = 0;
                            c2311.f9027 = true;
                            c2311.f9025 = true;
                        } else if (name2.equals("item")) {
                            if (!c2311.f9048) {
                                ActionProviderVisibilityListenerC1207 actionProviderVisibilityListenerC1207 = c2311.f9037;
                                if (actionProviderVisibilityListenerC1207 == null || !actionProviderVisibilityListenerC1207.f5133.hasSubMenu()) {
                                    c2311.f9048 = true;
                                    c2311.m6014(menu2.add(c2311.f9044, c2311.f9031, c2311.f9045, c2311.f9047));
                                } else {
                                    c2311.f9048 = true;
                                    c2311.m6014(menu2.addSubMenu(c2311.f9044, c2311.f9031, c2311.f9045, c2311.f9047).getItem());
                                }
                            }
                        } else if (name2.equals("menu")) {
                            xmlPullParser2 = xmlPullParser;
                            z = true;
                        }
                        xmlPullParser2 = xmlPullParser;
                        z = z;
                    }
                }
                eventType = xmlPullParser2.next();
                i = 2;
                z = z;
                z2 = z2;
            } else {
                if (!z2) {
                    String name3 = xmlPullParser.getName();
                    boolean zEquals = name3.equals("group");
                    Context context = this.f2143;
                    if (zEquals) {
                        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AbstractC0542.f2804);
                        c2311.f9044 = typedArrayObtainStyledAttributes.getResourceId(1, 0);
                        c2311.f9028 = typedArrayObtainStyledAttributes.getInt(3, 0);
                        c2311.f9049 = typedArrayObtainStyledAttributes.getInt(4, 0);
                        c2311.f9022 = typedArrayObtainStyledAttributes.getInt(5, 0);
                        c2311.f9027 = typedArrayObtainStyledAttributes.getBoolean(2, true);
                        c2311.f9025 = typedArrayObtainStyledAttributes.getBoolean(0, true);
                        typedArrayObtainStyledAttributes.recycle();
                    } else {
                        if (name3.equals("item")) {
                            TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(attributeSet, AbstractC0542.f2812);
                            c2311.f9031 = typedArrayObtainStyledAttributes2.getResourceId(2, 0);
                            c2311.f9045 = (typedArrayObtainStyledAttributes2.getInt(5, c2311.f9028) & (-65536)) | (typedArrayObtainStyledAttributes2.getInt(6, c2311.f9049) & 65535);
                            c2311.f9047 = typedArrayObtainStyledAttributes2.getText(7);
                            c2311.f9024 = typedArrayObtainStyledAttributes2.getText(8);
                            c2311.f9042 = typedArrayObtainStyledAttributes2.getResourceId(0, 0);
                            String string = typedArrayObtainStyledAttributes2.getString(9);
                            c2311.f9041 = string == null ? (char) 0 : string.charAt(0);
                            c2311.f9043 = typedArrayObtainStyledAttributes2.getInt(16, 4096);
                            String string2 = typedArrayObtainStyledAttributes2.getString(10);
                            c2311.f9023 = string2 == null ? (char) 0 : string2.charAt(0);
                            c2311.f9033 = typedArrayObtainStyledAttributes2.getInt(20, 4096);
                            if (typedArrayObtainStyledAttributes2.hasValue(11)) {
                                c2311.f9046 = typedArrayObtainStyledAttributes2.getBoolean(11, false) ? 1 : 0;
                            } else {
                                c2311.f9046 = c2311.f9022;
                            }
                            c2311.f9032 = typedArrayObtainStyledAttributes2.getBoolean(3, false);
                            c2311.f9040 = typedArrayObtainStyledAttributes2.getBoolean(4, c2311.f9027);
                            c2311.f9030 = typedArrayObtainStyledAttributes2.getBoolean(1, c2311.f9025);
                            c2311.f9039 = typedArrayObtainStyledAttributes2.getInt(21, -1);
                            c2311.f9050 = typedArrayObtainStyledAttributes2.getString(12);
                            c2311.f9036 = typedArrayObtainStyledAttributes2.getResourceId(13, 0);
                            c2311.f9051 = typedArrayObtainStyledAttributes2.getString(15);
                            String string3 = typedArrayObtainStyledAttributes2.getString(14);
                            if (string3 != null && c2311.f9036 == 0 && c2311.f9051 == null) {
                                c2311.f9037 = (ActionProviderVisibilityListenerC1207) c2311.m6013(string3, f2142, this.f2145);
                            } else {
                                c2311.f9037 = null;
                            }
                            c2311.f9035 = typedArrayObtainStyledAttributes2.getText(17);
                            c2311.f9021 = typedArrayObtainStyledAttributes2.getText(22);
                            if (typedArrayObtainStyledAttributes2.hasValue(19)) {
                                c2311.f9029 = AbstractC1991.m5512(typedArrayObtainStyledAttributes2.getInt(19, -1), c2311.f9029);
                            } else {
                                c2311.f9029 = null;
                            }
                            if (typedArrayObtainStyledAttributes2.hasValue(18)) {
                                if (!typedArrayObtainStyledAttributes2.hasValue(18) || (resourceId = typedArrayObtainStyledAttributes2.getResourceId(18, 0)) == 0 || (colorStateList = AbstractC5363.m10989(context, resourceId)) == null) {
                                    colorStateList = typedArrayObtainStyledAttributes2.getColorStateList(18);
                                }
                                c2311.f9034 = colorStateList;
                            } else {
                                c2311.f9034 = null;
                            }
                            typedArrayObtainStyledAttributes2.recycle();
                            c2311.f9048 = false;
                            xmlPullParser2 = xmlPullParser;
                        } else if (name3.equals("menu")) {
                            c2311.f9048 = true;
                            SubMenu subMenuAddSubMenu = menu2.addSubMenu(c2311.f9044, c2311.f9031, c2311.f9045, c2311.f9047);
                            c2311.m6014(subMenuAddSubMenu.getItem());
                            xmlPullParser2 = xmlPullParser;
                            m1805(xmlPullParser2, attributeSet, subMenuAddSubMenu);
                        } else {
                            xmlPullParser2 = xmlPullParser;
                            str = name3;
                            z2 = true;
                        }
                        eventType = xmlPullParser2.next();
                        i = 2;
                        z = z;
                        z2 = z2;
                    }
                }
                xmlPullParser2 = xmlPullParser;
                z = z;
            }
            eventType = xmlPullParser2.next();
            i = 2;
            z = z;
            z2 = z2;
        }
    }
}
