Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslaux committed Jan 25, 2019
2 parents f76a052 + 1fa793f commit 1cc16b9
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 38 deletions.
2 changes: 1 addition & 1 deletion example/config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.anyline.examples.cordova" version="7.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="io.anyline.examples.cordova" version="7.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Anyline Cordova Example</name>
<preference name="deployment-target" value="10.0" />
<preference name="BackupWebStorage" value="local" />
Expand Down
3 changes: 2 additions & 1 deletion example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "anyline-cordova-example",
"version": "7.0.0",
"version": "7.0.1",
"description": "Cordova plugin for implementing Anyline",
"main": "index.js",
"scripts": {
Expand All @@ -21,4 +21,4 @@
"platforms": []
},
"dependencies": {}
}
}
5 changes: 3 additions & 2 deletions plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "io-anyline-cordova",
"version": "7.0.0",
"version": "7.0.1",
"description": "The cordova plugin for the Anyline SDK",
"cordova": {
"id": "io-anyline-cordova",
Expand All @@ -13,7 +13,8 @@
"keywords": [
"ecosystem:cordova",
"cordova-ios",
"cordova-android"
"cordova-android",
"cordova-windows"
],
"repository": {
"type": "git",
Expand Down
3 changes: 2 additions & 1 deletion plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="io-anyline-cordova"
version="7.0.0">
version="7.0.1">

<name>AnylineSDK</name>

Expand Down Expand Up @@ -156,6 +156,7 @@
</js-module>
<asset src="src/windows/css" target="css" />
<asset src="src/windows/js" target="js" />
<asset src="src/windows/img" target="img" />
</platform>

</plugin>
9 changes: 5 additions & 4 deletions plugin/src/windows/css/anylineDefault.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}

#anylineVideoElement{
position: fixed;
position: relative;
z-index: -1;
top:0;
bottom: 0;
Expand Down Expand Up @@ -58,11 +58,12 @@
background-color: transparent;
}

#anylineFlashButton{
#anylineFlashButton {
position: fixed;
z-index: 99999;
font-size: 3em;
background-color: transparent;
border: solid;
border: none;
color: white;
}
}

Binary file added plugin/src/windows/img/torch_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/src/windows/img/torch_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plugin/src/windows/lib/arm/Anyline.JS.winmd
Binary file not shown.
Binary file modified plugin/src/windows/lib/arm/Anyline.SDK.dll
Binary file not shown.
Binary file modified plugin/src/windows/lib/arm/Anyline.dll
Binary file not shown.
Binary file modified plugin/src/windows/lib/arm/Anyline.winmd
Binary file not shown.
Binary file modified plugin/src/windows/lib/x86/Anyline.JS.winmd
Binary file not shown.
Binary file modified plugin/src/windows/lib/x86/Anyline.SDK.dll
Binary file not shown.
106 changes: 79 additions & 27 deletions plugin/src/windows/scanview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@ const urlutil = require('cordova/urlutil');
let scanViewController = null;
let onErrorGlobal;
let baseConfig;

let TORCH_OFF = "TORCH OFF";
let TORCH_ON = "TORCH ON";

let skipFocus = false;
let TORCH_OFF = "<img src=\"img\\torch_off.png\" style=\"vertical-align:middle\" />";
let TORCH_ON = "<img src=\"img\\torch_on.png\" style=\"vertical-align:middle\" />";
module.exports = {

init: function (licenseKey, mode, config, onSuccess, onError, ocrConfig) {

Anyline.JS.Util.Debug.verbosity = 4;
// enable for debug purposes only!
/*Anyline.JS.Util.Debug.verbosity = 4;
/*Anyline.JS.Util.Debug.onlog = function (args) {
Anyline.JS.Util.Debug.onlog = function (args) {
console.log(args.toString());
}*/

baseConfig = config;
onErrorGlobal = onError;
scanViewController = new Anyline.JS.ScanViewController();

// set this if you're experiencing memory issues
scanViewController.setMemoryCollectionMode(2);

scanViewController.onnotifyexception = function (args) {
Expand Down Expand Up @@ -83,9 +85,10 @@ module.exports = {
scanViewController.captureManager.onpreviewrotated = () => {
calcVideoRelation();
}

scanViewController.onnotifyupdatevisualfeedback = function (args) {
if (args) {

const argsString = args.toString();
const functionName = argsString.split('(')[0];
const functionArgs = argsString.split('(')[1].split(')')[0];
Expand Down Expand Up @@ -149,13 +152,13 @@ function createPreview(cancelButton) {

// Scripts
if (!document.getElementById("anylineCutoutScript")) {
includeScript(urlutil.makeAbsolute("/www/js/cutout.js"), console.log, 'anylineCutoutScript');
includeScript(urlutil.makeAbsolute("/www/js/cutout.js"), 'anylineCutoutScript');
}
if (!document.getElementById("anylineVFScript")) {
includeScript(urlutil.makeAbsolute("/www/js/visualFeedback.js"), console.log, 'anylineVFScript');
includeScript(urlutil.makeAbsolute("/www/js/visualFeedback.js"), 'anylineVFScript');
}
if (!document.getElementById("anylineUtilScript")) {
includeScript(urlutil.makeAbsolute("/www/js/util.js"), console.log, 'anylineUtilScript');
includeScript(urlutil.makeAbsolute("/www/js/util.js"), 'anylineUtilScript');
}
// Root
const anylineRoot = document.createElement('div')
Expand All @@ -172,7 +175,7 @@ function createPreview(cancelButton) {
closeCamera();
destroyPreview();
delete scanViewController;
onErrorGlobal('canceled');
onErrorGlobal('Canceled');
}
anylineRoot.appendChild(cancelBtnElement);

Expand All @@ -198,22 +201,31 @@ function createPreview(cancelButton) {
flashButton.style.visibility = "hidden";
flashButton.innerHTML = TORCH_OFF;
flashButton.onclick = function () {

skipFocus = true;
setTimeout(function () { skipFocus = false; }, 1000);

if (scanViewController == null) return;
if (scanViewController.isFlashSupported()) {
if (!scanViewController.isFlashEnabled()) {
if (!scanViewController.captureManager.mediaCapture.videoDeviceController.flashControl.enabled) {
var success = scanViewController.enableFlash();
scanViewController.captureManager.mediaCapture.videoDeviceController.flashControl.enabled = true;
// flash is enabled:
if (success == true) {
flashButton.innerHTML = TORCH_ON;
console.log("Torch enabled.");
}
} else {
var success = scanViewController.disableFlash();
scanViewController.captureManager.mediaCapture.videoDeviceController.flashControl.enabled = false;
// flash is disabled:
if (success == true) {
flashButton.innerHTML = TORCH_OFF;
console.log("Torch disabled.");
}
}
}

};
flashButtonRoot.appendChild(flashButton);

Expand Down Expand Up @@ -276,7 +288,7 @@ function enableZoomAndScroll() {
document.body.classList.remove('no-scroll');
}

function includeScript(path, cb, id) {
function includeScript(path, id) {
if (!(window.MSApp && window.MSApp.execUnsafeLocalFunction)) {
var node = document.createElement("script"),
okHandler, errHandler;
Expand All @@ -287,12 +299,10 @@ function includeScript(path, cb, id) {
okHandler = function () {
this.removeEventListener("load", okHandler);
this.removeEventListener("error", errHandler);
cb(path, 'success');
};
errHandler = function (error) {
this.removeEventListener("load", okHandler);
this.removeEventListener("error", errHandler);
cb("Error loading script: " + path);
};

node.addEventListener("load", okHandler);
Expand All @@ -305,7 +315,6 @@ function includeScript(path, cb, id) {
var node = document.createElement("script");
node.text = result;
document.body.appendChild(node);
cb();
});
});
}
Expand Down Expand Up @@ -335,6 +344,26 @@ function readLocalFile(path, cb) {
/////////////////////// Camera ///////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////

function focus() {
try {

if (skipFocus)
return;

if (scanViewController != null) {
if (scanViewController.captureManager.mediaCapture.videoDeviceController.focusControl.supported == true) {
scanViewController.captureManager.mediaCapture.videoDeviceController.focusControl.focusAsync();
//console.log("Focused successfully.");
} else {
//console.log("Focus is not supported on this device.");
}
}
}
catch (exception) {
console.log("Unable to focus: " + exception);
}
}

// Visual Feedback
let VFRender = null;

Expand All @@ -348,13 +377,24 @@ function openCamera() {
}

videoElement.src = URL.createObjectURL(scanViewController.captureManager.mediaCapture, { oneTimeOnly: true });

videoElement.play().then(function () {
console.log("Playing.");
VFRender = setInterval(function () {
updateFrames();
}, 100);
});
try {
videoElement.onplay = function () {
console.log("Playing.");
VFRender = setInterval(function () {
updateFrames();
}, 100);
};
videoElement.play();

// tap to focus
const anylineRoot = document.getElementById("anylineRoot");
anylineRoot.onclick = function () {
focus();
};
}
catch (ex) {
console.log(ex);
}
});

updateFlashButton();
Expand All @@ -366,6 +406,10 @@ function openCamera() {

// stops the camera
function closeCamera() {
const anylineRoot = document.getElementById("anylineRoot");
if (anylineRoot)
anylineRoot.onclick = null;

scanViewController.cancelScanning();
if (scanViewController.captureManager.mediaCapture == null)
return;
Expand All @@ -387,7 +431,7 @@ function msVisibilityChangeHandler() {
closeCamera();
destroyPreview();
delete scanViewController;
onErrorGlobal('canceled');
onErrorGlobal('Canceled');
}

// align & update button from config
Expand Down Expand Up @@ -448,10 +492,15 @@ function calcVideoRelation() {
const canvasElement = document.getElementById("anylineCanvas");
const backgroundElement = document.getElementById("anylineBackground");
const videoElement = document.getElementById("anylineVideoElement");
const flashElement = document.getElementById("anylineFlashButton");

if (canvasElement == null || backgroundElement == null || videoElement == null)
return;

if (flashElement != null) {
flashElement.style.opacity = scanViewController.captureManager.mediaCapture.videoDeviceController.flashControl.supported ? 1.0 : 0.3;
}

// mirror preview & VF when the camera is front-facing
if (scanViewController.captureManager.isPreviewMirrored) {

Expand Down Expand Up @@ -493,11 +542,14 @@ function calcVideoRelation() {

const overflowHeight = window.innerWidth / camRelation - window.innerHeight;

videoElement.style.left = 0;
backgroundElement.style.left = 0;
canvasElement.style.left = 0;
videoElement.style.left = 0 + 'px';
backgroundElement.style.left = 0 + 'px';
canvasElement.style.left = 0 + 'px';
var oh = -(overflowHeight / 2) + 'px';
backgroundElement.style.top = oh;

videoElement.style.top = oh;

}

// Update Cutout from SDK
Expand Down

0 comments on commit 1cc16b9

Please sign in to comment.