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

118 lines
3.7 KiB
C#
Raw Normal View History

using System;
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class FormEntryCell : ExtendedViewCell
{
public FormEntryCell(
string labelText,
Keyboard entryKeyboard = null,
bool IsPassword = false,
VisualElement nextElement = null,
bool useLabelAsPlaceholder = false,
string imageSource = null,
Thickness? containerPadding = null)
{
2016-06-28 03:56:59 +03:00
if(!useLabelAsPlaceholder)
{
2016-06-28 03:56:59 +03:00
Label = new Label
{
Text = labelText,
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
VerticalOptions = LayoutOptions.Start,
Style = (Style)Application.Current.Resources["text-muted"],
HorizontalOptions = LayoutOptions.FillAndExpand
2016-06-28 03:56:59 +03:00
};
if(Device.OS == TargetPlatform.Android)
{
Label.FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label));
}
2016-06-28 03:56:59 +03:00
}
Entry = new ExtendedEntry
{
Keyboard = entryKeyboard,
2016-05-17 06:54:24 +03:00
HasBorder = false,
VerticalOptions = LayoutOptions.CenterAndExpand,
IsPassword = IsPassword,
AllowClear = true,
HorizontalOptions = LayoutOptions.FillAndExpand
};
if(Device.OS == TargetPlatform.Android)
{
Entry.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
Entry.TextColor = Color.Black;
}
2016-06-28 03:56:59 +03:00
if(useLabelAsPlaceholder)
{
Entry.Placeholder = labelText;
}
if(nextElement != null)
{
Entry.ReturnType = Enums.ReturnType.Next;
Entry.Completed += (object sender, EventArgs e) => { nextElement.Focus(); };
}
var imageStackLayout = new StackLayout
{
Padding = containerPadding ?? new Thickness(15, 10),
Orientation = StackOrientation.Horizontal,
Spacing = 10,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
if(imageSource != null)
{
var tgr = new TapGestureRecognizer();
tgr.Tapped += Tgr_Tapped;
var theImage = new Image
{
Source = imageSource,
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Center
};
theImage.GestureRecognizers.Add(tgr);
imageStackLayout.Children.Add(theImage);
}
var formStackLayout = new StackLayout
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
};
2016-06-28 03:56:59 +03:00
if(!useLabelAsPlaceholder)
{
formStackLayout.Children.Add(Label);
2016-06-28 03:56:59 +03:00
}
formStackLayout.Children.Add(Entry);
imageStackLayout.Children.Add(formStackLayout);
2016-07-05 05:35:49 +03:00
Tapped += FormEntryCell_Tapped;
View = imageStackLayout;
}
public Label Label { get; private set; }
public ExtendedEntry Entry { get; private set; }
private void Tgr_Tapped(object sender, EventArgs e)
{
Entry.Focus();
}
2016-07-05 05:35:49 +03:00
private void FormEntryCell_Tapped(object sender, EventArgs e)
{
Entry.Focus();
}
}
}