From 8fb6b04f790575eec226808b8cc461f134c1083c Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Fri, 6 Feb 2015 15:20:14 +0100 Subject: [PATCH] =?UTF-8?q?Impl=C3=A9mentation=20du=20switch=20camera=20av?= =?UTF-8?q?ec=20prise=20en=20compte=20des=20rotations=20de=20la=20preview?= =?UTF-8?q?=20et=20de=20l'effet=20miroir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../geneanet/customcamera/CameraActivity.java | 42 +++++++-------- .../geneanet/customcamera/ManagerCamera.java | 51 +++++++++++++++++++ 2 files changed, 68 insertions(+), 25 deletions(-) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 63510d5..7d9c20d 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -655,13 +655,12 @@ public class CameraActivity extends Activity { Matrix mat = new Matrix(); int defaultOrientation = getDeviceDefaultOrientation(); int orientationCamera = getOrientationOfCamera(); - int redirect = 0; + int redirect = CameraActivity.DEGREE_0; + switch (getCustomRotation()) { case 0: redirect = CameraActivity.DEGREE_90; - // If the device is in front camera by default - if (orientationCamera == 1 - && defaultOrientation == Configuration.ORIENTATION_PORTRAIT) { + if (ManagerCamera.currentCameraIsFacingFront() || orientationCamera == 1) { redirect = CameraActivity.DEGREE_270; } break; @@ -669,10 +668,11 @@ public class CameraActivity extends Activity { redirect = CameraActivity.DEGREE_0; break; case 2: - redirect = CameraActivity.DEGREE_270; - // If the device is in front camera by default - if (orientationCamera == 1 - && defaultOrientation == Configuration.ORIENTATION_PORTRAIT) { + // Only on device with landscape mode by default. + if (defaultOrientation == Configuration.ORIENTATION_LANDSCAPE) { + redirect = CameraActivity.DEGREE_270; + } + if (ManagerCamera.currentCameraIsFacingFront() || orientationCamera == 1) { redirect = CameraActivity.DEGREE_90; } break; @@ -683,6 +683,14 @@ public class CameraActivity extends Activity { break; } mat.postRotate(redirect); + // We execute a mirror to the matrix in case of front camera. + if (ManagerCamera.currentCameraIsFacingFront() || orientationCamera == 1 ) { + if (getCustomRotation() == 0 || getCustomRotation() == 2) { + mat.preScale(1.0f, -1.0f); + } else if (getCustomRotation() == 1 || getCustomRotation() == 3) { + mat.preScale(-1.0f, 1.0f); + } + } // Creation of the bitmap photoTaken = Bitmap.createBitmap(photoTaken, 0, 0, @@ -1000,22 +1008,6 @@ public class CameraActivity extends Activity { (supportedFlashModes.size() == 1 && supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) ); } - - /** - * Check if a front camera exist. - * return boolean - */ - public boolean hasFrontCamera() { - int numCameras = Camera.getNumberOfCameras(); - for (int i = 0; i < numCameras; i++) { - Camera.CameraInfo info = new CameraInfo(); - Camera.getCameraInfo(i, info); - if (CameraInfo.CAMERA_FACING_FRONT == info.facing) { - return true; - } - } - return false; - } /** * To change the active camera. @@ -1034,7 +1026,7 @@ public class CameraActivity extends Activity { } /** - * + * To stabilize the orientation of the camera preview. * @param activity * @param cameraId * @param camera diff --git a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java index a654c62..fc1c713 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java @@ -54,14 +54,31 @@ public class ManagerCamera { } } + /** + * Return a function to determine the front camera in use. + * + * @return function + */ public static int determinePositionFrontCamera() { return determineCamera(Camera.CameraInfo.CAMERA_FACING_FRONT); } + /** + * Return a function to determine the back camera in use. + * + * @return function + */ public static int determinePositionBackCamera() { return determineCamera(Camera.CameraInfo.CAMERA_FACING_BACK); } + /** + * + * + * @param position Back or front camera. + * + * @return the cameraId of the current camera if it exists. + */ protected static Integer determineCamera(int position) { CameraInfo info = new Camera.CameraInfo(); if (Camera.getNumberOfCameras() == 0) { @@ -80,10 +97,20 @@ public class ManagerCamera { return 0; } + /** + * Get the currentCamera. + * + * @return the value of the variable. + */ private static int getCurrentFacingCamera() { return currentCameraPosition; } + /** + * Determine the opposite camera of which currently in use. + * + * @return function. + */ public static int determineOppositeCamera() { if (getCurrentFacingCamera() == Camera.CameraInfo.CAMERA_FACING_BACK) { return determinePositionFrontCamera(); @@ -91,4 +118,28 @@ public class ManagerCamera { return determinePositionBackCamera(); } } + + /** + * Determine if the current camera is front. + * + * @return True if the current camera is front. Else return false. + */ + public static boolean currentCameraIsFacingBack() { + if (getCurrentFacingCamera() == Camera.CameraInfo.CAMERA_FACING_BACK) { + return true; + } + return false; + } + + /** + * Determine if the camera is back. + * + * @return True if the current camera is back. Else return false. + */ + public static boolean currentCameraIsFacingFront() { + if (getCurrentFacingCamera() == Camera.CameraInfo.CAMERA_FACING_FRONT) { + return true; + } + return false; + } }