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:ca.spencerelliott.mercury.Changesets.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    int i = 0;//from w w w. j  a v a  2  s.  c om

    //Get the context menu info from the adapter
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

    //Find which item has been selected
    last_item_touched = info.position;

    //Create the menu
    //menu.add(0, EMAIL_PERSON, ++i, R.string.changesets_link_contact);
    menu.add(0, VIEW_BROWSER, ++i, R.string.changesets_view_browser);//.setEnabled(!is_https);

    SubMenu link_menu = menu.addSubMenu(0, LINK_COMMITTER, ++i, R.string.changesets_link_contact);

    if (contacts_list == null) {
        //Create the contacts list
        contacts_list = new ArrayList<Map<String, String>>();

        //Store which columns are needed from the contact
        String[] columns = { People._ID, People.NAME };

        //Get the Uri to the contacts content provider
        Uri contacts = People.CONTENT_URI;

        //Run the query to get all of the contacts on the device
        Cursor all_contacts = managedQuery(contacts, columns, null, null, People.NAME + " ASC");

        //Store the column number of the name and id from the content provider
        int id_column = all_contacts.getColumnIndex(People._ID);
        int name_column = all_contacts.getColumnIndex(People.NAME);

        //If there are columns
        if (all_contacts.moveToFirst()) {
            //Loop through each contact and add them to the list
            do {
                //Create a new contact map
                Map<String, String> new_contact = new HashMap<String, String>();

                //Add the id and name to the map
                new_contact.put("id", all_contacts.getString(id_column));
                new_contact.put("name", all_contacts.getString(name_column));

                //Add the new contact to the list
                contacts_list.add(new_contact);
            } while (all_contacts.moveToNext());
        }
    }

    //Set count to -1 since the loop pre-increments the variable so the first
    //used value of count will be 0
    int count = -1;

    //Add all the contacts to the sub-menu
    for (Map<String, String> c : contacts_list) {
        link_menu.add(CONTACT_GROUP, Integer.parseInt(c.get("id")), ++count, c.get("name"));
    }
}

From source file:bander.notepad.NoteListAppCompat.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {/*from w  ww.j  a  va 2 s .c  om*/
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        return;
    }

    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    if (cursor == null) {
        return;
    }

    menu.setHeaderTitle(cursor.getString(COLUMN_INDEX_TITLE));

    Uri uri = ContentUris.withAppendedId(getIntent().getData(), cursor.getInt(COLUMN_INDEX_ID));

    Intent[] specifics = new Intent[1];
    specifics[0] = new Intent(Intent.ACTION_EDIT, uri);
    MenuItem[] items = new MenuItem[1];

    Intent intent = new Intent(null, uri);
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items);

    menu.add(0, DELETE_ID, 0, R.string.menu_delete);
    // TODO: When you click on this, it crashes. I commented it out for now.
    // menu.add(0, SEND_ID, 0, R.string.menu_send);
}

From source file:com.numenta.taurus.instance.InstanceListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
    if (_scrolling) {
        return;/*from  www  .j a  v a  2 s  .  c  o  m*/
    }
    super.onCreateContextMenu(menu, view, menuInfo);
    // Make sure we have an instance before showing the menu
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    InstanceAnomalyChartData instance = (InstanceAnomalyChartData) getListAdapter().getItem(info.position);
    if (instance != null) {
        // Show Context menu with "Add/Remove Favorites" depending on the instance selected
        if (!TaurusApplication.isInstanceFavorite(instance.getId())) {
            menu.add(0, R.id.menu_add_favorite, 0, R.string.menu_add_favorite);
        } else {
            menu.add(0, R.id.menu_remove_favorite, 0, R.string.menu_remove_favorite);
        }
    }
}

From source file:com.markuspage.android.atimetracker.Tasks.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    menu.setHeaderTitle("Task menu");
    menu.add(0, EDIT_TASK, 0, getText(R.string.edit_task));
    menu.add(0, DELETE_TASK, 0, getText(R.string.delete_task));
    menu.add(0, SHOW_TIMES, 0, getText(R.string.show_times));
}

From source file:org.ros.android.app_chooser.ExchangeActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (v.getId() == R.id.installed_app_list) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        appSelected = installed_application_list[info.position];
        appSelectedDisplay = installed_application_display[info.position];
        menu.setHeaderTitle(appSelectedDisplay);
        String[] menuItems = getResources().getStringArray(R.array.installed_context_menu);
        for (int i = 0; i < menuItems.length; i++) {
            menu.add(INSTALLED_ITEM_ID, i, i, menuItems[i]);
        }/*from   w w w . j av  a2  s.  co m*/
    } else if (v.getId() == R.id.available_app_list) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        appSelected = available_application_list[info.position];
        appSelectedDisplay = available_application_display[info.position];
        menu.setHeaderTitle(appSelectedDisplay);
        String[] menuItems = getResources().getStringArray(R.array.exchange_context_menu);
        for (int i = 0; i < menuItems.length; i++) {
            menu.add(AVAILABLE_ITEM_ID, i, i, menuItems[i]);
        }
    }
}

From source file:info.corne.performancetool.MainActivity.java

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

    String selectedItem = (String) profilesAdapter.getItem(aInfo.position);

    menu.setHeaderTitle(selectedItem);/* w w  w.j  a  v  a2s  .  c  o  m*/
    menu.add(1, 1, 1, getResources().getString(R.string.details));
    menu.add(1, 2, 2, getResources().getString(R.string.delete));
}

From source file:org.junit4android.JunitTestRunnerActivity.java

/**
 * {@inheritDoc}/* w ww.  j av a2 s  .  c  om*/
 *
 * @see android.app.Activity#onCreateContextMenu(android.view.ContextMenu,
 *      android.view.View, android.view.ContextMenu.ContextMenuInfo)
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
    int type = ExpandableListView.getPackedPositionType(info.packedPosition);

    // Only create a context menu for group items
    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        selectedTestName = ((TextView) info.targetView).getText().toString();
        menu.setHeaderTitle(selectedTestName);
        menu.add(0, RERUN_MENU_ITEM_ID, 0, "Rerun this test...");
    }
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    String[] menuItems = getResources().getStringArray(R.array.context_menu);
    switch (v.getId()) {
    case R.id.listSnack:
        for (int i = 0; i < menuItems.length; i++) {
            menu.add(Menu.NONE, i, i, menuItems[i]);
        }/*from  w w  w. j  ava2  s.  co  m*/
        contextListChoice = 1;
        break;
    case R.id.listBreakfast:
        for (int i = 0; i < menuItems.length; i++) {
            menu.add(Menu.NONE, i, i, menuItems[i]);
        }
        contextListChoice = 2;
        break;
    case R.id.listLunch:
        for (int i = 0; i < menuItems.length; i++) {
            menu.add(Menu.NONE, i, i, menuItems[i]);
        }
        contextListChoice = 3;
        break;
    case R.id.listDinner:
        for (int i = 0; i < menuItems.length; i++) {
            menu.add(Menu.NONE, i, i, menuItems[i]);
        }
        contextListChoice = 4;
        break;
    }
}

From source file:com.dvdprime.mobile.android.ui.DocumentViewActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    HitTestResult hitTestResult = mWebView.getHitTestResult();
    if (hitTestResult.getType() == HitTestResult.IMAGE_TYPE
            || hitTestResult.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        contextUrl = hitTestResult.getExtra();
        menu.setHeaderTitle(hitTestResult.getExtra());
        menu.add(Menu.NONE, CONTEXT_MENU_COPY_URL, 0, getString(R.string.context_menu_copy_url));
        menu.add(Menu.NONE, CONTEXT_MENU_BROWSER, 1, getString(R.string.context_menu_open_browser));
        menu.add(Menu.NONE, CONTEXT_MENU_SAVE_IMAGE, 2, getString(R.string.context_menu_save_image));
    } else if (hitTestResult.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
        contextUrl = hitTestResult.getExtra();
        menu.setHeaderTitle(hitTestResult.getExtra());
        menu.add(Menu.NONE, CONTEXT_MENU_COPY_URL, 0, getString(R.string.context_menu_copy_url));
        menu.add(Menu.NONE, CONTEXT_MENU_BROWSER, 1, getString(R.string.context_menu_open_browser));
        menu.add(Menu.NONE, CONTEXT_MENU_SHARE_LINK, 1, getString(R.string.context_menu_share_url));
    }/* w ww .  j a  v a  2 s.c o  m*/
}

From source file:com.balakrish.gpstracker.WaypointsListActivity.java

/**
 * Create context menu for selected item
 *//*from  www  . ja v  a  2s  .  co m*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {

    super.onCreateContextMenu(menu, v, menuInfo);

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

    menu.setHeaderTitle(getString(R.string.waypoint));
    menu.add(Menu.NONE, 0, 0, R.string.edit);
    menu.add(Menu.NONE, 1, 1, R.string.delete);
    menu.add(Menu.NONE, 2, 2, R.string.email_to);
    menu.add(Menu.NONE, 3, 3, R.string.show_on_map);

}