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

# Builder

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/android/service/autofill/CustomDescription.Builder "View this page in Java")

```
class Builder
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.service.autofill.CustomDescription.Builder](https://developer.android.com/reference/kotlin/android/service/autofill/CustomDescription.Builder#) |

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

## Summary

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

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

## Public constructors

### Builder

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

```
Builder(parentPresentation: RemoteViews)
```

Default constructor.

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

| Parameters ||
|---|---|
| `parentPresentation` | [RemoteViews](https://developer.android.com/reference/kotlin/android/widget/RemoteViews.html#): template presentation with (optional) children views. This value cannot be `null`. |

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

## Public methods

### addChild

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

```
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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): view id of the children view. |
| `transformation` | [Transformation](https://developer.android.com/reference/kotlin/android/service/autofill/Transformation): an implementation provided by the Android System. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/service/autofill/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 `https://developer.android.com/reference/kotlin/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.html#ApiLevels)

```
open fun addOnClickAction(
    id: Int, 
    action: OnClickAction
): CustomDescription.Builder
```

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

```kotlin
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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): resource id of the child view. |
| `action` | [OnClickAction](https://developer.android.com/reference/kotlin/android/service/autofill/OnClickAction): action to be performed. Must be an an implementation provided by the Android System. This value cannot be `null`. |

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/service/autofill/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 `https://developer.android.com/reference/kotlin/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.html#ApiLevels)

```
open fun batchUpdate(
    condition: Validator, 
    updates: BatchUpdates
): CustomDescription.Builder
```

Updates the `https://developer.android.com/reference/kotlin/android/widget/RemoteViews.html#` 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/kotlin/android/service/autofill/CustomDescription.Builder#addChild(kotlin.Int,%20android.service.autofill.Transformation)` are applied to the children views.

For example, to make children views visible when fields are not empty:

```kotlin
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:

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

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/service/autofill/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 `https://developer.android.com/reference/kotlin/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.html#ApiLevels)

```
open fun build(): CustomDescription
```

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

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/service/autofill/CustomDescription` | This value cannot be `null`. |