Show cover art in notification

This commit is contained in:
Christopher Eby 2011-10-26 18:39:04 -05:00
parent 8508b6f00e
commit 724e3cfe23
3 changed files with 23 additions and 9 deletions

View File

@ -22,15 +22,17 @@ THE SOFTWARE.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:scaleType="fitCenter"
android:maxWidth="80dip"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dip" />
android:layout_height="fill_parent"
android:layout_marginRight="5dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@ -51,4 +53,4 @@ THE SOFTWARE.
android:singleLine="true"
android:ellipsize="marquee" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -89,6 +89,9 @@ THE SOFTWARE.
<string name="enqueue_all">Enqueue All</string>
<string name="all_songs">All Songs</string>
<!-- Notification -->
<string name="notification_title_paused">%s (Paused)</string>
<!-- Preferences -->
<plurals name="seconds">
<item quantity="one">01 second</item>

View File

@ -1396,11 +1396,20 @@ public final class PlaybackService extends Service implements Handler.Callback,
*/
public Notification createNotification(Song song, int state)
{
int statusIcon = (state & FLAG_PLAYING) != 0 ? R.drawable.status_icon : R.drawable.status_icon_paused;
boolean playing = (state & FLAG_PLAYING) != 0;
RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification);
views.setImageViewResource(R.id.icon, statusIcon);
views.setTextViewText(R.id.title, song.title);
if (!Song.mDisableCoverArt && song.hasCover(this)) {
views.setImageViewUri(R.id.icon, song.getCoverUri());
} else {
views.setImageViewResource(R.id.icon, R.drawable.icon);
}
if (playing) {
views.setTextViewText(R.id.title, song.title);
} else {
views.setTextViewText(R.id.title, getResources().getString(R.string.notification_title_paused, song.title));
}
views.setTextViewText(R.id.artist, song.artist);
if (mInvertNotification) {
@ -1413,7 +1422,7 @@ public final class PlaybackService extends Service implements Handler.Callback,
Notification notification = new Notification();
notification.contentView = views;
notification.icon = statusIcon;
notification.icon = playing ? R.drawable.status_icon : R.drawable.status_icon_paused;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.contentIntent = mNotificationAction;
return notification;