示例#1
0
 /** {@inheritDoc} */
 @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);
 }
示例#2
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;
    // Creat a new model
    mArtist = mAdapter.getItem(info.position);
    // Create a list of the artist's songs
    mArtistList = MusicUtils.getSongListForArtist(getActivity(), mArtist.mArtistId);

    // Play the artist
    menu.add(
        GROUP_ID,
        FragmentMenuItems.PLAY_SELECTION,
        Menu.NONE,
        getString(R.string.context_menu_play_selection));

    // Add the artist to the queue
    menu.add(GROUP_ID, FragmentMenuItems.ADD_TO_QUEUE, Menu.NONE, getString(R.string.add_to_queue));

    // Add the artist 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, false);

    // Delete the artist
    menu.add(
        GROUP_ID, FragmentMenuItems.DELETE, Menu.NONE, getString(R.string.context_menu_delete));
  }
示例#3
0
 /** Sets the correct drawable for playback. */
 public void updateState() {
   if (MusicUtils.isPlaying()) {
     setContentDescription(getResources().getString(R.string.accessibility_pause));
     setImageDrawable(mResources.getDrawable(PAUSE));
   } else {
     setContentDescription(getResources().getString(R.string.accessibility_play));
     setImageDrawable(mResources.getDrawable(PLAY));
   }
 }
示例#4
0
 /**
  * @return The position of an item in the list or grid based on the name of the currently playing
  *     artist.
  */
 private int getItemPositionByArtist() {
   final long artistId = MusicUtils.getCurrentArtistId();
   if (mAdapter == null) {
     return 0;
   }
   for (int i = 0; i < mAdapter.getCount(); i++) {
     if (mAdapter.getItem(i).mArtistId == artistId) {
       return i;
     }
   }
   return 0;
 }
示例#5
0
 /** {@inheritDoc} */
 @Override
 public void onClick(final View v) {
   MusicUtils.playOrPause();
   updateState();
 }
示例#6
0
  /** Actually makes the queue */
  private void makeNowPlayingCursor() {
    mQueueCursor = null;
    mNowPlaying = MusicUtils.getQueue();
    mSize = mNowPlaying.length;
    if (mSize == 0) {
      return;
    }

    final StringBuilder selection = new StringBuilder();
    selection.append(MediaStore.Audio.Media._ID + " IN (");
    for (int i = 0; i < mSize; i++) {
      selection.append(mNowPlaying[i]);
      if (i < mSize - 1) {
        selection.append(",");
      }
    }
    selection.append(")");

    mQueueCursor =
        mContext
            .getContentResolver()
            .query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                PROJECTION,
                selection.toString(),
                null,
                MediaStore.Audio.Media._ID);

    if (mQueueCursor == null) {
      mSize = 0;
      return;
    }

    final int playlistSize = mQueueCursor.getCount();
    mCursorIndexes = new long[playlistSize];
    mQueueCursor.moveToFirst();
    final int columnIndex = mQueueCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
    for (int i = 0; i < playlistSize; i++) {
      mCursorIndexes[i] = mQueueCursor.getLong(columnIndex);
      mQueueCursor.moveToNext();
    }
    mQueueCursor.moveToFirst();
    mCurPos = -1;

    int removed = 0;
    for (int i = mNowPlaying.length - 1; i >= 0; i--) {
      final long trackId = mNowPlaying[i];
      final int cursorIndex = Arrays.binarySearch(mCursorIndexes, trackId);
      if (cursorIndex < 0) {
        removed += MusicUtils.removeTrack(trackId);
      }
    }
    if (removed > 0) {
      mNowPlaying = MusicUtils.getQueue();
      mSize = mNowPlaying.length;
      if (mSize == 0) {
        mCursorIndexes = null;
        return;
      }
    }
  }