diff --git a/samples/InlineFillService/AndroidManifest.xml b/samples/InlineFillService/AndroidManifest.xml index c08ca855d..29e60da8b 100644 --- a/samples/InlineFillService/AndroidManifest.xml +++ b/samples/InlineFillService/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="foo.bar.inline" > presentationSpecs = - inlineRequest.getPresentationSpecs(); - final int specsSize = presentationSpecs.size(); - - InlinePresentationSpec currentSpecs = presentationSpecs.get(0); - for (int i = 1; i <= maxSuggestionsCount; i++) { - if (currentSpecs == null) { - break; - } - - if (i < specsSize) { - currentSpecs = presentationSpecs.get(i); - } - - final Uri uri = new Uri.Builder().appendPath("BasicService-" + i).build(); - final ArrayList autofillHints = new ArrayList<>(); - autofillHints.add(fields.keyAt(0)); - final Slice suggestionSlice = new Slice.Builder(uri, - new SliceSpec("InlineSuggestion", 1)) - .addInt(currentSpecs.getMinSize().getWidth(), "SUBTYPE_MIN_WIDTH", - Collections.EMPTY_LIST) - .addInt(currentSpecs.getMaxSize().getWidth(), "SUBTYPE_MAX_WIDTH", - Collections.EMPTY_LIST) - .addInt(currentSpecs.getMinSize().getHeight(), "SUBTYPE_MIN_HEIGHT", - Collections.EMPTY_LIST) - .addInt(currentSpecs.getMaxSize().getHeight(), "SUBTYPE_MAX_HEIGHT", - Collections.EMPTY_LIST) - .addHints(autofillHints) - .build(); - response.addInlineSuggestionSlice(suggestionSlice); - } - } - // 2.Add save info Collection ids = fields.values(); AutofillId[] requiredIds = new AutofillId[ids.size()]; @@ -149,19 +118,42 @@ public class InlineFillService extends AutofillService { } static Dataset newUnlockedDataset(@NonNull Map fields, - @NonNull String packageName, int i) { + @NonNull String packageName, int i, @Nullable InlineSuggestionsRequest inlineRequest) { + Dataset.Builder dataset = new Dataset.Builder(); for (Entry field : fields.entrySet()) { - String hint = field.getKey(); - AutofillId id = field.getValue(); - String value = hint + i; + final String hint = field.getKey(); + final AutofillId id = field.getValue(); + final String value = hint + i; // We're simple - our dataset values are hardcoded as "hintN" (for example, // "username1", "username2") and they're displayed as such, except if they're a // password - String displayValue = hint.contains("password") ? "password for #" + i : value; - RemoteViews presentation = newDatasetPresentation(packageName, displayValue); - dataset.setValue(id, AutofillValue.forText(value), presentation); + final String displayValue = hint.contains("password") ? "password for #" + i : value; + final RemoteViews presentation = newDatasetPresentation(packageName, displayValue); + + // Add Inline Suggestion required info. + InlinePresentation inlinePresentation = null; + if (inlineRequest != null) { + Log.d(TAG, "Found InlineSuggestionsRequest in FillRequest: " + inlineRequest); + + final Uri uri = new Uri.Builder().appendPath("BasicService-" + i).build(); + final ArrayList autofillHints = new ArrayList<>(); + autofillHints.add(hint); + final Slice suggestionSlice = new Slice.Builder(uri, + new SliceSpec("InlineSuggestion", 1)) + .addHints(autofillHints) + .build(); + + final List specs = inlineRequest.getPresentationSpecs(); + final int specsSize = specs.size(); + final InlinePresentationSpec currentSpec = i < specsSize + ? specs.get(i) + : specs.get(specsSize - 1); + inlinePresentation = new InlinePresentation(suggestionSlice, currentSpec); + } + + dataset.setValue(id, AutofillValue.forText(value), presentation, inlinePresentation); } return dataset.build();