Skip to content

Commit a80599f

Browse files
author
Gilles Debunne
committed
Revert "Bug 5248215: Even though I turned off the Spelling correction, it still shows up"
This reverts commit 6e405f8. Change-Id: I9593273d414aee1f9817f84b462cf45360ff19e3
1 parent faa75f6 commit a80599f

2 files changed

Lines changed: 18 additions & 65 deletions

File tree

core/java/android/widget/SpellChecker.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,6 @@ public SpellChecker(TextView textView) {
7575
mLength = 0;
7676
}
7777

78-
/**
79-
* @return true if a spell checker session has successfully been created. Returns false if not,
80-
* for instance when spell checking has been disabled in settings.
81-
*/
82-
public boolean isSessionActive() {
83-
return mSpellCheckerSession != null;
84-
}
85-
86-
public void closeSession() {
87-
if (mSpellCheckerSession != null) {
88-
mSpellCheckerSession.close();
89-
}
90-
}
91-
9278
public void addSpellCheckSpan(SpellCheckSpan spellCheckSpan) {
9379
int length = mIds.length;
9480
if (mLength >= length) {

core/java/android/widget/TextView.java

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3250,7 +3250,7 @@ private void setText(CharSequence text, BufferType type,
32503250
sendOnTextChanged(text, 0, oldlen, textLength);
32513251
onTextChanged(text, 0, oldlen, textLength);
32523252

3253-
if (startSpellCheck && getSpellChecker().isSessionActive()) {
3253+
if (startSpellCheck) {
32543254
updateSpellCheckSpans(0, textLength);
32553255
}
32563256

@@ -7595,16 +7595,14 @@ void handleTextChanged(CharSequence buffer, int start, int before, int after) {
75957595
}
75967596
ims.mChangedDelta += after-before;
75977597
}
7598-
7598+
75997599
sendOnTextChanged(buffer, start, before, after);
76007600
onTextChanged(buffer, start, before, after);
76017601

7602-
if (getSpellChecker().isSessionActive()) {
7603-
// The WordIterator text change listener may be called after this one.
7604-
// Make sure this changed text is rescanned before the iterator is used on it.
7605-
getWordIterator().forceUpdate();
7606-
updateSpellCheckSpans(start, start + after);
7607-
}
7602+
// The WordIterator text change listener may be called after this one.
7603+
// Make sure this changed text is rescanned before the iterator is used on it.
7604+
getWordIterator().forceUpdate();
7605+
updateSpellCheckSpans(start, start + after);
76087606

76097607
// Hide the controllers if the amount of content changed
76107608
if (before != after) {
@@ -8256,10 +8254,6 @@ public void onWindowFocusChanged(boolean hasWindowFocus) {
82568254
mBlink.uncancel();
82578255
makeBlink();
82588256
}
8259-
if (getSpellChecker().isSessionActive() && (mSuggestionsPopupWindow == null ||
8260-
!mSuggestionsPopupWindow.mSuggestionPopupWindowVisible)) {
8261-
updateSpellCheckSpans(0, mText.length());
8262-
}
82638257
} else {
82648258
if (mBlink != null) {
82658259
mBlink.cancel();
@@ -8271,16 +8265,6 @@ public void onWindowFocusChanged(boolean hasWindowFocus) {
82718265
}
82728266

82738267
hideControllers();
8274-
8275-
if (mSpellChecker != null && (mSuggestionsPopupWindow == null ||
8276-
!mSuggestionsPopupWindow.mSuggestionPopupWindowVisible)) {
8277-
mSpellChecker.closeSession();
8278-
removeMisspelledSpans();
8279-
// Forces the creation of a new SpellChecker next time this window if focused.
8280-
// Will handle the cases where the service has been enabled or disabled in
8281-
// settings in the meantime.
8282-
mSpellChecker = null;
8283-
}
82848268
}
82858269

82868270
startStopMarquee(hasWindowFocus);
@@ -8443,31 +8427,13 @@ private void downgradeEasyCorrectionSpans() {
84438427
int flags = suggestionSpans[i].getFlags();
84448428
if ((flags & SuggestionSpan.FLAG_EASY_CORRECT) != 0
84458429
&& (flags & SuggestionSpan.FLAG_MISSPELLED) == 0) {
8446-
flags &= ~SuggestionSpan.FLAG_EASY_CORRECT;
8430+
flags = flags & ~SuggestionSpan.FLAG_EASY_CORRECT;
84478431
suggestionSpans[i].setFlags(flags);
84488432
}
84498433
}
84508434
}
84518435
}
84528436

8453-
/**
8454-
* Removes the suggestion spans for misspelled words.
8455-
*/
8456-
private void removeMisspelledSpans() {
8457-
if (mText instanceof Spannable) {
8458-
Spannable spannable = (Spannable) mText;
8459-
SuggestionSpan[] suggestionSpans = spannable.getSpans(0,
8460-
spannable.length(), SuggestionSpan.class);
8461-
for (int i = 0; i < suggestionSpans.length; i++) {
8462-
int flags = suggestionSpans[i].getFlags();
8463-
if ((flags & SuggestionSpan.FLAG_EASY_CORRECT) != 0
8464-
&& (flags & SuggestionSpan.FLAG_MISSPELLED) != 0) {
8465-
spannable.removeSpan(suggestionSpans[i]);
8466-
}
8467-
}
8468-
}
8469-
}
8470-
84718437
@Override
84728438
public boolean onGenericMotionEvent(MotionEvent event) {
84738439
if (mMovement != null && mText instanceof Spannable && mLayout != null) {
@@ -9603,25 +9569,25 @@ private class SuggestionsPopupWindow extends PinnedPopupWindow implements OnItem
96039569
private SuggestionInfo[] mSuggestionInfos;
96049570
private int mNumberOfSuggestions;
96059571
private boolean mCursorWasVisibleBeforeSuggestions;
9606-
private boolean mSuggestionPopupWindowVisible;
96079572
private SuggestionAdapter mSuggestionsAdapter;
96089573
private final Comparator<SuggestionSpan> mSuggestionSpanComparator;
96099574
private final HashMap<SuggestionSpan, Integer> mSpansLengths;
96109575

9576+
96119577
private class CustomPopupWindow extends PopupWindow {
96129578
public CustomPopupWindow(Context context, int defStyle) {
96139579
super(context, null, defStyle);
96149580
}
96159581

96169582
@Override
96179583
public void dismiss() {
9618-
mSuggestionPopupWindowVisible = false;
96199584
super.dismiss();
96209585

96219586
TextView.this.getPositionListener().removeSubscriber(SuggestionsPopupWindow.this);
96229587

9623-
// Safe cast since show() checks that mText is an Editable
9624-
((Spannable) mText).removeSpan(mSuggestionRangeSpan);
9588+
if ((mText instanceof Spannable)) {
9589+
((Spannable) mText).removeSpan(mSuggestionRangeSpan);
9590+
}
96259591

96269592
setCursorVisible(mCursorWasVisibleBeforeSuggestions);
96279593
if (hasInsertionController()) {
@@ -9671,8 +9637,8 @@ private class SuggestionInfo {
96719637
void removeMisspelledFlag() {
96729638
int suggestionSpanFlags = suggestionSpan.getFlags();
96739639
if ((suggestionSpanFlags & SuggestionSpan.FLAG_MISSPELLED) > 0) {
9674-
suggestionSpanFlags &= ~SuggestionSpan.FLAG_MISSPELLED;
9675-
suggestionSpanFlags &= ~SuggestionSpan.FLAG_EASY_CORRECT;
9640+
suggestionSpanFlags &= ~(SuggestionSpan.FLAG_MISSPELLED);
9641+
suggestionSpanFlags &= ~(SuggestionSpan.FLAG_EASY_CORRECT);
96769642
suggestionSpan.setFlags(suggestionSpanFlags);
96779643
}
96789644
}
@@ -9759,7 +9725,6 @@ public void show() {
97599725

97609726
if (updateSuggestions()) {
97619727
mCursorWasVisibleBeforeSuggestions = mCursorVisible;
9762-
mSuggestionPopupWindowVisible = true;
97639728
setCursorVisible(false);
97649729
super.show();
97659730
}
@@ -10555,7 +10520,9 @@ private boolean isVisible() {
1055510520

1055610521
public abstract int getCurrentCursorOffset();
1055710522

10558-
protected abstract void updateSelection(int offset);
10523+
protected void updateSelection(int offset) {
10524+
updateDrawable();
10525+
}
1055910526

1056010527
public abstract void updatePosition(float x, float y);
1056110528

@@ -10829,8 +10796,8 @@ public int getCurrentCursorOffset() {
1082910796

1083010797
@Override
1083110798
public void updateSelection(int offset) {
10799+
super.updateSelection(offset);
1083210800
Selection.setSelection((Spannable) mText, offset, getSelectionEnd());
10833-
updateDrawable();
1083410801
}
1083510802

1083610803
@Override
@@ -10871,8 +10838,8 @@ public int getCurrentCursorOffset() {
1087110838

1087210839
@Override
1087310840
public void updateSelection(int offset) {
10841+
super.updateSelection(offset);
1087410842
Selection.setSelection((Spannable) mText, getSelectionStart(), offset);
10875-
updateDrawable();
1087610843
}
1087710844

1087810845
@Override

0 commit comments

Comments
 (0)