Extended button and device specific monospace fonts

This commit is contained in:
Kyle Spearrin 2016-08-16 22:18:45 -04:00
parent 2c05c9595b
commit 189c56342a
12 changed files with 131 additions and 11 deletions

View File

@ -295,6 +295,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Controls\ExtendedButtonRenderer.cs" />
<Compile Include="Controls\ExtendedTableViewRenderer.cs" />
<Compile Include="HockeyAppCrashManagerListener.cs" />
<Compile Include="LoginService.cs" />

View File

@ -0,0 +1,41 @@
using System;
using System.ComponentModel;
using Bit.Android.Controls;
using Bit.App.Controls;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(ExtendedButton), typeof(ExtendedButtonRenderer))]
namespace Bit.Android.Controls
{
public class ExtendedButtonRenderer : ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
SetPadding();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if(e.PropertyName == ExtendedButton.PaddingProperty.PropertyName)
{
SetPadding();
}
}
private void SetPadding()
{
var element = Element as ExtendedButton;
if(element != null)
{
Control.SetPadding(
(int)element.Padding.Left,
(int)element.Padding.Top,
(int)element.Padding.Right,
(int)element.Padding.Bottom);
}
}
}
}

View File

@ -56,6 +56,7 @@
<Compile Include="Controls\DismissModalToolBarItem.cs" />
<Compile Include="Controls\EntryLabel.cs" />
<Compile Include="Controls\ExtendedEditor.cs" />
<Compile Include="Controls\ExtendedButton.cs" />
<Compile Include="Controls\ExtendedNavigationPage.cs" />
<Compile Include="Controls\ExtendedContentPage.cs" />
<Compile Include="Controls\StepperCell.cs" />

View File

@ -0,0 +1,18 @@
using Bit.App.Enums;
using System;
using Xamarin.Forms;
namespace Bit.App.Controls
{
public class ExtendedButton : Button
{
public static readonly BindableProperty PaddingProperty =
BindableProperty.Create(nameof(Padding), typeof(Thickness), typeof(ExtendedButton), default(Thickness));
public Thickness Padding
{
get { return (Thickness)GetValue(PaddingProperty); }
set { SetValue(PaddingProperty, value); }
}
}
}

View File

@ -63,7 +63,7 @@ namespace Bit.App.Controls
if(button1Text != null)
{
Button1 = new Button
Button1 = new ExtendedButton
{
Text = button1Text,
HorizontalOptions = LayoutOptions.End,
@ -76,7 +76,7 @@ namespace Bit.App.Controls
if(button2Text != null)
{
Button2 = new Button
Button2 = new ExtendedButton
{
Text = button2Text,
HorizontalOptions = LayoutOptions.End,
@ -87,6 +87,18 @@ namespace Bit.App.Controls
buttonStackLayout.Children.Add(Button2);
}
if(Device.OS == TargetPlatform.Android)
{
if(Button1 != null)
{
Button1.Padding = new Thickness(5);
}
if(Button2 != null)
{
Button2.Padding = new Thickness(5);
}
}
containerStackLayout.Children.Add(buttonStackLayout);
View = containerStackLayout;
@ -94,7 +106,7 @@ namespace Bit.App.Controls
public Label Label { get; private set; }
public Label Value { get; private set; }
public Button Button1 { get; private set; }
public Button Button2 { get; private set; }
public ExtendedButton Button1 { get; private set; }
public ExtendedButton Button2 { get; private set; }
}
}

View File

@ -13,8 +13,8 @@ namespace Bit.App.Controls
{
HorizontalTextAlignment = TextAlignment.Center,
FontSize = 35,
FontFamily = "Courier"
};
FontFamily = Device.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier")
};
Entry = new ExtendedEntry
{

View File

@ -42,7 +42,7 @@ namespace Bit.App.Pages
FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)),
Margin = new Thickness(15, 40, 15, 40),
HorizontalTextAlignment = TextAlignment.Center,
FontFamily = "Courier",
FontFamily = Device.OnPlatform(iOS: "Courier", Android: "monospace", WinPhone: "Courier"),
LineBreakMode = LineBreakMode.TailTruncation,
VerticalOptions = LayoutOptions.Start
};

View File

@ -41,7 +41,8 @@ namespace Bit.App.Pages
usernameCell.Entry.DisableAutocapitalize = true;
usernameCell.Entry.Autocorrect = false;
usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = "Courier";
usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = Device.OnPlatform(
iOS: "Courier", Android: "monospace", WinPhone: "Courier");
var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);
var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.Entry);

View File

@ -52,7 +52,8 @@ namespace Bit.App.Pages
usernameCell.Entry.DisableAutocapitalize = true;
usernameCell.Entry.Autocorrect = false;
usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = "Courier";
usernameCell.Entry.FontFamily = PasswordCell.Entry.FontFamily = Device.OnPlatform(
iOS: "Courier", Android: "monospace", WinPhone: "Courier");
var uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);
uriCell.Entry.Text = site.Uri?.Decrypt();

View File

@ -52,7 +52,8 @@ namespace Bit.App.Pages
UsernameCell.Button1.Command = new Command(() => Copy(Model.Username, AppResources.Username));
// Password
PasswordCell = new LabeledValueCell(AppResources.Password, button1Text: string.Empty, button2Text: AppResources.Copy);
PasswordCell = new LabeledValueCell(AppResources.Password, button1Text: string.Empty,
button2Text: AppResources.Copy);
PasswordCell.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.MaskedPassword);
PasswordCell.Button1.SetBinding<VaultViewSitePageModel>(Button.ImageProperty, s => s.ShowHideImage);
if(Device.OS == TargetPlatform.iOS)
@ -62,7 +63,8 @@ namespace Bit.App.Pages
PasswordCell.Button1.Command = new Command(() => Model.RevealPassword = !Model.RevealPassword);
PasswordCell.Button2.Command = new Command(() => Copy(Model.Password, AppResources.Password));
UsernameCell.Value.FontFamily = PasswordCell.Value.FontFamily = "Courier";
UsernameCell.Value.FontFamily = PasswordCell.Value.FontFamily = Device.OnPlatform(
iOS: "Courier", Android: "monospace", WinPhone: "Courier");
// URI
UriCell = new LabeledValueCell(AppResources.Website, button1Text: AppResources.Launch);

View File

@ -0,0 +1,42 @@
using System;
using Bit.iOS.Controls;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using System.ComponentModel;
using Bit.App.Controls;
[assembly: ExportRenderer(typeof(ExtendedButton), typeof(ExtendedButtonRenderer))]
namespace Bit.iOS.Controls
{
public class ExtendedButtonRenderer : CustomButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
SetPadding();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if(e.PropertyName == ExtendedButton.PaddingProperty.PropertyName)
{
SetPadding();
}
}
private void SetPadding()
{
var element = Element as ExtendedButton;
if(element != null)
{
Control.ContentEdgeInsets = new UIEdgeInsets(
(int)element.Padding.Top,
(int)element.Padding.Left,
(int)element.Padding.Bottom,
(int)element.Padding.Right);
}
}
}
}

View File

@ -226,6 +226,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Controls\ContentPageRenderer.cs" />
<Compile Include="Controls\ExtendedButtonRenderer.cs" />
<Compile Include="Controls\CustomButtonRenderer.cs" />
<Compile Include="Controls\CustomLabelRenderer.cs" />
<Compile Include="Controls\ExtendedEditorRenderer.cs" />