summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Luca Zanolin <zano@google.com> 2011-09-08 12:03:37 +0100
committer Luca Zanolin <zano@google.com> 2011-09-12 18:07:31 +0100
commite076045f10a1f4fd2764ec2230e068702fd64d06 (patch)
tree8ec82e8e303a28b248ae18705f476d03e1d41771
parent92bda84b11ba2aec98036313784444d9f5aebc9a (diff)
If suggestion span is not enable, removes the suggestion span (so no underline is displayed),
and do not try to display the suggestion pop-up. Bug: 5267093 Change-Id: Ia6f2596d0c62885ef9affeb478e00d3b92d76aac
-rw-r--r--core/java/android/widget/TextView.java32
1 files changed, 30 insertions, 2 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index b9481140c721..40d85d8c07ca 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -3102,6 +3102,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
text = "";
}
+ // If suggestions are not enabled, remove the suggestion spans from the text
+ if (!isSuggestionsEnabled()) {
+ text = removeSuggestionSpans(text);
+ }
+
if (!mUserSetTextScaleX) mTextPaint.setTextScaleX(1.0f);
if (text instanceof Spanned &&
@@ -3503,6 +3508,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
applySingleLine(singleLine, !isPassword, true);
}
+ if (!isSuggestionsEnabled()) {
+ mText = removeSuggestionSpans(mText);
+ }
+
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null) imm.restartInput(this);
}
@@ -9923,9 +9932,28 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
}
- void showSuggestions() {
- if (!isSuggestionsEnabled() || !isTextEditable()) return;
+ /**
+ * Removes the suggestion spans.
+ */
+ CharSequence removeSuggestionSpans(CharSequence text) {
+ if (text instanceof Spanned) {
+ Spannable spannable;
+ if (text instanceof Spannable) {
+ spannable = (Spannable) text;
+ } else {
+ spannable = new SpannableString(text);
+ text = spannable;
+ }
+ SuggestionSpan[] spans = spannable.getSpans(0, text.length(), SuggestionSpan.class);
+ for (int i = 0; i < spans.length; i++) {
+ spannable.removeSpan(spans[i]);
+ }
+ }
+ return text;
+ }
+
+ void showSuggestions() {
if (mSuggestionsPopupWindow == null) {
mSuggestionsPopupWindow = new SuggestionsPopupWindow();
}