Added auto-fill listeners for RadioGroup and CompoundButton.
Bug: 33550221
Bug: 3380254
Test: CtsAutoFillServiceTestCases pass
Change-Id: Ia9293d16b6fe092552e19563328697c298451f8a
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java
index 6f687fe..f2c2af5 100644
--- a/core/java/android/widget/CompoundButton.java
+++ b/core/java/android/widget/CompoundButton.java
@@ -34,6 +34,7 @@
import android.view.ViewHierarchyEncoder;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
+import android.view.autofill.AutoFillManager;
import android.view.autofill.AutoFillType;
import android.view.autofill.AutoFillValue;
@@ -164,6 +165,10 @@
if (mOnCheckedChangeWidgetListener != null) {
mOnCheckedChangeWidgetListener.onCheckedChanged(this, mChecked);
}
+ final AutoFillManager afm = mContext.getSystemService(AutoFillManager.class);
+ if (afm != null) {
+ afm.valueChanged(this);
+ }
mBroadcasting = false;
}
@@ -563,8 +568,6 @@
// TODO(b/33197203): add unit/CTS tests for auto-fill methods (and make sure they handle enable)
- // TODO(b/33197203): override onProvideAutoFillStructure and add a change listener
-
@Override
public void autoFill(AutoFillValue value) {
if (!isEnabled()) return;
@@ -579,6 +582,6 @@
@Override
public AutoFillValue getAutoFillValue() {
- return isEnabled() ? null : AutoFillValue.forToggle(isChecked());
+ return isEnabled() ? AutoFillValue.forToggle(isChecked()) : null;
}
}
diff --git a/core/java/android/widget/RadioGroup.java b/core/java/android/widget/RadioGroup.java
index 8ba4694..76b3813 100644
--- a/core/java/android/widget/RadioGroup.java
+++ b/core/java/android/widget/RadioGroup.java
@@ -24,6 +24,7 @@
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
+import android.view.autofill.AutoFillManager;
import android.view.autofill.AutoFillType;
import android.view.autofill.AutoFillValue;
@@ -177,6 +178,10 @@
if (mOnCheckedChangeListener != null) {
mOnCheckedChangeListener.onCheckedChanged(this, mCheckedId);
}
+ final AutoFillManager afm = mContext.getSystemService(AutoFillManager.class);
+ if (afm != null) {
+ afm.valueChanged(this);
+ }
}
private void setCheckedStateForView(int viewId, boolean checked) {
@@ -405,8 +410,6 @@
// TODO(b/33197203): add unit/CTS tests for auto-fill methods (and make sure they handle enable)
- // TODO(b/33197203): override onProvideAutoFillStructure and add a change listener
-
@Override
public void autoFill(AutoFillValue value) {
if (!isEnabled()) return;
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index bfaddaf..5079f72 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -727,9 +727,6 @@
// mAutoSizeStepGranularityInPx.
private boolean mHasPresetAutoSizeValues = false;
- // Watcher used to notify changes to auto-fill manager.
- private AutoFillChangeWatcher mAutoFillChangeWatcher;
-
// Indicates whether the text was set from resources or dynamically, so it can be used to
// sanitize auto-fill request.
private boolean mTextFromResource = false;
@@ -9113,6 +9110,16 @@
list.get(i).afterTextChanged(text);
}
}
+
+ // Always notify AutoFillManager - it will return right away if auto-fill is disabled.
+ final AutoFillManager afm = mContext.getSystemService(AutoFillManager.class);
+ if (afm != null) {
+ if (DEBUG_AUTOFILL) {
+ Log.v(LOG_TAG, "sendAfterTextChanged(): notify AFM for text=" + text);
+ }
+ afm.valueChanged(TextView.this);
+ }
+
hideErrorIfUnchanged();
}
@@ -9887,11 +9894,6 @@
|| isPasswordInputType(getInputType());
if (forAutoFill) {
structure.setSanitized(mTextFromResource);
- if (mAutoFillChangeWatcher == null && isTextEditable()) {
- mAutoFillChangeWatcher = new AutoFillChangeWatcher();
- addTextChangedListener(mAutoFillChangeWatcher);
- // TODO(b/33197203): remove mAutoFillValueListener auto-fill session is finished
- }
}
if (!isPassword || forAutoFill) {
@@ -11524,30 +11526,6 @@
}
}
- // TODO(b/33197203): implements SpanWatcher too?
- private final class AutoFillChangeWatcher implements TextWatcher {
-
- private final AutoFillManager mAfm = mContext.getSystemService(AutoFillManager.class);
-
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
-
- @Override
- public void afterTextChanged(Editable s) {
- if (mAfm != null) {
- if (DEBUG_AUTOFILL) {
- Log.v(LOG_TAG, "AutoFillChangeWatcher.afterTextChanged(): s=" + s);
- }
- mAfm.valueChanged(TextView.this);
- }
- }
- }
-
private class ChangeWatcher implements TextWatcher, SpanWatcher {
private CharSequence mBeforeText;