From 0cdba2a13d76974d3e661370c2e2b766ab665ce4 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 25 Aug 2016 21:43:47 -0400 Subject: [PATCH] Added Scale to device info service. Stack layout padding adjsutments depending on android scale. --- src/Android/Services/DeviceInfoService.cs | 37 ++++++++++++++++++- .../Services/IDeviceInfoService.cs | 1 + src/App/App.cs | 10 +---- src/App/Controls/FormEditorCell.cs | 1 + src/App/Controls/FormEntryCell.cs | 7 +++- src/App/Controls/FormPickerCell.cs | 1 + src/App/Controls/LabeledValueCell.cs | 3 ++ src/App/Controls/StepperCell.cs | 1 + src/App/Pages/Tools/ToolsPage.cs | 2 + .../Pages/Tools/ToolsPasswordGeneratorPage.cs | 1 + src/App/Utilities/Extentions.cs | 24 ++++++++++++ src/iOS.Core/Services/DeviceInfoService.cs | 1 + 12 files changed, 79 insertions(+), 10 deletions(-) diff --git a/src/Android/Services/DeviceInfoService.cs b/src/Android/Services/DeviceInfoService.cs index 0117b5e0d..e206e22cf 100644 --- a/src/Android/Services/DeviceInfoService.cs +++ b/src/Android/Services/DeviceInfoService.cs @@ -1,4 +1,6 @@ +using Android.App; using Android.OS; +using Android.Util; using Bit.App.Abstractions; namespace Bit.Android.Services @@ -7,5 +9,38 @@ namespace Bit.Android.Services { public string Model => Build.Model; public int Version => (int)Build.VERSION.SdkInt; + public float Scale + { + get + { + var density = Application.Context.Resources.DisplayMetrics.Density; + if(density <= 0.75) + { + return 0.75f; + } + else if(density <= 1) + { + return 1f; + } + else if(density <= 1.5) + { + return 1.5f; + } + else if(density <= 2) + { + return 2f; + } + else if(density <= 3) + { + return 3f; + } + else if(density <= 4) + { + return 4f; + } + + return 1f; + } + } } -} \ No newline at end of file +} diff --git a/src/App/Abstractions/Services/IDeviceInfoService.cs b/src/App/Abstractions/Services/IDeviceInfoService.cs index 5a5e31b00..6c08cc187 100644 --- a/src/App/Abstractions/Services/IDeviceInfoService.cs +++ b/src/App/Abstractions/Services/IDeviceInfoService.cs @@ -4,5 +4,6 @@ { string Model { get; } int Version { get; } + float Scale { get; } } } diff --git a/src/App/App.cs b/src/App/App.cs index abbc8211f..54140a2ed 100644 --- a/src/App/App.cs +++ b/src/App/App.cs @@ -113,7 +113,7 @@ namespace Bit.App var lockPinPage = Current.MainPage.Navigation.ModalStack.LastOrDefault() as LockPinPage; if(lockPinPage != null) { - lockPinPage.PinControl.Entry.Focus(); + lockPinPage.PinControl.Entry.FocusWithDelay(); } } @@ -228,13 +228,7 @@ namespace Bit.App await Current.MainPage.Navigation.PushModalAsync(new ExtendedNavigationPage(new LockFingerprintPage(!forceLock)), false); break; case Enums.LockType.PIN: - var lockPinPage = (currentPage?.CurrentPage as LockPinPage); - if(lockPinPage == null) - { - lockPinPage = new LockPinPage(); - await Current.MainPage.Navigation.PushModalAsync(new ExtendedNavigationPage(lockPinPage), false); - lockPinPage.PinControl.Entry.Focus(); - } + await Current.MainPage.Navigation.PushModalAsync(new ExtendedNavigationPage(new LockPinPage()), false); break; case Enums.LockType.Password: await Current.MainPage.Navigation.PushModalAsync(new ExtendedNavigationPage(new LockPasswordPage()), false); diff --git a/src/App/Controls/FormEditorCell.cs b/src/App/Controls/FormEditorCell.cs index f323bc14c..2fe9d28bb 100644 --- a/src/App/Controls/FormEditorCell.cs +++ b/src/App/Controls/FormEditorCell.cs @@ -28,6 +28,7 @@ namespace Bit.App.Controls Tapped += FormEditorCell_Tapped; Editor.AdjustMarginsForDevice(); + stackLayout.AdjustPaddingForDevice(); View = stackLayout; } diff --git a/src/App/Controls/FormEntryCell.cs b/src/App/Controls/FormEntryCell.cs index b6c48e4e7..8e98ee013 100644 --- a/src/App/Controls/FormEntryCell.cs +++ b/src/App/Controls/FormEntryCell.cs @@ -86,7 +86,7 @@ namespace Bit.App.Controls { if(deviceInfo.Version < 21) { - Entry.Margin = new Thickness(-9, 0); + Entry.Margin = new Thickness(-9, 1, -9, 0); } else if(deviceInfo.Version == 21) { @@ -97,6 +97,11 @@ namespace Bit.App.Controls { Entry.AdjustMarginsForDevice(); } + + if(containerPadding == null) + { + imageStackLayout.AdjustPaddingForDevice(); + } } if(!useLabelAsPlaceholder) diff --git a/src/App/Controls/FormPickerCell.cs b/src/App/Controls/FormPickerCell.cs index a9d40a8f6..bd95aba5f 100644 --- a/src/App/Controls/FormPickerCell.cs +++ b/src/App/Controls/FormPickerCell.cs @@ -40,6 +40,7 @@ namespace Bit.App.Controls stackLayout.Spacing = 0; } Picker.AdjustMarginsForDevice(); + stackLayout.AdjustPaddingForDevice(); Tapped += FormPickerCell_Tapped; diff --git a/src/App/Controls/LabeledValueCell.cs b/src/App/Controls/LabeledValueCell.cs index 0bce6b117..4285a6813 100644 --- a/src/App/Controls/LabeledValueCell.cs +++ b/src/App/Controls/LabeledValueCell.cs @@ -92,6 +92,9 @@ namespace Bit.App.Controls { Button2.Padding = new Thickness(5); } + + + containerStackLayout.AdjustPaddingForDevice(); } containerStackLayout.Children.Add(buttonStackLayout); diff --git a/src/App/Controls/StepperCell.cs b/src/App/Controls/StepperCell.cs index fdb566ba0..ca2e436a0 100644 --- a/src/App/Controls/StepperCell.cs +++ b/src/App/Controls/StepperCell.cs @@ -51,6 +51,7 @@ namespace Bit.App.Controls { Label.TextColor = Color.Black; } + stackLayout.AdjustPaddingForDevice(); View = stackLayout; } diff --git a/src/App/Pages/Tools/ToolsPage.cs b/src/App/Pages/Tools/ToolsPage.cs index 41501f119..d8518019d 100644 --- a/src/App/Pages/Tools/ToolsPage.cs +++ b/src/App/Pages/Tools/ToolsPage.cs @@ -139,6 +139,8 @@ namespace Bit.App.Pages WinPhone: new Thickness(15, 25)) }; + containerStackLayout.AdjustPaddingForDevice(); + ShowDisclousure = true; View = containerStackLayout; } diff --git a/src/App/Pages/Tools/ToolsPasswordGeneratorPage.cs b/src/App/Pages/Tools/ToolsPasswordGeneratorPage.cs index ee698395a..3ee148775 100644 --- a/src/App/Pages/Tools/ToolsPasswordGeneratorPage.cs +++ b/src/App/Pages/Tools/ToolsPasswordGeneratorPage.cs @@ -215,6 +215,7 @@ namespace Bit.App.Pages WinPhone: new Thickness(15, 8)) }; + stackLayout.AdjustPaddingForDevice(); if(Device.OS == TargetPlatform.Android) { label.TextColor = Color.Black; diff --git a/src/App/Utilities/Extentions.cs b/src/App/Utilities/Extentions.cs index 529820663..61a11ca0f 100644 --- a/src/App/Utilities/Extentions.cs +++ b/src/App/Utilities/Extentions.cs @@ -64,5 +64,29 @@ namespace Bit.App } } } + + public static void AdjustPaddingForDevice(this StackLayout view) + { + if(Device.OS == TargetPlatform.Android) + { + var deviceInfo = Resolver.Resolve(); + if(deviceInfo.Scale == 1) // mdpi + { + view.Padding = new Thickness(21, view.Padding.Top, 21, view.Padding.Bottom); + } + else if(deviceInfo.Scale < 2) // hdpi + { + view.Padding = new Thickness(19, view.Padding.Top, 19, view.Padding.Bottom); + } + else if(deviceInfo.Scale < 3) // xhdpi + { + view.Padding = new Thickness(17, view.Padding.Top, 17, view.Padding.Bottom); + } + else // xxhdpi and xxxhdpi + { + view.Padding = new Thickness(15, view.Padding.Top, 15, view.Padding.Bottom); + } + } + } } } diff --git a/src/iOS.Core/Services/DeviceInfoService.cs b/src/iOS.Core/Services/DeviceInfoService.cs index 6240fdc4e..646bbd69e 100644 --- a/src/iOS.Core/Services/DeviceInfoService.cs +++ b/src/iOS.Core/Services/DeviceInfoService.cs @@ -21,5 +21,6 @@ namespace Bit.iOS.Core.Services return -1; } } + public float Scale => (float)UIScreen.MainScreen.Scale; } }