Esempio n. 1
0
 /**
  * Used to fetch for the album art via Last.fm.
  *
  * @param context The {@link Context} to use.
  * @param album The name of the album in the profile the user is viewing.
  */
 public void fetchAlbumPhoto(final Activity context, final String album) {
   if (!TextUtils.isEmpty(album)) {
     mFetcher.removeFromCache(album + Config.ALBUM_ART_SUFFIX);
     mFetcher.loadAlbumImage(MusicUtils.getAlbumArtist(context, album), album, -1, mAlbumArt);
   } else {
     setDefault(context);
   }
 }
Esempio n. 2
0
 /**
  * Used to set the artist image 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 setArtistPhoto(final Activity context, final String artist) {
   if (!TextUtils.isEmpty(artist)) {
     mFetcher.loadArtistImage(artist, mPhoto);
   } else {
     setDefault(context);
   }
 }
Esempio n. 3
0
  /**
   * Used to blur the artist image in the album profile.
   *
   * @param context The {@link Context} to use.
   * @param artist The artist nmae used to fetch the cached artist image.
   * @param album The album name used to fetch the album art in case the artist image is missing.
   */
  public void blurPhoto(final Activity context, final String artist, final String album) {
    // FIXME: this should go into an AsyncTask

    // First check for the artist image
    Bitmap artistImage = mFetcher.getCachedBitmap(artist);
    // Second check for cached artwork
    if (artistImage == null) {
      artistImage = mFetcher.getCachedArtwork(album);
    }
    // If all else, use the default image
    if (artistImage == null) {
      artistImage = BitmapFactory.decodeResource(getResources(), R.drawable.theme_preview);
    }
    final Bitmap blur = BitmapUtils.createBlurredBitmap(artistImage);
    mPhoto.setImageBitmap(blur);
  }
Esempio n. 4
0
 /**
  * Used to set the header image for playlists and genres.
  *
  * @param context The {@link Context} to use.
  * @param profileName The key used to fetch the image.
  */
 public void setPlaylistOrGenrePhoto(final Activity context, final String profileName) {
   if (!TextUtils.isEmpty(profileName)) {
     final Bitmap image = mFetcher.getCachedBitmap(profileName);
     if (image != null) {
       mPhoto.setImageBitmap(image);
     } else {
       setDefault(context);
     }
   } else {
     setDefault(context);
   }
 }
Esempio n. 5
0
 /**
  * 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) {
   if (!TextUtils.isEmpty(album)) {
     mAlbumArt.setVisibility(View.VISIBLE);
     mFetcher.loadAlbumImage(
         MusicUtils.getAlbumArtist(context, album),
         album,
         MusicUtils.getIdForAlbum(context, album),
         mAlbumArt);
   } else {
     setDefault(context);
   }
 }
  /** {@inheritDoc} */
  @Override
  public View getView(final int position, View convertView, final ViewGroup parent) {

    // Return a faux header at position 0
    if (position == 0) {
      return mHeader;
    }

    // Recycle MusicHolder's items
    MusicHolder holder;
    if (convertView == null) {
      convertView = LayoutInflater.from(getContext()).inflate(mLayoutId, parent, false);
      holder = new MusicHolder(convertView);
      // Remove the background layer
      holder.mOverlay.get().setBackgroundColor(0);
      convertView.setTag(holder);
    } else {
      holder = (MusicHolder) convertView.getTag();
    }

    // Retrieve the album
    final Album album = getItem(position - 1);
    final String albumName = album.mAlbumName;

    // Set each album name (line one)
    holder.mLineOne.get().setText(albumName);
    // Set the number of songs (line two)
    holder
        .mLineTwo
        .get()
        .setText(MusicUtils.makeLabel(getContext(), R.plurals.Nsongs, album.mSongNumber));
    // Set the album year (line three)
    holder.mLineThree.get().setText(album.mYear);
    // Asynchronously load the album images into the adapter
    mImageFetcher.loadAlbumImage(album.mArtistName, albumName, album.mAlbumId, holder.mImage.get());
    // Play the album when the artwork is touched
    playAlbum(holder.mImage.get(), position);
    return convertView;
  }
Esempio n. 7
0
  /**
   * 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), 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));
              MusicUtils.playAll(getContext(), albumList, 0, false);
            }
          });
    } else {
      setDefault(context);
    }
  }
 /** Flushes the disk cache. */
 public void flush() {
   mImageFetcher.flush();
 }
 /** @param album The key used to find the cached album to remove */
 public void removeFromCache(final Album album) {
   if (mImageFetcher != null) {
     mImageFetcher.removeFromCache(
         ImageFetcher.generateAlbumCacheKey(album.mAlbumName, album.mArtistName));
   }
 }
 /** @param pause True to temporarily pause the disk cache, false otherwise. */
 public void setPauseDiskCache(final boolean pause) {
   if (mImageFetcher != null) {
     mImageFetcher.setPauseDiskCache(pause);
   }
 }
    /** {@inheritDoc} */
    @Override
    public void bindView(final View convertView, final Context context, final Cursor cursor) {
      /* Recycle ViewHolder's items */
      MusicHolder holder = (MusicHolder) convertView.getTag();
      if (holder == null) {
        holder = new MusicHolder(convertView);
        convertView.setTag(holder);
      }

      // Get the MIME type
      final String mimetype =
          cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.MIME_TYPE));

      if (mimetype.equals("artist")) {
        holder.mImage.get().setScaleType(ScaleType.CENTER_CROP);

        // Get the artist name
        final String artist = cursor.getString(cursor.getColumnIndexOrThrow(ArtistColumns.ARTIST));
        holder.mLineOne.get().setText(artist);

        // Get the album count
        final String albumCount = cursor.getString(cursor.getColumnIndexOrThrow("data1"));
        holder.mLineTwo.get().setText(MusicUtils.makeLabel(context, R.plurals.Nalbums, albumCount));

        // Get the song count
        final String songCount = cursor.getString(cursor.getColumnIndexOrThrow("data2"));
        holder.mLineThree.get().setText(MusicUtils.makeLabel(context, R.plurals.Nsongs, songCount));

        // Asynchronously load the artist image into the adapter
        mImageFetcher.loadArtistImage(artist, holder.mImage.get());

        // Highlght the query
        mHighlighter.setText(holder.mLineOne.get(), artist, mPrefix);
      } else if (mimetype.equals("album")) {
        holder.mImage.get().setScaleType(ScaleType.FIT_XY);

        // Get the Id of the album
        final String id = cursor.getString(cursor.getColumnIndexOrThrow(BaseColumns._ID));

        // Get the album name
        final String album = cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ALBUM));
        holder.mLineOne.get().setText(album);

        // Get the artist name
        final String artist = cursor.getString(cursor.getColumnIndexOrThrow(AlbumColumns.ARTIST));
        holder.mLineTwo.get().setText(artist);

        // Asynchronously load the album images into the adapter
        mImageFetcher.loadAlbumImage(artist, album, id, holder.mImage.get());
        // Asynchronously load the artist image into the adapter
        mImageFetcher.loadArtistImage(artist, holder.mBackground.get());

        // Highlght the query
        mHighlighter.setText(holder.mLineOne.get(), album, mPrefix);

      } else if (mimetype.startsWith("audio/")
          || mimetype.equals("application/ogg")
          || mimetype.equals("application/x-ogg")) {
        holder.mImage.get().setScaleType(ScaleType.FIT_XY);
        holder.mImage.get().setImageResource(R.drawable.header_temp);

        // Get the track name
        final String track = cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.TITLE));
        holder.mLineOne.get().setText(track);

        // Get the album name
        final String album = cursor.getString(cursor.getColumnIndexOrThrow(AudioColumns.ALBUM));
        holder.mLineTwo.get().setText(album);

        final String artist = cursor.getString(cursor.getColumnIndexOrThrow(AudioColumns.ARTIST));
        // Asynchronously load the artist image into the adapter
        mImageFetcher.loadArtistImage(artist, holder.mBackground.get());
        holder.mLineThree.get().setText(artist);

        // Highlght the query
        mHighlighter.setText(holder.mLineOne.get(), track, mPrefix);
      }
    }