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.abcvoipsip.ui.account.AccountsEditListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    final SipProfile account = profileFromContextMenuInfo(menuInfo);
    if (account == null) {
        return;// w ww  . j a v  a2s .  com
    }
    WizardInfo wizardInfos = WizardUtils.getWizardClass(account.wizard);

    // Setup the menu header
    menu.setHeaderTitle(account.display_name);
    menu.setHeaderIcon(wizardInfos.icon);

    // Add a menu item to delete the note
    menu.add(0, MENU_ITEM_ACTIVATE, 0,
            account.active ? R.string.deactivate_account : R.string.activate_account);
    menu.add(0, MENU_ITEM_MODIFY, 0, R.string.modify_account);
    menu.add(0, MENU_ITEM_DELETE, 0, R.string.delete_account);
    menu.add(0, MENU_ITEM_WIZARD, 0, R.string.choose_wizard);

}

From source file:org.totschnig.myexpenses.fragment.PlanList.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
    int type = ExpandableListView.getPackedPositionType(info.packedPosition);

    // Menu entries relevant only for the group
    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        super.onCreateContextMenu(menu, v, menuInfo);
    } else {//from  ww  w  .  j  a  v a2s  .c  o  m
        Long transactionId = mInstance2TransactionMap.get(info.id);
        if (transactionId == null) {
            //state open
            menu.add(0, R.id.CREATE_INSTANCE_SAVE_COMMAND, 0, R.string.menu_apply_template_and_save);
            menu.add(0, R.id.CREATE_INSTANCE_EDIT_COMMAND, 0, R.string.menu_apply_template_and_edit);
            menu.add(0, R.id.CANCEL_PLAN_INSTANCE_COMMAND, 0, R.string.menu_cancel_plan_instance);
        } else if (transactionId == 0L) {
            //state cancelled
            menu.add(0, R.id.RESET_PLAN_INSTANCE_COMMAND, 0, R.string.menu_reset_plan_instance);
        } else {
            //state applied
            menu.add(0, R.id.EDIT_COMMAND, 0, R.string.menu_edit);
            menu.add(0, R.id.CANCEL_PLAN_INSTANCE_COMMAND, 0, R.string.menu_cancel_plan_instance);
            menu.add(0, R.id.RESET_PLAN_INSTANCE_COMMAND, 0, R.string.menu_reset_plan_instance);
        }
    }
}

From source file:org.geometerplus.android.fbreader.network.NetworkLibraryActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    if (myContextMenuActions.isEmpty()) {
        fillContextMenuList();/*from   w w  w. j a  va  2  s .c o  m*/
    }

    final int position = ((AdapterView.AdapterContextMenuInfo) menuInfo).position;
    final NetworkTree tree = (NetworkTree) getListAdapter().getItem(position);
    if (tree != null) {
        menu.setHeaderTitle(tree.getName());
        for (Action a : getContextMenuActions(tree)) {
            if (a.isVisible(tree) && a.isEnabled(tree)) {
                menu.add(0, a.Code, 0, a.getContextLabel(tree));
            }
        }
    }
}

From source file:monakhv.android.samlib.BookListFragment.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);
        long book_id = cursor.getLong(cursor.getColumnIndex(SQLController.COL_ID));

        selected = sql.getBookController().getById(book_id);
        if (selected.isIsNew()) {
            menu.add(1, menu_mark_read, 1, getText(R.string.menu_read));
        }//ww w  .  j  a  v  a 2s. c om
        menu.add(1, menu_browser, 20, getText(R.string.menu_open_web));
        if (selected.getGroup_id() == Book.SELECTED_GROUP_ID) {
            menu.add(1, menu_deselected, 40, getText(R.string.menu_deselected));
        } else {
            menu.add(1, menu_selected, 30, getText(R.string.menu_selected));
        }
        menu.add(1, menu_reload, 50, getText(R.string.menu_reload));

    }
}

From source file:com.login.home.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
    String title = ((TextView) info.targetView).getText().toString();
    menu.setHeaderTitle(title);//from ww w .  jav  a2 s  .  c  om

    int type = ExpandableListView.getPackedPositionType(info.packedPosition);

    if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        super.onCreateContextMenu(menu, v, menuInfo);
        int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        if (groupPos == 1 || groupPos == 0) {
            menu.add(1, 0, 0, "ACCEPT");
            menu.add(1, 1, 0, "DECLINE");
            menu.add(1, 2, 0, "SHOW INFO");
        } else if (groupPos == 2) {
            menu.add(1, 0, 0, "SHOW INFO");
            menu.add(1, 1, 0, "SHOW ON A MAP");
            menu.add(1, 2, 0, "WILL NOT ATTEND");

        }
    }
}

From source file:com.csipsimple.ui.account.AccountsEditListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    final SipProfile account = profileFromContextMenuInfo(menuInfo);
    if (account == null) {
        return;/*  w  ww .j  av  a2  s. c o  m*/
    }
    WizardInfo wizardInfos = WizardUtils.getWizardClass(account.wizard);

    // Setup the menu header
    menu.setHeaderTitle(account.display_name);
    if (wizardInfos != null) {
        menu.setHeaderIcon(wizardInfos.icon);
    }

    menu.add(0, MENU_ITEM_ACTIVATE, 0,
            account.active ? R.string.deactivate_account : R.string.activate_account);
    menu.add(0, MENU_ITEM_MODIFY, 0, R.string.modify_account);
    menu.add(0, MENU_ITEM_DELETE, 0, R.string.delete_account);
    menu.add(0, MENU_ITEM_WIZARD, 0, R.string.choose_wizard);

}

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

/**
 * {@inheritDoc}//from  ww  w  . ja va2  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, 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));

        // Remove the song from playlist
        menu.add(GROUP_ID, FragmentMenuItems.REMOVE_FROM_PLAYLIST, Menu.NONE,
                getString(R.string.context_menu_remove_from_playlist));

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

From source file:com.sandklef.coachapp.fragments.MemberFragment.java

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

    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    String word = ((TextView) info.targetView).getText().toString();
    long id = info.id;

    try {//from  www.j a  v  a 2 s.c o m
        menu.setHeaderTitle("Select");
        String memberUuid = Storage.getInstance().getMembers().get((int) id).getUuid();

        contextMedia = MediaFilterEngine.apply(Storage.getInstance().getMedia(),
                MediaMemberFilter.newMediaMemberFilter(memberUuid));

        for (Media media : contextMedia) {
            Log.d(LOG_TAG, " * " + media.getUuid());
            menu.add(0, v.getId(), 0, CADateFormat.getDateString(media.getDate()));
        }
    } catch (StorageNoClubException e) {
        e.printStackTrace();
    }
}

From source file:com.sip.pwc.sipphone.ui.account.AccountsEditListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    final SipProfile account = profileFromContextMenuInfo(menuInfo);
    if (account == null) {
        return;//from   w w  w  .j a  v  a  2  s. c  o m
    }
    WizardUtils.WizardInfo wizardInfos = WizardUtils.getWizardClass(account.wizard);

    // Setup the menu header
    menu.setHeaderTitle(account.display_name);
    if (wizardInfos != null) {
        menu.setHeaderIcon(wizardInfos.icon);
    }

    menu.add(0, MENU_ITEM_ACTIVATE, 0,
            account.active ? R.string.deactivate_account : R.string.activate_account);
    menu.add(0, MENU_ITEM_MODIFY, 0, R.string.modify_account);
    menu.add(0, MENU_ITEM_DELETE, 0, R.string.delete_account);
    menu.add(0, MENU_ITEM_WIZARD, 0, R.string.choose_wizard);

}

From source file:com.audiokernel.euphonyrmt.fragments.BrowseFragment.java

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

    final int index = (int) info.id;
    if (index >= 0 && mItems.size() > index) {
        menu.setHeaderTitle(mItems.get((int) info.id).toString());
        // If in simple mode, show "Play" (add, replace & play), "Add to queue" and "Add to playlist"
        if (mApp.isInSimpleMode()) {
            final MenuItem playItem = menu.add(ADD_REPLACE_PLAY, ADD_REPLACE_PLAY, 0, R.string.play);
            playItem.setOnMenuItemClickListener(this);
            final MenuItem addItem = menu.add(ADD, ADD, 0, R.string.addToQueue);
            addItem.setOnMenuItemClickListener(this);
        } else {/* w w w  . ja v  a 2  s  . c  om*/
            final MenuItem addItem = menu.add(ADD, ADD, 0, mIrAdd);
            addItem.setOnMenuItemClickListener(this);
            final MenuItem addAndReplaceItem = menu.add(ADD_REPLACE, ADD_REPLACE, 0, R.string.addAndReplace);
            addAndReplaceItem.setOnMenuItemClickListener(this);
            final MenuItem addAndReplacePlayItem = menu.add(ADD_REPLACE_PLAY, ADD_REPLACE_PLAY, 0,
                    R.string.addAndReplacePlay);
            addAndReplacePlayItem.setOnMenuItemClickListener(this);
            final MenuItem addAndPlayItem = menu.add(ADD_PLAY, ADD_PLAY, 0, R.string.addAndPlay);
            addAndPlayItem.setOnMenuItemClickListener(this);
        }

        if (R.string.addPlaylist != mIrAdd && R.string.addStream != mIrAdd
                && mApp.oMPDAsyncHelper.oMPD.isCommandAvailable(MPDCommand.MPD_CMD_LISTPLAYLISTS)) {

            int id = 0;
            final SubMenu playlistMenu = menu.addSubMenu(R.string.addToPlaylist);
            MenuItem item = playlistMenu.add(ADD_TO_PLAYLIST, id++, (int) info.id, R.string.newPlaylist);
            item.setOnMenuItemClickListener(this);

            try {
                final List<Item> playlists = mApp.oMPDAsyncHelper.oMPD.getPlaylists();

                if (null != playlists) {
                    for (final Item pl : playlists) {
                        item = playlistMenu.add(ADD_TO_PLAYLIST, id++, (int) info.id, pl.getName());
                        item.setOnMenuItemClickListener(this);
                    }
                }
            } catch (final IOException | MPDException e) {
                Log.e(TAG, "Failed to parse playlists.", e);
            }
        }
        final MenuItem gotoArtistItem = menu.add(GOTO_ARTIST, GOTO_ARTIST, 0, R.string.goToArtist);
        gotoArtistItem.setOnMenuItemClickListener(this);

    }
}