support for expanded notifications
This commit is contained in:
parent
0ede5aa4d1
commit
beb440a7ac
128
res/layout/notification_expanded.xml
Normal file
128
res/layout/notification_expanded.xml
Normal file
@ -0,0 +1,128 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2014 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cover"
|
||||
android:scaleType="fitCenter"
|
||||
android:layout_width="96dip"
|
||||
android:layout_height="96dip"
|
||||
android:layout_marginRight="8dip"
|
||||
android:contentDescription="@string/cover_art" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@android:style/TextAppearance.StatusBar.EventContent.Title"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee" />
|
||||
<TextView
|
||||
android:id="@+id/album"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@android:style/TextAppearance.StatusBar.EventContent"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee" />
|
||||
<TextView
|
||||
android:id="@+id/artist"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@android:style/TextAppearance.StatusBar.EventContent"
|
||||
android:singleLine="true"
|
||||
android:ellipsize="marquee" />
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/close"
|
||||
android:padding="5dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="24dip"
|
||||
android:layout_gravity="top"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/notification_close"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:contentDescription="@string/close_notification" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/previous"
|
||||
android:paddingTop="5dip"
|
||||
android:paddingBottom="5dip"
|
||||
android:layout_height="42dip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/previous"
|
||||
android:contentDescription="@string/next_song" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/play_pause"
|
||||
android:paddingTop="5dip"
|
||||
android:paddingBottom="5dip"
|
||||
android:layout_height="42dip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/play"
|
||||
android:contentDescription="@string/play_pause" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/next"
|
||||
android:paddingTop="5dip"
|
||||
android:paddingBottom="5dip"
|
||||
android:layout_height="42dip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/next"
|
||||
android:contentDescription="@string/next_song" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
@ -1840,35 +1840,49 @@ public final class PlaybackService extends Service
|
||||
boolean playing = (state & FLAG_PLAYING) != 0;
|
||||
|
||||
RemoteViews views = new RemoteViews(getPackageName(), R.layout.notification);
|
||||
RemoteViews expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded);
|
||||
|
||||
Bitmap cover = song.getCover(this);
|
||||
if (cover == null) {
|
||||
views.setImageViewResource(R.id.cover, R.drawable.fallback_cover);
|
||||
expanded.setImageViewResource(R.id.cover, R.drawable.fallback_cover);
|
||||
} else {
|
||||
views.setImageViewBitmap(R.id.cover, cover);
|
||||
expanded.setImageViewBitmap(R.id.cover, cover);
|
||||
}
|
||||
|
||||
String title = song.title;
|
||||
|
||||
int playButton = playing ? R.drawable.pause : R.drawable.play;
|
||||
views.setImageViewResource(R.id.play_pause, playButton);
|
||||
expanded.setImageViewResource(R.id.play_pause, playButton);
|
||||
|
||||
ComponentName service = new ComponentName(this, PlaybackService.class);
|
||||
|
||||
Intent previous = new Intent(PlaybackService.ACTION_PREVIOUS_SONG);
|
||||
previous.setComponent(service);
|
||||
expanded.setOnClickPendingIntent(R.id.previous, PendingIntent.getService(this, 0, previous, 0));
|
||||
|
||||
Intent playPause = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK_NOTIFICATION);
|
||||
playPause.setComponent(service);
|
||||
views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0));
|
||||
expanded.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(this, 0, playPause, 0));
|
||||
|
||||
Intent next = new Intent(PlaybackService.ACTION_NEXT_SONG);
|
||||
next.setComponent(service);
|
||||
views.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));
|
||||
expanded.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));
|
||||
|
||||
Intent close = new Intent(PlaybackService.ACTION_CLOSE_NOTIFICATION);
|
||||
close.setComponent(service);
|
||||
views.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0));
|
||||
expanded.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0));
|
||||
|
||||
views.setTextViewText(R.id.title, title);
|
||||
views.setTextViewText(R.id.artist, song.artist);
|
||||
expanded.setTextViewText(R.id.title, title);
|
||||
expanded.setTextViewText(R.id.album, song.album);
|
||||
expanded.setTextViewText(R.id.artist, song.artist);
|
||||
|
||||
if (mInvertNotification) {
|
||||
views.setTextColor(R.id.title, 0xffffffff);
|
||||
@ -1880,6 +1894,9 @@ public final class PlaybackService extends Service
|
||||
notification.icon = R.drawable.status_icon;
|
||||
notification.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
notification.contentIntent = mNotificationAction;
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
notification.bigContentView = expanded; // expanded view is available since 4.1
|
||||
}
|
||||
return notification;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user