diff --git a/hooks/before_build/generateActivity.js b/hooks/before_build/generateActivity.js index 1c0de2f..87b40e5 100644 --- a/hooks/before_build/generateActivity.js +++ b/hooks/before_build/generateActivity.js @@ -125,7 +125,7 @@ var updateConfig = function() { translationsForApplication = JSON.parse(translationsForApplication); for (lang in translationsForApplication) { var pathFileTranslate = pathResAndroidCordova+"values-"+lang+"/"; - if (lang == "0") { + if (lang == "default") { pathFileTranslate = pathResAndroidCordova+"values/"; } diff --git a/res/translations.json b/res/translations.json index f1c9e1c..5fd127c 100644 --- a/res/translations.json +++ b/res/translations.json @@ -1,5 +1,5 @@ { - "0": { + "default": { "miniature": "Miniature", "capture": "Capture", "acceptePicture": "Valid the picture", diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 3d0a66a..b97399e 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -75,16 +75,20 @@ public class CameraActivity extends Activity { /** * To get camera resource or stop this activity. * + * @param position The position of the camera. + * * @return boolean */ - protected boolean initCameraResource() { - int defaultCamera; - if (this.getIntent().getIntExtra("defaultCamera", CameraActivity.CAMERA_BACK) == CameraActivity.CAMERA_FRONT) { - defaultCamera = ManagerCamera.determinePositionFrontCamera(); - } else { - defaultCamera = ManagerCamera.determinePositionBackCamera(); + protected boolean initCameraResource(Integer position) { + if (position == null) { + if (this.getIntent().getIntExtra("defaultCamera", CameraActivity.CAMERA_BACK) == CameraActivity.CAMERA_FRONT) { + position = ManagerCamera.determinePositionFrontCamera(); + } else { + position = ManagerCamera.determinePositionBackCamera(); + } } - customCamera = ManagerCamera.getCameraInstance(defaultCamera); + customCamera = ManagerCamera.getCameraInstance(position); + ManagerCamera.setCameraDisplayOrientation(this); if (customCamera == null) { this.setResult(2, @@ -208,33 +212,12 @@ public class CameraActivity extends Activity { super.onStart(); // Init camera resource. - if (!initCameraResource()) { + if (!initCameraResource(null)) { return; } stateFlash = this.getIntent().getIntExtra("defaultFlash", CameraActivity.FLASH_DISABLE); - updateStateFlash(stateFlash); - - int orientation = 0; - switch (getCustomRotation()) { - case 0: - orientation = CameraActivity.DEGREE_90; - break; - case 1: - orientation = CameraActivity.DEGREE_0; - break; - case 2: - orientation = CameraActivity.DEGREE_270; - break; - case 3: - orientation = CameraActivity.DEGREE_180; - break; - default: - break; - } - - customCamera.setDisplayOrientation(orientation); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); @@ -1028,8 +1011,7 @@ public class CameraActivity extends Activity { */ public void switchCamera(View view) { int oppositeCamera = ManagerCamera.determineOppositeCamera(); - customCamera = ManagerCamera.getCameraInstance(oppositeCamera); - setCameraDisplayOrientation(CameraActivity.this, oppositeCamera, customCamera); + initCameraResource(oppositeCamera); FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview); cameraPreview.removeAllViews(); CameraPreview myPreview = new CameraPreview(this, customCamera); @@ -1037,34 +1019,4 @@ public class CameraActivity extends Activity { // To re-display the flash. updateStateFlash(stateFlash); } - - /** - * To stabilize the orientation of the camera preview. - * @param activity - * @param cameraId - * @param camera - */ - public static void setCameraDisplayOrientation(Activity activity, - int cameraId, android.hardware.Camera camera) { - Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); - Camera.getCameraInfo(cameraId, info); - int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); - int degrees = 0; - switch (rotation) { - case Surface.ROTATION_0: degrees = 0; break; - case Surface.ROTATION_90: degrees = 90; break; - case Surface.ROTATION_180: degrees = 180; break; - case Surface.ROTATION_270: degrees = 270; break; - default : break; - } - - int result; - if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { - result = (info.orientation + degrees) % 360; - result = (360 - result) % 360; // compensate the mirror - } else { // back-facing - result = (info.orientation - degrees + 360) % 360; - } - camera.setDisplayOrientation(result); - } } diff --git a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java index 95c3782..e86a53f 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java @@ -1,8 +1,10 @@ package org.geneanet.customcamera; +import android.app.Activity; import android.hardware.Camera; import android.hardware.Camera.CameraInfo; import android.util.Log; +import android.view.Surface; /** * Manage camera resource. @@ -55,23 +57,36 @@ public class ManagerCamera { } /** - * Return a function to determine the front camera in use. + * Return the value of the position of the front camera. * - * @return function + * @return int */ public static int determinePositionFrontCamera() { return determineCamera(Camera.CameraInfo.CAMERA_FACING_FRONT); } /** - * Return a function to determine the back camera in use. + * Return the value of the position of the back camera. * - * @return function + * @return int */ public static int determinePositionBackCamera() { return determineCamera(Camera.CameraInfo.CAMERA_FACING_BACK); } + /** + * Determine the opposite camera of which currently in use. + * + * @return int. + */ + public static int determineOppositeCamera() { + if (getCurrentFacingCamera() == Camera.CameraInfo.CAMERA_FACING_BACK) { + return determinePositionFrontCamera(); + } else { + return determinePositionBackCamera(); + } + } + /** * Determine the cameraId of the camera currently in use. * @@ -98,25 +113,15 @@ public class ManagerCamera { } /** - * Get the currentCamera. + * Get the current camera. * - * @return the value of the variable. + * @return the value of currentCameraPosition. */ 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(); - } else { - return determinePositionBackCamera(); - } + CameraInfo info = new Camera.CameraInfo(); + Camera.getCameraInfo(currentCameraPosition, info); + + return info.facing; } /** @@ -142,4 +147,33 @@ public class ManagerCamera { } return false; } + + /** + * To stabilize the orientation of the camera preview. + * @param activity + * @param cameraId + * @param camera + */ + public static void setCameraDisplayOrientation(Activity activity) { + CameraInfo info = new Camera.CameraInfo(); + Camera.getCameraInfo(ManagerCamera.currentCameraPosition, info); + int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); + int degrees = 0; + switch (rotation) { + case Surface.ROTATION_0: degrees = 0; break; + case Surface.ROTATION_90: degrees = 90; break; + case Surface.ROTATION_180: degrees = 180; break; + case Surface.ROTATION_270: degrees = 270; break; + default : break; + } + + int result; + if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { + result = (info.orientation + degrees) % 360; + result = (360 - result) % 360; // compensate the mirror + } else { // back-facing + result = (info.orientation - degrees + 360) % 360; + } + ManagerCamera.mCamera.setDisplayOrientation(result); + } }