public static Dataset BuildDataset(Context context, FieldCollection fields, FilledItem filledItem, InlinePresentationSpec inlinePresentationSpec = null) { var overlayPresentation = BuildOverlayPresentation( filledItem.Name, filledItem.Subtitle, filledItem.Icon, context); var inlinePresentation = BuildInlinePresentation( inlinePresentationSpec, filledItem.Name, filledItem.Subtitle, filledItem.Icon, null, context); var datasetBuilder = new Dataset.Builder(overlayPresentation); if (inlinePresentation != null) { datasetBuilder.SetInlinePresentation(inlinePresentation); } if (filledItem.ApplyToFields(fields, datasetBuilder)) { return(datasetBuilder.Build()); } return(null); }
public static InlinePresentation BuildInlinePresentation(InlinePresentationSpec inlinePresentationSpec, string text, string subtext, int iconId, PendingIntent pendingIntent, Context context) { if ((int)Build.VERSION.SdkInt < 30 || inlinePresentationSpec == null) { return(null); } if (pendingIntent == null) { // InlinePresentation requires nonNull pending intent (even though we only utilize one for the // "my vault" presentation) so we're including an empty one here pendingIntent = PendingIntent.GetService(context, 0, new Intent(), PendingIntentFlags.OneShot | PendingIntentFlags.UpdateCurrent); } var slice = CreateInlinePresentationSlice( inlinePresentationSpec, text, subtext, iconId, "Autofill option", pendingIntent, context); if (slice != null) { return(new InlinePresentation(slice, inlinePresentationSpec, false)); } return(null); }
public static InlinePresentation BuildInlinePresentation(InlinePresentationSpec inlinePresentationSpec, string text, string subtext, int iconId, PendingIntent pendingIntent, Context context) { if ((int)Build.VERSION.SdkInt < 30 || inlinePresentationSpec == null) { return(null); } //make sure we have a pendingIntent always not null pendingIntent ??= PendingIntent.GetService(context, 0, new Intent(), PendingIntentFlags.OneShot | PendingIntentFlags.UpdateCurrent); var slice = CreateInlinePresentationSlice( inlinePresentationSpec, text, subtext, iconId, "Autofill option", pendingIntent, context); if (slice != null) { return(new InlinePresentation(slice, inlinePresentationSpec, false)); } return(null); }
public static void AddInlinePresentation(Context context, InlinePresentationSpec inlinePresentationSpec, string datasetName, Dataset.Builder datasetBuilder, int iconId) { if (inlinePresentationSpec != null) { var inlinePresentation = BuildInlinePresentation(inlinePresentationSpec, datasetName, "", iconId, null, context); datasetBuilder.SetInlinePresentation(inlinePresentation); } }
public static FillResponse BuildFillResponse(Parser parser, List <FilledItem> items, bool locked, bool inlineAutofillEnabled, FillRequest fillRequest = null) { // Acquire inline presentation specs on Android 11+ IList <InlinePresentationSpec> inlinePresentationSpecs = null; var inlinePresentationSpecsCount = 0; var inlineMaxSuggestedCount = 0; if (inlineAutofillEnabled && fillRequest != null && (int)Build.VERSION.SdkInt >= 30) { var inlineSuggestionsRequest = fillRequest.InlineSuggestionsRequest; inlineMaxSuggestedCount = inlineSuggestionsRequest?.MaxSuggestionCount ?? 0; inlinePresentationSpecs = inlineSuggestionsRequest?.InlinePresentationSpecs; inlinePresentationSpecsCount = inlinePresentationSpecs?.Count ?? 0; } // Build response var responseBuilder = new FillResponse.Builder(); if (items != null && items.Count > 0) { var maxItems = items.Count; if (inlineMaxSuggestedCount > 0) { // -1 to adjust for 'open vault' option maxItems = Math.Min(maxItems, inlineMaxSuggestedCount - 1); } for (int i = 0; i < maxItems; i++) { InlinePresentationSpec inlinePresentationSpec = null; if (inlinePresentationSpecs != null) { if (i < inlinePresentationSpecsCount) { inlinePresentationSpec = inlinePresentationSpecs[i]; } else { // If the max suggestion count is larger than the number of specs in the list, then // the last spec is used for the remainder of the suggestions inlinePresentationSpec = inlinePresentationSpecs[inlinePresentationSpecsCount - 1]; } } var dataset = BuildDataset(parser.ApplicationContext, parser.FieldCollection, items[i], inlinePresentationSpec); if (dataset != null) { responseBuilder.AddDataset(dataset); } } } responseBuilder.AddDataset(BuildVaultDataset(parser.ApplicationContext, parser.FieldCollection, parser.Uri, locked, inlinePresentationSpecs)); AddSaveInfo(parser, fillRequest, responseBuilder, parser.FieldCollection); responseBuilder.SetIgnoredIds(parser.FieldCollection.IgnoreAutofillIds.ToArray()); return(responseBuilder.Build()); }
private static Slice CreateInlinePresentationSlice( InlinePresentationSpec inlinePresentationSpec, string text, string subtext, int iconId, string contentDescription, PendingIntent pendingIntent, Context context) { var imeStyle = inlinePresentationSpec.Style; if (!UiVersions.GetVersions(imeStyle).Contains(UiVersions.InlineUiVersion1)) { return(null); } var contentBuilder = InlineSuggestionUi.NewContentBuilder(pendingIntent) .SetContentDescription(contentDescription); if (!string.IsNullOrWhiteSpace(text)) { contentBuilder.SetTitle(text); } if (!string.IsNullOrWhiteSpace(subtext)) { contentBuilder.SetSubtitle(subtext); } if (iconId > 0) { var icon = Icon.CreateWithResource(context, iconId); if (icon != null) { if (iconId == Resource.Drawable.icon) { // Don't tint our logo icon.SetTintBlendMode(BlendMode.Dst); } contentBuilder.SetStartIcon(icon); } } return(contentBuilder.Build().JavaCast <InlineSuggestionUi.Content>()?.Slice); }
private void AddDisableDataset(string query, AutofillId[] autofillIds, FillResponse.Builder responseBuilder, bool isManual, InlinePresentationSpec inlinePresentationSpec) { bool isQueryDisabled = IsQueryDisabled(query); if (isQueryDisabled && !isManual) { return; } bool isForDisable = !isQueryDisabled; var sender = IntentBuilder.GetDisableIntentSenderForResponse(this, query, isManual, isForDisable); string text = GetString(isForDisable ? Resource.String.autofill_disable : Resource.String.autofill_enable_for, new Java.Lang.Object[] { GetDisplayNameForQuery(query, this) }); RemoteViews presentation = AutofillHelper.NewRemoteViews(base.PackageName, text, Resource.Drawable.ic_menu_close_grey); var datasetBuilder = new Dataset.Builder(presentation); datasetBuilder.SetAuthentication(sender); AutofillHelper.AddInlinePresentation(this, inlinePresentationSpec, text, datasetBuilder, Resource.Drawable.ic_menu_close_grey); foreach (var autofillId in autofillIds) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER")); } responseBuilder.AddDataset(datasetBuilder.Build()); }
private void AddQueryDataset(string query, string queryDomain, string queryPackage, bool isManual, AutofillId[] autofillIds, FillResponse.Builder responseBuilder, bool autoReturnFromQuery, DisplayWarning warning, InlinePresentationSpec inlinePresentationSpec) { var sender = IntentBuilder.GetAuthIntentSenderForResponse(this, query, queryDomain, queryPackage, isManual, autoReturnFromQuery, warning); string text = GetString(Resource.String.autofill_sign_in_prompt); RemoteViews presentation = AutofillHelper.NewRemoteViews(base.PackageName, text, AppNames.LauncherIcon); var datasetBuilder = new Dataset.Builder(presentation); datasetBuilder.SetAuthentication(sender); //need to add placeholders so we can directly fill after ChooseActivity foreach (var autofillId in autofillIds) { datasetBuilder.SetValue(autofillId, AutofillValue.ForText("PLACEHOLDER")); } AutofillHelper.AddInlinePresentation(this, inlinePresentationSpec, text, datasetBuilder, AppNames.LauncherIcon); responseBuilder.AddDataset(datasetBuilder.Build()); }