Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Adds Windows8 implementation (scan method only)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrebnov authored and Ryan Willoughby committed Jul 31, 2014
1 parent 2a2fc65 commit 3a7d761
Show file tree
Hide file tree
Showing 9 changed files with 577 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,15 @@
<string name="wifi_type_label">Type</string>
</config-file>
</platform>

<platform name="windows8">
<js-module src="src/windows8/BarcodeScannerProxy.js" name="BarcodeScannerProxy">
<merges target="" />
</js-module>
<config-file target="package.appxmanifest" parent="/Package/Capabilities">
<DeviceCapability Name="webcam" />
</config-file>
<framework src="src/windows8/lib/ZXing.winmd" custom="true" />
<framework src="src/windows8/lib/WinRTBarcodeReader.winmd" custom="true" />
</platform>
</plugin>
130 changes: 130 additions & 0 deletions src/windows8/BarcodeScannerProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* 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.
*/

module.exports = {

/**
* Scans image via device camera and retieves barcode from it.
* @param {function} success Success callback
* @param {function} fail Error callback
* @param {array} args Arguments array
*/
scan: function (success, fail, args) {

var capturePreview = null,
captureCancelButton = null,
capture = null,
captureSettings = null,
reader = null,

/* Width of bitmap, generated from capture stream and used for barcode search */
bitmapWidth = 800,
/* Width of bitmap, generated from capture stream and used for barcode search */
bitmapHeight = 600;

/**
* Creates a preview frame and necessary objects
*/
function createPreview() {

// Create fullscreen preview
capturePreview = document.createElement("video");
capturePreview.style.cssText = "position: absolute; left: 0; top: 0; width: 100%; height: 100%";

// Create cancel button
captureCancelButton = document.createElement("button");
captureCancelButton.innerText = "Cancel";
captureCancelButton.style.cssText = "position: absolute; right: 0; bottom: 0; display: block; margin: 20px";
captureCancelButton.addEventListener('click', cancelPreview, false);

capture = new Windows.Media.Capture.MediaCapture();

captureSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
captureSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.video;
}

/**
* Starts stream transmission to preview frame and then run barcode search
*/
function startPreview() {
capture.initializeAsync(captureSettings).done(function () {
capturePreview.src = URL.createObjectURL(capture);
capturePreview.play();

// Insert preview frame and controls into page
document.body.appendChild(capturePreview);
document.body.appendChild(captureCancelButton);

startBarcodeSearch();
});
}

/**
* Starts barcode search process, implemented in WinRTBarcodeReader.winmd library
* Calls success callback, when barcode found.
*/
function startBarcodeSearch() {
reader = new WinRTBarcodeReader.Reader(capture, bitmapWidth, bitmapHeight);
var readOp = reader.readCode();
readOp.done(function (result) {
destroyPreview();
success({ text: result.text, format: result.barcodeFormat, cancelled: false });
});
}

/**
* Removes preview frame and corresponding objects from window
*/
function destroyPreview() {
capturePreview.pause();
capturePreview.src = null;
[capturePreview, captureCancelButton].forEach(function (elem) {
if (elem /* && elem in document.body.childNodes */) {
document.body.removeChild(elem);
}
});
if (reader) {
reader.stop();
reader = null;
}
if (capture) {
capture.stopRecordAsync();
capture = null;
}
}

/**
* Stops preview and then call success callback with cancelled=true
* See https://github.com/phonegap-build/BarcodeScanner#using-the-plugin
*/
function cancelPreview() {
destroyPreview();
success({ text: null, format: null, cancelled: true });
}

try {
createPreview();
startPreview();
} catch (ex) {
fail(ex);
}
},

/**
* Encodes specified data into barcode
* @param {function} success Success callback
* @param {function} fail Error callback
* @param {array} args Arguments array
*/
encode: function (success, fail, args) {
fail("Not implemented yet");
}
};
require("cordova/windows8/commandProxy").add("BarcodeScanner", module.exports);
Binary file added src/windows8/lib/WinRTBarcodeReader.winmd
Binary file not shown.
39 changes: 39 additions & 0 deletions src/windows8/lib/WinRTBarcodeReader/WinRTBarcodeReader.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30324.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinRTBarcodeReader", "WinRTBarcodeReader\WinRTBarcodeReader.csproj", "{01412F36-3781-4AF0-903C-ACEA7552C99C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Debug|ARM.ActiveCfg = Debug|ARM
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Debug|ARM.Build.0 = Debug|ARM
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Debug|x64.ActiveCfg = Debug|x64
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Debug|x64.Build.0 = Debug|x64
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Debug|x86.ActiveCfg = Debug|x86
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Debug|x86.Build.0 = Debug|x86
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Release|Any CPU.Build.0 = Release|Any CPU
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Release|ARM.ActiveCfg = Release|ARM
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Release|ARM.Build.0 = Release|ARM
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Release|x64.ActiveCfg = Release|x64
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Release|x64.Build.0 = Release|x64
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Release|x86.ActiveCfg = Release|x86
{01412F36-3781-4AF0-903C-ACEA7552C99C}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.
*/

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WindowsRuntimeComponent1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WindowsRuntimeComponent1")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]
Loading

0 comments on commit 3a7d761

Please sign in to comment.