2017-11-15 00:46:40 +03:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Android.Service.Autofill;
|
|
|
|
|
using Android.Views;
|
|
|
|
|
using Android.Views.Autofill;
|
|
|
|
|
using static Android.App.Assist.AssistStructure;
|
|
|
|
|
using Android.Text;
|
|
|
|
|
|
|
|
|
|
namespace Bit.Android.Autofill
|
|
|
|
|
{
|
2017-11-15 07:13:55 +03:00
|
|
|
|
public class Field
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
2017-11-15 07:13:55 +03:00
|
|
|
|
private List<string> _hints;
|
2017-11-15 00:46:40 +03:00
|
|
|
|
private string[] _autofillOptions;
|
|
|
|
|
|
2017-11-15 07:13:55 +03:00
|
|
|
|
public Field(ViewNode view)
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
|
|
|
|
_autofillOptions = view.GetAutofillOptions();
|
|
|
|
|
Id = view.Id;
|
|
|
|
|
AutofillId = view.AutofillId;
|
|
|
|
|
AutofillType = view.AutofillType;
|
|
|
|
|
InputType = view.InputType;
|
2017-11-15 07:13:55 +03:00
|
|
|
|
Focused = view.IsFocused;
|
|
|
|
|
Hints = AutofillHelpers.FilterForSupportedHints(view.GetAutofillHints())?.ToList() ?? new List<string>();
|
2017-11-15 00:46:40 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SaveDataType SaveType { get; set; } = SaveDataType.Generic;
|
2017-11-15 07:13:55 +03:00
|
|
|
|
public List<string> Hints
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
2017-11-15 07:13:55 +03:00
|
|
|
|
get => _hints;
|
2017-11-15 00:46:40 +03:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-11-15 07:13:55 +03:00
|
|
|
|
_hints = value;
|
2017-11-15 00:46:40 +03:00
|
|
|
|
UpdateSaveTypeFromHints();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public int Id { get; private set; }
|
|
|
|
|
public AutofillId AutofillId { get; private set; }
|
|
|
|
|
public AutofillType AutofillType { get; private set; }
|
|
|
|
|
public InputTypes InputType { get; private set; }
|
2017-11-15 07:13:55 +03:00
|
|
|
|
public bool Focused { get; private set; }
|
2017-11-15 00:46:40 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* When the {@link ViewNode} is a list that the user needs to choose a string from (i.e. a
|
|
|
|
|
* spinner), this is called to return the index of a specific item in the list.
|
|
|
|
|
*/
|
|
|
|
|
public int GetAutofillOptionIndex(string value)
|
|
|
|
|
{
|
|
|
|
|
for(var i = 0; i < _autofillOptions.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if(_autofillOptions[i].Equals(value))
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateSaveTypeFromHints()
|
|
|
|
|
{
|
|
|
|
|
SaveType = SaveDataType.Generic;
|
2017-11-15 07:13:55 +03:00
|
|
|
|
if(_hints == null)
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-15 07:13:55 +03:00
|
|
|
|
foreach(var hint in _hints)
|
2017-11-15 00:46:40 +03:00
|
|
|
|
{
|
|
|
|
|
switch(hint)
|
|
|
|
|
{
|
|
|
|
|
case View.AutofillHintCreditCardExpirationDate:
|
|
|
|
|
case View.AutofillHintCreditCardExpirationDay:
|
|
|
|
|
case View.AutofillHintCreditCardExpirationMonth:
|
|
|
|
|
case View.AutofillHintCreditCardExpirationYear:
|
|
|
|
|
case View.AutofillHintCreditCardNumber:
|
|
|
|
|
case View.AutofillHintCreditCardSecurityCode:
|
|
|
|
|
SaveType |= SaveDataType.CreditCard;
|
|
|
|
|
break;
|
|
|
|
|
case View.AutofillHintEmailAddress:
|
|
|
|
|
SaveType |= SaveDataType.EmailAddress;
|
|
|
|
|
break;
|
|
|
|
|
case View.AutofillHintPhone:
|
|
|
|
|
case View.AutofillHintName:
|
|
|
|
|
SaveType |= SaveDataType.Generic;
|
|
|
|
|
break;
|
|
|
|
|
case View.AutofillHintPassword:
|
|
|
|
|
SaveType |= SaveDataType.Password;
|
|
|
|
|
SaveType &= ~SaveDataType.EmailAddress;
|
|
|
|
|
SaveType &= ~SaveDataType.Username;
|
|
|
|
|
break;
|
|
|
|
|
case View.AutofillHintPostalAddress:
|
|
|
|
|
case View.AutofillHintPostalCode:
|
|
|
|
|
SaveType |= SaveDataType.Address;
|
|
|
|
|
break;
|
|
|
|
|
case View.AutofillHintUsername:
|
|
|
|
|
SaveType |= SaveDataType.Username;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|