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.ksharkapps.musicnow.ui.fragments.profile.GenreSongFragment.java

/**
 * {@inheritDoc}//from w  w  w.j a  va 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;
        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.QueueFragment.java

/**
 * {@inheritDoc}// w  ww.  jav a  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;
    // 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 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(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.ksharkapps.musicnow.ui.fragments.profile.LastAddedFragment.java

/**
 * {@inheritDoc}//from   www .j  ava2 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;
    if (info.position > 0) {

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

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

From source file:ivl.android.moneybalance.ExpenseListActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (v.getId() == R.id.expense_list) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
        int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        int child = ExpandableListView.getPackedPositionChild(info.packedPosition);
        if (child != -1) {
            Expense expense = (Expense) adapter.getChild(group, child);
            menu.setHeaderTitle(expense.getTitle());
            menu.add(0, ITEM_DELETE, 0, R.string.menu_delete);
        }/*  ww  w  . jav  a 2s  .c  o m*/
    }
}

From source file:can.yrt.onebusaway.RouteInfoListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
    if (ExpandableListView
            .getPackedPositionType(info.packedPosition) != ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        return;//ww  w .  j  av a 2  s  .  c  om
    }
    final TextView text = (TextView) info.targetView.findViewById(R.id.name);
    menu.setHeaderTitle(text.getText());
    menu.add(0, CONTEXT_MENU_DEFAULT, 0, R.string.route_info_context_get_stop_info);
    menu.add(0, CONTEXT_MENU_SHOWONMAP, 0, R.string.route_info_context_showonmap);
}

From source file:gov.cdc.epiinfo.RecordList.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.add(0, DELETE_ID, 0, R.string.menu_delete).setIcon(android.R.drawable.ic_menu_delete);
}

From source file:com.sim2dial.dialer.ChatFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (v.getId() == R.id.sendPicture) {
        menu.add(0, MENU_PICTURE_SMALL, 0, getString(R.string.share_picture_size_small));
        menu.add(0, MENU_PICTURE_MEDIUM, 0, getString(R.string.share_picture_size_medium));
        menu.add(0, MENU_PICTURE_LARGE, 0, getString(R.string.share_picture_size_large));
        // Not a good idea, very big pictures cause Out of Memory
        // exceptions, slow display, ...
        // menu.add(0, MENU_PICTURE_REAL, 0,
        // getString(R.string.share_picture_size_real));
    } else {/*from  w w w . j a va 2  s. c  o m*/
        menu.add(v.getId(), MENU_DELETE_MESSAGE, 0, getString(R.string.delete));
        ImageView iv = (ImageView) v.findViewById(R.id.image);
        if (iv != null && iv.getVisibility() == View.VISIBLE) {
            menu.add(v.getId(), MENU_SAVE_PICTURE, 0, getString(R.string.save_picture));
        } else {
            menu.add(v.getId(), MENU_COPY_TEXT, 0, getString(R.string.copy_text));
        }
    }
}

From source file:com.orangelabs.rcs.ri.messaging.chat.single.SingleChatView.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the list item position
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    Cursor cursor = (Cursor) mAdapter.getItem(info.position);
    // Adapt the contextual menu according to the selected item
    menu.add(0, MENU_ITEM_DELETE, MENU_ITEM_DELETE, R.string.menu_delete_message);
    Direction direction = Direction.valueOf(cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.DIRECTION)));
    if (Direction.OUTGOING != direction) {
        return;// ww  w.  j  ava2s  . c o  m
    }
    int providerId = cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.PROVIDER_ID));
    if (ChatLog.Message.HISTORYLOG_MEMBER_ID == providerId) {
        Content.Status status = Content.Status
                .valueOf(cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.STATUS)));
        if (Content.Status.FAILED == status) {
            menu.add(0, MENU_ITEM_RESEND, MENU_ITEM_RESEND, R.string.menu_resend_message);
        }
        // TODO depending on mime-type allow user to view file image

    } else if (FileTransferLog.HISTORYLOG_MEMBER_ID == providerId) {
        FileTransfer.State state = FileTransfer.State
                .valueOf(cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.STATUS)));
        if (FileTransfer.State.FAILED == state) {
            menu.add(0, MENU_ITEM_RESEND, MENU_ITEM_RESEND, R.string.menu_resend_message);
        }
    }
}

From source file:com.radicaldynamic.groupinform.activities.AccountFolderList.java

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

    boolean enabled = false;
    boolean visible = true;

    if (Collect.getInstance().getIoService().isSignedIn())
        enabled = true;/*from w ww  . j  av  a  2  s  . c  om*/

    if (mCopyToFolder)
        visible = false;

    if (!Collect.getInstance().getInformOnlineState().getDeviceRole().equals(AccountDevice.ROLE_DATA_ENTRY)) {
        menu.add(0, CONTEXT_MENU_EDIT, 0, getString(R.string.tf_edit_folder)).setEnabled(enabled)
                .setVisible(visible);
    }

    menu.add(0, CONTEXT_MENU_INFO, 0, getString(R.string.tf_more_info));
}

From source file:it.geosolutions.geocollect.android.core.form.FormEditActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    Log.v("FEA", "CreatingMenu for " + v.getClass().getName());
    super.onCreateContextMenu(menu, v, menuInfo);

    // a longPress on an Image is detected
    // Currently supported Actions are:
    // - Delete Image
    if (v instanceof GridView) {
        menu.setHeaderTitle(getString(R.string.gallery_context_menu_title));
        // Delete Option
        menu.add(Menu.NONE, CONTEXT_IMAGE_ACTION_DELETE, Menu.NONE,
                getString(R.string.gallery_context_menu_delete));
    }// ww  w.  ja v a2s .  c  o  m

}