Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions ios/CsZBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface

#pragma mark - Plugin API

- (void)scan: (CDVInvokedUrlCommand*)command;
- (void)scan: (CDVInvokedUrlCommand*)command;
{
if (self.scanInProgress) {
[self.commandDelegate
Expand All @@ -62,7 +62,7 @@ - (void)scan: (CDVInvokedUrlCommand*)command;
self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;

NSString *flash = [params objectForKey:@"flash"];

if ([flash isEqualToString:@"on"]) {
self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
} else if ([flash isEqualToString:@"off"]) {
Expand All @@ -85,24 +85,27 @@ - (void)scan: (CDVInvokedUrlCommand*)command;
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

BOOL drawSight = [params objectForKey:@"drawSight"] ? [[params objectForKey:@"drawSight"] boolValue] : true;
UIToolbar *toolbarViewFlash = [[UIToolbar alloc] init];

//The bar length it depends on the orientation
toolbarViewFlash.frame = CGRectMake(0.0, 0, (screenWidth > screenHeight ?screenWidth:screenHeight), 44.0);
toolbarViewFlash.barStyle = UIBarStyleBlackOpaque;
UIBarButtonItem *buttonFlash = [[UIBarButtonItem alloc] initWithTitle:@"Flash" style:UIBarButtonItemStyleDone target:self action:@selector(toggleflash)];

NSArray *buttons = [NSArray arrayWithObjects: buttonFlash, nil];
[toolbarViewFlash setItems:buttons animated:NO];
[self.scanReader.view addSubview:toolbarViewFlash];

if (drawSight) {
CGFloat dim = screenWidth < screenHeight ? screenWidth / 1.1 : screenHeight / 1.1;
UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( (screenWidth/2) - (dim/2), (screenHeight/2) - (dim/2), dim, dim)];

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,dim / 2, dim, 1)];
UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( (screenWidth/2) - (dim/2), (screenHeight/2) - (dim/2), dim, dim)];
//polygonView.center = self.scanReader.view.center;
polygonView.layer.borderColor = [UIColor whiteColor].CGColor;
polygonView.layer.borderWidth = 3.0f;

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, dim / 2, dim, 1)];
lineView.backgroundColor = [UIColor redColor];
[polygonView addSubview:lineView];

Expand All @@ -115,7 +118,7 @@ - (void)scan: (CDVInvokedUrlCommand*)command;

- (void)toggleflash {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

[device lockForConfiguration:nil];
if (device.torchAvailable == 1) {
if (device.torchMode == 0) {
Expand All @@ -126,7 +129,7 @@ - (void)toggleflash {
[device setFlashMode:AVCaptureFlashModeOff];
}
}

[device unlockForConfiguration];
}

Expand All @@ -146,9 +149,9 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM
if ([self.scanReader isBeingDismissed]) {
return;
}

id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];

ZBarSymbol *symbol = nil;
for (symbol in results) break; // get the first result

Expand Down