Example usage for android.view SubMenu add

List of usage examples for android.view SubMenu add

Introduction

In this page you can find the example usage for android.view SubMenu add.

Prototype

public MenuItem add(int groupId, int itemId, int order, CharSequence title);

Source Link

Document

Add a new item to the menu.

Usage

From source file:com.yacorso.nowaste.views.activities.DrawerActivity.java

private void loadNavItems() {
    int index = 0;
    Menu navigationMenu = navigationView.getMenu();
    navigationMenu.clear();/* w ww  . java 2 s.c om*/
    navigationItems.clear();

    SubMenu fridgeSection = navigationMenu.addSubMenu(getText(R.string.menu_section_fridges));
    List<Fridge> fridges = currentUser.getFridges();
    for (Fridge fridge : fridges) {
        navigationItems.put(index, fridge);
        fridgeSection.add(0, index++, 0, fridge.getName()).setIcon(R.drawable.ic_fridge);
    }

    SubMenu customListSection = navigationMenu.addSubMenu(getText(R.string.menu_section_custom_lists));
    List<CustomList> customLists = currentUser.getCustomLists();

    for (CustomList customList : customLists) {
        navigationItems.put(index, customList);
        customListSection.add(1, index++, 0, customList.getName()).setIcon(R.drawable.ic_folder);
    }

    navigationMenu.add(2, index++, 0, R.string.menu_add_foodlist).setIcon(R.drawable.ic_add_circle_white);
    navigationMenu.add(3, index, 0, R.string.menu_title_settings).setIcon(R.drawable.ic_setting_dark);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.getGroupId() < 2) {
                changeFragment(menuItem.getItemId(), true);
            } else if (menuItem.getGroupId() == 2) {
                launchDialog(ChooseTypeFoodListDialog.newInstance());
            } else if (menuItem.getGroupId() == 3) {
                changeFragment(menuItem.getItemId(), false);
            }

            return true;
        }
    });

    mDrawerLayout.post(new Runnable() {
        @Override
        public void run() {
            mDrawerToggle.syncState();
        }
    });
}

From source file:com.mifos.mifosxdroid.online.LoanAccountSummaryFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();/* w  w w  .ja  v  a2 s  .co  m*/
    menu.addSubMenu(Menu.NONE, MENU_ITEM_DATA_TABLES, Menu.NONE, Constants.DATA_TABLE_LOAN_NAME);
    menu.add(Menu.NONE, MENU_ITEM_LOAN_TRANSACTIONS, Menu.NONE,
            getResources().getString(R.string.transactions));
    menu.add(Menu.NONE, MENU_ITEM_REPAYMENT_SCHEDULE, Menu.NONE,
            getResources().getString(R.string.loan_repayment_schedule));
    menu.add(Menu.NONE, MENU_ITEM_DOCUMENTS, Menu.NONE, getResources().getString(R.string.documents));
    menu.add(Menu.NONE, MENU_ITEM_CHARGES, Menu.NONE, getResources().getString(R.string.charges));

    int SUBMENU_ITEM_ID = 0;

    // Create a Sub Menu that holds a link to all data tables
    SubMenu dataTableSubMenu = menu.getItem(1).getSubMenu();
    if (dataTableSubMenu != null && loanDataTables != null && loanDataTables.size() > 0) {
        Iterator<DataTable> dataTableIterator = loanDataTables.iterator();
        while (dataTableIterator.hasNext()) {
            dataTableSubMenu.add(Menu.NONE, SUBMENU_ITEM_ID, Menu.NONE,
                    dataTableIterator.next().getRegisteredTableName());
            SUBMENU_ITEM_ID++;
        }
    }
    super.onPrepareOptionsMenu(menu);
}

From source file:org.alfresco.mobile.android.application.fragments.actions.NodeIdActions.java

protected void getMenu(FragmentActivity activity, Menu menu) {
    SubMenu createMenu;

    // SYNC/* w  ww .ja  va  2s.  co m*/
    if (SyncContentManager.getInstance(getActivity()).hasActivateSync(getAccount())) {
        createMenu = menu.addSubMenu(Menu.NONE, R.id.menu_action_sync_group, Menu.FIRST, R.string.sync);
        createMenu.setIcon(R.drawable.ic_sync_light);
        createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        hideActionIfNecessary(menu, createMenu.getItem().getItemId(),
                ConfigurableActionHelper.ACTION_NODE_SYNC);

        createMenu.add(Menu.NONE, R.id.menu_action_sync_group_sync, Menu.FIRST + 1, R.string.sync);
        createMenu.add(Menu.NONE, R.id.menu_action_sync_group_unsync, Menu.FIRST + 2, R.string.unsync);
    }

    // FAVORITES
    createMenu = menu.addSubMenu(Menu.NONE, R.id.menu_action_favorite_group, Menu.FIRST + 2, R.string.favorite);
    createMenu.setIcon(R.drawable.ic_favorite_light);
    createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    hideActionIfNecessary(menu, createMenu.getItem().getItemId(),
            ConfigurableActionHelper.ACTION_NODE_FAVORITE);

    createMenu.add(Menu.NONE, R.id.menu_action_favorite_group_favorite, Menu.FIRST + 1, R.string.favorite);
    createMenu.add(Menu.NONE, R.id.menu_action_favorite_group_unfavorite, Menu.FIRST + 2, R.string.unfavorite);

    // LIKE
    AlfrescoSession alfSession = SessionUtils.getSession(activity);
    if (alfSession != null && alfSession.getRepositoryInfo() != null
            && alfSession.getRepositoryInfo().getCapabilities() != null
            && alfSession.getRepositoryInfo().getCapabilities().doesSupportLikingNodes()) {
        createMenu = menu.addSubMenu(Menu.NONE, R.id.menu_action_like_group, Menu.FIRST + 3, R.string.like);
        createMenu.setIcon(R.drawable.ic_like);
        createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        hideActionIfNecessary(menu, createMenu.getItem().getItemId(),
                ConfigurableActionHelper.ACTION_NODE_LIKE);

        createMenu.add(Menu.NONE, R.id.menu_action_like_group_like, Menu.FIRST + 1, R.string.like);
        createMenu.add(Menu.NONE, R.id.menu_action_like_group_unlike, Menu.FIRST + 2, R.string.unlike);
    }
}

From source file:th.in.ffc.person.visit.VisitDiagActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.edit_activity, menu);
    String[] diagType = getResources().getStringArray(R.array.diag_DX);
    SubMenu sub = menu.addSubMenu(R.string.add);
    sub.add(0, 2, 0, diagType[2]);
    sub.add(0, 4, 0, diagType[4]);/*from  w w  w.  j a v  a  2 s .co  m*/
    sub.add(0, 5, 0, diagType[5]);
    sub.setIcon(R.drawable.ic_action_add);
    sub.getItem().setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
    return true;
}

From source file:com.cyanogenmod.effem.FmRadio.java

/**
 * Sets up the options menu when the menu button is pushed, dynamic
 * population of the station select menu
 *///w  w w.ja  va2s .c  o m
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    boolean result = super.onCreateOptionsMenu(menu);

    // Create and populate the band selection menu
    SubMenu subMenu = menu.addSubMenu(BASE_OPTION_MENU, FM_BAND, Menu.NONE, R.string.band_select);
    subMenu.setIcon(android.R.drawable.ic_menu_mapmode);
    subMenu.add(BAND_SELECTION_MENU, BAND_US, Menu.NONE, R.string.band_us);
    subMenu.add(BAND_SELECTION_MENU, BAND_EU, Menu.NONE, R.string.band_eu);
    subMenu.add(BAND_SELECTION_MENU, BAND_JAPAN, Menu.NONE, R.string.band_ja);
    subMenu.add(BAND_SELECTION_MENU, BAND_CHINA, Menu.NONE, R.string.band_ch);
    subMenu.setGroupCheckable(BAND_SELECTION_MENU, true, true);
    subMenu.getItem(mSelectedBand).setChecked(true);

    // Create and populate the speaker/headset selection menu if speaker supported
    if (context.getResources().getBoolean(R.bool.speaker_supported)) {
        subMenu = menu.addSubMenu(BASE_OPTION_MENU, OUTPUT_SOUND, Menu.NONE, R.string.output_select);
        subMenu.setIcon(android.R.drawable.ic_menu_mapmode);
        subMenu.add(LOUDSPEAKER_SELECTION_MENU, OUTPUT_HEADSET, Menu.NONE, R.string.output_select_default);
        subMenu.add(LOUDSPEAKER_SELECTION_MENU, OUTPUT_SPEAKER, Menu.NONE, R.string.output_select_loudspeaker);
        subMenu.setGroupCheckable(LOUDSPEAKER_SELECTION_MENU, true, true);
        subMenu.getItem(mSelectedOutput).setChecked(true);
    }

    // Create the station select menu
    subMenu = menu.addSubMenu(BASE_OPTION_MENU, STATION_SELECT, Menu.NONE, R.string.station_select);
    subMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    // Dynamically populate the station select menu
    if (mMenuAdapter.isEmpty()) {
        subMenu.setGroupEnabled(STATION_SELECTION_MENU, false);
    } else {
        subMenu.setGroupEnabled(STATION_SELECTION_MENU, true);
        for (int i = 0; i < mMenuAdapter.getCount(); i++) {
            subMenu.add(STATION_SELECTION_MENU, STATION_SELECT_MENU_ITEMS + i, Menu.NONE,
                    mMenuAdapter.getItem(i).toString());
        }
    }
    return result;
}

From source file:com.github.kanata3249.ffxieq.android.FoodSelectorActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item;/*  w  ww.ja v a  2  s.c  o  m*/

    FoodListView flv;

    item = menu.findItem(R.id.FilterByType);
    SubMenu submenu = item.getSubMenu();
    submenu.removeGroup(R.id.FilterByType);

    flv = (FoodListView) findViewById(R.id.ListView);
    if (flv != null) {
        String types[] = flv.getAvailableFoodTypes();

        if (types == null || types.length == 1) {
            item.setEnabled(false);
        } else {
            item.setEnabled(true);
            submenu.add(R.id.FilterByType, -1, Menu.NONE, getString(R.string.ResetFilterByType));
            for (int i = 0; i < types.length; i++) {
                submenu.add(R.id.FilterByType, i, Menu.NONE, types[i]);
            }
        }

    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

/**
 * Fills out the given submenu with items for "new playlist" and
 * any existing playlists. When the user selects an item, the
 * application will receive PLAYLIST_SELECTED with the Uri of
 * the selected playlist, NEW_PLAYLIST if a new playlist
 * should be created, and QUEUE if the "current playlist" was
 * selected.//from   w w w .  j av  a 2 s . c  om
 *
 * @param context The context to use for creating the menu items
 * @param sub     The submenu to add the items to.
 */
public static void makePlaylistMenu(Context context, SubMenu sub) {
    String[] cols = new String[] { MediaStore.Audio.Playlists._ID, MediaStore.Audio.Playlists.NAME };
    ContentResolver resolver = context.getContentResolver();
    if (resolver == null) {
        System.out.println("resolver = null");
    } else {
        String whereclause = MediaStore.Audio.Playlists.NAME + " != ''";
        Cursor cur = resolver.query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, cols, whereclause, null,
                MediaStore.Audio.Playlists.NAME);
        sub.clear();
        sub.add(1, Defs.QUEUE, 0, R.string.queue);
        sub.add(1, Defs.NEW_PLAYLIST, 0, R.string.new_playlist);
        if (cur != null && cur.getCount() > 0) {
            //sub.addSeparator(1, 0);
            cur.moveToFirst();
            while (!cur.isAfterLast()) {
                Intent intent = new Intent();
                intent.putExtra("playlist", cur.getLong(0));
                //                    if (cur.getInt(0) == mLastPlaylistSelected) {
                //                        sub.add(0, MusicBaseActivity.PLAYLIST_SELECTED, cur.getString(1)).setIntent(intent);
                //                    } else {
                sub.add(1, Defs.PLAYLIST_SELECTED, 0, cur.getString(1)).setIntent(intent);
                //                    }
                cur.moveToNext();
            }
        }
        if (cur != null) {
            cur.close();
        }
    }
}

From source file:com.mifos.mifosxdroid.online.SavingsAccountSummaryFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();//from  w  ww.  ja v a 2 s.c  o  m
    menu.addSubMenu(Menu.NONE, MENU_ITEM_DATA_TABLES, Menu.NONE, Constants.DATA_TABLE_SAVINGS_ACCOUNTS_NAME);
    menu.add(Menu.NONE, MENU_ITEM_DOCUMENTS, Menu.NONE, getResources().getString(R.string.documents));

    // This is the ID of Each data table which will be used in onOptionsItemSelected Method
    int SUBMENU_ITEM_ID = 0;
    // Create a Sub Menu that holds a link to all data tables
    SubMenu dataTableSubMenu = menu.getItem(1).getSubMenu();
    if (dataTableSubMenu != null && savingsAccountDataTables != null && savingsAccountDataTables.size() > 0) {
        Iterator<DataTable> dataTableIterator = savingsAccountDataTables.iterator();
        while (dataTableIterator.hasNext()) {
            dataTableSubMenu.add(Menu.NONE, SUBMENU_ITEM_ID, Menu.NONE,
                    dataTableIterator.next().getRegisteredTableName());
            SUBMENU_ITEM_ID++;
        }
    }
    super.onPrepareOptionsMenu(menu);
}

From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java

private void updateAccounts() {
    final Menu menu = binding.navigation.getMenu();
    final MenuItem libraries = menu.findItem(R.id.nav_libraries);
    final SubMenu subMenu = libraries.getSubMenu();

    while (subMenu.size() > 0) {
        subMenu.removeItem(subMenu.getItem(0).getItemId());
    }//from  w w w . ja v a  2  s  . com

    final List<Account> accounts = getServer().getAccounts();
    for (int index = 0; index < accounts.size(); index++) {
        final Account account = accounts.get(index);
        final MenuItem menuItem = subMenu.add(R.id.navigation, index, Menu.NONE, account.getDisplayName());
        if (account.getId().equals("local")) {
            menuItem.setIcon(R.drawable.ic_folder_24dp);
        } else {
            menuItem.setIcon(R.drawable.ic_cloud_24dp);
        }
        menuItem.setCheckable(true);
    }

    final MenuItem menuItem = subMenu.add(R.id.navigation, R.id.nav_addaccount, Menu.NONE,
            R.string.nav_addaccount);
    menuItem.setIcon(R.drawable.ic_add_24dp);

    for (int i = 0, count = binding.navigation.getChildCount(); i < count; i++) {
        final View child = binding.navigation.getChildAt(i);
        if (child != null && child instanceof ListView) {
            final ListView menuView = (ListView) child;
            final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
            final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
            wrapped.notifyDataSetChanged();
        }
    }

    getServer().loadRecent(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem recent = menu.findItem(R.id.nav_recent);
            if (recent != null) {
                recent.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
    getServer().loadStarred(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem starred = menu.findItem(R.id.nav_starred);
            if (starred != null) {
                starred.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
}

From source file:in.andres.kandroid.ui.MainActivity.java

private void populateProjectsMenu() {
    if (mProjectList == null) {
        if (BuildConfig.DEBUG)
            Log.d("Kandroid", "Tried to populate drawer, but mDashboard was null");
        return;//  ww w . ja  va  2  s.  co m
    }
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getBaseContext());
    List<KanboardProject> projList = mProjectList;
    if (preferences.getBoolean("projects_sort_alphabetic", false))
        Collections.sort(projList);
    NavigationView nav = (NavigationView) findViewById(R.id.nav_view);
    SubMenu projMenu = nav.getMenu().findItem(R.id.projects).getSubMenu();
    projMenu.clear();
    for (KanboardProject item : projList)
        projMenu.add(Menu.NONE, item.getId(), Menu.NONE, item.getName()).setIcon(R.drawable.project);
}