Java Code Examples for android.view.MenuItem#hasSubMenu()

The following examples show how to use android.view.MenuItem#hasSubMenu() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppMenuAdapter.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public int getItemViewType(int position) {
    MenuItem item = getItem(position);
    int viewCount = item.hasSubMenu() ? item.getSubMenu().size() : 1;

    if (item.getItemId() == R.id.update_menu_id) {
        return UPDATE_MENU_ITEM;
    } else if (viewCount == 5) {
        return FIVE_BUTTON_MENU_ITEM;
    } else if (viewCount == 4) {
        return FOUR_BUTTON_MENU_ITEM;
    } else if (viewCount == 3) {
        return THREE_BUTTON_MENU_ITEM;
    } else if (viewCount == 2) {
        return TITLE_BUTTON_MENU_ITEM;
    }
    return STANDARD_MENU_ITEM;
}
 
Example 2
Source File: AppMenuAdapter.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public int getItemViewType(int position) {
    MenuItem item = getItem(position);
    int viewCount = item.hasSubMenu() ? item.getSubMenu().size() : 1;

    if (item.getItemId() == R.id.update_menu_id) {
        return UPDATE_MENU_ITEM;
    } else if (viewCount == 4) {
        return FOUR_BUTTON_MENU_ITEM;
    } else if (viewCount == 3) {
        return THREE_BUTTON_MENU_ITEM;
    } else if (viewCount == 2) {
        return TITLE_BUTTON_MENU_ITEM;
    }
    return STANDARD_MENU_ITEM;
}
 
Example 3
Source File: RadialMenuManager.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
  handler.removeCallbacks(radialMenuHint);

  EventId eventId = EVENT_ID_UNTRACKED; // Not tracking performance of menu events.
  pipeline.returnFeedback(
      eventId, Feedback.vibration(R.array.view_clicked_pattern).sound(R.raw.tick));

  boolean handled =
      menuActionInterceptor != null && menuActionInterceptor.onInterceptMenuClick(menuItem);

  if (!handled) {
    handled = client != null && client.onMenuItemClicked(menuItem);
  }

  if (!handled && (menuItem == null)) {
    pipeline.returnFeedback(
        EVENT_ID_UNTRACKED, Feedback.part().setInterruptAllFeedback(true));
  }

  if ((menuItem != null) && menuItem.hasSubMenu()) {
    playScaleForMenu(menuItem.getSubMenu());
  }

  return true;
}
 
Example 4
Source File: AppMenuAdapter.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public int getItemViewType(int position) {
    MenuItem item = getItem(position);
    int viewCount = item.hasSubMenu() ? item.getSubMenu().size() : 1;

    if (item.getItemId() == R.id.update_menu_id) {
        return UPDATE_MENU_ITEM;
    } else if (viewCount == 5) {
        return FIVE_BUTTON_MENU_ITEM;
    } else if (viewCount == 4) {
        return FOUR_BUTTON_MENU_ITEM;
    } else if (viewCount == 3) {
        return THREE_BUTTON_MENU_ITEM;
    } else if (viewCount == 2) {
        return TITLE_BUTTON_MENU_ITEM;
    }
    return STANDARD_MENU_ITEM;
}
 
Example 5
Source File: WishlistFragment.java    From CineLog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (!item.hasSubMenu()) {
        createListView(item.getItemId());
    }

    return super.onOptionsItemSelected(item);
}
 
Example 6
Source File: MenuInflateFromXml.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // For "Title only": Examples of matching an ID with one assigned in
        //                   the XML
        case R.id.jump:
            Toast.makeText(this, "Jump up in the air!", Toast.LENGTH_SHORT).show();
            return true;

        case R.id.dive:
            Toast.makeText(this, "Dive into the water!", Toast.LENGTH_SHORT).show();
            return true;

        // For "Groups": Toggle visibility of grouped menu items with
        //               nongrouped menu items
        case R.id.browser_visibility:
            // The refresh item is part of the browser group
            final boolean shouldShowBrowser = !mMenu.findItem(R.id.refresh).isVisible();
            mMenu.setGroupVisible(R.id.browser, shouldShowBrowser);
            break;
            
        case R.id.email_visibility:
            // The reply item is part of the email group
            final boolean shouldShowEmail = !mMenu.findItem(R.id.reply).isVisible();
            mMenu.setGroupVisible(R.id.email, shouldShowEmail);
            break;
            
        // Generic catch all for all the other menu resources
        default:
            // Don't toast text when a submenu is clicked
            if (!item.hasSubMenu()) {
                Toast.makeText(this, item.getTitle(), Toast.LENGTH_SHORT).show();
                return true;
            }
            break;
    }
    
    return false;
}
 
Example 7
Source File: ContextUtils.java    From kimai-android with MIT License 5 votes vote down vote up
/**
 * Try to tint all {@link Menu}s {@link MenuItem}s with given color
 */
@SuppressWarnings("ConstantConditions")
public void tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        try {
            tintDrawable(item.getIcon(), iconColor);
            if (item.hasSubMenu() && recurse) {
                tintMenuItems(item.getSubMenu(), recurse, iconColor);
            }
        } catch (Exception ignored) {
            // This should not happen at all, but may in bad menu.xml configuration
        }
    }
}
 
Example 8
Source File: BubbleActions.java    From BubbleActions with Apache License 2.0 5 votes vote down vote up
/**
 * Set the actions using a menu xml resource. There are 3 requirements of the menu xml:
 * 1. The menu cannot have more than 5 items,
 * 2. Each menu item cannot have a submenu, and
 * 3. Each menu item must have an icon, title, and an id
 *
 * @param menuRes  The resource id of the menu
 * @param callback A callback to run on the main thread when an action is selected
 * @return the BubbleActions instance that called this method
 */
public BubbleActions fromMenu(int menuRes, final MenuCallback callback) {
    Menu menu = new PopupMenu(root.getContext(), null).getMenu();
    MenuInflater inflater = new MenuInflater(root.getContext());
    inflater.inflate(menuRes, menu);

    if (menu.size() > BubbleActionOverlay.MAX_ACTIONS) {
        throw new IllegalArgumentException(TAG + ": menu resource cannot have more than "
                + BubbleActionOverlay.MAX_ACTIONS + "actions.");
    }

    for (int i = 0; i < menu.size(); i++) {
        final MenuItem item = menu.getItem(i);

        if (item.hasSubMenu() || item.getIcon() == null || item.getTitle() == null || item.getItemId() == 0) {
            throw new IllegalArgumentException(TAG + ": menu resource cannot have a submenu and " +
                    "must have an icon, title, and id.");
        }

        final int id = item.getItemId();
        addAction(item.getTitle(), item.getIcon(), new Callback() {
            @Override
            public void doAction() {
                callback.doAction(id);
            }
        });
    }

    return this;
}
 
Example 9
Source File: ContextUtils.java    From Stringlate with MIT License 5 votes vote down vote up
/**
 * Try to tint all {@link Menu}s {@link MenuItem}s with given color
 */
@SuppressWarnings("ConstantConditions")
public void tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        tintDrawable(item.getIcon(), iconColor);
        if (item.hasSubMenu() && recurse) {
            tintMenuItems(item.getSubMenu(), recurse, iconColor);
        }
    }
}
 
Example 10
Source File: ContextUtils.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Try to tint all {@link Menu}s {@link MenuItem}s with given color
 */
@SuppressWarnings("ConstantConditions")
public void tintMenuItems(final Menu menu, final boolean recurse, @ColorInt final int iconColor) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        try {
            tintDrawable(item.getIcon(), iconColor);
            if (item.hasSubMenu() && recurse) {
                tintMenuItems(item.getSubMenu(), recurse, iconColor);
            }
        } catch (Exception ignored) {
            // This should not happen at all, but may in bad menu.xml configuration
        }
    }
}
 
Example 11
Source File: ContextUtils.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Try to tint all {@link Menu}s {@link MenuItem}s with given color
 */
@SuppressWarnings("ConstantConditions")
public void tintMenuItems(final Menu menu, final boolean recurse, @ColorInt final int iconColor) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        try {
            tintDrawable(item.getIcon(), iconColor);
            if (item.hasSubMenu() && recurse) {
                tintMenuItems(item.getSubMenu(), recurse, iconColor);
            }
        } catch (Exception ignored) {
            // This should not happen at all, but may in bad menu.xml configuration
        }
    }
}
 
Example 12
Source File: ListFragment.java    From CineLog with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(!item.hasSubMenu()) {
        createListView(item.getItemId());
    }

    return super.onOptionsItemSelected(item);
}
 
Example 13
Source File: BottomSheetAdapterBuilder.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor,
                                                 int itemTextColor, int itemBackground,
                                                 int tintColor) {
    List<BottomSheetItem> items = new ArrayList<>();
    mTitles = 0;

    boolean addedSubMenu = false;

    for (int i = 0; i < mMenu.size(); i++) {
        MenuItem item = mMenu.getItem(i);

        if (item.isVisible()) {
            if (item.hasSubMenu()) {
                SubMenu subMenu = item.getSubMenu();

                if (i != 0 && addedSubMenu) {
                    if (mMode == BottomSheetBuilder.MODE_GRID) {
                        throw new IllegalArgumentException("MODE_GRID can't have submenus." +
                                " Use MODE_LIST instead");
                    }
                    items.add(new BottomSheetDivider(dividerBackground));
                }

                CharSequence title = item.getTitle();
                if (title != null && !title.equals("")) {
                    items.add(new BottomSheetHeader(title.toString(), titleTextColor));
                    mTitles++;
                }

                for (int j = 0; j < subMenu.size(); j++) {
                    MenuItem subItem = subMenu.getItem(j);
                    if (subItem.isVisible()) {
                        items.add(new BottomSheetMenuItem(subItem, itemTextColor,
                                itemBackground, tintColor));
                        addedSubMenu = true;
                    }
                }
            } else {
                items.add(new BottomSheetMenuItem(item, itemTextColor, itemBackground, tintColor));
            }
        }
    }

    return items;
}
 
Example 14
Source File: BottomSheetAdapterBuilder.java    From BottomSheetBuilder with Apache License 2.0 4 votes vote down vote up
private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor,
                                                 int itemTextColor, int itemBackground,
                                                 int tintColor) {
    List<BottomSheetItem> items = new ArrayList<>();
    mTitles = 0;

    boolean addedSubMenu = false;

    for (int i = 0; i < mMenu.size(); i++) {
        MenuItem item = mMenu.getItem(i);

        if (item.isVisible()) {
            if (item.hasSubMenu()) {
                SubMenu subMenu = item.getSubMenu();

                if (i != 0 && addedSubMenu) {
                    if (mMode == BottomSheetBuilder.MODE_GRID) {
                        throw new IllegalArgumentException("MODE_GRID can't have submenus." +
                                " Use MODE_LIST instead");
                    }
                    items.add(new BottomSheetDivider(dividerBackground));
                }

                CharSequence title = item.getTitle();
                if (title != null && !title.equals("")) {
                    items.add(new BottomSheetHeader(title.toString(), titleTextColor));
                    mTitles++;
                }

                for (int j = 0; j < subMenu.size(); j++) {
                    MenuItem subItem = subMenu.getItem(j);
                    if (subItem.isVisible()) {
                        items.add(new BottomSheetMenuItem(subItem, itemTextColor,
                                itemBackground, tintColor));
                        addedSubMenu = true;
                    }
                }
            } else {
                items.add(new BottomSheetMenuItem(item, itemTextColor, itemBackground, tintColor));
            }
        }
    }

    return items;
}
 
Example 15
Source File: MenuSheetView.java    From ThreePhasesBottomSheet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * 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;
            }
        }
    }
}
 
Example 16
Source File: aa.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
boolean a(MenuItem menuitem)
{
    return !menuitem.hasSubMenu();
}
 
Example 17
Source File: ShareCompat.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
boolean shouldAddChooserIntent(MenuItem item) {
    return !item.hasSubMenu();
}
 
Example 18
Source File: ShareCompat.java    From letv with Apache License 2.0 4 votes vote down vote up
boolean shouldAddChooserIntent(MenuItem item) {
    return !item.hasSubMenu();
}
 
Example 19
Source File: MenuSheetView.java    From bottomsheet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * 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;
            }
        }
    }
}
 
Example 20
Source File: ShareCompat.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
boolean shouldAddChooserIntent(MenuItem item) {
    return !item.hasSubMenu();
}