Commit a7ed6890 authored by EddyVerbruggen's avatar EddyVerbruggen

Flashlight option #381

parent 77622ca9
{
"name": "phonegap-plugin-barcodescanner",
"version": "6.0.3",
"version": "6.0.4",
"description": "You can use the BarcodeScanner plugin to scan different types of barcodes (using the device's camera) and get the metadata encoded in them for processing within your application.",
"cordova": {
"id": "phonegap-plugin-barcodescanner",
......
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:rim="http://www.blackberry.com/ns/widgets" id="phonegap-plugin-barcodescanner" version="6.0.3">
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:rim="http://www.blackberry.com/ns/widgets" id="phonegap-plugin-barcodescanner" version="6.0.4">
<name>BarcodeScanner</name>
<description>You can use the BarcodeScanner plugin to scan different types of barcodes (using the device's camera) and get the metadata encoded in them for processing within your application.</description>
<license>MIT</license>
......@@ -52,7 +52,7 @@
<uses-feature android:name="android.hardware.camera" android:required="true"/>
</config-file>
<framework src="src/android/barcodescanner.gradle" custom="true" type="gradleReference"/>
<resource-file src="src/android/barcodescanner-release-2.0.1.aar" target="libs/barcodescanner.aar"/>
<resource-file src="src/android/barcodescanner-release-2.1.0.aar" target="libs/barcodescanner.aar"/>
<dependency id="cordova-plugin-compat" version="^1.0.0"/>
</platform>
<platform name="windows">
......
......@@ -46,6 +46,7 @@ public class BarcodeScanner extends CordovaPlugin {
private static final String PREFER_FRONTCAMERA = "preferFrontCamera";
private static final String ORIENTATION = "orientation";
private static final String SHOW_FLIP_CAMERA_BUTTON = "showFlipCameraButton";
private static final String SHOW_TORCH_BUTTON = "showTorchButton";
private static final String FORMATS = "formats";
private static final String PROMPT = "prompt";
private static final String TEXT_TYPE = "TEXT_TYPE";
......@@ -172,6 +173,7 @@ public class BarcodeScanner extends CordovaPlugin {
intentScan.putExtra(Intents.Scan.CAMERA_ID, obj.optBoolean(PREFER_FRONTCAMERA, false) ? 1 : 0);
intentScan.putExtra(Intents.Scan.SHOW_FLIP_CAMERA_BUTTON, obj.optBoolean(SHOW_FLIP_CAMERA_BUTTON, false));
intentScan.putExtra(Intents.Scan.SHOW_TORCH_BUTTON, obj.optBoolean(SHOW_TORCH_BUTTON, false));
if (obj.has(FORMATS)) {
intentScan.putExtra(Intents.Scan.FORMATS, obj.optString(FORMATS));
}
......
......@@ -70,6 +70,7 @@
@property (nonatomic) BOOL capturing;
@property (nonatomic) BOOL isFrontCamera;
@property (nonatomic) BOOL isShowFlipCameraButton;
@property (nonatomic) BOOL isShowTorchButton;
@property (nonatomic) BOOL isFlipped;
......@@ -162,6 +163,8 @@
}
BOOL preferFrontCamera = [options[@"preferFrontCamera"] boolValue];
BOOL showFlipCameraButton = [options[@"showFlipCameraButton"] boolValue];
BOOL showTorchButton = [options[@"showTorchButton"] boolValue];
// We allow the user to define an alternate xib file for loading the overlay.
NSString *overlayXib = [options objectForKey:@"overlayXib"];
......@@ -191,6 +194,10 @@
processor.isShowFlipCameraButton = true;
}
if (showTorchButton) {
processor.isShowTorchButton = true;
}
processor.formats = options[@"formats"];
[processor performSelector:@selector(scanBarcode) withObject:nil afterDelay:0];
......@@ -428,6 +435,19 @@ parentViewController:(UIViewController*)parentViewController
}];
}
- (void)toggleTorch {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil];
if (device.flashActive) {
[device setTorchMode:AVCaptureTorchModeOff];
[device setFlashMode:AVCaptureFlashModeOff];
} else {
[device setTorchModeOnWithLevel:AVCaptureMaxAvailableTorchLevel error:nil];
[device setFlashMode:AVCaptureFlashModeOn];
}
[device unlockForConfiguration];
}
//--------------------------------------------------------------------------
- (NSString*)setUpCaptureSession {
NSError* error = nil;
......@@ -893,6 +913,11 @@ parentViewController:(UIViewController*)parentViewController
[self.processor performSelector:@selector(flipCamera) withObject:nil afterDelay:0];
}
- (void)torchButtonPressed:(id)sender
{
[self.processor performSelector:@selector(toggleTorch) withObject:nil afterDelay:0];
}
//--------------------------------------------------------------------------
- (UIView *)buildOverlayViewFromXib
{
......@@ -944,6 +969,8 @@ parentViewController:(UIViewController*)parentViewController
action:@selector(flipCameraButtonPressed:)
] autorelease];
NSMutableArray *items;
#if USE_SHUTTER
id shutterButton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
......@@ -952,17 +979,36 @@ parentViewController:(UIViewController*)parentViewController
] autorelease];
if (_processor.isShowFlipCameraButton) {
toolbar.items = [NSArray arrayWithObjects:flexSpace,cancelButton,flexSpace, flipCamera ,shutterButton,nil];
items = [NSMutableArray arrayWithObjects:flexSpace, cancelButton, flexSpace, flipCamera, shutterButton, nil];
} else {
toolbar.items = [NSArray arrayWithObjects:flexSpace,cancelButton,flexSpace ,shutterButton,nil];
items = [NSMutableArray arrayWithObjects:flexSpace, cancelButton, flexSpace, shutterButton, nil];
}
#else
if (_processor.isShowFlipCameraButton) {
toolbar.items = [NSArray arrayWithObjects:flexSpace,cancelButton,flexSpace, flipCamera,nil];
items = [NSMutableArray arrayWithObjects:flexSpace, cancelButton, flexSpace, flipCamera, nil];
} else {
toolbar.items = [NSArray arrayWithObjects:flexSpace,cancelButton,flexSpace,nil];
items = [NSMutableArray arrayWithObjects:flexSpace, cancelButton, flexSpace, nil];
}
#endif
if (_processor.isShowTorchButton && !_processor.isFrontCamera) {
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"CDVBarcodeScanner" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
NSString *imagePath = [bundle pathForResource:@"torch" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
id torchButton = [[[UIBarButtonItem alloc]
initWithImage:image
style:UIBarButtonItemStylePlain
target:(id)self
action:@selector(torchButtonPressed:)
] autorelease];
[items insertObject:torchButton atIndex:0];
}
toolbar.items = items;
bounds = overlayView.bounds;
[toolbar sizeToFit];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment