Example usage for android.view ContextMenu setHeaderTitle

List of usage examples for android.view ContextMenu setHeaderTitle

Introduction

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

Prototype

public ContextMenu setHeaderTitle(CharSequence title);

Source Link

Document

Sets the context menu header's title to the title given in title.

Usage

From source file:com.zen.androidhtmleditor.AHEActivity.java

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

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);

    String currentServers = settings.getString("Accounts", "");
    if (currentServers.equals("")) {
        menu.add(0, v.getId(), 0, "No Accounts");
    } else {// w w  w .j a va2  s.com
        Gson gson = new Gson();
        SearchResponse response = gson.fromJson(currentServers, SearchResponse.class);
        List<Result> results = response.data;
        int menuCount = 0;
        for (Result l : results) {
            String accName = l.serverName;
            if (l.accountName != null && l.accountName.length() > 0) {
                accName = l.accountName;
            }
            menu.add(menuCount, v.getId(), menuCount, accName);
            menuCount++;
        }

    }
    //menu.add(0, v.getId(), 0, "zenstudio.com.au");  
    //menu.add(0, v.getId(), 0, "Action 2");  
}

From source file:edu.chalmers.dat255.audiobookplayer.view.BookshelfFragment.java

@SuppressWarnings("rawtypes")
@Override/* w ww  .  jav  a  2  s.c o  m*/
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    // check that the menuInfo is of the correct type
    // this method is allowed to have quite a high cyclomatic complexity as
    // it would otherwise cause code duplication

    if (menuInfo instanceof ExpandableListContextMenuInfo && adapter != null) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
        // get the provided book position
        int bookIndex = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        // trackIndex will be -1 if group is clicked
        int trackIndex = ExpandableListView.getPackedPositionChild(info.packedPosition);
        // get the type of the context menu
        int type = ExpandableListView.getPackedPositionType(info.packedPosition);
        // create an empty array to prevent trying to loop over an
        // uninitialized variable
        IContextMenuItem[] menuItems = new IContextMenuItem[0];
        String title = "";
        // fill the context menu with the correct items
        if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
            // get all menu items from the child context menu
            menuItems = ChildContextMenuItem.values();
            // set the context menu's title to that of the value of the
            // child
            title = adapter.getChild(bookIndex, trackIndex);

        } else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
            // get all menu items from the group context menu
            menuItems = GroupContextMenuItem.values();
            // set the context menu's title to that of the value of the book
            title = adapter.getGroup(bookIndex);
        }
        // set the title
        menu.setHeaderTitle(title);
        // populate the context menu with items in the order they were
        // declared in the enum declaration.
        for (IContextMenuItem item : menuItems) {
            // as this only loops when menuItems is of either of type
            // GroupContextMenuItem[] or ChildContextMenuItem[], Enum can be
            // used as a raw type
            menu.add(Menu.NONE, ((Enum) item).ordinal(), ((Enum) item).ordinal(), item.getText());
        }
    }
}

From source file:cgeo.geocaching.CacheDetailActivity.java

@Override
public void onCreateContextMenu(final ContextMenu menu, final View view,
        final ContextMenu.ContextMenuInfo info) {
    super.onCreateContextMenu(menu, view, info);
    final int viewId = view.getId();
    switch (viewId) {
    case R.id.waypoint:
        menu.setHeaderTitle(selectedWaypoint.getName() + " (" + res.getString(R.string.waypoint) + ")");
        getMenuInflater().inflate(R.menu.waypoint_options, menu);
        final boolean isOriginalWaypoint = selectedWaypoint.getWaypointType() == WaypointType.ORIGINAL;
        menu.findItem(R.id.menu_waypoint_reset_cache_coords).setVisible(isOriginalWaypoint);
        menu.findItem(R.id.menu_waypoint_edit).setVisible(!isOriginalWaypoint);
        menu.findItem(R.id.menu_waypoint_duplicate).setVisible(!isOriginalWaypoint);
        menu.findItem(R.id.menu_waypoint_delete).setVisible(!isOriginalWaypoint);
        final boolean hasCoords = selectedWaypoint.getCoords() != null;
        final MenuItem defaultNavigationMenu = menu.findItem(R.id.menu_waypoint_navigate_default);
        defaultNavigationMenu.setVisible(hasCoords);
        defaultNavigationMenu.setTitle(NavigationAppFactory.getDefaultNavigationApplication().getName());
        menu.findItem(R.id.menu_waypoint_navigate).setVisible(hasCoords);
        menu.findItem(R.id.menu_waypoint_caches_around).setVisible(hasCoords);
        menu.findItem(R.id.menu_waypoint_copy_coordinates).setVisible(hasCoords);
        final boolean canClearCoords = hasCoords
                && (selectedWaypoint.isUserDefined() || selectedWaypoint.isOriginalCoordsEmpty());
        menu.findItem(R.id.menu_waypoint_clear_coordinates).setVisible(canClearCoords);
        break;/*from w  w w  . ja  va 2  s .c om*/
    default:
        if (imagesList != null) {
            imagesList.onCreateContextMenu(menu, view);
        }
        break;
    }
}

From source file:com.seal.ui.components.CustomWebView.java

private void setupContextMenu() {
    setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

        @Override//from   www. j  a  v a  2  s .co m
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            HitTestResult result = ((WebView) v).getHitTestResult();
            int resultType = result.getType();

            if ((resultType == HitTestResult.ANCHOR_TYPE) || (resultType == HitTestResult.IMAGE_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)) {

                MenuItem item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN, 0, R.string.ContextMenuOpen);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, 0,
                        R.string.ContextMenuOpenNewTab);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN_IN_BACKGROUND, 0,
                        R.string.ContextMenuOpenInBackground);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN_IN_BACKGROUND, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_COPY, 0, R.string.ContextMenuCopyLinkUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_COPY, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_DOWNLOAD, 0, R.string.ContextMenuDownload);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_DOWNLOAD, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_SHARE, 0, R.string.ContextMenuShareLinkUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_SHARE, resultType, result.getExtra()));

                createContributedContextMenu(menu, resultType, result.getExtra());

                menu.setHeaderTitle(result.getExtra());

            } else if (resultType == HitTestResult.IMAGE_TYPE) {

                MenuItem item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN, 0,
                        R.string.ContextMenuViewImage);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, 0,
                        R.string.ContextMenuViewImageInNewTab);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_COPY, 0, R.string.ContextMenuCopyImageUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_COPY, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_DOWNLOAD, 0,
                        R.string.ContextMenuDownloadImage);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_DOWNLOAD, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_SHARE, 0,
                        R.string.ContextMenuShareImageUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_SHARE, resultType, result.getExtra()));

                createContributedContextMenu(menu, resultType, result.getExtra());

                menu.setHeaderTitle(result.getExtra());

            } else if (resultType == HitTestResult.EMAIL_TYPE) {

                Intent sendMail = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(WebView.SCHEME_MAILTO + result.getExtra()));

                MenuItem item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_SEND_MAIL, 0,
                        R.string.ContextMenuSendEmail);
                item.setIntent(sendMail);

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_COPY, 0, R.string.ContextMenuCopyEmailUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_COPY, resultType, result.getExtra()));

                item = menu.add(0, SealBrowserActivity.CONTEXT_MENU_SHARE, 0,
                        R.string.ContextMenuShareEmailUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        SealBrowserActivity.CONTEXT_MENU_SHARE, resultType, result.getExtra()));

                createContributedContextMenu(menu, resultType, result.getExtra());

                menu.setHeaderTitle(result.getExtra());

            }
        }
    });
}

From source file:com.android.music.TrackBrowserFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfoIn) {
    menu.add(0, PLAY_SELECTION, 0, R.string.play_selection);
    SubMenu sub = menu.addSubMenu(0, ADD_TO_PLAYLIST, 0, R.string.add_to_playlist);
    MusicUtils.makePlaylistMenu(getActivity(), sub);
    if (mEditMode) {
        menu.add(0, REMOVE, 0, R.string.remove_from_playlist);
    }/*from  w w  w. j a  v a2s . co m*/
    menu.add(0, USE_AS_RINGTONE, 0, R.string.ringtone_menu);
    menu.add(0, DELETE_ITEM, 0, R.string.delete_item);
    AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfoIn;
    mSelectedPosition = mi.position;
    mTrackCursor.moveToPosition(mSelectedPosition);
    try {
        int id_idx = mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.AUDIO_ID);
        mSelectedId = mTrackCursor.getLong(id_idx);
    } catch (IllegalArgumentException ex) {
        mSelectedId = mi.id;
    }
    // only add the 'search' menu if the selected item is music
    if (isMusic(mTrackCursor)) {
        menu.add(0, SEARCH, 0, R.string.search_title);
    }
    mCurrentAlbumName = mTrackCursor
            .getString(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
    mCurrentArtistNameForAlbum = mTrackCursor
            .getString(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
    mCurrentTrackName = mTrackCursor
            .getString(mTrackCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
    menu.setHeaderTitle(mCurrentTrackName);
}

From source file:com.acrutiapps.browser.ui.components.CustomWebView.java

private void setupContextMenu() {
    setOnCreateContextMenuListener(new OnCreateContextMenuListener() {

        @Override//from  w ww .  ja  v a 2  s  .c  o  m
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            HitTestResult result = ((WebView) v).getHitTestResult();
            int resultType = result.getType();

            if ((resultType == HitTestResult.ANCHOR_TYPE) || (resultType == HitTestResult.IMAGE_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)) {

                MenuItem item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_OPEN, 0, R.string.ContextMenuOpen);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_OPEN, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, 0,
                        R.string.ContextMenuOpenNewTab);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_OPEN_IN_BACKGROUND, 0,
                        R.string.ContextMenuOpenInBackground);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_OPEN_IN_BACKGROUND, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_COPY, 0, R.string.ContextMenuCopyLinkUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_COPY, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_DOWNLOAD, 0, R.string.ContextMenuDownload);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_DOWNLOAD, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_SHARE, 0, R.string.ContextMenuShareLinkUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_SHARE, resultType, result.getExtra()));

                createContributedContextMenu(menu, resultType, result.getExtra());

                menu.setHeaderTitle(result.getExtra());

            } else if (resultType == HitTestResult.IMAGE_TYPE) {

                MenuItem item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_OPEN, 0,
                        R.string.ContextMenuViewImage);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_OPEN, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, 0,
                        R.string.ContextMenuViewImageInNewTab);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_COPY, 0, R.string.ContextMenuCopyImageUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_COPY, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_DOWNLOAD, 0,
                        R.string.ContextMenuDownloadImage);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_DOWNLOAD, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_SHARE, 0,
                        R.string.ContextMenuShareImageUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_SHARE, resultType, result.getExtra()));

                createContributedContextMenu(menu, resultType, result.getExtra());

                menu.setHeaderTitle(result.getExtra());

            } else if (resultType == HitTestResult.EMAIL_TYPE) {

                Intent sendMail = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(WebView.SCHEME_MAILTO + result.getExtra()));

                MenuItem item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_SEND_MAIL, 0,
                        R.string.ContextMenuSendEmail);
                item.setIntent(sendMail);

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_COPY, 0, R.string.ContextMenuCopyEmailUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_COPY, resultType, result.getExtra()));

                item = menu.add(0, TintBrowserActivity.CONTEXT_MENU_SHARE, 0,
                        R.string.ContextMenuShareEmailUrl);
                item.setIntent(createIntent(Constants.ACTION_BROWSER_CONTEXT_MENU,
                        TintBrowserActivity.CONTEXT_MENU_SHARE, resultType, result.getExtra()));

                createContributedContextMenu(menu, resultType, result.getExtra());

                menu.setHeaderTitle(result.getExtra());

            }
        }
    });
}

From source file:com.kll.collect.android.activities.FormEntryActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    Collect.getInstance().getActivityLogger().logInstanceAction(this, "onCreateContextMenu", "show");
    FormController formController = Collect.getInstance().getFormController();

    menu.add(0, v.getId(), 0, getString(R.string.clear_answer));
    if (formController.indexContainsRepeatableGroup()) {
        menu.add(0, DELETE_REPEAT, 0, getString(R.string.delete_repeat));
    }//from ww w  .j ava  2  s  . c  om
    menu.setHeaderTitle(getString(R.string.edit_prompt));
}

From source file:org.mozilla.gecko.AwesomeBar.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    ListView list = (ListView) view;
    Object selectedItem = null;/* w w  w . jav  a 2  s . c om*/
    String title = "";

    if (list == findViewById(R.id.history_list)) {
        if (!(menuInfo instanceof ExpandableListView.ExpandableListContextMenuInfo)) {
            Log.e(LOGTAG, "menuInfo is not ExpandableListContextMenuInfo");
            return;
        }

        ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
        int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
        int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);

        // Check if long tap is on a header row
        if (groupPosition < 0 || childPosition < 0)
            return;

        ExpandableListView exList = (ExpandableListView) list;
        selectedItem = exList.getExpandableListAdapter().getChild(groupPosition, childPosition);

        // The history list is backed by a SimpleExpandableListAdapter
        @SuppressWarnings("rawtypes")
        Map map = (Map) selectedItem;
        title = (String) map.get(URLColumns.TITLE);
    } else {
        if (!(menuInfo instanceof AdapterView.AdapterContextMenuInfo)) {
            Log.e(LOGTAG, "menuInfo is not AdapterContextMenuInfo");
            return;
        }

        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        selectedItem = list.getItemAtPosition(info.position);

        if (!(selectedItem instanceof Cursor)) {
            Log.e(LOGTAG, "item at " + info.position + " is not a Cursor");
            return;
        }

        Cursor cursor = (Cursor) selectedItem;
        title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE));

        // Don't show the context menu for folders
        if (list == findViewById(R.id.bookmarks_list)
                && cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.IS_FOLDER)) == 1) {
            selectedItem = null;
        }
    }

    if (selectedItem == null || !((selectedItem instanceof Cursor) || (selectedItem instanceof Map))) {
        mContextMenuSubject = null;
        return;
    }

    mContextMenuSubject = selectedItem;

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.awesomebar_contextmenu, menu);

    if (list != findViewById(R.id.bookmarks_list)) {
        MenuItem removeBookmarkItem = menu.findItem(R.id.remove_bookmark);
        removeBookmarkItem.setVisible(false);
    }

    menu.setHeaderTitle(title);
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    MenuItem item;/*from ww w.  jav  a 2 s  .c om*/

    // If the trackball is held down, then the context menu pops up and
    // we never get onKeyUp() for the long-press. So check for it here
    // and change the selection to the long-press state.
    /*if (mSelectionMode != SELECTION_LONGPRESS) {
    mSelectionMode = SELECTION_LONGPRESS;
    invalidate();
    }*/

    final long startMillis = getSelectedTimeInMillis();
    int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_CAP_NOON_MIDNIGHT | DateUtils.FORMAT_SHOW_WEEKDAY;
    final String title = DayUtils.formatDateRange(mContext, startMillis, startMillis, flags);
    menu.setHeaderTitle(title);

    int numSelectedEvents = mSelectedEvents.size();
    if (mNumDays == 1) {
        // Day view.

        // If there is a selected event, then allow it to be viewed and
        // edited.
        if (numSelectedEvents >= 1) {
            item = menu.add(0, MENU_EVENT_VIEW, 0, "View event");
            item.setOnMenuItemClickListener(mContextMenuHandler);
            item.setIcon(android.R.drawable.ic_menu_info_details);
        }
    } else {
        // Week view.

        // If there is a selected event, then allow it to be viewed and
        // edited.
        if (numSelectedEvents >= 1) {
            item = menu.add(0, MENU_EVENT_VIEW, 0, "View event");
            item.setOnMenuItemClickListener(mContextMenuHandler);
            item.setIcon(android.R.drawable.ic_menu_info_details);
        }

        item = menu.add(0, MENU_DAY, 0, "Show day");
        item.setOnMenuItemClickListener(mContextMenuHandler);
        item.setIcon(android.R.drawable.ic_menu_day);
        item.setAlphabeticShortcut('d');
    }
}

From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java

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

    // This is a hack to give the longclick handler time
    // to find the word the user long clicked on.

    if (this.selectedWord != null) {

        final CharSequence word = this.selectedWord.getText();
        final int startIndex = this.selectedWord.getStartOffset();
        final int endIndex = this.selectedWord.getEndOffset();

        String header = String.format(getString(R.string.word_select), selectedWord.getText());

        menu.setHeaderTitle(header);

        if (isDictionaryAvailable()) {
            android.view.MenuItem item = menu.add(getString(R.string.dictionary_lookup));
            onMenuPress(item).thenDo(() -> lookupDictionary(word.toString()));
        }/*from   w  w w .  j  a v  a  2 s  . co  m*/

        menu.add(R.string.highlight).setOnMenuItemClickListener(item -> {
            highLight(startIndex, endIndex, word.toString());
            return false;
        });

        android.view.MenuItem lookUpWikipediaItem = menu.add(getString(R.string.wikipedia_lookup));

        onMenuPress(lookUpWikipediaItem).thenDo(() -> lookupWikipedia(word.toString()));

        android.view.MenuItem lookUpWiktionaryItem = menu.add(getString(R.string.lookup_wiktionary));

        lookUpWiktionaryItem.setOnMenuItemClickListener(item -> {
            lookupWiktionary(word.toString());
            return true;
        });

        android.view.MenuItem lookupGoogleItem = menu.add(getString(R.string.google_lookup));

        lookupGoogleItem.setOnMenuItemClickListener(item -> {
            lookupGoogle(word.toString());
            return true;
        });

        this.selectedWord = null;
    }
}