method public android.view.animation.Animation getAnimation();
method public android.os.IBinder getApplicationWindowToken();
method public java.lang.String[] getAutofillHints();
+ method public final android.view.autofill.AutofillId getAutofillId();
method public int getAutofillType();
method public android.view.autofill.AutofillValue getAutofillValue();
method public android.graphics.drawable.Drawable getBackground();
method public abstract int addChildCount(int);
method public abstract void asyncCommit();
method public abstract android.view.ViewStructure asyncNewChild(int);
+ method public abstract android.view.autofill.AutofillId getAutofillId();
method public abstract int getChildCount();
method public abstract android.os.Bundle getExtras();
method public abstract java.lang.CharSequence getHint();
method public abstract void setActivated(boolean);
method public abstract void setAlpha(float);
method public abstract void setAutofillHints(java.lang.String[]);
- method public abstract void setAutofillId(android.view.ViewStructure, int);
+ method public abstract void setAutofillId(android.view.autofill.AutofillId);
+ method public abstract void setAutofillId(android.view.autofill.AutofillId, int);
method public abstract void setAutofillOptions(java.lang.CharSequence[]);
method public abstract void setAutofillType(int);
method public abstract void setAutofillValue(android.view.autofill.AutofillValue);
method public abstract void setTextLines(int[], int[]);
method public abstract void setTextStyle(float, int, int, int);
method public abstract void setTransformation(android.graphics.Matrix);
- method public abstract deprecated void setUrl(java.lang.String);
method public abstract void setVisibility(int);
method public abstract void setWebDomain(java.lang.String);
}
method public android.view.animation.Animation getAnimation();
method public android.os.IBinder getApplicationWindowToken();
method public java.lang.String[] getAutofillHints();
+ method public final android.view.autofill.AutofillId getAutofillId();
method public int getAutofillType();
method public android.view.autofill.AutofillValue getAutofillValue();
method public android.graphics.drawable.Drawable getBackground();
method public abstract int addChildCount(int);
method public abstract void asyncCommit();
method public abstract android.view.ViewStructure asyncNewChild(int);
+ method public abstract android.view.autofill.AutofillId getAutofillId();
method public abstract int getChildCount();
method public abstract android.os.Bundle getExtras();
method public abstract java.lang.CharSequence getHint();
method public abstract void setActivated(boolean);
method public abstract void setAlpha(float);
method public abstract void setAutofillHints(java.lang.String[]);
- method public abstract void setAutofillId(android.view.ViewStructure, int);
+ method public abstract void setAutofillId(android.view.autofill.AutofillId);
+ method public abstract void setAutofillId(android.view.autofill.AutofillId, int);
method public abstract void setAutofillOptions(java.lang.CharSequence[]);
method public abstract void setAutofillType(int);
method public abstract void setAutofillValue(android.view.autofill.AutofillValue);
method public abstract void setTextLines(int[], int[]);
method public abstract void setTextStyle(float, int, int, int);
method public abstract void setTransformation(android.graphics.Matrix);
- method public abstract deprecated void setUrl(java.lang.String);
method public abstract void setVisibility(int);
method public abstract void setWebDomain(java.lang.String);
}
method public android.view.animation.Animation getAnimation();
method public android.os.IBinder getApplicationWindowToken();
method public java.lang.String[] getAutofillHints();
+ method public final android.view.autofill.AutofillId getAutofillId();
method public int getAutofillType();
method public android.view.autofill.AutofillValue getAutofillValue();
method public android.graphics.drawable.Drawable getBackground();
method public abstract int addChildCount(int);
method public abstract void asyncCommit();
method public abstract android.view.ViewStructure asyncNewChild(int);
+ method public abstract android.view.autofill.AutofillId getAutofillId();
method public abstract int getChildCount();
method public abstract android.os.Bundle getExtras();
method public abstract java.lang.CharSequence getHint();
method public abstract void setActivated(boolean);
method public abstract void setAlpha(float);
method public abstract void setAutofillHints(java.lang.String[]);
- method public abstract void setAutofillId(android.view.ViewStructure, int);
+ method public abstract void setAutofillId(android.view.autofill.AutofillId);
+ method public abstract void setAutofillId(android.view.autofill.AutofillId, int);
method public abstract void setAutofillOptions(java.lang.CharSequence[]);
method public abstract void setAutofillType(int);
method public abstract void setAutofillValue(android.view.autofill.AutofillValue);
method public abstract void setTextLines(int[], int[]);
method public abstract void setTextStyle(float, int, int, int);
method public abstract void setTransformation(android.graphics.Matrix);
- method public abstract deprecated void setUrl(java.lang.String);
method public abstract void setVisibility(int);
method public abstract void setWebDomain(java.lang.String);
}
@Override
public void setAutofillId(@NonNull ViewStructure parent, int virtualId) {
- mNode.mAutofillId = new AutofillId(parent.getAutofillId(), virtualId);
+ setAutofillId(parent.getAutofillId(), virtualId);
}
@Override
}
@Override
- public void setAutofillId(int viewId) {
- mNode.mAutofillId = new AutofillId(viewId);
+ public void setAutofillId(@NonNull AutofillId id) {
+ mNode.mAutofillId = id;
+ }
+
+ @Override
+ public void setAutofillId(@NonNull AutofillId parentId, int virtualId) {
+ mNode.mAutofillId = new AutofillId(parentId, virtualId);
}
@Override
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Transformation;
+import android.view.autofill.AutofillId;
import android.view.autofill.AutofillManager;
import android.view.autofill.AutofillValue;
import android.view.inputmethod.EditorInfo;
public static final String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay";
/**
- * Hintd for the autofill services that describes the content of the view.
+ * Hints for the autofill services that describes the content of the view.
*/
private @Nullable String[] mAutofillHints;
+ /**
+ * Autofill id, lazily created on calls to {@link #getAutofillId()}.
+ */
+ private AutofillId mAutofillId;
+
/** @hide */
@IntDef({
AUTOFILL_TYPE_NONE,
*
* <p>This method already provides most of what's needed for autofill, but should be overridden
* when:
- * <ol>
- * <li>The view contents does not include PII (Personally Identifiable Information), so it
+ * <ul>
+ * <li>The view contents does not include PII (Personally Identifiable Information), so it
* can call {@link ViewStructure#setDataIsSensitive(boolean)} passing {@code false}.
- * <li>It must set fields such {@link ViewStructure#setText(CharSequence)},
+ * <li>It must set fields such {@link ViewStructure#setText(CharSequence)},
* {@link ViewStructure#setAutofillOptions(CharSequence[])},
- * or {@link ViewStructure#setUrl(String)}.
- * </ol>
+ * or {@link ViewStructure#setWebDomain(String)}.
+ * </ul>
*
* @param structure Fill in with structured view data. The default implementation
* fills in all data that can be inferred from the view itself.
onProvideStructureForAssistOrAutofill(structure, true);
}
- private void setAutofillId(ViewStructure structure) {
- // The autofill id needs to be unique, but its value doesn't matter,
- // so it's better to reuse the accessibility id to save space.
- structure.setAutofillId(getAccessibilityViewId());
- }
-
private void onProvideStructureForAssistOrAutofill(ViewStructure structure,
boolean forAutofill) {
final int id = mID;
}
if (forAutofill) {
- setAutofillId(structure);
final @AutofillType int autofillType = getAutofillType();
// Don't need to fill autofill info if view does not support it.
// For example, only TextViews that are editable support autofill
* @param flags optional flags (currently {@code 0}).
*/
public void onProvideAutofillVirtualStructure(ViewStructure structure, int flags) {
- // TODO(b/36171235): need a way to let apps set the ViewStructure without forcing them
- // to call super() (in case they override both this method and dispatchProvide....
- // Perhaps the best solution would simply make setAutofillId(ViewStructure) public.
- setAutofillId(structure);
}
/**
}
/**
+ * Gets the unique identifier of this view on the screen for Autofill purposes.
+ *
+ * @return The View's Autofill id.
+ */
+ public final AutofillId getAutofillId() {
+ if (mAutofillId == null) {
+ // The autofill id needs to be unique, but its value doesn't matter,
+ // so it's better to reuse the accessibility id to save space.
+ mAutofillId = new AutofillId(getAccessibilityViewId());
+ }
+ return mAutofillId;
+ }
+
+ /**
* Describes the autofill type that should be used on calls to
* {@link #autofill(AutofillValue)} and {@link #autofill(SparseArray)}.
*
/**
* Dispatch creation of {@link ViewStructure} down the hierarchy.
*
- * <p>The structure must be filled according to the request type, which is set in the
- * {@code flags} parameter - see the documentation on each flag for more details.
+ * <p>The default implementation does the following:
+ *
+ * <ul>
+ * <li>Sets the {@link AutofillId} in the structure.
+ * <li>Calls {@link #onProvideAutofillStructure(ViewStructure, int)}.
+ * <li>Calls {@link #onProvideAutofillVirtualStructure(ViewStructure, int)}.
+ * </ul>
*
- * <p>The default implementation calls {@link #onProvideAutofillStructure(ViewStructure, int)}
- * and {@link #onProvideAutofillVirtualStructure(ViewStructure, int)}.
+ * <p>When overridden, it must either call
+ * {@code super.dispatchProvideAutofillStructure(structure, flags)} or explicitly
+ * set the {@link AutofillId} in the structure (for example, by calling
+ * {@code structure.setAutofillId(getAutofillId())}).
*
* @param structure Fill in with structured view data.
* @param flags optional flags (currently {@code 0}).
*/
- public void dispatchProvideAutofillStructure(ViewStructure structure, int flags) {
+ public void dispatchProvideAutofillStructure(@NonNull ViewStructure structure, int flags) {
dispatchProvideStructureForAssistOrAutofill(structure, true);
}
boolean blocked = forAutofill ? isAutofillBlocked() : isAssistBlocked();
if (!blocked) {
if (forAutofill) {
- setAutofillId(structure);
+ structure.setAutofillId(getAutofillId());
// NOTE: flags are not currently supported, hence 0
onProvideAutofillStructure(structure, 0);
onProvideAutofillVirtualStructure(structure, 0);
public abstract ViewStructure asyncNewChild(int index);
/**
+ * Gets the {@link AutofillId} associated with this node.
+ */
+ @Nullable
+ public abstract AutofillId getAutofillId();
+
+ /**
+ * Sets the {@link AutofillId} associated with this node.
+ */
+ public abstract void setAutofillId(@NonNull AutofillId id);
+
+ /**
* Sets the {@link AutofillId} for this virtual node.
*
- * @param parent parent node.
+ * @param parentId id of the parent node.
* @param virtualId an opaque ID to the Android System; it's the same id used on
* {@link View#autofill(android.util.SparseArray)}.
*/
+ public abstract void setAutofillId(@NonNull AutofillId parentId, int virtualId);
+
+ /**
+ * @deprecated - use {@link #setAutofillId(AutofillId, int)} instead
+ * @hide
+ */
+ @Deprecated
public abstract void setAutofillId(@NonNull ViewStructure parent, int virtualId);
/**
/** @hide */
public abstract Rect getTempRect();
- /** @hide */
- public abstract void setAutofillId(int viewId);
-
- /** @hide */
- public abstract AutofillId getAutofillId();
-
/**
* @deprecated - use {@link #setWebDomain(String)} instead.
+ * @hide
*/
@Deprecated
public abstract void setUrl(String url);
// This view is self-sufficient for autofill, so it needs to call
// onProvideAutoFillStructure() to fill itself, but it does not need to call
// dispatchProvideAutoFillStructure() to fill its children.
+ structure.setAutofillId(getAutofillId());
onProvideAutofillStructure(structure, flags);
}
// This view is self-sufficient for autofill, so it needs to call
// onProvideAutoFillStructure() to fill itself, but it does not need to call
// dispatchProvideAutoFillStructure() to fill its children.
+ structure.setAutofillId(getAutofillId());
onProvideAutofillStructure(structure, flags);
}