Google is committed to advancing racial equity for Black communities. See how.

InlineSuggestionUi

public final class InlineSuggestionUi
extends Object

java.lang.Object
   ↳ androidx.autofill.inline.v1.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 InlineSuggestionUi.Content.Builder.build() for the conditions.

A default theme will be applied on the UI. The client can use InlineSuggestionUi.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 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 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 classes

class InlineSuggestionUi.Content

Content for the V1 inline suggestion UI. 

class InlineSuggestionUi.Style

Style for the V1 inline suggestion UI. 

Public methods

static InlineSuggestionUi.Content.Builder newContentBuilder(PendingIntent attributionIntent)

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

static InlineSuggestionUi.Style.Builder newStyleBuilder()

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

Inherited methods

Public methods

newContentBuilder

public static InlineSuggestionUi.Content.Builder newContentBuilder (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 PendingIntent.cancel(), or reusing them for the next set of suggestions. Intents are safe to cleanup on receiving a new AutofillService.onFillRequestnull call.

Parameters
attributionIntent PendingIntent: invoked when the UI is long-pressed.

Returns
InlineSuggestionUi.Content.Builder

newStyleBuilder

public static InlineSuggestionUi.Style.Builder newStyleBuilder ()

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

Returns
InlineSuggestionUi.Style.Builder