diff options
author | Svet Ganov <svetoslavganov@google.com> | 2014-10-14 08:53:33 -0700 |
---|---|---|
committer | Svet Ganov <svetoslavganov@google.com> | 2014-10-14 08:53:37 -0700 |
commit | 9e1c67e861302f0df55859c422000b437cef2027 (patch) | |
tree | df56016c009cbf80253aa24eea7284be46e8d7ec /core/java/android/widget/TextView.java | |
parent | e78aa53123df02a021cf20f2d19af8d07e890058 (diff) | |
download | frameworks_base-9e1c67e861302f0df55859c422000b437cef2027.zip frameworks_base-9e1c67e861302f0df55859c422000b437cef2027.tar.gz frameworks_base-9e1c67e861302f0df55859c422000b437cef2027.tar.bz2 |
Optimize text rendering in accessibility mode.
In accessibility mode when iterating over the text of a TextView we
use the selection to keep track of the current position. Consequentally,
if the text of a TextView does not support selection we change the text
to Spannable. Doing that has performance cost. While we need selection
support before we used to convert the text to Spannable even if we do
not need to. Now this transformation happens only when the user decides
to traverse the text which is very rare as opposed to doing this for
every TextView.
bug:17491082
Change-Id: Id7e82e01034e439b5d34133b9350a4efc4d19d4a
Diffstat (limited to 'core/java/android/widget/TextView.java')
-rw-r--r-- | core/java/android/widget/TextView.java | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 5cdee53..0917b32 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -8518,6 +8518,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } return false; case AccessibilityNodeInfo.ACTION_SET_SELECTION: { if (isFocused() && canSelectText()) { + ensureIterableTextForAccessibilitySelectable(); CharSequence text = getIterableTextForAccessibility(); if (text == null) { return false; @@ -8543,6 +8544,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } } return false; + case AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY: + case AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY: { + ensureIterableTextForAccessibilitySelectable(); + return super.performAccessibilityAction(action, arguments); + } default: { return super.performAccessibilityAction(action, arguments); } @@ -9032,10 +9038,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener */ @Override public CharSequence getIterableTextForAccessibility() { + return mText; + } + + private void ensureIterableTextForAccessibilitySelectable() { if (!(mText instanceof Spannable)) { setText(mText, BufferType.SPANNABLE); } - return mText; } /** |