InlineSuggestionUi

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


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 build for the conditions.

A default theme will be applied on the UI. The client can use Style to customize the style for individual widgets as well as the overall UI background.

For Autofill provider developer, to build a content Slice that can be used as input to the android.service.autofill.InlinePresentation, you may use the 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 Bundle that can be used as input to the android.widget.inline.InlinePresentationSpec, you may use the 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 InlineSuggestionUi.Content implements UiVersions.Content

Content for the V1 inline suggestion UI.

Builder for the Content.

public final class InlineSuggestionUi.Style implements UiVersions.Style

Style for the V1 inline suggestion UI.

Builder for the Style.

Public methods

static @NonNull InlineSuggestionUi.Content.Builder

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

static @NonNull InlineSuggestionUi.Style.Builder

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

Public methods

newContentBuilder

Added in 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 AutofillService is responsible for keeping track of the PendingIntent attribution intents it has used and cleaning them up properly with cancel, or reusing them for the next set of suggestions. Intents are safe to cleanup on receiving a new onFillRequest call.

Parameters
@NonNull PendingIntent attributionIntent

invoked when the UI is long-pressed.

newStyleBuilder

Added in 1.1.0
public static @NonNull InlineSuggestionUi.Style.Builder newStyleBuilder()

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