Fix widget

This commit is contained in:
Joshua Bahnsen 2013-02-22 19:59:40 -07:00
parent 4c7c0ebf90
commit 8d4bf5d4b0
3 changed files with 141 additions and 141 deletions

View File

@ -2,19 +2,20 @@
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:orientation="horizontal" a:background="@drawable/appwidget_bg"
a:background="@drawable/appwidget_bg"> a:orientation="horizontal" >
<ImageView
<ImageView
a:id="@+id/appwidget_coverart" a:id="@+id/appwidget_coverart"
a:layout_height="fill_parent"
a:layout_width="81dip" a:layout_width="81dip"
a:scaleType="fitXY" a:layout_height="fill_parent"
a:src="@drawable/appwidget_art_default" a:background="@drawable/list_selector_holo_dark"
a:clickable="true" a:clickable="true"
a:focusable="true" a:focusable="true"
a:background="@drawable/list_selector_holo_dark"/> a:scaleType="fitXY"
a:src="@drawable/appwidget_art_default" />
<LinearLayout <LinearLayout
a:id="@+id/linearLayout1" a:id="@+id/linearLayout1"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="match_parent" a:layout_height="match_parent"
@ -55,12 +56,11 @@
a:paddingBottom="2dip" a:paddingBottom="2dip"
a:paddingLeft="5dip" a:paddingLeft="5dip"
a:singleLine="true" a:singleLine="true"
a:textColor="@color/cyan" a:textColor="@color/appwidget_text"
a:textSize="12sp" /> a:textSize="12sp" />
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="fill_parent" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:layout_marginTop="3dp" a:layout_marginTop="3dp"
@ -93,7 +93,6 @@
a:scaleType="center" a:scaleType="center"
a:src="@drawable/ic_appwidget_music_next" /> a:src="@drawable/ic_appwidget_music_next" />
</LinearLayout> </LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -44,6 +44,7 @@ import net.sourceforge.subsonic.androidapp.audiofx.VisualizerController;
import net.sourceforge.subsonic.androidapp.domain.MusicDirectory; import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
import net.sourceforge.subsonic.androidapp.domain.PlayerState; import net.sourceforge.subsonic.androidapp.domain.PlayerState;
import net.sourceforge.subsonic.androidapp.domain.RepeatMode; 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.receiver.MediaButtonIntentReceiver;
import net.sourceforge.subsonic.androidapp.util.CancellableTask; import net.sourceforge.subsonic.androidapp.util.CancellableTask;
import net.sourceforge.subsonic.androidapp.util.LRUCache; import net.sourceforge.subsonic.androidapp.util.LRUCache;
@ -435,7 +436,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
setRemoteControl(); 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); Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState);
} else { } else {
Util.hidePlayingNotification(this, this, handler); Util.hidePlayingNotification(this, this, handler);
@ -684,15 +688,14 @@ public class DownloadServiceImpl extends Service implements DownloadService {
setRemoteControl(); setRemoteControl();
if (Util.isNotificationEnabled(this)) { // Update widget
SubsonicAppWidgetProvider4x1.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED);
if (show) { if (show) {
Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState); Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState);
} else if (hide) { } else if (hide) {
Util.hidePlayingNotification(this, this, handler); Util.hidePlayingNotification(this, this, handler);
} }
} else {
Util.hidePlayingNotification(this, this, handler);
}
if (playerState == STARTED) { if (playerState == STARTED) {
scrobbler.scrobble(this, currentPlaying, false); scrobbler.scrobble(this, currentPlaying, false);

View File

@ -592,17 +592,21 @@ 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) { public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song, final Notification notification, PlayerState playerState) {
if (Util.isNotificationEnabled(context)) {
if (currentSong != song) { if (currentSong != song) {
currentSong = song; currentSong = song;
// Use the same text for the ticker and the expanded notification // Use the same text for the ticker and the expanded
// notification
String title = song.getTitle(); String title = song.getTitle();
String text = song.getArtist(); String text = song.getArtist();
String album = song.getAlbum(); String album = song.getAlbum();
// Set the album art. // Set the album art.
try { try {
int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); int size = context.getResources()
.getDrawable(R.drawable.unknown_album)
.getIntrinsicHeight();
Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size);
if (bitmap == null) { if (bitmap == null) {
// set default album art // set default album art
@ -623,8 +627,7 @@ public class Util extends DownloadActivity {
if (playerState == PlayerState.PAUSED) { if (playerState == PlayerState.PAUSED) {
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play); notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play);
} } else if (playerState == PlayerState.STARTED) {
else if (playerState == PlayerState.STARTED) {
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_pause); notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_pause);
} }
@ -635,9 +638,7 @@ public class Util extends DownloadActivity {
startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification); 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) { public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler) {
@ -651,9 +652,6 @@ public class Util extends DownloadActivity {
stopForeground(downloadService, true); stopForeground(downloadService, true);
} }
}); });
// Update widget
SubsonicAppWidgetProvider4x1.getInstance().notifyChange(context, downloadService, false);
} }
public static void sleepQuietly(long millis) { public static void sleepQuietly(long millis) {