Example usage for android.view MenuItem getSubMenu

List of usage examples for android.view MenuItem getSubMenu

Introduction

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

Prototype

public SubMenu getSubMenu();

Source Link

Document

Get the sub-menu to be invoked when this item is selected, if it has one.

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 a va  2  s .co  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);
        }/*  w  ww  .  j  a  v  a 2s .c  om*/
    }
}

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);
        }// w  w w .  j  a v  a  2  s  . c  o  m
    }
}

From source file:task.application.com.colette.navigation.AppNavigationViewAsDrawerImpl.java

private void applyFontToSubMenu(MenuItem item) {
    SubMenu subMenu = item.getSubMenu();
    if (subMenu != null && subMenu.size() > 0) {
        for (int i = 0; i < subMenu.size(); i++) {
            MenuItem subMenuItem = subMenu.getItem(i);
            applyFontToMenuItem(subMenuItem);
        }/*w  w  w. j  a v  a2  s  . com*/
    }
}

From source file:org.jboss.demo.loanmanagement.StatusesScreen.java

/**
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
 *//*from   ww  w .j a  v a2s  .  com*/
@Override
public boolean onCreateOptionsMenu(final Menu optionsMenu) {
    getMenuInflater().inflate(R.menu.statuses_screen_menu, optionsMenu);

    final MenuItem sortItem = optionsMenu.findItem(R.id.menu_sort);
    final SubMenu sortMenu = sortItem.getSubMenu();

    // find out which sort to turn on
    final String sorterId = this.adapter.getSorterId();

    if (Prefs.SORT_BY_NAME.equals(sorterId)) {
        final MenuItem item = sortMenu.findItem(R.id.action_sort_by_name);
        item.setChecked(true);
    } else if (Prefs.SORT_BY_SSN.equals(sorterId)) {
        final MenuItem item = sortMenu.findItem(R.id.action_sort_by_ssn);
        item.setChecked(true);
    } else if (Prefs.SORT_BY_RATE.equals(sorterId)) {
        final MenuItem item = sortMenu.findItem(R.id.action_sort_by_rate);
        item.setChecked(true);
    } else {
        final MenuItem item = sortMenu.findItem(R.id.action_sort_by_status);
        item.setChecked(true);
    }

    return true; // show menu and action bar items
}

From source file:org.randoomz.learnit.ui.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    subscribe = db.createQuery(Language.TABLE, Language.ALL_QUERY).map(Language.MAP)
            .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<List<Language>>() {
                @Override//from   w  w  w. j  a va 2 s. com
                public void call(List<Language> languages) {
                    MainActivity.this.languages = languages;
                    final MenuItem item = navigationView.getMenu().findItem(R.id.languages);
                    final SubMenu subMenuLanguages = item.getSubMenu();
                    subMenuLanguages.clear();
                    for (int i = 0; i < languages.size(); i++) {
                        subMenuLanguages.add(Menu.NONE, i, i, languages.get(i).language()).setCheckable(true);
                    }
                    onNavigationItemSelected(subMenuLanguages.getItem(currentPosition));
                }
            });
}

From source file:org.jboss.demo.loanmanagement.EvaluationsScreen.java

/**
 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
 *///from  w  ww.  ja  v  a2  s . c om
@Override
public boolean onCreateOptionsMenu(final Menu optionsMenu) {
    getMenuInflater().inflate(R.menu.evaluations_screen_menu, optionsMenu);

    final MenuItem sortItem = optionsMenu.findItem(R.id.menu_sort);
    final SubMenu sortMenu = sortItem.getSubMenu();

    // find out which sort to turn on
    final String sorterId = this.adapter.getSorterId();

    if (Prefs.SORT_BY_NAME.equals(sorterId)) {
        final MenuItem sortByNameItem = sortMenu.findItem(R.id.action_sort_by_name);
        sortByNameItem.setChecked(true);
    } else if (Prefs.SORT_BY_NAME.equals(sorterId)) {
        final MenuItem sortBySsnItem = sortMenu.findItem(R.id.action_sort_by_ssn);
        sortBySsnItem.setChecked(true);
    } else {
        final MenuItem sortByDateItem = sortMenu.findItem(R.id.action_sort_by_date);
        sortByDateItem.setChecked(true);
    }

    return true; // show menu and action bar items
}

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");
                    }//from  w  ww.  ja v a  2 s .  c  o  m
                    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:org.mariotaku.twidere.util.ThemeUtils.java

public static void wrapToolbarMenuIcon(@Nullable ActionMenuView view, int itemColor, int popupItemColor,
        int... excludeGroups) {
    if (view == null)
        return;/*from   ww  w  . j  a  v a 2  s .c om*/
    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(item.getSubMenu(), popupItemColor, popupItemColor, excludeGroups);
        }
        if (item.isVisible()) {
            k++;
        }
    }
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void wrapMenuIcon(ActionMenuView view, int colorDark, int colorLight, int... excludeGroups) {
    final int itemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext());
    final int popupItemBackgroundColor = ThemeUtils.getThemeBackgroundColor(view.getContext(),
            view.getPopupTheme());/*w w  w  . ja  v  a 2 s. c o  m*/
    final int itemColor = TwidereColorUtils.getContrastYIQ(itemBackgroundColor, colorDark, colorLight);
    final int popupItemColor = TwidereColorUtils.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(item.getSubMenu(), popupItemColor, popupItemColor, excludeGroups);
        }
        if (item.isVisible()) {
            k++;
        }
    }
}