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 boolean initialized;
private boolean previewing;
private int requestedCameraId = -1;
private int requestedFramingRectWidth;
private int requestedFramingRectHeight;
/**
@ -65,7 +66,7 @@ public final class CameraManager {
this.configManager = new CameraConfigurationManager(context);
previewCallback = new PreviewCallback(configManager);
}
/**
* Opens the camera driver and initializes the hardware parameters.
*
@ -75,8 +76,14 @@ public final class CameraManager {
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
Camera theCamera = camera;
if (theCamera == null) {
theCamera = OpenCameraInterface.open();
if (theCamera == null) {
if (requestedCameraId > -1) {
theCamera = OpenCameraInterface.open(requestedCameraId);
} else {
theCamera = OpenCameraInterface.open();
}
if (theCamera == null) {
throw new IOException();
}
camera = theCamera;
@ -265,6 +272,21 @@ public final class CameraManager {
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
* them automatically based on screen resolution.