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.josecarlos.couplecounters.MainActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    getMenuInflater().inflate(R.menu.menu_counter, menu);
    MenuItem item = (MenuItem) menu.findItem(R.id.counter_change);
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    if (listAdapter.getItem(info.position).isCommon()) {
        item.setTitle("make individual counter");
    } else/*from   w  w  w  . j  a  v a 2 s  .  c om*/
        item.setTitle("make common counter");
    super.onCreateContextMenu(menu, v, menuInfo);
}

From source file:info.schnatterer.nusic.android.fragments.ReleaseListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // If this callback was invoked on the visible fragment instance
    if (getUserVisibleHint()) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        Release release = (Release) releasesListView.getItemAtPosition(info.position);
        try {/*from w  w  w .ja  v a  2s. com*/
            switch (item.getItemId()) {
            case R.id.releaseListMenuHideRelease:
                displayLoading();
                release.setHidden(true);
                getReleaseService().update(release);
                getActivity().onContentChanged();
                break;
            case R.id.releaseListMenuHideAllByArtist:
                Artist artist = release.getArtist();
                artist.setHidden(true);
                getArtistService().update(artist);
                getActivity().onContentChanged();
                break;
            default:
                return super.onContextItemSelected(item);
            }
        } catch (ServiceException e) {
            Log.w(Constants.LOG, "Error hiding release/artist", e);
            NusicApplication.toast(e.getLocalizedMessageId());
        }
        return true; // Finish processing fragment instances
    } else {
        return false; // Pass the event to the next fragment
    }
}

From source file:de.hshannover.f4.trust.ironcontrol.view.list_activities.ListSavedConnectionsActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    String listItemId = Long.toString(info.id);
    switch (item.getItemId()) {
    case DEFAULT_ID:
        updateDefaultConnections(info.id);
        break;/*w ww  .  j  a  v  a  2 s  .c om*/
    case REMOVE_ID:
        removeListItem(listItemId);
        break;
    case EDIT_ID:
        Intent intent = new Intent(this, ConnectionFragmentActivity.class);
        intent.putExtra("listItemId", listItemId);
        startActivity(intent);
        break;
    }
    return super.onContextItemSelected(item);
}

From source file:com.github.nutomic.pegasus.activities.AreaList.java

/**
 * Context item on ListView selected, allow choosing the associated sound 
 * profile, renaming, learning or deleting the area.
 *//*w  w  w.j a va 2  s  .com*/
@Override
public boolean onContextItemSelected(MenuItem item) {
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    final Database db = Database.getInstance(this);
    switch (item.getItemId()) {
    case R.id.rename:
        renameArea(info.id, getAreaName((AdapterContextMenuInfo) item.getMenuInfo()));
        return true;
    case R.id.learn:
        new AlertDialog.Builder(this).setTitle(R.string.arealist_learn)
                .setItems(R.array.arealist_learn_area_strings, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        TypedArray millisecondValues = getResources()
                                .obtainTypedArray(R.array.arealist_learn_area_values);
                        long interval = millisecondValues.getInt(which, 0);

                        if (interval > 0) {
                            // Add future cells during interval.
                            Intent i = new Intent(AreaList.this, LocationService.class);
                            i.putExtra(LocationService.MESSAGE_LEARN_AREA, info.id);
                            i.putExtra(LocationService.MESSAGE_LEARN_INTERVAL, interval);
                            startService(i);
                            // Add only the current cell from database.
                            interval = 0;
                        } else {
                            // Do not pass the negativity to Database.
                            interval = -interval;
                        }

                        final long selectionStartTime = System.currentTimeMillis() - interval;
                        new UpdateTask() {

                            @Override
                            protected Long doInBackground(Void... params) {
                                ContentValues cv = new ContentValues();
                                cv.put(CellColumns.AREA_ID, info.id);
                                // Set current area in current cell and in any cell that was visited during interval.
                                db.getWritableDatabase().update(CellColumns.TABLE_NAME, cv,
                                        CellColumns._ID + " = (SELECT " + CellLogColumns.CELL_ID + " FROM "
                                                + CellLogColumns.TABLE_NAME + " ORDER BY "
                                                + CellLogColumns.TIMESTAMP + " DESC Limit 1) OR "
                                                + CellColumns._ID + " IN (SELECT " + CellLogColumns.CELL_ID
                                                + " FROM " + CellLogColumns.TABLE_NAME + " WHERE "
                                                + CellLogColumns.TIMESTAMP + " > ?)",
                                        new String[] { Long.toString(selectionStartTime) });
                                return null;
                            }
                        }.execute((Void) null);
                    }
                }).show();
        return true;
    case R.id.delete:
        new AlertDialog.Builder(this).setTitle(R.string.arealist_delete)
                .setMessage(R.string.arealist_delete_message)
                .setPositiveButton(android.R.string.yes, new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        new UpdateTask() {

                            @Override
                            protected Long doInBackground(Void... params) {
                                // Don't delete default area.
                                if (info.id != AreaColumns.AREA_DEFAULT) {
                                    db.getWritableDatabase().delete(AreaColumns.TABLE_NAME,
                                            AreaColumns._ID + " = ?", new String[] { Long.toString(info.id) });
                                    // Reset cells to default area.
                                    ContentValues cv = new ContentValues();
                                    cv.put(CellColumns.AREA_ID, AreaColumns.AREA_DEFAULT);
                                    db.getWritableDatabase().update(CellColumns.TABLE_NAME, cv,
                                            CellColumns.AREA_ID + " = ?",
                                            new String[] { Long.toString(info.id) });
                                }
                                return null;
                            }
                        }.execute((Void) null);
                    }
                }).setNegativeButton(android.R.string.no, null).show();
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:de.questmaster.fatremote.fragments.SelectFATFragment.java

/**
 * An item of the context menu was selected.
 * //from  ww w.  j  a va 2 s.  com
 * @see android.app.Activity#onContextItemSelected(android.view.MenuItem)
 */
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {
    case R.id.cm_delete:
        mDbHelper.deleteFatDevice(menuInfo.id);
        updateListView();

        return true;
    case R.id.cm_delete_all:
        mDbHelper.deleteAllFatDevices();
        updateListView();

        return true;
    default:
        Log.e(LOG_TAG, "Should not happen: default case of switch reached.");
    }
    return super.onContextItemSelected(item);
}

From source file:nz.co.wholemeal.christchurchmetro.FavouritesActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Stop stop = (Stop) stops.get((int) info.id);
    switch (item.getItemId()) {
    case R.id.remove_favourite:
        removeFavourite(stop);/*from  ww  w  .j a v  a2  s . com*/
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.GroupsActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    Cursor cursor = (Cursor) mGroups.getItem(info.position);
    final Group g = new Group(cursor);
    switch (menuItemIndex) {
    case 0:// w  ww  .  j  a  v  a  2 s.  c  o  m
        mHelper.deleteGroup(GroupsActivity.this, g.id);
        break;
    case 1:
        if (g.dynUpdateUri != null) {
            Uri uri = Uri.parse(g.dynUpdateUri);
            ((HomeActivity) getParent()).writeGroupToTag(uri);
        } else {
            Toast.makeText(this, "Invalid group.", Toast.LENGTH_SHORT).show();
        }
        break;
    }
    return true;
}

From source file:org.gateshipone.malp.application.fragments.serverfragments.AlbumTracksFragment.java

/**
 * Hook called when an menu item in the context menu is selected.
 *
 * @param item The menu item that was selected.
 * @return True if the hook was consumed here.
 *//*from   w w w  .java2s .  c  o m*/
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    if (info == null) {
        return super.onContextItemSelected(item);
    }

    switch (item.getItemId()) {
    case R.id.action_song_enqueue:
        enqueueTrack(info.position);
        return true;
    case R.id.action_song_play:
        play(info.position);
        return true;
    case R.id.action_song_play_next:
        playNext(info.position);
        return true;
    case R.id.action_add_to_saved_playlist:
        // open dialog in order to save the current playlist as a playlist in the mediastore
        ChoosePlaylistDialog choosePlaylistDialog = new ChoosePlaylistDialog();
        Bundle args = new Bundle();
        args.putBoolean(ChoosePlaylistDialog.EXTRA_SHOW_NEW_ENTRY, true);
        choosePlaylistDialog.setCallback(
                new AddPathToPlaylist((MPDFileEntry) mFileAdapter.getItem(info.position), getActivity()));
        choosePlaylistDialog.setArguments(args);
        choosePlaylistDialog.show(((AppCompatActivity) getContext()).getSupportFragmentManager(),
                "ChoosePlaylistDialog");
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.guayaba.tapir.ui.fragments.PlaylistFragment.java

/**
 * {@inheritDoc}//from  w  ww.ja  va 2  s.c  o m
 */
@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            if (info.position == 0) {
                MusicUtils.playFavorites(getActivity());
            } else if (info.position == 1) {
                MusicUtils.playLastAdded(getActivity());
            } else {
                MusicUtils.playPlaylist(getActivity(), mPlaylist.mPlaylistId);
            }
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            long[] list = null;
            if (info.position == 0) {
                list = MusicUtils.getSongListForFavorites(getActivity());
            } else if (info.position == 1) {
                list = MusicUtils.getSongListForLastAdded(getActivity());
            } else {
                list = MusicUtils.getSongListForPlaylist(getActivity(), mPlaylist.mPlaylistId);
            }
            MusicUtils.addToQueue(getActivity(), list);
            return true;
        case FragmentMenuItems.RENAME_PLAYLIST:
            RenamePlaylist.getInstance(mPlaylist.mPlaylistId).show(getFragmentManager(), "RenameDialog");
            return true;
        case FragmentMenuItems.DELETE:
            buildDeleteDialog().show();
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:cn.kangeqiu.kq.activity.ContactlistFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.delete_contact) {
        User tobeDeleteUser = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
        // ?/* ww  w .  ja v a2s.com*/
        deleteContact(tobeDeleteUser);
        // ?
        InviteMessgeDao dao = new InviteMessgeDao(getActivity());
        dao.deleteMessage(tobeDeleteUser.getUsername());
        return true;
    } else if (item.getItemId() == R.id.add_to_blacklist) {
        User user = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
        moveToBlacklist(user.getUsername());
        return true;
    }
    return super.onContextItemSelected(item);
}