Added in [API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#pubctors) \| [Methods](https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#inhmethods)

# CustomDescription.Builder

*** ** * ** ***


`
public
static


class
CustomDescription.Builder
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.service.autofill.CustomDescription.Builder |

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/android/service/autofill/CustomDescription` objects.

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#Builder(android.widget.RemoteViews)(https://developer.android.com/reference/android/widget/RemoteViews parentPresentation) ` Default constructor. |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder` | ` https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#addChild(int,%20android.service.autofill.Transformation)(int id, https://developer.android.com/reference/android/service/autofill/Transformation transformation) ` Adds a transformation to replace the value of a child view with the fields in the screen. |
| ` https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder` | ` https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#addOnClickAction(int,%20android.service.autofill.OnClickAction)(int id, https://developer.android.com/reference/android/service/autofill/OnClickAction action) ` Sets an action to be applied to the `https://developer.android.com/reference/android/widget/RemoteViews` when the child view with the given `id` is clicked. |
| ` https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder` | ` https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#batchUpdate(android.service.autofill.Validator,%20android.service.autofill.BatchUpdates)(https://developer.android.com/reference/android/service/autofill/Validator condition, https://developer.android.com/reference/android/service/autofill/BatchUpdates updates) ` Updates the `https://developer.android.com/reference/android/widget/RemoteViews` when a condition is satisfied by applying a series of remote view operations. |
| ` https://developer.android.com/reference/android/service/autofill/CustomDescription` | ` https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#build()() ` Creates a new `https://developer.android.com/reference/android/service/autofill/CustomDescription` instance. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


## Public constructors

### Builder

Added in [API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Builder (RemoteViews parentPresentation)
```

Default constructor.

**Note:** If any child view of presentation triggers a
`https://developer.android.com/reference/android/widget/RemoteViews#setOnClickPendingIntent(int,%20android.app.PendingIntent)`, such `https://developer.android.com/reference/android/app/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 `https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE` flag.
- It must be a PendingIntent for an `https://developer.android.com/reference/android/app/Activity`.
- The activity must call `https://developer.android.com/reference/android/app/Activity#finish()` when done.
- The activity should not launch other activities.

<br />

<br />

| Parameters ||
|---|---|
| `parentPresentation` | `RemoteViews`: template presentation with (optional) children views. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException` | if `parentPresentation` is null (on Android `https://developer.android.com/reference/android/os/Build.VERSION_CODES#P` or higher). |

## Public methods

### addChild

Added in [API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CustomDescription.Builder addChild (int id, 
                Transformation transformation)
```

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.

<br />

| Parameters ||
|---|---|
| `id` | `int`: view id of the children view. <br /> |
| `transformation` | `Transformation`: an implementation provided by the Android System. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder` | this builder. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `transformation` is not a class provided by the Android System. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if `https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#build()` was already called. |

### addOnClickAction

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CustomDescription.Builder addOnClickAction (int id, 
                OnClickAction action)
```

Sets an action to be applied to the `https://developer.android.com/reference/android/widget/RemoteViews` 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.

<br />

| Parameters ||
|---|---|
| `id` | `int`: resource id of the child view. <br /> |
| `action` | `OnClickAction`: action to be performed. Must be an an implementation provided by the Android System. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder` | this builder. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `action` is not a class provided by the Android System. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if `https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#build()` was already called. |

### batchUpdate

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CustomDescription.Builder batchUpdate (Validator condition, 
                BatchUpdates updates)
```

Updates the `https://developer.android.com/reference/android/widget/RemoteViews` 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
`https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#addChild(int,%20android.service.autofill.Transformation)` 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();
```

<br />

<br />

| Parameters ||
|---|---|
| `condition` | `Validator`: condition used to trigger the updates. This value cannot be `null`. <br /> |
| `updates` | `BatchUpdates`: actions to be applied to the `https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#Builder(android.widget.RemoteViews)` when the condition is satisfied. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder` | this builder. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if `condition` is not a class provided by the Android System. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if `https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder#build()` was already called. |

### build

Added in [API level 27](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CustomDescription build ()
```

Creates a new `https://developer.android.com/reference/android/service/autofill/CustomDescription` instance.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/autofill/CustomDescription` | This value cannot be `null`. <br /> |