Example usage for android.view ContextMenu addIntentOptions

List of usage examples for android.view ContextMenu addIntentOptions

Introduction

In this page you can find the example usage for android.view ContextMenu addIntentOptions.

Prototype

public int addIntentOptions(int groupId, int itemId, int order, ComponentName caller, Intent[] specifics,
        Intent intent, int flags, MenuItem[] outSpecificItems);

Source Link

Document

Add a group of menu items corresponding to actions that can be performed for a particular Intent.

Usage

From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java

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

    // The data from the menu item.
    AdapterView.AdapterContextMenuInfo info;

    // Tries to get the position of the item in the ListView that was long-pressed.
    try {/*from  www. j av a 2s .c  om*/
        // Casts the incoming data object into the type for AdapterView objects.
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        // If the menu object can't be cast, logs an error.
        Log.e(TAG, "bad menuInfo", e);
        return;
    }
    Intent intent = new Intent(null,
            Uri.withAppendedPath(getIntent().getData(), Integer.toString((int) info.id)));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, RecipesList.class), null,
            intent, 0, null);
}

From source file:bander.notepad.NoteListAppCompat.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {//from   w w w.j  ava  2s .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.kyakujin.android.tagnotepad.ui.TagListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterView.AdapterContextMenuInfo info;
    try {/*ww w .jav  a  2 s . co m*/
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad AdapterContextMenuInfo", e);
        return;
    }

    Cursor c = (Cursor) mTagListView.getAdapter().getItem(info.position);
    if (c == null) {
        return;
    }

    android.view.MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.context_menu_tag_list, menu);

    mTagName = c.getString(TagsQuery.TAGNAME);
    menu.setHeaderTitle(mTagName);

    Intent intent = new Intent(null, ContentUris.withAppendedId(Tags.CONTENT_URI, (int) info.id));

    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
            new ComponentName(getActivity(), TagListFragment.class), null, intent, 0, null);
}

From source file:com.kyakujin.android.tagnotepad.ui.NoteListFragment.java

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

    AdapterView.AdapterContextMenuInfo info;
    try {//from  w ww . ja  v a  2s.co m
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad AdapterContextMenuInfo", e);
        return;
    }

    Cursor c = (Cursor) mNoteListView.getAdapter().getItem(info.position);
    if (c == null) {
        return;
    }

    android.view.MenuInflater inflater = getSherlockActivity().getMenuInflater();
    inflater.inflate(R.menu.context_menu_note_list, menu);

    menu.setHeaderTitle(c.getString(NotesQuery.TITLE));

    Intent intent = new Intent(null, ContentUris.withAppendedId(Notes.CONTENT_URI, (int) info.id));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);

    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
            new ComponentName(getSherlockActivity(), NoteListFragment.class), null, intent, 0, null);
}

From source file:com.kyakujin.android.autoeco.ui.MainActivity.java

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

    AdapterView.AdapterContextMenuInfo info;
    try {// ww  w  .  j  ava2  s  .c om
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad AdapterContextMenuInfo", e);
        return;
    }

    android.view.MenuInflater inflater = this.getMenuInflater();
    inflater.inflate(R.menu.context_menu_schedlist, menu);

    menu.setHeaderTitle(getResources().getString(R.string.label_menu));

    Intent intent = new Intent(null, ContentUris.withAppendedId(SchedTbl.CONTENT_URI, (int) info.id));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);

    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(mActivity, MainActivity.class),
            null, intent, 0, null);
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private void addUriSpecificMenuItems(ContextMenu menu, View v, int position) {
    Uri uri = getSelectedUriFromMessageList((ListView) v, position);

    if (uri != null) {
        Intent intent = new Intent(null, uri);
        intent.addCategory(Intent.CATEGORY_SELECTED_ALTERNATIVE);
        menu.addIntentOptions(0, 0, 0, new android.content.ComponentName(this, ComposeMessageActivity.class),
                null, intent, 0, null);//from   w  ww  .j av  a 2s . c o m
    }
}