summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2022-05-03 09:10:04 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-05-03 09:10:04 +0000
commitfec95a19af1cebe487c6777b54f856d29326fac5 (patch)
tree0d1eb8186223a28c20f3cc8bb8e48af9991ad8c7
parent8964677e3a099778b5af99129bd75e8a3b23093a (diff)
parent4cb200dfb1f3b02beebddc5b4b50221f1f79dd60 (diff)
downloaddevelopment-fec95a19af1cebe487c6777b54f856d29326fac5.tar.gz
Merge "Update Autofill sample to use new API instead of deprecated APIs." into tm-dev am: 4cb200dfb1
Original change: https://googleplex-android-review.googlesource.com/c/platform/development/+/18058628 Change-Id: I3f13d723d47d6b8202e73c0de8e13a5877850bd6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--samples/InlineFillService/src/com/example/android/inlinefillservice/InlineFillService.java8
-rw-r--r--samples/InlineFillService/src/com/example/android/inlinefillservice/ResponseHelper.java38
2 files changed, 30 insertions, 16 deletions
diff --git a/samples/InlineFillService/src/com/example/android/inlinefillservice/InlineFillService.java b/samples/InlineFillService/src/com/example/android/inlinefillservice/InlineFillService.java
index 27e6d2f77..cce61378f 100644
--- a/samples/InlineFillService/src/com/example/android/inlinefillservice/InlineFillService.java
+++ b/samples/InlineFillService/src/com/example/android/inlinefillservice/InlineFillService.java
@@ -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);
}
diff --git a/samples/InlineFillService/src/com/example/android/inlinefillservice/ResponseHelper.java b/samples/InlineFillService/src/com/example/android/inlinefillservice/ResponseHelper.java
index 59fb0cd75..f6e6ab7e8 100644
--- a/samples/InlineFillService/src/com/example/android/inlinefillservice/ResponseHelper.java
+++ b/samples/InlineFillService/src/com/example/android/inlinefillservice/ResponseHelper.java
@@ -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();
}