Fixed notification when using next/previous

This commit is contained in:
Joshua Bahnsen 2013-01-04 08:57:23 -07:00
parent 49c9d3184f
commit 7a520554ec
14 changed files with 18 additions and 19 deletions

View File

@ -2,7 +2,7 @@
<manifest xmlns:a="http://schemas.android.com/apk/res/android"
package="net.sourceforge.subsonic.androidapp"
a:versionCode="47"
a:versionName="3.9.9.3" a:installLocation="auto">
a:versionName="3.9.9.4" a:installLocation="auto">
<uses-permission a:name="android.permission.INTERNET"/>
<uses-permission a:name="android.permission.READ_PHONE_STATE"/>

View File

@ -2,7 +2,7 @@
<manifest xmlns:a="http://schemas.android.com/apk/res/android"
package="net.sourceforge.subsonic.androidapp"
a:versionCode="47"
a:versionName="3.9.9.3" a:installLocation="auto">
a:versionName="3.9.9.4" a:installLocation="auto">
<uses-permission a:name="android.permission.INTERNET"/>
<uses-permission a:name="android.permission.READ_PHONE_STATE"/>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -19,6 +19,7 @@
package net.sourceforge.subsonic.androidapp.service;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
@ -28,7 +29,9 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManager;
import android.util.Log;
import android.widget.RemoteViews;
import net.sourceforge.subsonic.androidapp.R;
import net.sourceforge.subsonic.androidapp.activity.DownloadActivity;
import net.sourceforge.subsonic.androidapp.audiofx.EqualizerController;
import net.sourceforge.subsonic.androidapp.audiofx.VisualizerController;
import net.sourceforge.subsonic.androidapp.domain.MusicDirectory;
@ -127,6 +130,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
});
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
notification.contentView = new RemoteViews(this.getPackageName(), R.layout.notification);
Intent notificationIntent = new Intent(this, DownloadActivity.class);
notification.contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Util.linkButtons(this, notification.contentView, false);
if (equalizerAvailable) {
equalizerController = new EqualizerController(this, mediaPlayer);

View File

@ -577,38 +577,31 @@ public class Util extends DownloadActivity {
String text = song.getArtist();
String album = song.getAlbum();
RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification);
// 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
contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
} else {
contentView.setImageViewBitmap(R.id.notification_image, bitmap);
notification.contentView.setImageViewBitmap(R.id.notification_image, bitmap);
}
} catch (Exception x) {
Log.w(TAG, "Failed to get notification cover art", x);
contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
notification.contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
}
// set the text for the notifications
contentView.setTextViewText(R.id.trackname, title);
contentView.setTextViewText(R.id.artist, text);
contentView.setTextViewText(R.id.album, album);
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)
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)
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);
notification.contentView = contentView;
Intent notificationIntent = new Intent(context, DownloadActivity.class);
notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
// Send the notification and put the service in the foreground.
handler.post(new Runnable() {
@Override
@ -618,7 +611,6 @@ public class Util extends DownloadActivity {
});
// Update widget
linkButtons(context, contentView, false);
SubsonicAppWidgetProvider4x1.getInstance().notifyChange(context, downloadService, true);
}
@ -787,7 +779,7 @@ public class Util extends DownloadActivity {
context.sendBroadcast(intent);
}
private static void linkButtons(Context context, RemoteViews views, boolean playerActive) {
public static void linkButtons(Context context, RemoteViews views, boolean playerActive) {
Intent intent = new Intent(context, playerActive ? DownloadActivity.class : MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);