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:uk.org.rivernile.edinburghbustracker.android.fragments.general.NearestStopsFragment.java

/**
 * {@inheritDoc}/*from  www . j a  va2 s .  co  m*/
 */
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    // Get the MenuInflater.
    final MenuInflater inflater = getActivity().getMenuInflater();
    // Cast the menuInfo object to something we understand.
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    // Get the item relating to the selected item.
    selectedStop = ad.getItem(info.position);

    final String name;

    if (selectedStop.locality != null) {
        name = getString(R.string.busstop_locality, selectedStop.stopName, selectedStop.locality,
                selectedStop.stopCode);
    } else {
        name = getString(R.string.busstop, selectedStop.stopName, selectedStop.stopCode);
    }

    // Set the title of the context menu.
    menu.setHeaderTitle(name);

    // Inflate the menu from XML.
    inflater.inflate(R.menu.neareststops_context_menu, menu);

    // Title depends on whether it's already a favourite or not.
    MenuItem item = menu.findItem(R.id.neareststops_context_menu_favourite);
    if (sd.getFavouriteStopExists(selectedStop.stopCode)) {
        item.setTitle(R.string.neareststops_context_remasfav);
    } else {
        item.setTitle(R.string.neareststops_context_addasfav);
    }

    // Title depends on whether a proximity alert has already been added or
    // not.
    item = menu.findItem(R.id.neareststops_context_menu_prox_alert);
    if (sd.isActiveProximityAlert(selectedStop.stopCode)) {
        item.setTitle(R.string.neareststops_menu_prox_rem);
    } else {
        item.setTitle(R.string.neareststops_menu_prox_add);
    }

    // Title depends on whether a time alert has already been added or not.
    item = menu.findItem(R.id.neareststops_context_menu_time_alert);
    if (sd.isActiveTimeAlert(selectedStop.stopCode)) {
        item.setTitle(R.string.neareststops_menu_time_rem);
    } else {
        item.setTitle(R.string.neareststops_menu_time_add);
    }

    // If the Google Play Services is not available, then don't show the
    // option to show the stop on the map.
    item = menu.findItem(R.id.neareststops_context_menu_showonmap);

    if (!GenericUtils.isGoogleMapsAvailable(getActivity())) {
        item.setVisible(false);
    }
}

From source file:com.android.music.AlbumBrowserFragment.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);
    menu.add(0, DELETE_ITEM, 0, R.string.delete_item);

    AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfoIn;
    mAlbumCursor.moveToPosition(mi.position);
    mCurrentAlbumId = mAlbumCursor.getString(mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID));
    mCurrentAlbumName = mAlbumCursor/* ww w .  j a  v a 2  s .c  om*/
            .getString(mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
    mCurrentArtistNameForAlbum = mAlbumCursor
            .getString(mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST));
    mIsUnknownArtist = mCurrentArtistNameForAlbum == null
            || mCurrentArtistNameForAlbum.equals(MediaStore.UNKNOWN_STRING);
    mIsUnknownAlbum = mCurrentAlbumName == null || mCurrentAlbumName.equals(MediaStore.UNKNOWN_STRING);
    if (mIsUnknownAlbum) {
        menu.setHeaderTitle(getString(R.string.unknown_album_name));
    } else {
        menu.setHeaderTitle(mCurrentAlbumName);
    }
    if (!mIsUnknownAlbum || !mIsUnknownArtist) {
        menu.add(0, SEARCH, 0, R.string.search_title);
    }
}

From source file:com.todoroo.astrid.activity.TaskListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    AdapterContextMenuInfo adapterInfo = (AdapterContextMenuInfo) menuInfo;
    Task task = ((ViewHolder) adapterInfo.targetView.getTag()).task;
    if (task.getValue(Task.IS_READONLY) > 0)
        return;//from   w  ww . j a  v a2  s .c o  m

    int id = (int) task.getId();
    menu.setHeaderTitle(task.getValue(Task.TITLE));

    if (task.isDeleted()) {
        menu.add(id, CONTEXT_MENU_UNDELETE_TASK_ID, Menu.NONE, R.string.TAd_contextUndeleteTask);

        menu.add(id, CONTEXT_MENU_PURGE_TASK_ID, Menu.NONE, R.string.TAd_contextPurgeTask);
    } else {
        menu.add(id, CONTEXT_MENU_EDIT_TASK_ID, Menu.NONE, R.string.TAd_contextEditTask);
        menu.add(id, CONTEXT_MENU_COPY_TASK_ID, Menu.NONE, R.string.TAd_contextCopyTask);

        for (int i = 0; i < contextItemExposers.length; i++) {
            Object label = contextItemExposers[i].getLabel(task);
            if (label != null) {
                if (label instanceof Integer)
                    menu.add(id, CONTEXT_MENU_PLUGIN_ID_FIRST + i, Menu.NONE, (Integer) label);
                else
                    menu.add(id, CONTEXT_MENU_PLUGIN_ID_FIRST + i, Menu.NONE, (String) label);
            }
        }

        long taskId = task.getId();
        for (ContextMenuItem item : contextMenuExtensionLoader.getList()) {
            android.view.MenuItem menuItem = menu.add(id, CONTEXT_MENU_BROADCAST_INTENT_ID, Menu.NONE,
                    item.title);
            item.intent.putExtra(AstridApiConstants.EXTRAS_TASK_ID, taskId);
            menuItem.setIntent(item.intent);
        }

        menu.add(id, CONTEXT_MENU_DELETE_TASK_ID, Menu.NONE, R.string.TAd_contextDeleteTask);

    }
}

From source file:com.android.music.AlbumBrowserActivity.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(this, sub);
    menu.add(0, DELETE_ITEM, 0, R.string.delete_item);

    AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfoIn;
    mAlbumCursor.moveToPosition(mi.position);
    mCurrentAlbumId = mAlbumCursor.getString(mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums._ID));
    mCurrentAlbumName = mAlbumCursor//from w  w  w.j a va 2 s.  c  om
            .getString(mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM));
    mCurrentArtistNameForAlbum = mAlbumCursor
            .getString(mAlbumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST));
    mIsUnknownArtist = mCurrentArtistNameForAlbum == null
            || mCurrentArtistNameForAlbum.equals(MediaStore.UNKNOWN_STRING);
    mIsUnknownAlbum = mCurrentAlbumName == null || mCurrentAlbumName.equals(MediaStore.UNKNOWN_STRING);
    if (mIsUnknownAlbum) {
        menu.setHeaderTitle(getString(R.string.unknown_album_name));
    } else {
        menu.setHeaderTitle(mCurrentAlbumName);
    }
    if (!mIsUnknownAlbum || !mIsUnknownArtist) {
        menu.add(0, SEARCH, 0, R.string.search_title);
    }
}

From source file:com.gh4a.fragment.EventListFragment.java

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

    if (v.getId() == R.id.list_view) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        Event event = (Event) mAdapter.getItem(info.position);
        int groupId = getMenuGroupId();

        //if payload is a base class, return void.  Think that it is an old event which not supported
        //by API v3.
        if (event.getPayload().getClass().getSimpleName().equals("EventPayload")) {
            return;
        }/*from  w  w w. j  a  v a 2  s.  c om*/

        String eventType = event.getType();
        EventRepository eventRepo = event.getRepo();
        String[] repoNamePart = eventRepo.getName().split("/");
        String repoOwner = null;
        String repoName = null;
        if (repoNamePart.length == 2) {
            repoOwner = repoNamePart[0];
            repoName = repoNamePart[1];
        }
        String repoUrl = eventRepo.getUrl();

        menu.setHeaderTitle("Go to");

        /** Common menu */
        menu.add(groupId, MENU_USER, Menu.NONE, "User " + event.getActor().getLogin());
        if (repoOwner != null) {
            menu.add(groupId, MENU_REPO, Menu.NONE, "Repo " + repoOwner + "/" + repoName);
        }

        /** PushEvent extra menu for commits */
        if (Event.TYPE_PUSH.equals(eventType)) {
            if (repoOwner != null) {
                PushPayload payload = (PushPayload) event.getPayload();
                menu.add(groupId, MENU_COMPARE, Menu.NONE, "Compare " + payload.getHead());

                List<Commit> commits = payload.getCommits();
                for (Commit commit : commits) {
                    menu.add(groupId, MENU_COMMIT, Menu.NONE, "Commit " + commit.getSha());
                }
            }
        }

        /** IssueEvent extra menu for commits */
        else if (Event.TYPE_ISSUES.equals(eventType)) {
            IssuesPayload payload = (IssuesPayload) event.getPayload();
            menu.add(groupId, MENU_ISSUE, Menu.NONE, "Issue " + payload.getIssue().getNumber());
        }

        /** FollowEvent */
        else if (Event.TYPE_FOLLOW.equals(eventType)) {
            FollowPayload payload = (FollowPayload) event.getPayload();
            if (payload.getTarget() != null) {
                menu.add(groupId, MENU_USER, Menu.NONE, "User " + payload.getTarget().getLogin());
            }
        }

        /** CommitCommentEvent */
        else if (Event.TYPE_COMMIT_COMMENT.equals(eventType)) {
            if (repoOwner != null) {
                CommitCommentPayload payload = (CommitCommentPayload) event.getPayload();
                menu.add(groupId, MENU_COMMIT, Menu.NONE,
                        "Commit " + payload.getComment().getCommitId().substring(0, 7));
                //menu.add("Comment in browser");
            }
        }

        /** GistEvent */
        else if (Event.TYPE_GIST.equals(eventType)) {
            GistPayload payload = (GistPayload) event.getPayload();
            menu.add(groupId, MENU_GIST, Menu.NONE, "Gist " + payload.getGist().getId());
        }

        /** DownloadEvent */
        else if (Event.TYPE_DOWNLOAD.equals(eventType)) {
            DownloadPayload payload = (DownloadPayload) event.getPayload();
            menu.add(groupId, MENU_FILE, Menu.NONE, "File " + payload.getDownload().getName());
        }

        /** ForkEvent */
        else if (Event.TYPE_FORK.equals(eventType)) {
            ForkPayload payload = (ForkPayload) event.getPayload();
            Repository forkee = payload.getForkee();
            if (forkee != null) {
                menu.add(groupId, MENU_FORKED_REPO, Menu.NONE,
                        "Forked repo " + forkee.getOwner().getLogin() + "/" + forkee.getName());
            }
        }

        /** GollumEvent */
        else if (Event.TYPE_GOLLUM.equals(eventType)) {
            menu.add(groupId, MENU_WIKI_IN_BROWSER, Menu.NONE, "Wiki in browser");
        }

        /** PullRequestEvent */
        else if (Event.TYPE_PULL_REQUEST.equals(eventType)) {
            PullRequestPayload payload = (PullRequestPayload) event.getPayload();
            menu.add(groupId, MENU_PULL_REQ, Menu.NONE, "Pull request " + payload.getNumber());
        }

        /** IssueCommentEvent */
        else if (Event.TYPE_ISSUE_COMMENT.equals(eventType)) {
            menu.add(groupId, MENU_OPEN_ISSUES, Menu.NONE, "Open issues");
        }
    }
}

From source file:org.yammp.fragment.ArtistFragment.java

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

    ExpandableListContextMenuInfo mi = (ExpandableListContextMenuInfo) info;

    int itemtype = ExpandableListView.getPackedPositionType(mi.packedPosition);
    mSelectedGroupPosition = ExpandableListView.getPackedPositionGroup(mi.packedPosition);
    int gpos = mSelectedGroupPosition;
    if (itemtype == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {

        mGroupSelected = true;/*from  ww  w . j a  va2  s.c  o m*/
        mChildSelected = false;
        mGroupCursor.moveToPosition(gpos);
        menu.add(hashCode(), PLAY_SELECTION, 0, R.string.play_selection);
        menu.add(hashCode(), DELETE_ITEMS, 0, R.string.delete_music);
        menu.add(hashCode(), DELETE_LYRICS, 0, R.string.delete_lyrics);
        if (gpos == -1) {
            // this shouldn't happen
            Log.d("Artist/Album", "no group");
            return;
        }
        mCurrentGroupArtistName = mGroupCursor.getString(mGroupArtistIdx);
        mSelectedGroupId = mGroupCursor.getLong(mGroupArtistIdIdx);
        if (mCurrentGroupArtistName != null && !MediaStore.UNKNOWN_STRING.equals(mCurrentGroupArtistName)) {
            menu.setHeaderTitle(mCurrentGroupArtistName);
            menu.add(hashCode(), SEARCH, 0, android.R.string.search_go);
        } else {
            menu.setHeaderTitle(getString(R.string.unknown_artist));
        }
    }
}

From source file:uk.co.pjmobile.mobile_apps.page_turner_reader.ReadingActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, 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;

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

        final Intent intent = new Intent(PICK_RESULT_ACTION);
        intent.putExtra(EXTRA_QUERY, word.toString()); // Search Query
        intent.putExtra(EXTRA_FULLSCREEN, false); //
        intent.putExtra(EXTRA_HEIGHT, 400); // 400pixel, if you don't
        // specify, fill_parent"
        intent.putExtra(EXTRA_GRAVITY, Gravity.BOTTOM);
        intent.putExtra(EXTRA_MARGIN_LEFT, 100);

        if (isIntentAvailable(this, intent)) {
            MenuItem item = menu.add(getString(R.string.dictionary_lookup));
            item.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override/*from   www . j  a  v  a  2 s. com*/
                public boolean onMenuItemClick(MenuItem item) {
                    startActivityForResult(intent, 5);
                    return true;
                }
            });
        }

        MenuItem newItem = menu.add(getString(R.string.wikipedia_lookup));
        newItem.setOnMenuItemClickListener(new BrowserSearchMenuItem(
                "http://en.wikipedia.org/wiki/Special:Search?search=" + URLEncoder.encode(word.toString())));

        MenuItem newItem2 = menu.add(getString(R.string.google_lookup));
        newItem2.setOnMenuItemClickListener(new BrowserSearchMenuItem(
                "http://www.google.com/search?q=" + URLEncoder.encode(word.toString())));

        this.selectedWord = null;
    }
}

From source file:org.planetmono.dcuploader.ActivityUploader.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (v.getId() == R.id.upload_target) {
        if (passThrough)
            return;

        menu.clear();/* w ww. j  a  v  a 2s.  co m*/

        DatabaseHelper db = new DatabaseHelper(ActivityUploader.this);
        db.getFavorites(ids, names);
        db.close();

        menu.setHeaderTitle(" ?");
        for (int i = 0; i < names.size(); ++i)
            menu.add(MENU_GROUP_SELECT_GALLERY, i, 0, names.get(i));
        menu.add(MENU_GROUP_SELECT_GALLERY, MENU_ADD_GALLERY, 0, " ...");
    } else if (v.getId() == R.id.upload_visit) {
        menu.clear();

        if (pageDestination.equals("dcinside")) {
            visitPage(MENU_DCINSIDE);
        } else if (pageDestination.equals("mobile")) {
            visitPage(MENU_MOBILE);
        } else {
            menu.setHeaderTitle(" ?");

            String dest;
            if (mobilePageProvider.equals("moolzo"))
                dest = "";
            else
                dest = "DCmys";

            menu.add(MENU_GROUP_VISIT, MENU_DCINSIDE, 0, "??");
            menu.add(MENU_GROUP_VISIT, MENU_MOBILE, 0, dest);
        }
    }
}

From source file:jackpal.androidterm.Term.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle(R.string.edit_text);
    menu.add(0, SELECT_TEXT_ID, 0, R.string.select_text);
    menu.add(0, COPY_ALL_ID, 0, R.string.copy_all);
    menu.add(0, PASTE_ID, 0, R.string.paste);
    // menu.add(0, SEND_CONTROL_KEY_ID, 0, R.string.send_control_key);
    // menu.add(0, SEND_FN_KEY_ID, 0, R.string.send_fn_key);
    menu.add(0, SEND_MENU_ID, 0, R.string.title_functionbar_menu);
    // menu.add(0, SEND_FUNCTION_BAR_ID, 0, R.string.toggle_function_bar);
    if (!canPaste()) {
        menu.getItem(PASTE_ID).setEnabled(false);
    }// w ww.  j  a va2  s . com
}

From source file:monakhv.android.samlib.AuthorListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    if (v.getId() == getListView().getId()) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;

        Cursor cursor = (Cursor) adapter.getItem(info.position);
        author = AuthorController.Cursor2Author(getActivity().getApplicationContext(), cursor);

        if (author == null) {
            Log.d(DEBUG_TAG, "Context menu Created - author is NULL!!");
        } else {//from w ww.  ja va  2  s.  c om
            Log.d(DEBUG_TAG, "Context menu Created - author is " + author.getName());
        }
        if (author.isIsNew()) {
            menu.add(1, read_option_item, 10, getText(R.string.menu_read));
        }
        menu.add(1, tags_option_item, 20, getText(R.string.menu_tags));
        menu.add(1, browser_option_item, 30, getText(R.string.menu_open_web));
        menu.add(1, edit_author_option_item, 40, getText(R.string.menu_edit));
        menu.add(1, delete_option_item, 50, getText(R.string.menu_delete));
        menu.add(1, update_option_item, 60, getText(R.string.menu_refresh));
        menu.setHeaderTitle(author.getName());
    }

}