You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

104 lines
3.5 KiB
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

/*
* Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
namespace WPCordovaClassLib.Cordova.Commands
{
using System;
using System.Windows;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;
using ZXing;
/// <summary>
/// Class that represents barcode scanner task that mimics standart WP8 tasks.
/// </summary>
public class BarcodeScannerTask
{
/// <summary>
/// Occurs when task is [completed].
/// </summary>
public event EventHandler<ScanResult> Completed;
/// <summary>
/// Shows barcode scanner interface.
/// </summary>
public void Show()
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
var root = Application.Current.RootVisual as PhoneApplicationFrame;
if (root == null)
{
return;
}
root.Navigated += this.OnNavigated;
root.Navigate(new Uri("/Plugins/phonegap-plugin-barcodescanner/BarcodeScannerUI.xaml", UriKind.Relative));
});
}
/// <summary>
/// Called when [navigated].
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="NavigationEventArgs"/> instance containing the event data.</param>
private void OnNavigated(object sender, NavigationEventArgs e)
{
if (!(e.Content is BarcodeScannerUI))
{
return;
}
var phoneApplicationFrame = Application.Current.RootVisual as PhoneApplicationFrame;
if (phoneApplicationFrame != null)
{
phoneApplicationFrame.Navigated -= this.OnNavigated;
}
var barcodeScanner = (BarcodeScannerUI)e.Content;
if (barcodeScanner != null)
{
barcodeScanner.Completed += this.Completed;
}
else if (this.Completed != null)
{
this.Completed(this, new ScanResult(TaskResult.Cancel));
}
}
/// <summary>
/// Represents barcode scan result.
/// </summary>
public class ScanResult : TaskEventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="ScanResult"/> class.
/// </summary>
/// <param name="taskResult">One of the enumeration values that specifies the status of the task.</param>
public ScanResult(TaskResult taskResult)
: base(taskResult)
{
}
/// <summary>
/// Gets the barcode scan result.
/// </summary>
/// <value>
/// The barcode scan result.
/// </value>
public Result Barcode { get; internal set; }
}
}
}