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:de.kuschku.util.ui.MenuTint.java

/**
 * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the
 * OverflowMenuButton.</p>/*from  ww  w. ja  v  a 2 s .c o  m*/
 * <p>
 * <p>This should only be called after calling {@link #apply(Activity)}. It is useful for when
 * {@link MenuItem}s might be re-arranged due to an action view being collapsed or expanded.</p>
 */
public void reapply() {

    for (int i = 0, size = menu.size(); i < size; i++) {
        MenuItem item = menu.getItem(i);
        if (isActionButton(item)) {
            colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha);
        }
    }

    if (actionBarView == null) {
        return;
    }

    actionBarView.post(() -> {
        for (int i = 0, size = menu.size(); i < size; i++) {
            MenuItem menuItem = menu.getItem(i);
            if (isInOverflow(menuItem)) {
                colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha);
            } else {
                colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha);
            }
            if (menuItem.hasSubMenu()) {
                SubMenu subMenu = menuItem.getSubMenu();
                for (int j = 0; j < subMenu.size(); j++) {
                    colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha);
                }
            }
        }
        if (menuItemIconColor != null || menuItemIconAlpha != null) {
            colorOverflowMenuItem(overflowButton);
        }
    });
}

From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarTinter.java

/**
 * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the
 * OverflowMenuButton.</p>/*from ww w  .  j av a 2  s. c  om*/
 * <p>
 * <p>This should only be called after calling {@link #apply(Activity)}. It is useful for when
 * {@link MenuItem}s might be re-arranged due to an action view being collapsed or expanded.</p>
 */
public void reapply() {

    if (menu != null) {
        for (int i = 0, size = menu.size(); i < size; i++) {
            MenuItem item = menu.getItem(i);
            if (isActionButton(item)) {
                colorMenuItem(menu.getItem(i), iconsColor, iconsAlpha);
            }
        }
    }

    if (actionBarView == null) {
        return;
    }

    actionBarView.post(new Runnable() {

        @Override
        public void run() {
            if (menu != null) {
                for (int i = 0, size = menu.size(); i < size; i++) {
                    MenuItem menuItem = menu.getItem(i);
                    if (isInOverflow(menuItem)) {
                        colorMenuItem(menuItem, iconsColor, iconsAlpha);
                    } else {
                        colorMenuItem(menu.getItem(i), iconsColor, iconsAlpha);
                    }
                    if (menuItem.hasSubMenu()) {
                        SubMenu subMenu = menuItem.getSubMenu();
                        for (int j = 0; j < subMenu.size(); j++) {
                            colorMenuItem(subMenu.getItem(j), iconsColor, iconsAlpha);
                        }
                    }
                }
            }
            if (iconsColor != null || iconsAlpha != null) {
                colorOverflowMenuItem(overflowButton);
            }
        }

    });
}

From source file:paulscode.android.mupen64plusae.game.GameActivity.java

private void UpdateControllerMenu(int menuItemId, boolean isPlugged, int playerNumber) {
    final MenuItem pakGroupItem = mGameSidebar.getMenu().findItem(R.id.menuItem_paks);

    if (mGameSidebar.getMenu().findItem(menuItemId) != null) {
        if (!isPlugged) {
            pakGroupItem.getSubMenu().removeItem(menuItemId);
        } else {/*from w  w  w .  j  a v a 2 s  . com*/
            final MenuItem playerItem = mGameSidebar.getMenu().findItem(menuItemId);
            playerItem.setTitleCondensed(
                    this.getString(mGlobalPrefs.getPakType(playerNumber).getResourceString()));
        }
    }
}

From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java

/**
 * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the
 * OverflowMenuButton.</p>/*  w ww . j  a  v  a  2  s . com*/
 * <p/>
 * <p>This should only be called after calling {@link #apply(Activity)}. It is useful for when
 * {@link MenuItem}s might be re-arranged due to an action view being collapsed or expanded.</p>
 */
public void reapply() {

    for (int i = 0, size = menu.size(); i < size; i++) {
        MenuItem item = menu.getItem(i);
        if (isActionButton(item)) {
            colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha);
        }
    }

    if (actionBarView == null) {
        return;
    }

    actionBarView.post(new Runnable() {

        @Override
        public void run() {
            for (int i = 0, size = menu.size(); i < size; i++) {
                MenuItem menuItem = menu.getItem(i);
                if (isInOverflow(menuItem)) {
                    colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha);
                } else {
                    colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha);
                }
                if (menuItem.hasSubMenu()) {
                    SubMenu subMenu = menuItem.getSubMenu();
                    for (int j = 0; j < subMenu.size(); j++) {
                        colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha);
                    }
                }
            }
            if (menuItemIconColor != null || menuItemIconAlpha != null) {
                colorOverflowMenuItem(overflowButton);
            }
        }

    });
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Try to tint all {@link Menu}s {@link MenuItem}s with given color
 *///from  w  w w. ja  va  2 s.co  m
@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
        }
    }
}

From source file:net.evendanan.android.thumbremote.ui.RemoteUiActivity.java

@Override
public void addAnnouncedServers(ArrayList<ServerAddress> servers) {
    mServersMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override/* w w  w  .  j a  va 2s. c om*/
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getSubMenu().size() < 1) {
                scanForServersMenu();
            }
            return false;
        }
    });

    for (ServerAddress server : servers) {
        final String name = server.name() != null ? server.name() : server.address().getHostName();
        final String serverNameKey = server.type() + "@" + name;
        mServersMenu.getSubMenu().add(serverNameKey);
        mServersMenu.getSubMenu().getItem(mServersMenu.getSubMenu().size() - 1)
                .setOnMenuItemClickListener(new OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        ServerAddress server = mServers.get(item.getTitle());
                        if (server == null) {
                            return true;
                        }
                        RemoteApplication.getConfig().putServer(server, false);
                        rescanForServers();
                        return false;
                    }
                });
        mServers.put(serverNameKey, server);
    }
}

From source file:com.money.manager.ex.account.AccountTransactionListFragment.java

private void selectCurrentPeriod(Menu menu) {
    MenuItem item = menu.findItem(R.id.menu_period);
    if (item == null)
        return;/* www. j a va2 s  .c  om*/

    SubMenu subMenu = item.getSubMenu();

    // on init, mark the default item as checked
    AppSettings settings = new AppSettings(getActivity());
    DefinedDateRangeName rangeName = settings.getLookAndFeelSettings().getShowTransactions();
    if (rangeName == null)
        return;

    DefinedDateRanges ranges = new DefinedDateRanges(getActivity());
    DefinedDateRange range = ranges.get(rangeName);
    if (range == null)
        return;
    int id = range.menuResourceId;

    MenuItem itemToMark = subMenu.findItem(id);
    if (itemToMark == null)
        return;

    itemToMark.setChecked(true);
}

From source file:com.money.manager.ex.account.AccountTransactionListFragment.java

private void selectCurrentStatus(Menu menu) {
    MenuItem toolbarItem = menu.findItem(R.id.menuTransactionStatusSelector);
    if (toolbarItem == null)
        return;/*from w w w .  j  a v a 2s  .co m*/

    SubMenu subMenu = toolbarItem.getSubMenu();

    for (int i = 0; i < subMenu.size(); i++) {
        MenuItem subItem = subMenu.getItem(i);
        int menuId = subItem.getItemId();

        if (mFilter.transactionStatus.contains(menuId)) {
            subItem.setChecked(true);
        }
    }
}

From source file:org.cm.podd.report.activity.HomeActivity.java

private void updateRecordMenu() {
    Menu menu = navigationView.getMenu();
    MenuItem menuItem = menu.getItem(0);
    menuItem.getSubMenu().clear();

    int cnt = 0;//w w  w  .j a  va  2 s .  c om
    for (RecordSpec record : recordSpecDataSource.findRootRecords()) {
        menuItem.getSubMenu().add(0, (int) record.id, cnt, record.name);
        cnt++;
    }
    if (cnt == 0) {
        menuItem.setVisible(false);
    } else {
        menuItem.setVisible(true);
    }

    navigationView.invalidate();
    mDrawerLayout.invalidate();

}

From source file:com.ruesga.rview.MainActivity.java

private void updateAccountCustomFilters() {
    // Remove all custom filters and re-add them
    final DrawerNavigationMenu menu = (DrawerNavigationMenu) mBinding.drawerNavigationView.getMenu();
    int myFiltersGroupIndex = menu.findGroupIndex(R.id.category_my_filters);
    MenuItem group = menu.getItem(myFiltersGroupIndex);
    SubMenu myFiltersSubMenu = group.getSubMenu();
    int count = myFiltersSubMenu.size() - 1;
    for (int i = count; i >= 0; i--) {
        ((DrawerNavigationSubMenu) myFiltersSubMenu).removeItemAt(i);
    }//w  ww.  j a v a  2  s  .co  m

    mCustomFilters = Preferences.getAccountCustomFilters(this, mAccount);
    if (mCustomFilters != null) {
        int i = 0;
        for (CustomFilter filter : mCustomFilters) {
            int id = MY_FILTERS_GROUP_BASE_ID + i;
            String title = filter.mName + DrawerNavigationView.SEPARATOR + filter.mQuery.toString()
                    + DrawerNavigationView.SEPARATOR + "ic_close";
            MenuItem item = myFiltersSubMenu.add(group.getGroupId(), id, Menu.NONE, title);
            item.setIcon(R.drawable.ic_filter);
            item.setCheckable(true);
            i++;
        }
    }

    menu.setGroupVisible(R.id.category_my_filters,
            !mModel.isAccountExpanded && mCustomFilters != null && !mCustomFilters.isEmpty());
    mBinding.drawerNavigationView.setCheckedItem(mModel.currentNavigationItemId);
}