Show album art in the background of the song list for an album.
diff --git a/src/com/android/music/MusicUtils.java b/src/com/android/music/MusicUtils.java
index 58f9bee..d1aea06 100644
--- a/src/com/android/music/MusicUtils.java
+++ b/src/com/android/music/MusicUtils.java
@@ -32,6 +32,10 @@
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
+import android.graphics.ColorMatrix;
+import android.graphics.ColorMatrixColorFilter;
+import android.graphics.Matrix;
+import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -903,11 +907,20 @@
}
return null;
}
-
+
+ /** Get album art for specified album. You should not pass in the album id
+ * for the "unknown" album here (use -1 instead)
+ * This method always returns the default album art icon when no album art is found.
+ */
+ public static Bitmap getArtwork(Context context, long song_id, long album_id) {
+ return getArtwork(context, song_id, album_id, true);
+ }
+
/** Get album art for specified album. You should not pass in the album id
* for the "unknown" album here (use -1 instead)
*/
- public static Bitmap getArtwork(Context context, long song_id, long album_id) {
+ public static Bitmap getArtwork(Context context, long song_id, long album_id,
+ boolean allowdefault) {
if (album_id < 0) {
// This is something that is not in the database, so get the album art directly
@@ -918,7 +931,10 @@
return bm;
}
}
- return getDefaultArtwork(context);
+ if (allowdefault) {
+ return getDefaultArtwork(context);
+ }
+ return null;
}
ContentResolver res = context.getContentResolver();
@@ -935,11 +951,11 @@
if (bm != null) {
if (bm.getConfig() == null) {
bm = bm.copy(Bitmap.Config.RGB_565, false);
- if (bm == null) {
+ if (bm == null && allowdefault) {
return getDefaultArtwork(context);
}
}
- } else {
+ } else if (allowdefault) {
bm = getDefaultArtwork(context);
}
return bm;
@@ -1180,4 +1196,41 @@
nowPlayingView.setVisibility(View.GONE);
}
+ static void setBackground(View v, Bitmap bm) {
+
+ if (bm == null) {
+ v.setBackgroundResource(0);
+ return;
+ }
+
+ int vwidth = v.getWidth();
+ int vheight = v.getHeight();
+ int bwidth = bm.getWidth();
+ int bheight = bm.getHeight();
+ float scalex = (float) vwidth / bwidth;
+ float scaley = (float) vheight / bheight;
+ float scale = Math.max(scalex, scaley) * 1.3f;
+
+ Bitmap.Config config = Bitmap.Config.ARGB_8888;
+ Bitmap bg = Bitmap.createBitmap(vwidth, vheight, config);
+ Canvas c = new Canvas(bg);
+ Paint paint = new Paint();
+ paint.setAntiAlias(true);
+ paint.setFilterBitmap(true);
+ ColorMatrix greymatrix = new ColorMatrix();
+ greymatrix.setSaturation(0);
+ ColorMatrix darkmatrix = new ColorMatrix();
+ darkmatrix.setScale(.3f, .3f, .3f, 1.0f);
+ greymatrix.postConcat(darkmatrix);
+ ColorFilter filter = new ColorMatrixColorFilter(greymatrix);
+ paint.setColorFilter(filter);
+ Matrix matrix = new Matrix();
+ matrix.setTranslate(-bwidth/2, -bheight/2); // move bitmap center to origin
+ matrix.postRotate(10);
+ matrix.postScale(scale, scale);
+ matrix.postTranslate(vwidth/2, vheight/2); // Move bitmap center to view center
+ c.drawBitmap(bm, matrix, paint);
+ v.setBackgroundDrawable(new BitmapDrawable(bg));
+ }
+
}
diff --git a/src/com/android/music/TrackBrowserActivity.java b/src/com/android/music/TrackBrowserActivity.java
index b544c4f..f972892 100644
--- a/src/com/android/music/TrackBrowserActivity.java
+++ b/src/com/android/music/TrackBrowserActivity.java
@@ -31,6 +31,7 @@
import android.database.AbstractCursor;
import android.database.CharArrayBuffer;
import android.database.Cursor;
+import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.MediaFile;
import android.net.Uri;
@@ -174,6 +175,14 @@
setListAdapter(mAdapter);
}
MusicUtils.bindToService(this, this);
+
+ // don't set the album art until after the view has been layed out
+ mTrackList.post(new Runnable() {
+
+ public void run() {
+ setAlbumArtBackground();
+ }
+ });
}
public void onServiceConnected(ComponentName name, IBinder service)
@@ -401,6 +410,21 @@
}
}
+ private void setAlbumArtBackground() {
+ try {
+ long albumid = Long.valueOf(mAlbumId);
+ Bitmap bm = MusicUtils.getArtwork(TrackBrowserActivity.this, -1, albumid, false);
+ if (bm != null) {
+ MusicUtils.setBackground(mTrackList, bm);
+ mTrackList.setCacheColorHint(0);
+ return;
+ }
+ } catch (Exception ex) {
+ }
+ mTrackList.setBackgroundResource(0);
+ mTrackList.setCacheColorHint(0xff000000);
+ }
+
private void setTitle() {
CharSequence fancyName = null;