package c.a.m;

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.j;
import androidx.appcompat.view.menu.k;
import androidx.appcompat.widget.c0;
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: compiled from: SupportMenuInflater.java */
/* JADX INFO: loaded from: classes.dex */
public class g extends MenuInflater {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    static final Class<?>[] f1240e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    static final Class<?>[] f1241f;
    final Object[] a;

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

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

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

    /* JADX INFO: compiled from: SupportMenuInflater.java */
    private static class a implements MenuItem.OnMenuItemClickListener {

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private static final Class<?>[] f1245c = {MenuItem.class};
        private Object a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private Method f1246b;

        public a(Object obj, String str) {
            this.a = obj;
            Class<?> cls = obj.getClass();
            try {
                this.f1246b = cls.getMethod(str, f1245c);
            } catch (Exception e2) {
                InflateException inflateException = new InflateException("Couldn't resolve menu item onClick handler " + str + " in class " + cls.getName());
                inflateException.initCause(e2);
                throw inflateException;
            }
        }

        @Override // android.view.MenuItem.OnMenuItemClickListener
        public boolean onMenuItemClick(MenuItem menuItem) {
            try {
                if (this.f1246b.getReturnType() == Boolean.TYPE) {
                    return ((Boolean) this.f1246b.invoke(this.a, menuItem)).booleanValue();
                }
                this.f1246b.invoke(this.a, menuItem);
                return true;
            } catch (Exception e2) {
                throw new RuntimeException(e2);
            }
        }
    }

    /* JADX INFO: compiled from: SupportMenuInflater.java */
    private class b {
        c.f.l.b A;
        private CharSequence B;
        private CharSequence C;
        private ColorStateList D = null;
        private PorterDuff.Mode E = null;
        private Menu a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private int f1247b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private int f1248c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private int f1249d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private int f1250e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private boolean f1251f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private boolean f1252g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        private boolean f1253h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        private int f1254i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        private int f1255j;

        /* JADX INFO: renamed from: k, reason: collision with root package name */
        private CharSequence f1256k;
        private CharSequence l;
        private int m;
        private char n;
        private int o;
        private char p;
        private int q;
        private int r;
        private boolean s;
        private boolean t;
        private boolean u;
        private int v;
        private int w;
        private String x;
        private String y;
        private String z;

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

        private char c(String str) {
            if (str == null) {
                return (char) 0;
            }
            return str.charAt(0);
        }

        private <T> T e(String str, Class<?>[] clsArr, Object[] objArr) {
            try {
                Constructor<?> constructor = g.this.f1243c.getClassLoader().loadClass(str).getConstructor(clsArr);
                constructor.setAccessible(true);
                return (T) constructor.newInstance(objArr);
            } catch (Exception e2) {
                Log.w("SupportMenuInflater", "Cannot instantiate class: " + str, e2);
                return null;
            }
        }

        private void i(MenuItem menuItem) {
            boolean z = false;
            menuItem.setChecked(this.s).setVisible(this.t).setEnabled(this.u).setCheckable(this.r >= 1).setTitleCondensed(this.l).setIcon(this.m);
            int i2 = this.v;
            if (i2 >= 0) {
                menuItem.setShowAsAction(i2);
            }
            if (this.z != null) {
                if (g.this.f1243c.isRestricted()) {
                    throw new IllegalStateException("The android:onClick attribute cannot be used within a restricted context");
                }
                menuItem.setOnMenuItemClickListener(new a(g.this.b(), this.z));
            }
            boolean z2 = menuItem instanceof j;
            if (z2) {
            }
            if (this.r >= 2) {
                if (z2) {
                    ((j) menuItem).s(true);
                } else if (menuItem instanceof k) {
                    ((k) menuItem).i(true);
                }
            }
            String str = this.x;
            if (str != null) {
                menuItem.setActionView((View) e(str, g.f1240e, g.this.a));
                z = true;
            }
            int i3 = this.w;
            if (i3 > 0) {
                if (z) {
                    Log.w("SupportMenuInflater", "Ignoring attribute 'itemActionViewLayout'. Action view already specified.");
                } else {
                    menuItem.setActionView(i3);
                }
            }
            c.f.l.b bVar = this.A;
            if (bVar != null) {
                c.f.l.h.a(menuItem, bVar);
            }
            c.f.l.h.c(menuItem, this.B);
            c.f.l.h.g(menuItem, this.C);
            c.f.l.h.b(menuItem, this.n, this.o);
            c.f.l.h.f(menuItem, this.p, this.q);
            PorterDuff.Mode mode = this.E;
            if (mode != null) {
                c.f.l.h.e(menuItem, mode);
            }
            ColorStateList colorStateList = this.D;
            if (colorStateList != null) {
                c.f.l.h.d(menuItem, colorStateList);
            }
        }

        public void a() {
            this.f1253h = true;
            i(this.a.add(this.f1247b, this.f1254i, this.f1255j, this.f1256k));
        }

        public SubMenu b() {
            this.f1253h = true;
            SubMenu subMenuAddSubMenu = this.a.addSubMenu(this.f1247b, this.f1254i, this.f1255j, this.f1256k);
            i(subMenuAddSubMenu.getItem());
            return subMenuAddSubMenu;
        }

        public boolean d() {
            return this.f1253h;
        }

        public void f(AttributeSet attributeSet) {
            TypedArray typedArrayObtainStyledAttributes = g.this.f1243c.obtainStyledAttributes(attributeSet, c.a.j.MenuGroup);
            this.f1247b = typedArrayObtainStyledAttributes.getResourceId(c.a.j.MenuGroup_android_id, 0);
            this.f1248c = typedArrayObtainStyledAttributes.getInt(c.a.j.MenuGroup_android_menuCategory, 0);
            this.f1249d = typedArrayObtainStyledAttributes.getInt(c.a.j.MenuGroup_android_orderInCategory, 0);
            this.f1250e = typedArrayObtainStyledAttributes.getInt(c.a.j.MenuGroup_android_checkableBehavior, 0);
            this.f1251f = typedArrayObtainStyledAttributes.getBoolean(c.a.j.MenuGroup_android_visible, true);
            this.f1252g = typedArrayObtainStyledAttributes.getBoolean(c.a.j.MenuGroup_android_enabled, true);
            typedArrayObtainStyledAttributes.recycle();
        }

        public void g(AttributeSet attributeSet) {
            TypedArray typedArrayObtainStyledAttributes = g.this.f1243c.obtainStyledAttributes(attributeSet, c.a.j.MenuItem);
            this.f1254i = typedArrayObtainStyledAttributes.getResourceId(c.a.j.MenuItem_android_id, 0);
            this.f1255j = (typedArrayObtainStyledAttributes.getInt(c.a.j.MenuItem_android_menuCategory, this.f1248c) & (-65536)) | (typedArrayObtainStyledAttributes.getInt(c.a.j.MenuItem_android_orderInCategory, this.f1249d) & 65535);
            this.f1256k = typedArrayObtainStyledAttributes.getText(c.a.j.MenuItem_android_title);
            this.l = typedArrayObtainStyledAttributes.getText(c.a.j.MenuItem_android_titleCondensed);
            this.m = typedArrayObtainStyledAttributes.getResourceId(c.a.j.MenuItem_android_icon, 0);
            this.n = c(typedArrayObtainStyledAttributes.getString(c.a.j.MenuItem_android_alphabeticShortcut));
            this.o = typedArrayObtainStyledAttributes.getInt(c.a.j.MenuItem_alphabeticModifiers, 4096);
            this.p = c(typedArrayObtainStyledAttributes.getString(c.a.j.MenuItem_android_numericShortcut));
            this.q = typedArrayObtainStyledAttributes.getInt(c.a.j.MenuItem_numericModifiers, 4096);
            if (typedArrayObtainStyledAttributes.hasValue(c.a.j.MenuItem_android_checkable)) {
                this.r = typedArrayObtainStyledAttributes.getBoolean(c.a.j.MenuItem_android_checkable, false) ? 1 : 0;
            } else {
                this.r = this.f1250e;
            }
            this.s = typedArrayObtainStyledAttributes.getBoolean(c.a.j.MenuItem_android_checked, false);
            this.t = typedArrayObtainStyledAttributes.getBoolean(c.a.j.MenuItem_android_visible, this.f1251f);
            this.u = typedArrayObtainStyledAttributes.getBoolean(c.a.j.MenuItem_android_enabled, this.f1252g);
            this.v = typedArrayObtainStyledAttributes.getInt(c.a.j.MenuItem_showAsAction, -1);
            this.z = typedArrayObtainStyledAttributes.getString(c.a.j.MenuItem_android_onClick);
            this.w = typedArrayObtainStyledAttributes.getResourceId(c.a.j.MenuItem_actionLayout, 0);
            this.x = typedArrayObtainStyledAttributes.getString(c.a.j.MenuItem_actionViewClass);
            String string = typedArrayObtainStyledAttributes.getString(c.a.j.MenuItem_actionProviderClass);
            this.y = string;
            boolean z = string != null;
            if (z && this.w == 0 && this.x == null) {
                this.A = (c.f.l.b) e(this.y, g.f1241f, g.this.f1242b);
            } else {
                if (z) {
                    Log.w("SupportMenuInflater", "Ignoring attribute 'actionProviderClass'. Action view already specified.");
                }
                this.A = null;
            }
            this.B = typedArrayObtainStyledAttributes.getText(c.a.j.MenuItem_contentDescription);
            this.C = typedArrayObtainStyledAttributes.getText(c.a.j.MenuItem_tooltipText);
            if (typedArrayObtainStyledAttributes.hasValue(c.a.j.MenuItem_iconTintMode)) {
                this.E = c0.d(typedArrayObtainStyledAttributes.getInt(c.a.j.MenuItem_iconTintMode, -1), this.E);
            } else {
                this.E = null;
            }
            if (typedArrayObtainStyledAttributes.hasValue(c.a.j.MenuItem_iconTint)) {
                this.D = typedArrayObtainStyledAttributes.getColorStateList(c.a.j.MenuItem_iconTint);
            } else {
                this.D = null;
            }
            typedArrayObtainStyledAttributes.recycle();
            this.f1253h = false;
        }

        public void h() {
            this.f1247b = 0;
            this.f1248c = 0;
            this.f1249d = 0;
            this.f1250e = 0;
            this.f1251f = true;
            this.f1252g = true;
        }
    }

    static {
        Class<?>[] clsArr = {Context.class};
        f1240e = clsArr;
        f1241f = clsArr;
    }

    public g(Context context) {
        super(context);
        this.f1243c = context;
        Object[] objArr = {context};
        this.a = objArr;
        this.f1242b = objArr;
    }

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

    private void c(XmlPullParser xmlPullParser, AttributeSet attributeSet, Menu menu) throws XmlPullParserException, IOException {
        b bVar = new b(menu);
        int eventType = xmlPullParser.getEventType();
        while (true) {
            if (eventType == 2) {
                String name = xmlPullParser.getName();
                if (!name.equals("menu")) {
                    throw new RuntimeException("Expecting menu, got " + name);
                }
                eventType = xmlPullParser.next();
            } else {
                eventType = xmlPullParser.next();
                if (eventType == 1) {
                    break;
                }
            }
        }
        String str = null;
        boolean z = false;
        boolean z2 = false;
        while (!z) {
            if (eventType == 1) {
                throw new RuntimeException("Unexpected end of document");
            }
            if (eventType != 2) {
                if (eventType == 3) {
                    String name2 = xmlPullParser.getName();
                    if (z2 && name2.equals(str)) {
                        str = null;
                        z2 = false;
                    } else if (name2.equals("group")) {
                        bVar.h();
                    } else if (name2.equals("item")) {
                        if (!bVar.d()) {
                            c.f.l.b bVar2 = bVar.A;
                            if (bVar2 == null || !bVar2.a()) {
                                bVar.a();
                            } else {
                                bVar.b();
                            }
                        }
                    } else if (name2.equals("menu")) {
                        z = true;
                    }
                }
            } else if (!z2) {
                String name3 = xmlPullParser.getName();
                if (name3.equals("group")) {
                    bVar.f(attributeSet);
                } else if (name3.equals("item")) {
                    bVar.g(attributeSet);
                } else if (name3.equals("menu")) {
                    c(xmlPullParser, attributeSet, bVar.b());
                } else {
                    str = name3;
                    z2 = true;
                }
            }
            eventType = xmlPullParser.next();
        }
    }

    Object b() {
        if (this.f1244d == null) {
            this.f1244d = a(this.f1243c);
        }
        return this.f1244d;
    }

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