package X6FRs_4.KQgRr5e_0.YghfZG_14.XnFJ5_9;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.SparseArray;
import android.view.ContextMenu;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.SubMenu;
import android.view.View;
import android.view.ViewConfiguration;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/* compiled from: MenuBuilder.java */
/* loaded from: classes.dex */
public class FSaI4_7 implements X6FRs_4.IMuAHx_6.IMuAHx_6.KQgRr5e_0.KQgRr5e_0 {
    public static final String ACTION_VIEW_STATES_KEY = "android:menu:actionviewstates";
    public static final String EXPANDED_ACTION_VIEW_ID = "android:menu:expandedactionview";
    public static final String PRESENTER_KEY = "android:menu:presenters";
    public static final String TAG = "MenuBuilder";
    public static final int[] sCategoryToOrder = {1, 4, 5, 3, 2, 0};
    public KQgRr5e_0 mCallback;
    public final Context mContext;
    public ContextMenu.ContextMenuInfo mCurrentMenuInfo;
    public XnFJ5_9 mExpandedItem;
    public SparseArray<Parcelable> mFrozenViewStates;
    public Drawable mHeaderIcon;
    public CharSequence mHeaderTitle;
    public View mHeaderView;
    public boolean mOverrideVisibleItems;
    public boolean mQwertyMode;
    public final Resources mResources;
    public boolean mShortcutsVisible;
    public int mDefaultShowAsAction = 0;
    public boolean mPreventDispatchingItemsChanged = false;
    public boolean mItemsChangedWhileDispatchPrevented = false;
    public boolean mStructureChangedWhileDispatchPrevented = false;
    public boolean mOptionalIconsVisible = false;
    public boolean mIsClosing = false;
    public ArrayList<XnFJ5_9> mTempShortcutItemList = new ArrayList<>();
    public CopyOnWriteArrayList<WeakReference<YghfZG_14>> mPresenters = new CopyOnWriteArrayList<>();
    public boolean mGroupDividerEnabled = false;
    public ArrayList<XnFJ5_9> mItems = new ArrayList<>();
    public ArrayList<XnFJ5_9> mVisibleItems = new ArrayList<>();
    public boolean mIsVisibleItemsStale = true;
    public ArrayList<XnFJ5_9> mActionItems = new ArrayList<>();
    public ArrayList<XnFJ5_9> mNonActionItems = new ArrayList<>();
    public boolean mIsActionItemsStale = true;

    /* compiled from: MenuBuilder.java */
    /* loaded from: classes.dex */
    public interface KQgRr5e_0 {
        boolean onMenuItemSelected(FSaI4_7 fSaI4_7, MenuItem menuItem);

        void onMenuModeChange(FSaI4_7 fSaI4_7);
    }

    /* compiled from: MenuBuilder.java */
    /* loaded from: classes.dex */
    public interface QxJ9d_1 {
        boolean KQgRr5e_0(XnFJ5_9 xnFJ5_9);
    }

    public FSaI4_7(Context context) {
        this.mContext = context;
        this.mResources = context.getResources();
        setShortcutsVisibleInner(true);
    }

    private XnFJ5_9 createNewMenuItem(int i, int i2, int i3, int i4, CharSequence charSequence, int i5) {
        return new XnFJ5_9(this, i, i2, i3, i4, charSequence, i5);
    }

    private void dispatchPresenterUpdate(boolean z) {
        if (this.mPresenters.isEmpty()) {
            return;
        }
        stopDispatchingItemsChanged();
        Iterator<WeakReference<YghfZG_14>> it = this.mPresenters.iterator();
        while (it.hasNext()) {
            WeakReference<YghfZG_14> next = it.next();
            YghfZG_14 yghfZG_14 = next.get();
            if (yghfZG_14 == null) {
                this.mPresenters.remove(next);
            } else {
                yghfZG_14.updateMenuView(z);
            }
        }
        startDispatchingItemsChanged();
    }

    private void dispatchRestoreInstanceState(Bundle bundle) {
        Parcelable parcelable;
        SparseArray sparseParcelableArray = bundle.getSparseParcelableArray(PRESENTER_KEY);
        if (sparseParcelableArray == null || this.mPresenters.isEmpty()) {
            return;
        }
        Iterator<WeakReference<YghfZG_14>> it = this.mPresenters.iterator();
        while (it.hasNext()) {
            WeakReference<YghfZG_14> next = it.next();
            YghfZG_14 yghfZG_14 = next.get();
            if (yghfZG_14 == null) {
                this.mPresenters.remove(next);
            } else {
                int id = yghfZG_14.getId();
                if (id > 0 && (parcelable = (Parcelable) sparseParcelableArray.get(id)) != null) {
                    yghfZG_14.onRestoreInstanceState(parcelable);
                }
            }
        }
    }

    private void dispatchSaveInstanceState(Bundle bundle) {
        Parcelable onSaveInstanceState;
        if (this.mPresenters.isEmpty()) {
            return;
        }
        SparseArray<? extends Parcelable> sparseArray = new SparseArray<>();
        Iterator<WeakReference<YghfZG_14>> it = this.mPresenters.iterator();
        while (it.hasNext()) {
            WeakReference<YghfZG_14> next = it.next();
            YghfZG_14 yghfZG_14 = next.get();
            if (yghfZG_14 == null) {
                this.mPresenters.remove(next);
            } else {
                int id = yghfZG_14.getId();
                if (id > 0 && (onSaveInstanceState = yghfZG_14.onSaveInstanceState()) != null) {
                    sparseArray.put(id, onSaveInstanceState);
                }
            }
        }
        bundle.putSparseParcelableArray(PRESENTER_KEY, sparseArray);
    }

    private boolean dispatchSubMenuSelected(ZzDuCHW_20 zzDuCHW_20, YghfZG_14 yghfZG_14) {
        if (this.mPresenters.isEmpty()) {
            return false;
        }
        boolean onSubMenuSelected = yghfZG_14 != null ? yghfZG_14.onSubMenuSelected(zzDuCHW_20) : false;
        Iterator<WeakReference<YghfZG_14>> it = this.mPresenters.iterator();
        while (it.hasNext()) {
            WeakReference<YghfZG_14> next = it.next();
            YghfZG_14 yghfZG_142 = next.get();
            if (yghfZG_142 == null) {
                this.mPresenters.remove(next);
            } else if (!onSubMenuSelected) {
                onSubMenuSelected = yghfZG_142.onSubMenuSelected(zzDuCHW_20);
            }
        }
        return onSubMenuSelected;
    }

    public static int findInsertIndex(ArrayList<XnFJ5_9> arrayList, int i) {
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            if (arrayList.get(size).KQgRr5e_0() <= i) {
                return size + 1;
            }
        }
        return 0;
    }

    public static int getOrdering(int i) {
        int i2 = ((-65536) & i) >> 16;
        if (i2 >= 0) {
            int[] iArr = sCategoryToOrder;
            if (i2 < iArr.length) {
                return (i & 65535) | (iArr[i2] << 16);
            }
        }
        throw new IllegalArgumentException("order does not contain a valid category.");
    }

    private void removeItemAtInt(int i, boolean z) {
        if (i < 0 || i >= this.mItems.size()) {
            return;
        }
        this.mItems.remove(i);
        if (z) {
            onItemsChanged(true);
        }
    }

    private void setHeaderInternal(int i, CharSequence charSequence, int i2, Drawable drawable, View view) {
        Resources resources = getResources();
        if (view != null) {
            this.mHeaderView = view;
            this.mHeaderTitle = null;
            this.mHeaderIcon = null;
        } else {
            if (i > 0) {
                this.mHeaderTitle = resources.getText(i);
            } else if (charSequence != null) {
                this.mHeaderTitle = charSequence;
            }
            if (i2 > 0) {
                this.mHeaderIcon = X6FRs_4.IMuAHx_6.X6FRs_4.KQgRr5e_0.m332KQgRr5e_0(getContext(), i2);
            } else if (drawable != null) {
                this.mHeaderIcon = drawable;
            }
            this.mHeaderView = null;
        }
        onItemsChanged(false);
    }

    private void setShortcutsVisibleInner(boolean z) {
        boolean z2 = true;
        this.mShortcutsVisible = (z && this.mResources.getConfiguration().keyboard != 1 && X6FRs_4.IMuAHx_6.EuDEkJe_12.RfjZ_21.m243KQgRr5e_0(ViewConfiguration.get(this.mContext), this.mContext)) ? false : false;
    }

    @Override // android.view.Menu
    public MenuItem add(CharSequence charSequence) {
        return addInternal(0, 0, 0, charSequence);
    }

    @Override // android.view.Menu
    public int addIntentOptions(int i, int i2, int i3, ComponentName componentName, Intent[] intentArr, Intent intent, int i4, MenuItem[] menuItemArr) {
        int i5;
        PackageManager packageManager = this.mContext.getPackageManager();
        List<ResolveInfo> queryIntentActivityOptions = packageManager.queryIntentActivityOptions(componentName, intentArr, intent, 0);
        int size = queryIntentActivityOptions != null ? queryIntentActivityOptions.size() : 0;
        if ((i4 & 1) == 0) {
            removeGroup(i);
        }
        for (int i6 = 0; i6 < size; i6++) {
            ResolveInfo resolveInfo = queryIntentActivityOptions.get(i6);
            int i7 = resolveInfo.specificIndex;
            Intent intent2 = new Intent(i7 < 0 ? intent : intentArr[i7]);
            ActivityInfo activityInfo = resolveInfo.activityInfo;
            intent2.setComponent(new ComponentName(activityInfo.applicationInfo.packageName, activityInfo.name));
            MenuItem intent3 = add(i, i2, i3, resolveInfo.loadLabel(packageManager)).setIcon(resolveInfo.loadIcon(packageManager)).setIntent(intent2);
            if (menuItemArr != null && (i5 = resolveInfo.specificIndex) >= 0) {
                menuItemArr[i5] = intent3;
            }
        }
        return size;
    }

    public MenuItem addInternal(int i, int i2, int i3, CharSequence charSequence) {
        int ordering = getOrdering(i3);
        XnFJ5_9 createNewMenuItem = createNewMenuItem(i, i2, i3, ordering, charSequence, this.mDefaultShowAsAction);
        ContextMenu.ContextMenuInfo contextMenuInfo = this.mCurrentMenuInfo;
        if (contextMenuInfo != null) {
            createNewMenuItem.KQgRr5e_0(contextMenuInfo);
        }
        ArrayList<XnFJ5_9> arrayList = this.mItems;
        arrayList.add(findInsertIndex(arrayList, ordering), createNewMenuItem);
        onItemsChanged(true);
        return createNewMenuItem;
    }

    public void addMenuPresenter(YghfZG_14 yghfZG_14) {
        addMenuPresenter(yghfZG_14, this.mContext);
    }

    @Override // android.view.Menu
    public SubMenu addSubMenu(CharSequence charSequence) {
        return addSubMenu(0, 0, 0, charSequence);
    }

    public void changeMenuMode() {
        KQgRr5e_0 kQgRr5e_0 = this.mCallback;
        if (kQgRr5e_0 != null) {
            kQgRr5e_0.onMenuModeChange(this);
        }
    }

    @Override // android.view.Menu
    public void clear() {
        XnFJ5_9 xnFJ5_9 = this.mExpandedItem;
        if (xnFJ5_9 != null) {
            collapseItemActionView(xnFJ5_9);
        }
        this.mItems.clear();
        onItemsChanged(true);
    }

    public void clearAll() {
        this.mPreventDispatchingItemsChanged = true;
        clear();
        clearHeader();
        this.mPresenters.clear();
        this.mPreventDispatchingItemsChanged = false;
        this.mItemsChangedWhileDispatchPrevented = false;
        this.mStructureChangedWhileDispatchPrevented = false;
        onItemsChanged(true);
    }

    public void clearHeader() {
        this.mHeaderIcon = null;
        this.mHeaderTitle = null;
        this.mHeaderView = null;
        onItemsChanged(false);
    }

    public final void close(boolean z) {
        if (this.mIsClosing) {
            return;
        }
        this.mIsClosing = true;
        Iterator<WeakReference<YghfZG_14>> it = this.mPresenters.iterator();
        while (it.hasNext()) {
            WeakReference<YghfZG_14> next = it.next();
            YghfZG_14 yghfZG_14 = next.get();
            if (yghfZG_14 == null) {
                this.mPresenters.remove(next);
            } else {
                yghfZG_14.onCloseMenu(this, z);
            }
        }
        this.mIsClosing = false;
    }

    public boolean collapseItemActionView(XnFJ5_9 xnFJ5_9) {
        boolean z = false;
        if (!this.mPresenters.isEmpty() && this.mExpandedItem == xnFJ5_9) {
            stopDispatchingItemsChanged();
            Iterator<WeakReference<YghfZG_14>> it = this.mPresenters.iterator();
            while (it.hasNext()) {
                WeakReference<YghfZG_14> next = it.next();
                YghfZG_14 yghfZG_14 = next.get();
                if (yghfZG_14 == null) {
                    this.mPresenters.remove(next);
                } else {
                    z = yghfZG_14.collapseItemActionView(this, xnFJ5_9);
                    if (z) {
                        break;
                    }
                }
            }
            startDispatchingItemsChanged();
            if (z) {
                this.mExpandedItem = null;
            }
        }
        return z;
    }

    public boolean dispatchMenuItemSelected(FSaI4_7 fSaI4_7, MenuItem menuItem) {
        KQgRr5e_0 kQgRr5e_0 = this.mCallback;
        return kQgRr5e_0 != null && kQgRr5e_0.onMenuItemSelected(fSaI4_7, menuItem);
    }

    public boolean expandItemActionView(XnFJ5_9 xnFJ5_9) {
        boolean z = false;
        if (this.mPresenters.isEmpty()) {
            return false;
        }
        stopDispatchingItemsChanged();
        Iterator<WeakReference<YghfZG_14>> it = this.mPresenters.iterator();
        while (it.hasNext()) {
            WeakReference<YghfZG_14> next = it.next();
            YghfZG_14 yghfZG_14 = next.get();
            if (yghfZG_14 == null) {
                this.mPresenters.remove(next);
            } else {
                z = yghfZG_14.expandItemActionView(this, xnFJ5_9);
                if (z) {
                    break;
                }
            }
        }
        startDispatchingItemsChanged();
        if (z) {
            this.mExpandedItem = xnFJ5_9;
        }
        return z;
    }

    public int findGroupIndex(int i) {
        return findGroupIndex(i, 0);
    }

    @Override // android.view.Menu
    public MenuItem findItem(int i) {
        MenuItem findItem;
        int size = size();
        for (int i2 = 0; i2 < size; i2++) {
            XnFJ5_9 xnFJ5_9 = this.mItems.get(i2);
            if (xnFJ5_9.getItemId() == i) {
                return xnFJ5_9;
            }
            if (xnFJ5_9.hasSubMenu() && (findItem = xnFJ5_9.getSubMenu().findItem(i)) != null) {
                return findItem;
            }
        }
        return null;
    }

    public int findItemIndex(int i) {
        int size = size();
        for (int i2 = 0; i2 < size; i2++) {
            if (this.mItems.get(i2).getItemId() == i) {
                return i2;
            }
        }
        return -1;
    }

    public XnFJ5_9 findItemWithShortcutForKey(int i, KeyEvent keyEvent) {
        char numericShortcut;
        ArrayList<XnFJ5_9> arrayList = this.mTempShortcutItemList;
        arrayList.clear();
        findItemsWithShortcutForKey(arrayList, i, keyEvent);
        if (arrayList.isEmpty()) {
            return null;
        }
        int metaState = keyEvent.getMetaState();
        KeyCharacterMap.KeyData keyData = new KeyCharacterMap.KeyData();
        keyEvent.getKeyData(keyData);
        int size = arrayList.size();
        if (size == 1) {
            return arrayList.get(0);
        }
        boolean isQwertyMode = isQwertyMode();
        for (int i2 = 0; i2 < size; i2++) {
            XnFJ5_9 xnFJ5_9 = arrayList.get(i2);
            if (isQwertyMode) {
                numericShortcut = xnFJ5_9.getAlphabeticShortcut();
            } else {
                numericShortcut = xnFJ5_9.getNumericShortcut();
            }
            if ((numericShortcut == keyData.meta[0] && (metaState & 2) == 0) || ((numericShortcut == keyData.meta[2] && (metaState & 2) != 0) || (isQwertyMode && numericShortcut == '\b' && i == 67))) {
                return xnFJ5_9;
            }
        }
        return null;
    }

    public void findItemsWithShortcutForKey(List<XnFJ5_9> list, int i, KeyEvent keyEvent) {
        boolean isQwertyMode = isQwertyMode();
        int modifiers = keyEvent.getModifiers();
        KeyCharacterMap.KeyData keyData = new KeyCharacterMap.KeyData();
        if (keyEvent.getKeyData(keyData) || i == 67) {
            int size = this.mItems.size();
            for (int i2 = 0; i2 < size; i2++) {
                XnFJ5_9 xnFJ5_9 = this.mItems.get(i2);
                if (xnFJ5_9.hasSubMenu()) {
                    ((FSaI4_7) xnFJ5_9.getSubMenu()).findItemsWithShortcutForKey(list, i, keyEvent);
                }
                char alphabeticShortcut = isQwertyMode ? xnFJ5_9.getAlphabeticShortcut() : xnFJ5_9.getNumericShortcut();
                if (((modifiers & 69647) == ((isQwertyMode ? xnFJ5_9.getAlphabeticModifiers() : xnFJ5_9.getNumericModifiers()) & 69647)) && alphabeticShortcut != 0) {
                    char[] cArr = keyData.meta;
                    if ((alphabeticShortcut == cArr[0] || alphabeticShortcut == cArr[2] || (isQwertyMode && alphabeticShortcut == '\b' && i == 67)) && xnFJ5_9.isEnabled()) {
                        list.add(xnFJ5_9);
                    }
                }
            }
        }
    }

    public void flagActionItems() {
        ArrayList<XnFJ5_9> visibleItems = getVisibleItems();
        if (this.mIsActionItemsStale) {
            Iterator<WeakReference<YghfZG_14>> it = this.mPresenters.iterator();
            boolean z = false;
            while (it.hasNext()) {
                WeakReference<YghfZG_14> next = it.next();
                YghfZG_14 yghfZG_14 = next.get();
                if (yghfZG_14 == null) {
                    this.mPresenters.remove(next);
                } else {
                    z |= yghfZG_14.flagActionItems();
                }
            }
            if (z) {
                this.mActionItems.clear();
                this.mNonActionItems.clear();
                int size = visibleItems.size();
                for (int i = 0; i < size; i++) {
                    XnFJ5_9 xnFJ5_9 = visibleItems.get(i);
                    if (xnFJ5_9.PGPF6hQ_2()) {
                        this.mActionItems.add(xnFJ5_9);
                    } else {
                        this.mNonActionItems.add(xnFJ5_9);
                    }
                }
            } else {
                this.mActionItems.clear();
                this.mNonActionItems.clear();
                this.mNonActionItems.addAll(getVisibleItems());
            }
            this.mIsActionItemsStale = false;
        }
    }

    public ArrayList<XnFJ5_9> getActionItems() {
        flagActionItems();
        return this.mActionItems;
    }

    public String getActionViewStatesKey() {
        return ACTION_VIEW_STATES_KEY;
    }

    public Context getContext() {
        return this.mContext;
    }

    public XnFJ5_9 getExpandedItem() {
        return this.mExpandedItem;
    }

    public Drawable getHeaderIcon() {
        return this.mHeaderIcon;
    }

    public CharSequence getHeaderTitle() {
        return this.mHeaderTitle;
    }

    public View getHeaderView() {
        return this.mHeaderView;
    }

    @Override // android.view.Menu
    public MenuItem getItem(int i) {
        return this.mItems.get(i);
    }

    public ArrayList<XnFJ5_9> getNonActionItems() {
        flagActionItems();
        return this.mNonActionItems;
    }

    public boolean getOptionalIconsVisible() {
        return this.mOptionalIconsVisible;
    }

    public Resources getResources() {
        return this.mResources;
    }

    public FSaI4_7 getRootMenu() {
        return this;
    }

    public ArrayList<XnFJ5_9> getVisibleItems() {
        if (this.mIsVisibleItemsStale) {
            this.mVisibleItems.clear();
            int size = this.mItems.size();
            for (int i = 0; i < size; i++) {
                XnFJ5_9 xnFJ5_9 = this.mItems.get(i);
                if (xnFJ5_9.isVisible()) {
                    this.mVisibleItems.add(xnFJ5_9);
                }
            }
            this.mIsVisibleItemsStale = false;
            this.mIsActionItemsStale = true;
            return this.mVisibleItems;
        }
        return this.mVisibleItems;
    }

    @Override // android.view.Menu
    public boolean hasVisibleItems() {
        if (this.mOverrideVisibleItems) {
            return true;
        }
        int size = size();
        for (int i = 0; i < size; i++) {
            if (this.mItems.get(i).isVisible()) {
                return true;
            }
        }
        return false;
    }

    public boolean isGroupDividerEnabled() {
        return this.mGroupDividerEnabled;
    }

    public boolean isQwertyMode() {
        return this.mQwertyMode;
    }

    @Override // android.view.Menu
    public boolean isShortcutKey(int i, KeyEvent keyEvent) {
        return findItemWithShortcutForKey(i, keyEvent) != null;
    }

    public boolean isShortcutsVisible() {
        return this.mShortcutsVisible;
    }

    public void onItemActionRequestChanged(XnFJ5_9 xnFJ5_9) {
        this.mIsActionItemsStale = true;
        onItemsChanged(true);
    }

    public void onItemVisibleChanged(XnFJ5_9 xnFJ5_9) {
        this.mIsVisibleItemsStale = true;
        onItemsChanged(true);
    }

    public void onItemsChanged(boolean z) {
        if (!this.mPreventDispatchingItemsChanged) {
            if (z) {
                this.mIsVisibleItemsStale = true;
                this.mIsActionItemsStale = true;
            }
            dispatchPresenterUpdate(z);
            return;
        }
        this.mItemsChangedWhileDispatchPrevented = true;
        if (z) {
            this.mStructureChangedWhileDispatchPrevented = true;
        }
    }

    @Override // android.view.Menu
    public boolean performIdentifierAction(int i, int i2) {
        return performItemAction(findItem(i), i2);
    }

    public boolean performItemAction(MenuItem menuItem, int i) {
        return performItemAction(menuItem, null, i);
    }

    @Override // android.view.Menu
    public boolean performShortcut(int i, KeyEvent keyEvent, int i2) {
        XnFJ5_9 findItemWithShortcutForKey = findItemWithShortcutForKey(i, keyEvent);
        boolean performItemAction = findItemWithShortcutForKey != null ? performItemAction(findItemWithShortcutForKey, i2) : false;
        if ((i2 & 2) != 0) {
            close(true);
        }
        return performItemAction;
    }

    @Override // android.view.Menu
    public void removeGroup(int i) {
        int findGroupIndex = findGroupIndex(i);
        if (findGroupIndex >= 0) {
            int size = this.mItems.size() - findGroupIndex;
            int i2 = 0;
            while (true) {
                int i3 = i2 + 1;
                if (i2 >= size || this.mItems.get(findGroupIndex).getGroupId() != i) {
                    break;
                }
                removeItemAtInt(findGroupIndex, false);
                i2 = i3;
            }
            onItemsChanged(true);
        }
    }

    @Override // android.view.Menu
    public void removeItem(int i) {
        removeItemAtInt(findItemIndex(i), true);
    }

    public void removeItemAt(int i) {
        removeItemAtInt(i, true);
    }

    public void removeMenuPresenter(YghfZG_14 yghfZG_14) {
        Iterator<WeakReference<YghfZG_14>> it = this.mPresenters.iterator();
        while (it.hasNext()) {
            WeakReference<YghfZG_14> next = it.next();
            YghfZG_14 yghfZG_142 = next.get();
            if (yghfZG_142 == null || yghfZG_142 == yghfZG_14) {
                this.mPresenters.remove(next);
            }
        }
    }

    public void restoreActionViewStates(Bundle bundle) {
        MenuItem findItem;
        if (bundle == null) {
            return;
        }
        SparseArray<Parcelable> sparseParcelableArray = bundle.getSparseParcelableArray(getActionViewStatesKey());
        int size = size();
        for (int i = 0; i < size; i++) {
            MenuItem item = getItem(i);
            View actionView = item.getActionView();
            if (actionView != null && actionView.getId() != -1) {
                actionView.restoreHierarchyState(sparseParcelableArray);
            }
            if (item.hasSubMenu()) {
                ((ZzDuCHW_20) item.getSubMenu()).restoreActionViewStates(bundle);
            }
        }
        int i2 = bundle.getInt(EXPANDED_ACTION_VIEW_ID);
        if (i2 <= 0 || (findItem = findItem(i2)) == null) {
            return;
        }
        findItem.expandActionView();
    }

    public void restorePresenterStates(Bundle bundle) {
        dispatchRestoreInstanceState(bundle);
    }

    public void saveActionViewStates(Bundle bundle) {
        int size = size();
        SparseArray<? extends Parcelable> sparseArray = null;
        for (int i = 0; i < size; i++) {
            MenuItem item = getItem(i);
            View actionView = item.getActionView();
            if (actionView != null && actionView.getId() != -1) {
                if (sparseArray == null) {
                    sparseArray = new SparseArray<>();
                }
                actionView.saveHierarchyState(sparseArray);
                if (item.isActionViewExpanded()) {
                    bundle.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
                }
            }
            if (item.hasSubMenu()) {
                ((ZzDuCHW_20) item.getSubMenu()).saveActionViewStates(bundle);
            }
        }
        if (sparseArray != null) {
            bundle.putSparseParcelableArray(getActionViewStatesKey(), sparseArray);
        }
    }

    public void savePresenterStates(Bundle bundle) {
        dispatchSaveInstanceState(bundle);
    }

    public void setCallback(KQgRr5e_0 kQgRr5e_0) {
        this.mCallback = kQgRr5e_0;
    }

    public void setCurrentMenuInfo(ContextMenu.ContextMenuInfo contextMenuInfo) {
        this.mCurrentMenuInfo = contextMenuInfo;
    }

    public FSaI4_7 setDefaultShowAsAction(int i) {
        this.mDefaultShowAsAction = i;
        return this;
    }

    public void setExclusiveItemChecked(MenuItem menuItem) {
        int groupId = menuItem.getGroupId();
        int size = this.mItems.size();
        stopDispatchingItemsChanged();
        for (int i = 0; i < size; i++) {
            XnFJ5_9 xnFJ5_9 = this.mItems.get(i);
            if (xnFJ5_9.getGroupId() == groupId && xnFJ5_9.Mqv2r_3() && xnFJ5_9.isCheckable()) {
                xnFJ5_9.QxJ9d_1(xnFJ5_9 == menuItem);
            }
        }
        startDispatchingItemsChanged();
    }

    @Override // android.view.Menu
    public void setGroupCheckable(int i, boolean z, boolean z2) {
        int size = this.mItems.size();
        for (int i2 = 0; i2 < size; i2++) {
            XnFJ5_9 xnFJ5_9 = this.mItems.get(i2);
            if (xnFJ5_9.getGroupId() == i) {
                xnFJ5_9.PGPF6hQ_2(z2);
                xnFJ5_9.setCheckable(z);
            }
        }
    }

    @Override // android.view.Menu
    public void setGroupDividerEnabled(boolean z) {
        this.mGroupDividerEnabled = z;
    }

    @Override // android.view.Menu
    public void setGroupEnabled(int i, boolean z) {
        int size = this.mItems.size();
        for (int i2 = 0; i2 < size; i2++) {
            XnFJ5_9 xnFJ5_9 = this.mItems.get(i2);
            if (xnFJ5_9.getGroupId() == i) {
                xnFJ5_9.setEnabled(z);
            }
        }
    }

    @Override // android.view.Menu
    public void setGroupVisible(int i, boolean z) {
        int size = this.mItems.size();
        boolean z2 = false;
        for (int i2 = 0; i2 < size; i2++) {
            XnFJ5_9 xnFJ5_9 = this.mItems.get(i2);
            if (xnFJ5_9.getGroupId() == i && xnFJ5_9.m481KQgRr5e_0(z)) {
                z2 = true;
            }
        }
        if (z2) {
            onItemsChanged(true);
        }
    }

    public FSaI4_7 setHeaderIconInt(Drawable drawable) {
        setHeaderInternal(0, null, 0, drawable, null);
        return this;
    }

    public FSaI4_7 setHeaderTitleInt(CharSequence charSequence) {
        setHeaderInternal(0, charSequence, 0, null, null);
        return this;
    }

    public FSaI4_7 setHeaderViewInt(View view) {
        setHeaderInternal(0, null, 0, null, view);
        return this;
    }

    public void setOptionalIconsVisible(boolean z) {
        this.mOptionalIconsVisible = z;
    }

    public void setOverrideVisibleItems(boolean z) {
        this.mOverrideVisibleItems = z;
    }

    @Override // android.view.Menu
    public void setQwertyMode(boolean z) {
        this.mQwertyMode = z;
        onItemsChanged(false);
    }

    public void setShortcutsVisible(boolean z) {
        if (this.mShortcutsVisible == z) {
            return;
        }
        setShortcutsVisibleInner(z);
        onItemsChanged(false);
    }

    @Override // android.view.Menu
    public int size() {
        return this.mItems.size();
    }

    public void startDispatchingItemsChanged() {
        this.mPreventDispatchingItemsChanged = false;
        if (this.mItemsChangedWhileDispatchPrevented) {
            this.mItemsChangedWhileDispatchPrevented = false;
            onItemsChanged(this.mStructureChangedWhileDispatchPrevented);
        }
    }

    public void stopDispatchingItemsChanged() {
        if (this.mPreventDispatchingItemsChanged) {
            return;
        }
        this.mPreventDispatchingItemsChanged = true;
        this.mItemsChangedWhileDispatchPrevented = false;
        this.mStructureChangedWhileDispatchPrevented = false;
    }

    @Override // android.view.Menu
    public MenuItem add(int i) {
        return addInternal(0, 0, 0, this.mResources.getString(i));
    }

    public void addMenuPresenter(YghfZG_14 yghfZG_14, Context context) {
        this.mPresenters.add(new WeakReference<>(yghfZG_14));
        yghfZG_14.initForMenu(context, this);
        this.mIsActionItemsStale = true;
    }

    @Override // android.view.Menu
    public SubMenu addSubMenu(int i) {
        return addSubMenu(0, 0, 0, this.mResources.getString(i));
    }

    public int findGroupIndex(int i, int i2) {
        int size = size();
        if (i2 < 0) {
            i2 = 0;
        }
        while (i2 < size) {
            if (this.mItems.get(i2).getGroupId() == i) {
                return i2;
            }
            i2++;
        }
        return -1;
    }

    public boolean performItemAction(MenuItem menuItem, YghfZG_14 yghfZG_14, int i) {
        XnFJ5_9 xnFJ5_9 = (XnFJ5_9) menuItem;
        if (xnFJ5_9 == null || !xnFJ5_9.isEnabled()) {
            return false;
        }
        boolean QxJ9d_12 = xnFJ5_9.QxJ9d_1();
        X6FRs_4.IMuAHx_6.EuDEkJe_12.QxJ9d_1 KQgRr5e_02 = xnFJ5_9.KQgRr5e_0();
        boolean z = KQgRr5e_02 != null && KQgRr5e_02.m242KQgRr5e_0();
        if (xnFJ5_9.KQgRr5e_0()) {
            QxJ9d_12 |= xnFJ5_9.expandActionView();
            if (QxJ9d_12) {
                close(true);
            }
        } else if (xnFJ5_9.hasSubMenu() || z) {
            if ((i & 4) == 0) {
                close(false);
            }
            if (!xnFJ5_9.hasSubMenu()) {
                xnFJ5_9.KQgRr5e_0(new ZzDuCHW_20(getContext(), this, xnFJ5_9));
            }
            ZzDuCHW_20 zzDuCHW_20 = (ZzDuCHW_20) xnFJ5_9.getSubMenu();
            if (z) {
                KQgRr5e_02.KQgRr5e_0(zzDuCHW_20);
            }
            QxJ9d_12 |= dispatchSubMenuSelected(zzDuCHW_20, yghfZG_14);
            if (!QxJ9d_12) {
                close(true);
            }
        } else if ((i & 1) == 0) {
            close(true);
        }
        return QxJ9d_12;
    }

    public FSaI4_7 setHeaderIconInt(int i) {
        setHeaderInternal(0, null, i, null, null);
        return this;
    }

    public FSaI4_7 setHeaderTitleInt(int i) {
        setHeaderInternal(i, null, 0, null, null);
        return this;
    }

    @Override // android.view.Menu
    public MenuItem add(int i, int i2, int i3, CharSequence charSequence) {
        return addInternal(i, i2, i3, charSequence);
    }

    @Override // android.view.Menu
    public SubMenu addSubMenu(int i, int i2, int i3, CharSequence charSequence) {
        XnFJ5_9 xnFJ5_9 = (XnFJ5_9) addInternal(i, i2, i3, charSequence);
        ZzDuCHW_20 zzDuCHW_20 = new ZzDuCHW_20(this.mContext, this, xnFJ5_9);
        xnFJ5_9.KQgRr5e_0(zzDuCHW_20);
        return zzDuCHW_20;
    }

    @Override // android.view.Menu
    public MenuItem add(int i, int i2, int i3, int i4) {
        return addInternal(i, i2, i3, this.mResources.getString(i4));
    }

    @Override // android.view.Menu
    public SubMenu addSubMenu(int i, int i2, int i3, int i4) {
        return addSubMenu(i, i2, i3, this.mResources.getString(i4));
    }

    @Override // android.view.Menu
    public void close() {
        close(true);
    }
}
