From 39f2aee640eea62b43fa79f28dec3a962e5cb065 Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Tue, 29 May 2012 09:15:30 -0700 Subject: Updating the behaviour of accessibility text iterators. 1. Iterators were skipping content on reversing direction. 2. The cursor was positioned at the beginning of the next text segment when moving forward and at end of the previous text segment when moving backwards. This is incorrect and now the cursor is positioned at the end of the segment when moving forward and at the beginning when moving backward. 3. The cursor position was not properly set when reaching the end/start of the text. 4. The iterators were reporting strictly the next/previous segment even if the cursor is within such a segment. Thus, when traversing some content may be skipped. Now moving forward moves the selection to the next segment end and the start position is either the old index if it was within a segment or the start of the segment. Same in reverse. bug:6575099 Change-Id: Ib48a649cec53910339baf831a75e26440be6e576 --- core/java/android/widget/TextView.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'core/java/android/widget/TextView.java') diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 81a44fdf09c5..1826341877f3 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -8376,10 +8376,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @Override public int getAccessibilityCursorPosition() { if (TextUtils.isEmpty(getContentDescription())) { - return getSelectionEnd(); - } else { - return super.getAccessibilityCursorPosition(); + final int selectionEnd = getSelectionEnd(); + if (selectionEnd >= 0) { + return selectionEnd; + } } + return super.getAccessibilityCursorPosition(); } /** @@ -8391,7 +8393,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return; } if (TextUtils.isEmpty(getContentDescription())) { - if (index >= 0) { + if (index >= 0 && index <= mText.length()) { Selection.setSelection((Spannable) mText, index); } else { Selection.removeSelection((Spannable) mText); -- cgit v1.2.3