-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMainPage.xaml.cs
88 lines (83 loc) · 3.4 KB
/
MainPage.xaml.cs
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
namespace DocumentReaderSample;
public partial class MainPage : ContentPage
{
static readonly bool btDeviceSample = false;
readonly IDocReaderScanner docReaderScanner;
static List<string> Scenarios = [];
public MainPage()
{
InitializeComponent();
Application.Current.UserAppTheme = AppTheme.Light;
Application.Current.RequestedThemeChanged += (s, a) => { Application.Current.UserAppTheme = AppTheme.Light; };
// Fix disappearing selection in iOS
Loaded += (object sender, EventArgs e) =>
{
if (Scenarios.Count > 0)
ScenariosListView.UpdateSelectedItems([ScenariosListView.SelectedItem]);
};
docReaderScanner = DependencyService.Get<IDocReaderScanner>();
docReaderScanner.ResultsObtained += (object s, IDocReaderScannerEvent e) =>
{
NamesLabels.Text = e.SurnameAndGivenNames;
if (e.PortraitField != null)
PortraitImage.Source = ImageSource.FromStream(() => { return new MemoryStream(e.PortraitField); });
if (e.DocumentField != null)
DocumentImage.Source = ImageSource.FromStream(() => { return new MemoryStream(e.DocumentField); });
};
if (btDeviceSample)
{
NamesLabels.Text = "Connect btDevice.";
StartServiceButton.IsVisible = true;
BTDeviceName.IsVisible = true;
RecognizeButton.IsVisible = false;
return;
}
IDocReaderInit docReaderInit = DependencyService.Get<IDocReaderInit>();
docReaderInit.ScenariosObtained += (object sender, IDocReaderInitEvent e) =>
{
if (e.IsSuccess)
{
foreach (Scenario scenario in e.Scenarios) { Scenarios.Add(scenario.Name); }
ScenariosListView.ItemsSource = Scenarios;
ScenariosListView.SelectedItem = Scenarios[0];
ScenariosListView.SelectionChanged += (object sender, SelectionChangedEventArgs e) =>
{
string scenario = e.CurrentSelection.FirstOrDefault() as string;
docReaderScanner.SelectScenario(scenario);
};
RfidLayout.IsVisible = e.IsRfidAvailable;
NamesLabels.Text = "Ready";
}
else NamesLabels.Text = "Init failed";
};
NamesLabels.Text = "Initializing...";
docReaderInit.InitDocReader();
}
void ShowScanner_Clicked(object sender, EventArgs evt)
{
ClearResults();
docReaderScanner.ShowScanner(ReadRfidCb.IsChecked);
}
async void RecognizeImage_Clicked(object sender, EventArgs evt)
{
ClearResults();
Stream stream = await DependencyService.Get<IPhotoPickerService>().GetImageStreamAsync();
if (stream != null)
{
NamesLabels.Text = "Recognize image...";
docReaderScanner.RecognizeImage(stream, ReadRfidCb.IsChecked);
}
(sender as Button).IsEnabled = true;
}
void ClearResults()
{
NamesLabels.Text = "";
PortraitImage.Source = "mainpage_portrait_icon.png";
DocumentImage.Source = "mainpage_id_icon.png";
}
void StartService_Clicked(object sender, EventArgs evt)
{
IDocReaderInit docReaderInit = DependencyService.Get<IDocReaderInit>();
docReaderInit.CheckPermissionsAndConnect(BTDeviceName.Text);
}
}