From 88d92da325bf976245cffa773afd2df5a951a357 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Thu, 16 Apr 2015 17:41:06 +0900 Subject: Enable mouse drag text selection for unfocused TextView. Bug: 17643755 Change-Id: If6ca064a082feaf6faf9555b1455c4b2f6312952 --- .../text/method/ArrowKeyMovementMethod.java | 39 +++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/core/java/android/text/method/ArrowKeyMovementMethod.java b/core/java/android/text/method/ArrowKeyMovementMethod.java index fcc3a4007e42..de509b2d7b9a 100644 --- a/core/java/android/text/method/ArrowKeyMovementMethod.java +++ b/core/java/android/text/method/ArrowKeyMovementMethod.java @@ -240,23 +240,30 @@ public class ArrowKeyMovementMethod extends BaseMovementMethod implements Moveme boolean handled = Touch.onTouchEvent(widget, buffer, event); - if (widget.isFocused() && !widget.didTouchFocusSelect()) { - if (action == MotionEvent.ACTION_DOWN) { - // Capture the mouse pointer down location to ensure selection starts - // right under the mouse (and is not influenced by cursor location). - // The code below needs to run for mouse events. - // For touch events, the code should run only when selection is active. - if (isMouse || isTouchSelecting(isMouse, buffer)) { - int offset = widget.getOffsetForPosition(event.getX(), event.getY()); - buffer.setSpan(LAST_TAP_DOWN, offset, offset, Spannable.SPAN_POINT_POINT); - // Disallow intercepting of the touch events, so that - // users can scroll and select at the same time. - // without this, users would get booted out of select - // mode once the view detected it needed to scroll. - widget.getParent().requestDisallowInterceptTouchEvent(true); + if (widget.didTouchFocusSelect() && !isMouse) { + return handled; + } + if (action == MotionEvent.ACTION_DOWN) { + // Capture the mouse pointer down location to ensure selection starts + // right under the mouse (and is not influenced by cursor location). + // The code below needs to run for mouse events. + // For touch events, the code should run only when selection is active. + if (isMouse || isTouchSelecting(isMouse, buffer)) { + if (!widget.isFocused()) { + if (!widget.requestFocus()) { + return handled; + } } - } else if (action == MotionEvent.ACTION_MOVE) { - + int offset = widget.getOffsetForPosition(event.getX(), event.getY()); + buffer.setSpan(LAST_TAP_DOWN, offset, offset, Spannable.SPAN_POINT_POINT); + // Disallow intercepting of the touch events, so that + // users can scroll and select at the same time. + // without this, users would get booted out of select + // mode once the view detected it needed to scroll. + widget.getParent().requestDisallowInterceptTouchEvent(true); + } + } else if (widget.isFocused()) { + if (action == MotionEvent.ACTION_MOVE) { // Cursor can be active at any location in the text while mouse pointer can start // selection from a totally different location. Use LAST_TAP_DOWN span to ensure // text selection will start from mouse pointer location. -- cgit v1.2.3-59-g8ed1b