Added expandable notifications to PlaybackService
This commit is contained in:
parent
d297b51255
commit
d85b90f56e
@ -53,6 +53,7 @@
|
||||
<!-- actions on feeditems -->
|
||||
<string name="download_label">Download</string>
|
||||
<string name="play_label">Play</string>
|
||||
<string name="pause_label">Pause</string>
|
||||
<string name="stream_label">Stream</string>
|
||||
<string name="remove_label">Remove</string>
|
||||
<string name="mark_read_label">Mark as read</string>
|
||||
|
@ -146,5 +146,12 @@ public class FeedMedia extends FeedFile {
|
||||
public boolean isInProgress() {
|
||||
return (this.position > 0);
|
||||
}
|
||||
|
||||
public FeedImage getImage() {
|
||||
if (item != null && item.getFeed() != null) {
|
||||
return item.getFeed().getImage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
@ -47,6 +48,7 @@ import de.danoeh.antennapod.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.feed.MediaType;
|
||||
import de.danoeh.antennapod.receiver.MediaButtonReceiver;
|
||||
import de.danoeh.antennapod.receiver.PlayerWidget;
|
||||
import de.danoeh.antennapod.util.BitmapDecoder;
|
||||
import de.danoeh.antennapod.util.ChapterUtils;
|
||||
|
||||
/** Controls the MediaPlayer that plays a FeedMedia-file */
|
||||
@ -125,7 +127,6 @@ public class PlaybackService extends Service {
|
||||
public static boolean isRunning = false;
|
||||
|
||||
private static final int NOTIFICATION_ID = 1;
|
||||
private NotificationCompat.Builder notificationBuilder;
|
||||
|
||||
private AudioManager audioManager;
|
||||
private ComponentName mediaButtonReceiver;
|
||||
@ -907,22 +908,57 @@ public class PlaybackService extends Service {
|
||||
}
|
||||
|
||||
/** Prepares notification and starts the service in the foreground. */
|
||||
@SuppressLint("NewApi")
|
||||
private void setupNotification() {
|
||||
PendingIntent pIntent = PendingIntent.getActivity(this, 0,
|
||||
PlaybackService.getPlayerActivityIntent(this),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
Bitmap icon = BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.ic_stat_antenna);
|
||||
notificationBuilder = new NotificationCompat.Builder(this)
|
||||
.setContentTitle(
|
||||
getString(R.string.playbackservice_notification_title))
|
||||
.setContentText(
|
||||
getString(R.string.playbackservice_notification_content))
|
||||
.setOngoing(true).setContentIntent(pIntent).setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.ic_stat_antenna);
|
||||
Bitmap icon = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
if (media != null && media.getImage() != null
|
||||
&& media.getImage().getFile_url() != null) {
|
||||
int iconSize = getResources().getDimensionPixelSize(
|
||||
android.R.dimen.notification_large_icon_width);
|
||||
icon = BitmapDecoder.decodeBitmap(iconSize, media.getImage()
|
||||
.getFile_url());
|
||||
}
|
||||
}
|
||||
if (icon == null) {
|
||||
icon = BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.ic_stat_antenna);
|
||||
}
|
||||
|
||||
startForeground(NOTIFICATION_ID, notificationBuilder.getNotification());
|
||||
String contentText = media.getItem().getFeed().getTitle();
|
||||
String contentTitle = media.getItem().getTitle();
|
||||
Notification notification = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= 16) {
|
||||
Intent pauseButtonIntent = new Intent(this, PlaybackService.class);
|
||||
pauseButtonIntent.putExtra(MediaButtonReceiver.EXTRA_KEYCODE,
|
||||
KeyEvent.KEYCODE_MEDIA_PAUSE);
|
||||
PendingIntent pauseButtonPendingIntent = PendingIntent
|
||||
.getService(this, 0, pauseButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Notification.Builder notificationBuilder = new Notification.Builder(
|
||||
this)
|
||||
.setContentTitle(contentTitle)
|
||||
.setContentText(contentText)
|
||||
.setOngoing(true)
|
||||
.setContentIntent(pIntent)
|
||||
.setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.ic_stat_antenna)
|
||||
.addAction(android.R.drawable.ic_media_pause,
|
||||
getString(R.string.pause_label),
|
||||
pauseButtonPendingIntent);
|
||||
notification = notificationBuilder.build();
|
||||
} else {
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
|
||||
this).setContentTitle(contentTitle)
|
||||
.setContentText(contentText).setOngoing(true)
|
||||
.setContentIntent(pIntent).setLargeIcon(icon)
|
||||
.setSmallIcon(R.drawable.ic_stat_antenna);
|
||||
notification = notificationBuilder.getNotification();
|
||||
}
|
||||
startForeground(NOTIFICATION_ID, notification);
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Notification set up");
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
package de.danoeh.antennapod.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Log;
|
||||
@ -17,26 +22,30 @@ public class BitmapDecoder {
|
||||
}
|
||||
|
||||
public static Bitmap decodeBitmap(int preferredLength, String fileUrl) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(fileUrl, options);
|
||||
int srcWidth = options.outWidth;
|
||||
int srcHeight = options.outHeight;
|
||||
int length = Math.max(srcWidth, srcHeight);
|
||||
int sampleSize = calculateSampleSize(preferredLength, length);
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Using samplesize " + sampleSize);
|
||||
options.inJustDecodeBounds = false;
|
||||
options.inSampleSize = sampleSize;
|
||||
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
if (fileUrl != null && new File(fileUrl).exists()) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(fileUrl, options);
|
||||
int srcWidth = options.outWidth;
|
||||
int srcHeight = options.outHeight;
|
||||
int length = Math.max(srcWidth, srcHeight);
|
||||
int sampleSize = calculateSampleSize(preferredLength, length);
|
||||
if (AppConfig.DEBUG)
|
||||
Log.d(TAG, "Using samplesize " + sampleSize);
|
||||
options.inJustDecodeBounds = false;
|
||||
options.inSampleSize = sampleSize;
|
||||
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
||||
|
||||
Bitmap decodedBitmap = BitmapFactory.decodeFile(fileUrl, options);
|
||||
if (decodedBitmap == null) {
|
||||
Log.i(TAG,
|
||||
"Bitmap could not be decoded in custom sample size. Trying default sample size (path was "
|
||||
+ fileUrl + ")");
|
||||
decodedBitmap = BitmapFactory.decodeFile(fileUrl);
|
||||
Bitmap decodedBitmap = BitmapFactory.decodeFile(fileUrl, options);
|
||||
if (decodedBitmap == null) {
|
||||
Log.i(TAG,
|
||||
"Bitmap could not be decoded in custom sample size. Trying default sample size (path was "
|
||||
+ fileUrl + ")");
|
||||
decodedBitmap = BitmapFactory.decodeFile(fileUrl);
|
||||
}
|
||||
return decodedBitmap;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return decodedBitmap;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user