@Override
 public void initialize(MenuItemImpl itemData, int menuType) {
   mItemData = itemData;
   setVisibility(itemData.isVisible() ? View.VISIBLE : View.GONE);
   setTitle(itemData.getTitleForItemView(this));
   setCheckable(itemData.isCheckable());
   setShortcut(itemData.shouldShowShortcut(), itemData.getShortcut());
   setIcon(itemData.getIcon());
   setEnabled(itemData.isEnabled());
 }
Esempio n. 2
0
  public boolean hasVisibleItems() {
    final int size = size();

    for (int i = 0; i < size; i++) {
      MenuItemImpl item = mItems.get(i);
      if (item.isVisible()) {
        return true;
      }
    }

    return false;
  }
Esempio n. 3
0
  ArrayList<MenuItemImpl> getVisibleItems() {
    if (!mIsVisibleItemsStale) return mVisibleItems;

    // Refresh the visible items
    mVisibleItems.clear();

    final int itemsSize = mItems.size();
    MenuItemImpl item;
    for (int i = 0; i < itemsSize; i++) {
      item = mItems.get(i);
      if (item.isVisible()) mVisibleItems.add(item);
    }

    mIsVisibleItemsStale = false;
    mIsActionItemsStale = true;

    return mVisibleItems;
  }
Esempio n. 4
0
  public boolean bindNativeOverflow(
      android.view.Menu menu,
      android.view.MenuItem.OnMenuItemClickListener listener,
      HashMap<android.view.MenuItem, MenuItemImpl> map) {
    final List<MenuItemImpl> nonActionItems = getNonActionItems();
    if (nonActionItems == null || nonActionItems.size() == 0) {
      return false;
    }

    boolean visible = false;
    menu.clear();
    for (MenuItemImpl nonActionItem : nonActionItems) {
      if (!nonActionItem.isVisible()) {
        continue;
      }
      visible = true;

      android.view.MenuItem nativeItem;
      if (nonActionItem.hasSubMenu()) {
        android.view.SubMenu nativeSub =
            menu.addSubMenu(
                nonActionItem.getGroupId(),
                nonActionItem.getItemId(),
                nonActionItem.getOrder(),
                nonActionItem.getTitle());

        SubMenuBuilder subMenu = (SubMenuBuilder) nonActionItem.getSubMenu();
        for (MenuItemImpl subItem : subMenu.getVisibleItems()) {
          android.view.MenuItem nativeSubItem =
              nativeSub.add(
                  subItem.getGroupId(),
                  subItem.getItemId(),
                  subItem.getOrder(),
                  subItem.getTitle());

          nativeSubItem.setIcon(subItem.getIcon());
          nativeSubItem.setOnMenuItemClickListener(listener);
          nativeSubItem.setEnabled(subItem.isEnabled());
          nativeSubItem.setIntent(subItem.getIntent());
          nativeSubItem.setNumericShortcut(subItem.getNumericShortcut());
          nativeSubItem.setAlphabeticShortcut(subItem.getAlphabeticShortcut());
          nativeSubItem.setTitleCondensed(subItem.getTitleCondensed());
          nativeSubItem.setCheckable(subItem.isCheckable());
          nativeSubItem.setChecked(subItem.isChecked());

          if (subItem.isExclusiveCheckable()) {
            nativeSub.setGroupCheckable(subItem.getGroupId(), true, true);
          }

          map.put(nativeSubItem, subItem);
        }

        nativeItem = nativeSub.getItem();
      } else {
        nativeItem =
            menu.add(
                nonActionItem.getGroupId(),
                nonActionItem.getItemId(),
                nonActionItem.getOrder(),
                nonActionItem.getTitle());
      }
      nativeItem.setIcon(nonActionItem.getIcon());
      nativeItem.setOnMenuItemClickListener(listener);
      nativeItem.setEnabled(nonActionItem.isEnabled());
      nativeItem.setIntent(nonActionItem.getIntent());
      nativeItem.setNumericShortcut(nonActionItem.getNumericShortcut());
      nativeItem.setAlphabeticShortcut(nonActionItem.getAlphabeticShortcut());
      nativeItem.setTitleCondensed(nonActionItem.getTitleCondensed());
      nativeItem.setCheckable(nonActionItem.isCheckable());
      nativeItem.setChecked(nonActionItem.isChecked());

      if (nonActionItem.isExclusiveCheckable()) {
        menu.setGroupCheckable(nonActionItem.getGroupId(), true, true);
      }

      map.put(nativeItem, nonActionItem);
    }
    return visible;
  }