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.github.kanata3249.ffxieq.android.EquipmentSelectorActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item;//  ww w .  j av  a 2s .co m

    item = menu.findItem(R.id.OrderByName);
    if (item != null) {
        if (mOrderByName)
            item.setTitle(getString(R.string.OrderByLevel));
        else
            item.setTitle(getString(R.string.OrderByName));
    }

    EquipmentListView elv;

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

    elv = (EquipmentListView) findViewById(R.id.ListView);
    if (elv != null) {
        String types[] = elv.getAvailableWeaponTypes();

        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:com.github.kanata3249.ffxieq.android.AugmentSelectorActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item;//from ww  w . j a v  a2s. c  o  m

    item = menu.findItem(R.id.OrderByName);
    if (item != null) {
        if (mOrderByName)
            item.setTitle(getString(R.string.OrderByLevel));
        else
            item.setTitle(getString(R.string.OrderByName));
    }

    AugmentListView lv;

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

    lv = (AugmentListView) findViewById(R.id.ListView);
    if (lv != null) {
        String types[] = lv.getAvailableWeaponTypes();

        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:org.akvo.flow.activity.SurveyActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.survey_activity, menu);
    SubMenu subMenu = menu.findItem(R.id.more_submenu).getSubMenu();
    if (isReadOnly()) {
        subMenu.removeItem(R.id.clear);//from w ww. ja  va  2  s.com
    } else if (mSurveyGroup.isMonitored()) {
        // Add 'pre-fill' option, if applies
        if (mDatabase.getLastSurveyInstance(mRecordId, mSurvey.getId()) != null) {
            subMenu.add(Menu.NONE, MENU_PREFILL, Menu.NONE, R.string.prefill_title);
        }
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:android.support.v7.widget.ShareActionProvider.java

/**
 * {@inheritDoc}/*ww w.ja  va  2  s .c  om*/
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();

    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);

    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager))
                .setOnMenuItemClickListener(mOnMenuItemClickListener);
    }

    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount,
                mContext.getString(R.string.abc_activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
                    .setIcon(activity.loadIcon(packageManager))
                    .setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}

From source file:com.example.FilteredShareActionProvider.java

/**
 * {@inheritDoc}/*from   w w w  . java 2  s. c om*/
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    FilteredActivityChooserModel dataModel = FilteredActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();

    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);

    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager))
                .setOnMenuItemClickListener(mOnMenuItemClickListener);
    }

    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount,
                mContext.getString(R.string.abc_activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
                    .setIcon(activity.loadIcon(packageManager))
                    .setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}

From source file:fr.rolandl.smartshareactionprovider.SmartShareActionProvider.java

/**
 * {@inheritDoc}//from  www .jav a  2s.c o m
 */
@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    // Clear since the order of items may change.
    subMenu.clear();

    SmartActivityChooserModel dataModel = SmartActivityChooserModel.get(mContext, mShareHistoryFileName);
    PackageManager packageManager = mContext.getPackageManager();

    final int expandedActivityCount = dataModel.getActivityCount();
    final int collapsedActivityCount = Math.min(expandedActivityCount, mMaxShownActivityCount);

    // Populate the sub-menu with a sub set of the activities.
    for (int i = 0; i < collapsedActivityCount; i++) {
        ResolveInfo activity = dataModel.getActivity(i);
        subMenu.add(0, i, i, activity.loadLabel(packageManager)).setIcon(activity.loadIcon(packageManager))
                .setOnMenuItemClickListener(mOnMenuItemClickListener);
    }

    if (collapsedActivityCount < expandedActivityCount) {
        // Add a sub-menu for showing all activities as a list item.
        SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount, collapsedActivityCount,
                mContext.getString(R.string.abc_activity_chooser_view_see_all));
        for (int i = 0; i < expandedActivityCount; i++) {
            ResolveInfo activity = dataModel.getActivity(i);
            expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
                    .setIcon(activity.loadIcon(packageManager))
                    .setOnMenuItemClickListener(mOnMenuItemClickListener);
        }
    }
}

From source file:com.ushahidi.android.presentation.view.ui.activity.PostActivity.java

private void setNavigationViewMenuItems(@NonNull Menu menu) {
    // Reset menu items to avoid duplicates because we reinitialize them
    menu.clear();/*from  w  w  w  .  java2  s.c om*/
    if (!Utility.isCollectionEmpty(mDeploymentModelList)) {
        SubMenu subMenu = menu.addSubMenu(Menu.NONE, Menu.FIRST, Menu.NONE, R.string.deployments);
        subMenu.setGroupCheckable(DEPLOYMENTS_MENU_ITEMS_GROUP_ID, true, true);
        // Use item position as the menu item's id that way we can retrieve the individual
        // deployment when user clicks on it to make it the active deployment
        for (int pos = 0; pos < mDeploymentModelList.size(); pos++) {
            subMenu.add(DEPLOYMENTS_MENU_ITEMS_GROUP_ID, pos, pos, mDeploymentModelList.get(pos).getTitle())
                    .setIcon(R.drawable.ic_action_globe);
            if (mDeploymentModelList.get(pos).getStatus().equals(DeploymentModel.Status.ACTIVATED)) {
                mNavigationView.getMenu().findItem(pos).setChecked(true);
                mToolbar.setTitle(mNavigationView.getMenu().findItem(pos).getTitle());
            } else {
                mNavigationView.getMenu().findItem(pos).setChecked(false);
            }
        }
    }

    mSubMenuMisc = menu.addSubMenu(Menu.NONE, Menu.FIRST, Menu.NONE, R.string.actions);

    mSubMenuMisc.add(MISC_MENU_ITEMS, MANAGE_DEPLOYMENT_MENU_ID, 1, R.string.manage_deployments)
            .setIcon(R.drawable.ic_action_map);

    mSubMenuMisc.add(MISC_MENU_ITEMS, FEEDBACK_MENU_ID, 2, R.string.send_feedback)
            .setIcon(R.drawable.ic_action_help);
    mSubMenuMisc.add(MISC_MENU_ITEMS, ABOUT_MENU_ID, 3, R.string.about).setIcon(R.drawable.ic_action_info);

    if (mSessionManager.getActiveSession() != null) {
        mSubMenuMisc.add(MISC_MENU_ITEMS, LOGOUT_MENU_ID, 4, R.string.logout)
                .setIcon(R.drawable.ic_action_logout);
    }

    mSubMenuMisc.setGroupCheckable(MISC_MENU_ITEMS, true, true);

}

From source file:nl.thehyve.transmartclient.MainActivity.java

private void refreshNavigationMenu() {

    NavigationView mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    final Menu menu = mNavigationView.getMenu();
    List<TransmartServer> connectedServers = getConnectedServers();

    menu.clear();//from w w  w.java2  s.  c  o m

    int order = 0;
    int group = 1;

    SubMenu serverMenu = menu.addSubMenu(Menu.NONE, order, order, getString(R.string.menu_serversSubmenu));
    order += 1;

    for (TransmartServer transmartServer : connectedServers) {
        int menuItemID = serverMenu.add(group, order, order, transmartServer.getServerLabel())
                .setIcon(R.drawable.ic_action_accounts).getItemId();
        transmartServer.setMenuItemID(menuItemID);
        order += 1;
    }
    add_server_item = serverMenu.add(group, order, order, R.string.menu_addNewServer)
            .setIcon(R.drawable.ic_action_new_account).getItemId();
    order += 1;

    serverMenu.setGroupCheckable(group, true, true);

    about_item = menu.add(Menu.NONE, order, order, R.string.menu_about).setIcon(R.drawable.ic_action_about)
            .getItemId();
}

From source file:com.gmail.boiledorange73.ut.map.MapActivityBase.java

/** Called whe the menu is created. */
@Override/*  ww  w. jav a 2s.  c  o m*/
public boolean onCreateOptionsMenu(Menu menu) {
    // zoom (invisible)
    menu.add(Menu.NONE, ID_ZOOM, Menu.NONE, Messages.getString("W_ZOOM"))
            .setIcon(android.R.drawable.ic_menu_zoom).setVisible(false);
    // mylocation (invisible)
    menu.add(Menu.NONE, ID_MYLOCATION, Menu.NONE, Messages.getString("W_MYLOCATION"))
            .setIcon(android.R.drawable.ic_menu_mylocation).setVisible(false);
    // maptypes (invisible)
    menu.add(Menu.NONE, ID_MAPTYPE, Menu.NONE, Messages.getString("W_CHANGE_MAP"))
            .setIcon(android.R.drawable.ic_menu_mapmode).setVisible(false);
    // geocoder (invisible)
    if (this.getGeocoderActivityClass() != null) {
        menu.add(Menu.NONE, ID_GEOCODER, Menu.NONE, Messages.getString("W_GEOCODER"))
                .setIcon(android.R.drawable.ic_menu_search).setVisible(false);
    }
    // more
    SubMenu smMore = menu.addSubMenu(Messages.getString("W_MORE")).setIcon(android.R.drawable.ic_menu_more);
    if (this.getPreferenceActivityClass() != null) {
        smMore.add(Menu.NONE, ID_MORE_PREFERENCES, Menu.NONE, Messages.getString("W_PREFERENCES"));
    }
    // more/externalmap (invisible)
    smMore.add(Menu.NONE, ID_MORE_EXTERNALMAP, Menu.NONE, Messages.getString("W_EXTERNALMAP"))
            .setVisible(false);
    // more/removedownloadedfiles (shown if needed)
    if (this.hasDownloadedFiles()) {
        smMore.add(Menu.NONE, ID_MORE_REMOVEDOWNLOADEDFILES, Menu.NONE,
                Messages.getString("W_REMOVEDOWNLOADEDFILES")).setIcon(android.R.drawable.ic_menu_delete);
    }
    // more/clearcache (2013/08/07)
    smMore.add(Menu.NONE, ID_MORE_CLEARCACHE, Menu.NONE, Messages.getString("W_CLEARCACHE"));

    // more/about
    smMore.add(Menu.NONE, ID_MORE_ABOUT, Menu.NONE, Messages.getString("W_ABOUT"));
    // more/exit
    smMore.add(Menu.NONE, ID_MORE_EXIT, Menu.NONE, Messages.getString("W_EXIT"));
    return super.onCreateOptionsMenu(menu);
}

From source file:com.nachiket.titan.LibraryActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() != 0)
        return super.onContextItemSelected(item);

    Intent intent = item.getIntent();/* w ww. ja  v  a 2s  . co  m*/

    switch (item.getItemId()) {
    case MENU_EXPAND:
        expand(intent);
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
            updateHeaders();
        }
        break;
    case MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case MENU_NEW_PLAYLIST: {
        NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, intent);
        dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog));
        dialog.show();
        break;
    }
    case MENU_RENAME_PLAYLIST: {
        NewPlaylistDialog dialog = new NewPlaylistDialog(this, intent.getStringExtra("title"), R.string.rename,
                intent);
        dialog.setDismissMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, dialog));
        dialog.show();
        break;
    }
    case MENU_DELETE:
        mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent));
        break;
    case MENU_ADD_TO_PLAYLIST: {
        SubMenu playlistMenu = item.getSubMenu();
        playlistMenu.add(0, MENU_NEW_PLAYLIST, 0, R.string.new_playlist).setIntent(intent);
        Cursor cursor = Playlist.queryPlaylists(getContentResolver());
        if (cursor != null) {
            for (int i = 0, count = cursor.getCount(); i != count; ++i) {
                cursor.moveToPosition(i);
                long id = cursor.getLong(0);
                String name = cursor.getString(1);
                Intent copy = new Intent(intent);
                copy.putExtra("playlist", id);
                copy.putExtra("playlistName", name);
                playlistMenu.add(0, MENU_SELECT_PLAYLIST, 0, name).setIntent(copy);
            }
            cursor.close();
        }
        break;
    }
    case MENU_SELECT_PLAYLIST:
        mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, intent));
        break;
    case MENU_MORE_FROM_ARTIST: {
        String selection;
        if (intent.getIntExtra(LibraryAdapter.DATA_TYPE, -1) == MediaUtils.TYPE_ALBUM) {
            selection = "album_id=";
        } else {
            selection = "_id=";
        }
        selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID);
        setLimiter(MediaUtils.TYPE_ARTIST, selection);
        updateLimiterViews();
        break;
    }
    case MENU_MORE_FROM_ALBUM:
        setLimiter(MediaUtils.TYPE_ALBUM,
                "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    }

    return true;
}