*/
public static final int SAVE_DATA_TYPE_EMAIL_ADDRESS = 0x10;
+ /**
+ * Style for the negative button of the save UI to cancel the
+ * save operation. In this case, the user tapping the negative
+ * button signals that they would prefer to not save the filled
+ * content.
+ */
+ public static final int NEGATIVE_BUTTON_STYLE_CANCEL = 0;
+
+ /**
+ * Style for the negative button of the save UI to reject the
+ * save operation. This could be useful if the user needs to
+ * opt-in your service and the save prompt is an advertisement
+ * of the potential value you can add to the user. In this
+ * case, the user tapping the negative button sends a strong
+ * signal that the feature may not be useful and you may
+ * consider some backoff strategy.
+ */
+ public static final int NEGATIVE_BUTTON_STYLE_REJECT = 1;
+
+ /** @hide */
+ @IntDef(
+ value = {
+ NEGATIVE_BUTTON_STYLE_CANCEL,
+ NEGATIVE_BUTTON_STYLE_REJECT})
+ @Retention(RetentionPolicy.SOURCE)
+ @interface NegativeButtonStyle{}
+
/** @hide */
@IntDef(
flag = true,
@interface SaveInfoFlags{}
private final @SaveDataType int mType;
- private final CharSequence mNegativeActionTitle;
+ private final @NegativeButtonStyle int mNegativeButtonStyle;
private final IntentSender mNegativeActionListener;
private final AutofillId[] mRequiredIds;
private final AutofillId[] mOptionalIds;
private SaveInfo(Builder builder) {
mType = builder.mType;
- mNegativeActionTitle = builder.mNegativeActionTitle;
+ mNegativeButtonStyle = builder.mNegativeButtonStyle;
mNegativeActionListener = builder.mNegativeActionListener;
mRequiredIds = builder.mRequiredIds;
mOptionalIds = builder.mOptionalIds;
}
/** @hide */
- public @Nullable CharSequence getNegativeActionTitle() {
- return mNegativeActionTitle;
+ public @NegativeButtonStyle int getNegativeActionStyle() {
+ return mNegativeButtonStyle;
}
/** @hide */
public static final class Builder {
private final @SaveDataType int mType;
- private CharSequence mNegativeActionTitle;
+ private @NegativeButtonStyle int mNegativeButtonStyle = NEGATIVE_BUTTON_STYLE_CANCEL;
private IntentSender mNegativeActionListener;
private final AutofillId[] mRequiredIds;
private AutofillId[] mOptionalIds;
return this;
}
+ /** @hide */
+ // TODO (b/37563972): Remove when callers migrate
+ public @NonNull Builder setNegativeAction(@Nullable CharSequence title,
+ @Nullable IntentSender listener) {
+ throwIfDestroyed();
+ setNegativeAction(NEGATIVE_BUTTON_STYLE_CANCEL, listener);
+ return this;
+ }
+
/**
- * Sets the title and listener for the negative save action.
+ * Sets the style and listener for the negative save action.
*
- * <p>This allows a fill-provider to customize the text and be
+ * <p>This allows a fill-provider to customize the style and be
* notified when the user selects the negative action in the save
- * UI. Note that selecting the negative action regardless of its text
+ * UI. Note that selecting the negative action regardless of its style
* and listener being customized would dismiss the save UI and if a
* custom listener intent is provided then this intent will be
- * started.</p>
- *
- * <p>This customization could be useful for providing additional
- * semantics to the negative action. For example, a fill-provider
- * can use this mechanism to add a "Disable" function or a "More info"
- * function, etc. Note that the save action is exclusively controlled
- * by the platform to ensure user consent is collected to release
- * data from the filled app to the fill-provider.</p>
+ * started. The default style is {@link #NEGATIVE_BUTTON_STYLE_CANCEL}</p>
*
- * @param title The action title.
+ * @param style The action style.
* @param listener The action listener.
* @return This builder.
*
- * @throws IllegalArgumentException If the title and the listener
- * are not both either null or non-null.
+ * @see #NEGATIVE_BUTTON_STYLE_CANCEL
+ * @see #NEGATIVE_BUTTON_STYLE_REJECT
+ *
+ * @throws IllegalArgumentException If the style is invalid
*/
- public @NonNull Builder setNegativeAction(@Nullable CharSequence title,
+ public @NonNull Builder setNegativeAction(@NegativeButtonStyle int style,
@Nullable IntentSender listener) {
throwIfDestroyed();
- if (title == null ^ listener == null) {
- throw new IllegalArgumentException("title and listener"
- + " must be both non-null or null");
+ if (style != NEGATIVE_BUTTON_STYLE_CANCEL
+ && style != NEGATIVE_BUTTON_STYLE_REJECT) {
+ throw new IllegalArgumentException("Invalid style: " + style);
}
- mNegativeActionTitle = title;
+ mNegativeButtonStyle = style;
mNegativeActionListener = listener;
return this;
}
.append(", requiredIds=").append(Arrays.toString(mRequiredIds))
.append(", optionalIds=").append(Arrays.toString(mOptionalIds))
.append(", description=").append(mDescription)
+ .append(DebugUtils.flagsToString(SaveInfo.class, "NEGATIVE_BUTTON_STYLE_",
+ mNegativeButtonStyle))
.append(", mFlags=").append(mFlags)
.append("]").toString();
}
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeInt(mType);
parcel.writeParcelableArray(mRequiredIds, flags);
- parcel.writeCharSequence(mNegativeActionTitle);
+ parcel.writeInt(mNegativeButtonStyle);
parcel.writeParcelable(mNegativeActionListener, flags);
parcel.writeParcelableArray(mOptionalIds, flags);
parcel.writeCharSequence(mDescription);
// using specially crafted parcels.
final Builder builder = new Builder(parcel.readInt(),
parcel.readParcelableArray(null, AutofillId.class));
- builder.setNegativeAction(parcel.readCharSequence(), parcel.readParcelable(null));
+ builder.setNegativeAction(parcel.readInt(), parcel.readParcelable(null));
builder.setOptionalIds(parcel.readParcelableArray(null, AutofillId.class));
builder.setDescription(parcel.readCharSequence());
builder.setFlags(parcel.readInt());