mirror of
https://github.com/bitwarden/android.git
synced 2024-12-19 07:41:52 +03:00
Optimizations for dynamic text sizes.
This commit is contained in:
parent
734d2632dc
commit
2e9410846e
12 changed files with 206 additions and 30 deletions
|
@ -43,6 +43,20 @@ namespace Bit.Android.Controls
|
||||||
return View;
|
return View;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
|
||||||
|
{
|
||||||
|
base.OnCellPropertyChanged(sender, args);
|
||||||
|
|
||||||
|
var cell = (ExtendedTextCell)Cell;
|
||||||
|
|
||||||
|
if(args.PropertyName == ExtendedTextCell.BackgroundColorProperty.PropertyName)
|
||||||
|
{
|
||||||
|
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: other properties
|
||||||
|
}
|
||||||
|
|
||||||
private class DisclosureImage : ImageView
|
private class DisclosureImage : ImageView
|
||||||
{
|
{
|
||||||
private ExtendedTextCell _cell;
|
private ExtendedTextCell _cell;
|
||||||
|
@ -66,19 +80,5 @@ namespace Bit.Android.Controls
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
|
|
||||||
{
|
|
||||||
base.OnCellPropertyChanged(sender, args);
|
|
||||||
|
|
||||||
var cell = (ExtendedTextCell)Cell;
|
|
||||||
|
|
||||||
if(args.PropertyName == ExtendedTextCell.BackgroundColorProperty.PropertyName)
|
|
||||||
{
|
|
||||||
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: other properties
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ using Bit.App.Controls;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using Xamarin.Forms.Platform.Android;
|
using Xamarin.Forms.Platform.Android;
|
||||||
using AView = Android.Views.View;
|
using AView = Android.Views.View;
|
||||||
|
using Android.Widget;
|
||||||
|
|
||||||
[assembly: ExportRenderer(typeof(ExtendedViewCell), typeof(ExtendedViewCellRenderer))]
|
[assembly: ExportRenderer(typeof(ExtendedViewCell), typeof(ExtendedViewCellRenderer))]
|
||||||
namespace Bit.Android.Controls
|
namespace Bit.Android.Controls
|
||||||
|
@ -16,12 +17,28 @@ namespace Bit.Android.Controls
|
||||||
|
|
||||||
protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
|
protected override AView GetCellCore(Cell item, AView convertView, ViewGroup parent, Context context)
|
||||||
{
|
{
|
||||||
var View = base.GetCellCore(item, convertView, parent, context);
|
var View = (BaseCellView)base.GetCellCore(item, convertView, parent, context);
|
||||||
var extendedCell = (ExtendedViewCell)item;
|
var extendedCell = (ExtendedViewCell)item;
|
||||||
|
|
||||||
if(View != null)
|
if(View != null)
|
||||||
{
|
{
|
||||||
View.SetBackgroundColor(extendedCell.BackgroundColor.ToAndroid());
|
View.SetBackgroundColor(extendedCell.BackgroundColor.ToAndroid());
|
||||||
|
|
||||||
|
|
||||||
|
if(extendedCell.ShowDisclousure)
|
||||||
|
{
|
||||||
|
var resourceId = Resource.Drawable.ion_chevron_right;
|
||||||
|
if(!string.IsNullOrWhiteSpace(extendedCell.DisclousureImage))
|
||||||
|
{
|
||||||
|
var fileName = System.IO.Path.GetFileNameWithoutExtension(extendedCell.DisclousureImage);
|
||||||
|
resourceId = context.Resources.GetIdentifier(fileName, "drawable", context.PackageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
var image = new DisclosureImage(context, extendedCell);
|
||||||
|
image.SetImageResource(resourceId);
|
||||||
|
image.SetPadding(10, 10, 30, 10);
|
||||||
|
View.SetAccessoryView(image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return View;
|
return View;
|
||||||
|
@ -31,12 +48,36 @@ namespace Bit.Android.Controls
|
||||||
{
|
{
|
||||||
base.OnCellPropertyChanged(sender, args);
|
base.OnCellPropertyChanged(sender, args);
|
||||||
|
|
||||||
var cell = (ExtendedTextCell)Cell;
|
var cell = (ExtendedViewCell)Cell;
|
||||||
|
|
||||||
if(args.PropertyName == ExtendedTextCell.BackgroundColorProperty.PropertyName)
|
if(args.PropertyName == ExtendedViewCell.BackgroundColorProperty.PropertyName)
|
||||||
{
|
{
|
||||||
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
|
View.SetBackgroundColor(cell.BackgroundColor.ToAndroid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class DisclosureImage : ImageView
|
||||||
|
{
|
||||||
|
private ExtendedViewCell _cell;
|
||||||
|
|
||||||
|
public DisclosureImage(Context context, ExtendedViewCell cell) : base(context)
|
||||||
|
{
|
||||||
|
_cell = cell;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool OnTouchEvent(MotionEvent e)
|
||||||
|
{
|
||||||
|
switch(e.Action)
|
||||||
|
{
|
||||||
|
case MotionEventActions.Up:
|
||||||
|
_cell.OnDisclousureTapped();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@
|
||||||
<Compile Include="Controls\ExtendedViewCell.cs" />
|
<Compile Include="Controls\ExtendedViewCell.cs" />
|
||||||
<Compile Include="Controls\FormEditorCell.cs" />
|
<Compile Include="Controls\FormEditorCell.cs" />
|
||||||
<Compile Include="Controls\ExtendedTextCell.cs" />
|
<Compile Include="Controls\ExtendedTextCell.cs" />
|
||||||
|
<Compile Include="Controls\LabeledDetailCell.cs" />
|
||||||
<Compile Include="Controls\LabeledValueCell.cs" />
|
<Compile Include="Controls\LabeledValueCell.cs" />
|
||||||
<Compile Include="Controls\FormPickerCell.cs" />
|
<Compile Include="Controls\FormPickerCell.cs" />
|
||||||
<Compile Include="Controls\FormEntryCell.cs" />
|
<Compile Include="Controls\FormEntryCell.cs" />
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Xamarin.Forms;
|
using System;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
namespace Bit.App.Controls
|
namespace Bit.App.Controls
|
||||||
{
|
{
|
||||||
|
@ -7,10 +8,35 @@ namespace Bit.App.Controls
|
||||||
public static readonly BindableProperty BackgroundColorProperty =
|
public static readonly BindableProperty BackgroundColorProperty =
|
||||||
BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(ExtendedTextCell), Color.White);
|
BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(ExtendedTextCell), Color.White);
|
||||||
|
|
||||||
|
public static readonly BindableProperty ShowDisclousureProperty =
|
||||||
|
BindableProperty.Create(nameof(DisclousureImage), typeof(bool), typeof(ExtendedTextCell), false);
|
||||||
|
|
||||||
|
public static readonly BindableProperty DisclousureImageProperty =
|
||||||
|
BindableProperty.Create(nameof(DisclousureImage), typeof(string), typeof(ExtendedTextCell), string.Empty);
|
||||||
|
|
||||||
public Color BackgroundColor
|
public Color BackgroundColor
|
||||||
{
|
{
|
||||||
get { return (Color)GetValue(BackgroundColorProperty); }
|
get { return (Color)GetValue(BackgroundColorProperty); }
|
||||||
set { SetValue(BackgroundColorProperty, value); }
|
set { SetValue(BackgroundColorProperty, value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ShowDisclousure
|
||||||
|
{
|
||||||
|
get { return (bool)GetValue(ShowDisclousureProperty); }
|
||||||
|
set { SetValue(ShowDisclousureProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public string DisclousureImage
|
||||||
|
{
|
||||||
|
get { return (string)GetValue(DisclousureImageProperty); }
|
||||||
|
set { SetValue(DisclousureImageProperty, value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public event EventHandler DisclousureTapped;
|
||||||
|
|
||||||
|
public void OnDisclousureTapped()
|
||||||
|
{
|
||||||
|
DisclousureTapped?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
38
src/App/Controls/LabeledDetailCell.cs
Normal file
38
src/App/Controls/LabeledDetailCell.cs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Bit.App.Controls
|
||||||
|
{
|
||||||
|
public class LabeledDetailCell : ExtendedViewCell
|
||||||
|
{
|
||||||
|
public LabeledDetailCell()
|
||||||
|
{
|
||||||
|
Label = new Label
|
||||||
|
{
|
||||||
|
VerticalOptions = LayoutOptions.CenterAndExpand,
|
||||||
|
LineBreakMode = LineBreakMode.TailTruncation
|
||||||
|
};
|
||||||
|
|
||||||
|
Detail = new Label
|
||||||
|
{
|
||||||
|
FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),
|
||||||
|
LineBreakMode = LineBreakMode.TailTruncation,
|
||||||
|
VerticalOptions = LayoutOptions.End,
|
||||||
|
Style = (Style)Application.Current.Resources["text-muted"],
|
||||||
|
};
|
||||||
|
|
||||||
|
var stackLayout = new StackLayout
|
||||||
|
{
|
||||||
|
Padding = new Thickness(15, 5),
|
||||||
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
||||||
|
VerticalOptions = LayoutOptions.FillAndExpand,
|
||||||
|
Children = { Label, Detail },
|
||||||
|
Spacing = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
View = stackLayout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Label Label { get; private set; }
|
||||||
|
public Label Detail { get; private set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -87,6 +87,7 @@ namespace Bit.App.Pages
|
||||||
{
|
{
|
||||||
EnableScrolling = true,
|
EnableScrolling = true,
|
||||||
Intent = TableIntent.Menu,
|
Intent = TableIntent.Menu,
|
||||||
|
HasUnevenRows = true,
|
||||||
Root = new TableRoot
|
Root = new TableRoot
|
||||||
{
|
{
|
||||||
new TableSection("Security")
|
new TableSection("Security")
|
||||||
|
@ -108,10 +109,11 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var scrollView = new ScrollView
|
if( Device.OS == TargetPlatform.iOS )
|
||||||
{
|
{
|
||||||
Content = table
|
table.RowHeight = -1;
|
||||||
};
|
table.EstimatedRowHeight = 44;
|
||||||
|
}
|
||||||
|
|
||||||
Title = AppResources.Settings;
|
Title = AppResources.Settings;
|
||||||
Content = table;
|
Content = table;
|
||||||
|
|
|
@ -179,7 +179,7 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class VaultListViewCell : ExtendedTextCell
|
private class VaultListViewCell : LabeledDetailCell
|
||||||
{
|
{
|
||||||
private VaultListSitesPage _page;
|
private VaultListSitesPage _page;
|
||||||
|
|
||||||
|
@ -196,9 +196,9 @@ namespace Bit.App.Pages
|
||||||
moreAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
|
moreAction.SetBinding(MenuItem.CommandParameterProperty, new Binding("."));
|
||||||
moreAction.Clicked += MoreAction_Clicked;
|
moreAction.Clicked += MoreAction_Clicked;
|
||||||
|
|
||||||
SetBinding(CommandParameterProperty, new Binding("."));
|
//SetBinding(CommandParameterProperty, new Binding("."));
|
||||||
this.SetBinding<VaultListPageModel.Site>(TextProperty, s => s.Name);
|
Label.SetBinding<VaultListPageModel.Site>(Label.TextProperty, s => s.Name);
|
||||||
this.SetBinding<VaultListPageModel.Site>(DetailProperty, s => s.Username);
|
Detail.SetBinding<VaultListPageModel.Site>(Label.TextProperty, s => s.Username);
|
||||||
|
|
||||||
ContextActions.Add(deleteAction);
|
ContextActions.Add(deleteAction);
|
||||||
ContextActions.Add(moreAction);
|
ContextActions.Add(moreAction);
|
||||||
|
@ -218,8 +218,8 @@ namespace Bit.App.Pages
|
||||||
private void VaultListViewCell_DisclousureTapped(object sender, EventArgs e)
|
private void VaultListViewCell_DisclousureTapped(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var cell = sender as VaultListViewCell;
|
var cell = sender as VaultListViewCell;
|
||||||
var site = cell.CommandParameter as VaultListPageModel.Site;
|
//var site = cell.CommandParameter as VaultListPageModel.Site;
|
||||||
_page.MoreClickedAsync(site);
|
// _page.MoreClickedAsync(site);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
40
src/iOS/Controls/CustomButtonRenderer.cs
Normal file
40
src/iOS/Controls/CustomButtonRenderer.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
using System;
|
||||||
|
using Bit.iOS.Controls;
|
||||||
|
using UIKit;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Platform.iOS;
|
||||||
|
|
||||||
|
[assembly: ExportRenderer(typeof(Button), typeof(CustomButtonRenderer))]
|
||||||
|
namespace Bit.iOS.Controls
|
||||||
|
{
|
||||||
|
public class CustomButtonRenderer : ButtonRenderer
|
||||||
|
{
|
||||||
|
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
|
||||||
|
{
|
||||||
|
base.OnElementChanged(e);
|
||||||
|
|
||||||
|
var view = e.NewElement as Button;
|
||||||
|
if(Control != null && view != null)
|
||||||
|
{
|
||||||
|
var descriptor = UIFontDescriptor.PreferredBody;
|
||||||
|
var pointSize = descriptor.PointSize;
|
||||||
|
|
||||||
|
var size = view.FontSize;
|
||||||
|
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Button)))
|
||||||
|
{
|
||||||
|
pointSize *= 1.4f;
|
||||||
|
}
|
||||||
|
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Button)))
|
||||||
|
{
|
||||||
|
pointSize *= .8f;
|
||||||
|
}
|
||||||
|
else if(size == Device.GetNamedSize(NamedSize.Micro, typeof(Button)))
|
||||||
|
{
|
||||||
|
pointSize *= .6f;
|
||||||
|
}
|
||||||
|
|
||||||
|
Control.Font = UIFont.FromDescriptor(descriptor, pointSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ namespace Bit.iOS.Controls
|
||||||
var size = view.FontSize;
|
var size = view.FontSize;
|
||||||
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label)))
|
if(size == Device.GetNamedSize(NamedSize.Large, typeof(Label)))
|
||||||
{
|
{
|
||||||
pointSize *= 1.7f;
|
pointSize *= 1.4f;
|
||||||
}
|
}
|
||||||
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label)))
|
else if(size == Device.GetNamedSize(NamedSize.Small, typeof(Label)))
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,7 @@ namespace Bit.iOS.Controls
|
||||||
pointSize *= .6f;
|
pointSize *= .6f;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIFont.FromDescriptor(descriptor, pointSize);
|
Control.Font = UIFont.FromDescriptor(descriptor, pointSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,8 @@ namespace Bit.iOS.Controls
|
||||||
var view = e.NewElement as ExtendedEntry;
|
var view = e.NewElement as ExtendedEntry;
|
||||||
if(view != null)
|
if(view != null)
|
||||||
{
|
{
|
||||||
UIFont.FromDescriptor(UIFontDescriptor.PreferredBody, 1.0f);
|
var descriptor = UIFontDescriptor.PreferredBody;
|
||||||
|
Control.Font = UIFont.FromDescriptor( descriptor, descriptor.PointSize );
|
||||||
|
|
||||||
SetBorder(view);
|
SetBorder(view);
|
||||||
SetMaxLength(view);
|
SetMaxLength(view);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Bit.App.Controls;
|
using Bit.App.Controls;
|
||||||
using Bit.iOS.Controls;
|
using Bit.iOS.Controls;
|
||||||
|
using CoreGraphics;
|
||||||
using UIKit;
|
using UIKit;
|
||||||
using Xamarin.Forms;
|
using Xamarin.Forms;
|
||||||
using Xamarin.Forms.Platform.iOS;
|
using Xamarin.Forms.Platform.iOS;
|
||||||
|
@ -17,6 +18,31 @@ namespace Bit.iOS.Controls
|
||||||
if(cell != null)
|
if(cell != null)
|
||||||
{
|
{
|
||||||
cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor();
|
cell.BackgroundColor = extendedCell.BackgroundColor.ToUIColor();
|
||||||
|
if(extendedCell.ShowDisclousure)
|
||||||
|
{
|
||||||
|
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
|
||||||
|
if(!string.IsNullOrEmpty(extendedCell.DisclousureImage))
|
||||||
|
{
|
||||||
|
var detailDisclosureButton = UIButton.FromType(UIButtonType.Custom);
|
||||||
|
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Normal);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage + "_selected"), UIControlState.Selected);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
detailDisclosureButton.SetImage(UIImage.FromBundle(extendedCell.DisclousureImage), UIControlState.Selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
detailDisclosureButton.Frame = new CGRect(0f, 0f, 50f, 40f);
|
||||||
|
detailDisclosureButton.TouchUpInside += (sender, e) =>
|
||||||
|
{
|
||||||
|
extendedCell.OnDisclousureTapped();
|
||||||
|
};
|
||||||
|
cell.AccessoryView = detailDisclosureButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cell;
|
return cell;
|
||||||
|
|
|
@ -101,6 +101,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Controls\ContentPageRenderer.cs" />
|
<Compile Include="Controls\ContentPageRenderer.cs" />
|
||||||
|
<Compile Include="Controls\CustomButtonRenderer.cs" />
|
||||||
<Compile Include="Controls\CustomLabelRenderer.cs" />
|
<Compile Include="Controls\CustomLabelRenderer.cs" />
|
||||||
<Compile Include="Controls\ExtendedSwitchCellRenderer.cs" />
|
<Compile Include="Controls\ExtendedSwitchCellRenderer.cs" />
|
||||||
<Compile Include="Controls\ListViewRenderer.cs" />
|
<Compile Include="Controls\ListViewRenderer.cs" />
|
||||||
|
|
Loading…
Reference in a new issue