From d8a4b23f672e5678ef8c738c70a316c684e40916 Mon Sep 17 00:00:00 2001 From: Steve Elliott Date: Thu, 23 Sep 2021 15:52:31 -0400 Subject: [PATCH] [RemoteInputView] RemoteInputQuickSettingsDisabler to Controller Bug: 193539698 Test: mp sysuig, focus a remote input, try to swipe down quick settings Change-Id: Ia2128ee62cb2f593bc8a2ef03ed021d098b28812 --- .../row/NotificationContentView.java | 20 +++++++++++- .../statusbar/policy/RemoteInputView.java | 6 ---- .../policy/RemoteInputViewController.kt | 32 +++++++++++++++++-- .../statusbar/policy/dagger/RemoteInput.kt | 4 ++- 4 files changed, 52 insertions(+), 10 deletions(-) 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 81b363507e3fe..4568470c611a1 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 @@ -421,6 +421,9 @@ public class NotificationContentView extends FrameLayout { mExpandedChild.animate().cancel(); removeView(mExpandedChild); mExpandedRemoteInput = null; + if (mExpandedRemoteInputController != null) { + mExpandedRemoteInputController.unbind(); + } mExpandedRemoteInputController = null; } if (child == null) { @@ -465,6 +468,9 @@ public class NotificationContentView extends FrameLayout { mHeadsUpChild.animate().cancel(); removeView(mHeadsUpChild); mHeadsUpRemoteInput = null; + if (mHeadsUpRemoteInputController != null) { + mHeadsUpRemoteInputController.unbind(); + } mHeadsUpRemoteInputController = null; } if (child == null) { @@ -1211,8 +1217,14 @@ public class NotificationContentView extends FrameLayout { mExpandedWrapper); mExpandedRemoteInput = expandedData.mView; mExpandedRemoteInputController = expandedData.mController; + if (mExpandedRemoteInputController != null) { + mExpandedRemoteInputController.bind(); + } } else { mExpandedRemoteInput = null; + if (mExpandedRemoteInputController != null) { + mExpandedRemoteInputController.unbind(); + } mExpandedRemoteInputController = null; } if (mCachedExpandedRemoteInput != null @@ -1230,8 +1242,14 @@ public class NotificationContentView extends FrameLayout { mHeadsUpWrapper); mHeadsUpRemoteInput = headsUpData.mView; mHeadsUpRemoteInputController = headsUpData.mController; + if (mHeadsUpRemoteInputController != null) { + mHeadsUpRemoteInputController.bind(); + } } else { mHeadsUpRemoteInput = null; + if (mHeadsUpRemoteInputController != null) { + mHeadsUpRemoteInputController.unbind(); + } mHeadsUpRemoteInputController = null; } if (mCachedHeadsUpRemoteInput != null @@ -1272,7 +1290,7 @@ public class NotificationContentView extends FrameLayout { // Create a new controller for the view. The lifetime of the controller is 1:1 // with that of the view. RemoteInputViewSubcomponent subcomponent = - mRemoteInputSubcomponentFactory.create(); + mRemoteInputSubcomponentFactory.create(result.mView); result.mController = subcomponent.getController(); result.mView.setController(result.mController); } else { 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 7e3f5fd87ed11..d25013acd1474 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputView.java @@ -128,7 +128,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene // TODO(b/193539698): move these to a Controller private RemoteInputController mController; - private final RemoteInputQuickSettingsDisabler mRemoteInputQuickSettingsDisabler; private final UiEventLogger mUiEventLogger; private NotificationEntry mEntry; private PendingIntent mPendingIntent; @@ -170,7 +169,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene super(context, attrs); mTextWatcher = new SendButtonTextWatcher(); mEditorActionHandler = new EditorActionHandler(); - mRemoteInputQuickSettingsDisabler = Dependency.get(RemoteInputQuickSettingsDisabler.class); mUiEventLogger = Dependency.get(UiEventLogger.class); TypedArray ta = getContext().getTheme().obtainStyledAttributes(new int[]{ com.android.internal.R.attr.colorAccent, @@ -522,8 +520,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene } } - mRemoteInputQuickSettingsDisabler.setRemoteInputActive(false); - if (logClose) { mUiEventLogger.logWithInstanceId( NotificationRemoteInputEvent.NOTIFICATION_REMOTE_INPUT_CLOSE, @@ -623,8 +619,6 @@ public class RemoteInputView extends LinearLayout implements View.OnClickListene mController.addRemoteInput(mEntry, mToken); setAttachment(mEntry.remoteInputAttachment); - mRemoteInputQuickSettingsDisabler.setRemoteInputActive(true); - updateSendButton(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputViewController.kt index f948030af7208..383170e9b24df 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RemoteInputViewController.kt @@ -16,10 +16,38 @@ package com.android.systemui.statusbar.policy +import android.view.View import com.android.systemui.statusbar.policy.dagger.RemoteInputViewScope import javax.inject.Inject -interface RemoteInputViewController +interface RemoteInputViewController { + fun bind() + fun unbind() +} @RemoteInputViewScope -class RemoteInputViewControllerImpl @Inject constructor() : RemoteInputViewController \ No newline at end of file +class RemoteInputViewControllerImpl @Inject constructor( + private val view: RemoteInputView, + private val remoteInputQuickSettingsDisabler: RemoteInputQuickSettingsDisabler +) : RemoteInputViewController { + + private var isBound = false + + override fun bind() { + if (isBound) return + isBound = true + + view.addOnEditTextFocusChangedListener(onFocusChangeListener) + } + + override fun unbind() { + if (!isBound) return + isBound = false + + view.removeOnEditTextFocusChangedListener(onFocusChangeListener) + } + + private val onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus -> + remoteInputQuickSettingsDisabler.setRemoteInputActive(hasFocus) + } +} \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/RemoteInput.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/RemoteInput.kt index fe56a9840024c..aff39efdd0a40 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/RemoteInput.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/dagger/RemoteInput.kt @@ -16,9 +16,11 @@ package com.android.systemui.statusbar.policy.dagger +import com.android.systemui.statusbar.policy.RemoteInputView import com.android.systemui.statusbar.policy.RemoteInputViewController import com.android.systemui.statusbar.policy.RemoteInputViewControllerImpl import dagger.Binds +import dagger.BindsInstance import dagger.Module import dagger.Subcomponent import javax.inject.Qualifier @@ -30,7 +32,7 @@ interface RemoteInputViewSubcomponent { @Subcomponent.Factory interface Factory { - fun create(): RemoteInputViewSubcomponent + fun create(@BindsInstance view: RemoteInputView): RemoteInputViewSubcomponent } }