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 timwindsor/master
Browse files Browse the repository at this point in the history
Adds BlackBerry 10 support for scanning
  • Loading branch information
timwindsor committed Jul 17, 2015
2 parents 70ca00b + 52b5adb commit 30196b3
Show file tree
Hide file tree
Showing 36 changed files with 9,480 additions and 5 deletions.
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ It is also possible to install via repo url directly ( unstable )
- iOS
- Windows 8
- Windows Phone 8
- BlackBerry 10
- Browser

Note: the Android source for this project includes an Android Library Project.
Expand Down Expand Up @@ -104,6 +105,17 @@ The following barcode types are currently supported:
* AZTEC
* PDF417

### BlackBerry 10
* UPC_A
* UPC_E
* EAN_8
* EAN_13
* CODE_39
* CODE_128
* ITF
* DATA_MATRIX
* AZTEC

`success` and `fail` are callback functions. Success is passed an object with data, type and cancelled properties. Data is the text representation of the barcode data, type is the type of barcode detected and cancelled is whether or not the user cancelled the scan.

A full example could be:
Expand Down Expand Up @@ -144,15 +156,19 @@ A full example could be:
```

## Windows8 quirks ##
Windows 8 implenemtation currently doesn't support encode functionality.
Windows 8 implementation currently doesn't support encode functionality.

## Windows Phone 8 quirks ##
Windows Phone 8 implenemtation currently doesn't support encode functionality.
Windows Phone 8 implementation currently doesn't support encode functionality.

## Thanks on Github ##
## BlackBerry 10 quirks
BlackBerry 10 implementation currently doesn't support encode functionality.
Cancelling a scan on BlackBerry 10 is done by touching the screen.

So many -- check out the original [iOS](https://github.com/phonegap/phonegap-plugins/tree/DEPRECATED/iOS/BarcodeScanner) and [Android](https://github.com/phonegap/phonegap-plugins/tree/DEPRECATED/Android/BarcodeScanner) repos.
## Thanks on Github ##

So many -- check out the original [iOS](https://github.com/phonegap/phonegap-plugins/tree/DEPRECATED/iOS/BarcodeScanner), [Android](https://github.com/phonegap/phonegap-plugins/tree/DEPRECATED/Android/BarcodeScanner) and
[BlackBerry 10](https://github.com/blackberry/WebWorks-Community-APIs/tree/master/BB10-Cordova/BarcodeScanner) repos.

## Licence ##

Expand Down
17 changes: 16 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,20 @@
<runs />
</js-module>
</platform>


<!-- BlackBerry 10 -->
<platform name="blackberry10">
<source-file src="src/blackberry10/index.js" target-dir="BarcodeScanner" />
<lib-file src="src/blackberry10/native/device/libBarcodeScanner.so" arch="device"/>
<lib-file src="src/blackberry10/native/simulator/libBarcodeScanner.so" arch="simulator"/>
<config-file target="www/config.xml" parent="/widget">
<feature name="BarcodeScanner">
<param name="blackberry-package" value="phonegap-plugin-barcodescanner" />
</feature>
</config-file>
<config-file target="www/config.xml" parent="/widget/rim:permissions">
<rim:permit>use_camera</rim:permit>
</config-file>
<dependency id="cordova-plugin-bb-app" />
</platform>
</plugin>
703 changes: 703 additions & 0 deletions src/blackberry10/LICENSE

Large diffs are not rendered by default.

147 changes: 147 additions & 0 deletions src/blackberry10/index.js
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();
Loading

0 comments on commit 30196b3

Please sign in to comment.