diff options
| author | 2018-01-24 16:21:07 -0800 | |
|---|---|---|
| committer | 2018-01-25 00:25:33 +0000 | |
| commit | de4de0e204a028f8f8608d7fd649fe1a60784c4e (patch) | |
| tree | 72c715d227cc29ee1f591a23ea94199f9c529962 | |
| parent | 7fa385abd882b8381e928d107bc81d984a8bbee4 (diff) | |
Added the reply draft as an extra to the content intent
Change-Id: I406833a5875221731baf0834f2e47e283b84aae9
Fixes: 36858677
Test: Add notification, draft reply and click on it. Ensure that extra is sent
6 files changed, 50 insertions, 2 deletions
diff --git a/api/current.txt b/api/current.txt index 61465acd362c..b07e8bc11440 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5224,6 +5224,7 @@ package android.app { field public static final java.lang.String EXTRA_PROGRESS = "android.progress"; field public static final java.lang.String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; field public static final java.lang.String EXTRA_PROGRESS_MAX = "android.progressMax"; + field public static final java.lang.String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; field public static final java.lang.String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory"; field public static final deprecated java.lang.String EXTRA_SELF_DISPLAY_NAME = "android.selfDisplayName"; field public static final java.lang.String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index d6fddfca986e..0b5b363ddecd 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -200,6 +200,16 @@ public class Notification implements Parcelable */ private static final int MAX_REPLY_HISTORY = 5; + + /** + * If the notification contained an unsent draft for a RemoteInput when the user clicked on it, + * we're adding the draft as a String extra to the {@link #contentIntent} using this key. + * + * <p>Apps may use this extra to prepopulate text fields in the app, where the user usually + * sends messages.</p> + */ + public static final String EXTRA_REMOTE_INPUT_DRAFT = "android.remoteInputDraft"; + /** * A timestamp related to this notification, in milliseconds since the epoch. * diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 3901277f150a..e9673ea3ede0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -1458,6 +1458,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView mMenuRow.resetMenu(); } + public CharSequence getActiveRemoteInputText() { + return mPrivateLayout.getActiveRemoteInputText(); + } + + public void animateTranslateNotification(final float leftTarget) { if (mTranslateAnim != null) { mTranslateAnim.cancel(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java index a4c17e3681b0..e811ed3d77ae 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java @@ -1563,4 +1563,14 @@ public class NotificationContentView extends FrameLayout { } return visibleWrapper.shouldClipToRounding(topRounded, bottomRounded); } + + public CharSequence getActiveRemoteInputText() { + if (mExpandedRemoteInput != null && mExpandedRemoteInput.isActive()) { + return mExpandedRemoteInput.getText(); + } + if (mHeadsUpRemoteInput != null && mHeadsUpRemoteInput.isActive()) { + return mHeadsUpRemoteInput.getText(); + } + return null; + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 77afe9b8d509..a423c126cddf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -100,6 +100,8 @@ import android.provider.Settings; import android.service.notification.StatusBarNotification; import android.service.vr.IVrManager; import android.service.vr.IVrStateCallbacks; +import android.text.SpannedString; +import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.EventLog; import android.util.Log; @@ -4937,9 +4939,25 @@ public class StatusBar extends SystemUI implements DemoMode, } } } + Intent fillInIntent = null; + Entry entry = row.getEntry(); + CharSequence remoteInputText = null; + RemoteInputController controller = mRemoteInputManager.getController(); + if (controller.isRemoteInputActive(entry)) { + remoteInputText = row.getActiveRemoteInputText(); + } + if (TextUtils.isEmpty(remoteInputText) + && !TextUtils.isEmpty(entry.remoteInputText)) { + remoteInputText = entry.remoteInputText; + } + if (!TextUtils.isEmpty(remoteInputText) + && !controller.isSpinning(entry.key)) { + fillInIntent = new Intent().putExtra(Notification.EXTRA_REMOTE_INPUT_DRAFT, + remoteInputText.toString()); + } try { - launchResult = intent.sendAndReturnResult(null, 0, null, null, null, null, - getActivityOptions(row)); + launchResult = intent.sendAndReturnResult(mContext, 0, fillInIntent, null, + null, null, getActivityOptions(row)); } catch (PendingIntent.CanceledException e) { // the stack trace isn't very helpful here. // Just log the exception message. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java index b63c1da59cba..179c0d57aa50 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java @@ -169,6 +169,10 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene } } + public CharSequence getText() { + return mEditText.getText(); + } + public static RemoteInputView inflate(Context context, ViewGroup root, NotificationData.Entry entry, RemoteInputController controller) { |