Merge pull request #66 from tjwoon/fixes

Fixes
This commit is contained in:
Daniel Cousens 2016-04-22 13:37:30 +10:00
commit 843b432d56
11 changed files with 423 additions and 118 deletions

View File

@ -6,6 +6,7 @@
This plugin integrates with the [ZBar](http://zbar.sourceforge.net/) library,
exposing a JavaScript interface for scanning barcodes (QR, 2D, etc).
In this fork a button has been added to turn off and on device flash. In addition the plugin can now handle the device orientation change.
## Installation

View File

@ -5,15 +5,20 @@ import java.lang.RuntimeException;
import org.json.JSONException;
import org.json.JSONObject;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PreviewCallback;
import android.hardware.Camera.AutoFocusCallback;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.SurfaceHolder;
@ -22,6 +27,9 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.content.pm.PackageManager;
import android.view.Surface;
import java.util.ArrayList;
import java.util.Collection;
@ -43,14 +51,14 @@ implements SurfaceHolder.Callback {
// Config ----------------------------------------------------------
private static int autoFocusInterval = 500; // Interval between AFcallback and next AF attempt.
private static int autoFocusInterval = 2000; // Interval between AFcallback and next AF attempt.
// 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;
private static final int CAMERA_PERMISSION_REQUEST = 1;
// State -----------------------------------------------------------
private Camera camera;
@ -80,73 +88,111 @@ implements SurfaceHolder.Callback {
// Activity Lifecycle ----------------------------------------------
@Override
public void onCreate (Bundle savedInstanceState)
{
public void onCreate (Bundle savedInstanceState) {
int permissionCheck = ContextCompat.checkSelfPermission(this.getBaseContext(), Manifest.permission.CAMERA);
if(permissionCheck == PackageManager.PERMISSION_GRANTED){
setUpCamera();
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA},
CAMERA_PERMISSION_REQUEST);
}
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");
Boolean drawSight = params.optBoolean("drawSight", true);
whichCamera = params.optString("camera");
flashMode = params.optString("flash");
// Initiate instance variables
autoFocusHandler = new Handler();
scanner = new ImageScanner();
scanner.setConfig(0, Config.X_DENSITY, 3);
scanner.setConfig(0, Config.Y_DENSITY, 3);
}
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case CAMERA_PERMISSION_REQUEST: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
setUpCamera();
} else {
// Set the config for barcode formats
for(ZBarcodeFormat format : getFormats()) {
scanner.setConfig(format.getId(), Config.ENABLE, 1);
}
// 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);
// Draw/hide the sight
if(!drawSight) {
findViewById(getResourceId("id/csZbarScannerSight")).setVisibility(View.INVISIBLE);
}
// Create preview SurfaceView
scannerSurface = new SurfaceView (this) {
@Override
public void onSizeChanged (int w, int h, int oldW, int oldH) {
surfW = w;
surfH = h;
matchSurfaceToPreviewRatio();
onBackPressed();
}
return;
}
};
scannerSurface.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER
));
scannerSurface.getHolder().addCallback(this);
// Add preview SurfaceView to the screen
FrameLayout scannerView = (FrameLayout) findViewById(getResourceId("id/csZbarScannerView"));
scannerView.addView(scannerSurface);
// other 'case' lines to check for other
// permissions this app might request
}
}
private void setUpCamera() {
// If request is cancelled, the result arrays are empty.
// 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");
Boolean drawSight = params.optBoolean("drawSight", true);
whichCamera = params.optString("camera");
flashMode = params.optString("flash");
// Initiate instance variables
autoFocusHandler = new Handler();
scanner = new ImageScanner();
scanner.setConfig(0, Config.X_DENSITY, 3);
scanner.setConfig(0, Config.Y_DENSITY, 3);
// Set the config for barcode formats
for(ZBarcodeFormat format : getFormats()) {
scanner.setConfig(format.getId(), Config.ENABLE, 1);
}
// 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);
// Draw/hide the sight
if(!drawSight) {
findViewById(getResourceId("id/csZbarScannerSight")).setVisibility(View.INVISIBLE);
}
// Create preview SurfaceView
scannerSurface = new SurfaceView (this) {
@Override
public void onSizeChanged (int w, int h, int oldW, int oldH) {
surfW = w;
surfH = h;
matchSurfaceToPreviewRatio();
}
};
scannerSurface.setLayoutParams(new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER
));
scannerSurface.getHolder().addCallback(this);
// Add preview SurfaceView to the screen
FrameLayout scannerView = (FrameLayout) findViewById(getResourceId("id/csZbarScannerView"));
scannerView.addView(scannerSurface);
findViewById(getResourceId("id/csZbarScannerTitle")).bringToFront();
findViewById(getResourceId("id/csZbarScannerInstructions")).bringToFront();
findViewById(getResourceId("id/csZbarScannerSightContainer")).bringToFront();
findViewById(getResourceId("id/csZbarScannerSight")).bringToFront();
scannerView.requestLayout();
scannerView.invalidate();
findViewById(getResourceId("id/csZbarScannerTitle")).bringToFront();
findViewById(getResourceId("id/csZbarScannerInstructions")).bringToFront();
findViewById(getResourceId("id/csZbarScannerSightContainer")).bringToFront();
findViewById(getResourceId("id/csZbarScannerSight")).bringToFront();
scannerView.requestLayout();
scannerView.invalidate();
}
@Override
@ -170,33 +216,36 @@ implements SurfaceHolder.Callback {
if(camera == null) throw new Exception ("Error: No suitable camera found.");
} catch (RuntimeException e) {
die("Error: Could not open the camera.");
//die("Error: Could not open the camera.");
return;
} catch (Exception e) {
die(e.getMessage());
// die(e.getMessage());
return;
}
Camera.Parameters camParams = camera.getParameters();
if(flashMode.equals("on")) {
camParams.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
} else if(flashMode.equals("off")) {
camParams.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
} else {
camParams.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
}
if (android.os.Build.VERSION.SDK_INT >= 14) {
camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
}
try { camera.setParameters(camParams); }
catch (RuntimeException e) {
Log.d("csZBar", "Unsupported camera parameter reported for flash mode: "+flashMode);
}
tryStartPreview();
}
private void setCameraDisplayOrientation(Activity activity ,int cameraId) {
android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(cameraId, info);
int rotation = activity.getWindowManager().getDefaultDisplay()
.getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0: degrees = 0; break;
case Surface.ROTATION_90: degrees = 90; break;
case Surface.ROTATION_180: degrees = 180; break;
case Surface.ROTATION_270: degrees = 270; break;
}
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (info.orientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} else { // back-facing
result = (info.orientation - degrees + 360) % 360;
}
camera.setDisplayOrientation(result);
}
@Override
public void onPause ()
{
@ -207,7 +256,7 @@ implements SurfaceHolder.Callback {
@Override
public void onDestroy ()
{
scanner.destroy();
if(scanner != null) scanner.destroy();
super.onDestroy();
}
@ -251,7 +300,75 @@ implements SurfaceHolder.Callback {
holder = hld;
tryStartPreview();
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
int rotation = getWindowManager().getDefaultDisplay().getRotation();
switch(rotation)
{
case 0: // '\0'
rotation = 90;
break;
case 1: // '\001'
rotation = 0;
break;
case 2: // '\002'
rotation = 270;
break;
case 3: // '\003'
rotation = 180;
break;
default:
rotation = 90;
break;
}
camera.setDisplayOrientation(rotation);
android.hardware.Camera.Parameters params = camera.getParameters();
tryStopPreview();
tryStartPreview();
}
public void toggleFlash(View view) {
camera.startPreview();
android.hardware.Camera.Parameters camParams = camera.getParameters();
//If the flash is set to off
try {
if (camParams.getFlashMode().equals(Parameters.FLASH_MODE_OFF) && !(camParams.getFlashMode().equals(Parameters.FLASH_MODE_TORCH)) && !(camParams.getFlashMode().equals(Parameters.FLASH_MODE_ON)))
camParams.setFlashMode(Parameters.FLASH_MODE_TORCH);
else //if(camParams.getFlashMode() == Parameters.FLASH_MODE_ON || camParams.getFlashMode()== Parameters.FLASH_MODE_TORCH)
camParams.setFlashMode(Parameters.FLASH_MODE_OFF);
} catch(RuntimeException e) {
}
try {
// camera.setParameters(camParams);
camera.setPreviewDisplay(holder);
camera.setPreviewCallback(previewCb);
camera.startPreview();
if (android.os.Build.VERSION.SDK_INT >= 14) {
camera.autoFocus(autoFocusCb); // We are not using any of the
// continuous autofocus modes as that does not seem to work
// well with flash setting of "on"... At least with this
// simple and stupid focus method, we get to turn the flash
// on during autofocus.
camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
}
//tryStopPreview();
//tryStartPreview();
//camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
camera.setParameters(camParams);
} catch(RuntimeException e) {
Log.d("csZBar", (new StringBuilder("Unsupported camera parameter reported for flash mode: ")).append(flashMode).toString());
} catch (IOException e) {
Log.d("csZBar", (new StringBuilder("Wrong holder data")).append(flashMode).toString());
}
}
// Continuously auto-focus -----------------------------------------
// For API Level < 14
@ -380,8 +497,43 @@ implements SurfaceHolder.Callback {
private void tryStartPreview () {
if(holder != null) {
try {
int rotation = getWindowManager().getDefaultDisplay().getRotation();
switch(rotation)
{
case 0: // '\0'
rotation = 90;
break;
case 1: // '\001'
rotation = 0;
break;
case 2: // '\002'
rotation = 270;
break;
case 3: // '\003'
rotation = 180;
break;
default:
rotation = 90;
break;
}
// 90 degrees rotation for Portrait orientation Activity.
camera.setDisplayOrientation(90);
// camera.setDisplayOrientation(rotation);
setCameraDisplayOrientation(this, 0);
android.hardware.Camera.Parameters camParams = camera.getParameters();
//camParams.setFlashMode(Parameters.FLASH_MODE_TORCH);
try {
camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
camera.setParameters(camParams);
} catch (Exception e) {
// TODO: don't swallow
}
camera.setPreviewDisplay(holder);
camera.setPreviewCallback(previewCb);

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/csZbarScannerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/csZbarScannerBackground" >
<TextView android:id="@+id/csZbarScannerTitle"
@ -18,29 +18,29 @@
android:textColor="@color/csZbarScannerTextColor"
android:background="@color/csZbarScannerTextBackground"
android:fontFamily="sans-serif-light"
android:textSize="20pt" />
android:textSize="15pt" />
<TextView android:id="@+id/csZbarScannerInstructions"
android:layout_gravity="bottom|center_horizontal"
android:layout_width="match_parent"
android:layout_gravity="center|bottom"
android:layout_width="296dp"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="15dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:gravity="center"
android:textSize="12pt"
android:textSize="8pt"
android:textColor="@color/csZbarScannerTextColor"
android:background="@color/csZbarScannerTextBackground"
android:fontFamily="sans-serif-light"
android:text="@string/csZbarScannerInstructions" />
<RelativeLayout android:id="@+id/csZbarScannerSightContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal|bottom">
<View android:id="@+id/csZbarScannerSight"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
@ -48,6 +48,19 @@
android:gravity="center_vertical"
android:background="#ff0000" />
<ImageButton
android:layout_width="60dp"
android:layout_height="70dp"
android:id="@+id/imageButton"
android:src="@drawable/camera_flash"
android:background="@color/csZbarScannerTextBackground"
android:onClick="toggleFlash"
android:longClickable="true"
android:visibility="visible"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
</FrameLayout>

View File

@ -7,6 +7,7 @@
//
#import "AlmaZBarReaderViewController.h"
#import "CsZbar.h"
@interface AlmaZBarReaderViewController ()
@ -14,28 +15,92 @@
@implementation AlmaZBarReaderViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//[button setTitle:@"Flash" forState:UIControlStateNormal];
[button sizeToFit];
CGRect screenRect = [[UIScreen mainScreen] bounds];
//[button setContentEdgeInsets:UIEdgeInsetsMake(20, 30, 20, 30)];
CGRect frame;
if(screenRect.size.height>(screenRect.size.width)){
frame = CGRectMake(0,0, screenRect.size.width*(0.15), screenRect.size.height*0.15);
//button.center = CGPointMake( 0,0);
}else{
frame = CGRectMake(0,0, screenRect.size.width*(0.10), screenRect.size.height*0.20);
//button.center = CGPointMake(0,0);
}
button.frame =frame;
button.layer.cornerRadius = 10;
button.clipsToBounds = YES;
// Set a new (x,y) point for the button's center
//[button setBackgroundColor:[UIColor colorWithRed:.859 green:.765 blue:.616 alpha:1.0] forState:UIControlStateHighlighted];
//button.center = CGPointMake( 0,0);
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate{
return NO;
//Techedge Changes NSS fase 2
- (void)buttonPressed: (UIButton *) button {
CsZBar *obj = [[CsZBar alloc] init];
[obj toggleflash];
}
- (BOOL)shouldAutorotate{
return YES;
}
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
//AlmaZBarReaderViewController.scanner.scanner.cameraOverlayView = poli
//NSDictionary *params = (NSDictionary*) [command argumentAtIndex:0];
BOOL drawSight = true;//[params objectForKey:@"drawSight"] ? [[params objectForKey:@"drawSight"] boolValue] : true;
if(drawSight){
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
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)];
//polygonView.center = self.scanReader.view.center;
//polygonView.layer.borderColor = [UIColor greenColor].CGColor;
//polygonView.layer.borderWidth = 3.0f;
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,dim / 2, dim, 1)];
lineView.backgroundColor = [UIColor redColor];
[polygonView addSubview:lineView];
self.cameraOverlayView = polygonView;
}
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end

View File

@ -1,9 +1,14 @@
#import <Cordova/CDV.h>
#import "ZBarSDK.h"
#import <UIKit/UIKit.h>
@interface CsZBar : CDVPlugin <ZBarReaderDelegate>
- (void)scan: (CDVInvokedUrlCommand*)command;
- (void)toggleflash;
@end

View File

@ -1,4 +1,5 @@
#import "CsZBar.h"
#import <AVFoundation/AVFoundation.h>
#import "AlmaZBarReaderViewController.h"
#pragma mark - State
@ -7,6 +8,7 @@
@property bool scanInProgress;
@property NSString *scanCallbackId;
@property AlmaZBarReaderViewController *scanReader;
@end
@ -25,12 +27,31 @@
{
self.scanInProgress = NO;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
return;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait);
}
/*
- (void)viewDidLoad {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:@"Turn on Flash" forState:UIControlStateNormal];
[button sizeToFit];
// Set a new (x,y) point for the button's center
button.center = CGPointMake(320/2, 60);
[button addTarget:self action:@selector(flashOn) forControlEvents:UIControlEventTouchUpInside];
[self.viewController parentViewController:button];
}*/
#pragma mark - Plugin API
- (void)scan: (CDVInvokedUrlCommand*)command;
{
if(self.scanInProgress) {
[self.commandDelegate
sendPluginResult: [CDVPluginResult
@ -53,29 +74,48 @@
// as not all devices will have a rear-facing camera.
self.scanReader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
NSString *flash = [params objectForKey:@"flash"];
if([flash isEqualToString:@"on"]) {
if([flash isEqualToString:@"on"]) {
self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOn;
} else if([flash isEqualToString:@"off"]) {
self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
}else if([flash isEqualToString:@"auto"]) {
self.scanReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeAuto;
}
// Hack to hide the bottom bar's Info button... originally based on http://stackoverflow.com/a/16353530
UIView *infoButton = [[[[[self.scanReader.view.subviews objectAtIndex:2] subviews] objectAtIndex:0] subviews] objectAtIndex:3];
[infoButton setHidden:YES];
// Add an action in current code file (i.e. target)
// [infoButton addTarget: action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
//UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setTitle:@"Press Me" forState:UIControlStateNormal]; [button sizeToFit]; [self.view addSubview:button];
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){
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
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 *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 greenColor].CGColor;
//polygonView.layer.borderWidth = 3.0f;
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(dim / 2, 0, 1, dim)];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,dim / 2, dim, 1)];
lineView.backgroundColor = [UIColor redColor];
[polygonView addSubview:lineView];
@ -87,6 +127,23 @@
}
}
- (void)toggleflash{
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil];
if (device.torchAvailable == 1) {
if (device.torchMode == 0) {
[device setTorchMode:AVCaptureTorchModeOn];
[device setFlashMode:AVCaptureFlashModeOn];
}else{
[device setTorchMode:AVCaptureTorchModeOff];
[device setFlashMode:AVCaptureFlashModeOff];
}
}
[device unlockForConfiguration];
}
#pragma mark - Helpers
@ -98,6 +155,10 @@
#pragma mark - ZBarReaderDelegate
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
return;
}
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
if ([self.scanReader isBeingDismissed]) { return; }

View File

@ -1,6 +1,6 @@
{
"name": "cordova-plugin-cszbar",
"version": "1.3.1",
"version": "1.3.3",
"description": "Plugin to integrate with the ZBar barcode scanning library.",
"cordova": {
"id": "cordova-plugin-cszbar",

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-cszbar" version="1.3.1">
id="cordova-plugin-cszbar" version="1.3.2">
<engines>
<engine name="cordova" version=">=3.0.0" />
@ -23,11 +23,10 @@
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="application">
<activity
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:name="org.cloudsky.cordovaPlugins.ZBarScannerActivity"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="portrait" >
</activity>
android:screenOrientation="fullUser"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-feature android:name="android.hardware.camera" />
@ -43,6 +42,7 @@
<color name="csZbarScannerTextBackground">#88000000</color>
<color name="csZbarScannerBackground">#000000</color>
</config-file>
<framework src="com.android.support:support-v4:23.1.0" />
<resource-file src="android/res/layout/cszbarscanner.xml" target="res/layout/cszbarscanner.xml" />
<source-file src="android/ZBarcodeFormat.java" target-dir="src/org/cloudsky/cordovaPlugins" />
<source-file src="android/ZBar.java" target-dir="src/org/cloudsky/cordovaPlugins" />
@ -52,8 +52,16 @@
<source-file src="android/libs/armeabi/libzbarjni.so" target-dir="libs/armeabi" />
<source-file src="android/libs/armeabi-v7a/libiconv.so" target-dir="libs/armeabi-v7a" />
<source-file src="android/libs/armeabi-v7a/libzbarjni.so" target-dir="libs/armeabi-v7a" />
<source-file src="android/libs/arm64-v8a/libiconv.so" target-dir="libs/arm64-v8a" />
<source-file src="android/libs/arm64-v8a/libzbarjni.so" target-dir="libs/arm64-v8a" />s
<source-file src="android/libs/x86/libiconv.so" target-dir="libs/x86" />
<source-file src="android/libs/x86/libzbarjni.so" target-dir="libs/x86" />
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-hdpi"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-ldpi"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-mdpi"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-xhdpi"/>
<source-file src="android/res/drawable/camera_flash.png" target-dir="res/drawable-xxhdpi"/>
</platform>
<platform name="ios">