summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Keisuke Kuroyanagi <ksk@google.com> 2015-04-16 17:41:06 +0900
committer Keisuke Kuroyanagi <ksk@google.com> 2015-04-16 17:41:06 +0900
commit88d92da325bf976245cffa773afd2df5a951a357 (patch)
treebb17263a2c85bfedd1e796d4daa0ebaa7b7bd6b6
parent7a11a0e8c1bf452de0516b675b0180f63d9c5c5d (diff)
Enable mouse drag text selection for unfocused TextView.
Bug: 17643755 Change-Id: If6ca064a082feaf6faf9555b1455c4b2f6312952
-rw-r--r--core/java/android/text/method/ArrowKeyMovementMethod.java39
1 files 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.