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.money.manager.ex.fragment.PayeeListFragment.java

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

    Cursor cursor = ((SimpleCursorAdapter) getListAdapter()).getCursor();
    cursor.moveToPosition(info.position);
    menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(Payee.PAYEENAME)));

    menu.add(Menu.NONE, ContextMenuIds.EDIT.getId(), Menu.NONE, getString(R.string.edit));
    menu.add(Menu.NONE, ContextMenuIds.DELETE.getId(), Menu.NONE, getString(R.string.delete));
    menu.add(Menu.NONE, ContextMenuIds.VIEW_TRANSACTIONS.getId(), Menu.NONE,
            getString(R.string.view_transactions));
}

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

/**
 * {@inheritDoc}//  w w 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 = Long.valueOf(mSong.mSongId);
    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));

    // 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.money.manager.ex.currency.recycler.CurrencyRecyclerListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    RecyclerViewContextMenuInfo info = (RecyclerViewContextMenuInfo) menuInfo;
    Currency currency = getCurrencyAtPosition(info.position);
    menu.setHeaderTitle(currency.getName());

    // compose context menu
    String[] menuItems = getResources().getStringArray(R.array.context_menu_currencies);
    for (int i = 0; i < menuItems.length; i++) {
        menu.add(Menu.NONE, i, i, menuItems[i]);
    }// w  w  w .  j  a va  2 s  . com
}

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

/**
 * {@inheritDoc}//from  w w  w  .  j  a v  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;
    // Create a new album
    mAlbum = mAdapter.getItem(info.position - 1);
    // 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);

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

From source file:net.gaast.giggity.ChooserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //this.setTheme(android.R.style.Theme_Holo);

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_PROGRESS);

    /*//test stuff/*from  w  w w.jav  a  2  s .  c  om*/
    Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
    long[] pattern = {  };
    v.vibrate(pattern, -1);
    */

    Giggity app = (Giggity) getApplication();
    db = app.getDb();
    pref = PreferenceManager.getDefaultSharedPreferences(app);

    refreshSeed(false);

    list = new ListView(this);
    list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
            DbSchedule item = (DbSchedule) lista.getItem(position);
            if (item != null) {
                openSchedule(item, false);
            }
        }
    });
    list.setLongClickable(true);
    list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
            DbSchedule sched = (DbSchedule) lista.getItem((int) mi.id);
            if (sched != null) {
                menu.setHeaderTitle(sched.getTitle());
                menu.add(ContextMenu.NONE, 0, 0, R.string.refresh);
                menu.add(ContextMenu.NONE, 3, 0, R.string.unhide);
                menu.add(ContextMenu.NONE, 1, 0, R.string.remove);
                menu.add(ContextMenu.NONE, 2, 0, R.string.show_url);
            }
        }
    });

    /* Filling in the list in onResume(). */
    refresher = new SwipeRefreshLayout(this);
    refresher.setOnRefreshListener(this);
    refresher.addView(list);

    LinearLayout cont = new LinearLayout(this);
    cont.setOrientation(LinearLayout.VERTICAL);
    cont.addView(refresher, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1));

    setContentView(cont);
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedMembersFragment.java

public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    Cursor cursor = (Cursor) mContacts.getItem(info.position);
    final Contact c = Helpers.getContact(v.getContext(),
            cursor.getLong(cursor.getColumnIndexOrThrow(Contact._ID)));
    ;/*  w ww . j a  va  2s  . c  o  m*/
    menu.setHeaderTitle(c.name);
    String[] menuItems = new String[] { "Delete" };
    for (int i = 0; i < menuItems.length; i++) {
        menu.add(Menu.NONE, i, i, menuItems[i]);
    }
}

From source file:org.rapidandroid.activity.FormCreator.java

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

    menu.setHeaderTitle("Current Field");
    menu.add(0, CONTEXT_MOVE_UP, 0, "Move Up");
    menu.add(0, CONTEXT_MOVE_DOWN, 0, "Move Down");
    // menu.add(0, CONTEXT_EDIT, 0, "Edit");
    menu.add(0, CONTEXT_REMOVE, 0, "Remove").setIcon(android.R.drawable.ic_menu_delete);

}

From source file:com.ninetwozero.battlelog.fragments.ComFriendFragment.java

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

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

    // Get the "object"
    ProfileData selectedUser = (ProfileData) info.targetView.getTag();

    // Wait, is the position 0? If so, it's the heading...
    if (selectedUser.getId() != 0) {

        if (selectedUser.isFriend()) {

            menu.add(0, MENU_POS_CHAT, 0, R.string.label_chat_open);
            menu.add(0, MENU_POS_PROFILE, 0, R.string.label_soldier_view);
            menu.add(0, MENU_POS_UNLOCKS, 0, R.string.label_soldier_unlocks);
            menu.add(0, MENU_POS_COMPARE, 0, R.string.label_compare_bs);
            menu.add(0, MENU_POS_ASSIGNMENTS, 0, R.string.label_assignments_view);

        } else {//from w w  w .ja  va  2  s.  co  m

            menu.add(0, MENU_POS_REQUEST_Y, 0, R.string.label_com_accept);
            menu.add(0, MENU_POS_REQUEST_N, 0, R.string.label_com_reject);
            menu.add(0, MENU_POS_PROFILE, 0, R.string.label_soldier_view);
            menu.add(0, MENU_POS_UNLOCKS, 0, R.string.label_soldier_unlocks);
            menu.add(0, MENU_POS_COMPARE, 0, R.string.label_compare_bs);
            menu.add(0, MENU_POS_ASSIGNMENTS, 0, R.string.label_assignments_view);

        }
    }
    return;

}

From source file:org.transdroid.gui.search.Search.java

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

    menu.add(0, SEARCHMENU_ADD_ID, 0, R.string.searchmenu_add);
    menu.add(0, SEARCHMENU_DETAILS_ID, 0, R.string.searchmenu_details);
    menu.add(0, SEARCHMENU_OPENWITH_ID, 0, R.string.searchmenu_openwith);
    menu.add(0, SEARCHMENU_SHARELINK_ID, 0, R.string.searchmenu_sharelink);

}

From source file:net.vivekiyer.GAL.CorporateContactRecordFragment.java

/**
 * @param menu/*from  w w  w. j a  v  a 2 s.c om*/
 * @param v
 * @param menuInfo
 * 
 *            Create a context menu for the list view Depending upon the
 *            item selected, shows the user different options
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

    // Get the selected item from the listview adapter
    final KeyValuePair kvp = m_adapter.getItem(info.position);

    // Set the header to the selected text
    menu.setHeaderTitle(kvp.getValue());

    // Add the default options (copy to clipboard)
    menu.add(Menu.NONE, MENU_ID_COPY_TO_CLIPBOARD, Menu.NONE, R.string.copyToClipboard)
            .setIcon(android.R.drawable.ic_menu_view);

    // Handle the special cases
    switch (kvp.get_type()) {
    case EMAIL:
        menu.add(Menu.NONE, MENU_ID_EMAIL, Menu.NONE, R.string.send_email)
                .setIcon(android.R.drawable.sym_action_email);
        break;
    case MOBILE:
        menu.add(Menu.NONE, MENU_ID_SMS, Menu.NONE, getString(R.string.send_sms_to) + kvp.getValue())
                .setIcon(android.R.drawable.ic_menu_send);
    case PHONE:
        menu.add(Menu.NONE, MENU_ID_CALL, Menu.NONE, getString(R.string.call_) + kvp.getValue())
                .setIcon(android.R.drawable.ic_menu_call);
        menu.add(Menu.NONE, MENU_ID_EDIT_BEFORE_CALL, Menu.NONE, R.string.edit_number_before_call)
                .setIcon(android.R.drawable.ic_menu_edit);
    case OTHER:
    case UNDEFINED:
        break;
    }
}