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:com.orangelabs.rcs.ri.messaging.chat.single.SingleChatView.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Cursor cursor = (Cursor) (mAdapter.getItem(info.position));
    int providerId = cursor.getInt(cursor.getColumnIndexOrThrow(HistoryLog.PROVIDER_ID));
    String messageId = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.ID));
    if (LogUtils.isActive) {
        Log.d(LOGTAG, "onContextItemSelected Id=".concat(messageId));
    }/*www  .j a v  a  2s  . c  om*/
    switch (item.getItemId()) {
    case MENU_ITEM_RESEND:
        try {
            if (ChatLog.Message.HISTORYLOG_MEMBER_ID == providerId) {
                mChat.resendMessage(messageId);
            } else {
                FileTransfer fileTransfer = mFileTransferService.getFileTransfer(messageId);
                if (fileTransfer != null) {
                    fileTransfer.resendTransfer();
                }
            }
        } catch (RcsServiceException e) {
            showException(e);
        }
        return true;

    case MENU_ITEM_DELETE:
        try {
            if (ChatLog.Message.HISTORYLOG_MEMBER_ID == providerId) {
                mChatService.deleteMessage(messageId);
            } else {
                mFileTransferService.deleteFileTransfer(messageId);
            }
        } catch (RcsServiceException e) {
            showException(e);
        }
        return true;

    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.cowboycoders.cyclisimo.BikeListActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // ((AdapterContextMenuInfo) item.getMenuInfo()).position)
    if (item != null
            && handleContextItem(item.getItemId(), ((AdapterContextMenuInfo) item.getMenuInfo()).position)) {
        return true;
    }/*from  ww w  .  j a  v a 2  s .c om*/
    return super.onContextItemSelected(item);
}

From source file:com.shinymayhem.radiopresets.FragmentStations.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    boolean handled = false;
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.delete_station:
        long[] ids = { (long) info.id };
        delete(ids);//from ww w  .j a v a  2 s.c om
        handled = true;
        break;
    case R.id.edit_station:
        edit(info.position);
        handled = true;
        break;
    default:
        throw new IllegalArgumentException("Unknown context menu item");
    }
    if (handled) {
        //mode.finish();
        //mActionMode = null;
    }
    return handled;
    //return super.onContextItemSelected(item);
}

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {
    case R.id.cmenu_dlist_delete:
        ClaimListController.removeDestination(destAdaptor.getItem(info.position), theClaim);
        destAdaptor.notifyDataSetChanged();
        return true;
    case R.id.cmenu_dlist_edit:
        //show a dialog for editing destinations 
        final EditText enterLocation = new EditText(this);
        final EditText enterReason = new EditText(this);

        enterLocation.setText(destAdaptor.getItem(info.position).getLocation());
        enterReason.setText(destAdaptor.getItem(info.position).getReason());

        enterLocation.setHint("Enter location");
        enterReason.setHint("Enter reason");

        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout.addView(enterLocation);
        linearLayout.addView(enterReason);

        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setView(linearLayout);/*ww w  .j  a  v  a 2  s.  c  om*/

        alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                destAdaptor.getItem(info.position).setLocation(enterLocation.getText().toString());
                destAdaptor.getItem(info.position).setReason(enterReason.getText().toString());
                destAdaptor.notifyDataSetChanged();
            }
        });
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });

        alert.show();
        return true;

    case R.id.cmenu_dlist_geolocation:
        adaptorPos = info.position;
        AlertDialog.Builder alertGl = new AlertDialog.Builder(this);
        alertGl.setPositiveButton("GPS", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (GeoLocationController.checkGPSEnabled()) {
                    GeoLocationController.setDestinationGeoLocationGPS(destAdaptor.getItem(info.position));
                    destAdaptor.notifyDataSetChanged();
                }
            }
        });
        alertGl.setNegativeButton("Map", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Open map view \
                Intent intent = GeoLocationController.pickLocationIntent(EditClaimActivity.this);
                startActivityForResult(intent, GET_GEOLOCATION_CODE);
            }
        });

        alertGl.show();
        return true;
    case R.id.cmenu_delete_tag:
        ClaimListController.removeTag(theClaim, tagAdaptor.getItem(info.position));
        tagAdaptor.notifyDataSetChanged();
        return true;
    case R.id.cmenu_rename_tag:
        //create a Alert dialog for editing tag name
        final TextView enterTag = new AutoCompleteTextView(this);

        enterTag.setHint("Enter tag");

        AlertDialog.Builder alertTag = new AlertDialog.Builder(this);

        alertTag.setView(enterTag);

        alertTag.setPositiveButton("Add", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                tagAdaptor.getItem(info.position).setName(enterTag.getText().toString());
                tagAdaptor.notifyDataSetChanged();
            }
        });
        alertTag.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });

        alertTag.show();

        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.nttec.everychan.ui.BoardsListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    try {//from  w ww . j a  va2s  . co  m
        if (item.getItemId() == R.id.context_menu_favorites_from_fragment) {
            String url = chan.buildUrl(getUrlModel(adapter.getItem(menuInfo.position).model.boardName));
            UrlPageModel model = UrlHandler.getPageModel(url);
            if (model != null) {
                if (database.isFavorite(model.chanName, model.boardName, Integer.toString(model.boardPage),
                        null)) {
                    database.removeFavorite(model.chanName, model.boardName, Integer.toString(model.boardPage),
                            null);
                } else {
                    database.addFavorite(model.chanName, model.boardName, Integer.toString(model.boardPage),
                            null, getString(R.string.tabs_title_boardpage_first, model.boardName), url);
                }
                updateListSavePosition();
                return true;
            }
        } else if (item.getItemId() == R.id.context_menu_quickaccess_add) {
            QuickAccess.Entry newEntry = new QuickAccess.Entry();
            newEntry.chan = chan;
            SimpleBoardModel simleBoardModel = adapter.getItem(menuInfo.position).model;
            newEntry.boardName = simleBoardModel.boardName;
            newEntry.boardDescription = simleBoardModel.boardDescription;
            quickAccessList.add(0, newEntry);
            QuickAccess.saveQuickAccessToPreferences(quickAccessList);
            return true;
        }
    } catch (Exception e) {
        Logger.e(TAG, e);
    }
    return false;
}

From source file:com.ovrhere.android.currencyconverter.ui.fragments.MainFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() == Menu.CATEGORY_SECONDARY) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        switch (item.getItemId()) {
        case 0:// w  w w .j  a  v  a  2  s. c om
            int pos1 = info.position;
            copyConvertedValue(pos1, false);
            break;
        case 1:
            int pos2 = info.position;
            copyConvertedValue(pos2, true);
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.code.android.vibevault.ShowDetailsScreen.java

/** Handle user's long-click selection.
*
*//*from www  .  ja va  2  s  . c  om*/
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    if (menuInfo != null) {
        ArchiveSongObj selSong = (ArchiveSongObj) trackList.getAdapter().getItem(menuInfo.position);
        switch (item.getItemId()) {
        case (VibeVault.STREAM_CONTEXT_ID):
            // Start streaming.
            int track = pService.enqueue(selSong);
            pService.playSongFromPlaylist(track);
            break;
        case (VibeVault.DOWNLOAD_SONG):
            selSong.setDownloadShow(show);
            dService.addSong(selSong);
            break;
        case (VibeVault.ADD_SONG_TO_QUEUE):
            pService.enqueue(selSong);
            break;
        case (VibeVault.EMAIL_LINK):
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Great song on archive.org: " + selSong.toString());
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                    "Hey,\n\nI found a song you should listen to.  It's called " + selSong.toString()
                            + " and it's off of " + selSong.getShowTitle() + ".  You can get it here: "
                            + selSong.getLowBitRate() + "\n\nSent using VibeVault for Android.");
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
            break;
        default:
            return false;
        }
        return true;
    }
    return false;
}

From source file:sjizl.com.FileUploadTest.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int index = info.position;
    String textTocopy = stock_list3.get(index);

    switch (item.getItemId()) {
    case R.id.rotate_left:
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();
        naam_to_delete = stock_list.get(info.position);

        new RotateToLeft().execute();
        //  Toast.makeText(getApplicationContext(), "Rotate left"+naam_to_delete, Toast.LENGTH_SHORT).show();
        return true;

    case R.id.rotate_right:
        naam_to_delete = stock_list.get(info.position);
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();
        new RotateToRight().execute();
        //  Toast.makeText(getApplicationContext(), "Rotate right"+naam_to_delete, Toast.LENGTH_SHORT).show();

        return true;

    case R.id.profile_photo:
        fid_to_set = stock_list7.get(info.position);

        //   Toast.makeText(getApplicationContext(), "profile_photo:"+stock_list7.get(info.position)+":fid_to_set"+fid_to_set, Toast.LENGTH_SHORT).show();
        //   quoteResult.remove(info.position);
        //   ((StockQuoteAdapter)getListAdapter()).notifyDataSetChanged();
        new SetAsProfilePhoto().execute();
        //  Toast.makeText(getApplicationContext(), "Rotate right"+naam_to_delete, Toast.LENGTH_SHORT).show();

        return true;
    }//from w w  w  .  j a  v a  2  s.  co  m
    return false;
}

From source file:de.elanev.studip.android.app.widget.UserListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // Workaround: Check if tab is visible, else pass call to the next tab
    if (getUserVisibleHint()) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        int itemId = item.getItemId();

        // Get userInfo from cursor
        Cursor c = (Cursor) mListView.getAdapter().getItem(info.position);
        String userId = c.getString(c.getColumnIndex(UsersContract.Columns.USER_ID));

        int userIntId = c.getInt(c.getColumnIndex(UsersContract.Columns._ID));

        switch (itemId) {
        // add to or remove user from favorites
        case R.id.add_to_favorites: {
            String favGroupId = null;
            Cursor favCursor1 = mContext.getContentResolver().query(ContactsContract.CONTENT_URI_CONTACT_GROUPS,
                    new String[] { ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_ID },
                    ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_NAME + "= ?",
                    new String[] { mContext.getString(R.string.studip_app_contacts_favorites) },
                    ContactsContract.DEFAULT_SORT_ORDER_CONTACT_GROUPS);
            if (favCursor1.getCount() > 0) {
                favCursor1.moveToFirst();
                favGroupId = favCursor1//from   www.  j av  a2 s.  c  o m
                        .getString(favCursor1.getColumnIndex(ContactsContract.Columns.ContactGroups.GROUP_ID));
            }
            favCursor1.close();

            addUserToGroup(userId, favGroupId, mContext);
            return true;
        }
        case R.id.remove_from_favorites: {
            String favGroupId = null;
            int favGroupIntId = 0;
            Cursor favCursor2 = mContext.getContentResolver().query(ContactsContract.CONTENT_URI_CONTACT_GROUPS,
                    new String[] { ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_ID,
                            ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_ID },
                    ContactsContract.Qualified.ContactGroups.CONTACT_GROUPS_GROUP_NAME + "= ?",
                    new String[] { mContext.getString(R.string.studip_app_contacts_favorites) },
                    ContactsContract.DEFAULT_SORT_ORDER_CONTACT_GROUPS);
            if (favCursor2.getCount() > 0) {
                favCursor2.moveToFirst();
                favGroupId = favCursor2
                        .getString(favCursor2.getColumnIndex(ContactsContract.Columns.ContactGroups.GROUP_ID));
                favGroupIntId = favCursor2
                        .getInt(favCursor2.getColumnIndex(ContactsContract.Columns.ContactGroups._ID));
            }
            favCursor2.close();

            deleteUserFromGroup(userId, favGroupId, favGroupIntId, userIntId, mContext);
            return true;
        }

        // add to or remove from contacts
        case R.id.add_to_contacts: {
            addUserToContacts(userId, mContext);
            return true;
        }
        case R.id.remove_from_contacts: {
            deleteUserFromContacts(userId, mContext);
            return true;
        }
        case R.id.manage_groups: {
            Bundle args = new Bundle();
            args.putString(ContactsContract.Columns.Contacts.USER_ID, userId);
            args.putInt(ContactsContract.Columns.Contacts._ID, userIntId);
            ContactGroupsDialogFragment frag = (ContactGroupsDialogFragment) ContactGroupsDialogFragment
                    .instantiate(mContext, ContactGroupsDialogFragment.class.getName());
            frag.setArguments(args);
            getFragmentManager().beginTransaction().add(frag, ContactGroupsDialogFragment.class.getName())
                    .commit();
            return true;
        }

        default:
            return super.onContextItemSelected(item);
        }
    } else {
        return false;
    }

}

From source file:com.projects.nosleepreader.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (mFrag.scrollLoading) {
        Toast.makeText(this, LOADING_TOAST_TEXT, Toast.LENGTH_SHORT);
        return true;
    }//from  ww w .j ava  2s.co  m
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int id = item.getItemId();
    switch (id) {
    case R.id.copy_url:
        ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("label",
                mValuesArray.get(info.position).getAsString(ListingDbHelper.COLUMN_URL));
        clipboard.setPrimaryClip(clip);
        break;
    case R.id.context_menu_favorite:
        if (mCurrentTable.equals(ListingDbHelper.TABLE_NAME_FAVORITES)) {
            mPosition = (info.position - 1 >= 0) ? info.position - 1 : 0;
            mDbHelper.deleteFavoites(mValuesArray.get(info.position).getAsString(ListingDbHelper.COLUMN_ID));
            mFrag.getFavorites(mValuesArray);
        } else
            mDbHelper.insertFavorites(mValuesArray.get(info.position));
        break;
    case R.id.context_menu_author:
        String author = mValuesArray.get(info.position).getAsString(ListingDbHelper.COLUMN_AUTHOR);
        getSupportActionBar().setTitle("Submissions By " + author);
        firstRun = true;
        mCurrentTable = CURRENT_AUTHOR_TAG;
        mAuthor = "author:" + author;
        resetList();
        mFrag.getAuthor(mAfter, mValuesArray, count, mAuthor);
    }
    return super.onContextItemSelected(item);
}