Skip to content

Commit fc7a808

Browse files
Gilles DebunneAndroid (Google) Code Review
authored andcommitted
Merge "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."
2 parents 3e1dc03 + e076045 commit fc7a808

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

core/java/android/widget/TextView.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3102,6 +3102,11 @@ private void setText(CharSequence text, BufferType type,
31023102
text = "";
31033103
}
31043104

3105+
// If suggestions are not enabled, remove the suggestion spans from the text
3106+
if (!isSuggestionsEnabled()) {
3107+
text = removeSuggestionSpans(text);
3108+
}
3109+
31053110
if (!mUserSetTextScaleX) mTextPaint.setTextScaleX(1.0f);
31063111

31073112
if (text instanceof Spanned &&
@@ -3503,6 +3508,10 @@ public void setInputType(int type) {
35033508
applySingleLine(singleLine, !isPassword, true);
35043509
}
35053510

3511+
if (!isSuggestionsEnabled()) {
3512+
mText = removeSuggestionSpans(mText);
3513+
}
3514+
35063515
InputMethodManager imm = InputMethodManager.peekInstance();
35073516
if (imm != null) imm.restartInput(this);
35083517
}
@@ -9923,9 +9932,28 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
99239932
}
99249933
}
99259934

9926-
void showSuggestions() {
9927-
if (!isSuggestionsEnabled() || !isTextEditable()) return;
9935+
/**
9936+
* Removes the suggestion spans.
9937+
*/
9938+
CharSequence removeSuggestionSpans(CharSequence text) {
9939+
if (text instanceof Spanned) {
9940+
Spannable spannable;
9941+
if (text instanceof Spannable) {
9942+
spannable = (Spannable) text;
9943+
} else {
9944+
spannable = new SpannableString(text);
9945+
text = spannable;
9946+
}
99289947

9948+
SuggestionSpan[] spans = spannable.getSpans(0, text.length(), SuggestionSpan.class);
9949+
for (int i = 0; i < spans.length; i++) {
9950+
spannable.removeSpan(spans[i]);
9951+
}
9952+
}
9953+
return text;
9954+
}
9955+
9956+
void showSuggestions() {
99299957
if (mSuggestionsPopupWindow == null) {
99309958
mSuggestionsPopupWindow = new SuggestionsPopupWindow();
99319959
}

0 commit comments

Comments
 (0)