diff options
author | Gilles Debunne <debunne@google.com> | 2010-07-09 20:13:45 -0700 |
---|---|---|
committer | Gilles Debunne <debunne@google.com> | 2010-07-12 18:45:40 -0700 |
commit | 05336274dd8e7ababfe5b253069653abbba20c3c (patch) | |
tree | a5229e6d1ab6151fb5d104b7aed58ab1b0c2bd6c /core/java/android/text | |
parent | 36febe1e041ca8d18712f2e75a255e4df6f9f545 (diff) | |
download | frameworks_base-05336274dd8e7ababfe5b253069653abbba20c3c.zip frameworks_base-05336274dd8e7ababfe5b253069653abbba20c3c.tar.gz frameworks_base-05336274dd8e7ababfe5b253069653abbba20c3c.tar.bz2 |
Selection handlers in TextView
Long press on text view triggers selection mode. Two handles can be used to
adjust selection.
Change-Id: I45bb5fd62cae910570cff34920e45c4383160179
Diffstat (limited to 'core/java/android/text')
-rw-r--r-- | core/java/android/text/method/ArrowKeyMovementMethod.java | 44 |
1 files changed, 7 insertions, 37 deletions
diff --git a/core/java/android/text/method/ArrowKeyMovementMethod.java b/core/java/android/text/method/ArrowKeyMovementMethod.java index 9df63a9..55ec655 100644 --- a/core/java/android/text/method/ArrowKeyMovementMethod.java +++ b/core/java/android/text/method/ArrowKeyMovementMethod.java @@ -138,35 +138,6 @@ public class ArrowKeyMovementMethod implements MovementMethod { } } - private int getOffset(int x, int y, TextView widget){ - // Converts the absolute X,Y coordinates to the character offset for the - // character whose position is closest to the specified - // horizontal position. - x -= widget.getTotalPaddingLeft(); - y -= widget.getTotalPaddingTop(); - - // Clamp the position to inside of the view. - if (x < 0) { - x = 0; - } else if (x >= (widget.getWidth()-widget.getTotalPaddingRight())) { - x = widget.getWidth()-widget.getTotalPaddingRight() - 1; - } - if (y < 0) { - y = 0; - } else if (y >= (widget.getHeight()-widget.getTotalPaddingBottom())) { - y = widget.getHeight()-widget.getTotalPaddingBottom() - 1; - } - - x += widget.getScrollX(); - y += widget.getScrollY(); - - Layout layout = widget.getLayout(); - int line = layout.getLineForVertical(y); - - int offset = layout.getOffsetForHorizontal(line, x); - return offset; - } - public boolean onKeyDown(TextView widget, Spannable buffer, int keyCode, KeyEvent event) { if (executeDown(widget, buffer, keyCode)) { MetaKeyKeyListener.adjustMetaAfterKeypress(buffer); @@ -263,7 +234,7 @@ public class ArrowKeyMovementMethod implements MovementMethod { MetaKeyKeyListener.META_SELECTING) != 0); int x = (int) event.getX(); int y = (int) event.getY(); - int offset = getOffset(x, y, widget); + int offset = widget.getOffset(x, y); if (cap) { buffer.setSpan(LAST_TAP_DOWN, offset, offset, @@ -320,7 +291,7 @@ public class ArrowKeyMovementMethod implements MovementMethod { // Get the current touch position int x = (int) event.getX(); int y = (int) event.getY(); - int offset = getOffset(x, y, widget); + int offset = widget.getOffset(x, y); final OnePointFiveTapState[] tap = buffer.getSpans(0, buffer.length(), OnePointFiveTapState.class); @@ -366,7 +337,7 @@ public class ArrowKeyMovementMethod implements MovementMethod { int x = (int) event.getX(); int y = (int) event.getY(); - int off = getOffset(x, y, widget); + int off = widget.getOffset(x, y); // XXX should do the same adjust for x as we do for the line. @@ -442,11 +413,10 @@ public class ArrowKeyMovementMethod implements MovementMethod { widget.cancelLongPress(); // Offset the current touch position (from controller to cursor) - final int x = (int) event.getX() + mCursorController.getOffsetX(); - final int y = (int) event.getY() + mCursorController.getOffsetY(); - int offset = getOffset(x, y, widget); - Selection.setSelection(buffer, offset); - mCursorController.updatePosition(); + final float x = event.getX() + mCursorController.getOffsetX(); + final float y = event.getY() + mCursorController.getOffsetY(); + int offset = widget.getOffset((int) x, (int) y); + mCursorController.updatePosition(offset); return true; case MotionEvent.ACTION_UP: |