diff options
| author | Svetoslav <svetoslavganov@google.com> | 2013-02-04 18:39:59 -0800 |
|---|---|---|
| committer | Svetoslav <svetoslavganov@google.com> | 2013-02-05 13:44:25 -0800 |
| commit | d0c83cccca9955da92d076dfdfbc3e349fbbc415 (patch) | |
| tree | 73275acc3a0cb42d5ce4c5ec7a1ec27e4bef1141 /core/java/android/widget/TextView.java | |
| parent | 69ced73b35277e437c9dbbd9e90bfa06c144062f (diff) | |
Set accessibility cursor position in non-editable views with content description.
While an accessibility service can set the cursor position in an editable
text field, it was not possible to set it for non-editable views with
content description. This patch enables that.
bug:8134469
Change-Id: I28b0ef1666b9e3ed5c0642718fbe63d4c9616569
Diffstat (limited to 'core/java/android/widget/TextView.java')
| -rw-r--r-- | core/java/android/widget/TextView.java | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 2f02780270f3..1579e79d4561 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -8030,28 +8030,30 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } return false; case AccessibilityNodeInfo.ACTION_SET_SELECTION: { if (isFocused() && canSelectText()) { - final int start = (arguments != null) ? arguments.getInt( - AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, -1) : -1; - final int end = (arguments != null) ? arguments.getInt( - AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, -1) : -1; CharSequence text = getIterableTextForAccessibility(); if (text == null) { return false; } - // No arguments clears the selection. - if (start == end && end == -1) { - Selection.removeSelection((Spannable) text); - notifyAccessibilityStateChanged(); - return true; - } - if (start >= 0 && start <= end && end <= text.length()) { - Selection.setSelection((Spannable) text, start, end); - // Make sure selection mode is engaged. - if (mEditor != null) { - mEditor.startSelectionActionMode(); + final int start = (arguments != null) ? arguments.getInt( + AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_START_INT, -1) : -1; + final int end = (arguments != null) ? arguments.getInt( + AccessibilityNodeInfo.ACTION_ARGUMENT_SELECTION_END_INT, -1) : -1; + if ((getSelectionStart() != start || getSelectionEnd() != end)) { + // No arguments clears the selection. + if (start == end && end == -1) { + Selection.removeSelection((Spannable) text); + notifyAccessibilityStateChanged(); + return true; + } + if (start >= 0 && start <= end && end <= text.length()) { + Selection.setSelection((Spannable) text, start, end); + // Make sure selection mode is engaged. + if (mEditor != null) { + mEditor.startSelectionActionMode(); + } + notifyAccessibilityStateChanged(); + return true; } - notifyAccessibilityStateChanged(); - return true; } } } return false; |
