Repository navigation
Expand file tree
/
Copy pathBarcodeScanner.cs
More file actions
62 lines (53 loc) · 2.14 KB
/
Copy pathBarcodeScanner.cs
File metadata and controls
62 lines (53 loc) · 2.14 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
using System.Runtime.Serialization;
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
using WPCordovaClassLib.Cordova.JSON;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using System.Windows;
namespace org.apache.cordova
{
public class barcodeScanner : WPCordovaClassLib.Cordova.Commands.BaseCommand
{
public void scan(string options)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var root = Application.Current.RootVisual as PhoneApplicationFrame;
root.Navigated += new System.Windows.Navigation.NavigatedEventHandler(root_Navigated);
root.Navigate(new System.Uri("/BarcodeScanner;component/Scanner.xaml?dummy=" + Guid.NewGuid().ToString(), UriKind.Relative));
});
}
void root_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
if (!(e.Content is BarcodeScanner.Scanner)) return;
(Application.Current.RootVisual as PhoneApplicationFrame).Navigated -= root_Navigated;
BarcodeScanner.Scanner scanner = (BarcodeScanner.Scanner)e.Content;
if (scanner != null)
{
scanner.Completed += new EventHandler<BarcodeScanner.ScannerResult>(scanner_Completed);
}
}
void scanner_Completed(object sender, BarcodeScanner.ScannerResult e)
{
if (e.TaskResult == TaskResult.OK)
{
string result = String.Format("\"cancelled\":{0},\"text\":\"{1}\"", 0, e.ScanCode);
result = "{" + result + "}";
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, result));
}
else
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Failed to scan QR code"));
}
}
public void encode(string options)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Not implemented"));
}
}
}