summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ralston Da Silva <ralu@google.com> 2019-02-10 05:10:22 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-02-10 05:10:22 +0000
commit0671c44a85bf38db54445a909979382d521318cc (patch)
treede10f97f172b3466639e12b522b82c7045f3bfc6
parentb0eab4fad11b12934fb99bace599565506b9c9f6 (diff)
parentccec37e1d13ae6b5223f9a29696d444ae6f3e1f2 (diff)
Merge "Removing hidden api usage from AutoCompleteTextView"
-rw-r--r--api/current.txt1
-rw-r--r--core/java/android/widget/AutoCompleteTextView.java80
2 files changed, 52 insertions, 29 deletions
diff --git a/api/current.txt b/api/current.txt
index cb719c3f7982..91f5cef85e56 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -55250,6 +55250,7 @@ package android.widget {
method public void performCompletion();
method protected void performFiltering(CharSequence, int);
method public void performValidation();
+ method public final void refreshAutoCompleteResults();
method protected void replaceText(CharSequence);
method public <T extends android.widget.ListAdapter & android.widget.Filterable> void setAdapter(T);
method public void setCompletionHint(CharSequence);
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index 9bc055e7111b..7ed7aa293f21 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -126,7 +126,7 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
private boolean mDropDownDismissedOnCompletion = true;
private int mLastKeyCode = KeyEvent.KEYCODE_UNKNOWN;
- private boolean mOpenBefore;
+ private MyWatcher mAutoCompleteTextWatcher;
private Validator mValidator = null;
@@ -302,7 +302,8 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
setFocusable(true);
- addTextChangedListener(new MyWatcher());
+ mAutoCompleteTextWatcher = new MyWatcher();
+ addTextChangedListener(mAutoCompleteTextWatcher);
mPassThroughClickListener = new PassThroughClickListener();
super.setOnClickListener(mPassThroughClickListener);
@@ -872,45 +873,66 @@ public class AutoCompleteTextView extends EditText implements Filter.FilterListe
return getText().length() >= mThreshold;
}
- /**
- * This is used to watch for edits to the text view. Note that we call
- * to methods on the auto complete text view class so that we can access
- * private vars without going through thunks.
- */
+
+
+ /** This is used to watch for edits to the text view. */
private class MyWatcher implements TextWatcher {
- public void afterTextChanged(Editable s) {
- doAfterTextChanged();
- }
+ private boolean mOpenBefore;
+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- doBeforeTextChanged();
+ if (mBlockCompletion) return;
+
+ // when text is changed, inserted or deleted, we attempt to show
+ // the drop down
+ mOpenBefore = isPopupShowing();
+ if (DEBUG) Log.v(TAG, "before text changed: open=" + mOpenBefore);
+ }
+
+ public void afterTextChanged(Editable s) {
+ if (mBlockCompletion) return;
+
+ // if the list was open before the keystroke, but closed afterwards,
+ // then something in the keystroke processing (an input filter perhaps)
+ // called performCompletion() and we shouldn't do any more processing.
+ if (DEBUG) {
+ Log.v(TAG, "after text changed: openBefore=" + mOpenBefore
+ + " open=" + isPopupShowing());
+ }
+
+ if (mOpenBefore && !isPopupShowing()) return;
+
+ refreshAutoCompleteResults();
}
+
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
}
- @UnsupportedAppUsage
+ /**
+ * This function is deprecated. Please use {@link #refreshAutoCompleteResults} instead.
+ * Note: Remove {@link #mAutoCompleteTextWatcher} after removing this function.
+ */
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
void doBeforeTextChanged() {
- if (mBlockCompletion) return;
-
- // when text is changed, inserted or deleted, we attempt to show
- // the drop down
- mOpenBefore = isPopupShowing();
- if (DEBUG) Log.v(TAG, "before text changed: open=" + mOpenBefore);
+ mAutoCompleteTextWatcher.beforeTextChanged(null, 0, 0, 0);
}
- @UnsupportedAppUsage
+ /**
+ * This function is deprecated. Please use {@link #refreshAutoCompleteResults} instead.
+ * Note: Remove {@link #mAutoCompleteTextWatcher} after removing this function.
+ */
+ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
void doAfterTextChanged() {
- if (mBlockCompletion) return;
-
- // if the list was open before the keystroke, but closed afterwards,
- // then something in the keystroke processing (an input filter perhaps)
- // called performCompletion() and we shouldn't do any more processing.
- if (DEBUG) Log.v(TAG, "after text changed: openBefore=" + mOpenBefore
- + " open=" + isPopupShowing());
- if (mOpenBefore && !isPopupShowing()) {
- return;
- }
+ mAutoCompleteTextWatcher.afterTextChanged(null);
+ }
+ /**
+ * Refreshes the auto complete results. You usually shouldn't have to manually refresh the
+ * AutoCompleteResults as this is done automatically whenever the text changes. However if the
+ * results are not available and have to be fetched, you can call this function after fetching
+ * the results.
+ */
+ public final void refreshAutoCompleteResults() {
// the drop down is shown only when a minimum number of characters
// was typed in the text view
if (enoughToFilter()) {