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.cachirulop.moneybox.fragment.MovementsFragment.java

/**
 * Creates a context menu for the list of movements, showing an option for
 * delete the movement and another to get the movement.
 *///from ww  w  .j  a va2 s.  co m
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    if (v.getId() == R.id.lvMovements) {
        AdapterView.AdapterContextMenuInfo info;
        ListView listView;
        Movement selected;

        listView = (ListView) getActivity().findViewById(R.id.lvMovements);
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;

        selected = (Movement) ((MoneyboxMovementAdapter) listView.getAdapter()).getItem(info.position);

        MenuItem item;

        menu.setHeaderTitle(selected.getInsertDateFormatted());
        item = menu.add(Menu.NONE, CONTEXT_MENU_GET, 0, R.string.get_from_moneybox);
        item.setEnabled(MovementsManager.canGetMovement(selected));

        item = menu.add(Menu.NONE, CONTEXT_MENU_DROP, 1, R.string.drop_to_moneybox_again);
        item.setEnabled(MovementsManager.canDropMovement(selected));

        item = menu.add(Menu.NONE, CONTEXT_MENU_DELETE, 2, R.string.delete);
        item.setEnabled(MovementsManager.canDeleteMovement(selected));
    }
}

From source file:com.ksharkapps.musicnow.ui.fragments.profile.FavoriteFragment.java

/**
 * {@inheritDoc}//w ww.j  ava  2 s.co  m
 */
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the position of the selected item
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    if (info.position > 0) {

        mSelectedPosition = info.position - 1;
        // Creat a new song
        mSong = mAdapter.getItem(mSelectedPosition);
        mSelectedId = mSong.mSongId;
        mArtistName = mSong.mArtistName;

        // Play the song
        menu.add(GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE,
                getString(R.string.context_menu_play_selection));

        // Play next
        menu.add(GROUP_ID, FragmentMenuItems.PLAY_NEXT, Menu.NONE, getString(R.string.context_menu_play_next));

        // Add the song to the queue
        menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue));

        // Add the song to a playlist
        final SubMenu subMenu = menu.addSubMenu(GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE,
                R.string.add_to_playlist);
        MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, subMenu, false);

        // View more content by the song artist
        menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
                getString(R.string.context_menu_more_by_artist));

        // Make the song a ringtone
        menu.add(GROUP_ID, FragmentMenuItems.USE_AS_RINGTONE, Menu.NONE,
                getString(R.string.context_menu_use_as_ringtone));

        // Remove from favorites
        menu.add(GROUP_ID, FragmentMenuItems.REMOVE_FROM_FAVORITES, Menu.NONE,
                getString(R.string.remove_from_favorites));

        // Delete the song
        menu.add(GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete));
    }
}

From source file:com.example.android.notepad.NotesList.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {/*from   www .jav  a  2 s.  c  om*/
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return;
    }

    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    if (cursor == null) {
        // For some reason the requested item isn't available, do nothing
        return;
    }

    // Setup the menu header
    menu.setHeaderTitle(cursor.getString(COLUMN_INDEX_TITLE));

    // Add a menu item to delete the note
    menu.add(0, MENU_ITEM_DELETE, 0, R.string.menu_delete);
}

From source file:com.googlecode.android_scripting.activity.ScriptManager.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    menu.add(Menu.NONE, MenuId.RENAME.getId(), Menu.NONE, getString(R.string.s_Rename));
    menu.add(Menu.NONE, MenuId.DELETE.getId(), Menu.NONE, getString(R.string.s_Delete));
    menu.add(Menu.NONE, MenuId.DECOMPILE.getId(), Menu.NONE, getString(R.string.s_Decompile));
    menu.add(Menu.NONE, MenuId.BUILD.getId(), Menu.NONE, getString(R.string.s_Build));
}

From source file:ru.mtuci.musicanalyzer.apollo.ui.fragments.profile.GenreSongFragment.java

/**
 * {@inheritDoc}// ww w  . j  a v a  2 s . c  om
 */
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the position of the selected item
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    mSelectedPosition = info.position - 1;
    // Creat a new song
    mSong = mAdapter.getItem(mSelectedPosition);
    mSelectedId = mSong.mSongId;
    mSongName = mSong.mSongName;
    mAlbumName = mSong.mAlbumName;
    mArtistName = mSong.mArtistName;

    // Play the song
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE,
            getString(R.string.context_menu_play_selection));

    // Add the song to the queue
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue));

    // Add the song to a playlist
    final SubMenu subMenu = menu.addSubMenu(GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE,
            R.string.add_to_playlist);
    MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, subMenu, true);

    // View more content by the song artist
    menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
            getString(R.string.context_menu_more_by_artist));

    // Make the song a ringtone
    menu.add(GROUP_ID, FragmentMenuItems.USE_AS_RINGTONE, Menu.NONE,
            getString(R.string.context_menu_use_as_ringtone));

    // Delete the song
    menu.add(GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete));
}

From source file:com.boko.vimusic.ui.fragments.profile.GenreSongFragment.java

/**
 * {@inheritDoc}// ww w .  j a  v  a 2  s.co  m
 */
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the position of the selected item
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    mSelectedPosition = info.position - 1;
    // Creat a new song
    mSong = mAdapter.getItem(mSelectedPosition);
    mSelectedId = mSong;
    mSongName = mSong.getName();
    mAlbumName = mSong.mAlbumName;
    mArtistName = mSong.mArtistName;

    // Play the song
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE,
            getString(R.string.context_menu_play_selection));

    // Play the song
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_NEXT, Menu.NONE, getString(R.string.context_menu_play_next));

    // Add the song to the queue
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue));

    // Add the song to a playlist
    final SubMenu subMenu = menu.addSubMenu(GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE,
            R.string.add_to_playlist);
    MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, subMenu, true);

    // View more content by the song artist
    menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
            getString(R.string.context_menu_more_by_artist));

    // Make the song a ringtone
    menu.add(GROUP_ID, FragmentMenuItems.USE_AS_RINGTONE, Menu.NONE,
            getString(R.string.context_menu_use_as_ringtone));

    // Delete the song
    menu.add(GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete));
}

From source file:com.guayaba.tapir.ui.fragments.profile.GenreSongFragment.java

/**
 * {@inheritDoc}/*from  www .  j  av  a 2  s.c  om*/
 */
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the position of the selected item
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    mSelectedPosition = info.position - 1;
    // Creat a new song
    mSong = mAdapter.getItem(mSelectedPosition);
    mSelectedId = mSong.mSongId;
    mSongName = mSong.mSongName;
    mAlbumName = mSong.mAlbumName;
    mArtistName = mSong.mArtistName;

    // Play the song
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE,
            getString(R.string.context_menu_play_selection));

    // Play the song
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_NEXT, Menu.NONE, getString(R.string.context_menu_play_next));

    // Add the song to the queue
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue));

    // Add the song to a playlist
    final SubMenu subMenu = menu.addSubMenu(GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE,
            R.string.add_to_playlist);
    MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, subMenu, true);

    // View more content by the song artist
    menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
            getString(R.string.context_menu_more_by_artist));

    // Make the song a ringtone
    menu.add(GROUP_ID, FragmentMenuItems.USE_AS_RINGTONE, Menu.NONE,
            getString(R.string.context_menu_use_as_ringtone));

    // Delete the song
    menu.add(GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete));
}

From source file:com.andrew.apollo.ui.fragments.profile.LastAddedFragment.java

/**
 * {@inheritDoc}//  ww  w . j  av a 2s . com
 */
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the position of the selected item
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    mSelectedPosition = info.position - 1;
    // Creat a new song
    mSong = mAdapter.getItem(mSelectedPosition);
    mSelectedId = Long.valueOf(mSong.mSongId);
    mSongName = mSong.mSongName;
    mAlbumName = mSong.mAlbumName;
    mArtistName = mSong.mArtistName;

    // Play the song
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE,
            getString(R.string.context_menu_play_selection));

    // Add the song to the queue
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue));

    // Add the song to a playlist
    final SubMenu subMenu = menu.addSubMenu(GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE,
            R.string.add_to_playlist);
    MusicUtils.makePlaylistMenu(getSherlockActivity(), GROUP_ID, subMenu, false);

    // View more content by the song artist
    menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
            getString(R.string.context_menu_more_by_artist));

    // Make the song a ringtone
    menu.add(GROUP_ID, FragmentMenuItems.USE_AS_RINGTONE, Menu.NONE,
            getString(R.string.context_menu_use_as_ringtone));

    // Delete the song
    menu.add(GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete));
}

From source file:com.andrew.apollo.ui.fragments.profile.AlbumSongFragment.java

/**
 * {@inheritDoc}//from w w w.j  a va2s  .  com
 */
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the position of the selected item
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    mSelectedPosition = info.position - 1;
    // Creat a new song
    mSong = mAdapter.getItem(mSelectedPosition);
    mSelectedId = Long.valueOf(mSong.mSongId);
    mSongName = mSong.mSongName;
    mAlbumName = mSong.mAlbumName;
    mArtistName = mSong.mArtistName;

    // Play the song
    menu.add(GROUP_ID, FragmentMenuItems.PLAY_SELECTION, Menu.NONE,
            getString(R.string.context_menu_play_selection));

    // Add the song to the queue
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue));

    // Add the song to a playlist
    final SubMenu subMenu = menu.addSubMenu(GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE,
            R.string.add_to_playlist);
    MusicUtils.makePlaylistMenu(getSherlockActivity(), GROUP_ID, subMenu, true);

    // Make the song a ringtone
    menu.add(GROUP_ID, FragmentMenuItems.USE_AS_RINGTONE, Menu.NONE,
            getString(R.string.context_menu_use_as_ringtone));

    // Delete the song
    menu.add(GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete));
}

From source file:com.seal.ui.components.CustomWebView.java

private void setupContextMenu() {
    setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

        @Override//  ww w  .j a  v  a 2 s. c o m
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            HitTestResult result = ((WebView) v).getHitTestResult();
            int resultType = result.getType();

            if ((resultType == HitTestResult.ANCHOR_TYPE) || (resultType == HitTestResult.IMAGE_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)) {

                MenuItem item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN, 0, R.string.ContextMenuOpen);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, 0,
                        R.string.ContextMenuOpenNewTab);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN_IN_BACKGROUND, 0,
                        R.string.ContextMenuOpenInBackground);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN_IN_BACKGROUND, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_COPY, 0, R.string.ContextMenuCopyLinkUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_COPY, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_DOWNLOAD, 0, R.string.ContextMenuDownload);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_DOWNLOAD, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_SHARE, 0, R.string.ContextMenuShareLinkUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_SHARE, resultType, result.getExtra()));

                createContributedContextMenu(menu, resultType, result.getExtra());

                menu.setHeaderTitle(result.getExtra());

            } else if (resultType == HitTestResult.IMAGE_TYPE) {

                MenuItem item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN, 0,
                        R.string.ContextMenuViewImage);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, 0,
                        R.string.ContextMenuViewImageInNewTab);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_COPY, 0, R.string.ContextMenuCopyImageUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_COPY, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_DOWNLOAD, 0,
                        R.string.ContextMenuDownloadImage);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_DOWNLOAD, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_SHARE, 0,
                        R.string.ContextMenuShareImageUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_SHARE, resultType, result.getExtra()));

                createContributedContextMenu(menu, resultType, result.getExtra());

                menu.setHeaderTitle(result.getExtra());

            } else if (resultType == HitTestResult.EMAIL_TYPE) {

                Intent sendMail = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(WebView.SCHEME_MAILTO + result.getExtra()));

                MenuItem item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_SEND_MAIL, 0,
                        R.string.ContextMenuSendEmail);
                item.setIntent(sendMail);

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_COPY, 0, R.string.ContextMenuCopyEmailUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_COPY, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_SHARE, 0,
                        R.string.ContextMenuShareEmailUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_SHARE, resultType, result.getExtra()));

                createContributedContextMenu(menu, resultType, result.getExtra());

                menu.setHeaderTitle(result.getExtra());

            }
        }
    });
}