Merge "Limit created string size in Spell Checker" into ics-mr1
This commit is contained in:
committed by
Android (Google) Code Review
commit
0e7b8020fd
@@ -863,6 +863,17 @@ public class SpannableStringBuilder implements CharSequence, GetChars, Spannable
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a String containing a copy of the chars in this buffer, limited to the
|
||||
* [start, end[ range.
|
||||
* @hide
|
||||
*/
|
||||
public String substring(int start, int end) {
|
||||
char[] buf = new char[end - start];
|
||||
getChars(start, end, buf, 0);
|
||||
return new String(buf);
|
||||
}
|
||||
|
||||
private TextWatcher[] sendTextWillChange(int start, int before, int after) {
|
||||
TextWatcher[] recip = getSpans(start, start + before, TextWatcher.class);
|
||||
int n = recip.length;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package android.text.method;
|
||||
|
||||
import android.text.Selection;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
||||
import java.text.BreakIterator;
|
||||
import java.util.Locale;
|
||||
@@ -58,7 +59,11 @@ public class WordIterator implements Selection.PositionIterator {
|
||||
mOffsetShift = Math.max(0, start - WINDOW_WIDTH);
|
||||
final int windowEnd = Math.min(charSequence.length(), end + WINDOW_WIDTH);
|
||||
|
||||
mString = charSequence.toString().substring(mOffsetShift, windowEnd);
|
||||
if (charSequence instanceof SpannableStringBuilder) {
|
||||
mString = ((SpannableStringBuilder) charSequence).substring(mOffsetShift, windowEnd);
|
||||
} else {
|
||||
mString = charSequence.subSequence(mOffsetShift, windowEnd).toString();
|
||||
}
|
||||
mIterator.setText(mString);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package android.widget;
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
import android.text.Selection;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.WordIterator;
|
||||
import android.text.style.SpellCheckSpan;
|
||||
@@ -239,7 +240,9 @@ public class SpellChecker implements SpellCheckerSessionListener {
|
||||
|
||||
// Do not check this word if the user is currently editing it
|
||||
if (start >= 0 && end > start && (selectionEnd < start || selectionStart > end)) {
|
||||
final String word = editable.subSequence(start, end).toString();
|
||||
final String word = (editable instanceof SpannableStringBuilder) ?
|
||||
((SpannableStringBuilder) editable).substring(start, end) :
|
||||
editable.subSequence(start, end).toString();
|
||||
spellCheckSpan.setSpellCheckInProgress(true);
|
||||
textInfos[textInfosCount++] = new TextInfo(word, mCookie, mIds[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user