diff options
author | Gilles Debunne <debunne@google.com> | 2012-01-25 17:06:34 -0800 |
---|---|---|
committer | Gilles Debunne <debunne@google.com> | 2012-01-25 17:06:38 -0800 |
commit | 7af1f9669b98020f83aa5278bb173550053b53d3 (patch) | |
tree | 551258a62f7809799c91139e75657f4bc244434d | |
parent | 3f696b264e4a3dd28421e9e1a58fe2c6241f48e4 (diff) | |
download | frameworks_base-7af1f9669b98020f83aa5278bb173550053b53d3.zip frameworks_base-7af1f9669b98020f83aa5278bb173550053b53d3.tar.gz frameworks_base-7af1f9669b98020f83aa5278bb173550053b53d3.tar.bz2 |
Fix for IOOB when suggestions have disappeared
This new test is required since the suggestion popup is now triggered by a
Runnable. We have to make sure there is still at least one SuggestionSpan
at that position.
Change-Id: I5c84ba0ca412f51a0201bee5c2e63b5bd3717338
-rw-r--r-- | core/java/android/widget/TextView.java | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index b82a632..3902cee 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -9754,11 +9754,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener public void show() { if (!(mText instanceof Editable)) return; - updateSuggestions(); - mCursorWasVisibleBeforeSuggestions = mCursorVisible; - setCursorVisible(false); - mIsShowingUp = true; - super.show(); + if (updateSuggestions()) { + mCursorWasVisibleBeforeSuggestions = mCursorVisible; + setCursorVisible(false); + mIsShowingUp = true; + super.show(); + } } @Override @@ -9814,11 +9815,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener super.hide(); } - private void updateSuggestions() { + private boolean updateSuggestions() { Spannable spannable = (Spannable) TextView.this.mText; SuggestionSpan[] suggestionSpans = getSuggestionSpans(); final int nbSpans = suggestionSpans.length; + // Suggestions are shown after a delay: the underlying spans may have been removed + if (nbSpans == 0) return false; mNumberOfSuggestions = 0; int spanUnionStart = mText.length(); @@ -9904,6 +9907,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mSuggestionsAdapter.notifyDataSetChanged(); + return true; } private void highlightTextDifferences(SuggestionInfo suggestionInfo, int unionStart, |