am afa0a714: am df372289: Merge "Fixed SpellCheckerSessions leak in TextView" into ics-mr1
* commit 'afa0a714acb45e90bdda3fd72b529a817a25f2d1':
Fixed SpellCheckerSessions leak in TextView
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 5b73a74..90fb106 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -3210,7 +3210,6 @@
}
boolean needEditableForNotification = false;
- boolean startSpellCheck = false;
if (mListeners != null && mListeners.size() != 0) {
needEditableForNotification = true;
@@ -3222,7 +3221,6 @@
setFilters(t, mFilters);
InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null) imm.restartInput(this);
- startSpellCheck = true;
} else if (type == BufferType.SPANNABLE || mMovement != null) {
text = mSpannableFactory.newSpannable(text);
} else if (!(text instanceof CharWrapper)) {
@@ -3311,11 +3309,6 @@
sendOnTextChanged(text, 0, oldlen, textLength);
onTextChanged(text, 0, oldlen, textLength);
- if (startSpellCheck && mSpellChecker != null) {
- // This view has to have been previously attached for mSpellChecker to exist
- updateSpellCheckSpans(0, textLength);
- }
-
if (needEditableForNotification) {
sendAfterTextChanged((Editable) text);
}
@@ -4482,8 +4475,8 @@
// Resolve drawables as the layout direction has been resolved
resolveDrawables();
-
- updateSpellCheckSpans(0, mText.length());
+
+ updateSpellCheckSpans(0, mText.length(), true /* create the spell checker if needed */);
}
@Override
@@ -7636,7 +7629,7 @@
}
}
- updateSpellCheckSpans(start, start + after);
+ updateSpellCheckSpans(start, start + after, false);
// Hide the controllers as soon as text is modified (typing, procedural...)
// We do not hide the span controllers, since they can be added when a new text is
@@ -7794,17 +7787,22 @@
}
}
- if (newStart < 0 && what instanceof SpellCheckSpan) {
- getSpellChecker().removeSpellCheckSpan((SpellCheckSpan) what);
+ if (mSpellChecker != null && newStart < 0 && what instanceof SpellCheckSpan) {
+ mSpellChecker.removeSpellCheckSpan((SpellCheckSpan) what);
}
}
/**
* Create new SpellCheckSpans on the modified region.
*/
- private void updateSpellCheckSpans(int start, int end) {
+ private void updateSpellCheckSpans(int start, int end, boolean createSpellChecker) {
if (isTextEditable() && isSuggestionsEnabled()) {
- getSpellChecker().spellCheck(start, end);
+ if (mSpellChecker == null && createSpellChecker) {
+ mSpellChecker = new SpellChecker(this);
+ }
+ if (mSpellChecker != null) {
+ mSpellChecker.spellCheck(start, end);
+ }
}
}
@@ -8976,13 +8974,6 @@
return packRangeInLong(offset, offset);
}
- private SpellChecker getSpellChecker() {
- if (mSpellChecker == null) {
- mSpellChecker = new SpellChecker(this);
- }
- return mSpellChecker;
- }
-
private long getLastTouchOffsets() {
SelectionModifierCursorController selectionController = getSelectionController();
final int minOffset = selectionController.getMinTouchOffset();
@@ -9937,7 +9928,7 @@
// There is no way to know if the word was indeed added. Re-check.
// TODO The ExtractEditText should remove the span in the original text instead
editable.removeSpan(suggestionInfo.suggestionSpan);
- updateSpellCheckSpans(spanStart, spanEnd);
+ updateSpellCheckSpans(spanStart, spanEnd, false);
} else {
// SuggestionSpans are removed by replace: save them before
SuggestionSpan[] suggestionSpans = editable.getSpans(spanStart, spanEnd,