summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Gustav Sennton <gsennton@google.com> 2018-12-03 16:48:36 +0000
committer Gustav Sennton <gsennton@google.com> 2018-12-11 09:27:22 +0000
commitd0e8453578e03eba197b0ffac1967eecf68bd12d (patch)
tree42205e60c8a3f2de11b510ac355f3f0bf601526b
parent451db48526e2227fc0044279fb728151e6a27023 (diff)
Add Smart Suggestions to heads up notifications.
Add smart replies and actions to Heads-up notifications (HUN). Note: only one line of text is shown in HUNs with messaging templates. Thus the user might not see the full message to respond to even when the smart replies/actions are displayed. Screenshot: https://screenshot.googleplex.com/3R5GVZGXGNg.png Bug: 117257685 Test: Use cinek@'s Notify app to display HUN with smart replies/actions. Change-Id: I10d2c87b445de8f471ad0978829cede9ac6a6663
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java4
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java14
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java23
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java9
4 files changed, 41 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
index 8214ea6c7616..8bed3663cf49 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
@@ -1098,6 +1098,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
mHeadsUpManager = headsUpManager;
}
+ public HeadsUpManager getHeadsUpManager() {
+ return mHeadsUpManager;
+ }
+
public void setGutsView(MenuItem item) {
if (mGuts != null && item.getGutsView() instanceof NotificationGuts.GutsContent) {
((NotificationGuts.GutsContent) item.getGutsView()).setGutsParent(mGuts);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
index 689d6d530308..edd54ca936fa 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
@@ -91,6 +91,7 @@ public class NotificationContentView extends FrameLayout {
private SmartReplyConstants mSmartReplyConstants;
private SmartReplyView mExpandedSmartReplyView;
+ private SmartReplyView mHeadsUpSmartReplyView;
private SmartReplyController mSmartReplyController;
private NotificationViewWrapper mContractedWrapper;
@@ -253,6 +254,9 @@ public class NotificationContentView extends FrameLayout {
}
if (mHeadsUpChild != null) {
int maxHeight = mHeadsUpHeight;
+ if (mHeadsUpSmartReplyView != null) {
+ maxHeight += mHeadsUpSmartReplyView.getHeightUpperLimit();
+ }
maxHeight += mHeadsUpWrapper.getExtraMeasureHeight();
int size = maxHeight;
ViewGroup.LayoutParams layoutParams = mHeadsUpChild.getLayoutParams();
@@ -955,6 +959,9 @@ public class NotificationContentView extends FrameLayout {
if (mExpandedSmartReplyView != null) {
mExpandedSmartReplyView.setBackgroundTintColor(color);
}
+ if (mHeadsUpSmartReplyView != null) {
+ mHeadsUpSmartReplyView.setBackgroundTintColor(color);
+ }
}
public int getVisibleType() {
@@ -1472,6 +1479,10 @@ public class NotificationContentView extends FrameLayout {
entry, smartRepliesAndActions.smartReplies.choices.length);
}
}
+ if (mHeadsUpChild != null) {
+ mHeadsUpSmartReplyView =
+ applySmartReplyView(mHeadsUpChild, smartRepliesAndActions, entry);
+ }
}
private SmartReplyView applySmartReplyView(View view,
@@ -1520,7 +1531,8 @@ public class NotificationContentView extends FrameLayout {
}
if (smartRepliesAndActions.smartActions != null) {
smartReplyView.addSmartActions(
- smartRepliesAndActions.smartActions, mSmartReplyController, entry);
+ smartRepliesAndActions.smartActions, mSmartReplyController, entry,
+ mContainingNotification.getHeadsUpManager());
}
smartReplyContainer.setVisibility(View.VISIBLE);
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java
index 2a4336e809a0..913b2ae90cf6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SmartReplyView.java
@@ -16,6 +16,8 @@ import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
import android.text.Layout;
import android.text.TextPaint;
import android.text.method.TransformationMethod;
@@ -61,6 +63,7 @@ public class SmartReplyView extends ViewGroup {
private final SmartReplyConstants mConstants;
private final KeyguardDismissUtil mKeyguardDismissUtil;
+ private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());
/**
* The upper bound for the height of this view in pixels. Notifications are automatically
@@ -209,13 +212,15 @@ public class SmartReplyView extends ViewGroup {
* notification are shown.
*/
public void addSmartActions(SmartActions smartActions,
- SmartReplyController smartReplyController, NotificationData.Entry entry) {
+ SmartReplyController smartReplyController, NotificationData.Entry entry,
+ HeadsUpManager headsUpManager) {
int numSmartActions = smartActions.actions.size();
for (int n = 0; n < numSmartActions; n++) {
Notification.Action action = smartActions.actions.get(n);
if (action.actionIntent != null) {
Button actionButton = inflateActionButton(
- getContext(), this, n, smartActions, smartReplyController, entry);
+ getContext(), this, n, smartActions, smartReplyController, entry,
+ headsUpManager);
addView(actionButton);
}
}
@@ -274,7 +279,7 @@ public class SmartReplyView extends ViewGroup {
@VisibleForTesting
Button inflateActionButton(Context context, ViewGroup root, int actionIndex,
SmartActions smartActions, SmartReplyController smartReplyController,
- NotificationData.Entry entry) {
+ NotificationData.Entry entry, HeadsUpManager headsUpManager) {
Notification.Action action = smartActions.actions.get(actionIndex);
Button button = (Button) LayoutInflater.from(context).inflate(
R.layout.smart_action_button, root, false);
@@ -290,8 +295,12 @@ public class SmartReplyView extends ViewGroup {
button.setOnClickListener(view ->
getActivityStarter().startPendingIntentDismissingKeyguard(
action.actionIntent,
- () -> smartReplyController.smartActionClicked(
- entry, actionIndex, action, smartActions.fromAssistant)));
+ () -> {
+ smartReplyController.smartActionClicked(
+ entry, actionIndex, action, smartActions.fromAssistant);
+ postOnUiThread(() ->
+ headsUpManager.removeNotification(entry.key, true));
+ }));
// TODO(b/119010281): handle accessibility
@@ -301,6 +310,10 @@ public class SmartReplyView extends ViewGroup {
return button;
}
+ private void postOnUiThread(Runnable runnable) {
+ mMainThreadHandler.post(runnable);
+ }
+
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
return new LayoutParams(mContext, attrs);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java
index 506fa974944a..c5bac9242b8b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java
@@ -98,6 +98,7 @@ public class SmartReplyViewTest extends SysuiTestCase {
private Notification mNotification;
@Mock ActivityStarter mActivityStarter;
+ @Mock HeadsUpManager mHeadsUpManager;
@Before
public void setUp() {
@@ -434,7 +435,8 @@ public class SmartReplyViewTest extends SysuiTestCase {
mView.addSmartActions(
new SmartReplyView.SmartActions(createActions(actionTitles), false),
mLogger,
- mEntry);
+ mEntry,
+ mHeadsUpManager);
}
private void setSmartRepliesAndActions(CharSequence[] choices, String[] actionTitles) {
@@ -442,7 +444,8 @@ public class SmartReplyViewTest extends SysuiTestCase {
mView.addSmartActions(
new SmartReplyView.SmartActions(createActions(actionTitles), false),
mLogger,
- mEntry);
+ mEntry,
+ mHeadsUpManager);
}
private ViewGroup buildExpectedView(CharSequence[] choices, int lineCount) {
@@ -747,7 +750,7 @@ public class SmartReplyViewTest extends SysuiTestCase {
private Button inflateActionButton(Notification.Action action) {
return mView.inflateActionButton(getContext(), mView, 0,
new SmartReplyView.SmartActions(Collections.singletonList(action), false),
- mLogger, mEntry);
+ mLogger, mEntry, mHeadsUpManager);
}
@Test