Example usage for android.view ContextMenu add

List of usage examples for android.view ContextMenu add

Introduction

In this page you can find the example usage for android.view ContextMenu 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.ninetwozero.battlelog.fragments.ForumThreadFragment.java

public void createContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {

    // Get the actual menu item and tag
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

    // Show the menu
    menu.add(0, 0, 0, R.string.info_profile_view);
    menu.add(0, 1, 0, R.string.info_forum_quote);
    menu.add(0, 2, 0, R.string.info_forum_links);
    menu.add(0, 3, 0, R.string.info_forum_report);

    return;// ww  w .j  a  va 2 s. c o m

}

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

/**
 * Creates a context menu for an adapter row.
 *
 * @param menu The menu to create.//from  ww w . j a  v  a  2s . c o  m
 * @param rowData Data for the adapter row.
 */
public void onCreateContextMenu(ContextMenu menu, Intent rowData) {
    if (rowData.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID) == LibraryAdapter.HEADER_ID) {
        menu.setHeaderTitle(getString(R.string.all_songs));
        menu.add(0, MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        menu.add(0, MENU_ENQUEUE_ALL, 0, R.string.enqueue_all).setIntent(rowData);
        menu.addSubMenu(0, MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
    } else {
        int type = rowData.getIntExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_INVALID);
        boolean isAllAdapter = type <= MediaUtils.TYPE_SONG;

        menu.setHeaderTitle(rowData.getStringExtra(LibraryAdapter.DATA_TITLE));
        menu.add(0, MENU_PLAY, 0, R.string.play).setIntent(rowData);
        if (isAllAdapter)
            menu.add(0, MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        menu.add(0, MENU_ENQUEUE, 0, R.string.enqueue).setIntent(rowData);
        if (isAllAdapter)
            menu.add(0, MENU_ENQUEUE_ALL, 0, R.string.enqueue_all).setIntent(rowData);
        if (type == MediaUtils.TYPE_PLAYLIST) {
            menu.add(0, MENU_RENAME_PLAYLIST, 0, R.string.rename).setIntent(rowData);
            menu.add(0, MENU_EXPAND, 0, R.string.edit).setIntent(rowData);
        } else if (rowData.getBooleanExtra(LibraryAdapter.DATA_EXPANDABLE, false)) {
            menu.add(0, MENU_EXPAND, 0, R.string.expand).setIntent(rowData);
        }
        if (type == MediaUtils.TYPE_ALBUM || type == MediaUtils.TYPE_SONG)
            menu.add(0, MENU_MORE_FROM_ARTIST, 0, R.string.more_from_artist).setIntent(rowData);
        if (type == MediaUtils.TYPE_SONG)
            menu.add(0, MENU_MORE_FROM_ALBUM, 0, R.string.more_from_album).setIntent(rowData);
        menu.addSubMenu(0, MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
        menu.add(0, MENU_DELETE, 0, R.string.delete).setIntent(rowData);
    }
}

From source file:com.nttec.everychan.ui.MainActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (v.getId() == R.id.sidebar_tabs_list) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        TabModel model = tabsAdapter.getItem(info.position);
        if (tabsAdapter.getCount() > 1) {
            menu.add(Menu.NONE, R.id.context_menu_move, 1, R.string.context_menu_move);
        }//  ww w  .  ja v  a2 s .c om
        if (model.webUrl != null) {
            menu.add(Menu.NONE, R.id.context_menu_copy_url, 2, R.string.context_menu_copy_url);
            menu.add(Menu.NONE, R.id.context_menu_share_link, 3, R.string.context_menu_share_link);
        }
        if (canFavorite(model)) {
            menu.add(Menu.NONE, R.id.context_menu_favorites, 4,
                    isFavorite(model) ? R.string.context_menu_remove_favorites
                            : R.string.context_menu_add_favorites);
        }
        if (model.type == TabModel.TYPE_NORMAL && model.pageModel != null
                && model.pageModel.type == UrlPageModel.TYPE_THREADPAGE) {
            boolean backgroundAutoupdateEnabled = MainApplication.getInstance().settings.isAutoupdateEnabled()
                    && MainApplication.getInstance().settings.isAutoupdateBackground();
            menu.add(Menu.NONE, R.id.context_menu_autoupdate_background, 5,
                    backgroundAutoupdateEnabled ? R.string.context_menu_autoupdate_background
                            : R.string.context_menu_autoupdate_background_off)
                    .setCheckable(true).setChecked(model.autoupdateBackground);
        }
        if (model.autoupdateBackground && TabsTrackerService.getCurrentUpdatingTabId() == -1) {
            menu.add(Menu.NONE, R.id.context_menu_autoupdate_now, 6, R.string.context_menu_autoupdate_now);
        }
    }
}

From source file:com.audiokernel.euphonyrmt.SearchActivity.java

@Override
public void onCreateContextMenu(final ContextMenu menu, final View v,
        final ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

    switch (mPager.getCurrentItem()) {
    case 0:/*  w  ww.j  av a2  s . c  o  m*/
        final Artist artist = mArtistResults.get((int) info.id);
        menu.setHeaderTitle(artist.mainText());
        setContextForObject(artist);
        break;
    case 1:
        final Album album = mAlbumResults.get((int) info.id);
        menu.setHeaderTitle(album.mainText());
        setContextForObject(album);
        break;
    case 2:
        final Music music = mSongResults.get((int) info.id);
        final MenuItem gotoAlbumItem = menu.add(Menu.NONE, GOTO_ALBUM, 0, R.string.goToAlbum);
        gotoAlbumItem.setOnMenuItemClickListener(this);
        menu.setHeaderTitle(music.mainText());
        setContextForObject(music);
        break;
    default:
        break;
    }

    final MenuItem addItem = menu.add(Menu.NONE, ADD, 0, getString(mAddString));
    final MenuItem addAndReplaceItem = menu.add(Menu.NONE, ADD_REPLACE, 0, R.string.addAndReplace);
    final MenuItem addReplacePlayItem = menu.add(Menu.NONE, ADD_REPLACE_PLAY, 0, R.string.addAndReplacePlay);
    final MenuItem addAndPlayItem = menu.add(Menu.NONE, ADD_PLAY, 0, R.string.addAndPlay);

    addItem.setOnMenuItemClickListener(this);
    addAndReplaceItem.setOnMenuItemClickListener(this);
    addReplacePlayItem.setOnMenuItemClickListener(this);
    addAndPlayItem.setOnMenuItemClickListener(this);
}

From source file:monakhv.android.samlib.AuthorListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    if (v.getId() == getListView().getId()) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

        Cursor cursor = (Cursor) adapter.getItem(info.position);
        author = AuthorController.Cursor2Author(getActivity().getApplicationContext(), cursor);

        if (author == null) {
            Log.d(DEBUG_TAG, "Context menu Created - author is NULL!!");
        } else {/*from   w w w  .j  av a 2 s .c o  m*/
            Log.d(DEBUG_TAG, "Context menu Created - author is " + author.getName());
        }
        if (author.isIsNew()) {
            menu.add(1, read_option_item, 10, getText(R.string.menu_read));
        }
        menu.add(1, tags_option_item, 20, getText(R.string.menu_tags));
        menu.add(1, browser_option_item, 30, getText(R.string.menu_open_web));
        menu.add(1, edit_author_option_item, 40, getText(R.string.menu_edit));
        menu.add(1, delete_option_item, 50, getText(R.string.menu_delete));
        menu.add(1, update_option_item, 60, getText(R.string.menu_refresh));
        menu.setHeaderTitle(author.getName());
    }

}

From source file:com.nttec.everychan.ui.BoardsListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (adapter == null)
        return;//from   w  w w.j  a v a2  s. c  o m
    try {
        if (v.getId() == android.R.id.list) {
            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
            SimpleBoardModel boardModel = adapter.getItem(info.position).model;
            if (boardModel != null) {
                UrlPageModel model = getUrlModel(boardModel.boardName);
                model = UrlHandler.getPageModel(chan.buildUrl(model));
                if (model != null) {
                    boolean isFavorite = database.isFavorite(model.chanName, model.boardName,
                            Integer.toString(model.boardPage), null);
                    menu.add(Menu.NONE, R.id.context_menu_favorites_from_fragment, 1,
                            isFavorite ? R.string.context_menu_remove_favorites
                                    : R.string.context_menu_add_favorites);

                    for (QuickAccess.Entry entry : quickAccessList)
                        if (entry.boardName != null && entry.chan != null)
                            if (entry.chan.getChanName().equals(model.chanName)
                                    && entry.boardName.equals(model.boardName))
                                return;
                    menu.add(Menu.NONE, R.id.context_menu_quickaccess_add, 2,
                            R.string.context_menu_quickaccess_add);
                }
            }
        }
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
}

From source file:in.shick.diode.mail.InboxListActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    int rowId = (int) info.id;
    ThingInfo item = mMessagesAdapter.getItem(rowId);

    // Mark the message/comment as selected
    mVoteTargetThingInfo = item;//  ww w.  j  ava  2 s  .c  o m
    mReplyTargetName = item.getName();

    if (item.isWas_comment()) {
        menu.add(0, Constants.DIALOG_COMMENT_CLICK, Menu.NONE, R.string.view_context);
    } else {
        menu.add(0, Constants.DIALOG_MESSAGE_CLICK, Menu.NONE, "Reply");
    }
    // Lazy-load the URL list to make the list-loading more 'snappy'.
    if (mVoteTargetThingInfo.getUrls() != null && mVoteTargetThingInfo.getUrls().isEmpty()) {
        Markdown.getURLs(mVoteTargetThingInfo.getBody(), mVoteTargetThingInfo.getUrls());
    }
    if (mVoteTargetThingInfo.getUrls() != null && !mVoteTargetThingInfo.getUrls().isEmpty()) {
        menu.add(0, Constants.DIALOG_LINKS, Menu.NONE, R.string.links_menu_item);
    }
}

From source file:com.pdftron.pdf.controls.UserBookmarkDialogFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    if (v.getId() == R.id.controls_bookmark_recycler_view) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        UserBookmarkItem item = mBookmarkViewAdapter.getItem(info.position);
        menu.setHeaderTitle(item.title);
        String[] menuItems = getResources().getStringArray(R.array.user_bookmark_dialog_context_menu);
        menu.add(Menu.NONE, CONTEXT_MENU_EDIT_ITEM, CONTEXT_MENU_EDIT_ITEM, menuItems[CONTEXT_MENU_EDIT_ITEM]);
        menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ITEM, CONTEXT_MENU_DELETE_ITEM,
                menuItems[CONTEXT_MENU_DELETE_ITEM]);
        menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ALL, CONTEXT_MENU_DELETE_ALL,
                menuItems[CONTEXT_MENU_DELETE_ALL]);

        MenuItem.OnMenuItemClickListener listener = new MenuItem.OnMenuItemClickListener() {
            @Override//ww  w . j a  v a 2s .co m
            public boolean onMenuItemClick(MenuItem item) {
                onContextItemSelected(item);
                return true;
            }
        };
        menu.getItem(CONTEXT_MENU_EDIT_ITEM).setOnMenuItemClickListener(listener);
        menu.getItem(CONTEXT_MENU_DELETE_ITEM).setOnMenuItemClickListener(listener);
        menu.getItem(CONTEXT_MENU_DELETE_ALL).setOnMenuItemClickListener(listener);
    }
}

From source file:com.android.music.TrackBrowserFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfoIn) {
    menu.add(0, PLAY_SELECTION, 0, R.string.play_selection);
    SubMenu sub = menu.addSubMenu(0, ADD_TO_PLAYLIST, 0, R.string.add_to_playlist);
    MusicUtils.makePlaylistMenu(getActivity(), sub);
    if (mEditMode) {
        menu.add(0, REMOVE, 0, R.string.remove_from_playlist);
    }//from ww  w.  jav  a2s.co m
    menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu);
    menu.add(0, DELETE_ITEM, 0, R.string.delete_item);
    AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfoIn;
    mSelectedPosition = mi.position;
    mTrackCursor.moveToPosition(mSelectedPosition);
    try {
        int id_idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID);
        mSelectedId = mTrackCursor.getLong(id_idx);
    } catch (IllegalArgumentException ex) {
        mSelectedId = mi.id;
    }
    // only add the 'search' menu if the selected item is music
    if (isMusic(mTrackCursor)) {
        menu.add(0, SEARCH, 0, R.string.search_title);
    }
    mCurrentAlbumName = mTrackCursor
            .getString(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
    mCurrentArtistNameForAlbum = mTrackCursor
            .getString(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
    mCurrentTrackName = mTrackCursor
            .getString(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
    menu.setHeaderTitle(mCurrentTrackName);
}