# InlineSuggestionUi

Artifact: [androidx.autofill:autofill](https://developer.android.com/jetpack/androidx/releases/autofill) [View Source](https://cs.android.com/search?q=file:androidx/autofill/inline/v1/InlineSuggestionUi.java+class:androidx.autofill.inline.v1.InlineSuggestionUi) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/autofill#1.1.0)

*** ** * ** ***


```
@RequiresApi(api = Build.VERSION_CODES.R)
public final class InlineSuggestionUi
```

<br />

*** ** * ** ***

The entry point for building the content or style for the V1 inline suggestion UI.

The V1 UI composes of four widgets, put in order in a horizontal linear layout: start icon, title, subtitle, and end icon. Some of the widgets are optional, or conditionally optional based on existence of other widgets. See `https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Content.Builder#build()` for the conditions.

A default theme will be applied on the UI. The client can use `https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Style` to customize the style for individual widgets as well as the overall UI background.

For Autofill provider developer, to build a content `https://developer.android.com/reference/android/app/slice/Slice.html` that can be used as input to the `https://developer.android.com/reference/android/service/autofill/InlinePresentation.html`, you may use the `https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Content.Builder`. For example:

```
  public Slice createSlice(
      InlinePresentationSpec imeSpec,
      CharSequence title,
      CharSequence subtitle,
      Icon startIcon,
      Icon endIcon,
      CharSequence contentDescription,
      PendingIntent attribution) {
    // Make sure that the IME spec claims support for v1 UI template.
    Bundle imeStyle = imeSpec.getStyle();
    if (!UiVersions.getVersions(imeStyle).contains(UiVersions.INLINE_UI_VERSION_1)) {
      return null;
    }

    // Build the content for the v1 UI.
    Content.Builder builder =
        InlineSuggestionUi.newContentBuilder(attribution)
          .setContentDescription(contentDescription);
    if(!TextUtils.isEmpty(title)) {
      builder.setTitle(title);
    }
    if (!TextUtils.isEmpty(subtitle)) {
      builder.setSubtitle(subtitle);
    }
    if (startIcon != null) {
      startIcon.setTintBlendMode(BlendMode.DST)
      builder.setStartIcon(startIcon);
    }
    if (endIcon != null) {
      builder.setEndIcon(endIcon);
    }
    return builder.build().getSlice();
  }
```

For IME developer, to build a styles `https://developer.android.com/reference/android/os/Bundle.html` that can be used as input to the `https://developer.android.com/reference/android/widget/inline/InlinePresentationSpec.html`, you may use the `https://developer.android.com/reference/androidx/autofill/inline/UiVersions.StylesBuilder`. For example:

```
  public Bundle createBundle(Bundle uiExtras) {
    // We have styles builder, because it's possible that the IME can support multiple UI
    // templates in the future.
    StylesBuilder stylesBuilder = UiVersions.newStylesBuilder();

    // Assuming we only want to support v1 UI template. If the provided uiExtras doesn't contain
    // v1, then return null.
    if (!UiVersions.getVersions(uiExtras).contains(UiVersions.INLINE_UI_VERSION_1)) {
      return null;
    }

    // Create the style for v1 template.
    Style style = InlineSuggestionUi.newStyleBuilder()
        .setSingleIconChipStyle(
            new ViewStyle.Builder()
                .setBackgroundColor(Color.TRANSPARENT)
                .setPadding(0, 0, 0, 0)
                .setLayoutMargin(0, 0, 0, 0)
                .build())
        .setSingleIconChipIconStyle(
            new ImageViewStyle.Builder()
                .setMaxWidth(actionIconSize)
                .setMaxHeight(actionIconSize)
                .setScaleType(ScaleType.FIT_CENTER)
                .setLayoutMargin(0, 0, pinnedActionMarginEnd, 0)
                .setTintList(actionIconColor)
                .build())
        .setChipStyle(
            new ViewStyle.Builder()
                .setBackground(
                    Icon.createWithResource(this, R.drawable.chip_background))
                .setPadding(toPixel(13), 0, toPixel(13), 0)
                .build())
        .setStartIconStyle(
            new ImageViewStyle.Builder()
                .setLayoutMargin(0, 0, 0, 0)
                .setTintList(chipIconColor)
                .build())
        .setTitleStyle(
            new TextViewStyle.Builder()
                .setLayoutMargin(toPixel(4), 0, toPixel(4), 0)
                .setTextColor(Color.parseColor("#FF202124"))
                .setTextSize(16)
                .build())
        .setSubtitleStyle(
            new TextViewStyle.Builder()
                .setLayoutMargin(0, 0, toPixel(4), 0)
                .setTextColor(Color.parseColor("#99202124")) // 60% opacity
                .setTextSize(14)
                .build())
        .setEndIconStyle(
            new ImageViewStyle.Builder()
                .setLayoutMargin(0, 0, 0, 0)
                .setTintList(chipIconColor)
                .build())
        .build();

    // Add v1 UI style to the supported styles and return.
    stylesBuilder.addStyle(style);
    Bundle stylesBundle = stylesBuilder.build();
    return stylesBundle;
  }
```

Alternatively, if the IME wants to use the default style, then:

```
  public Bundle createBundle(Bundle uiExtras) {
    if (!UiVersions.getVersions(uiExtras).contains(UiVersions.INLINE_UI_VERSION_1)) {
      return null;
    }
    StylesBuilder stylesBuilder = UiVersions.newStylesBuilder();
    stylesBuilder.addStyle(InlineSuggestionUi.newStyleBuilder().build());
    return stylesBuilder.build();
  }
```

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Content implements https://developer.android.com/reference/androidx/autofill/inline/UiVersions.Content` Content for the V1 inline suggestion UI. |
| `public final class https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Content.Builder` Builder for the `https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Content`. |
| `public final class https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Style implements https://developer.android.com/reference/androidx/autofill/inline/UiVersions.Style` Style for the V1 inline suggestion UI. |
| `public final class https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Style.Builder` Builder for the `https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Style`. |

| ### Public methods |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Content.Builder` | `https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi#newContentBuilder(android.app.PendingIntent)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/PendingIntent.html attributionIntent)` Returns a builder to build the content for V1 inline suggestion UI. |
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi.Style.Builder` | `https://developer.android.com/reference/androidx/autofill/inline/v1/InlineSuggestionUi#newStyleBuilder()()` Returns a builder to build the style for V1 inline suggestion UI. |

## Public methods

### newContentBuilder

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/autofill#1.1.0)

```
public static @NonNull InlineSuggestionUi.Content.Builder newContentBuilder(@NonNull PendingIntent attributionIntent)
```

Returns a builder to build the content for V1 inline suggestion UI.

**Important Note:** The `https://developer.android.com/reference/android/service/autofill/AutofillService.html` is responsible for keeping track of the `https://developer.android.com/reference/android/app/PendingIntent.html` attribution intents it has used and cleaning them up properly with `https://developer.android.com/reference/android/app/PendingIntent.html#cancel()`, or reusing them for the next set of suggestions. Intents are safe to cleanup on receiving a new `https://developer.android.com/reference/android/service/autofill/AutofillService.html#onFillRequest(android.service.autofill.FillRequest, android.os.CancellationSignal, android.service.autofill.FillCallback)` call.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/PendingIntent.html attributionIntent` | invoked when the UI is long-pressed. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/autofill/inline/Renderer#getAttributionIntent(android.app.slice.Slice)` |   |

### newStyleBuilder

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/autofill#1.1.0)

```
public static @NonNull InlineSuggestionUi.Style.Builder newStyleBuilder()
```

Returns a builder to build the style for V1 inline suggestion UI.