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
63 changes: 25 additions & 38 deletions android/ZBarScannerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PreviewCallback;
import android.hardware.Camera.AutoFocusCallback;
import android.nfc.Tag;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
Expand Down Expand Up @@ -201,19 +202,7 @@ public void onResume ()
super.onResume();

try {
if(whichCamera.equals("front")) {
int numCams = Camera.getNumberOfCameras();
CameraInfo cameraInfo = new CameraInfo();
for(int i=0; i<numCams; i++) {
Camera.getCameraInfo(i, cameraInfo);
if(cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
camera = Camera.open(i);
}
}
} else {
camera = Camera.open();
}

ensureCameraIsOpen();
if(camera == null) throw new Exception ("Error: No suitable camera found.");
} catch (RuntimeException e) {
//die("Error: Could not open the camera.");
Expand All @@ -223,7 +212,29 @@ public void onResume ()
return;
}
}

private void ensureCameraIsOpen() {
if (whichCamera.equals("front")) {
int numCams = Camera.getNumberOfCameras();
CameraInfo cameraInfo = new CameraInfo();
for(int i=0; i<numCams; i++) {
Camera.getCameraInfo(i, cameraInfo);
if(cameraInfo.facing == CameraInfo.CAMERA_FACING_FRONT) {
camera = Camera.open(i);
}
}
} else {
camera = Camera.open();
}
}

private void setCameraDisplayOrientation(Activity activity ,int cameraId) {
ensureCameraIsOpen();
if (camera == null) {
Log.w(this.getClass().getName(), "No suitable camera found");
return;
}

android.hardware.Camera.CameraInfo info =
new android.hardware.Camera.CameraInfo();
android.hardware.Camera.getCameraInfo(cameraId, info);
Expand Down Expand Up @@ -303,31 +314,7 @@ public void surfaceChanged (SurfaceHolder hld, int fmt, int w, int h)
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();

Expand Down