made new notification layout available for older platforms
This commit is contained in:
parent
a94f9fd3e5
commit
1c17be9760
|
@ -205,9 +205,9 @@ public class BackgroundPlayer extends Service /*implements MediaPlayer.OnPrepare
|
||||||
if(action.equals(ACTION_PLAYPAUSE)) {
|
if(action.equals(ACTION_PLAYPAUSE)) {
|
||||||
if(mediaPlayer.isPlaying()) {
|
if(mediaPlayer.isPlaying()) {
|
||||||
mediaPlayer.pause();
|
mediaPlayer.pause();
|
||||||
note.contentView.setImageViewResource(R.id.backgroundPlayPause, R.drawable.ic_play_circle_filled_white_24dp);
|
note.contentView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_play_circle_filled_white_24dp);
|
||||||
if(android.os.Build.VERSION.SDK_INT >=16){
|
if(android.os.Build.VERSION.SDK_INT >=16){
|
||||||
note.bigContentView.setImageViewResource(R.id.backgroundPlayPause, R.drawable.ic_play_circle_filled_white_24dp);
|
note.bigContentView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_play_circle_filled_white_24dp);
|
||||||
}
|
}
|
||||||
noteMgr.notify(noteID, note);
|
noteMgr.notify(noteID, note);
|
||||||
}
|
}
|
||||||
|
@ -215,9 +215,9 @@ public class BackgroundPlayer extends Service /*implements MediaPlayer.OnPrepare
|
||||||
//reacquire CPU lock after auto-releasing it on pause
|
//reacquire CPU lock after auto-releasing it on pause
|
||||||
mediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
|
mediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
|
||||||
mediaPlayer.start();
|
mediaPlayer.start();
|
||||||
note.contentView.setImageViewResource(R.id.backgroundPlayPause, R.drawable.ic_pause_white_24dp);
|
note.contentView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_pause_white_24dp);
|
||||||
if(android.os.Build.VERSION.SDK_INT >=16){
|
if(android.os.Build.VERSION.SDK_INT >=16){
|
||||||
note.bigContentView.setImageViewResource(R.id.backgroundPlayPause, R.drawable.ic_pause_white_24dp);
|
note.bigContentView.setImageViewResource(R.id.notificationPlayPause, R.drawable.ic_pause_white_24dp);
|
||||||
}
|
}
|
||||||
noteMgr.notify(noteID, note);
|
noteMgr.notify(noteID, note);
|
||||||
}
|
}
|
||||||
|
@ -275,11 +275,13 @@ public class BackgroundPlayer extends Service /*implements MediaPlayer.OnPrepare
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//build intent to return to video, on tapping notification
|
//build intent to return to video, on tapping notification
|
||||||
Intent openDetailView = new Intent(getApplicationContext(),
|
Intent openDetailViewIntent = new Intent(getApplicationContext(),
|
||||||
VideoItemDetailActivity.class);
|
VideoItemDetailActivity.class);
|
||||||
openDetailView.putExtra(VideoItemDetailFragment.STREAMING_SERVICE, serviceId);
|
openDetailViewIntent.putExtra(VideoItemDetailFragment.STREAMING_SERVICE, serviceId);
|
||||||
openDetailView.putExtra(VideoItemDetailFragment.VIDEO_URL, webUrl);
|
openDetailViewIntent.putExtra(VideoItemDetailFragment.VIDEO_URL, webUrl);
|
||||||
openDetailView.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
openDetailViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
PendingIntent openDetailView = PendingIntent.getActivity(owner, noteID,
|
||||||
|
openDetailViewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||||
|
|
||||||
noteBuilder
|
noteBuilder
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
|
@ -291,74 +293,39 @@ public class BackgroundPlayer extends Service /*implements MediaPlayer.OnPrepare
|
||||||
String.format(res.getString(
|
String.format(res.getString(
|
||||||
R.string.background_player_time_text), title))
|
R.string.background_player_time_text), title))
|
||||||
.setContentIntent(PendingIntent.getActivity(getApplicationContext(),
|
.setContentIntent(PendingIntent.getActivity(getApplicationContext(),
|
||||||
noteID, openDetailView,
|
noteID, openDetailViewIntent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT));
|
PendingIntent.FLAG_UPDATE_CURRENT));
|
||||||
|
|
||||||
|
|
||||||
if (android.os.Build.VERSION.SDK_INT < 21) {
|
RemoteViews view =
|
||||||
|
new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.player_notification);
|
||||||
|
view.setImageViewBitmap(R.id.notificationCover, videoThumbnail);
|
||||||
|
view.setTextViewText(R.id.notificationSongName, title);
|
||||||
|
view.setTextViewText(R.id.notificationArtist, channelName);
|
||||||
|
view.setOnClickPendingIntent(R.id.notificationStop, stopPI);
|
||||||
|
view.setOnClickPendingIntent(R.id.notificationPlayPause, playPI);
|
||||||
|
view.setOnClickPendingIntent(R.id.notificationBackgroundButton, openDetailView);
|
||||||
|
|
||||||
NotificationCompat.Action playButton = new NotificationCompat.Action.Builder
|
//possibly found the expandedView problem,
|
||||||
(R.drawable.ic_play_arrow_white_48dp,
|
//but can't test it as I don't have a 5.0 device. -medavox
|
||||||
res.getString(R.string.play_btn_text), playPI).build();
|
RemoteViews expandedView =
|
||||||
|
new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.player_notification_expanded);
|
||||||
|
expandedView.setImageViewBitmap(R.id.notificationCover, videoThumbnail);
|
||||||
|
expandedView.setTextViewText(R.id.notificationSongName, title);
|
||||||
|
expandedView.setTextViewText(R.id.notificationArtist, channelName);
|
||||||
|
expandedView.setOnClickPendingIntent(R.id.notificationStop, stopPI);
|
||||||
|
expandedView.setOnClickPendingIntent(R.id.notificationPlayPause, playPI);
|
||||||
|
expandedView.setOnClickPendingIntent(R.id.notificationBackgroundButton, openDetailView);
|
||||||
|
|
||||||
noteBuilder
|
noteBuilder.setCategory(Notification.CATEGORY_TRANSPORT);
|
||||||
.setContentTitle(title)
|
|
||||||
//really? Id like to put something more helpful here.
|
|
||||||
//was more of a placeholder than anything else. -medavox
|
|
||||||
//.setContentText("NewPipe is playing in the background")
|
|
||||||
.setContentText(channelName)
|
|
||||||
//.setAutoCancel(!mediaPlayer.isPlaying())
|
|
||||||
.setDeleteIntent(stopPI)
|
|
||||||
//doesn't fit with Notification.MediaStyle
|
|
||||||
//.setProgress(vidLength, 0, false)
|
|
||||||
.setLargeIcon(videoThumbnail)
|
|
||||||
.addAction(playButton);
|
|
||||||
//.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
||||||
//.setLargeIcon(cover)
|
|
||||||
|
|
||||||
//is wrapping this in an SDK version check really necessary,
|
//Make notification appear on lockscreen
|
||||||
// if we're using NotificationCompat?
|
noteBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
|
||||||
// the compat libraries should handle this, right? -medavox
|
|
||||||
if (android.os.Build.VERSION.SDK_INT >= 16)
|
|
||||||
noteBuilder.setPriority(Notification.PRIORITY_LOW);
|
|
||||||
|
|
||||||
noteBuilder.setStyle(new NotificationCompat.MediaStyle()
|
note = noteBuilder.build();
|
||||||
//.setMediaSession(mMediaSession.getSessionToken())
|
note.contentView = view;
|
||||||
.setShowActionsInCompactView(new int[]{0})
|
|
||||||
.setShowCancelButton(true)
|
|
||||||
.setCancelButtonIntent(stopPI));
|
|
||||||
if (videoThumbnail != null) {
|
|
||||||
noteBuilder.setLargeIcon(videoThumbnail);
|
|
||||||
}
|
|
||||||
note = noteBuilder.build();
|
|
||||||
} else {
|
|
||||||
RemoteViews view =
|
|
||||||
new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.player_notification);
|
|
||||||
view.setImageViewBitmap(R.id.backgroundCover, videoThumbnail);
|
|
||||||
view.setTextViewText(R.id.backgroundSongName, title);
|
|
||||||
view.setTextViewText(R.id.backgroundArtist, channelName);
|
|
||||||
view.setOnClickPendingIntent(R.id.backgroundStop, stopPI);
|
|
||||||
view.setOnClickPendingIntent(R.id.backgroundPlayPause, playPI);
|
|
||||||
|
|
||||||
//possibly found the expandedView problem,
|
if (android.os.Build.VERSION.SDK_INT > 16) {
|
||||||
//but can't test it as I don't have a 5.0 device. -medavox
|
|
||||||
RemoteViews expandedView =
|
|
||||||
new RemoteViews(BuildConfig.APPLICATION_ID, R.layout.player_notification_expanded);
|
|
||||||
expandedView.setImageViewBitmap(R.id.backgroundCover, videoThumbnail);
|
|
||||||
expandedView.setTextViewText(R.id.backgroundSongName, title);
|
|
||||||
expandedView.setTextViewText(R.id.backgroundArtist, channelName);
|
|
||||||
expandedView.setOnClickPendingIntent(R.id.backgroundStop, stopPI);
|
|
||||||
expandedView.setOnClickPendingIntent(R.id.backgroundPlayPause, playPI);
|
|
||||||
|
|
||||||
noteBuilder.setCategory(Notification.CATEGORY_TRANSPORT);
|
|
||||||
|
|
||||||
//Make notification appear on lockscreen
|
|
||||||
noteBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
|
|
||||||
|
|
||||||
note = noteBuilder.build();
|
|
||||||
note.contentView = view;
|
|
||||||
|
|
||||||
//todo: This never shows up. I was not able to figure out why:
|
|
||||||
note.bigContentView = expandedView;
|
note.bigContentView = expandedView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/content"
|
android:id="@+id/content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
@ -10,57 +10,72 @@
|
||||||
android:background="@color/background_notification_color"
|
android:background="@color/background_notification_color"
|
||||||
tools:targetApi="jelly_bean">
|
tools:targetApi="jelly_bean">
|
||||||
|
|
||||||
<ImageView
|
<Button
|
||||||
android:id="@+id/backgroundCover"
|
android:id="@+id/notificationBackgroundButton"
|
||||||
android:layout_width="64dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="64dp"
|
android:layout_height="64dp"
|
||||||
android:src="@drawable/dummy_thumbnail"
|
android:background="@android:color/transparent"/>
|
||||||
android:scaleType="centerCrop"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="0dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="64dp"
|
||||||
android:layout_marginLeft="8dp"
|
android:gravity="center_vertical"
|
||||||
android:layout_weight="1"
|
android:orientation="horizontal">
|
||||||
android:orientation="vertical" >
|
|
||||||
|
|
||||||
<TextView
|
<ImageView
|
||||||
android:id="@+id/backgroundSongName"
|
android:id="@+id/notificationCover"
|
||||||
style="@android:style/TextAppearance.StatusBar.EventContent.Title"
|
android:layout_width="64dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="64dp"
|
||||||
android:layout_height="wrap_content"
|
android:src="@drawable/dummy_thumbnail"
|
||||||
android:ellipsize="marquee"
|
android:scaleType="centerCrop"/>
|
||||||
android:singleLine="true"
|
|
||||||
android:text="title" />
|
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/backgroundArtist"
|
android:layout_width="0dp"
|
||||||
style="@android:style/TextAppearance.StatusBar.EventContent"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:ellipsize="marquee"
|
android:layout_marginLeft="8dp"
|
||||||
android:singleLine="true"
|
android:layout_weight="1"
|
||||||
android:text="artist" />
|
android:orientation="vertical" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/notificationSongName"
|
||||||
|
style="@android:style/TextAppearance.StatusBar.EventContent.Title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="title" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/notificationArtist"
|
||||||
|
style="@android:style/TextAppearance.StatusBar.EventContent"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="artist" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/notificationPlayPause"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:background="#00ffffff"
|
||||||
|
android:clickable="true"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:src="@drawable/ic_pause_white_24dp" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/notificationStop"
|
||||||
|
android:layout_width="40dp"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_margin="5dp"
|
||||||
|
android:background="#00ffffff"
|
||||||
|
android:clickable="true"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:src="@drawable/ic_close_white_24dp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageButton
|
|
||||||
android:id="@+id/backgroundPlayPause"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_margin="5dp"
|
|
||||||
android:background="#00ffffff"
|
|
||||||
android:clickable="true"
|
|
||||||
android:scaleType="fitXY"
|
|
||||||
android:src="@drawable/ic_pause_white_24dp" />
|
|
||||||
|
|
||||||
<ImageButton
|
</RelativeLayout>
|
||||||
android:id="@+id/backgroundStop"
|
|
||||||
android:layout_width="40dp"
|
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_margin="5dp"
|
|
||||||
android:background="#00ffffff"
|
|
||||||
android:clickable="true"
|
|
||||||
android:scaleType="fitXY"
|
|
||||||
android:src="@drawable/ic_close_white_24dp" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
|
@ -8,8 +8,14 @@
|
||||||
android:background="@color/background_notification_color"
|
android:background="@color/background_notification_color"
|
||||||
tools:targetApi="jelly_bean" >
|
tools:targetApi="jelly_bean" >
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/notificationBackgroundButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="128dp"
|
||||||
|
android:background="@android:color/transparent"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/backgroundCover"
|
android:id="@+id/notificationCover"
|
||||||
android:layout_width="128dp"
|
android:layout_width="128dp"
|
||||||
android:layout_height="128dp"
|
android:layout_height="128dp"
|
||||||
android:layout_marginRight="8dp"
|
android:layout_marginRight="8dp"
|
||||||
|
@ -19,13 +25,13 @@
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"
|
android:layout_height="fill_parent"
|
||||||
android:layout_above="@+id/backgroundButtons"
|
android:layout_above="@+id/notificationButtons"
|
||||||
android:layout_toRightOf="@+id/backgroundCover"
|
android:layout_toRightOf="@+id/notificationCover"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/backgroundSongName"
|
android:id="@+id/notificationSongName"
|
||||||
style="@android:style/TextAppearance.StatusBar.EventContent.Title"
|
style="@android:style/TextAppearance.StatusBar.EventContent.Title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -35,7 +41,7 @@
|
||||||
android:text="title" />
|
android:text="title" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/backgroundArtist"
|
android:id="@+id/notificationArtist"
|
||||||
style="@android:style/TextAppearance.StatusBar.EventContent"
|
style="@android:style/TextAppearance.StatusBar.EventContent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -45,7 +51,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/backgroundStop"
|
android:id="@+id/notificationStop"
|
||||||
android:layout_width="30dp"
|
android:layout_width="30dp"
|
||||||
android:layout_height="30dp"
|
android:layout_height="30dp"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
|
@ -56,16 +62,16 @@
|
||||||
android:src="@drawable/ic_close_white_24dp" />
|
android:src="@drawable/ic_close_white_24dp" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/backgroundButtons"
|
android:id="@+id/notificationButtons"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="50dp"
|
android:layout_height="50dp"
|
||||||
android:layout_alignBottom="@id/backgroundCover"
|
android:layout_alignBottom="@id/notificationCover"
|
||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
android:layout_toRightOf="@+id/backgroundCover"
|
android:layout_toRightOf="@+id/notificationCover"
|
||||||
android:orientation="horizontal" >
|
android:orientation="horizontal" >
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/backgroundPlayPause"
|
android:id="@+id/notificationPlayPause"
|
||||||
android:layout_width="40dp"
|
android:layout_width="40dp"
|
||||||
android:layout_height="40dp"
|
android:layout_height="40dp"
|
||||||
android:background="#00ffffff"
|
android:background="#00ffffff"
|
||||||
|
|
Loading…
Reference in New Issue