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

Commit

Permalink
Merge pull request #1 from MSOpenTech/2.1-windows
Browse files Browse the repository at this point in the history
Introduces universal windows platform, improvements and bugfixing
  • Loading branch information
Tim Barham committed Apr 17, 2015
2 parents 47aa588 + 21083d4 commit 4e5af0c
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 256 deletions.
29 changes: 21 additions & 8 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
<license>MIT</license>

<repo>https://github.com/wildabeast/BarcodeScanner</repo>
<issue>https://github.com/wildabeast/BarcodeScanner/issues</issue>
<issue>https://github.com/wildabeast/BarcodeScanner/issues</issue>

<engines>
<engine name="cordova" version=">=3.0.0" />
</engines>
</engines>

<js-module src="www/barcodescanner.js" name="BarcodeScanner">
<clobbers target="cordova.plugins.barcodeScanner" />
Expand Down Expand Up @@ -52,7 +52,7 @@
<!--
<source-file src="R.java" target-dir="src/com/google/zxing/client/android" />
-->

<!--
<config-file target="res/xml/plugins.xml" parent="/plugins">
<plugin name="BarcodeScanner" value="com.phonegap.plugins.barcodescanner.BarcodeScanner"/>
Expand Down Expand Up @@ -107,7 +107,7 @@
search: (src/android/LibraryProject/(.+?)/[^/]+)$
replace: <source-file src="$1" target-dir="$2"/>
-->

<source-file src="src/android/LibraryProject/res/drawable/launcher_icon.png" target-dir="res/drawable"/>
<source-file src="src/android/LibraryProject/res/drawable/share_via_barcode.png" target-dir="res/drawable"/>
<source-file src="src/android/LibraryProject/res/drawable/shopper_icon.png" target-dir="res/drawable"/>
Expand Down Expand Up @@ -291,14 +291,27 @@
</platform>

<platform name="windows8">
<js-module src="src/windows8/BarcodeScannerProxy.js" name="BarcodeScannerProxy">
<js-module src="src/windows/BarcodeScannerProxy.js" name="BarcodeScannerProxy">
<merges target="" />
</js-module>

<config-file target="package.appxmanifest" parent="/Package/Capabilities">
<DeviceCapability Name="webcam" />
</config-file>

<framework src="src/windows/lib/WinRTBarcodeReader.csproj" custom="true" type="projectReference"/>
</platform>

<platform name="windows">
<js-module src="src/windows/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" />

<framework src="src/windows/lib/WinRTBarcodeReader.csproj" custom="true" type="projectReference"/>
</platform>

<!-- Windows Phone 8 -->
Expand Down
176 changes: 176 additions & 0 deletions src/windows/BarcodeScannerProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* 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,
capturePreviewAlignmentMark,
captureCancelButton,
capture,
reader;

/**
* 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%; background: black";

capturePreviewAlignmentMark = document.createElement('div');
capturePreviewAlignmentMark.style.cssText = "position: absolute; left: 0; top: 50%; width: 100%; height: 3px; background: red";

// 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();
}

/**
* Starts stream transmission to preview frame and then run barcode search
*/
function startPreview() {
var captureSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
captureSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.video;
captureSettings.photoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.videoPreview;

capture.initializeAsync(captureSettings).done(function () {

//trying to set focus mode
var controller = capture.videoDeviceController;

if (controller.focusControl && controller.focusControl.supported) {
if (controller.focusControl.configure) {
var focusConfig = new Windows.Media.Devices.FocusSettings();
focusConfig.autoFocusRange = Windows.Media.Devices.AutoFocusRange.macro;

var supportContinuousFocus = controller.focusControl.supportedFocusModes.indexOf(Windows.Media.Devices.FocusMode.continuous).returnValue;
var supportAutoFocus = controller.focusControl.supportedFocusModes.indexOf(Windows.Media.Devices.FocusMode.auto).returnValue;

if (supportContinuousFocus) {
focusConfig.mode = Windows.Media.Devices.FocusMode.continuous;
} else if (supportAutoFocus) {
focusConfig.mode = Windows.Media.Devices.FocusMode.auto;
}

controller.focusControl.configure(focusConfig);
controller.focusControl.focusAsync();
}
}

var deviceProps = controller.getAvailableMediaStreamProperties(Windows.Media.Capture.MediaStreamType.videoRecord);

deviceProps = Array.prototype.slice.call(deviceProps);
deviceProps = deviceProps.filter(function (prop) {
// filter out streams with "unknown" subtype - causes errors on some devices
return prop.subtype !== "Unknown";
}).sort(function (propA, propB) {
// sort properties by resolution
return propB.width - propA.width;
});

var maxResProps = deviceProps[0];

controller.setMediaStreamPropertiesAsync(Windows.Media.Capture.MediaStreamType.videoRecord, maxResProps).done(function () {
// handle portrait orientation
if (Windows.Graphics.Display.DisplayProperties.nativeOrientation == Windows.Graphics.Display.DisplayOrientations.portrait) {
capture.setPreviewRotation(Windows.Media.Capture.VideoRotation.clockwise90Degrees);
capturePreview.msZoom = true;
}

capturePreview.src = URL.createObjectURL(capture);
capturePreview.play();

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

startBarcodeSearch(maxResProps.width, maxResProps.height);
});
});
}

/**
* Starts barcode search process, implemented in WinRTBarcodeReader.winmd library
* Calls success callback, when barcode found.
*/
function startBarcodeSearch(width, height) {

reader = new WinRTBarcodeReader.Reader();
reader.init(capture, width, height);
reader.readCode().done(function (result) {
destroyPreview();
success({ text: result && result.text, format: result && result.barcodeFormat, cancelled: !result });
}, function (err) {
destroyPreview();
fail(err);
});
}

/**
* Removes preview frame and corresponding objects from window
*/
function destroyPreview() {

capturePreview.pause();
capturePreview.src = null;

[capturePreview, capturePreviewAlignmentMark, captureCancelButton].forEach(function (elem) {
elem && document.body.removeChild(elem);
});

reader && reader.stop();
reader = null;

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() {
reader && reader.stop();
}

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/exec/proxy").add("BarcodeScanner", module.exports);
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// 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: AssemblyTitle("WinRTBarcodeReader")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WindowsRuntimeComponent1")]
[assembly: AssemblyProduct("WinRTBarcodeReader")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand Down
Loading

2 comments on commit 4e5af0c

@ClaudeVernier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I am new on GitHub, I don't understand everything here yet (PR, Issues, version numbers...) but I am interested in this plugin for a project that targets primarily all Windows platforms but I would like to extend to Android and IOS at some point. I am trying to also use WebSQL and InAppBrowser.

When I used this version of the barcode plugin, I had this error message:

Severity Description File Line Column
Error Uh oh! MDAVSCLI 1 1

I tried removing all plugins, recompile adding only this plugin and then again, this error above.
I am using VS2015...

Any idea what this problem could be ?? Is it me ? Is the rigth place to say this ?

Regards,
Claude

@sebastieno
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error may happen if you mix the Cordova CLI and Visual Studio 15 (or VS 13 + Multi device hybrid apps extension).

In my case, I added a platform with CLI (cordova platform add windows) and a plugin (this one). After that, Visual Studio no longer wanted to build the App.

This error may also happen if your plugin.xml is wrong (but if you didn't touch it, it's probably not related).

Please sign in to comment.