This repository has been archived by the owner on Aug 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from timwindsor/master
Adds BlackBerry 10 support for scanning
- Loading branch information
Showing
36 changed files
with
9,480 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Copyright 2013-2015 BlackBerry Limited. | ||
* | ||
* 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. | ||
*/ | ||
var barcodescanner, | ||
resultObjs = {}, | ||
readCallback, | ||
_utils = require("../../lib/utils"); | ||
|
||
module.exports = { | ||
|
||
// methods to start and stop scanning | ||
scan: function (success, fail, args, env) { | ||
var result = new PluginResult(args, env); | ||
resultObjs[result.callbackId] = result; | ||
readCallback = result.callbackId; | ||
var views = qnx.webplatform.getWebViews(); | ||
var handle = null; | ||
var group = null; | ||
var z = -1; | ||
for (var i = 0; i < views.length; i++) { | ||
if (views[i].visible && views[i].zOrder > z){ | ||
z = views[i].zOrder; | ||
group = views[i].windowGroup; | ||
handle = views[i].jsScreenWindowHandle; | ||
} | ||
} | ||
if (handle !== null) { | ||
var values = { group: group, handle: handle }; | ||
barcodescanner.getInstance().startRead(result.callbackId, values); | ||
// result.noResult(true); // calls the error handler for some reason | ||
} else { | ||
result.error("Failed to find window handle", false); | ||
} | ||
}, | ||
|
||
encode: function (success, fail, args, env) { | ||
|
||
} | ||
}; | ||
|
||
|
||
JNEXT.BarcodeScanner = function () { | ||
var self = this, | ||
hasInstance = false; | ||
|
||
self.getId = function () { | ||
return self.m_id; | ||
}; | ||
|
||
self.init = function () { | ||
if (!JNEXT.require("libBarcodeScanner")) { | ||
return false; | ||
} | ||
|
||
self.m_id = JNEXT.createObject("libBarcodeScanner.BarcodeScannerJS"); | ||
|
||
if (self.m_id === "") { | ||
return false; | ||
} | ||
|
||
JNEXT.registerEvents(self); | ||
}; | ||
|
||
// ************************ | ||
// Enter your methods here | ||
// ************************ | ||
|
||
// Fired by the Event framework (used by asynchronous callbacks) | ||
|
||
self.onEvent = function (strData) { | ||
var arData = strData.split(" "), | ||
callbackId = arData[0], | ||
receivedEvent = arData[1], | ||
data = arData[2], | ||
result = resultObjs[callbackId], | ||
events = ["community.barcodescanner.codefound.native", | ||
"community.barcodescanner.errorfound.native", | ||
"community.barcodescanner.started.native", | ||
"community.barcodescanner.ended.native"]; | ||
|
||
// Restructures results when codefound has spaces | ||
if(arData.length > 3){ | ||
var i; | ||
for(i=3; i<arData.length; i++) { | ||
data += " " + arData[i]; | ||
} | ||
} | ||
|
||
if (receivedEvent == "community.barcodescanner.codefound.native") { | ||
if (result) { | ||
result.callbackOk(data, false); | ||
} | ||
this.stopRead(callbackId); | ||
|
||
} | ||
if (receivedEvent == "community.barcodescanner.started.native") { | ||
console.log("Scanning started successfully"); | ||
} | ||
if (receivedEvent == "community.barcodescanner.errorfound.native") { | ||
if (result) { | ||
result.callbackError(data, false); | ||
} | ||
} | ||
|
||
if(receivedEvent == "community.barcodescanner.ended.native" || receivedEvent == "community.barcodescanner.errorfound.native") { | ||
delete resultObjs[readCallback]; | ||
readCallback = null; | ||
} | ||
|
||
}; | ||
|
||
// Thread methods | ||
self.startRead = function (callbackId, handle) { | ||
return JNEXT.invoke(self.m_id, "startRead " + callbackId + " " + JSON.stringify(handle)); | ||
}; | ||
self.stopRead = function (callbackId) { | ||
return JNEXT.invoke(self.m_id, "stopRead " + callbackId); | ||
}; | ||
|
||
// ************************ | ||
// End of methods to edit | ||
// ************************ | ||
self.m_id = ""; | ||
|
||
self.getInstance = function () { | ||
if (!hasInstance) { | ||
hasInstance = true; | ||
self.init(); | ||
} | ||
return self; | ||
}; | ||
|
||
}; | ||
|
||
barcodescanner = new JNEXT.BarcodeScanner(); |
Oops, something went wrong.