Builder
class Builder
kotlin.Any | |
↳ | android.service.autofill.CustomDescription.Builder |
Builder for CustomDescription
objects.
Summary
Public constructors | |
---|---|
Builder(parentPresentation: RemoteViews) Default constructor. |
Public methods | |
---|---|
open CustomDescription.Builder |
addChild(id: Int, transformation: Transformation) Adds a transformation to replace the value of a child view with the fields in the screen. |
open CustomDescription.Builder |
addOnClickAction(id: Int, action: OnClickAction) Sets an action to be applied to the |
open CustomDescription.Builder |
batchUpdate(condition: Validator, updates: BatchUpdates) Updates the |
open CustomDescription |
build() Creates a new |
Public constructors
Builder
Builder(parentPresentation: RemoteViews)
Default constructor.
Note: If any child view of presentation triggers a on click
, such PendingIntent
must follow the restrictions below, otherwise it might not be triggered or the autofill save UI might not be shown when its activity is finished:
- It cannot be created with the
PendingIntent#FLAG_IMMUTABLE
flag. - It must be a PendingIntent for an
Activity
. - The activity must call
Activity#finish()
when done. - The activity should not launch other activities.
Parameters | |
---|---|
parentPresentation |
RemoteViews: template presentation with (optional) children views. This value cannot be null . |
Exceptions | |
---|---|
java.lang.NullPointerException |
if parentPresentation is null (on Android android.os.Build.VERSION_CODES#P or higher). |
Public methods
addChild
open fun addChild(
id: Int,
transformation: Transformation
): CustomDescription.Builder
Adds a transformation to replace the value of a child view with the fields in the screen.
When multiple transformations are added for the same child view, they will be applied in the same order as added.
Parameters | |
---|---|
id |
Int: view id of the children view. |
transformation |
Transformation: an implementation provided by the Android System. This value cannot be null . |
Return | |
---|---|
CustomDescription.Builder |
this builder. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if transformation is not a class provided by the Android System. |
java.lang.IllegalStateException |
if build() was already called. |
addOnClickAction
open fun addOnClickAction(
id: Int,
action: OnClickAction
): CustomDescription.Builder
Sets an action to be applied to the presentation template
when the child view with the given id
is clicked.
Typically used when the presentation uses a masked field (like ****
) for sensitive fields like passwords or credit cards numbers, but offers a an icon that the user can tap to show the value for that field.
Example:
customDescriptionBuilder .addChild(R.id.password_plain, new CharSequenceTransformation .Builder(passwordId, Pattern.compile("^(.*)$"), "$1").build()) .addOnClickAction(R.id.showIcon, new VisibilitySetterAction .Builder(R.id.hideIcon, View.VISIBLE) .setVisibility(R.id.showIcon, View.GONE) .setVisibility(R.id.password_plain, View.VISIBLE) .setVisibility(R.id.password_masked, View.GONE) .build()) .addOnClickAction(R.id.hideIcon, new VisibilitySetterAction .Builder(R.id.showIcon, View.VISIBLE) .setVisibility(R.id.hideIcon, View.GONE) .setVisibility(R.id.password_masked, View.VISIBLE) .setVisibility(R.id.password_plain, View.GONE) .build());
Note: Currently only one action can be applied to a child; if this method is called multiple times passing the same id
, only the last call will be used.
Parameters | |
---|---|
id |
Int: resource id of the child view. |
action |
OnClickAction: action to be performed. Must be an an implementation provided by the Android System. This value cannot be null . |
Return | |
---|---|
CustomDescription.Builder |
this builder This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if action is not a class provided by the Android System. |
java.lang.IllegalStateException |
if build() was already called. |
batchUpdate
open fun batchUpdate(
condition: Validator,
updates: BatchUpdates
): CustomDescription.Builder
Updates the presentation template
when a condition is satisfied by applying a series of remote view operations. This allows dynamic customization of the portion of the save UI that is controlled by the autofill service. Such dynamic customization is based on the content of target views.
The updates are applied in the sequence they are added, after the transformations
are applied to the children views.
For example, to make children views visible when fields are not empty:
RemoteViews template = new RemoteViews(pgkName, R.layout.my_full_template); Pattern notEmptyPattern = Pattern.compile(".+"); Validator hasAddress = new RegexValidator(addressAutofillId, notEmptyPattern); Validator hasCcNumber = new RegexValidator(ccNumberAutofillId, notEmptyPattern); RemoteViews addressUpdates = new RemoteViews(pgkName, R.layout.my_full_template) addressUpdates.setViewVisibility(R.id.address, View.VISIBLE); // Make address visible BatchUpdates addressBatchUpdates = new BatchUpdates.Builder() .updateTemplate(addressUpdates) .build(); RemoteViews ccUpdates = new RemoteViews(pgkName, R.layout.my_full_template) ccUpdates.setViewVisibility(R.id.cc_number, View.VISIBLE); // Mask credit card number (as .....LAST_4_DIGITS) and make it visible BatchUpdates ccBatchUpdates = new BatchUpdates.Builder() .updateTemplate(ccUpdates) .transformChild(R.id.templateCcNumber, new CharSequenceTransformation .Builder(ccNumberId, Pattern.compile("^.*(\\d\\d\\d\\d)$"), "...$1") .build()) .build(); CustomDescription customDescription = new CustomDescription.Builder(template) .batchUpdate(hasAddress, addressBatchUpdates) .batchUpdate(hasCcNumber, ccBatchUpdates) .build();
Another approach is to add a child first, then apply the transformations. Example:
RemoteViews template = new RemoteViews(pgkName, R.layout.my_base_template); RemoteViews addressPresentation = new RemoteViews(pgkName, R.layout.address) RemoteViews addressUpdates = new RemoteViews(pgkName, R.layout.my_template) addressUpdates.addView(R.id.parentId, addressPresentation); BatchUpdates addressBatchUpdates = new BatchUpdates.Builder() .updateTemplate(addressUpdates) .build(); RemoteViews ccPresentation = new RemoteViews(pgkName, R.layout.cc) RemoteViews ccUpdates = new RemoteViews(pgkName, R.layout.my_template) ccUpdates.addView(R.id.parentId, ccPresentation); BatchUpdates ccBatchUpdates = new BatchUpdates.Builder() .updateTemplate(ccUpdates) .transformChild(R.id.templateCcNumber, new CharSequenceTransformation .Builder(ccNumberId, Pattern.compile("^.*(\\d\\d\\d\\d)$"), "...$1") .build()) .build(); CustomDescription customDescription = new CustomDescription.Builder(template) .batchUpdate(hasAddress, addressBatchUpdates) .batchUpdate(hasCcNumber, ccBatchUpdates) .build();
Parameters | |
---|---|
condition |
Validator: condition used to trigger the updates. This value cannot be null . |
updates |
BatchUpdates: actions to be applied to the template presentation when the condition is satisfied. This value cannot be null . |
Return | |
---|---|
CustomDescription.Builder |
this builder This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if condition is not a class provided by the Android System. |
java.lang.IllegalStateException |
if build() was already called. |
build
open fun build(): CustomDescription
Creates a new CustomDescription
instance.
Return | |
---|---|
CustomDescription |
This value cannot be null . |