diff --git a/samples/InlineFillService/res/drawable/ic_settings.png b/samples/InlineFillService/res/drawable/ic_settings.png new file mode 100644 index 000000000..eaf1d4758 Binary files /dev/null and b/samples/InlineFillService/res/drawable/ic_settings.png differ diff --git a/samples/InlineFillService/src/foo/bar/inline/InlineFillService.java b/samples/InlineFillService/src/foo/bar/inline/InlineFillService.java index ac97bdaaa..2b688e8d0 100644 --- a/samples/InlineFillService/src/foo/bar/inline/InlineFillService.java +++ b/samples/InlineFillService/src/foo/bar/inline/InlineFillService.java @@ -35,6 +35,7 @@ import android.service.autofill.SaveInfo; import android.service.autofill.SaveRequest; import android.util.ArrayMap; import android.util.Log; +import android.util.Size; import android.view.autofill.AutofillId; import android.view.autofill.AutofillValue; import android.view.inline.InlinePresentationSpec; @@ -104,6 +105,15 @@ public class InlineFillService extends AutofillService { response.addDataset(unlockedDataset); } + if(inlineRequest != null) { + // Reuse the first spec's height for the inline action size, as there isn't dedicated + // value from the request for this. + final int height = inlineRequest.getPresentationSpecs().get(0).getMinSize().getHeight(); + final Size actionIconSize = new Size(height, height); + response.addInlineAction( + newInlineAction(context, actionIconSize, R.drawable.ic_settings)); + } + // 2.Add save info Collection ids = fields.values(); AutofillId[] requiredIds = new AutofillId[ids.size()]; @@ -116,6 +126,18 @@ public class InlineFillService extends AutofillService { return response.build(); } + static InlinePresentation newInlineAction(@NonNull Context context, + @NonNull Size size, int drawable) { + final Slice suggestionSlice = new Slice.Builder(Uri.parse("inline.slice"), + new SliceSpec("InlinePresentation", 1)) + .addIcon(Icon.createWithResource(context, drawable), null, + Collections.singletonList("")) + .build(); + final InlinePresentationSpec currentSpec = new InlinePresentationSpec.Builder(size, + size).build(); + return new InlinePresentation(suggestionSlice, currentSpec, /** pined= */ true); + } + static Dataset newUnlockedDataset(@NonNull Context context, @NonNull Map fields, @NonNull String packageName, int i, @Nullable InlineSuggestionsRequest inlineRequest) {