Bug 1014233 - Discard autocomplete result if we are not expecting a result. r=wesj

This commit is contained in:
Jim Chen 2014-05-21 14:58:00 -04:00
Родитель 6ebb289168
Коммит cd33c2cc58
1 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -61,6 +61,8 @@ public class ToolbarEditText extends CustomEditText
private boolean mSettingAutoComplete; private boolean mSettingAutoComplete;
// Spans used for marking the autocomplete text // Spans used for marking the autocomplete text
private Object[] mAutoCompleteSpans; private Object[] mAutoCompleteSpans;
// Do not process autocomplete result
private boolean mDiscardAutoCompleteResult;
public ToolbarEditText(Context context, AttributeSet attrs) { public ToolbarEditText(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
@ -226,6 +228,12 @@ public class ToolbarEditText extends CustomEditText
*/ */
@Override @Override
public final void onAutocomplete(final String result) { public final void onAutocomplete(final String result) {
// If mDiscardAutoCompleteResult is true, we temporarily disabled
// autocomplete (due to backspacing, etc.) and we should bail early.
if (mDiscardAutoCompleteResult) {
return;
}
if (!isEnabled() || result == null) { if (!isEnabled() || result == null) {
mAutoCompleteResult = ""; mAutoCompleteResult = "";
return; return;
@ -437,6 +445,10 @@ public class ToolbarEditText extends CustomEditText
mAutoCompletePrefixLength = textLength; mAutoCompletePrefixLength = textLength;
// If we are not autocompleting, we set mDiscardAutoCompleteResult to true
// to discard any autocomplete results that are in-flight, and vice versa.
mDiscardAutoCompleteResult = !doAutocomplete;
if (doAutocomplete && mAutoCompleteResult.startsWith(text)) { if (doAutocomplete && mAutoCompleteResult.startsWith(text)) {
// If this text already matches our autocomplete text, autocomplete likely // If this text already matches our autocomplete text, autocomplete likely
// won't change. Just reuse the old autocomplete value. // won't change. Just reuse the old autocomplete value.