Skip to content
Browse files

Merge branch 'master' of https://github.com/roblabs/phonegap-plugins

…into roblabs-master
  • Loading branch information...
2 parents efadb79 + 862f5a9 commit 99c996fb57c808dc27ed9afee241a163a1f6e8ce Matt Kane committed
View
61 Android/BarcodeScanner/BarcodeScanner.java 100644 → 100755
@@ -57,7 +57,44 @@ public PluginResult execute(String action, JSONArray args, String callbackId) {
this.callback = callbackId;
try {
- if (action.equals("scan")) {
+ if (action.equals("encode")) {
+ String type = null;
+ if(args.length() > 0) {
+ type = args.getString(0);
+ }
+
+ String data = null;
+ if(args.length() > 1) {
+ data = args.getString(1);
+ }
+
+ String installTitle = defaultInstallTitle;
+ if(args.length() > 2) {
+ installTitle = args.getString(2);
+ }
+
+ String installMessage = defaultInstallMessage;
+ if(args.length() > 3) {
+ installMessage = args.getString(3);
+ }
+
+ String yesString = defaultYesString;
+ if(args.length() > 4) {
+ yesString = args.getString(4);
+ }
+
+ String noString = defaultNoString;
+ if(args.length() > 5) {
+ noString = args.getString(5);
+ }
+
+ // if data.TypeOf() == Bundle, then call
+ // encode(type, Bundle)
+ // else
+ // encode(type, String)
+ this.encode(type, data, installTitle, installMessage, yesString, noString);
+ }
+ else if (action.equals("scan")) {
String barcodeTypes = null;
if(args.length() > 0) {
barcodeTypes = args.getString(0);
@@ -179,4 +216,26 @@ public void onClick(DialogInterface dlg, int i) {
};
context.runOnUiThread(runnable);
}
+
+ /**
+ * Initiates a barcode encode. If the ZXing scanner isn't installed, the user
+ * will be prompted to install it.
+ * @param type The barcode type to encode
+ * @param data The data to encode in the bar code
+ * @param installTitle The title for the dialog box that prompts the user to install the scanner
+ * @param installMessage The message prompting the user to install the barcode scanner
+ * @param yesString The string "Yes" or localised equivalent
+ * @param noString The string "No" or localised version
+ */
+ public void encode(String type, String data, String installTitle, String installMessage, String yesString, String noString) {
+ Intent intentEncode = new Intent("com.google.zxing.client.android.ENCODE");
+ intentEncode.putExtra("ENCODE_TYPE", type);
+ intentEncode.putExtra("ENCODE_DATA", data);
+
+ try {
+ this.ctx.startActivity(intentEncode);
+ } catch (ActivityNotFoundException e) {
+ showDownloadDialog(installTitle, installMessage, yesString, noString);
+ }
+ }
}
View
26 Android/BarcodeScanner/README.md
@@ -7,7 +7,12 @@ If the user doesn't have the app install they will be promped to install it the
1. To install the plugin, move barcodescanner.js to your project's www folder and include a reference to it
in your html files.
-2. Create a folder called "beetight" within your project's src/com/ folder and move the java file into it.
+2. Create a folder called 'src/com/beetight/barcodescanner' within your project's src/com/ folder.
+3. And copy the java file into that new folder.
+
+`mkdir <your_project>/src/com/beetight/barcodescanner`
+
+`cp ./BarcodeScanner.java <your_project>/src/com/beetight/barcodescanner`
## Using the plugin ##
The plugin creates the object `window.plugins.barcodeScanner` with one method `scan(types, success, fail, options)`
@@ -50,6 +55,25 @@ A full example could be:
alert("Scanning failed: " + error);
}, {yesString: "Install"}
);
+
+## Encoding a Barcode ##
+Supported encoding types:
+
+* TEXT_TYPE
+* EMAIL_TYPE
+* PHONE_TYPE
+* SMS_TYPE
+
+
+A full example could be:
+
+ window.plugins.barcodeScanner.encode(BarcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com", function(success) {
+ alert("encode success: " + success);
+ }, function(fail) {
+ alert("encoding failed: " + fail);
+ }, {yesString: "Install"}
+ );
+
## BUGS AND CONTRIBUTIONS ##
The latest bleeding-edge version is available [on GitHub](http://github.com/ascorbic/phonegap-plugins/tree/master/Android/)
View
41 Android/BarcodeScanner/barcodescanner.js 100644 → 100755
@@ -28,6 +28,15 @@ BarcodeScanner.Type = {
ALL_CODE_TYPES: null
}
+BarcodeScanner.Encode = {
+ TEXT_TYPE: "TEXT_TYPE",
+ EMAIL_TYPE: "EMAIL_TYPE",
+ PHONE_TYPE: "PHONE_TYPE",
+ SMS_TYPE: "SMS_TYPE",
+ // CONTACT_TYPE: "CONTACT_TYPE", // TODO: not implemented, requires passing a Bundle class from Javascriopt to Java
+ // LOCATION_TYPE: "LOCATION_TYPE" // TODO: not implemented, requires passing a Bundle class from Javascriopt to Java
+ }
+
BarcodeScanner.prototype.scan = function(types, success, fail, options) {
/* These are the strings used in the dialog that appears if ZXing isn't installed */
@@ -61,6 +70,38 @@ BarcodeScanner.prototype.scan = function(types, success, fail, options) {
}, 'BarcodeScanner', 'scan', [types, installTitle, installMessage, yesString, noString]);
};
+BarcodeScanner.prototype.encode = function(type, data, success, fail, options) {
+
+ /* These are the strings used in the dialog that appears if ZXing isn't installed */
+ var installTitle = "Install Barcode Scanner?";
+ var installMessage = "This requires the free Barcode Scanner app. Would you like to install it now?";
+ var yesString = "Yes";
+ var noString = "No";
+ if (typeof options != 'undefined') {
+ if(typeof options.installTitle != 'undefined') {
+ installTitle = options.installTitle;
+ }
+
+ if(typeof options.installMessage != 'undefined') {
+ installMessage = options.installMessage;
+ }
+
+ if(typeof options.yesString != 'undefined') {
+ yesString = options.yesString;
+ }
+
+ if(typeof options.noString != 'undefined') {
+ noString = options.noString;
+ }
+ }
+
+ return PhoneGap.exec(function(args) {
+ success(args);
+ }, function(args) {
+ fail(args);
+ }, 'BarcodeScanner', 'encode', [type, data, installTitle, installMessage, yesString, noString]);
+};
+
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('barcodeScanner', new BarcodeScanner());
PluginManager.addService("BarcodeScanner","com.beetight.barcodescanner.BarcodeScanner");

0 comments on commit 99c996f

Please sign in to comment.
Something went wrong with that request. Please try again.