Пример #1
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);
   }
 }
    /** {@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);
      }
    }