当前位置: 首页>>代码示例>>Java>>正文


Java SubMenu.hasVisibleItems方法代码示例

本文整理汇总了Java中android.view.SubMenu.hasVisibleItems方法的典型用法代码示例。如果您正苦于以下问题:Java SubMenu.hasVisibleItems方法的具体用法?Java SubMenu.hasVisibleItems怎么用?Java SubMenu.hasVisibleItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.SubMenu的用法示例。


在下文中一共展示了SubMenu.hasVisibleItems方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareMenuItems

import android.view.SubMenu; //导入方法依赖的package包/类
/**
 * Flattens the visible menu items of {@link #mMenu} into {@link #mItems},
 * while inserting separators between items when necessary.
 */
private void prepareMenuItems() {
    if (mUpdateSuspended) {
        return;
    }
    mUpdateSuspended = true;
    mItems.clear();
    mItems.add(new NavigationMenuHeaderItem());

    int currentGroupId = -1;
    int currentGroupStart = 0;
    boolean currentGroupHasIcon = false;
    for (int i = 0, totalSize = mMenu.getVisibleItems().size(); i < totalSize; i++) {
        MenuItemImpl item = mMenu.getVisibleItems().get(i);
        if (item.isChecked()) {
            setCheckedItem(item);
        }
        if (item.isCheckable()) {
            item.setExclusiveCheckable(false);
        }
        if (item.hasSubMenu()) {
            SubMenu subMenu = item.getSubMenu();
            if (subMenu.hasVisibleItems()) {
                if (i != 0) {
                    mItems.add(new NavigationMenuSeparatorItem(mPaddingSeparator, 0));
                }
                mItems.add(new NavigationMenuTextItem(item));
                boolean subMenuHasIcon = false;
                int subMenuStart = mItems.size();
                for (int j = 0, size = subMenu.size(); j < size; j++) {
                    MenuItemImpl subMenuItem = (MenuItemImpl) subMenu.getItem(j);
                    if (subMenuItem.isVisible()) {
                        if (!subMenuHasIcon && subMenuItem.getIcon() != null) {
                            subMenuHasIcon = true;
                        }
                        if (subMenuItem.isCheckable()) {
                            subMenuItem.setExclusiveCheckable(false);
                        }
                        if (item.isChecked()) {
                            setCheckedItem(item);
                        }
                        mItems.add(new NavigationMenuTextItem(subMenuItem));
                    }
                }
                if (subMenuHasIcon) {
                    appendTransparentIconIfMissing(subMenuStart, mItems.size());
                }
            }
        } else {
            int groupId = item.getGroupId();
            if (groupId != currentGroupId) { // first item in group
                currentGroupStart = mItems.size();
                currentGroupHasIcon = item.getIcon() != null;
                if (i != 0) {
                    currentGroupStart++;
                    mItems.add(new NavigationMenuSeparatorItem(
                            mPaddingSeparator, mPaddingSeparator));
                }
            } else if (!currentGroupHasIcon && item.getIcon() != null) {
                currentGroupHasIcon = true;
                appendTransparentIconIfMissing(currentGroupStart, mItems.size());
            }
            if (currentGroupHasIcon && item.getIcon() == null) {
                item.setIcon(android.R.color.transparent);
            }
            NavigationMenuTextItem textItem = new NavigationMenuTextItem(item);
            textItem.needsEmptyIcon = currentGroupHasIcon;
            mItems.add(textItem);
            currentGroupId = groupId;
        }
    }
    mUpdateSuspended = false;
}
 
开发者ID:jruesga,项目名称:rview,代码行数:77,代码来源:DrawerNavigationMenuPresenter.java

示例2: prepareMenuItems

import android.view.SubMenu; //导入方法依赖的package包/类
/**
 * Flattens the visible menu items of {@link #menu} into {@link #items},
 * while inserting separators between items when necessary.
 *
 * Adapted from the Design support library's NavigationMenuPresenter implementation
 */
private void prepareMenuItems() {
    items.clear();
    int currentGroupId = 0;

    // Iterate over the menu items
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isVisible()) {
            if (item.hasSubMenu()) {
                // Flatten the submenu
                SubMenu subMenu = item.getSubMenu();
                if (subMenu.hasVisibleItems()) {
                    if (menuType == LIST) {
                        items.add(SheetMenuItem.SEPARATOR);

                        // Add a header item if it has text
                        if (!TextUtils.isEmpty(item.getTitle())) {
                            items.add(SheetMenuItem.of(item));
                        }
                    }

                    // Add the sub-items
                    for (int subI = 0, size = subMenu.size(); subI < size; subI++) {
                        MenuItem subMenuItem = subMenu.getItem(subI);
                        if (subMenuItem.isVisible()) {
                            items.add(SheetMenuItem.of(subMenuItem));
                        }
                    }

                    // Add one more separator to the end to close it off if we have more items
                    if (menuType == LIST && i != menu.size() - 1) {
                        items.add(SheetMenuItem.SEPARATOR);
                    }
                }
            } else {
                int groupId = item.getGroupId();
                if (groupId != currentGroupId && menuType == LIST) {
                    items.add(SheetMenuItem.SEPARATOR);
                }
                items.add(SheetMenuItem.of(item));
                currentGroupId = groupId;
            }
        }
    }
}
 
开发者ID:NandagopalR,项目名称:Bottom-sheet-Listview,代码行数:52,代码来源:MenuSheetView.java

示例3: prepareMenuItems

import android.view.SubMenu; //导入方法依赖的package包/类
/**
 * Flattens the visible menu items of {@link #menu} into {@link #items}, while inserting
 * separators between items when necessary.
 */
private void prepareMenuItems() {
  if (updateSuspended) {
    return;
  }
  updateSuspended = true;
  items.clear();
  items.add(new NavigationMenuHeaderItem());

  int currentGroupId = -1;
  int currentGroupStart = 0;
  boolean currentGroupHasIcon = false;
  for (int i = 0, totalSize = menu.getVisibleItems().size(); i < totalSize; i++) {
    MenuItemImpl item = menu.getVisibleItems().get(i);
    if (item.isChecked()) {
      setCheckedItem(item);
    }
    if (item.isCheckable()) {
      item.setExclusiveCheckable(false);
    }
    if (item.hasSubMenu()) {
      SubMenu subMenu = item.getSubMenu();
      if (subMenu.hasVisibleItems()) {
        if (i != 0) {
          items.add(new NavigationMenuSeparatorItem(paddingSeparator, 0));
        }
        items.add(new NavigationMenuTextItem(item));
        boolean subMenuHasIcon = false;
        int subMenuStart = items.size();
        for (int j = 0, size = subMenu.size(); j < size; j++) {
          MenuItemImpl subMenuItem = (MenuItemImpl) subMenu.getItem(j);
          if (subMenuItem.isVisible()) {
            if (!subMenuHasIcon && subMenuItem.getIcon() != null) {
              subMenuHasIcon = true;
            }
            if (subMenuItem.isCheckable()) {
              subMenuItem.setExclusiveCheckable(false);
            }
            if (item.isChecked()) {
              setCheckedItem(item);
            }
            items.add(new NavigationMenuTextItem(subMenuItem));
          }
        }
        if (subMenuHasIcon) {
          appendTransparentIconIfMissing(subMenuStart, items.size());
        }
      }
    } else {
      int groupId = item.getGroupId();
      if (groupId != currentGroupId) { // first item in group
        currentGroupStart = items.size();
        currentGroupHasIcon = item.getIcon() != null;
        if (i != 0) {
          currentGroupStart++;
          items.add(new NavigationMenuSeparatorItem(paddingSeparator, paddingSeparator));
        }
      } else if (!currentGroupHasIcon && item.getIcon() != null) {
        currentGroupHasIcon = true;
        appendTransparentIconIfMissing(currentGroupStart, items.size());
      }
      NavigationMenuTextItem textItem = new NavigationMenuTextItem(item);
      textItem.needsEmptyIcon = currentGroupHasIcon;
      items.add(textItem);
      currentGroupId = groupId;
    }
  }
  updateSuspended = false;
}
 
开发者ID:material-components,项目名称:material-components-android,代码行数:73,代码来源:NavigationMenuPresenter.java


注:本文中的android.view.SubMenu.hasVisibleItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。