Added text_title and text_instructions parameters for customising the scanner view's title and instructions texts (Android only in this commit)
This commit is contained in:
parent
9fb4a6a23c
commit
8d0261b650
10
README.md
10
README.md
@ -19,7 +19,15 @@ This plugin is released under the Apache 2.0 license, but the ZBar library on wh
|
||||
|
||||
Arguments:
|
||||
|
||||
- **params**: _Unused for now. Will be an object in the future if we extend this plugin with options to specify scannable barcode types, etc._
|
||||
- **params**: Optional parameters:
|
||||
|
||||
```javascript
|
||||
{
|
||||
text_title: "Title Text - default = 'Scan QR Code'",
|
||||
text_instructions: "Instruction Text - default = 'Please point your camera at the QR code.'",
|
||||
}
|
||||
```
|
||||
|
||||
- **onSuccess**: function (s) {...} _Callback for successful scan._
|
||||
- **onFailure**: function (s) {...} _Callback for cancelled scan or error._
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
package org.cloudsky.cordovaPlugins;
|
||||
|
||||
import org.apache.cordova.CordovaInterface;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
@ -38,8 +37,11 @@ public class ZBar extends CordovaPlugin {
|
||||
} else {
|
||||
isInProgress = true;
|
||||
scanCallbackContext = callbackContext;
|
||||
JSONObject params = args.optJSONObject(0);
|
||||
|
||||
Context appCtx = cordova.getActivity().getApplicationContext();
|
||||
Intent scanIntent = new Intent(appCtx, ZBarScannerActivity.class);
|
||||
scanIntent.putExtra(ZBarScannerActivity.EXTRA_PARAMS, params.toString());
|
||||
cordova.startActivityForResult(this, scanIntent, SCAN_CODE);
|
||||
}
|
||||
return true;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.cloudsky.cordovaPlugins;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
@ -15,7 +17,7 @@ import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Toast;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.sourceforge.zbar.ImageScanner;
|
||||
import net.sourceforge.zbar.Image;
|
||||
@ -33,6 +35,7 @@ implements SurfaceHolder.Callback {
|
||||
// Public Constants ------------------------------------------------
|
||||
|
||||
public static final String EXTRA_QRVALUE = "qrValue";
|
||||
public static final String EXTRA_PARAMS = "params";
|
||||
public static final int RESULT_ERROR = RESULT_FIRST_USER + 1;
|
||||
|
||||
// State -----------------------------------------------------------
|
||||
@ -64,6 +67,15 @@ implements SurfaceHolder.Callback {
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Get parameters from JS
|
||||
Intent startIntent = getIntent();
|
||||
String paramStr = startIntent.getStringExtra(EXTRA_PARAMS);
|
||||
JSONObject params;
|
||||
try { params = new JSONObject(paramStr); }
|
||||
catch (JSONException e) { params = new JSONObject(); }
|
||||
String textTitle = params.optString("text_title");
|
||||
String textInstructions = params.optString("text_instructions");
|
||||
|
||||
// Initiate instance variables
|
||||
autoFocusHandler = new Handler();
|
||||
scanner = new ImageScanner();
|
||||
@ -72,7 +84,13 @@ implements SurfaceHolder.Callback {
|
||||
|
||||
// Set content view
|
||||
setContentView(getResourceId("layout/cszbarscanner"));
|
||||
|
||||
|
||||
// Update view with customisable strings
|
||||
TextView view_textTitle = (TextView) findViewById(getResourceId("id/csZbarScannerTitle"));
|
||||
TextView view_textInstructions = (TextView) findViewById(getResourceId("id/csZbarScannerInstructions"));
|
||||
view_textTitle.setText(textTitle);
|
||||
view_textInstructions.setText(textInstructions);
|
||||
|
||||
// Create preview SurfaceView
|
||||
scannerSurface = new SurfaceView (this) {
|
||||
@Override
|
||||
|
@ -8,6 +8,11 @@ ZBar.prototype = {
|
||||
scan: function (params, success, failure)
|
||||
{
|
||||
argscheck.checkArgs('*fF', 'CsZBar.scan', arguments);
|
||||
|
||||
params = params || {};
|
||||
if(params.text_title === undefined) params.text_title = "Scan QR Code";
|
||||
if(params.text_instructions === undefined) params.text_instructions = "Please point your camera at the QR code.";
|
||||
|
||||
exec(success, failure, 'CsZBar', 'scan', [params]);
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user