Skip to content

Commit

Permalink
experimental expandable notification for Android 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Steele committed Jun 29, 2012
1 parent 8362fa3 commit 0afbd15
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/project.properties
Expand Up @@ -10,6 +10,6 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-15
target=android-16
apk-configurations=
android.library.reference.1=../library
89 changes: 89 additions & 0 deletions app/res/layout/notification_big.xml
@@ -0,0 +1,89 @@

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:gravity="center_vertical">

<ImageView
android:id="@+id/image"
android:layout_width="128dip"
android:layout_height="128dip"
android:src="@drawable/no_artwork" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dip"
android:layout_weight="1"
android:gravity="left|center_vertical"
android:orientation="vertical" >

<TextView
android:id="@+id/title"
style="@style/NotificationTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="Track Title" />

<TextView
android:id="@+id/text"
style="@style/NotificationText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="Artist Name" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<ImageButton
android:id="@+id/love"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:padding="7dip"
android:src="@drawable/love" />

<ImageButton
android:id="@+id/ban"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:padding="7dip"
android:src="@drawable/ban" />

<ImageButton
android:id="@+id/stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:padding="7dip"
android:src="@drawable/pause" />

<ImageButton
android:id="@+id/skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@null"
android:padding="7dip"
android:src="@drawable/skip" />

</LinearLayout>

</LinearLayout>

</LinearLayout>
31 changes: 23 additions & 8 deletions app/src/fm/last/android/player/RadioPlayerService.java
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
Expand Down Expand Up @@ -428,14 +429,7 @@ private void clearNotification() {
}
}

private Notification buildNotification(Bitmap art) {
Notification notification = new Notification(R.drawable.as_statusbar, getString(R.string.playerservice_streaming_ticker_text, currentTrack.getTitle(),
currentTrack.getCreator()), System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(RadioPlayerService.this, 0, new Intent(RadioPlayerService.this, Player.class), 0);
String info = currentTrack.getTitle() + " - " + currentTrack.getCreator();
notification.setLatestEventInfo(RadioPlayerService.this, currentStation.getName(), info, contentIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);
private void fillNotificationView(RemoteViews contentView, Bitmap art) {
if(art != null)
contentView.setImageViewBitmap(R.id.image, mArtwork);
else
Expand All @@ -460,7 +454,28 @@ private Notification buildNotification(Bitmap art) {
intent = new Intent("fm.last.android.widget.STOP");
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
contentView.setOnClickPendingIntent(R.id.stop, pendingIntent);
}

private Notification buildNotification(Bitmap art) {
Notification notification = new Notification(R.drawable.as_statusbar, getString(R.string.playerservice_streaming_ticker_text, currentTrack.getTitle(),
currentTrack.getCreator()), System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(RadioPlayerService.this, 0, new Intent(RadioPlayerService.this, Player.class), 0);
String info = currentTrack.getTitle() + " - " + currentTrack.getCreator();
notification.setLatestEventInfo(RadioPlayerService.this, currentStation.getName(), info, contentIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);
fillNotificationView(contentView, art);
notification.contentView = contentView;

try {
Field f = Notification.class.getField("bigContentView");
RemoteViews bigContentView = new RemoteViews(getPackageName(), R.layout.notification_big);
fillNotificationView(bigContentView, art);
f.set(notification, bigContentView);
} catch (Exception e) {
e.printStackTrace();
}

return notification;
}

Expand Down

0 comments on commit 0afbd15

Please sign in to comment.