Merge "Bug 5248215: Even though I turned off the Spelling correction, it still shows up"
This commit is contained in:
committed by
Android (Google) Code Review
commit
576b6bb2f9
@@ -75,6 +75,20 @@ public class SpellChecker implements SpellCheckerSessionListener {
|
|||||||
mLength = 0;
|
mLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if a spell checker session has successfully been created. Returns false if not,
|
||||||
|
* for instance when spell checking has been disabled in settings.
|
||||||
|
*/
|
||||||
|
public boolean isSessionActive() {
|
||||||
|
return mSpellCheckerSession != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeSession() {
|
||||||
|
if (mSpellCheckerSession != null) {
|
||||||
|
mSpellCheckerSession.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void addSpellCheckSpan(SpellCheckSpan spellCheckSpan) {
|
public void addSpellCheckSpan(SpellCheckSpan spellCheckSpan) {
|
||||||
int length = mIds.length;
|
int length = mIds.length;
|
||||||
if (mLength >= length) {
|
if (mLength >= length) {
|
||||||
|
|||||||
@@ -3250,7 +3250,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
sendOnTextChanged(text, 0, oldlen, textLength);
|
sendOnTextChanged(text, 0, oldlen, textLength);
|
||||||
onTextChanged(text, 0, oldlen, textLength);
|
onTextChanged(text, 0, oldlen, textLength);
|
||||||
|
|
||||||
if (startSpellCheck) {
|
if (startSpellCheck && getSpellChecker().isSessionActive()) {
|
||||||
updateSpellCheckSpans(0, textLength);
|
updateSpellCheckSpans(0, textLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7595,14 +7595,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
}
|
}
|
||||||
ims.mChangedDelta += after-before;
|
ims.mChangedDelta += after-before;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendOnTextChanged(buffer, start, before, after);
|
sendOnTextChanged(buffer, start, before, after);
|
||||||
onTextChanged(buffer, start, before, after);
|
onTextChanged(buffer, start, before, after);
|
||||||
|
|
||||||
// The WordIterator text change listener may be called after this one.
|
if (getSpellChecker().isSessionActive()) {
|
||||||
// Make sure this changed text is rescanned before the iterator is used on it.
|
// The WordIterator text change listener may be called after this one.
|
||||||
getWordIterator().forceUpdate();
|
// Make sure this changed text is rescanned before the iterator is used on it.
|
||||||
updateSpellCheckSpans(start, start + after);
|
getWordIterator().forceUpdate();
|
||||||
|
updateSpellCheckSpans(start, start + after);
|
||||||
|
}
|
||||||
|
|
||||||
// Hide the controllers if the amount of content changed
|
// Hide the controllers if the amount of content changed
|
||||||
if (before != after) {
|
if (before != after) {
|
||||||
@@ -8254,6 +8256,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
mBlink.uncancel();
|
mBlink.uncancel();
|
||||||
makeBlink();
|
makeBlink();
|
||||||
}
|
}
|
||||||
|
if (getSpellChecker().isSessionActive() && (mSuggestionsPopupWindow == null ||
|
||||||
|
!mSuggestionsPopupWindow.mSuggestionPopupWindowVisible)) {
|
||||||
|
updateSpellCheckSpans(0, mText.length());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mBlink != null) {
|
if (mBlink != null) {
|
||||||
mBlink.cancel();
|
mBlink.cancel();
|
||||||
@@ -8265,6 +8271,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
hideControllers();
|
hideControllers();
|
||||||
|
|
||||||
|
if (mSpellChecker != null && (mSuggestionsPopupWindow == null ||
|
||||||
|
!mSuggestionsPopupWindow.mSuggestionPopupWindowVisible)) {
|
||||||
|
mSpellChecker.closeSession();
|
||||||
|
removeMisspelledSpans();
|
||||||
|
// Forces the creation of a new SpellChecker next time this window if focused.
|
||||||
|
// Will handle the cases where the service has been enabled or disabled in
|
||||||
|
// settings in the meantime.
|
||||||
|
mSpellChecker = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
startStopMarquee(hasWindowFocus);
|
startStopMarquee(hasWindowFocus);
|
||||||
@@ -8427,13 +8443,31 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
int flags = suggestionSpans[i].getFlags();
|
int flags = suggestionSpans[i].getFlags();
|
||||||
if ((flags & SuggestionSpan.FLAG_EASY_CORRECT) != 0
|
if ((flags & SuggestionSpan.FLAG_EASY_CORRECT) != 0
|
||||||
&& (flags & SuggestionSpan.FLAG_MISSPELLED) == 0) {
|
&& (flags & SuggestionSpan.FLAG_MISSPELLED) == 0) {
|
||||||
flags = flags & ~SuggestionSpan.FLAG_EASY_CORRECT;
|
flags &= ~SuggestionSpan.FLAG_EASY_CORRECT;
|
||||||
suggestionSpans[i].setFlags(flags);
|
suggestionSpans[i].setFlags(flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the suggestion spans for misspelled words.
|
||||||
|
*/
|
||||||
|
private void removeMisspelledSpans() {
|
||||||
|
if (mText instanceof Spannable) {
|
||||||
|
Spannable spannable = (Spannable) mText;
|
||||||
|
SuggestionSpan[] suggestionSpans = spannable.getSpans(0,
|
||||||
|
spannable.length(), SuggestionSpan.class);
|
||||||
|
for (int i = 0; i < suggestionSpans.length; i++) {
|
||||||
|
int flags = suggestionSpans[i].getFlags();
|
||||||
|
if ((flags & SuggestionSpan.FLAG_EASY_CORRECT) != 0
|
||||||
|
&& (flags & SuggestionSpan.FLAG_MISSPELLED) != 0) {
|
||||||
|
spannable.removeSpan(suggestionSpans[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||||
if (mMovement != null && mText instanceof Spannable && mLayout != null) {
|
if (mMovement != null && mText instanceof Spannable && mLayout != null) {
|
||||||
@@ -9569,11 +9603,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
private SuggestionInfo[] mSuggestionInfos;
|
private SuggestionInfo[] mSuggestionInfos;
|
||||||
private int mNumberOfSuggestions;
|
private int mNumberOfSuggestions;
|
||||||
private boolean mCursorWasVisibleBeforeSuggestions;
|
private boolean mCursorWasVisibleBeforeSuggestions;
|
||||||
|
private boolean mSuggestionPopupWindowVisible;
|
||||||
private SuggestionAdapter mSuggestionsAdapter;
|
private SuggestionAdapter mSuggestionsAdapter;
|
||||||
private final Comparator<SuggestionSpan> mSuggestionSpanComparator;
|
private final Comparator<SuggestionSpan> mSuggestionSpanComparator;
|
||||||
private final HashMap<SuggestionSpan, Integer> mSpansLengths;
|
private final HashMap<SuggestionSpan, Integer> mSpansLengths;
|
||||||
|
|
||||||
|
|
||||||
private class CustomPopupWindow extends PopupWindow {
|
private class CustomPopupWindow extends PopupWindow {
|
||||||
public CustomPopupWindow(Context context, int defStyle) {
|
public CustomPopupWindow(Context context, int defStyle) {
|
||||||
super(context, null, defStyle);
|
super(context, null, defStyle);
|
||||||
@@ -9581,13 +9615,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dismiss() {
|
public void dismiss() {
|
||||||
|
mSuggestionPopupWindowVisible = false;
|
||||||
super.dismiss();
|
super.dismiss();
|
||||||
|
|
||||||
TextView.this.getPositionListener().removeSubscriber(SuggestionsPopupWindow.this);
|
TextView.this.getPositionListener().removeSubscriber(SuggestionsPopupWindow.this);
|
||||||
|
|
||||||
if ((mText instanceof Spannable)) {
|
// Safe cast since show() checks that mText is an Editable
|
||||||
((Spannable) mText).removeSpan(mSuggestionRangeSpan);
|
((Spannable) mText).removeSpan(mSuggestionRangeSpan);
|
||||||
}
|
|
||||||
|
|
||||||
setCursorVisible(mCursorWasVisibleBeforeSuggestions);
|
setCursorVisible(mCursorWasVisibleBeforeSuggestions);
|
||||||
if (hasInsertionController()) {
|
if (hasInsertionController()) {
|
||||||
@@ -9637,8 +9671,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
void removeMisspelledFlag() {
|
void removeMisspelledFlag() {
|
||||||
int suggestionSpanFlags = suggestionSpan.getFlags();
|
int suggestionSpanFlags = suggestionSpan.getFlags();
|
||||||
if ((suggestionSpanFlags & SuggestionSpan.FLAG_MISSPELLED) > 0) {
|
if ((suggestionSpanFlags & SuggestionSpan.FLAG_MISSPELLED) > 0) {
|
||||||
suggestionSpanFlags &= ~(SuggestionSpan.FLAG_MISSPELLED);
|
suggestionSpanFlags &= ~SuggestionSpan.FLAG_MISSPELLED;
|
||||||
suggestionSpanFlags &= ~(SuggestionSpan.FLAG_EASY_CORRECT);
|
suggestionSpanFlags &= ~SuggestionSpan.FLAG_EASY_CORRECT;
|
||||||
suggestionSpan.setFlags(suggestionSpanFlags);
|
suggestionSpan.setFlags(suggestionSpanFlags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9725,6 +9759,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
|
|
||||||
if (updateSuggestions()) {
|
if (updateSuggestions()) {
|
||||||
mCursorWasVisibleBeforeSuggestions = mCursorVisible;
|
mCursorWasVisibleBeforeSuggestions = mCursorVisible;
|
||||||
|
mSuggestionPopupWindowVisible = true;
|
||||||
setCursorVisible(false);
|
setCursorVisible(false);
|
||||||
super.show();
|
super.show();
|
||||||
}
|
}
|
||||||
@@ -10520,9 +10555,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
|
|
||||||
public abstract int getCurrentCursorOffset();
|
public abstract int getCurrentCursorOffset();
|
||||||
|
|
||||||
protected void updateSelection(int offset) {
|
protected abstract void updateSelection(int offset);
|
||||||
updateDrawable();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void updatePosition(float x, float y);
|
public abstract void updatePosition(float x, float y);
|
||||||
|
|
||||||
@@ -10796,8 +10829,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateSelection(int offset) {
|
public void updateSelection(int offset) {
|
||||||
super.updateSelection(offset);
|
|
||||||
Selection.setSelection((Spannable) mText, offset, getSelectionEnd());
|
Selection.setSelection((Spannable) mText, offset, getSelectionEnd());
|
||||||
|
updateDrawable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -10838,8 +10871,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateSelection(int offset) {
|
public void updateSelection(int offset) {
|
||||||
super.updateSelection(offset);
|
|
||||||
Selection.setSelection((Spannable) mText, getSelectionStart(), offset);
|
Selection.setSelection((Spannable) mText, getSelectionStart(), offset);
|
||||||
|
updateDrawable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user