Skip to content

Commit

Permalink
Merge pull request #19 from KevinTCoughlin/update-notification-action
Browse files Browse the repository at this point in the history
Toggle Pause and Resume actions on notification for playback.
  • Loading branch information
KevinTCoughlin committed Sep 19, 2015
2 parents 07650e5 + 1074a22 commit c9ddbcc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Smodr/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kevintcoughlin.smodr"
android:versionCode="14"
android:versionName="1.4.5">
android:versionCode="15"
android:versionName="1.4.6">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import android.graphics.BitmapFactory;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import com.kevintcoughlin.smodr.R;
Expand Down Expand Up @@ -129,18 +131,17 @@ private void stopPlayback() {

private void createNotification() {
final Intent mIntent = new Intent(this, MediaPlaybackService.class);
mIntent.setAction(getAction());
final PendingIntent mPendingIntent = PendingIntent.getService(this, 0, mIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mIntent.setAction(ACTION_STOP);

final NotificationCompat.Action action = new NotificationCompat.Action.Builder(
R.drawable.ic_action_pause,
getString(R.string.notification_action_pause),
getIcon(),
getTitle(),
mPendingIntent).build();

final NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon))
.setSmallIcon(R.drawable.ic_action_play)
.setSmallIcon(getIcon())
.setOngoing(true)
.setContentTitle(mTitle)
.setContentText(mDescription)
Expand Down Expand Up @@ -171,4 +172,22 @@ public void onPrepared(MediaPlayer mediaPlayer) {
createNotification();
mPrepared = true;
}

@DrawableRes
private int getIcon() {
return (mMediaPlayer != null && mMediaPlayer.isPlaying())
? R.drawable.ic_action_pause
: R.drawable.ic_action_play;
}

@StringRes
private String getTitle() {
return (mMediaPlayer != null && mMediaPlayer.isPlaying())
? getString(R.string.notification_action_pause)
: getString(R.string.notification_action_play);
}

private String getAction() {
return (mMediaPlayer != null && mMediaPlayer.isPlaying()) ? ACTION_PAUSE : ACTION_RESUME;
}
}
1 change: 1 addition & 0 deletions Smodr/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<string name="cover_art">Cover art</string>
<string name="facebook_app_id">889919744389128</string>
<string name="test_device_id">C6D397172C2598AF256CF30C6393FBFC</string>
<string name="notification_action_play">Play</string>
</resources>

0 comments on commit c9ddbcc

Please sign in to comment.