Example usage for android.view MenuItem getMenuInfo

List of usage examples for android.view MenuItem getMenuInfo

Introduction

In this page you can find the example usage for android.view MenuItem getMenuInfo.

Prototype

public ContextMenuInfo getMenuInfo();

Source Link

Document

Gets the extra information linked to this menu item.

Usage

From source file:org.mariotaku.twidere.fragment.AbsStatusesFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (!getUserVisibleHint())
        return false;
    final ExtendedRecyclerView.ContextMenuInfo contextMenuInfo = (ExtendedRecyclerView.ContextMenuInfo) item
            .getMenuInfo();/*www .j av  a  2 s  .c  om*/
    final ParcelableStatus status = getAdapter().getStatus(contextMenuInfo.getPosition());
    if (status == null)
        return false;
    if (item.getItemId() == R.id.share) {
        final Intent shareIntent = Utils.createStatusShareIntent(getActivity(), status);
        final Intent chooser = Intent.createChooser(shareIntent, getString(R.string.share_status));
        Utils.addCopyLinkIntent(getContext(), chooser, LinkCreator.getStatusWebLink(status));
        startActivity(chooser);
        return true;
    }
    return MenuUtils.handleStatusClick(getActivity(), this, getFragmentManager(), mUserColorNameManager,
            mTwitterWrapper, status, item);
}

From source file:org.mklab.mikity.android.SceneGraphTreeFragment.java

/**
 * {@inheritDoc}/*from   w ww .ja va2s  .  c  om*/
 */
@Override
public boolean onContextItemSelected(MenuItem item) {
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    int position = info.position;

    int itemId = item.getItemId();

    if (itemId == CONTEXT_MENU_CUT) {
        cutSelectedItem();
        return true;
    }
    if (itemId == CONTEXT_MENU_COPY) {
        copySelectedItem();
        return true;
    }
    if (itemId == CONTEXT_MENU_PASTE) {
        pasteBufferedObjectToSelectedItem();
        return true;
    }
    if (itemId == CONTEXT_MENU_DELETE) {
        deleteSelectedItem();
        return true;
    }
    if (itemId == CONTEXT_MENU_EDIT) {
        editSelectedItem();
        return true;
    }
    //    if (itemId == CONTEXT_MENU_TRANSFORM) {
    //      return true;
    //    }

    return super.onContextItemSelected(item);
}

From source file:com.cerema.cloud2.ui.fragment.OCFileListFragment.java

/**
 * {@inhericDoc}//from  w  ww. j  a  v a 2  s.co m
 */
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    boolean matched = onFileActionChosen(item.getItemId(),
            ((AdapterContextMenuInfo) item.getMenuInfo()).position);
    if (!matched) {
        return super.onContextItemSelected(item);
    } else {
        return matched;
    }
}

From source file:com.money.manager.ex.common.CategoryListFragment.java

@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) item
            .getMenuInfo();//from  w ww  . j  a  v  a  2s.co m

    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    int child = ExpandableListView.getPackedPositionChild(info.packedPosition);

    CategorySub categoryIds = new CategorySub();
    categoryIds.categId = Constants.NOT_SET;
    categoryIds.categName = "";
    categoryIds.subCategId = Constants.NOT_SET;
    categoryIds.subCategName = "";

    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        categoryIds.categId = mCategories.get(group).getId();
        categoryIds.categName = mCategories.get(group).getName();
    } else if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        categoryIds.categId = mSubCategories.get(mCategories.get(group)).get(child).getCategId();
        categoryIds.subCategId = mSubCategories.get(mCategories.get(group)).get(child).getSubCategId();
        categoryIds.subCategName = mSubCategories.get(mCategories.get(group)).get(child).getSubcategoryName()
                .toString();
    }
    // manage select menu
    ContextMenuIds menuId = ContextMenuIds.get(item.getItemId());
    switch (menuId) {
    case EDIT:
        if (categoryIds.subCategId == ExpandableListView.INVALID_POSITION) {
            showDialogEditCategoryName(SQLTypeTransaction.UPDATE, categoryIds.categId, categoryIds.categName);
        } else {
            showDialogEditSubCategoryName(SQLTypeTransaction.UPDATE, categoryIds.categId,
                    categoryIds.subCategId, categoryIds.subCategName);
        }
        break;

    case DELETE:
        showDialogDeleteCategorySub(categoryIds);
        break;

    case VIEW_TRANSACTIONS: // view transactions
        SearchParameters parameters = new SearchParameters();
        parameters.category = categoryIds;

        showSearchActivityFor(parameters);
    }
    return false;
}

From source file:org.geometerplus.android.fbreader.TOCActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position;
    BaseAdapter adapter = null;/*from w  w  w  . j  av a2  s. c o m*/
    if (isBookMark) {//?
        adapter = bookmarkAdapter;
    } else {
        adapter = myThisBookAdapter;
    }

    final Bookmark bookmark = (Bookmark) adapter.getItem(position);
    switch (item.getItemId()) {
    case OPEN_ITEM_ID://
        gotoBookmark(bookmark);
        return true;
    case EDIT_ITEM_ID://
        final Intent intent = new Intent(this, BookmarksEditActivity.class);
        intent.putExtra("bgColor", bgValue);
        intent.putExtra("type", true);
        FBReaderIntents.putBookmarkExtra(intent, bookmark);
        OrientationUtil.startActivity(this, intent);
        return true;
    case DELETE_ITEM_ID://
        myCollection.deleteBookmark(bookmark);
        FBReaderWindowUtil.deleteBookmarkForIdea_Table(bookmark);
        if (isBookMark) {
            bookmarkAdapter.myBookmarksList.remove(bookmark);
            bookmarkAdapter.notifyDataSetChanged();
            if (bookmarkAdapter.myBookmarksList.size() == 0) {
                emptyRl.setVisibility(View.VISIBLE);
                markLv.setVisibility(View.INVISIBLE);
            }
        }
        return true;
    }
    return super.onContextItemSelected(item);
}

From source file:uk.co.massimocarli.friendfence.location.FenceSessionListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // We get the object that contains the information for the selected item
    AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    // We get the position and the id
    final int position = menuInfo.position;
    final long sessionId = menuInfo.id;
    // We execute the related operation
    final int selectedItemId = item.getItemId();
    // We use if and not switch because preventing usage into libraries
    if (R.id.session_context_delete_menu_item == selectedItemId) {
        // We delete the related session in async way
        deleteSessionData(sessionId, position);
    } else if (R.id.session_context_view_menu_item == selectedItemId) {
        // We want to view the item
        viewSessionData(sessionId, position);
    } else if (R.id.session_context_edit_menu_item == selectedItemId) {
        // We want to edit the item
        editSessionData(sessionId, position);
    } else if (R.id.session_context_edit_show_map == selectedItemId) {
        // Show the FenceSession in Map
        showInMap(sessionId);/*from www  . j av a 2s  .  c  o m*/
    } else if (R.id.session_context_show_street_view == selectedItemId) {
        // Show the FenceSession in StreetView
        showInStreetView(sessionId);
    } else if (R.id.session_context_export == selectedItemId) {
        // We export the information of the session
        //exportFenceSession(sessionId);
        exportDirectFenceSession(sessionId);
        //searchFenceSessionFiles();
    }
    return super.onContextItemSelected(item);
}

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

@Override
public boolean onMenuItemClick(final MenuItem item) {
    switch (item.getGroupId()) {
    case ADD_REPLACE_PLAY:
    case ADD_REPLACE:
    case ADD:/*from  www .  j av  a2 s  .com*/
    case ADD_PLAY:
        addAndReplace(item);
        break;
    case ADD_TO_PLAYLIST:
        addToPlaylist(item);
        break;
    case GOTO_ARTIST:
        final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        final Object selectedItem = mItems.get((int) info.id);
        final Intent intent = new Intent(getActivity(), SimpleLibraryActivity.class);
        Artist artist = null;

        if (selectedItem instanceof Album) {
            artist = ((AbstractAlbum) selectedItem).getArtist();
        } else if (selectedItem instanceof Artist) {
            artist = (Artist) selectedItem;
        } else if (selectedItem instanceof Music) {
            artist = new Artist(((AbstractMusic) selectedItem).getAlbumArtistOrArtist());
        }

        if (artist != null) {
            intent.putExtra("artist", artist);
            startActivityForResult(intent, -1);
        }
        break;
    default:
        final String name = item.getTitle().toString();
        final int id = item.getOrder();
        mApp.oMPDAsyncHelper.execAsync(new Runnable() {
            @Override
            public void run() {
                add(mItems.get(id), name);
            }
        });
        break;
    }
    return false;
}

From source file:com.plined.liftlog.RoutineListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {

    //Figure out if they hit the delete button
    switch (item.getItemId()) {
    case R.id.menu_item_delete_routine: {
        //Trying to delete.
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        int position = info.position;

        //Figure out which we're trying to delete
        RoutineCursorAdapter adapter = (RoutineCursorAdapter) getListAdapter();
        RoutineCursor rotCursor = (RoutineCursor) adapter.getItem(position);
        Routine rotDel = rotCursor.getRoutine();

        //Launch a delete confirm dialog.
        //Create the fragment. We'll attach our current routine ID with it so it knows what to edit.
        DeleteRoutineConfirmDialog fragToUse = DeleteRoutineConfirmDialog.newInstance(rotDel.getId());

        //Launch this fragment.
        launchDialogFragmentTarget(fragToUse, "deleteroutineconfirm", REQUEST_DELETE_ROUTINE);

        return true;
    }/*from   w w w. jav a2 s.  c  o m*/
    //      //TODO: REIMPLEMENT ROUITINE COPYING
    //      case R.id.menu_item_copy_routine: {
    //         //Trying to copy a routine.
    //         AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
    //         int position = info.position;
    //         
    //         //Figure out which we're trying to copy
    //         /*
    //          * The reason we do position-1 here is because the header we added here takes up position 0. So
    //          * everything else is off by 1.
    //          */
    //         RoutineCursorAdapter adapter = (RoutineCursorAdapter)getListAdapter();
    //         RoutineCursor rotCursor = (RoutineCursor) adapter.getItem(position-1);
    //         Routine rotCopy = rotCursor.getRoutine();
    //         
    //         //Launch a copy dialog.
    //         //Create the fragment. We'll attach our current routine ID with it so it knows what the routine
    //         //to source exercises from is.
    //         CopyRoutineDialog fragToUse = CopyRoutineDialog.newInstance(rotCopy.getId());
    //         
    //         //Launch this fragment.
    //         launchDialogFragmentTarget(fragToUse, "copyroutinenameselect", REQUEST_COPY_ROUTINE);
    //         
    //         return true;
    //      }
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.ale.scanner.zotero.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.ctx_edit:
        ExpandableListContextMenuInfo einfo = (ExpandableListContextMenuInfo) item.getMenuInfo();

        int index = (int) einfo.id;
        BibItem toEdit = (BibItem) mItemAdapter.getGroup(index);
        Intent intent = new Intent(MainActivity.this, EditItemActivity.class);
        intent.putExtra(EditItemActivity.INTENT_EXTRA_BIBITEM, toEdit);
        intent.putExtra(EditItemActivity.INTENT_EXTRA_INDEX, index);
        startActivityForResult(intent, RESULT_EDIT);
        break;/*  w w w.j  ava  2  s  .  c  om*/
    case R.id.ctx_delete:
        ExpandableListContextMenuInfo dinfo = (ExpandableListContextMenuInfo) item.getMenuInfo();
        mItemAdapter.deleteItem((BibItem) mItemAdapter.getGroup((int) dinfo.id));
        break;
    case R.id.ctx_cancel:
        AdapterContextMenuInfo cinfo = (AdapterContextMenuInfo) item.getMenuInfo();

        mPendingAdapter.remove(mPendingAdapter.getItem(cinfo.position));
        if (mPendingAdapter.getCount() == 0)
            mPendingList.setVisibility(View.GONE);
        redrawPendingList();
        break;
    case R.id.ctx_retry:
        AdapterContextMenuInfo rinfo = (AdapterContextMenuInfo) item.getMenuInfo();
        String ident = mPendingAdapter.getItem(rinfo.position);
        if (mPendingAdapter.getStatus(ident) != PendingListAdapter.STATUS_LOADING) {
            mPendingAdapter.remove(ident);
            lookupISBN(ident);
        }
    default:
        return super.onContextItemSelected(item);
    }
    return true;
}

From source file:com.ultramegasoft.flavordex2.fragment.EntryListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final Context context = getContext();

    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    final Cursor cursor = (Cursor) mAdapter.getItem(info.position);

    switch (item.getItemId()) {
    case R.id.menu_share:
        if (context != null && cursor != null) {
            final String title = cursor.getString(cursor.getColumnIndex(Tables.Entries.TITLE));
            final float rating = cursor.getFloat(cursor.getColumnIndex(Tables.Entries.RATING));
            EntryUtils.share(context, title, rating);
        }// www  .  j  a va2  s  .c  o  m
        return true;
    case R.id.menu_edit_entry:
        if (context != null && cursor != null) {
            EditEntryActivity.startActivity(context, info.id,
                    cursor.getString(cursor.getColumnIndex(Tables.Entries.CAT)));
        }
        return true;
    case R.id.menu_delete_entry:
        if (cursor != null) {
            final FragmentManager fm = getFragmentManager();
            if (fm != null) {
                final String title = cursor.getString(cursor.getColumnIndex(Tables.Entries.TITLE));
                final Intent deleteIntent = new Intent();
                deleteIntent.putExtra(EXTRA_ENTRY_ID, info.id);
                ConfirmationDialog.showDialog(fm, this, REQUEST_DELETE_ENTRY,
                        getString(R.string.title_delete_entry),
                        getString(R.string.message_confirm_delete, title), R.drawable.ic_delete, deleteIntent);
            }
        }
        return true;
    }
    return super.onContextItemSelected(item);
}