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.andrew.apollo.ui.fragments.profile.GenreSongFragment.java

/**
 * {@inheritDoc}/* www  .  java  2s .  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 = 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);

    // 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.QueueFragment.java

/**
 * {@inheritDoc}//w  ww.  j a va  2 s  .c  o 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;
    // Creat a new song
    mSong = mAdapter.getItem(mSelectedPosition);
    mSelectedId = mSong;
    mSongName = mSong.getName();
    mAlbumName = mSong.mAlbumName;
    mArtistName = mSong.mArtistName;

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

    // 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);

    // Remove the song from the queue
    menu.add(GROUP_ID, FragmentMenuItems.REMOVE_FROM_QUEUE, Menu.NONE, getString(R.string.remove_from_queue));

    // 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:org.zirco.ui.components.CustomPagerAdapter.java

private CustomWebView initializeWebView(CustomWebView webView) {

    webView.setOnTouchListener(mParentActivity);

    webView.setWebViewClient(new CustomWebViewClient(mParentActivity));
    webView.setWebChromeClient(new CustomWebChromeClient(mParentActivity, webView));

    webView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override/*  ww w.  jav a 2  s.co 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)) {

                Intent i = new Intent();
                i.putExtra(Constants.EXTRA_ID_URL, result.getExtra());

                MenuItem item = menu.add(0, MainActivity.CONTEXT_MENU_OPEN, 0, R.string.Main_MenuOpen);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, 0, R.string.Main_MenuOpenNewTab);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_COPY, 0, R.string.Main_MenuCopyLinkUrl);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_DOWNLOAD, 0, R.string.Main_MenuDownload);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_SHARE, 0, R.string.Main_MenuShareLinkUrl);
                item.setIntent(i);

                menu.setHeaderTitle(result.getExtra());
            } else if (resultType == HitTestResult.IMAGE_TYPE) {
                Intent i = new Intent();
                i.putExtra(Constants.EXTRA_ID_URL, result.getExtra());

                MenuItem item = menu.add(0, MainActivity.CONTEXT_MENU_OPEN, 0, R.string.Main_MenuViewImage);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_COPY, 0, R.string.Main_MenuCopyImageUrl);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_DOWNLOAD, 0, R.string.Main_MenuDownloadImage);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_SHARE, 0, R.string.Main_MenuShareImageUrl);
                item.setIntent(i);

                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, MainActivity.CONTEXT_MENU_SEND_MAIL, 0,
                        R.string.Main_MenuSendEmail);
                item.setIntent(sendMail);

                Intent i = new Intent();
                i.putExtra(Constants.EXTRA_ID_URL, result.getExtra());

                item = menu.add(0, MainActivity.CONTEXT_MENU_COPY, 0, R.string.Main_MenuCopyEmailUrl);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_SHARE, 0, R.string.Main_MenuShareEmailUrl);
                item.setIntent(i);

                menu.setHeaderTitle(result.getExtra());
            }
        }
    });

    webView.setDownloadListener(new DownloadListener() {

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            mParentActivity.doDownloadStart(url, userAgent, contentDisposition, mimetype, contentLength);
        }

    });

    return webView;
}

From source file:com.guayaba.tapir.ui.fragments.RecentFragment.java

/**
 * {@inheritDoc}//from  w  w  w  .j av  a2  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;
    // Create a new album
    mAlbum = mAdapter.getItem(info.position);
    // Create a list of the album's songs
    mAlbumList = MusicUtils.getSongListForAlbum(getActivity(), mAlbum.mAlbumId);

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

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

    // Add the album 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 album artist
    menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
            getString(R.string.context_menu_more_by_artist));

    // Remove the album from the list
    menu.add(GROUP_ID, FragmentMenuItems.REMOVE_FROM_RECENT, Menu.NONE,
            getString(R.string.context_menu_remove_from_recent));

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

From source file:com.abcvoipsip.ui.prefs.CodecsFragment.java

@Override
@SuppressWarnings("unchecked")
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {// w  w  w  .  ja v a  2s.  com
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(THIS_FILE, "bad menuInfo", e);
        return;
    }

    HashMap<String, Object> codec = (HashMap<String, Object>) mAdapter.getItem(info.position);
    if (codec == null) {
        // If for some reason the requested item isn't available, do nothing
        return;
    }

    boolean isDisabled = ((Short) codec.get(CODEC_PRIORITY) == 0);
    menu.add(0, MENU_ITEM_ACTIVATE, 0, isDisabled ? R.string.activate : R.string.deactivate);

}

From source file:com.boko.vimusic.ui.fragments.RecentFragment.java

/**
 * {@inheritDoc}/*w ww .  j a v a2 s. c  o  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;
    // Create a new album
    mAlbum = mAdapter.getItem(info.position);
    // Create a list of the album's songs
    mAlbumList = MusicUtils.getSongListForAlbum(getActivity(), mAlbum.getId());

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

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

    // Add the album 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 album artist
    menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
            getString(R.string.context_menu_more_by_artist));

    // Remove the album from the list
    menu.add(GROUP_ID, FragmentMenuItems.REMOVE_FROM_RECENT, Menu.NONE,
            getString(R.string.context_menu_remove_from_recent));

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

From source file:com.boko.vimusic.ui.fragments.SongFragment.java

/**
 * {@inheritDoc}//from   ww  w  .  j a v a 2 s . c o  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;
    // 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 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, 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:ru.mtuci.musicanalyzer.apollo.ui.fragments.SongFragment.java

/**
 * {@inheritDoc}//  w  w w . j a  va2s.  c o 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;
    // 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.piusvelte.taplock.client.core.TapLockSettings.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    menu.add(0, REMOVE_ID, 0, R.string.mn_remove);
}

From source file:com.andrew.apollo.ui.fragments.RecentFragment.java

/**
 * {@inheritDoc}//w  ww.j a  v  a 2s.  c o 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;
    // Create a new album
    mAlbum = mAdapter.getItem(info.position);
    // Create a list of the album's songs
    mAlbumList = MusicUtils.getSongListForAlbum(getSherlockActivity(), mAlbum.mAlbumId);

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

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

    // Add the album 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 album artist
    menu.add(GROUP_ID, FragmentMenuItems.MORE_BY_ARTIST, Menu.NONE,
            getString(R.string.context_menu_more_by_artist));

    // Remove the album from the list
    menu.add(GROUP_ID, FragmentMenuItems.REMOVE_FROM_RECENT, Menu.NONE,
            getString(R.string.context_menu_remove_from_recent));

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