content: package androidx.appcompat.view.menu;
  
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import androidx.appcompat.view.menu.MenuPresenter;
  import androidx.appcompat.view.menu.MenuView;
  import java.util.ArrayList;
  
  public abstract class BaseMenuPresenter implements MenuPresenter {
      private MenuPresenter.Callback mCallback;
      protected Context mContext;
      private int mId;
      protected LayoutInflater mInflater;
      private int mItemLayoutRes;
      protected MenuBuilder mMenu;
      private int mMenuLayoutRes;
      protected MenuView mMenuView;
      protected Context mSystemContext;
      protected LayoutInflater mSystemInflater;
  
      public BaseMenuPresenter(Context context, int menuLayoutRes, int itemLayoutRes) {
          this.mSystemContext = context;
          this.mSystemInflater = LayoutInflater.from(context);
          this.mMenuLayoutRes = menuLayoutRes;
          this.mItemLayoutRes = itemLayoutRes;
      }
  
      /* access modifiers changed from: protected */
      public void addItemView(View itemView, int childIndex) {
          ViewGroup viewGroup = (ViewGroup) itemView.getParent();
          if (viewGroup != null) {
              viewGroup.removeView(itemView);
          }
          ((ViewGroup) this.mMenuView).addView(itemView, childIndex);
      }
  
      public abstract void bindItemView(MenuItemImpl menuItemImpl, MenuView.ItemView itemView);
  
      public boolean collapseItemActionView(MenuBuilder menu, MenuItemImpl item) {
          return false;
      }
  
      public MenuView.ItemView createItemView(ViewGroup parent) {
          return (MenuView.ItemView) this.mSystemInflater.inflate(this.mItemLayoutRes, parent, false);
      }
  
      public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) {
          return false;
      }
  
      /* access modifiers changed from: protected */
      public boolean filterLeftoverView(ViewGroup parent, int childIndex) {
          parent.removeViewAt(childIndex);
          return true;
      }
  
      public boolean flagActionItems() {
          return false;
      }
  
      public MenuPresenter.Callback getCallback() {
          return this.mCallback;
      }
  
      public int getId() {
          return this.mId;
      }
  
      public View getItemView(MenuItemImpl item, View convertView, ViewGroup parent) {
          MenuView.ItemView createItemView = convertView instanceof MenuView.ItemView ? (MenuView.ItemView) convertView : createItemView(parent);
          bindItemView(item, createItemView);
          return (View) createItemView;
      }
  
      public MenuView getMenuView(ViewGroup root) {
          if (this.mMenuView == null) {
              MenuView menuView = (MenuView) this.mSystemInflater.inflate(this.mMenuLayoutRes, root, false);
              this.mMenuView = menuView;
              menuView.initialize(this.mMenu);
              updateMenuView(true);
          }
          return this.mMenuView;
      }
  
      public void initForMenu(Context context, MenuBuilder menu) {
          this.mContext = context;
          this.mInflater = LayoutInflater.from(context);
          this.mMenu = menu;
      }
  
      public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) {
          MenuPresenter.Callback callback = this.mCallback;
          if (callback != null) {
              callback.onCloseMenu(menu, allMenusAreClosing);
          }
      }
  
      public boolean onSubMenuSelected(SubMenuBuilder menu) {
          MenuPresenter.Callback callback = this.mCallback;
          if (callback == null) {
              return false;
          }
          return callback.onOpenSubMenu(menu != null ? menu : this.mMenu);
      }
  
      public void setCallback(MenuPresenter.Callback cb) {
          this.mCallback = cb;
      }
  
      public void setId(int id) {
          this.mId = id;
      }
  
      public boolean shouldIncludeItem(int childIndex, MenuItemImpl item) {
          return true;
      }
  
      public void updateMenuView(boolean cleared) {
          ViewGroup viewGroup = (ViewGroup) this.mMenuView;
          if (viewGroup != null) {
              int i = 0;
              MenuBuilder menuBuilder = this.mMenu;
              if (menuBuilder != null) {
                  menuBuilder.flagActionItems();
                  ArrayList<MenuItemImpl> visibleItems = this.mMenu.getVisibleItems();
                  int size = visibleItems.size();
                  for (int i2 = 0; i2 < size; i2++) {
                      MenuItemImpl menuItemImpl = visibleItems.get(i2);
                      if (shouldIncludeItem(i, menuItemImpl)) {
                          View childAt = viewGroup.getChildAt(i);
                          MenuItemImpl itemData = childAt instanceof MenuView.ItemView ? ((MenuView.ItemView) childAt).getItemData() : null;
                          View itemView = getItemView(menuItemImpl, childAt, viewGroup);
                          if (menuItemImpl != itemData) {
                              itemView.setPressed(false);
                              itemView.jumpDrawablesToCurrentState();
                          }
                          if (itemView != childAt) {
                              addItemView(itemView, i);
                          }
                          i++;
                      }
                  }
              }
              while (i < viewGroup.getChildCount()) {
                  if (!filterLeftoverView(viewGroup, i)) {
                      i++;
                  }
              }
          }
      }
  }
  