Example usage for android.view MenuItem hasSubMenu

List of usage examples for android.view MenuItem hasSubMenu

Introduction

In this page you can find the example usage for android.view MenuItem hasSubMenu.

Prototype

public boolean hasSubMenu();

Source Link

Document

Check whether this item has an associated sub-menu.

Usage

From source file:org.tasks.ui.MenuColorizer.java

/** Sets a color filter on all menu icons, including the overflow button (if it exists) */
private static void colorMenu(final Menu menu, final int color) {
    for (int i = 0, size = menu.size(); i < size; i++) {
        final MenuItem menuItem = menu.getItem(i);
        colorMenuItem(menuItem, color);//from  w w w.j  av  a2 s  . c  o  m
        if (menuItem.hasSubMenu()) {
            final SubMenu subMenu = menuItem.getSubMenu();
            for (int j = 0; j < subMenu.size(); j++) {
                colorMenuItem(subMenu.getItem(j), color);
            }
        }
    }
}

From source file:me.henrytao.mdcore.core.MdCompat.java

public static void supportDrawableTint(Context context, MenuItem menuItem, Palette palette) {
    if (menuItem != null) {
        menuItem.setIcon(MdCompat.supportDrawableTint(context, menuItem.getIcon(), Palette.PRIMARY));
        if (menuItem.hasSubMenu()) {
            supportDrawableTint(context, menuItem.getSubMenu(), palette);
        }//  ww w . java  2s. co m
    }
}

From source file:de.vanita5.twittnuker.activity.support.MenuDialogFragment.java

@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    final Fragment parentFragment = getParentFragment();
    final MenuItem item = (MenuItem) parent.getItemAtPosition(position);
    if (item.hasSubMenu()) {

    } else if (parentFragment instanceof OnMenuItemClickListener) {
        ((OnMenuItemClickListener) parentFragment).onMenuItemClick(item);
        dismiss();/*from   ww  w  . j  a  v a2 s  .co m*/
    }
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void wrapMenuIcon(@NonNull Menu menu, int itemColor, int subItemColor, int... excludeGroups) {
    for (int i = 0, j = menu.size(); i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(item.getSubMenu(), subItemColor, subItemColor, excludeGroups);
        }/*from   w ww .  j a va 2  s  .com*/
    }
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void wrapMenuIcon(ActionMenuView view, int... excludeGroups) {
    final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext());
    final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(),
            view.getPopupTheme());//from w w w. ja v a  2s .  c  o  m
    final Resources resources = view.getResources();
    final int colorDark = resources.getColor(R.color.action_icon_dark);
    final int colorLight = resources.getColor(R.color.action_icon_light);
    final int itemColor = ColorUtils.getContrastYIQ(itemBackgroundColor, colorDark, colorLight);
    final int popupItemColor = ColorUtils.getContrastYIQ(popupItemBackgroundColor, colorDark, colorLight);
    final Menu menu = view.getMenu();
    final int childCount = view.getChildCount();
    for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
        }
        if (item.isVisible()) {
            k++;
        }
    }

}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static void wrapMenuIcon(Context context, int backgroundColor, int popupBackgroundColor, Menu menu,
        int... excludeGroups) {
    final Resources resources = context.getResources();
    final int colorDark = resources.getColor(R.color.action_icon_dark);
    final int colorLight = resources.getColor(R.color.action_icon_light);
    final int itemColor = ColorUtils.getContrastYIQ(backgroundColor, colorDark, colorLight);
    final int popupItemColor = ColorUtils.getContrastYIQ(popupBackgroundColor, colorDark, colorLight);
    for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
        }//from  w  w w .  j a  v a2s . c o m
        if (item.isVisible()) {
            k++;
        }
    }
}

From source file:org.getlantern.firetweet.util.ThemeUtils.java

public static void wrapMenuIcon(ActionMenuView view, int... excludeGroups) {
    final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext());
    final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(),
            view.getPopupTheme());/*from  ww  w .j  av a2  s.c  om*/
    final Resources resources = view.getResources();
    final int colorDark = resources.getColor(R.color.action_icon_dark);
    final int colorLight = resources.getColor(R.color.action_icon_light);
    final int itemColor = ColorUtils.getContrastYIQ(itemBackgroundColor, colorDark, colorLight);
    final int popupItemColor = ColorUtils.getContrastYIQ(popupItemBackgroundColor, colorDark, colorLight);
    final Menu menu = view.getMenu();
    final int childCount = view.getChildCount();
    for (int i = 0, j = menu.size(), k = 0; i < j; i++) {
        final MenuItem item = menu.getItem(i);
        wrapMenuItemIcon(item, itemColor, excludeGroups);
        if (item.hasSubMenu()) {
            wrapMenuIcon(menu, popupItemColor, popupItemColor, excludeGroups);
        }
        if (item.isVisible()) {
            k++;
        }
    }
}

From source file:com.github.rubensousa.bottomsheetbuilder.adapter.BottomSheetAdapterBuilder.java

private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor, int itemTextColor,
        int itemBackground, int tintColor) {
    List<BottomSheetItem> items = new ArrayList<>();

    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");
                    }//  ww w .  j  a va 2 s. com
                    items.add(new BottomSheetDivider(dividerBackground));
                }

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

                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;
}

From source file:com.android.screenspeak.contextmenu.ListMenuManager.java

@Override
public boolean showMenu(int menuId) {
    mLastUtterance = mService.getSpeechController().getLastUtterance();
    dismissAll();// ww  w.ja v  a2s .com

    // Some ScreenSpeak tutorial modules don't allow context menus.
    if (AccessibilityTutorialActivity.isTutorialActive()
            && !AccessibilityTutorialActivity.shouldAllowContextMenus()) {
        return false;
    }

    mService.saveFocusedNode();
    final ListMenu menu = new ListMenu(mService);
    menu.setDefaultListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.hasSubMenu()) {
                CharSequence[] items = getItemsFromMenu(item.getSubMenu());
                ListMenu menu = (ListMenu) item.getSubMenu();
                showDialogMenu(menu.getTitle(), items, menu);
            } else if (item.getItemId() == R.id.spell_last_utterance) {
                AccessibilityNodeInfo node = mService.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY);
                if (node != null) {
                    AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(node);
                    CharSequence text = NodeSpeechRuleProcessor.getInstance().getDescriptionForNode(compat,
                            null);
                    compat.recycle();
                    mService.getSpeechController().spellUtterance(text);
                }
            } else if (item.getItemId() == R.id.repeat_last_utterance) {
                mService.getSpeechController().interrupt();
                mService.getSpeechController().repeatUtterance(mLastUtterance);
            } else {
                mMenuClickProcessor.onMenuItemClicked(item);
            }

            return true;
        }
    });

    ListMenuPreparer menuPreparer = new ListMenuPreparer(mService);
    menuPreparer.prepareMenu(menu, menuId);
    showDialogMenu(menu.getTitle(), getItemsFromMenu(menu), menu);
    return false;
}

From source file:com.android.talkback.contextmenu.ListMenuManager.java

@Override
public boolean showMenu(int menuId) {
    mLastUtterance = mService.getSpeechController().getLastUtterance();
    dismissAll();/*  w ww .ja v a 2s  . co m*/

    // Some TalkBack tutorial modules don't allow context menus.
    if (AccessibilityTutorialActivity.isTutorialActive()
            && !AccessibilityTutorialActivity.shouldAllowContextMenus()) {
        return false;
    }

    mService.saveFocusedNode();
    final ListMenu menu = new ListMenu(mService);
    menu.setDefaultListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.hasSubMenu()) {
                CharSequence[] items = getItemsFromMenu(item.getSubMenu());
                ListMenu menu = (ListMenu) item.getSubMenu();
                showDialogMenu(menu.getTitle(), items, menu);
            } else if (item.getItemId() == R.id.spell_last_utterance) {
                AccessibilityNodeInfo node = mService.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY);
                if (node != null) {
                    AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(node);
                    CharSequence text = NodeSpeechRuleProcessor.getInstance().getDescriptionForNode(compat,
                            null);
                    compat.recycle();
                    mService.getSpeechController().spellUtterance(text);
                }
            } else if (item.getItemId() == R.id.repeat_last_utterance) {
                mService.getSpeechController().interrupt();
                mService.getSpeechController().repeatUtterance(mLastUtterance);
            } else {
                mMenuClickProcessor.onMenuItemClicked(item);
            }

            return true;
        }
    });

    ListMenuPreparer menuPreparer = new ListMenuPreparer(mService);
    menuPreparer.prepareMenu(menu, menuId);
    showDialogMenu(menu.getTitle(), getItemsFromMenu(menu), menu);
    return false;
}