summaryrefslogtreecommitdiff
path: root/core/java/android/widget/TextView.java
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2012-04-12 14:50:23 -0700
committerGilles Debunne <debunne@google.com>2012-04-23 18:25:25 -0700
commitc62589cbecef6e748bcc6c6f4ea6a8ff7656923f (patch)
treedb06a9dcccc55d78ab361a43a3f30caf4938560a /core/java/android/widget/TextView.java
parente267f5f2b0f2059fac3b62e5cc09d46b65fdf200 (diff)
Editor uses a SpanWatcher to track EasyEditSpans
Will also fix Bug 6344997 The previous TextWatcher mechanism was inneficient. It require an expensive getSpans() call to retrieve all the spans and then search for the one we're interested in in case it has been changed. The SpanWatcher is faster, it will broadcast the add/changed/removed events we're interested in. Now that we can rely on SpanWatcher, use it to directly track addition and removals of EasyEditSpans. No unit test for this feature which require an integration with the voice IME. Easy to test manually though. Change-Id: Idabcacc48c479bf9868d5204c0b0ca709207ede2
Diffstat (limited to 'core/java/android/widget/TextView.java')
-rw-r--r--core/java/android/widget/TextView.java19
1 files changed, 8 insertions, 11 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 9867e47dea72..5164c7a7a4c3 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -3176,22 +3176,19 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (text instanceof Spannable && !mAllowTransformationLengthChange) {
Spannable sp = (Spannable) text;
- // Remove any ChangeWatchers that might have come
- // from other TextViews.
+ // Remove any ChangeWatchers that might have come from other TextViews.
final ChangeWatcher[] watchers = sp.getSpans(0, sp.length(), ChangeWatcher.class);
final int count = watchers.length;
- for (int i = 0; i < count; i++)
+ for (int i = 0; i < count; i++) {
sp.removeSpan(watchers[i]);
+ }
- if (mChangeWatcher == null)
- mChangeWatcher = new ChangeWatcher();
+ if (mChangeWatcher == null) mChangeWatcher = new ChangeWatcher();
sp.setSpan(mChangeWatcher, 0, textLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE |
(CHANGE_WATCHER_PRIORITY << Spanned.SPAN_PRIORITY_SHIFT));
- if (mEditor != null && getEditor().mKeyListener != null) {
- sp.setSpan(getEditor().mKeyListener, 0, textLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
- }
+ if (mEditor != null) mEditor.addSpanWatchers(sp);
if (mTransformation != null) {
sp.setSpan(mTransformation, 0, textLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
@@ -5231,7 +5228,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
*/
public void setExtracting(ExtractedTextRequest req) {
if (getEditor().mInputMethodState != null) {
- getEditor().mInputMethodState.mExtracting = req;
+ getEditor().mInputMethodState.mExtractedTextRequest = req;
}
// This would stop a possible selection mode, but no such mode is started in case
// extracted mode will start. Some text is selected though, and will trigger an action mode
@@ -6876,7 +6873,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (what instanceof ParcelableSpan) {
// If this is a span that can be sent to a remote process,
// the current extract editor would be interested in it.
- if (ims != null && ims.mExtracting != null) {
+ if (ims != null && ims.mExtractedTextRequest != null) {
if (ims.mBatchEditNesting != 0) {
if (oldStart >= 0) {
if (ims.mChangedStart > oldStart) {
@@ -6897,7 +6894,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
} else {
if (DEBUG_EXTRACT) Log.v(LOG_TAG, "Span change outside of batch: "
+ oldStart + "-" + oldEnd + ","
- + newStart + "-" + newEnd + what);
+ + newStart + "-" + newEnd + " " + what);
ims.mContentChanged = true;
}
}