public override string ToString() { return(id + "/" + idEntry + ": " + (type == AutofillType.Date ? Long.ToString(date) : text) // TODO: use DateFormat for date + " (" + CommonUtil.GetTypeAsString(type) + ")" + (editable ? " (editable)" : " (read-only)" + (sanitized ? " (sanitized)" : " (sensitive")) + (hints == null ? " (no hints)" : " ( " + hints + ")")); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.multiple_partitions_activity); mCustomVirtualView = FindViewById <ScrollableCustomVirtualView>(Resource.Id.custom_view); mCredentialsPartition = mCustomVirtualView.AddPartition(GetString(Resource.String.partition_credentials)); mCredentialsPartition.AddLine("username", AutofillType.Text, GetString(Resource.String.username_label), " ", false, View.AutofillHintUsername); mCredentialsPartition.AddLine("password", AutofillType.Text, GetString(Resource.String.password_label), " ", true, View.AutofillHintPassword); AutofillType ccExpirationType = AutofillType.Date; // TODO: add a checkbox to switch between text / date instead Intent intent = Intent; if (intent != null) { var newType = intent.GetIntExtra("dateType", -1); if (newType != -1) { ccExpirationType = (AutofillType)newType; var typeMessage = GetString(Resource.String.message_credit_card_expiration_type, CommonUtil.GetTypeAsString(ccExpirationType)); // TODO: display type in a header or proper status widget Toast.MakeText(ApplicationContext, typeMessage, ToastLength.Long).Show(); } } mCcPartition = mCustomVirtualView.AddPartition(GetString(Resource.String.partition_credit_card)); mCcPartition.AddLine("ccNumber", AutofillType.Text, GetString(Resource.String.credit_card_number_label), " ", true, View.AutofillHintCreditCardNumber); mCcPartition.AddLine("ccDay", AutofillType.Text, GetString(Resource.String.credit_card_expiration_day_label), " ", true, View.AutofillHintCreditCardExpirationDay); mCcPartition.AddLine("ccMonth", ccExpirationType, GetString(Resource.String.credit_card_expiration_month_label), " ", true, View.AutofillHintCreditCardExpirationMonth); mCcPartition.AddLine("ccYear", AutofillType.Text, GetString(Resource.String.credit_card_expiration_year_label), " ", true, View.AutofillHintCreditCardExpirationYear); mCcPartition.AddLine("ccDate", ccExpirationType, GetString(Resource.String.credit_card_expiration_date_label), " ", true, View.AutofillHintCreditCardExpirationDate); mCcPartition.AddLine("ccSecurityCode", AutofillType.Text, GetString(Resource.String.credit_card_security_code_label), " ", true, View.AutofillHintCreditCardSecurityCode); FindViewById(Resource.Id.clear).Click += delegate { ResetFields(); mCustomVirtualView.ResetPositions(); mAutofillManager.Cancel(); }; mAutofillManager = (AutofillManager)GetSystemService(Class.FromType(typeof(AutofillManager))); }
public override void Autofill(SparseArray values) { Context context = Context; // User has just selected a Dataset from the list of autofill suggestions. // The Dataset is comprised of a list of AutofillValues, with each AutofillValue meant // to fill a specific autofillable view. Now we have to update the UI based on the // AutofillValues in the list, but first we make sure all autofilled values belong to the // same partition if (DEBUG) { Log.Debug(TAG, "autofill(): " + values); } // First get the name of all partitions in the values ArraySet partitions = new ArraySet(); for (int i = 0; i < values.Size(); i++) { int id = values.KeyAt(i); var partition = mPartitionsByAutofillId.Get(id); if (partition == null) { ShowError(context.GetString(Resource.String.message_autofill_no_partitions, id, mPartitionsByAutofillId)); return; } partitions.Add(partition.mName); } // Then make sure they follow the Highlander rule (There can be only one) if (partitions.Size() != 1) { ShowError(context.GetString(Resource.String.message_autofill_blocked, partitions)); return; } // Finally, autofill it. var df = Android.Text.Format.DateFormat.GetDateFormat(context); for (int i = 0; i < values.Size(); i++) { int id = values.KeyAt(i); var value = (AutofillValue)values.ValueAt(i); var item = mVirtualViews.Get(id); if (item == null) { Log.Warn(TAG, "No item for id " + id); continue; } if (!item.editable) { ShowError(context.GetString(Resource.String.message_autofill_readonly, item.text.ToString())); continue; } // Check if the type was properly set by the autofill service if (DEBUG) { Log.Debug(TAG, "Validating " + i + ": expectedType=" + CommonUtil.GetTypeAsString(item.type) + "(" + item.type + "), value=" + value); } bool valid = false; if (value.IsText && item.type == AutofillType.Text) { item.text = value.TextValue; valid = true; } else if (value.IsDate && item.type == AutofillType.Date) { item.text = df.Format(new Date(value.DateValue)); valid = true; } else { Log.Warn(TAG, "Unsupported type: " + value); } if (!valid) { item.text = context.GetString(Resource.String.message_autofill_invalid); } } PostInvalidate(); ShowMessage(context.GetString(Resource.String.message_autofill_ok, partitions.ValueAt(0))); }