@Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.menu_sort_by_az:
       mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_A_Z);
       refresh();
       return true;
     case R.id.menu_sort_by_za:
       mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_Z_A);
       refresh();
       return true;
     case R.id.menu_sort_by_artist:
       mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_ARTIST);
       refresh();
       return true;
     case R.id.menu_sort_by_year:
       mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_YEAR);
       refresh();
       return true;
     case R.id.menu_sort_by_number_of_songs:
       mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_NUMBER_OF_SONGS);
       refresh();
       return true;
     case R.id.menu_view_as_simple:
       mPreferences.setAlbumLayout("simple");
       NavUtils.goHome(getActivity());
       return true;
     case R.id.menu_view_as_grid:
       mPreferences.setAlbumLayout("grid");
       NavUtils.goHome(getActivity());
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
  /** {@inheritDoc} */
  @Override
  public void onItemClick(
      final AdapterView<?> parent, final View view, final int position, final long id) {
    Cursor cursor = mAdapter.getCursor();
    cursor.moveToPosition(position);
    if (cursor.isBeforeFirst() || cursor.isAfterLast()) {
      return;
    }
    // Get the MIME type
    final String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.MIME_TYPE));

    // If it's an artist, open the artist profile
    if ("artist".equals(mimeType)) {
      NavUtils.openArtistProfile(
          this, cursor.getString(cursor.getColumnIndexOrThrow(ArtistColumns.ARTIST)));
    } else if ("album".equals(mimeType)) {
      // If it's an album, open the album profile
      NavUtils.openAlbumProfile(
          this,
          cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ALBUM)),
          cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ARTIST)));
    } else if (position >= 0 && id >= 0) {
      // If it's a song, play it and leave
      final long[] list = new long[] {id};
      MusicUtils.playAll(this, list, 0, false);
    }

    // Close it up
    cursor.close();
    cursor = null;
    // All done
    finish();
  }
Esempio n. 3
0
 @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.EDIT_TAGS:
         ApolloUtils.showTagsEditor(getActivity(), mSong);
         return true;
       case FragmentMenuItems.ADD_TO_QUEUE:
         MusicUtils.addToQueue(getActivity(), new long[] {mSelectedId});
         return true;
       case FragmentMenuItems.ADD_TO_FAVORITES:
         FavoritesStore.getInstance(getActivity())
             .addSongId(mSelectedId, mSongName, mAlbumName, mArtistName);
         return true;
       case FragmentMenuItems.NEW_PLAYLIST:
         CreateNewPlaylist.getInstance(new long[] {mSelectedId})
             .show(getFragmentManager(), "CreatePlaylist");
         return true;
       case FragmentMenuItems.PLAYLIST_SELECTED:
         final long playlistId = item.getIntent().getLongExtra("playlist", 0);
         MusicUtils.addToPlaylist(getActivity(), new long[] {mSelectedId}, playlistId);
         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.DELETE:
         DeleteDialog.newInstance(mSong.mSongName, new long[] {mSelectedId}, null)
             .show(getFragmentManager(), "DeleteDialog");
         SystemClock.sleep(10);
         mAdapter.notifyDataSetChanged();
         getLoaderManager().restartLoader(LOADER, null, this);
         return true;
       case FragmentMenuItems.REMOVE_FROM_PLAYLIST:
         mAdapter.remove(mSong);
         mAdapter.notifyDataSetChanged();
         MusicUtils.removeFromPlaylist(getActivity(), mSong.mSongId, mPlaylistId);
         getLoaderManager().restartLoader(LOADER, null, this);
         return true;
       default:
         break;
     }
   }
   return super.onContextItemSelected(item);
 }
Esempio n. 4
0
 @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.ADD_TO_FAVORITES:
         FavoritesStore.getInstance(getActivity())
             .addSongId(mSelectedId, mSongName, mAlbumName, mArtistName);
         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.DELETE:
         mShouldRefresh = true;
         DeleteDialog.newInstance(mSong.mSongName, new long[] {mSelectedId}, null)
             .show(getFragmentManager(), "DeleteDialog");
         return true;
       default:
         break;
     }
   }
   return super.onContextItemSelected(item);
 }
 /** {@inheritDoc} */
 @Override
 public boolean onOptionsItemSelected(final MenuItem item) {
   switch (item.getItemId()) {
     case R.id.menu_shuffle:
       // Shuffle all the songs
       MusicUtils.shuffleAll(getActivity());
       return true;
     case R.id.menu_favorite:
       // Toggle the current track as a favorite and update the menu
       // item
       MusicUtils.toggleFavorite();
       getActivity().invalidateOptionsMenu();
       return true;
     case R.id.menu_sort_by_az:
       if (isArtistPage()) {
         mPreferences.setArtistSortOrder(SortOrder.ArtistSortOrder.ARTIST_A_Z);
         getArtistFragment().refresh();
       } else if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_A_Z);
         getAlbumFragment().refresh();
       } else if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_A_Z);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_za:
       if (isArtistPage()) {
         mPreferences.setArtistSortOrder(SortOrder.ArtistSortOrder.ARTIST_Z_A);
         getArtistFragment().refresh();
       } else if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_Z_A);
         getAlbumFragment().refresh();
       } else if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_Z_A);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_artist:
       if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_ARTIST);
         getAlbumFragment().refresh();
       } else if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_ARTIST);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_album:
       if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_ALBUM);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_year:
       if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_YEAR);
         getAlbumFragment().refresh();
       } else if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_YEAR);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_duration:
       if (isSongPage()) {
         mPreferences.setSongSortOrder(SortOrder.SongSortOrder.SONG_DURATION);
         getSongFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_number_of_songs:
       if (isArtistPage()) {
         mPreferences.setArtistSortOrder(SortOrder.ArtistSortOrder.ARTIST_NUMBER_OF_SONGS);
         getArtistFragment().refresh();
       } else if (isAlbumPage()) {
         mPreferences.setAlbumSortOrder(SortOrder.AlbumSortOrder.ALBUM_NUMBER_OF_SONGS);
         getAlbumFragment().refresh();
       }
       return true;
     case R.id.menu_sort_by_number_of_albums:
       if (isArtistPage()) {
         mPreferences.setArtistSortOrder(SortOrder.ArtistSortOrder.ARTIST_NUMBER_OF_ALBUMS);
         getArtistFragment().refresh();
       }
       return true;
     case R.id.menu_view_as_simple:
       if (isRecentPage()) {
         mPreferences.setRecentLayout("simple");
       } else if (isArtistPage()) {
         mPreferences.setArtistLayout("simple");
       } else if (isAlbumPage()) {
         mPreferences.setAlbumLayout("simple");
       }
       NavUtils.goHome(getActivity());
       return true;
     case R.id.menu_view_as_detailed:
       if (isRecentPage()) {
         mPreferences.setRecentLayout("detailed");
       } else if (isArtistPage()) {
         mPreferences.setArtistLayout("detailed");
       } else if (isAlbumPage()) {
         mPreferences.setAlbumLayout("detailed");
       }
       NavUtils.goHome(getActivity());
       return true;
     case R.id.menu_view_as_grid:
       if (isRecentPage()) {
         mPreferences.setRecentLayout("grid");
       } else if (isArtistPage()) {
         mPreferences.setArtistLayout("grid");
       } else if (isAlbumPage()) {
         mPreferences.setAlbumLayout("grid");
       }
       NavUtils.goHome(getActivity());
       return true;
     default:
       break;
   }
   return super.onOptionsItemSelected(item);
 }