/** {@inheritDoc} */
 @Override
 public void onItemClick(
     final AdapterView<?> parent, final View view, final int position, final long id) {
   // When selecting a track from the queue, just jump there instead of
   // reloading the queue. This is both faster, and prevents accidentally
   // dropping out of party shuffle.
   MusicUtils.setQueuePosition(position);
 }
 /** {@inheritDoc} */
 @Override
 public void remove(final int which) {
   mSong = mAdapter.getItem(which);
   mAdapter.remove(mSong);
   mAdapter.notifyDataSetChanged();
   MusicUtils.removeTrack(mSong.mSongId);
   // Build the cache
   mAdapter.buildCache();
 }
 /**
  * Used to set the album art in the album profile.
  *
  * @param context The {@link Context} to use.
  * @param album The name of the album in the profile the user is viewing.
  */
 public void setAlbumPhoto(final Activity context, final String album, final String artist) {
   if (!TextUtils.isEmpty(album)) {
     mAlbumArt.setVisibility(View.VISIBLE);
     mFetcher.loadAlbumImage(
         artist, album, MusicUtils.getIdForAlbum(context, album, artist), mAlbumArt);
   } else {
     setDefault(context);
   }
 }
 /** {@inheritDoc} */
 @Override
 public boolean onContextItemSelected(final android.view.MenuItem item) {
   if (item.getGroupId() == GROUP_ID) {
     switch (item.getItemId()) {
       case FragmentMenuItems.PLAY_NEXT:
         NowPlayingCursor queue = (NowPlayingCursor) QueueLoader.makeQueueCursor(getActivity());
         queue.removeItem(mSelectedPosition);
         queue.close();
         queue = null;
         MusicUtils.playNext(new long[] {mSelectedId});
         refreshQueue();
         return true;
       case FragmentMenuItems.REMOVE_FROM_QUEUE:
         MusicUtils.removeTrack(mSelectedId);
         refreshQueue();
         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:
         DeleteDialog.newInstance(mSong.mSongName, new long[] {mSelectedId}, null)
             .show(getFragmentManager(), "DeleteDialog");
         return true;
       default:
         break;
     }
   }
   return super.onContextItemSelected(item);
 }
 /** {@inheritDoc} */
 @Override
 public void drop(final int from, final int to) {
   mSong = mAdapter.getItem(from);
   mAdapter.remove(mSong);
   mAdapter.insert(mSong, to);
   mAdapter.notifyDataSetChanged();
   MusicUtils.moveQueueItem(from, to);
   // Build the cache
   mAdapter.buildCache();
 }
 /** {@inheritDoc} */
 @Override
 public boolean onOptionsItemSelected(final MenuItem item) {
   switch (item.getItemId()) {
     case R.id.menu_save_queue:
       NowPlayingCursor queue = (NowPlayingCursor) QueueLoader.makeQueueCursor(getActivity());
       CreateNewPlaylist.getInstance(MusicUtils.getSongListForCursor(queue))
           .show(getFragmentManager(), "CreatePlaylist");
       queue.close();
       queue = null;
       return true;
     case R.id.menu_clear_queue:
       MusicUtils.clearQueue();
       NavUtils.goHome(getActivity());
       return true;
     default:
       break;
   }
   return super.onOptionsItemSelected(item);
 }
 /**
  * @return The position of an item in the list based on the name of the currently playing song.
  */
 private int getItemPositionBySong() {
   final long trackId = MusicUtils.getCurrentAudioId();
   if (mAdapter == null) {
     return 0;
   }
   for (int i = 0; i < mAdapter.getCount(); i++) {
     if (mAdapter.getItem(i).mSongId == trackId) {
       return i;
     }
   }
   return 0;
 }
  /** {@inheritDoc} */
  @Override
  public void onCreateContextMenu(
      final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    // Get the position of the selected item
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    mSelectedPosition = info.position;
    // Creat a new song
    mSong = mAdapter.getItem(mSelectedPosition);
    mSelectedId = mSong.mSongId;
    mSongName = mSong.mSongName;
    mAlbumName = mSong.mAlbumName;
    mArtistName = mSong.mArtistName;

    // Play the song next
    menu.add(
        GROUP_ID,
        FragmentMenuItems.PLAY_NEXT,
        Menu.NONE,
        getString(R.string.context_menu_play_next));

    // Add the song to a playlist
    final SubMenu subMenu =
        menu.addSubMenu(
            GROUP_ID, FragmentMenuItems.ADD_TO_PLAYLIST, Menu.NONE, R.string.add_to_playlist);
    MusicUtils.makePlaylistMenu(getActivity(), GROUP_ID, subMenu, true);

    // Remove the song from the queue
    menu.add(
        GROUP_ID,
        FragmentMenuItems.REMOVE_FROM_QUEUE,
        Menu.NONE,
        getString(R.string.remove_from_queue));

    // View more content by the song artist
    menu.add(
        GROUP_ID,
        FragmentMenuItems.MORE_BY_ARTIST,
        Menu.NONE,
        getString(R.string.context_menu_more_by_artist));

    // Make the song a ringtone
    menu.add(
        GROUP_ID,
        FragmentMenuItems.USE_AS_RINGTONE,
        Menu.NONE,
        getString(R.string.context_menu_use_as_ringtone));

    // Delete the song
    menu.add(
        GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete));
  }
  /**
   * Used to set the album art in the artist profile.
   *
   * @param context The {@link Context} to use.
   * @param artist The name of the artist in the profile the user is viewing.
   */
  public void setArtistAlbumPhoto(final Activity context, final String artist) {
    final String lastAlbum = MusicUtils.getLastAlbumForArtist(context, artist);
    if (!TextUtils.isEmpty(lastAlbum)) {
      // Set the last album the artist played
      mFetcher.loadAlbumImage(
          artist, lastAlbum, MusicUtils.getIdForAlbum(context, lastAlbum, artist), mPhoto);
      // Play the album
      mPhoto.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(final View v) {
              final long[] albumList =
                  MusicUtils.getSongListForAlbum(
                      getContext(), MusicUtils.getIdForAlbum(context, lastAlbum, artist));
              MusicUtils.playAll(getContext(), albumList, 0, false);
            }
          });
    } else {
      setDefault(context);
    }
  }