Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BlurProtectionManager.cs
1using Plugin.Maui.ScreenSecurity.Handlers;
2using UIKit;
3
4namespace NeuroAccessMaui
5{
6 internal class BlurProtectionManager
7 {
8 private static UIVisualEffectView? _blurBackground = null;
9
10 internal static void HandleBlurProtection(bool enabled, ThemeStyle? style = null, UIWindow? window = null)
11 {
12 UIApplication.Notifications.ObserveWillResignActive((sender, args) =>
13 {
14 try
15 {
16 if (enabled)
17 EnableBlurScreenProtection(window, style);
18 else
19 DisableBlurScreenProtection();
20 }
21 catch (Exception ex)
22 {
23 ErrorsHandler.HandleException(nameof(HandleBlurProtection), ex);
24 }
25 });
26
27 UIApplication.Notifications.ObserveDidBecomeActive((sender, args) =>
28 {
29 try
30 {
31 DisableBlurScreenProtection();
32 }
33 catch (Exception ex)
34 {
35 ErrorsHandler.HandleException(nameof(HandleBlurProtection), ex);
36 }
37 });
38 }
39
40 internal static void EnableBlur(UIWindow? window, ThemeStyle style)
41 {
42 try
43 {
44 EnableBlurScreenProtection(window, style);
45 }
46 catch (Exception ex)
47 {
48 ErrorsHandler.HandleException(nameof(EnableBlur), ex);
49 }
50 }
51
52 internal static void DisableBlur()
53 {
54 try
55 {
56 DisableBlurScreenProtection();
57 }
58 catch (Exception ex)
59 {
60 ErrorsHandler.HandleException(nameof(DisableBlur), ex);
61 }
62 }
63
64 private static void EnableBlurScreenProtection(UIWindow? window = null, ThemeStyle? style = null)
65 {
66 if (window != null)
67 {
68 var blurEffectStyle = style switch
69 {
70 ThemeStyle.Light => UIBlurEffectStyle.Light,
71 _ => UIBlurEffectStyle.Dark
72 };
73
74 using var blurEffect = UIBlurEffect.FromStyle(blurEffectStyle);
75
76 _blurBackground = new UIVisualEffectView(blurEffect)
77 {
78 Frame = window.Frame
79 };
80
81 window.AddSubview(_blurBackground);
82 }
83 }
84
85 private static void DisableBlurScreenProtection()
86 {
87 _blurBackground?.RemoveFromSuperview();
88
89 _blurBackground = null;
90 }
91 }
92}