Added setManualCameraId() and amended openDriver()

This commit is contained in:
slepmog 2014-05-01 05:22:06 -07:00
parent f18b11d7d8
commit 1cd8388b0c

View file

@ -52,6 +52,7 @@ public final class CameraManager {
private Rect framingRectInPreview; private Rect framingRectInPreview;
private boolean initialized; private boolean initialized;
private boolean previewing; private boolean previewing;
private int requestedCameraId = -1;
private int requestedFramingRectWidth; private int requestedFramingRectWidth;
private int requestedFramingRectHeight; private int requestedFramingRectHeight;
/** /**
@ -75,7 +76,13 @@ public final class CameraManager {
public synchronized void openDriver(SurfaceHolder holder) throws IOException { public synchronized void openDriver(SurfaceHolder holder) throws IOException {
Camera theCamera = camera; Camera theCamera = camera;
if (theCamera == null) { if (theCamera == null) {
if (requestedCameraId > -1) {
theCamera = OpenCameraInterface.open(requestedCameraId);
} else {
theCamera = OpenCameraInterface.open(); theCamera = OpenCameraInterface.open();
}
if (theCamera == null) { if (theCamera == null) {
throw new IOException(); throw new IOException();
} }
@ -265,6 +272,21 @@ public final class CameraManager {
return framingRectInPreview; return framingRectInPreview;
} }
/**
* Allows third party apps to specify the camera ID, rather than determine
* it automatically based on available cameras and their orientation.
*
* @param cameraId camera ID of the camera to use
*/
public synchronized void setManualCameraId(int cameraId) {
if (initialized) {
// FIXME throw exception? Just store for future use? Do not want to suddenly swap cameras!
} else {
requestedCameraId = cameraId;
}
}
/** /**
* Allows third party apps to specify the scanning rectangle dimensions, rather than determine * Allows third party apps to specify the scanning rectangle dimensions, rather than determine
* them automatically based on screen resolution. * them automatically based on screen resolution.