From eab5368d4f1cd21482fd3051f423def23b925ee8 Mon Sep 17 00:00:00 2001 From: Gustav Sennton Date: Thu, 1 Nov 2018 16:30:23 +0000 Subject: [PATCH] Add smart actions to message notifications. Smart Action look similar to Smart Replies with an icon next to the button text. Smart Actions can be added either by an app, or by the framework itself (through NotificationAssistantService). The idea is that Smart Actions are really actions relating to the content in the notification message. The priority order of smart replies vs. actions will be dealt with in a follow-up CL (i.e. whether we should prioritize showing smart actions over smart replies). Example notifications: System generated: https://screenshot.googleplex.com/f6p8uOMygeT.png App generated: https://screenshot.googleplex.com/VR6On1eh4CW.png 2 app generated actions: https://screenshot.googleplex.com/QuM5e792xhb.png Bug: 111406942 Test: manual tests = add custom actions directly in sys ui and ensure they're shown in message notifications. Test: atest SystemUITests Change-Id: I0ce959b74e89bcabc69b76c50c1877e70d6f06df --- core/java/android/app/Notification.java | 19 + .../res/layout/smart_action_button.xml | 34 ++ packages/SystemUI/res/values/dimens.xml | 1 + .../row/NotificationContentView.java | 130 +++++-- .../statusbar/policy/SmartReplyView.java | 113 +++++- .../row/NotificationContentViewTest.java | 205 +++++++++- .../statusbar/policy/SmartReplyViewTest.java | 362 +++++++++++++++++- 7 files changed, 796 insertions(+), 68 deletions(-) create mode 100644 packages/SystemUI/res/layout/smart_action_button.xml diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 450efdf166569..03939cf08ba2c 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -3192,6 +3192,25 @@ public class Notification implements Parcelable return null; } + /** + * Returns the actions that are contextual (marked as SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION) out + * of the actions in this notification. + * + * @hide + */ + public List getContextualActions() { + if (actions == null) return Collections.emptyList(); + + List contextualActions = new ArrayList<>(); + for (Notification.Action action : actions) { + if (action.getSemanticAction() + == Notification.Action.SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION) { + contextualActions.add(action); + } + } + return contextualActions; + } + /** * Builder class for {@link Notification} objects. * diff --git a/packages/SystemUI/res/layout/smart_action_button.xml b/packages/SystemUI/res/layout/smart_action_button.xml new file mode 100644 index 0000000000000..271603479482b --- /dev/null +++ b/packages/SystemUI/res/layout/smart_action_button.xml @@ -0,0 +1,34 @@ + + + +