am 0e7b8020: Merge "Limit created string size in Spell Checker" into ics-mr1

* commit '0e7b8020fd8607957844f7d67e8aaa6dc2ef816f':
  Limit created string size in Spell Checker
This commit is contained in:
Gilles Debunne
2011-12-08 11:58:31 -08:00
committed by Android Git Automerger
3 changed files with 21 additions and 2 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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]);
}