コード例 #1
0
        /**
         * Wraps autofill data in a Response object (essentially a series of Datasets) which can then
         * be sent back to the client View.
         */
        public static FillResponse NewResponse(Context context,
                                               bool datasetAuth, AutofillFieldMetadataCollection autofillFields,
                                               Dictionary <string, FilledAutofillFieldCollection> clientFormDataMap)
        {
            FillResponse.Builder responseBuilder = new FillResponse.Builder();
            if (clientFormDataMap != null)
            {
                var datasetNames = clientFormDataMap.Keys;
                foreach (var datasetName in datasetNames)
                {
                    var filledAutofillFieldCollection = clientFormDataMap[datasetName];
                    if (filledAutofillFieldCollection != null)
                    {
                        var dataset = NewDataset(context, autofillFields,
                                                 filledAutofillFieldCollection, datasetAuth);
                        if (dataset != null)
                        {
                            responseBuilder.AddDataset(dataset);
                        }
                    }
                }
            }

            if (autofillFields.GetSaveType() != 0)
            {
                AutofillId[] autofillIds = autofillFields.GetAutofillIds();
                responseBuilder.SetSaveInfo
                    (new SaveInfo.Builder((SaveDataType)autofillFields.GetSaveType(), autofillIds).Build());
                return(responseBuilder.Build());
            }

            Log.Debug(CommonUtil.TAG, "These fields are not meant to be saved by autofill.");
            return(null);
        }
コード例 #2
0
        /**
         * Wraps autofill data in a LoginCredential  Dataset object which can then be sent back to the
         * client View.
         */
        public static Dataset NewDataset(
            Context context,
            AutofillFieldMetadataCollection autofillFields,
            FilledAutofillFieldCollection filledAutofillFieldCollection,
            bool datasetAuth)
        {
            var datasetName = filledAutofillFieldCollection.GetDatasetName();

            if (datasetName != null)
            {
                Dataset.Builder datasetBuilder;
                if (datasetAuth)
                {
                    datasetBuilder = new Dataset.Builder
                                         (NewRemoteViews(context.PackageName, datasetName, Resource.Drawable.ic_lock_black_24dp));
                    var sender = AuthActivity.GetAuthIntentSenderForDataset(context, datasetName);
                    datasetBuilder.SetAuthentication(sender);
                }
                else
                {
                    datasetBuilder = new Dataset.Builder
                                         (NewRemoteViews(context.PackageName, datasetName, Resource.Drawable.ic_person_black_24dp));
                }

                var setValueAtLeastOnce = filledAutofillFieldCollection.ApplyToFields(autofillFields, datasetBuilder);
                if (setValueAtLeastOnce)
                {
                    return(datasetBuilder.Build());
                }
            }

            return(null);
        }