bitwarden-android/src/App/Controls/PinControl.cs

62 lines
1.8 KiB
C#
Raw Normal View History

2016-06-07 01:48:52 +03:00
using System;
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class PinControl
{
private Action _pinEnteredAction;
private Action _confirmPinEnteredAction;
2016-06-07 01:48:52 +03:00
public PinControl(Action pinEnteredAction, Action confirmPinEnteredAction = null)
2016-06-07 01:48:52 +03:00
{
_pinEnteredAction = pinEnteredAction;
_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
};
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
}
private void Entry_TextChanged(object sender, TextChangedEventArgs e)
2016-06-07 01:48:52 +03:00
{
if(e.NewTextValue.Length >= 4 && _pinEnteredAction != null)
2016-06-07 01:48:52 +03:00
{
_pinEnteredAction();
}
}
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; }
public ExtendedEntry ConfirmEntry { get; set; }
2016-06-07 01:48:52 +03:00
}
}