From fa4a2247e38fe19a96e2d7aab534e2464d7d9ee0 Mon Sep 17 00:00:00 2001 From: Dinis Vieira Date: Sat, 23 Dec 2023 23:09:11 +0000 Subject: [PATCH] PM-3349 Changed the "track color" for the Android switch so that the color is different from the "thumb" --- .../Android/Handlers/SwitchHandlerMappings.cs | 28 +++++++++++++++++++ src/Core/Resources/Styles/Android.xaml | 5 ---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/App/Platforms/Android/Handlers/SwitchHandlerMappings.cs b/src/App/Platforms/Android/Handlers/SwitchHandlerMappings.cs index ac287bb66..d1461e3e9 100644 --- a/src/App/Platforms/Android/Handlers/SwitchHandlerMappings.cs +++ b/src/App/Platforms/Android/Handlers/SwitchHandlerMappings.cs @@ -2,7 +2,10 @@ using Android.Graphics.Drawables; using Android.OS; using AndroidX.Core.Content.Resources; +using AndroidX.Core.Graphics; using Bit.App.Droid.Utilities; +using Bit.App.Utilities; +using Microsoft.Maui.Platform; namespace Bit.App.Handlers { @@ -37,6 +40,31 @@ namespace Bit.App.Handlers }; handler.PlatformView.ThumbTintList = new ColorStateList(thumbStates, thumbColors); }); + + Microsoft.Maui.Handlers.SwitchHandler.Mapper.AppendToMapping(nameof(ISwitch.TrackColor), (handler, mauiSwitch) => + { + var trackStates = new[] + { + new[] { Android.Resource.Attribute.StateChecked }, // checked + new[] { -Android.Resource.Attribute.StateChecked }, // unchecked + }; + + var selectedColor = ColorUtils.BlendARGB(ThemeHelpers.SwitchOnColor.ToArgb(), Colors.Black.ToPlatform().ToArgb(), 0.5f); + var unselectedColor = ColorUtils.BlendARGB(ThemeHelpers.SwitchThumbColor.ToArgb(), Colors.Black.ToPlatform().ToArgb(), 0.7f); + if (ThemeManager.UsingLightTheme) + { + selectedColor = ColorUtils.BlendARGB(ThemeHelpers.SwitchOnColor.ToArgb(), Colors.White.ToPlatform().ToArgb(), 0.7f); + unselectedColor = ColorUtils.BlendARGB(ThemeHelpers.SwitchThumbColor.ToArgb(), Colors.Black.ToPlatform().ToArgb(), 0.3f); + } + + var trackColors = new int[] + { + selectedColor, + unselectedColor + }; + + handler.PlatformView.TrackTintList = new ColorStateList(trackStates, trackColors); + }); } } } diff --git a/src/Core/Resources/Styles/Android.xaml b/src/Core/Resources/Styles/Android.xaml index b73356631..91e4ac7b6 100644 --- a/src/Core/Resources/Styles/Android.xaml +++ b/src/Core/Resources/Styles/Android.xaml @@ -42,11 +42,6 @@ -