summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/TextView.java
diff options
context:
space:
mode:
authorGilles Debunne <debunne@google.com>2011-09-16 14:26:12 -0700
committerGilles Debunne <debunne@google.com>2011-09-19 10:57:22 -0700
commit6e405f84b8d0c7c0f939bc8e9bec17e65e704a2d (patch)
tree639205e90c8b46cdb49c93173fb2ae738aea7540 /core/java/android/widget/TextView.java
parent86c2fe474117b4a003125138e0f0e44f5002dfac (diff)
downloadframeworks_base-6e405f84b8d0c7c0f939bc8e9bec17e65e704a2d.zip
frameworks_base-6e405f84b8d0c7c0f939bc8e9bec17e65e704a2d.tar.gz
frameworks_base-6e405f84b8d0c7c0f939bc8e9bec17e65e704a2d.tar.bz2
Bug 5248215: Even though I turned off the Spelling correction, it still shows up
Bug 5313754: SpellCheckSession is released when the window loses focus. When an EditText is initialized with text, a new spell check is initiated and previous spell check spans are removed. Requires a new flag to prevent this from happening when the window focus change comes from the suggestion popup window being shown. Also fixes bug 5329588: handle spell check language change. Change-Id: I113229dbe06863d34c1369d05d067292894f73f1
Diffstat (limited to 'core/java/android/widget/TextView.java')
-rw-r--r--core/java/android/widget/TextView.java69
1 files changed, 51 insertions, 18 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 58e0edd..724b383 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -3245,7 +3245,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
sendOnTextChanged(text, 0, oldlen, textLength);
onTextChanged(text, 0, oldlen, textLength);
- if (startSpellCheck) {
+ if (startSpellCheck && getSpellChecker().isSessionActive()) {
updateSpellCheckSpans(0, textLength);
}
@@ -7590,14 +7590,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
ims.mChangedDelta += after-before;
}
-
+
sendOnTextChanged(buffer, start, before, after);
onTextChanged(buffer, start, before, after);
- // The WordIterator text change listener may be called after this one.
- // Make sure this changed text is rescanned before the iterator is used on it.
- getWordIterator().forceUpdate();
- updateSpellCheckSpans(start, start + after);
+ if (getSpellChecker().isSessionActive()) {
+ // The WordIterator text change listener may be called after this one.
+ // Make sure this changed text is rescanned before the iterator is used on it.
+ getWordIterator().forceUpdate();
+ updateSpellCheckSpans(start, start + after);
+ }
// Hide the controllers if the amount of content changed
if (before != after) {
@@ -8249,6 +8251,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
mBlink.uncancel();
makeBlink();
}
+ if (getSpellChecker().isSessionActive() && (mSuggestionsPopupWindow == null ||
+ !mSuggestionsPopupWindow.mSuggestionPopupWindowVisible)) {
+ updateSpellCheckSpans(0, mText.length());
+ }
} else {
if (mBlink != null) {
mBlink.cancel();
@@ -8260,6 +8266,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
}
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);
@@ -8422,13 +8438,31 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
int flags = suggestionSpans[i].getFlags();
if ((flags & SuggestionSpan.FLAG_EASY_CORRECT) != 0
&& (flags & SuggestionSpan.FLAG_MISSPELLED) == 0) {
- flags = flags & ~SuggestionSpan.FLAG_EASY_CORRECT;
+ flags &= ~SuggestionSpan.FLAG_EASY_CORRECT;
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
public boolean onGenericMotionEvent(MotionEvent event) {
if (mMovement != null && mText instanceof Spannable && mLayout != null) {
@@ -9564,11 +9598,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
private SuggestionInfo[] mSuggestionInfos;
private int mNumberOfSuggestions;
private boolean mCursorWasVisibleBeforeSuggestions;
+ private boolean mSuggestionPopupWindowVisible;
private SuggestionAdapter mSuggestionsAdapter;
private final Comparator<SuggestionSpan> mSuggestionSpanComparator;
private final HashMap<SuggestionSpan, Integer> mSpansLengths;
-
private class CustomPopupWindow extends PopupWindow {
public CustomPopupWindow(Context context, int defStyle) {
super(context, null, defStyle);
@@ -9576,13 +9610,13 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
@Override
public void dismiss() {
+ mSuggestionPopupWindowVisible = false;
super.dismiss();
TextView.this.getPositionListener().removeSubscriber(SuggestionsPopupWindow.this);
- if ((mText instanceof Spannable)) {
- ((Spannable) mText).removeSpan(mSuggestionRangeSpan);
- }
+ // Safe cast since show() checks that mText is an Editable
+ ((Spannable) mText).removeSpan(mSuggestionRangeSpan);
setCursorVisible(mCursorWasVisibleBeforeSuggestions);
if (hasInsertionController()) {
@@ -9632,8 +9666,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
void removeMisspelledFlag() {
int suggestionSpanFlags = suggestionSpan.getFlags();
if ((suggestionSpanFlags & SuggestionSpan.FLAG_MISSPELLED) > 0) {
- suggestionSpanFlags &= ~(SuggestionSpan.FLAG_MISSPELLED);
- suggestionSpanFlags &= ~(SuggestionSpan.FLAG_EASY_CORRECT);
+ suggestionSpanFlags &= ~SuggestionSpan.FLAG_MISSPELLED;
+ suggestionSpanFlags &= ~SuggestionSpan.FLAG_EASY_CORRECT;
suggestionSpan.setFlags(suggestionSpanFlags);
}
}
@@ -9720,6 +9754,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (updateSuggestions()) {
mCursorWasVisibleBeforeSuggestions = mCursorVisible;
+ mSuggestionPopupWindowVisible = true;
setCursorVisible(false);
super.show();
}
@@ -10515,9 +10550,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
public abstract int getCurrentCursorOffset();
- protected void updateSelection(int offset) {
- updateDrawable();
- }
+ protected abstract void updateSelection(int offset);
public abstract void updatePosition(float x, float y);
@@ -10791,8 +10824,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
@Override
public void updateSelection(int offset) {
- super.updateSelection(offset);
Selection.setSelection((Spannable) mText, offset, getSelectionEnd());
+ updateDrawable();
}
@Override
@@ -10833,8 +10866,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
@Override
public void updateSelection(int offset) {
- super.updateSelection(offset);
Selection.setSelection((Spannable) mText, getSelectionStart(), offset);
+ updateDrawable();
}
@Override