Added an option for camera flash to be on/off/auto during QR code scanning
This commit is contained in:
parent
889be2cc3a
commit
0b0699f7b4
@ -26,6 +26,7 @@ Arguments:
|
|||||||
text_title: "OPTIONAL Title Text - default = 'Scan QR Code'", // Android only
|
text_title: "OPTIONAL Title Text - default = 'Scan QR Code'", // Android only
|
||||||
text_instructions: "OPTIONAL Instruction Text - default = 'Please point your camera at the QR code.'", // Android only
|
text_instructions: "OPTIONAL Instruction Text - default = 'Please point your camera at the QR code.'", // Android only
|
||||||
camera: "front" || "back" // defaults to "back"
|
camera: "front" || "back" // defaults to "back"
|
||||||
|
flash: "on" || "off" || "auto" // defaults to "auto"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import android.hardware.Camera.PreviewCallback;
|
|||||||
import android.hardware.Camera.AutoFocusCallback;
|
import android.hardware.Camera.AutoFocusCallback;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
@ -51,6 +52,7 @@ implements SurfaceHolder.Callback {
|
|||||||
|
|
||||||
// Customisable stuff
|
// Customisable stuff
|
||||||
String whichCamera;
|
String whichCamera;
|
||||||
|
String flashMode;
|
||||||
|
|
||||||
// For retrieving R.* resources, from the actual app package
|
// For retrieving R.* resources, from the actual app package
|
||||||
// (we can't use actual.application.package.R.* in our code as we
|
// (we can't use actual.application.package.R.* in our code as we
|
||||||
@ -81,6 +83,7 @@ implements SurfaceHolder.Callback {
|
|||||||
String textTitle = params.optString("text_title");
|
String textTitle = params.optString("text_title");
|
||||||
String textInstructions = params.optString("text_instructions");
|
String textInstructions = params.optString("text_instructions");
|
||||||
whichCamera = params.optString("camera");
|
whichCamera = params.optString("camera");
|
||||||
|
flashMode = params.optString("flash");
|
||||||
|
|
||||||
// Initiate instance variables
|
// Initiate instance variables
|
||||||
autoFocusHandler = new Handler();
|
autoFocusHandler = new Handler();
|
||||||
@ -147,6 +150,19 @@ implements SurfaceHolder.Callback {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Camera.Parameters camParams = camera.getParameters();
|
||||||
|
if(flashMode.equals("on")) {
|
||||||
|
camParams.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
|
||||||
|
} else if(flashMode.equals("off")) {
|
||||||
|
camParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
||||||
|
} else {
|
||||||
|
camParams.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
|
||||||
|
}
|
||||||
|
try { camera.setParameters(camParams); }
|
||||||
|
catch (RuntimeException e) {
|
||||||
|
Log.d("csZBar", "Unsupported camera parameter reported for flash mode: "+flashMode);
|
||||||
|
}
|
||||||
|
|
||||||
tryStartPreview();
|
tryStartPreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,6 +53,12 @@
|
|||||||
// as not all devices will have a rear-facing camera.
|
// as not all devices will have a rear-facing camera.
|
||||||
self.scanReader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
|
self.scanReader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
|
||||||
}
|
}
|
||||||
|
NSString *flash = [params objectForKey:@"flash"];
|
||||||
|
if([flash isEqualToString:@"on"]) {
|
||||||
|
self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
|
||||||
|
} else if([flash isEqualToString:@"off"]) {
|
||||||
|
self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
|
||||||
|
}
|
||||||
|
|
||||||
// Hack to hide the bottom bar's Info button... http://stackoverflow.com/a/16353530
|
// Hack to hide the bottom bar's Info button... http://stackoverflow.com/a/16353530
|
||||||
UIView *infoButton = [[[[[self.scanReader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:3];
|
UIView *infoButton = [[[[[self.scanReader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:3];
|
||||||
|
@ -13,6 +13,7 @@ ZBar.prototype = {
|
|||||||
if(params.text_title === undefined) params.text_title = "Scan QR Code";
|
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.";
|
if(params.text_instructions === undefined) params.text_instructions = "Please point your camera at the QR code.";
|
||||||
if(params.camera != "front") params.camera = "back";
|
if(params.camera != "front") params.camera = "back";
|
||||||
|
if(params.flash != "on" && params.flash != "off") params.flash = "auto";
|
||||||
|
|
||||||
exec(success, failure, 'CsZBar', 'scan', [params]);
|
exec(success, failure, 'CsZBar', 'scan', [params]);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user