예제 #1
0
  /**
   * This method updates the service covers if the current cover path is different than currently
   * playing, if cache is enabled.
   */
  private void updateAlbumCoverWithCached(final AlbumInfo albumInfo) {
    if (DEBUG) {
      Log.d(TAG, "updateAlbumCoverWithCache(music): " + albumInfo);
    }
    final String coverArtPath = retrieveCoverArtPath(albumInfo);
    final boolean sameCover = coverArtPath != null && coverArtPath.equals(mAlbumCoverPath);
    final boolean fullCoverValid = mFullSizeAlbumCover != null && !mFullSizeAlbumCover.isRecycled();
    final boolean smallCoverValid = mNotificationCover != null && !mNotificationCover.isRecycled();

    if (coverArtPath == null) {
      if (DEBUG) {
        Log.d(TAG, "Cover not found, attempting download.");
      }

      mNotificationListener.onCoverUpdate(null);
      mFullSizeListener.onCoverUpdate(null);
      mCoverAsyncHelper.downloadCover(albumInfo);
    } else if (sameCover && fullCoverValid && smallCoverValid) {
      if (DEBUG) {
        Log.d(TAG, "Cover the same as last time, omitting.");
      }

      mNotificationListener.onCoverUpdate(mNotificationCover);
      mFullSizeListener.onCoverUpdate(mFullSizeAlbumCover);
    } else {
      if (DEBUG) {
        Log.d(TAG, "Cover found in cache, decoding.");
      }

      new DecodeAlbumCover().execute(coverArtPath);
    }
  }
예제 #2
0
  /**
   * A method implemented from CoverDownloadListener executed after cover download has successfully
   * completed.
   *
   * @param cover A current {@code CoverInfo object}.
   */
  @Override
  public final void onCoverDownloaded(final CoverInfo cover) {
    if (mIsAlbumCacheEnabled) {
      /** This is a workaround for the rare occasion of cover.getBitmap()[0] being null. */
      Bitmap placeholder = null;
      for (final Bitmap bitmap : cover.getBitmap()) {
        if (bitmap != null) {
          placeholder = bitmap;
          break;
        }
      }

      if (placeholder != null) {
        mFullSizeAlbumCover = placeholder;
        mNotificationCover =
            Bitmap.createScaledBitmap(mFullSizeAlbumCover, mIconWidth, mIconHeight, false);
        mAlbumCoverPath = retrieveCoverArtPath(cover);
        mFullSizeListener.onCoverUpdate(mFullSizeAlbumCover);
        mNotificationListener.onCoverUpdate(mNotificationCover);
      }
    }
  }