Permalink
Browse files

improvements to lock screen handling, addition of close button for no…

…tifications
  • Loading branch information...
rebeccanesson committed Nov 9, 2012
1 parent 5c974b7 commit 5607b191464591b91a060f53d2c11b4f15c1ba6c
Binary file not shown.
@@ -8,34 +8,43 @@
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp" />
-
+
<ImageView
- android:id="@+id/notPlayPause"
+ android:id="@+id/notClose"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
- android:src="@drawable/playerhater_av_pause"
android:layout_alignParentRight="true"
- android:padding="5dp"
+ android:layout_gravity="center_vertical"
android:paddingRight="10dp"
- android:layout_gravity="center_vertical" />
+ android:src="@drawable/playerhater_close" />
+
+ <ImageView
+ android:id="@+id/notPlayPause"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_gravity="center_vertical"
+ android:layout_toLeftOf="@id/notClose"
+ android:padding="5dp"
+ android:paddingRight="5dp"
+ android:src="@drawable/playerhater_av_pause" />
<TextView
android:id="@+id/notContentTitle"
style="@android:style/TextAppearance.StatusBar.EventContent.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:paddingTop="5dp"
- android:paddingBottom="2dp"
+ android:layout_toLeftOf="@id/notPlayPause"
android:layout_toRightOf="@id/notImage"
- android:layout_toLeftOf="@id/notPlayPause" />
+ android:paddingBottom="2dp"
+ android:paddingTop="5dp" />
<TextView
android:id="@+id/notContentText"
style="@android:style/TextAppearance.StatusBar.EventContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_toRightOf="@id/notImage"
android:layout_below="@id/notContentTitle"
- android:layout_toLeftOf="@id/notPlayPause" />
+ android:layout_toLeftOf="@id/notPlayPause"
+ android:layout_toRightOf="@id/notImage" />
</RelativeLayout>
@@ -6,7 +6,6 @@
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
-import android.media.RemoteControlClient;
import android.util.Log;
import android.view.KeyEvent;
@@ -48,11 +47,9 @@ public static void doReceive(Context context, Intent intent) {
KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE == event.getKeyCode()) {
if (mService.isPlaying()) {
mService.pause();
- mService.getRemoteControlClient().setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
} else {
try {
mService.play();
- mService.getRemoteControlClient().setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
} catch (IOException e) {
e.printStackTrace();
}
@@ -70,6 +67,13 @@ public static void doReceive(Context context, Intent intent) {
e.printStackTrace();
}
}
+ if (intent.getAction() != null && intent.getAction().equals(NotificationHandler.STOP_ACTION)) {
+ try {
+ mService.stop();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
}
@@ -16,7 +16,9 @@
protected static final int NOTIFICATION_NU = 9747245;
public static final int PLAY_PAUSE_CLICK_ID = 845832;
+ public static final int STOP_CLICK_ID = 845833;
public static final String PLAY_PAUSE_ACTION = "org.prx.playerhater.PlayPause";
+ public static final String STOP_ACTION = "org.prx.playerhater.Stop";
private boolean notificationIsVisible = false;
@@ -91,11 +93,17 @@ private Notification getNotification() {
PendingIntent playPausePendingIntent = PendingIntent.getBroadcast(mService.getApplicationContext(),
NotificationHandler.PLAY_PAUSE_CLICK_ID, intent, 0);
+ Intent stopIntent = new Intent(mService.getApplicationContext(), BroadcastReceiver.class);
+ stopIntent.setAction(NotificationHandler.STOP_ACTION);
+ PendingIntent stopPendingIntent = PendingIntent.getBroadcast(mService.getApplicationContext(),
+ NotificationHandler.STOP_CLICK_ID, stopIntent, 0);
+
//Remoteview and intent for my button
RemoteViews notificationView = new RemoteViews(mService.getBaseContext().getPackageName(), R.layout.notification);
if (notificationView != null) {
notificationView.setOnClickPendingIntent(R.id.notPlayPause, playPausePendingIntent);
+ notificationView.setOnClickPendingIntent(R.id.notClose, stopPendingIntent);
notificationView.setTextViewText(R.id.notContentTitle, mNotificationTitle);
notificationView.setTextViewText(R.id.notContentText, mNotificationText);
notificationView.setImageViewResource(R.id.notImage, mNotificationIcon);
@@ -168,6 +168,13 @@ public boolean pause() throws IllegalStateException {
updateProgressThread = null;
}
this.mNotificationHandler.setToPlay();
+ try {
+ mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
+ } catch (NoClassDefFoundError e) {
+
+ } catch (java.lang.NoSuchMethodError e) {
+
+ }
return true;
}
@@ -292,6 +299,32 @@ public boolean play() throws IllegalStateException, IOException {
return true;
}
+
+ public void resetLockScreenControls() {
+ try {
+ mAudioManager.registerMediaButtonEventReceiver(mRemoteControlResponder);
+ if (this.lockScreenTitle != null && this.lockScreenImage != null) {
+ mRemoteControlClient.editMetadata(true)
+ .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, this.lockScreenTitle)
+ .putBitmap(100, this.lockScreenImage).apply();
+ } else if (this.lockScreenTitle != null) {
+ mRemoteControlClient.editMetadata(true).putString(MediaMetadataRetriever.METADATA_KEY_TITLE,this.lockScreenTitle).apply();
+ } else if (this.lockScreenImage != null) {
+ mRemoteControlClient.editMetadata(true).putBitmap(100, this.lockScreenImage).apply();
+ }
+ mRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE|RemoteControlClient.FLAG_KEY_MEDIA_STOP);
+ mAudioManager.registerRemoteControlClient(mRemoteControlClient);
+ if (this.isPlaying() || this.isLoading()) {
+ mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
+ } else {
+ mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
+ }
+ } catch (NoClassDefFoundError e) {
+
+ } catch (java.lang.NoSuchMethodError e) {
+
+ }
+ }
public TransientPlayer transientPlay(FileDescriptor file, boolean isDuckable) {
return TransientPlayer.play(this, file, isDuckable);
@@ -46,6 +46,7 @@
void setNotificationTitle(String notificationTitle);
void setNotificationText(String notificationText);
+ void resetLockScreenControls();
void setLockScreenImage(FileDescriptor file);
void setLockScreenImage(Resources res, int id);
void setLockScreenTitle(String title);
@@ -302,4 +302,8 @@ public void setLockScreenTitle(String title) {
mService.setLockScreenTitle(title);
}
+ @Override
+ public void resetLockScreenControls() {
+ mService.resetLockScreenControls();
+ }
}

0 comments on commit 5607b19

Please sign in to comment.