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

@ -1,99 +1,98 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<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
a:id="@+id/appwidget_coverart"
a:layout_height="fill_parent"
a:layout_width="81dip"
a:scaleType="fitXY"
a:src="@drawable/appwidget_art_default"
a:clickable="true"
a:focusable="true"
a:background="@drawable/list_selector_holo_dark"/>
<LinearLayout <ImageView
a:id="@+id/linearLayout1" a:id="@+id/appwidget_coverart"
a:layout_width="match_parent" a:layout_width="81dip"
a:layout_height="match_parent" a:layout_height="fill_parent"
a:orientation="vertical" >
<LinearLayout
a:id="@+id/appwidget_top"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:background="@drawable/list_selector_holo_dark" a:background="@drawable/list_selector_holo_dark"
a:clickable="true" a:clickable="true"
a:focusable="true" a:focusable="true"
a:orientation="vertical" > a:scaleType="fitXY"
a:src="@drawable/appwidget_art_default" />
<TextView
a:id="@+id/title"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:ellipsize="none"
a:fadingEdge="horizontal"
a:fadingEdgeLength="20dip"
a:minHeight="16sp"
a:paddingLeft="5dip"
a:paddingRight="5dip"
a:singleLine="true"
a:textColor="@color/appwidget_text"
a:textSize="16sp"
a:textStyle="bold" />
<TextView
a:id="@+id/artist"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:ellipsize="none"
a:fadingEdge="horizontal"
a:fadingEdgeLength="10dip"
a:minHeight="12sp"
a:paddingBottom="2dip"
a:paddingLeft="5dip"
a:singleLine="true"
a:textColor="@color/cyan"
a:textSize="12sp" />
</LinearLayout>
<LinearLayout <LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android" a:id="@+id/linearLayout1"
a:layout_width="fill_parent" a:layout_width="match_parent"
a:layout_height="fill_parent" a:layout_height="match_parent"
a:layout_marginTop="3dp" a:orientation="vertical" >
a:orientation="horizontal" >
<ImageButton <LinearLayout
a:id="@+id/control_previous" a:id="@+id/appwidget_top"
a:layout_width="0dip" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="wrap_content"
a:layout_weight="1"
a:background="@drawable/list_selector_holo_dark" a:background="@drawable/list_selector_holo_dark"
a:scaleType="center" a:clickable="true"
a:src="@drawable/ic_appwidget_music_previous" /> a:focusable="true"
a:orientation="vertical" >
<ImageButton <TextView
a:id="@+id/control_play" a:id="@+id/title"
a:layout_width="0dip" a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="wrap_content"
a:layout_weight="1" a:ellipsize="none"
a:background="@drawable/list_selector_holo_dark" a:fadingEdge="horizontal"
a:scaleType="center" a:fadingEdgeLength="20dip"
a:src="@drawable/ic_appwidget_music_play" /> a:minHeight="16sp"
a:paddingLeft="5dip"
a:paddingRight="5dip"
a:singleLine="true"
a:textColor="@color/appwidget_text"
a:textSize="16sp"
a:textStyle="bold" />
<ImageButton <TextView
a:id="@+id/control_next" a:id="@+id/artist"
a:layout_width="0dip" a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:ellipsize="none"
a:fadingEdge="horizontal"
a:fadingEdgeLength="10dip"
a:minHeight="12sp"
a:paddingBottom="2dip"
a:paddingLeft="5dip"
a:singleLine="true"
a:textColor="@color/appwidget_text"
a:textSize="12sp" />
</LinearLayout>
<LinearLayout
a:layout_width="fill_parent"
a:layout_height="fill_parent" a:layout_height="fill_parent"
a:layout_weight="1" a:layout_marginTop="3dp"
a:background="@drawable/list_selector_holo_dark" a:orientation="horizontal" >
a:scaleType="center"
a:src="@drawable/ic_appwidget_music_next" /> <ImageButton
a:id="@+id/control_previous"
a:layout_width="0dip"
a:layout_height="fill_parent"
a:layout_weight="1"
a:background="@drawable/list_selector_holo_dark"
a:scaleType="center"
a:src="@drawable/ic_appwidget_music_previous" />
<ImageButton
a:id="@+id/control_play"
a:layout_width="0dip"
a:layout_height="fill_parent"
a:layout_weight="1"
a:background="@drawable/list_selector_holo_dark"
a:scaleType="center"
a:src="@drawable/ic_appwidget_music_play" />
<ImageButton
a:id="@+id/control_next"
a:layout_width="0dip"
a:layout_height="fill_parent"
a:layout_weight="1"
a:background="@drawable/list_selector_holo_dark"
a:scaleType="center"
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
if (show) { SubsonicAppWidgetProvider4x1.getInstance().notifyChange(this, this, playerState == PlayerState.STARTED);
Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState);
} else if (hide) { if (show) {
Util.hidePlayingNotification(this, this, handler); Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState);
} } else if (hide) {
} else { Util.hidePlayingNotification(this, this, handler);
Util.hidePlayingNotification(this, this, handler); }
}
if (playerState == STARTED) { if (playerState == STARTED) {
scrobbler.scrobble(this, currentPlaying, false); scrobbler.scrobble(this, currentPlaying, false);

View File

@ -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) { public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song, final Notification notification, PlayerState playerState) {
if (currentSong != song) { if (Util.isNotificationEnabled(context)) {
currentSong = song; 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);
}
// set the text for the notifications // Use the same text for the ticker and the expanded
notification.contentView.setTextViewText(R.id.trackname, title); // notification
notification.contentView.setTextViewText(R.id.artist, text); String title = song.getTitle();
notification.contentView.setTextViewText(R.id.album, album); String text = song.getArtist();
} String album = song.getAlbum();
if (playerState == PlayerState.PAUSED) { // Set the album art.
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play); try {
} int size = context.getResources()
else if (playerState == PlayerState.STARTED) { .getDrawable(R.drawable.unknown_album)
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_pause); .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) { 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) {