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.graphics.PorterDuff;
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.MenuItem;
import android.view.SubMenu;
import android.view.View;
import androidx.appcompat.view.menu.k;
import androidx.appcompat.view.menu.l;
import defpackage.go7;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/* JADX INFO: loaded from: classes.dex */
@m38
public class fe9 extends MenuInflater {
    public static final Class[] e;
    public static final Class[] f;
    public final Object[] a;
    public final Object[] b;
    public final Context c;
    public Object d;

    public static class a implements MenuItem.OnMenuItemClickListener {
        public static final Class[] c = {MenuItem.class};
        public Object a;
        public Method b;

        @Override // android.view.MenuItem.OnMenuItemClickListener
        public final boolean onMenuItemClick(MenuItem menuItem) {
            Object obj = this.a;
            Method method = this.b;
            try {
                if (method.getReturnType() == Boolean.TYPE) {
                    return ((Boolean) method.invoke(obj, menuItem)).booleanValue();
                }
                method.invoke(obj, menuItem);
                return true;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    public class b {
        public final Menu a;
        public CharSequence aa;
        public CharSequence ab;
        public boolean h;
        public int i;
        public int j;
        public CharSequence k;
        public CharSequence l;
        public int m;
        public char n;
        public int o;
        public char p;
        public int q;
        public int r;
        public boolean s;
        public boolean t;
        public boolean u;
        public int v;
        public int w;
        public String x;
        public String y;
        public t7 z;
        public ColorStateList ac = null;
        public PorterDuff.Mode ad = null;
        public int b = 0;
        public int c = 0;
        public int d = 0;
        public int e = 0;
        public boolean f = true;
        public boolean g = true;

        public b(Menu menu) {
            this.a = menu;
        }

        public final Object a(String str, Class[] clsArr, Object[] objArr) {
            try {
                Constructor<?> constructor = Class.forName(str, false, fe9.this.c.getClassLoader()).getConstructor(clsArr);
                constructor.setAccessible(true);
                return constructor.newInstance(objArr);
            } catch (Exception e) {
                Log.w("SupportMenuInflater", "Cannot instantiate class: " + str, e);
                return null;
            }
        }

        public final void b(MenuItem menuItem) {
            fe9 fe9Var = fe9.this;
            Context context = fe9Var.c;
            boolean z = false;
            menuItem.setChecked(this.s).setVisible(this.t).setEnabled(this.u).setCheckable(this.r >= 1).setTitleCondensed(this.l).setIcon(this.m);
            int i = this.v;
            if (i >= 0) {
                menuItem.setShowAsAction(i);
            }
            if (this.y != null) {
                if (context.isRestricted()) {
                    throw new IllegalStateException("The android:onClick attribute cannot be used within a restricted context");
                }
                if (fe9Var.d == null) {
                    fe9Var.d = fe9.a(context);
                }
                Object obj = fe9Var.d;
                String str = this.y;
                a aVar = new a();
                aVar.a = obj;
                Class<?> cls = obj.getClass();
                try {
                    aVar.b = cls.getMethod(str, a.c);
                    menuItem.setOnMenuItemClickListener(aVar);
                } catch (Exception e) {
                    StringBuilder sbS = vw2.s("Couldn't resolve menu item onClick handler ", str, " in class ");
                    sbS.append(cls.getName());
                    InflateException inflateException = new InflateException(sbS.toString());
                    inflateException.initCause(e);
                    throw inflateException;
                }
            }
            if (this.r >= 2) {
                if (menuItem instanceof k) {
                    ((k) menuItem).f(true);
                } else if (menuItem instanceof l) {
                    l lVar = (l) menuItem;
                    ge9 ge9Var = lVar.d;
                    try {
                        if (lVar.e == null) {
                            lVar.e = ge9Var.getClass().getDeclaredMethod("setExclusiveCheckable", Boolean.TYPE);
                        }
                        lVar.e.invoke(ge9Var, Boolean.TRUE);
                    } catch (Exception e2) {
                        Log.w("MenuItemWrapper", "Error while calling setExclusiveCheckable", e2);
                    }
                }
            }
            String str2 = this.x;
            if (str2 != null) {
                menuItem.setActionView((View) a(str2, fe9.e, fe9Var.a));
                z = true;
            }
            int i2 = this.w;
            if (i2 > 0) {
                if (z) {
                    Log.w("SupportMenuInflater", "Ignoring attribute 'itemActionViewLayout'. Action view already specified.");
                } else {
                    menuItem.setActionView(i2);
                }
            }
            t7 t7Var = this.z;
            if (t7Var != null) {
                if (menuItem instanceof ge9) {
                    ((ge9) menuItem).a(t7Var);
                } else {
                    Log.w("MenuItemCompat", "setActionProvider: item does not implement SupportMenuItem; ignoring");
                }
            }
            CharSequence charSequence = this.aa;
            boolean z2 = menuItem instanceof ge9;
            if (z2) {
                ((ge9) menuItem).setContentDescription(charSequence);
            } else {
                menuItem.setContentDescription(charSequence);
            }
            CharSequence charSequence2 = this.ab;
            if (z2) {
                ((ge9) menuItem).setTooltipText(charSequence2);
            } else {
                menuItem.setTooltipText(charSequence2);
            }
            char c = this.n;
            int i3 = this.o;
            if (z2) {
                ((ge9) menuItem).setAlphabeticShortcut(c, i3);
            } else {
                menuItem.setAlphabeticShortcut(c, i3);
            }
            char c2 = this.p;
            int i4 = this.q;
            if (z2) {
                ((ge9) menuItem).setNumericShortcut(c2, i4);
            } else {
                menuItem.setNumericShortcut(c2, i4);
            }
            PorterDuff.Mode mode = this.ad;
            if (mode != null) {
                if (z2) {
                    ((ge9) menuItem).setIconTintMode(mode);
                } else {
                    menuItem.setIconTintMode(mode);
                }
            }
            ColorStateList colorStateList = this.ac;
            if (colorStateList != null) {
                if (z2) {
                    ((ge9) menuItem).setIconTintList(colorStateList);
                } else {
                    menuItem.setIconTintList(colorStateList);
                }
            }
        }
    }

    static {
        Class[] clsArr = {Context.class};
        e = clsArr;
        f = clsArr;
    }

    public fe9(Context context) {
        super(context);
        this.c = context;
        Object[] objArr = {context};
        this.a = objArr;
        this.b = objArr;
    }

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

    public final void b(XmlPullParser xmlPullParser, AttributeSet attributeSet, Menu menu) throws XmlPullParserException, IOException {
        int i;
        XmlPullParser xmlPullParser2;
        ColorStateList colorStateList;
        b bVar = new b(menu);
        int eventType = xmlPullParser.getEventType();
        while (true) {
            i = 2;
            if (eventType == 2) {
                String name = xmlPullParser.getName();
                if (!name.equals("menu")) {
                    throw new RuntimeException("Expecting menu, got ".concat(name));
                }
                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) {
                throw new RuntimeException("Unexpected end of document");
            }
            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")) {
                            bVar.b = 0;
                            bVar.c = 0;
                            bVar.d = 0;
                            bVar.e = 0;
                            bVar.f = true;
                            bVar.g = true;
                        } else if (name2.equals("item")) {
                            if (!bVar.h) {
                                t7 t7Var = bVar.z;
                                if (t7Var == null || !t7Var.a()) {
                                    bVar.h = true;
                                    bVar.b(bVar.a.add(bVar.b, bVar.i, bVar.j, bVar.k));
                                } else {
                                    bVar.h = true;
                                    bVar.b(bVar.a.addSubMenu(bVar.b, bVar.i, bVar.j, bVar.k).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.c;
                    if (zEquals) {
                        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, go7.m.q);
                        bVar.b = typedArrayObtainStyledAttributes.getResourceId(1, 0);
                        bVar.c = typedArrayObtainStyledAttributes.getInt(3, 0);
                        bVar.d = typedArrayObtainStyledAttributes.getInt(4, 0);
                        bVar.e = typedArrayObtainStyledAttributes.getInt(5, 0);
                        bVar.f = typedArrayObtainStyledAttributes.getBoolean(2, true);
                        bVar.g = typedArrayObtainStyledAttributes.getBoolean(0, true);
                        typedArrayObtainStyledAttributes.recycle();
                    } else {
                        if (name3.equals("item")) {
                            fp9 fp9VarE = fp9.e(context, attributeSet, go7.m.r);
                            TypedArray typedArray = fp9VarE.b;
                            bVar.i = typedArray.getResourceId(2, 0);
                            bVar.j = (typedArray.getInt(5, bVar.c) & (-65536)) | (typedArray.getInt(6, bVar.d) & 65535);
                            bVar.k = typedArray.getText(7);
                            bVar.l = typedArray.getText(8);
                            bVar.m = typedArray.getResourceId(0, 0);
                            String string = typedArray.getString(9);
                            bVar.n = string == null ? (char) 0 : string.charAt(0);
                            bVar.o = typedArray.getInt(16, 4096);
                            String string2 = typedArray.getString(10);
                            bVar.p = string2 == null ? (char) 0 : string2.charAt(0);
                            bVar.q = typedArray.getInt(20, 4096);
                            if (typedArray.hasValue(11)) {
                                bVar.r = typedArray.getBoolean(11, false) ? 1 : 0;
                            } else {
                                bVar.r = bVar.e;
                            }
                            bVar.s = typedArray.getBoolean(3, false);
                            bVar.t = typedArray.getBoolean(4, bVar.f);
                            bVar.u = typedArray.getBoolean(1, bVar.g);
                            bVar.v = typedArray.getInt(21, -1);
                            bVar.y = typedArray.getString(12);
                            bVar.w = typedArray.getResourceId(13, 0);
                            bVar.x = typedArray.getString(15);
                            String string3 = typedArray.getString(14);
                            boolean z3 = string3 != null;
                            if (z3 && bVar.w == 0 && bVar.x == null) {
                                bVar.z = (t7) bVar.a(string3, f, this.b);
                            } else {
                                if (z3) {
                                    Log.w("SupportMenuInflater", "Ignoring attribute 'actionProviderClass'. Action view already specified.");
                                }
                                bVar.z = null;
                            }
                            bVar.aa = typedArray.getText(17);
                            bVar.ab = typedArray.getText(22);
                            if (typedArray.hasValue(19)) {
                                bVar.ad = vf2.c(typedArray.getInt(19, -1), bVar.ad);
                                colorStateList = null;
                            } else {
                                colorStateList = null;
                                bVar.ad = null;
                            }
                            if (typedArray.hasValue(18)) {
                                bVar.ac = fp9VarE.a(18);
                            } else {
                                bVar.ac = colorStateList;
                            }
                            fp9VarE.g();
                            bVar.h = false;
                            xmlPullParser2 = xmlPullParser;
                        } else if (name3.equals("menu")) {
                            bVar.h = true;
                            SubMenu subMenuAddSubMenu = bVar.a.addSubMenu(bVar.b, bVar.i, bVar.j, bVar.k);
                            bVar.b(subMenuAddSubMenu.getItem());
                            xmlPullParser2 = xmlPullParser;
                            b(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;
        }
    }

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