From 184498ce5a8d77e1d9c45693363829daaeef9611 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Fri, 8 Oct 2010 17:57:18 -0400 Subject: [PATCH] Allow notifications to not specify a contentIntent. If they don't, the click events will be passed through to the individual views in the notification view, which may have their own PendingIntents attached. Previously, it was against the UX spec to allow this, but now we are changing that and will have buttons in there. Change-Id: I674234212f64b2b8802a0708b7eed0614e147ca3 --- .../systemui/statusbar/LatestItemView.java | 12 +++++++++++- .../statusbar/PhoneStatusBarService.java | 4 ++++ .../tablet/TabletStatusBarService.java | 4 ++++ .../server/NotificationManagerService.java | 4 ---- .../statusbartest/NotificationTestList.java | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemView.java b/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemView.java index 1e89624d89f80..2f94af61e3771 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemView.java @@ -23,12 +23,22 @@ import android.view.MotionEvent; import android.widget.FrameLayout; public class LatestItemView extends FrameLayout { + private boolean mDispatchTorches; public LatestItemView(Context context, AttributeSet attrs) { super(context, attrs); } public boolean dispatchTouchEvent(MotionEvent ev) { - return onTouchEvent(ev); + if (mDispatchTorches) { + return super.dispatchTouchEvent(ev); + } else { + return onTouchEvent(ev); + } + } + + public void setOnClickListener(OnClickListener l) { + mDispatchTorches = l == null; + super.setOnClickListener(l); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java index 9fbfc64f49497..fc7b534700cfb 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java @@ -440,6 +440,8 @@ public class PhoneStatusBarService extends StatusBarService { if (contentIntent != null) { oldEntry.content.setOnClickListener(new Launcher(contentIntent, notification.pkg, notification.tag, notification.id)); + } else { + oldEntry.content.setOnClickListener(null); } // Update the icon. final StatusBarIcon ic = new StatusBarIcon(notification.pkg, @@ -516,6 +518,8 @@ public class PhoneStatusBarService extends StatusBarService { if (contentIntent != null) { content.setOnClickListener(new Launcher(contentIntent, notification.pkg, notification.tag, notification.id)); + } else { + content.setOnClickListener(null); } View expanded = null; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java index 69e9a94a3078f..340e269d89c6f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBarService.java @@ -372,6 +372,8 @@ public class TabletStatusBarService extends StatusBarService { if (contentIntent != null) { oldEntry.content.setOnClickListener(new NotificationClicker(contentIntent, notification.pkg, notification.tag, notification.id)); + } else { + oldEntry.content.setOnClickListener(null); } // Update the icon. final StatusBarIcon ic = new StatusBarIcon(notification.pkg, @@ -771,6 +773,8 @@ public class TabletStatusBarService extends StatusBarService { if (contentIntent != null) { content.setOnClickListener(new NotificationClicker(contentIntent, sbn.pkg, sbn.tag, sbn.id)); + } else { + content.setOnClickListener(null); } View expanded = null; diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java index 5afabbd829a12..15eaa9e15aa95 100755 --- a/services/java/com/android/server/NotificationManagerService.java +++ b/services/java/com/android/server/NotificationManagerService.java @@ -741,10 +741,6 @@ public class NotificationManagerService extends INotificationManager.Stub throw new IllegalArgumentException("contentView required: pkg=" + pkg + " id=" + id + " notification=" + notification); } - if (notification.contentIntent == null) { - throw new IllegalArgumentException("contentIntent required: pkg=" + pkg - + " id=" + id + " notification=" + notification); - } } synchronized (mNotificationList) { diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java index e30cf4a6eea61..9c267d687040b 100644 --- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java +++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java @@ -86,6 +86,18 @@ public class NotificationTestList extends TestActivity } }, + new Test("custom intent on text view") { + public void run() { + Notification n = new Notification(R.drawable.icon1, null, + mActivityCreateTime); + n.setLatestEventInfo(NotificationTestList.this, "Persistent #1", + "This is a notification!!!", null); + n.contentView.setOnClickPendingIntent(com.android.internal.R.id.text, + makeIntent2()); + mNM.notify(1, n); + } + }, + new Test("Ticker 1 line") { public void run() { Notification n = new Notification(R.drawable.icon1, "tick tick tick", @@ -776,6 +788,12 @@ public class NotificationTestList extends TestActivity return PendingIntent.getActivity(this, 0, intent, 0); } + private PendingIntent makeIntent2() { + Intent intent = new Intent(this, StatusBarTest.class); + return PendingIntent.getActivity(this, 0, intent, 0); + } + + class StateStress extends Test { StateStress(String name, int pause, int iterations, Runnable[] tasks) { super(name);