Example usage for android.view MenuItem getIntent

List of usage examples for android.view MenuItem getIntent

Introduction

In this page you can find the example usage for android.view MenuItem getIntent.

Prototype

public Intent getIntent();

Source Link

Document

Return the Intent associated with this item.

Usage

From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() != 0)
        return super.onContextItemSelected(item);

    final Intent intent = item.getIntent();
    switch (item.getItemId()) {
    case CTX_MENU_EXPAND:
        expand(intent);//  w ww .  j ava  2 s. c om
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
            updateHeaders();
        }
        break;
    case CTX_MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case CTX_MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case CTX_MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case CTX_MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case CTX_MENU_ENQUEUE_AS_NEXT:
        pickSongs(intent, ACTION_ENQUEUE_AS_NEXT);
        break;
    case CTX_MENU_RENAME_PLAYLIST: {
        final String playlistName = intent.getStringExtra("title");
        final long playlistId = intent.getLongExtra("id", -1);
        PlaylistInputDialog dialog = new PlaylistInputDialog(new PlaylistInputDialog.Callback() {
            @Override
            public void onSuccess(String input) {
                PlaylistTask playlistTask = new PlaylistTask(playlistId, input);
                mHandler.sendMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, playlistTask));
            }
        }, playlistName, R.string.rename);
        dialog.show(getFragmentManager(), "RenamePlaylistInputDialog");
        break;
    }
    case CTX_MENU_DELETE:
        String delete_message = getString(R.string.delete_item, intent.getStringExtra("title"));
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle(R.string.delete);
        dialog.setMessage(delete_message)
                .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent));
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        dialog.create().show();
        break;
    case CTX_MENU_OPEN_EXTERNAL: {
        FileUtils.dispatchIntent(this, intent);
        break;
    }
    case CTX_MENU_MORE_FROM_ARTIST: {
        String selection;
        if (intent.getIntExtra(LibraryAdapter.DATA_TYPE, -1) == MediaUtils.TYPE_ALBUM) {
            selection = "album_id=";
        } else {
            selection = "_id=";
        }
        selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID);
        setLimiter(MediaUtils.TYPE_ARTIST, selection);
        updateLimiterViews();
        break;
    }
    case CTX_MENU_MORE_FROM_ALBUM:
        setLimiter(MediaUtils.TYPE_ALBUM,
                "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    case CTX_MENU_ADD_TO_PLAYLIST:
        long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
        PlaylistDialog plDialog = new PlaylistDialog(this, intent,
                (id == LibraryAdapter.HEADER_ID ? (MediaAdapter) mCurrentAdapter : null));
        plDialog.show(getFragmentManager(), "PlaylistDialog");
        break;
    default:
        return super.onContextItemSelected(item);
    }

    return true;
}

From source file:ru.mtuci.musicanalyzer.apollo.ui.fragments.profile.FavoriteFragment.java

@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), new long[] { mSelectedId }, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), new long[] { mSelectedId });
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new long[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getActivity(), new long[] { mSelectedId }, mPlaylistId);
            return true;
        case FragmentMenuItems.MORE_BY_ARTIST:
            NavUtils.openArtistProfile(getActivity(), mArtistName);
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(getActivity(), mSelectedId);
            return true;
        case FragmentMenuItems.REMOVE_FROM_FAVORITES:
            FavoritesStore.getInstance(getActivity()).removeItem(mSelectedId);
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mSong.mSongName, new long[] { mSelectedId }, null)
                    .show(getFragmentManager(), "DeleteDialog");
            SystemClock.sleep(10);// w  w  w .jav  a 2s.  c o m
            mAdapter.notifyDataSetChanged();
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.andrew.apollo.ui.fragments.profile.FavoriteFragment.java

@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getSherlockActivity(), new long[] { mSelectedId }, 0, false);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getSherlockActivity(), new long[] { mSelectedId });
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new long[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getSherlockActivity(), new long[] { mSelectedId }, mPlaylistId);
            return true;
        case FragmentMenuItems.MORE_BY_ARTIST:
            NavUtils.openArtistProfile(getSherlockActivity(), mArtistName);
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(getSherlockActivity(), mSelectedId);
            return true;
        case FragmentMenuItems.REMOVE_FROM_FAVORITES:
            FavoritesStore.getInstance(getSherlockActivity()).removeItem(Long.valueOf(mSelectedId));
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mSong.mSongName, new long[] { mSelectedId }, null)
                    .show(getFragmentManager(), "DeleteDialog");
            SystemClock.sleep(10);//from w  w w  . ja  v a2  s  .c om
            mAdapter.notifyDataSetChanged();
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() != 0)
        return super.onContextItemSelected(item);

    final Intent intent = item.getIntent();
    switch (item.getItemId()) {
    case CTX_MENU_EXPAND:
        expand(intent);/*from   w  w w .  jav  a 2 s  .  c o  m*/
        if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) {
            mLastAction = ACTION_EXPAND;
            updateHeaders();
        }
        break;
    case CTX_MENU_ENQUEUE:
        pickSongs(intent, ACTION_ENQUEUE);
        break;
    case CTX_MENU_PLAY:
        pickSongs(intent, ACTION_PLAY);
        break;
    case CTX_MENU_PLAY_ALL:
        pickSongs(intent, ACTION_PLAY_ALL);
        break;
    case CTX_MENU_ENQUEUE_ALL:
        pickSongs(intent, ACTION_ENQUEUE_ALL);
        break;
    case CTX_MENU_ENQUEUE_AS_NEXT:
        pickSongs(intent, ACTION_ENQUEUE_AS_NEXT);
        break;
    case CTX_MENU_RENAME_PLAYLIST: {
        final String playlistName = intent.getStringExtra("title");
        final long playlistId = intent.getLongExtra("id", -1);
        PlaylistInputDialog dialog = PlaylistInputDialog.newInstance(new PlaylistInputDialog.Callback() {
            @Override
            public void onSuccess(String input) {
                PlaylistTask playlistTask = new PlaylistTask(playlistId, input);
                mHandler.sendMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, playlistTask));
            }
        }, playlistName, R.string.rename);
        dialog.show(getFragmentManager(), "RenamePlaylistInputDialog");
        break;
    }
    case CTX_MENU_DELETE:
        String delete_message = getString(R.string.delete_item, intent.getStringExtra("title"));
        AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle(R.string.delete);
        dialog.setMessage(delete_message)
                .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent));
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });
        dialog.create().show();
        break;
    case CTX_MENU_OPEN_EXTERNAL: {
        FileUtils.dispatchIntent(this, intent);
        break;
    }
    case CTX_MENU_PLUGINS: {
        queryPluginsForIntent(intent);
        break;
    }
    case CTX_MENU_MORE_FROM_ARTIST: {
        String selection;
        if (intent.getIntExtra(LibraryAdapter.DATA_TYPE, -1) == MediaUtils.TYPE_ALBUM) {
            selection = "album_id=";
        } else {
            selection = "_id=";
        }
        selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID);
        setLimiter(MediaUtils.TYPE_ARTIST, selection);
        updateLimiterViews();
        break;
    }
    case CTX_MENU_MORE_FROM_ALBUM:
        setLimiter(MediaUtils.TYPE_ALBUM,
                "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID));
        updateLimiterViews();
        break;
    case CTX_MENU_ADD_TO_PLAYLIST:
        long id = intent.getLongExtra("id", LibraryAdapter.INVALID_ID);
        PlaylistDialog plDialog = PlaylistDialog.newInstance(this, intent,
                (id == LibraryAdapter.HEADER_ID ? mCurrentAdapter : null));
        plDialog.show(getFragmentManager(), "PlaylistDialog");
        break;
    default:
        return super.onContextItemSelected(item);
    }

    return true;
}

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

/**
 * {@inheritDoc}//ww w.  j  a  v  a  2 s.  c  om
 */
@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    // Avoid leaking context menu selections
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), mArtistList, 0, true);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), mArtistList);
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(mArtistList).show(getFragmentManager(), "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long id = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getActivity(), mArtistList, id);
            return true;
        case FragmentMenuItems.DELETE:
            mShouldRefresh = true;
            final String artist = mArtist.mArtistName;
            DeleteDialog.newInstance(artist, mArtistList, artist).show(getFragmentManager(), "DeleteDialog");
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.boko.vimusic.ui.fragments.ArtistFragment.java

/**
 * {@inheritDoc}//from  w w w .j a v  a  2  s  . co m
 */
@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    // Avoid leaking context menu selections
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), mArtistList, 0, true);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), mArtistList);
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(mArtistList).show(getFragmentManager(), "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final String id = item.getIntent().getStringExtra("playlist");
            MusicUtils.addToPlaylist(getActivity(), mArtistList, id);
            return true;
        case FragmentMenuItems.DELETE:
            mShouldRefresh = true;
            final String artist = mArtist.getName();
            DeleteDialog.newInstance(artist, mArtistList, artist).show(getFragmentManager(), "DeleteDialog");
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.andrew.apollo.ui.fragments.ArtistFragment.java

/**
 * {@inheritDoc}/*ww  w  .  j  a v  a2s  .c o  m*/
 */
@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    // Avoid leaking context menu selections
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getSherlockActivity(), mArtistList, 0, true);
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getSherlockActivity(), mArtistList);
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(mArtistList).show(getFragmentManager(), "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long id = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getSherlockActivity(), mArtistList, id);
            return true;
        case FragmentMenuItems.DELETE:
            mShouldRefresh = true;
            final String artist = mArtist.mArtistName;
            DeleteDialog.newInstance(artist, mArtistList, artist).show(getFragmentManager(), "DeleteDialog");
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.guayaba.tapir.ui.fragments.profile.FavoriteFragment.java

@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), new long[] { mSelectedId }, 0, false);
            return true;
        case FragmentMenuItems.PLAY_NEXT:
            MusicUtils.playNext(new long[] { mSelectedId });
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), new long[] { mSelectedId });
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new long[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getActivity(), new long[] { mSelectedId }, mPlaylistId);
            return true;
        case FragmentMenuItems.MORE_BY_ARTIST:
            NavUtils.openArtistProfile(getActivity(), mArtistName);
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(getActivity(), mSelectedId);
            return true;
        case FragmentMenuItems.REMOVE_FROM_FAVORITES:
            FavoritesStore.getInstance(getActivity()).removeItem(mSelectedId);
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mSong.mSongName, new long[] { mSelectedId }, null)
                    .show(getFragmentManager(), "DeleteDialog");
            SystemClock.sleep(10);/*from w  w  w.j a v  a2s .c  om*/
            mAdapter.notifyDataSetChanged();
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}

From source file:com.cyanogenmod.eleven.ui.fragments.AudioPlayerFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new long[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final long mPlaylistId = item.getIntent().getLongExtra("playlist", 0);
            MusicUtils.addToPlaylist(getActivity(), new long[] { mSelectedId }, mPlaylistId);
            return true;
        default:/*from   w  w w.j  av  a 2s .c  o m*/
            break;
        }
    }

    return super.onContextItemSelected(item);
}

From source file:com.boko.vimusic.ui.fragments.profile.FavoriteFragment.java

@Override
public boolean onContextItemSelected(final android.view.MenuItem item) {
    if (item.getGroupId() == GROUP_ID) {
        switch (item.getItemId()) {
        case FragmentMenuItems.PLAY_SELECTION:
            MusicUtils.playAll(getActivity(), new Song[] { mSelectedId }, 0, false);
            return true;
        case FragmentMenuItems.PLAY_NEXT:
            MusicUtils.playNext(new Song[] { mSelectedId });
            return true;
        case FragmentMenuItems.ADD_TO_QUEUE:
            MusicUtils.addToQueue(getActivity(), new Song[] { mSelectedId });
            return true;
        case FragmentMenuItems.NEW_PLAYLIST:
            CreateNewPlaylist.getInstance(new Song[] { mSelectedId }).show(getFragmentManager(),
                    "CreatePlaylist");
            return true;
        case FragmentMenuItems.PLAYLIST_SELECTED:
            final String mPlaylistId = item.getIntent().getStringExtra("playlist");
            MusicUtils.addToPlaylist(getActivity(), new Song[] { mSelectedId }, mPlaylistId);
            return true;
        case FragmentMenuItems.MORE_BY_ARTIST:
            NavUtils.openArtistProfile(getActivity(), mArtistName);
            return true;
        case FragmentMenuItems.USE_AS_RINGTONE:
            MusicUtils.setRingtone(getActivity(), mSelectedId.getId());
            return true;
        case FragmentMenuItems.REMOVE_FROM_FAVORITES:
            FavoritesStore.getInstance(getActivity()).removeSong(mSelectedId.getId(), mSelectedId.getHost());
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        case FragmentMenuItems.DELETE:
            DeleteDialog.newInstance(mSong.getName(), new Song[] { mSelectedId }, null)
                    .show(getFragmentManager(), "DeleteDialog");
            SystemClock.sleep(10);//from www . j  av  a2s .  com
            mAdapter.notifyDataSetChanged();
            getLoaderManager().restartLoader(LOADER, null, this);
            return true;
        default:
            break;
        }
    }
    return super.onContextItemSelected(item);
}