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.andrewshu.android.reddit.mail.InboxListActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    int rowId = (int) info.id;
    ThingInfo item = mMessagesAdapter.getItem(rowId);

    // Mark the message/comment as selected
    mVoteTargetThingInfo = item;//from  w w  w  .j a va  2  s. co m
    mVoteTargetView = v;
    mReplyTargetName = item.getName();

    if (item.isWas_comment()) {
        // TODO: include the context!
        menu.add(0, Constants.DIALOG_COMMENT_CLICK, Menu.NONE, "Go to comment");
    } else {
        menu.add(0, Constants.DIALOG_MESSAGE_CLICK, Menu.NONE, "Reply");
    }
}

From source file:com.piusvelte.sonet.core.SonetNotifications.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    // create clearing option
    menu.add(0, CLEAR, 0, R.string.clear);
}

From source file:cm.aptoide.pt.ManageRepos.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    Log.d("Aptoide-ManageRepos", "oncreateContext view: " + view.toString());
    final int repoHashid = Integer.parseInt(view.findViewById(R.id.repo_hashid).getTag().toString());
    if (!reposInserting.containsKey(repoHashid)) {
        super.onCreateContextMenu(menu, view, menuInfo);

        menu.setHeaderTitle(getString(R.string.options));
        menu.add(0, popupOptions.EDIT_REPO.ordinal(), 0, getString(R.string.edit));
        menu.add(0, popupOptions.REMOVE_REPO.ordinal(), 0, getString(R.string.remove));
    }/*  www .j  a  v  a 2  s .c o  m*/
}

From source file:com.edible.ocr.CaptureActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (v.equals(ocrResultView)) {
        menu.add(Menu.NONE, OPTIONS_COPY_RECOGNIZED_TEXT_ID, Menu.NONE, "Copy recognized text");
        menu.add(Menu.NONE, OPTIONS_SHARE_RECOGNIZED_TEXT_ID, Menu.NONE, "Share recognized text");
    } else if (v.equals(translationView)) {
        menu.add(Menu.NONE, OPTIONS_COPY_TRANSLATED_TEXT_ID, Menu.NONE, "Copy translated text");
        menu.add(Menu.NONE, OPTIONS_SHARE_TRANSLATED_TEXT_ID, Menu.NONE, "Share translated text");
    }/*from   w w  w . j  ava2 s.  c  om*/
}

From source file:com.pdftron.pdf.controls.AnnotationDialogFragment.java

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

    if (v.getId() == R.id.control_annotation_listview) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        AnnotationInfo item = mAnnotationListAdapter.getItem(info.position);
        String title = String.format(getResources().getString(R.string.controls_annotation_dialog_page),
                item.getPageNum());/*w ww. j  a v  a  2  s. co m*/
        if (item.getAuthor() != null && !item.getAuthor().isEmpty()) {
            title = title + " " + getResources().getString(R.string.controls_annotation_dialog_author) + " "
                    + item.getAuthor();
        }
        menu.setHeaderTitle(title);
        String[] menuItems = getResources().getStringArray(R.array.annotation_dialog_context_menu);
        menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ITEM, CONTEXT_MENU_DELETE_ITEM,
                menuItems[CONTEXT_MENU_DELETE_ITEM + 1]);
        if (mDebug) {
            // Convenient for debugging
            menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ITEM_ONPAGE, CONTEXT_MENU_DELETE_ITEM_ONPAGE,
                    menuItems[CONTEXT_MENU_DELETE_ITEM_ONPAGE + 1]);
            menu.add(Menu.NONE, CONTEXT_MENU_DELETE_ALL, CONTEXT_MENU_DELETE_ALL,
                    menuItems[CONTEXT_MENU_DELETE_ALL + 1]);
        }
        MenuItem.OnMenuItemClickListener listener = new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                onContextItemSelected(item);
                return true;
            }
        };
        menu.getItem(CONTEXT_MENU_DELETE_ITEM).setOnMenuItemClickListener(listener);
        if (mDebug) {
            menu.getItem(CONTEXT_MENU_DELETE_ITEM_ONPAGE).setOnMenuItemClickListener(listener);
            menu.getItem(CONTEXT_MENU_DELETE_ALL).setOnMenuItemClickListener(listener);
        }
    }
}

From source file:edu.cmu.cylab.starslinger.view.MessagesFragment.java

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

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    if (v.equals(mListViewThreads)) {
        RecipientRow recip = mThreadList.get(info.position).getRecipient();
        String delThreadStr = String.format(getString(R.string.menu_deleteThread),
                ThreadsAdapter.getBestIdentityName(getActivity(), mThreadList.get(info.position), recip));
        menu.add(Menu.NONE, R.id.item_delete_thread, Menu.NONE, delThreadStr);
        if (recip != null && recip.getRowId() > -1
                && recip.getSource() != RecipientDbAdapter.RECIP_SOURCE_INVITED) {
            if (!recip.isValidContactLink()) {
                menu.add(Menu.NONE, R.id.item_link_contact_add, Menu.NONE, R.string.menu_link_contact_add);
            } else {
                menu.add(Menu.NONE, R.id.item_link_contact_change, Menu.NONE,
                        R.string.menu_link_contact_change);
            }//from w  ww  .j a v a 2 s .  c o  m

            if (recip.isValidContactLink()) {
                menu.add(Menu.NONE, R.id.item_edit_contact, Menu.NONE, R.string.menu_EditContact);
            }
        }
        menu.add(Menu.NONE, R.id.item_thread_details, Menu.NONE, R.string.menu_Details);
    } else if (v.equals(mListViewMsgs)) {
        MenuInflater inflater = getActivity().getMenuInflater();
        inflater.inflate(R.layout.messagecontext, menu);

        final String text = mMessageList.get(info.position).getText();
        final String file = mMessageList.get(info.position).getFileName();
        if (!TextUtils.isEmpty(text)) {
            menu.add(Menu.NONE, R.id.item_message_copytext, Menu.NONE, R.string.menu_messageCopyText);
        }
        if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(file)) {
            menu.add(Menu.NONE, R.id.item_message_forward, Menu.NONE, R.string.menu_messageForward);
        }
        menu.add(Menu.NONE, R.id.item_message_details, Menu.NONE, R.string.menu_Details);

        if (SafeSlingerConfig.isDebug()) {
            menu.add(Menu.NONE, R.id.item_debug_transcript, Menu.NONE, R.string.menu_debugTranscript);
        }
    }
}

From source file:org.path.episample.android.fragments.NavigateFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (v.getId() == android.R.id.list) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        MainMenuActivity.SELECTED_CENSUS = (((CensusListAdapter) getListAdapter()).getItem(info.position));

        if (MainMenuActivity.SELECTED_CENSUS != null) {
            menu.setHeaderTitle(MainMenuActivity.SELECTED_CENSUS.getHeadName() + " ("
                    + MainMenuActivity.SELECTED_CENSUS.getHouseNumber() + ")");
            menu.add(Menu.NONE, MENU_START_QUESTIONNAIRE, Menu.NONE,
                    getActivity().getString(R.string.start_questionnaire));
            if (mEditSavedData == true) {
                menu.add(Menu.NONE, MENU_EDIT_POINT, menu.NONE, getActivity().getString(R.string.edit_point));
            }//from  w  w w .  ja  va  2s  .  c  o  m

            if (mMarkAsFinalizedByFriends == true && MainMenuActivity.SELECTED_CENSUS.getProcessed() != 3) {
                menu.add(Menu.NONE, MENU_MARK_AS_FINALIZED_BY_FRIENDS, menu.NONE,
                        getActivity().getString(R.string.mark_as_finalized_by_friends));
            }
        }
    }
}

From source file:mp.teardrop.LibraryActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    if (view == mRoundPlayAllButton) {
        menu.add(MENU_GROUP_ROUND_BUTTON, MENU_PLAY_ALL, 0, R.string.play_all);
        menu.add(MENU_GROUP_ROUND_BUTTON, MENU_ENQUEUE_ALL, 0, R.string.enqueue_all);
    }// w  w  w  .  j av  a  2  s  . c  o m
}

From source file:at.jclehner.rxdroid.DrugListActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, final View v, ContextMenuInfo menuInfo) {
    final DoseView doseView = (DoseView) v;

    if (toastIfPastMaxHistoryAge(doseView.getDate()))
        return;//  w ww .ja  v a2 s  . c o m

    final Drug drug = doseView.getDrug();
    final int doseTime = doseView.getDoseTime();

    // menu.setHeaderIcon(android.R.drawable.ic_menu_agenda);
    menu.setHeaderTitle(drug.getName());

    // ////////////////////////////////////////////////

    // ////////////////////////////////////////////////

    final boolean wasDoseTaken = doseView.wasDoseTaken();
    if (wasDoseTaken) {
        menu.add(0, CMENU_REMOVE_DOSE, 0, R.string._title_mark_not_taken)
                .setOnMenuItemClickListener(new OnContextMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(android.view.MenuItem item) {
                        MutableFraction dose = new MutableFraction();
                        for (DoseEvent intake : Entries.findDoseEvents(drug, mCurrentDate, doseTime)) {
                            dose.add(intake.getDose());
                            Database.delete(intake);
                        }

                        drug.setCurrentSupply(drug.getCurrentSupply().plus(dose));
                        Database.update(drug);

                        return true;
                    }
                });
    } else {
        menu.add(0, CMENU_IGNORE_DOSE, 0, R.string._title_ignore_dose)
                .setOnMenuItemClickListener(new OnContextMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(android.view.MenuItem item) {
                        Database.create(new DoseEvent(drug, doseView.getDate(), doseTime));
                        return true;
                    }
                });
    }

    menu.add(0, CMENU_TAKE_DOSE, 0, R.string._title_mark_taken)
            .setOnMenuItemClickListener(new OnContextMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(android.view.MenuItem item) {
                    showDoseDialog(drug, doseView.getDate(), doseTime, true);
                    return true;
                }
            });

    final Intent editIntent = new Intent(this, DrugEditActivity.class);
    editIntent.setAction(Intent.ACTION_EDIT);
    editIntent.putExtra(DrugEditActivity.EXTRA_DRUG_ID, drug.getId());
    menu.add(0, CMENU_EDIT_DRUG, 0, R.string._title_edit_drug).setIntent(editIntent);

    if (BuildConfig.DEBUG) {
        menu.add(0, CMENU_DUMP, 0, "Dump").setOnMenuItemClickListener(new OnContextMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(android.view.MenuItem item) {
                Util.dumpObjectMembers(TAG, Log.VERBOSE, drug, drug.getName());
                return true;
            }
        });
    }
}

From source file:uk.co.droidinactu.ebooklauncher.EBookLauncherActivity.java

private void setupList(final HorizontialListView listview, final SimpleCursorAdapter listAdapter,
        final Cursor cursr) {
    if (cursr == null || cursr != null && cursr.getCount() == 0) {
        Toast.makeText(getApplication(), "No books available", Toast.LENGTH_LONG);
    } else {//  w  ww . java 2  s.co  m
        listview.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(final ContextMenu conMenu, final View v,
                    final ContextMenuInfo menuInfo) {
                final LinearLayout ll = (LinearLayout) ((HorizontialListView) v)
                        .getChildAt(((AdapterContextMenuInfo) menuInfo).position);
                final Drawable bookCover = ((ImageView) ll.getChildAt(0)).getDrawable();
                final String bookTitle = ((TextView) ll.getChildAt(1)).getText().toString();
                conMenu.setHeaderIcon(bookCover); // set to book cover
                conMenu.setHeaderTitle(bookTitle); // set to book title
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_VIEW_DETAILS, 0,
                        R.string.book_grid_context_item_view_book_details);
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_OPEN_BOOK, 1,
                        R.string.book_grid_context_item_open_book);
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_DELETE_BOOK, 2,
                        R.string.book_grid_context_item_delete_book);
            }
        });
        listview.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(final AdapterView<?> av, final View v, final int pos, final long id) {
                myApp.dataMdl.launchBook(EBookLauncherActivity.this, id);
            }

            @Override
            public void onNothingSelected(final AdapterView<?> arg0) {
            }
        });
        listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
                boolean retval = false;
                final int idColIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID);
                final int thumbColIndex = cursor.getColumnIndexOrThrow(DeviceFactory.getCoverImgColumnName());

                if (columnIndex == idColIndex) {
                    try {
                        final ImageView coverImg = (ImageView) view;
                        final String thumbnailFilename = cursor.getString(thumbColIndex);
                        final Bitmap bitmap = myApp.dataMdl.getBookCoverImg(EBookLauncherActivity.this,
                                thumbnailFilename);
                        coverImg.setImageDrawable(new BitmapDrawable(bitmap));
                        retval = true;
                    } catch (final Exception e) {
                        Log.e(EBookLauncherApplication.LOG_TAG, EBookLauncherActivity.LOG_TAG + "Exception ",
                                e);
                    }
                    retval = true;
                }
                return retval;
            }
        });
        listview.setAdapter(listAdapter);
        registerForContextMenu(listview);
        startManagingCursor(cursr);
    }
}