/** Reuses item views when it can */
  public void updateMenuView(boolean cleared) {
    final ViewGroup parent = (ViewGroup) mMenuView;
    if (parent == null) return;

    int childIndex = 0;
    if (mMenu != null) {
      mMenu.flagActionItems();
      ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems();
      final int itemCount = visibleItems.size();
      for (int i = 0; i < itemCount; i++) {
        MenuItemImpl item = visibleItems.get(i);
        if (shouldIncludeItem(childIndex, item)) {
          final View convertView = parent.getChildAt(childIndex);
          final MenuItemImpl oldItem =
              convertView instanceof MenuView.ItemView
                  ? ((MenuView.ItemView) convertView).getItemData()
                  : null;
          final View itemView = getItemView(item, convertView, parent);
          if (item != oldItem) {
            // Don't let old states linger with new data.
            itemView.setPressed(false);
            itemView.jumpDrawablesToCurrentState();
          }
          if (itemView != convertView) {
            addItemView(itemView, childIndex);
          }
          childIndex++;
        }
      }
    }

    // Remove leftover views.
    while (childIndex < parent.getChildCount()) {
      if (!filterLeftoverView(parent, childIndex)) {
        childIndex++;
      }
    }
  }
Пример #2
0
 ArrayList<MenuItemImpl> getNonActionItems() {
   flagActionItems();
   return mNonActionItems;
 }