From 1cd8388b0cd81731d2101764bb7729f18803e206 Mon Sep 17 00:00:00 2001 From: slepmog Date: Thu, 1 May 2014 05:22:06 -0700 Subject: [PATCH] Added setManualCameraId() and amended openDriver() --- .../client/android/camera/CameraManager.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/android/src/com/google/zxing/client/android/camera/CameraManager.java b/android/src/com/google/zxing/client/android/camera/CameraManager.java index 9349b252f..7fc273116 100755 --- a/android/src/com/google/zxing/client/android/camera/CameraManager.java +++ b/android/src/com/google/zxing/client/android/camera/CameraManager.java @@ -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.