/** * Opens the requested camera with {@link Camera#open(int)}, if one exists. * * @param requestedId camera ID of the camera to use. A negative value * or {@link #NO_REQUESTED_CAMERA} means "no preference" * @return handle to {@link Camera} that was opened */ public static Camera open(int requestedId) { int cameraId = getCameraId(requestedId); if (cameraId == -1) { return null; } else { return Camera.open(cameraId); } } }
/** * Must be called from camera thread. */ public void open() { camera = OpenCameraInterface.open(settings.getRequestedCameraId()); if (camera == null) { throw new RuntimeException("Failed to open camera"); } int cameraId = OpenCameraInterface.getCameraId(settings.getRequestedCameraId()); cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(cameraId, cameraInfo); }
public OpenCameraManager() { super(OpenCameraInterface.class, new DefaultOpenCameraInterface()); addImplementationClass(9, "com.google.zxing.client.android.camera.open.GingerbreadOpenCameraInterface"); }
/** * Closes the camera driver if still in use. */ public synchronized void closeDriver() { if (camera != null) { camera.getCamera().release(); camera = null; // Make sure to clear these each time we close the camera, so that any scanning rect // requested by intent is forgotten. framingRect = null; framingRectInPreview = null; } }
public CameraManager(Context context) { this.context = context; this.configManager = new CameraConfigurationManager(context); }
public Point getPreviewSize() { return configManager.getCameraResolution(); }
/** * Asks the camera hardware to begin drawing preview frames to the screen. */ public synchronized void startPreview() { Camera theCamera = camera; if (theCamera != null && !previewing) { theCamera.startPreview(); previewing = true; autoFocusManager = new AutoFocusManager(context, camera); } }
/** * Tells the camera to stop drawing preview frames. */ public synchronized void stopPreview() { if (autoFocusManager != null) { autoFocusManager.stop(); autoFocusManager = null; } if (camera != null && previewing) { camera.stopPreview(); //previewCallback.setHandler(null, 0); previewing = false; } }
@Override protected Object doInBackground(Object... voids) { try { Thread.sleep(AUTO_FOCUS_INTERVAL_MS); } catch (InterruptedException e) { // continue } synchronized (AutoFocusManager.this) { if (active) { start(); } } return null; } }
@Override public synchronized void onAutoFocus(boolean success, Camera theCamera) { if (active) { outstandingTask = new AutoFocusTask(); taskExec.execute(outstandingTask); } }
/** * Reads, one time, values from the camera that are needed by the app. */ void initFromCameraParameters(Camera camera,int viewWidth,int viewHeight) { Camera.Parameters parameters = camera.getParameters(); int width = viewWidth; int height = viewHeight; screenResolution = new Point(width, height); Log.i(TAG, "Screen resolution: " + screenResolution); cameraResolution = findBestPreviewSizeValue(parameters, screenResolution); Log.i(TAG, "Camera resolution: " + cameraResolution); }
@Override protected void onPause() { super.onPause(); mQRCdoeReaderView.getCameraManager().stopPreview(); }
@Override protected void onResume() { super.onResume(); mQRCdoeReaderView.getCameraManager().startPreview(); }
synchronized void stop() { if (useAutoFocus) { try { camera.cancelAutoFocus(); } catch (RuntimeException re) { // Have heard RuntimeException reported in Android 4.0.x+; continue? Log.w(TAG, "Unexpected exception while cancelling focusing", re); } } if (outstandingTask != null) { outstandingTask.cancel(true); outstandingTask = null; } active = false; }
/** * Closes the camera driver if still in use. */ public synchronized void closeDriver() { if (camera != null) { camera.getCamera().release(); camera = null; // Make sure to clear these each time we close the camera, so that any scanning rect // requested by intent is forgotten. framingRect = null; framingRectInPreview = null; } }
/** * Asks the camera hardware to begin drawing preview frames to the screen. */ public synchronized void startPreview() { OpenCamera theCamera = camera; if (theCamera != null && !previewing) { theCamera.getCamera().startPreview(); previewing = true; autoFocusManager = new AutoFocusManager(context, theCamera.getCamera()); } }
/** * Asks the camera hardware to begin drawing preview frames to the screen. */ public synchronized void startPreview() { OpenCamera theCamera = camera; if (theCamera != null && !previewing) { theCamera.getCamera().startPreview(); previewing = true; autoFocusManager = new AutoFocusManager(context, theCamera.getCamera()); } }
/** * A single preview frame will be returned to the handler supplied. The data will arrive as byte[] * in the message.obj field, with width and height encoded as message.arg1 and message.arg2, * respectively. * * @param handler The handler to send the message to. * @param message The what field of the message to be sent. */ public synchronized void requestPreviewFrame(Handler handler, int message) { OpenCamera theCamera = camera; if (theCamera != null && previewing) { previewCallback.setHandler(handler, message); theCamera.getCamera().setOneShotPreviewCallback(previewCallback); } }
/** * Tells the camera to stop drawing preview frames. */ public synchronized void stopPreview() { if (autoFocusManager != null) { autoFocusManager.stop(); autoFocusManager = null; } if (camera != null && previewing) { camera.getCamera().stopPreview(); previewCallback.setHandler(null, 0); previewing = false; } }
/** * A single preview frame will be returned to the handler supplied. The data will arrive as byte[] * in the message.obj field, with width and height encoded as message.arg1 and message.arg2, * respectively. * * @param handler The handler to send the message to. * @param message The what field of the message to be sent. */ public synchronized void requestPreviewFrame(Handler handler, int message) { OpenCamera theCamera = camera; if (theCamera != null && previewing) { previewCallback.setHandler(handler, message); theCamera.getCamera().setOneShotPreviewCallback(previewCallback); } }