diff --git a/src/Android/MainActivity.cs b/src/Android/MainActivity.cs index 39fdfa6f1..8d5385e37 100644 --- a/src/Android/MainActivity.cs +++ b/src/Android/MainActivity.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Android.App; using Android.Content; using Android.Content.PM; +using Android.Content.Res; using Android.Nfc; using Android.OS; using Android.Runtime; @@ -18,7 +19,9 @@ using Bit.Core.Enums; using Bit.Core.Utilities; using Bit.Droid.Receivers; using Bit.Droid.Utilities; +using Xamarin.Essentials; using ZXing.Net.Mobile.Android; +using FileProvider = AndroidX.Core.Content.FileProvider; namespace Bit.Droid { @@ -35,6 +38,7 @@ namespace Bit.Droid private IStateService _stateService; private IAppIdService _appIdService; private IEventService _eventService; + private ILogger _logger; private PendingIntent _eventUploadPendingIntent; private AppOptions _appOptions; private string _activityKey = $"{nameof(MainActivity)}_{Java.Lang.JavaSystem.CurrentTimeMillis().ToString()}"; @@ -56,6 +60,7 @@ namespace Bit.Droid _stateService = ServiceContainer.Resolve("stateService"); _appIdService = ServiceContainer.Resolve("appIdService"); _eventService = ServiceContainer.Resolve("eventService"); + _logger = ServiceContainer.Resolve("logger"); TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; @@ -70,7 +75,7 @@ namespace Bit.Droid Window.AddFlags(Android.Views.WindowManagerFlags.Secure); }); - ServiceContainer.Resolve("logger").InitAsync(); + _logger.InitAsync(); var toplayout = Window?.DecorView?.RootView; if (toplayout != null) @@ -82,7 +87,7 @@ namespace Bit.Droid Xamarin.Forms.Forms.Init(this, savedInstanceState); _appOptions = GetOptions(); LoadApplication(new App.App(_appOptions)); - + DisableAndroidFontScale(); _broadcasterService.Subscribe(_activityKey, (message) => { @@ -401,5 +406,19 @@ namespace Bit.Droid alarmManager.Cancel(_eventUploadPendingIntent); await _eventService.UploadEventsAsync(); } + + private void DisableAndroidFontScale() + { + try + { + //As we are using NamedSizes the xamarin will change the font size. So we are disabling the Android scaling. + Resources.Configuration.FontScale = 1f; + BaseContext.Resources.DisplayMetrics.ScaledDensity = Resources.Configuration.FontScale * (float)DeviceDisplay.MainDisplayInfo.Density; + } + catch (Exception e) + { + _logger.Exception(e); + } + } } }