1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-12-22 16:18:21 +01:00

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> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Controls\ExtendedButtonRenderer.cs" />
<Compile Include="Controls\ExtendedTableViewRenderer.cs" /> <Compile Include="Controls\ExtendedTableViewRenderer.cs" />
<Compile Include="HockeyAppCrashManagerListener.cs" /> <Compile Include="HockeyAppCrashManagerListener.cs" />
<Compile Include="LoginService.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\DismissModalToolBarItem.cs" />
<Compile Include="Controls\EntryLabel.cs" /> <Compile Include="Controls\EntryLabel.cs" />
<Compile Include="Controls\ExtendedEditor.cs" /> <Compile Include="Controls\ExtendedEditor.cs" />
<Compile Include="Controls\ExtendedButton.cs" />
<Compile Include="Controls\ExtendedNavigationPage.cs" /> <Compile Include="Controls\ExtendedNavigationPage.cs" />
<Compile Include="Controls\ExtendedContentPage.cs" /> <Compile Include="Controls\ExtendedContentPage.cs" />
<Compile Include="Controls\StepperCell.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) if(button1Text != null)
{ {
Button1 = new Button Button1 = new ExtendedButton
{ {
Text = button1Text, Text = button1Text,
HorizontalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.End,
@ -76,7 +76,7 @@ namespace Bit.App.Controls
if(button2Text != null) if(button2Text != null)
{ {
Button2 = new Button Button2 = new ExtendedButton
{ {
Text = button2Text, Text = button2Text,
HorizontalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.End,
@ -87,6 +87,18 @@ namespace Bit.App.Controls
buttonStackLayout.Children.Add(Button2); 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); containerStackLayout.Children.Add(buttonStackLayout);
View = containerStackLayout; View = containerStackLayout;
@ -94,7 +106,7 @@ namespace Bit.App.Controls
public Label Label { get; private set; } public Label Label { get; private set; }
public Label Value { get; private set; } public Label Value { get; private set; }
public Button Button1 { get; private set; } public ExtendedButton Button1 { get; private set; }
public Button Button2 { get; private set; } public ExtendedButton Button2 { get; private set; }
} }
} }

View File

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

View File

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

View File

@ -41,7 +41,8 @@ namespace Bit.App.Pages
usernameCell.Entry.DisableAutocapitalize = true; usernameCell.Entry.DisableAutocapitalize = true;
usernameCell.Entry.Autocorrect = false; 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 uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);
var nameCell = new FormEntryCell(AppResources.Name, nextElement: uriCell.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.DisableAutocapitalize = true;
usernameCell.Entry.Autocorrect = false; 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 uriCell = new FormEntryCell(AppResources.URI, Keyboard.Url, nextElement: usernameCell.Entry);
uriCell.Entry.Text = site.Uri?.Decrypt(); 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)); UsernameCell.Button1.Command = new Command(() => Copy(Model.Username, AppResources.Username));
// Password // 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.Value.SetBinding<VaultViewSitePageModel>(Label.TextProperty, s => s.MaskedPassword);
PasswordCell.Button1.SetBinding<VaultViewSitePageModel>(Button.ImageProperty, s => s.ShowHideImage); PasswordCell.Button1.SetBinding<VaultViewSitePageModel>(Button.ImageProperty, s => s.ShowHideImage);
if(Device.OS == TargetPlatform.iOS) if(Device.OS == TargetPlatform.iOS)
@ -62,7 +63,8 @@ namespace Bit.App.Pages
PasswordCell.Button1.Command = new Command(() => Model.RevealPassword = !Model.RevealPassword); PasswordCell.Button1.Command = new Command(() => Model.RevealPassword = !Model.RevealPassword);
PasswordCell.Button2.Command = new Command(() => Copy(Model.Password, AppResources.Password)); 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 // URI
UriCell = new LabeledValueCell(AppResources.Website, button1Text: AppResources.Launch); 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> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Controls\ContentPageRenderer.cs" /> <Compile Include="Controls\ContentPageRenderer.cs" />
<Compile Include="Controls\ExtendedButtonRenderer.cs" />
<Compile Include="Controls\CustomButtonRenderer.cs" /> <Compile Include="Controls\CustomButtonRenderer.cs" />
<Compile Include="Controls\CustomLabelRenderer.cs" /> <Compile Include="Controls\CustomLabelRenderer.cs" />
<Compile Include="Controls\ExtendedEditorRenderer.cs" /> <Compile Include="Controls\ExtendedEditorRenderer.cs" />