Merge change 2411 into donut

* changes:
  Manual merge from cupcake_dcm. Need to be reviewed by enf.
This commit is contained in:
Android (Google) Code Review
2009-06-10 08:01:20 -07:00
4 changed files with 34 additions and 22 deletions

View File

@@ -49,10 +49,6 @@ public abstract class LoginFilter implements InputFilter {
*/ */
public CharSequence filter(CharSequence source, int start, int end, public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) { Spanned dest, int dstart, int dend) {
char[] out = new char[end - start]; // reserve enough space for whole string
int outidx = 0;
boolean changed = false;
onStart(); onStart();
// Scan through beginning characters in dest, calling onInvalidCharacter() // Scan through beginning characters in dest, calling onInvalidCharacter()
@@ -63,14 +59,26 @@ public abstract class LoginFilter implements InputFilter {
} }
// Scan through changed characters rejecting disallowed chars // Scan through changed characters rejecting disallowed chars
SpannableStringBuilder modification = null;
int modoff = 0;
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
char c = source.charAt(i); char c = source.charAt(i);
if (isAllowed(c)) { if (isAllowed(c)) {
// Character allowed. Add it to the sequence. // Character allowed.
out[outidx++] = c; modoff++;
} else { } else {
if (mAppendInvalid) out[outidx++] = c; if (mAppendInvalid) {
else changed = true; // we changed the original string modoff++;
} else {
if (modification == null) {
modification = new SpannableStringBuilder(source, start, end);
modoff = i - start;
}
modification.delete(modoff, modoff + 1);
}
onInvalidCharacter(c); onInvalidCharacter(c);
} }
} }
@@ -84,20 +92,9 @@ public abstract class LoginFilter implements InputFilter {
onStop(); onStop();
if (!changed) { // Either returns null if we made no changes,
return null; // or what we wanted to change it to if there were changes.
} return modification;
String s = new String(out, 0, outidx);
if (source instanceof Spanned) {
SpannableString sp = new SpannableString(s);
TextUtils.copySpansFrom((Spanned) source,
start, end, null, sp, 0);
return sp;
} else {
return s;
}
} }
/** /**

View File

@@ -916,6 +916,17 @@ public class TextUtils {
sp.setSpan(o, p.readInt(), p.readInt(), p.readInt()); sp.setSpan(o, p.readInt(), p.readInt(), p.readInt());
} }
/**
* Copies the spans from the region <code>start...end</code> in
* <code>source</code> to the region
* <code>destoff...destoff+end-start</code> in <code>dest</code>.
* Spans in <code>source</code> that begin before <code>start</code>
* or end after <code>end</code> but overlap this range are trimmed
* as if they began at <code>start</code> or ended at <code>end</code>.
*
* @throws IndexOutOfBoundsException if any of the copied spans
* are out of range in <code>dest</code>.
*/
public static void copySpansFrom(Spanned source, int start, int end, public static void copySpansFrom(Spanned source, int start, int end,
Class kind, Class kind,
Spannable dest, int destoff) { Spannable dest, int destoff) {

View File

@@ -950,6 +950,8 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
* @param text the selected suggestion in the drop down list * @param text the selected suggestion in the drop down list
*/ */
protected void replaceText(CharSequence text) { protected void replaceText(CharSequence text) {
clearComposingText();
setText(text); setText(text);
// make sure we keep the caret at the end of the text view // make sure we keep the caret at the end of the text view
Editable spannable = getText(); Editable spannable = getText();

View File

@@ -195,6 +195,8 @@ public class MultiAutoCompleteTextView extends AutoCompleteTextView {
*/ */
@Override @Override
protected void replaceText(CharSequence text) { protected void replaceText(CharSequence text) {
clearComposingText();
int end = getSelectionEnd(); int end = getSelectionEnd();
int start = mTokenizer.findTokenStart(getText(), end); int start = mTokenizer.findTokenStart(getText(), end);