-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarcodeCustomOverlay.cs
More file actions
137 lines (114 loc) · 3.46 KB
/
BarcodeCustomOverlay.cs
File metadata and controls
137 lines (114 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Platform;
using Plugin.Scanner.Core;
using ContentView = Microsoft.Maui.Controls.ContentView;
#if IOS
using UIKit;
#endif
#if ANDROID
using Android.App;
using Android.Views;
using View = Android.Views.View;
#endif
namespace Plugin.Scanner.Maui.Tests;
public class BarcodeCustomOverlay : IOverlay
{
#if IOS
private UIViewController? _viewController;
#endif
#if ANDROID
private View? _root;
#endif
public void Dispose()
{
}
public void AddOverlay()
{
Border boxView = new()
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Start,
Padding = new Thickness(20),
Background = new SolidColorBrush(Colors.Transparent),
Stroke = new SolidColorBrush(Colors.Green),
StrokeThickness = 5,
StrokeShape = new RoundRectangle
{
CornerRadius = new CornerRadius(20),
},
Content = new Label { Text = "I'm a custom overlay!" }
};
VerticalStackLayout stack = new()
{
Margin = new Thickness(0, 100)
};
stack.Add(boxView);
IMauiContext? context = Microsoft.Maui.Controls.Application.Current?.Handler?.MauiContext;
if (context is null)
{
return;
}
#if IOS
_viewController?.View?.Add(new ContentView { Content = stack }.ToPlatform(context));
#endif
#if ANDROID
if (_root is ViewGroup viewGroup)
{
View platformView = new ContentView {Content = stack }.ToPlatform(context);
viewGroup.AddView(platformView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
}
#endif
}
public void AddRegionOfInterest(IRegionOfInterest? regionOfInterest)
{
Border boxView = new()
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.End,
StrokeThickness = 5,
Padding = new Thickness(20),
Background = new SolidColorBrush(Colors.Transparent),
Stroke = new SolidColorBrush(Colors.Blue),
StrokeShape = new RoundRectangle
{
CornerRadius = new CornerRadius(20),
},
Content = new Label { Text = "I'm a custom region of interest!" }
};
Grid grid = new()
{
Margin = new Thickness(0, 100)
};
grid.Add(boxView);
IMauiContext? context = Microsoft.Maui.Controls.Application.Current?.Handler?.MauiContext;
if (context is null)
{
return;
}
#if IOS
_viewController?.View?.Add(new ContentView {Content = grid }.ToPlatform(context));
#endif
#if ANDROID
if (_root is ViewGroup viewGroup)
{
View platformView = new ContentView {Content = grid }.ToPlatform(context);
viewGroup.AddView(platformView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
}
#endif
}
public void Cleanup()
{
}
#if IOS
public void Init(UIViewController viewController)
{
_viewController = viewController;
}
#endif
#if ANDROID
public void Init(Dialog dialog, View root)
{
_root = root;
}
#endif
}