2016-06-07 01:48:52 +03:00
|
|
|
|
using System;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Bit.App.Controls
|
|
|
|
|
{
|
|
|
|
|
public class PinControl
|
|
|
|
|
{
|
|
|
|
|
private Action _pinEnteredAction;
|
2016-06-08 02:19:21 +03:00
|
|
|
|
private Action _confirmPinEnteredAction;
|
2016-06-07 01:48:52 +03:00
|
|
|
|
|
2016-06-08 02:19:21 +03:00
|
|
|
|
public PinControl(Action pinEnteredAction, Action confirmPinEnteredAction = null)
|
2016-06-07 01:48:52 +03:00
|
|
|
|
{
|
|
|
|
|
_pinEnteredAction = pinEnteredAction;
|
2016-06-08 02:19:21 +03:00
|
|
|
|
_confirmPinEnteredAction = confirmPinEnteredAction;
|
2016-06-07 01:48:52 +03:00
|
|
|
|
|
|
|
|
|
Label = new Label
|
|
|
|
|
{
|
|
|
|
|
HorizontalTextAlignment = TextAlignment.Center,
|
|
|
|
|
FontSize = 30,
|
|
|
|
|
TextColor = Color.FromHex("333333"),
|
|
|
|
|
FontFamily = "Courier"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Entry = new ExtendedEntry
|
|
|
|
|
{
|
|
|
|
|
Keyboard = Keyboard.Numeric,
|
2016-06-07 04:13:00 +03:00
|
|
|
|
MaxLength = 4,
|
|
|
|
|
Margin = new Thickness(0, int.MaxValue, 0, 0)
|
2016-06-07 01:48:52 +03:00
|
|
|
|
};
|
2016-06-08 02:19:21 +03:00
|
|
|
|
Entry.TextChanged += Entry_TextChanged;
|
|
|
|
|
|
|
|
|
|
ConfirmEntry = new ExtendedEntry
|
|
|
|
|
{
|
|
|
|
|
Keyboard = Keyboard.Numeric,
|
|
|
|
|
MaxLength = 4,
|
|
|
|
|
Margin = new Thickness(0, int.MaxValue, 0, 0)
|
|
|
|
|
};
|
|
|
|
|
Entry.TextChanged += ConfirmEntry_TextChanged;
|
2016-06-07 01:48:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 02:19:21 +03:00
|
|
|
|
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
|
2016-06-07 01:48:52 +03:00
|
|
|
|
{
|
2016-06-08 02:19:21 +03:00
|
|
|
|
if(e.NewTextValue.Length >= 4 && _pinEnteredAction != null)
|
2016-06-07 01:48:52 +03:00
|
|
|
|
{
|
|
|
|
|
_pinEnteredAction();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 02:19:21 +03:00
|
|
|
|
private void ConfirmEntry_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if(e.NewTextValue.Length >= 4 && _confirmPinEnteredAction != null)
|
|
|
|
|
{
|
|
|
|
|
_confirmPinEnteredAction();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 01:48:52 +03:00
|
|
|
|
public Label Label { get; set; }
|
|
|
|
|
public ExtendedEntry Entry { get; set; }
|
2016-06-08 02:19:21 +03:00
|
|
|
|
public ExtendedEntry ConfirmEntry { get; set; }
|
2016-06-07 01:48:52 +03:00
|
|
|
|
}
|
|
|
|
|
}
|