Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7843f0a7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Added auto-fill listeners for RadioGroup and CompoundButton."

parents 00a3c935 5882c4f5
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.view.ViewDebug;
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 @@ public abstract class CompoundButton extends Button implements Checkable {
            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 @@ public abstract class CompoundButton extends Button implements Checkable {

    // 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 @@ public abstract class CompoundButton extends Button implements Checkable {

    @Override
    public AutoFillValue getAutoFillValue() {
        return isEnabled() ? null : AutoFillValue.forToggle(isChecked());
        return isEnabled() ? AutoFillValue.forToggle(isChecked()) : null;
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.util.AttributeSet;
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 @@ public class RadioGroup extends LinearLayout {
        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 @@ public class RadioGroup extends LinearLayout {

    // 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;
+10 −32
Original line number Diff line number Diff line
@@ -726,9 +726,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    // 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;
@@ -9112,6 +9109,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                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();
    }

@@ -9876,11 +9883,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                || 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) {
@@ -11507,30 +11509,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }

    // 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;
+17 −16
Original line number Diff line number Diff line
@@ -792,8 +792,8 @@ final class AutoFillManagerServiceImpl {
                return;
            }

            if ((flags & FLAG_VALUE_CHANGED) != 0 && value != null &&
                    !value.equals(viewState.mAutoFillValue)) {
            if ((flags & FLAG_VALUE_CHANGED) != 0) {
                if (value != null && !value.equals(viewState.mAutoFillValue)) {
                    viewState.mValueUpdated = true;

                    // Must check if this update was caused by auto-filling the view, in which
@@ -811,6 +811,7 @@ final class AutoFillManagerServiceImpl {

                    // Update the chooser UI
                    mUi.updateFillUi(value.coerceToString());
                }
                return;
            }