From 7b9ed0d8fdb927cb1eece172af5fe28d319fe558 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Tue, 24 Jan 2017 15:55:18 -0800 Subject: [PATCH] DirectReply: Show historic messages Test: Post notification with MessagingStyle.addHistoricMessage(), verify they show up while direct replying. Change-Id: I26b801d05305a5251fe0d6fae1fe1c24064105a9 --- .../statusbar/NotificationContentView.java | 11 +++++---- ...ificationMessagingTemplateViewWrapper.java | 23 +++++++++++++++++-- .../notification/NotificationViewWrapper.java | 3 +++ .../statusbar/policy/RemoteInputView.java | 19 +++++++++++++++ 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java index b45cde87d79ae..df7161f6f5a32 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationContentView.java @@ -974,7 +974,6 @@ public class NotificationContentView extends FrameLayout { mStatusBarNotification = entry.notification; mBeforeN = entry.targetSdk < Build.VERSION_CODES.N; updateSingleLineView(); - applyRemoteInput(entry); if (mContractedChild != null) { mContractedWrapper.notifyContentUpdated(entry.notification); } @@ -987,6 +986,7 @@ public class NotificationContentView extends FrameLayout { if (mAmbientChild != null) { mAmbientWrapper.notifyContentUpdated(entry.notification); } + applyRemoteInput(entry); updateShowingLegacyBackground(); mForceSelectNextLayout = true; setDark(mDark, false /* animate */, 0 /* delay */); @@ -1028,7 +1028,8 @@ public class NotificationContentView extends FrameLayout { View bigContentView = mExpandedChild; if (bigContentView != null) { mExpandedRemoteInput = applyRemoteInput(bigContentView, entry, hasRemoteInput, - mPreviousExpandedRemoteInputIntent, mCachedExpandedRemoteInput); + mPreviousExpandedRemoteInputIntent, mCachedExpandedRemoteInput, + mExpandedWrapper); } else { mExpandedRemoteInput = null; } @@ -1042,7 +1043,7 @@ public class NotificationContentView extends FrameLayout { View headsUpContentView = mHeadsUpChild; if (headsUpContentView != null) { mHeadsUpRemoteInput = applyRemoteInput(headsUpContentView, entry, hasRemoteInput, - mPreviousHeadsUpRemoteInputIntent, mCachedHeadsUpRemoteInput); + mPreviousHeadsUpRemoteInputIntent, mCachedHeadsUpRemoteInput, mHeadsUpWrapper); } else { mHeadsUpRemoteInput = null; } @@ -1056,7 +1057,7 @@ public class NotificationContentView extends FrameLayout { private RemoteInputView applyRemoteInput(View view, NotificationData.Entry entry, boolean hasRemoteInput, PendingIntent existingPendingIntent, - RemoteInputView cachedView) { + RemoteInputView cachedView, NotificationViewWrapper wrapper) { View actionContainerCandidate = view.findViewById( com.android.internal.R.id.actions_container); if (actionContainerCandidate instanceof FrameLayout) { @@ -1095,6 +1096,8 @@ public class NotificationContentView extends FrameLayout { mContext.getColor(R.color.remote_input_text_enabled), mContext.getColor(R.color.remote_input_hint))); + existing.setWrapper(wrapper); + if (existingPendingIntent != null || existing.isActive()) { // The current action could be gone, or the pending intent no longer valid. // If we find a matching action in the new notification, focus, otherwise close. diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationMessagingTemplateViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationMessagingTemplateViewWrapper.java index 58f01c8cbd2fa..06d12cb8d6349 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationMessagingTemplateViewWrapper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationMessagingTemplateViewWrapper.java @@ -22,7 +22,11 @@ import com.android.systemui.statusbar.TransformableView; import android.content.Context; import android.service.notification.StatusBarNotification; +import android.text.TextUtils; import android.view.View; +import android.widget.TextView; + +import java.util.ArrayList; /** * Wraps a notification containing a messaging template @@ -30,6 +34,7 @@ import android.view.View; public class NotificationMessagingTemplateViewWrapper extends NotificationTemplateViewWrapper { private View mContractedMessage; + private ArrayList mHistoricMessages = new ArrayList(); protected NotificationMessagingTemplateViewWrapper(Context ctx, View view, ExpandableNotificationRow row) { @@ -44,11 +49,18 @@ public class NotificationMessagingTemplateViewWrapper extends NotificationTempla && ((MessagingLinearLayout) container).getChildCount() > 0) { MessagingLinearLayout messagingContainer = (MessagingLinearLayout) container; - // Only consider the first visible child - transforming to a position other than the - // first looks bad because we have to move across other messages that are fading in. int childCount = messagingContainer.getChildCount(); for (int i = 0; i < childCount; i++) { View child = messagingContainer.getChildAt(i); + + if (child.getVisibility() == View.GONE + && child instanceof TextView + && !TextUtils.isEmpty(((TextView) child).getText())) { + mHistoricMessages.add(child); + } + + // Only consider the first visible child - transforming to a position other than the + // first looks bad because we have to move across other messages that are fading in. if (child.getId() == messagingContainer.getContractedChildId()) { mContractedMessage = child; } else if (child.getVisibility() == View.VISIBLE) { @@ -75,4 +87,11 @@ public class NotificationMessagingTemplateViewWrapper extends NotificationTempla mContractedMessage); } } + + @Override + public void setRemoteInputVisible(boolean visible) { + for (int i = 0; i < mHistoricMessages.size(); i++) { + mHistoricMessages.get(i).setVisibility(visible ? View.VISIBLE : View.GONE); + } + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationViewWrapper.java index 16348dfe5818e..27fb5b952d5ea 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationViewWrapper.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationViewWrapper.java @@ -163,4 +163,7 @@ public abstract class NotificationViewWrapper implements TransformableView { public void setContentHeight(int contentHeight, int minHeightHint) { } + + public void setRemoteInputVisible(boolean visible) { + } } 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 44ec2831dd9b7..784f25e25a56f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java @@ -56,6 +56,7 @@ import com.android.systemui.R; import com.android.systemui.statusbar.ExpandableView; import com.android.systemui.statusbar.NotificationData; import com.android.systemui.statusbar.RemoteInputController; +import com.android.systemui.statusbar.notification.NotificationViewWrapper; import com.android.systemui.statusbar.stack.ScrollContainer; import com.android.systemui.statusbar.stack.StackStateAnimator; @@ -90,6 +91,7 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene private int mRevealR; private boolean mResetting; + private NotificationViewWrapper mWrapper; public RemoteInputView(Context context, AttributeSet attrs) { super(context, attrs); @@ -210,11 +212,17 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene @Override public void onAnimationEnd(Animator animation) { setVisibility(INVISIBLE); + if (mWrapper != null) { + mWrapper.setRemoteInputVisible(false); + } } }); reveal.start(); } else { setVisibility(INVISIBLE); + if (mWrapper != null) { + mWrapper.setRemoteInputVisible(false); + } } } MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_REMOTE_INPUT_CLOSE, @@ -267,6 +275,9 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene mEntry.notification.getPackageName()); setVisibility(VISIBLE); + if (mWrapper != null) { + mWrapper.setRemoteInputVisible(true); + } mController.addRemoteInput(mEntry, mToken); mEditText.setInnerFocusable(true); mEditText.mShowImeOnInputConnection = true; @@ -283,6 +294,10 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene // Update came in after we sent the reply, time to reset. reset(); } + + if (isActive() && mWrapper != null) { + mWrapper.setRemoteInputVisible(true); + } } private void reset() { @@ -452,6 +467,10 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene super.dispatchFinishTemporaryDetach(); } + public void setWrapper(NotificationViewWrapper wrapper) { + mWrapper = wrapper; + } + /** * An EditText that changes appearance based on whether it's focusable and becomes * un-focusable whenever the user navigates away from it or it becomes invisible.