Merge "Update Autofill sample to use new API instead of deprecated APIs." into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-03 08:05:00 +00:00
committed by Android (Google) Code Review
2 changed files with 30 additions and 16 deletions

View File

@@ -23,6 +23,7 @@ import android.service.autofill.FillCallback;
import android.service.autofill.FillRequest;
import android.service.autofill.FillResponse;
import android.service.autofill.InlinePresentation;
import android.service.autofill.Presentations;
import android.service.autofill.SaveCallback;
import android.service.autofill.SaveInfo;
import android.service.autofill.SaveRequest;
@@ -95,14 +96,17 @@ public class InlineFillService extends AutofillService {
InlinePresentation inlinePresentation =
InlineRequestHelper.maybeCreateInlineAuthenticationResponse(context,
inlineRequest);
final Presentations.Builder fieldPresentationsBuilder =
new Presentations.Builder();
fieldPresentationsBuilder.setMenuPresentation(presentation);
fieldPresentationsBuilder.setInlinePresentation(inlinePresentation);
response = new FillResponse.Builder()
.setAuthentication(ids, authentication, presentation, inlinePresentation)
.setAuthentication(ids, authentication, fieldPresentationsBuilder.build())
.build();
} else {
response = createResponse(this, fields, maxSuggestionsCount, mAuthenticateDatasets,
inlineRequest);
}
callback.onSuccess(response);
}

View File

@@ -21,7 +21,9 @@ import static com.example.android.inlinefillservice.InlineFillService.TAG;
import android.content.Context;
import android.content.IntentSender;
import android.service.autofill.Dataset;
import android.service.autofill.Field;
import android.service.autofill.InlinePresentation;
import android.service.autofill.Presentations;
import android.util.Log;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
@@ -51,21 +53,24 @@ class ResponseHelper {
Log.d(TAG, "hint: " + hint);
final String displayValue = hint.contains("password") ? "password for #" + (index + 1)
: value;
final RemoteViews presentation = newDatasetPresentation(packageName, displayValue);
// Add Inline Suggestion required info.
Field.Builder fieldBuilder = new Field.Builder();
fieldBuilder.setValue(AutofillValue.forText(value));
// Set presentation
final Presentations.Builder fieldPresentationsBuilder =
new Presentations.Builder();
final RemoteViews presentation = newDatasetPresentation(packageName, displayValue);
fieldPresentationsBuilder.setMenuPresentation(presentation);
if (inlineRequest.isPresent()) {
Log.d(TAG, "Found InlineSuggestionsRequest in FillRequest: " + inlineRequest);
final InlinePresentation inlinePresentation =
InlineRequestHelper.createInlineDataset(context, inlineRequest.get(),
displayValue, index);
dataset.setValue(id, AutofillValue.forText(value), presentation,
inlinePresentation);
} else {
dataset.setValue(id, AutofillValue.forText(value), presentation);
InlineRequestHelper.createInlineDataset(context, inlineRequest.get(),
displayValue, index);
fieldPresentationsBuilder.setInlinePresentation(inlinePresentation);
}
fieldBuilder.setPresentations(fieldPresentationsBuilder.build());
dataset.setField(id, fieldBuilder.build());
}
return dataset.build();
}
@@ -84,16 +89,21 @@ class ResponseHelper {
IntentSender authentication =
AuthActivity.newIntentSenderForDataset(context, unlockedDataset);
RemoteViews presentation = newDatasetPresentation(packageName, displayValue);
Field.Builder fieldBuilder = new Field.Builder();
fieldBuilder.setValue(AutofillValue.forText(value));
final Presentations.Builder fieldPresentationsBuilder =
new Presentations.Builder();
fieldPresentationsBuilder.setMenuPresentation(presentation);
if (inlineRequest.isPresent()) {
final InlinePresentation inlinePresentation =
InlineRequestHelper.createInlineDataset(context, inlineRequest.get(),
displayValue, index);
lockedDataset.setValue(id, null, presentation, inlinePresentation)
.setAuthentication(authentication);
} else {
lockedDataset.setValue(id, null, presentation)
.setAuthentication(authentication);
fieldPresentationsBuilder.setInlinePresentation(inlinePresentation);
}
fieldBuilder.setPresentations(fieldPresentationsBuilder.build());
lockedDataset.setField(id, fieldBuilder.build());
lockedDataset.setId(null).setAuthentication(authentication);
}
return lockedDataset.build();
}