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 #127 from timwindsor/barcodeEncodeBB
Browse files Browse the repository at this point in the history
Encode support for BlackBerry 10
  • Loading branch information
timwindsor committed Dec 15, 2015
2 parents 6b5f7fb + d9f4795 commit f4d5d5c
Show file tree
Hide file tree
Showing 3 changed files with 689 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
<!-- BlackBerry 10 -->
<platform name="blackberry10">
<source-file src="src/blackberry10/index.js" target-dir="BarcodeScanner" />
<source-file src="src/blackberry10/qrcode.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">
Expand Down
67 changes: 66 additions & 1 deletion src/blackberry10/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
var barcodescanner,
resultObjs = {},
readCallback,
_utils = require("../../lib/utils");
_utils = require("../../lib/utils"),
_qr = require('plugin/BarcodeScanner/qrcode.js');

const SMS_URI_ONE = "smsto:",
SMS_URI_TWO = "sms:",
EMAIL_URI = "mailto:",
PHONE_URI = "tel:+1",
SMS_TYPE = "SMS_TYPE",
PHONE_TYPE = "PHONE_TYPE",
EMAIL_TYPE = "EMAIL_TYPE",
TEXT_TYPE = "TEXT_TYPE";

module.exports = {

Expand Down Expand Up @@ -45,8 +55,63 @@ module.exports = {
}
},

/*
Method for barcode encoding. Returns base 64 image URI
Currently only creates QRcodes
*/
encode: function (success, fail, args, env) {

var result = new PluginResult(args, env);
values = decodeURIComponent(args[0]);
values = JSON.parse(values);
data = values["data"];
type = values["type"];

if(data == "" || data == undefined){
result.error("Data to be encoded was not specified", false);
return;
}
if(type == "" || type == undefined){
type = TEXT_TYPE;
}

if(type == SMS_TYPE){
var check_one = data.substring(0,6).toLowerCase();
var check_two = data.substring(0,4).toLowerCase();
if(!(check_one == SMS_URI_ONE || check_two == SMS_URI_TWO)){
data = SMS_URI_ONE+data;
}
}else if(type == EMAIL_TYPE){
var check = data.substring(0,7).toLowerCase();
if(check != EMAIL_URI){
data = EMAIL_URI+data;
}
}else if(type == PHONE_TYPE){
var check = data.substring(0,4).toLowerCase();
if(check != PHONE_URI){
data = PHONE_URI+data;
}
}

console.log("Type: "+type + " Data: " + data);

//Make QRcode using qrcode.js
var bdiv = document.createElement('div');
var options = {
text: data,
width: 256,
height: 256,
colorDark : "#000000",
colorLight : "#ffffff",
};

var imageURI = _qr.makeQRcode(bdiv, options);

try{
result.ok(imageURI,false);
}catch(e){
result.error("Failed to encode barcode", false);
}
}
};

Expand Down
Loading

0 comments on commit f4d5d5c

Please sign in to comment.