diff --git a/package.json b/package.json index b8aa6a22..d52fc990 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "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", diff --git a/plugin.xml b/plugin.xml index 824736fa..c53f5f0c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + BarcodeScanner 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. MIT @@ -52,7 +52,7 @@ - + diff --git a/src/android/barcodescanner-release-2.0.1.aar b/src/android/barcodescanner-release-2.0.1.aar deleted file mode 100644 index abea6444..00000000 Binary files a/src/android/barcodescanner-release-2.0.1.aar and /dev/null differ diff --git a/src/android/barcodescanner-release-2.1.0.aar b/src/android/barcodescanner-release-2.1.0.aar new file mode 100644 index 00000000..d4db7050 Binary files /dev/null and b/src/android/barcodescanner-release-2.1.0.aar differ diff --git a/src/android/com/phonegap/plugins/barcodescanner/BarcodeScanner.java b/src/android/com/phonegap/plugins/barcodescanner/BarcodeScanner.java index fe85d2a6..24f95e2e 100644 --- a/src/android/com/phonegap/plugins/barcodescanner/BarcodeScanner.java +++ b/src/android/com/phonegap/plugins/barcodescanner/BarcodeScanner.java @@ -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 void run() { 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)); } diff --git a/src/ios/CDVBarcodeScanner.bundle/torch.png b/src/ios/CDVBarcodeScanner.bundle/torch.png new file mode 100644 index 00000000..bc61037a Binary files /dev/null and b/src/ios/CDVBarcodeScanner.bundle/torch.png differ diff --git a/src/ios/CDVBarcodeScanner.bundle/torch@2x.png b/src/ios/CDVBarcodeScanner.bundle/torch@2x.png new file mode 100644 index 00000000..a3e4e85f Binary files /dev/null and b/src/ios/CDVBarcodeScanner.bundle/torch@2x.png differ diff --git a/src/ios/CDVBarcodeScanner.bundle/torch@3x.png b/src/ios/CDVBarcodeScanner.bundle/torch@3x.png new file mode 100644 index 00000000..d76584a3 Binary files /dev/null and b/src/ios/CDVBarcodeScanner.bundle/torch@3x.png differ diff --git a/src/ios/CDVBarcodeScanner.mm b/src/ios/CDVBarcodeScanner.mm index 820a50a6..9c9d0919 100644 --- a/src/ios/CDVBarcodeScanner.mm +++ b/src/ios/CDVBarcodeScanner.mm @@ -70,6 +70,7 @@ @interface CDVbcsProcessor : NSObject { @property (nonatomic) BOOL capturing; @property (nonatomic) BOOL isFrontCamera; @property (nonatomic) BOOL isShowFlipCameraButton; +@property (nonatomic) BOOL isShowTorchButton; @property (nonatomic) BOOL isFlipped; @@ -162,6 +163,8 @@ - (void)scan:(CDVInvokedUrlCommand*)command { } 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 @@ - (void)scan:(CDVInvokedUrlCommand*)command { processor.isShowFlipCameraButton = true; } + if (showTorchButton) { + processor.isShowTorchButton = true; + } + processor.formats = options[@"formats"]; [processor performSelector:@selector(scanBarcode) withObject:nil afterDelay:0]; @@ -428,6 +435,19 @@ - (void)flipCamera { }]; } +- (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 @@ - (void)flipCameraButtonPressed:(id)sender [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 @@ - (UIView*)buildOverlayView { action:@selector(flipCameraButtonPressed:) ] autorelease]; + NSMutableArray *items; + #if USE_SHUTTER id shutterButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera @@ -952,17 +979,36 @@ - (UIView*)buildOverlayView { ] 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];