diff --git a/res/layout/appwidget4x1.xml b/res/layout/appwidget4x1.xml index 1223c9f5..94146244 100644 --- a/res/layout/appwidget4x1.xml +++ b/res/layout/appwidget4x1.xml @@ -1,99 +1,98 @@ - + a:layout_width="fill_parent" + a:layout_height="fill_parent" + a:background="@drawable/appwidget_bg" + a:orientation="horizontal" > - - - - - - - - + a:scaleType="fitXY" + a:src="@drawable/appwidget_art_default" /> + a:id="@+id/linearLayout1" + a:layout_width="match_parent" + a:layout_height="match_parent" + a:orientation="vertical" > - + a:clickable="true" + a:focusable="true" + a:orientation="vertical" > - + - + + + + a:layout_marginTop="3dp" + a:orientation="horizontal" > + + + + + + + - - - + \ No newline at end of file diff --git a/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java b/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java index eda6427c..f8191a05 100644 --- a/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java +++ b/src/net/sourceforge/subsonic/androidapp/service/DownloadServiceImpl.java @@ -44,6 +44,7 @@ import net.sourceforge.subsonic.androidapp.audiofx.VisualizerController; import net.sourceforge.subsonic.androidapp.domain.MusicDirectory; import net.sourceforge.subsonic.androidapp.domain.PlayerState; import net.sourceforge.subsonic.androidapp.domain.RepeatMode; +import net.sourceforge.subsonic.androidapp.provider.SubsonicAppWidgetProvider4x1; import net.sourceforge.subsonic.androidapp.receiver.MediaButtonIntentReceiver; import net.sourceforge.subsonic.androidapp.util.CancellableTask; import net.sourceforge.subsonic.androidapp.util.LRUCache; @@ -435,7 +436,10 @@ public class DownloadServiceImpl extends Service implements DownloadService { setRemoteControl(); - if (Util.isNotificationEnabled(this) && currentPlaying != null && showNotification) { + // Update widget + SubsonicAppWidgetProvider4x1.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED); + + if (currentPlaying != null && showNotification) { Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState); } else { Util.hidePlayingNotification(this, this, handler); @@ -684,15 +688,14 @@ public class DownloadServiceImpl extends Service implements DownloadService { setRemoteControl(); - if (Util.isNotificationEnabled(this)) { - if (show) { - Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState); - } else if (hide) { - Util.hidePlayingNotification(this, this, handler); - } - } else { - Util.hidePlayingNotification(this, this, handler); - } + // Update widget + SubsonicAppWidgetProvider4x1.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED); + + if (show) { + Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState); + } else if (hide) { + Util.hidePlayingNotification(this, this, handler); + } if (playerState == STARTED) { scrobbler.scrobble(this, currentPlaying, false); diff --git a/src/net/sourceforge/subsonic/androidapp/util/Util.java b/src/net/sourceforge/subsonic/androidapp/util/Util.java index 34c7476b..759f51cf 100644 --- a/src/net/sourceforge/subsonic/androidapp/util/Util.java +++ b/src/net/sourceforge/subsonic/androidapp/util/Util.java @@ -592,52 +592,53 @@ public class Util extends DownloadActivity { public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song, final Notification notification, PlayerState playerState) { - if (currentSong != song) { - currentSong = song; - - // Use the same text for the ticker and the expanded notification - String title = song.getTitle(); - String text = song.getArtist(); - String album = song.getAlbum(); - - // Set the album art. - try { - int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); - Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); - if (bitmap == null) { - // set default album art - notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); - } else { - notification.contentView.setImageViewBitmap(R.id.notification_image, bitmap); - } - } catch (Exception x) { - Log.w(TAG, "Failed to get notification cover art", x); - notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); - } + if (Util.isNotificationEnabled(context)) { + if (currentSong != song) { + currentSong = song; - // set the text for the notifications - notification.contentView.setTextViewText(R.id.trackname, title); - notification.contentView.setTextViewText(R.id.artist, text); - notification.contentView.setTextViewText(R.id.album, album); - } - - if (playerState == PlayerState.PAUSED) { - notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play); - } - else if (playerState == PlayerState.STARTED) { - notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_pause); + // Use the same text for the ticker and the expanded + // notification + String title = song.getTitle(); + String text = song.getArtist(); + String album = song.getAlbum(); + + // Set the album art. + try { + int size = context.getResources() + .getDrawable(R.drawable.unknown_album) + .getIntrinsicHeight(); + Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); + if (bitmap == null) { + // set default album art + notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); + } else { + notification.contentView.setImageViewBitmap(R.id.notification_image, bitmap); + } + } catch (Exception x) { + Log.w(TAG, "Failed to get notification cover art", x); + notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); + } + + // set the text for the notifications + notification.contentView.setTextViewText(R.id.trackname, title); + notification.contentView.setTextViewText(R.id.artist, text); + notification.contentView.setTextViewText(R.id.album, album); + } + + if (playerState == PlayerState.PAUSED) { + notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play); + } else if (playerState == PlayerState.STARTED) { + notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_pause); + } + + // Send the notification and put the service in the foreground. + handler.post(new Runnable() { + @Override + public void run() { + startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification); + } + }); } - - // Send the notification and put the service in the foreground. - handler.post(new Runnable() { - @Override - public void run() { - startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification); - } - }); - - // Update widget - SubsonicAppWidgetProvider4x1.getInstance().notifyChange(context, downloadService, true); } public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler) { @@ -651,9 +652,6 @@ public class Util extends DownloadActivity { stopForeground(downloadService, true); } }); - - // Update widget - SubsonicAppWidgetProvider4x1.getInstance().notifyChange(context, downloadService, false); } public static void sleepQuietly(long millis) {