diff options
| author | Svetoslav Ganov <svetoslavganov@google.com> | 2012-05-29 09:15:30 -0700 |
|---|---|---|
| committer | Svetoslav Ganov <svetoslavganov@google.com> | 2012-05-29 15:16:19 -0700 |
| commit | 39f2aee640eea62b43fa79f28dec3a962e5cb065 (patch) | |
| tree | 0195879c55bb7823f5fe43e17fd7a39a66cfe1bd /core/java/android/widget | |
| parent | a587b890bb0c2f800fe4dfd3267f26366d00d32c (diff) | |
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
Diffstat (limited to 'core/java/android/widget')
| -rw-r--r-- | core/java/android/widget/AccessibilityIterators.java | 77 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 10 |
2 files changed, 31 insertions, 56 deletions
diff --git a/core/java/android/widget/AccessibilityIterators.java b/core/java/android/widget/AccessibilityIterators.java index e800e8df575f..a3d58a4e2060 100644 --- a/core/java/android/widget/AccessibilityIterators.java +++ b/core/java/android/widget/AccessibilityIterators.java @@ -56,16 +56,18 @@ final class AccessibilityIterators { if (offset >= mText.length()) { return null; } - int nextLine = -1; + int nextLine; if (offset < 0) { nextLine = mLayout.getLineForOffset(0); } else { final int currentLine = mLayout.getLineForOffset(offset); - if (currentLine < mLayout.getLineCount() - 1) { + if (getLineEdgeIndex(currentLine, DIRECTION_START) == offset) { + nextLine = currentLine; + } else { nextLine = currentLine + 1; } } - if (nextLine < 0) { + if (nextLine >= mLayout.getLineCount()) { return null; } final int start = getLineEdgeIndex(nextLine, DIRECTION_START); @@ -82,12 +84,14 @@ final class AccessibilityIterators { if (offset <= 0) { return null; } - int previousLine = -1; + int previousLine; if (offset > mText.length()) { previousLine = mLayout.getLineForOffset(mText.length()); } else { - final int currentLine = mLayout.getLineForOffset(offset - 1); - if (currentLine > 0) { + final int currentLine = mLayout.getLineForOffset(offset); + if (getLineEdgeIndex(currentLine, DIRECTION_END) + 1 == offset) { + previousLine = currentLine; + } else { previousLine = currentLine - 1; } } @@ -141,29 +145,18 @@ final class AccessibilityIterators { return null; } - final int currentLine = mLayout.getLineForOffset(offset); + final int start = Math.max(0, offset); + + final int currentLine = mLayout.getLineForOffset(start); final int currentLineTop = mLayout.getLineTop(currentLine); final int pageHeight = mTempRect.height() - mView.getTotalPaddingTop() - mView.getTotalPaddingBottom(); + final int nextPageStartY = currentLineTop + pageHeight; + final int lastLineTop = mLayout.getLineTop(mLayout.getLineCount() - 1); + final int currentPageEndLine = (nextPageStartY < lastLineTop) + ? mLayout.getLineForVertical(nextPageStartY) - 1 : mLayout.getLineCount() - 1; - final int nextPageStartLine; - final int nextPageEndLine; - if (offset < 0) { - nextPageStartLine = currentLine; - final int nextPageEndY = currentLineTop + pageHeight; - nextPageEndLine = mLayout.getLineForVertical(nextPageEndY); - } else { - final int nextPageStartY = currentLineTop + pageHeight; - nextPageStartLine = mLayout.getLineForVertical(nextPageStartY) + 1; - if (mLayout.getLineTop(nextPageStartLine) <= nextPageStartY) { - return null; - } - final int nextPageEndY = nextPageStartY + pageHeight; - nextPageEndLine = mLayout.getLineForVertical(nextPageEndY); - } - - final int start = getLineEdgeIndex(nextPageStartLine, DIRECTION_START); - final int end = getLineEdgeIndex(nextPageEndLine, DIRECTION_END) + 1; + final int end = getLineEdgeIndex(currentPageEndLine, DIRECTION_END) + 1; return getRange(start, end); } @@ -181,37 +174,17 @@ final class AccessibilityIterators { return null; } - final int currentLine = mLayout.getLineForOffset(offset); + final int end = Math.min(mText.length(), offset); + + final int currentLine = mLayout.getLineForOffset(end); final int currentLineTop = mLayout.getLineTop(currentLine); final int pageHeight = mTempRect.height() - mView.getTotalPaddingTop() - mView.getTotalPaddingBottom(); + final int previousPageEndY = currentLineTop - pageHeight; + final int currentPageStartLine = (previousPageEndY > 0) ? + mLayout.getLineForVertical(previousPageEndY) + 1 : 0; - final int previousPageStartLine; - final int previousPageEndLine; - if (offset > mText.length()) { - final int prevousPageStartY = mLayout.getHeight() - pageHeight; - if (prevousPageStartY < 0) { - return null; - } - previousPageStartLine = mLayout.getLineForVertical(prevousPageStartY); - previousPageEndLine = mLayout.getLineCount() - 1; - } else { - final int prevousPageStartY; - if (offset == mText.length()) { - prevousPageStartY = mLayout.getHeight() - 2 * pageHeight; - } else { - prevousPageStartY = currentLineTop - 2 * pageHeight; - } - if (prevousPageStartY < 0) { - return null; - } - previousPageStartLine = mLayout.getLineForVertical(prevousPageStartY); - final int previousPageEndY = prevousPageStartY + pageHeight; - previousPageEndLine = mLayout.getLineForVertical(previousPageEndY) - 1; - } - - final int start = getLineEdgeIndex(previousPageStartLine, DIRECTION_START); - final int end = getLineEdgeIndex(previousPageEndLine, DIRECTION_END) + 1; + final int start = getLineEdgeIndex(currentPageStartLine, DIRECTION_START); return getRange(start, end); } 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); |
