From ea5bbfeeb018c91f3998043d3c2dee5a7bad5c9c Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 27 Jul 2022 14:05:09 +0900 Subject: [PATCH] Hide text UIs for mouse interaction Floating toolbar, magnifier and tear drop selection handles are designed for finger touch input. For the mouse UX, these UI will not be good. So hiding them if the TextView/EditText has interacted with mouse device. Bug: 240383641 Test: atest TextViewMouseInteractionTest Change-Id: I66f169ee3f2b77e3a066aecb07170e82248c2cde --- core/java/android/widget/Editor.java | 28 ++++++++++++++++--- .../widget/SelectionActionModeHelper.java | 6 +++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java index fb298c75c9097..fcf1ce12ef54e 100644 --- a/core/java/android/widget/Editor.java +++ b/core/java/android/widget/Editor.java @@ -226,6 +226,8 @@ public class Editor { final UndoInputFilter mUndoInputFilter = new UndoInputFilter(this); boolean mAllowUndo = true; + private int mLastToolType = MotionEvent.TOOL_TYPE_UNKNOWN; + private final MetricsLogger mMetricsLogger = new MetricsLogger(); // Cursor Controllers. @@ -1737,6 +1739,9 @@ public class Editor { @VisibleForTesting public void onTouchEvent(MotionEvent event) { final boolean filterOutEvent = shouldFilterOutTouchEvent(event); + + mLastToolType = event.getToolType(event.getActionIndex()); + mLastButtonState = event.getButtonState(); if (filterOutEvent) { if (event.getActionMasked() == MotionEvent.ACTION_UP) { @@ -1789,7 +1794,7 @@ public class Editor { } private void showFloatingToolbar() { - if (mTextActionMode != null) { + if (mTextActionMode != null && showUIForFingerInput()) { // Delay "show" so it doesn't interfere with click confirmations // or double-clicks that could "dismiss" the floating toolbar. int delay = ViewConfiguration.getDoubleTapTimeout(); @@ -1869,7 +1874,8 @@ public class Editor { final CursorController cursorController = mTextView.hasSelection() ? getSelectionController() : getInsertionController(); if (cursorController != null && !cursorController.isActive() - && !cursorController.isCursorBeingModified()) { + && !cursorController.isCursorBeingModified() + && showUIForFingerInput()) { cursorController.show(); } } @@ -2520,6 +2526,10 @@ public class Editor { return false; } + if (!showUIForFingerInput()) { + return false; + } + ActionMode.Callback actionModeCallback = new TextActionModeCallback(actionMode); mTextActionMode = mTextView.startActionMode(actionModeCallback, ActionMode.TYPE_FLOATING); registerOnBackInvokedCallback(); @@ -2672,7 +2682,7 @@ public class Editor { mTextView.postDelayed(mShowSuggestionRunnable, ViewConfiguration.getDoubleTapTimeout()); } else if (hasInsertionController()) { - if (shouldInsertCursor) { + if (shouldInsertCursor && showUIForFingerInput()) { getInsertionController().show(); } else { getInsertionController().hide(); @@ -5401,7 +5411,8 @@ public class Editor { final PointF showPosInView = new PointF(); final boolean shouldShow = checkForTransforms() /*check not rotated and compute scale*/ && !tooLargeTextForMagnifier() - && obtainMagnifierShowCoordinates(event, showPosInView); + && obtainMagnifierShowCoordinates(event, showPosInView) + && showUIForFingerInput(); if (shouldShow) { // Make the cursor visible and stop blinking. mRenderCursorRegardlessTiming = true; @@ -6347,6 +6358,15 @@ public class Editor { } } + /** + * Returns true when need to show UIs, e.g. floating toolbar, etc, for finger based interaction. + * + * @return true if UIs need to show for finger interaciton. false if UIs are not necessary. + */ + public boolean showUIForFingerInput() { + return mLastToolType != MotionEvent.TOOL_TYPE_MOUSE; + } + /** Controller for the insertion cursor. */ @VisibleForTesting public class InsertionPointCursorController implements CursorController { diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java index a0ec48bc6beb7..54a415cfa01b2 100644 --- a/core/java/android/widget/SelectionActionModeHelper.java +++ b/core/java/android/widget/SelectionActionModeHelper.java @@ -301,7 +301,11 @@ public final class SelectionActionModeHelper { final SelectionModifierCursorController controller = mEditor.getSelectionController(); if (controller != null && (mTextView.isTextSelectable() || mTextView.isTextEditable())) { - controller.show(); + if (mEditor.showUIForFingerInput()) { + controller.show(); + } else { + controller.hide(); + } } if (result != null) { switch (actionMode) {