From 930ccf7eff351a029c66099bb181b175c9c0bf68 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Wed, 28 Jan 2015 14:41:05 +0100 Subject: [PATCH 01/13] =?UTF-8?q?Premi=C3=A8re=20impl=C3=A9mentation=20du?= =?UTF-8?q?=20switch=20camera=20->=20Marche=20de=20camera=20back=20=C3=A0?= =?UTF-8?q?=20camera=20front=20mais=20pas=20l'inverse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/drawable-hdpi/switch_camera.png | Bin 0 -> 4646 bytes .../res/layout/activity_camera_view.xml | 9 ++ .../geneanet/customcamera/CameraActivity.java | 109 ++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 src/android/customCamera/res/drawable-hdpi/switch_camera.png diff --git a/src/android/customCamera/res/drawable-hdpi/switch_camera.png b/src/android/customCamera/res/drawable-hdpi/switch_camera.png new file mode 100644 index 0000000000000000000000000000000000000000..7a69823276a17e267cdafdb4f87faf00ca4f82ac GIT binary patch literal 4646 zcmV+>64~vEP)zw_-2g<+Wi5C8{23_t*IDwS$249h-%O#kx$qyQv<06@*WtJkjnPOP72 z01~~90Vn{zUNZod}q@%0&Ofe{uMF9*iZ=95Nhz)+=9jdPsw^+uKZxX=W8 zn&8;_c&fo9`k8Bi5!M+}ziYT}I1^dikLu7StxGt9Hns>f8v+ZAxnZdfwMEi^QI$&7 z7PAyU(c+9_5$NX5Fk+TgD%DKy%Y(_&CUe|Bf;P4YG#gTjGm%DL$PrZw!?Ftil}a_S z2sB`Z>TuMS{nWZ)S*cXBFf2FdeQfC^=V;3;F^e>qg2jE8!mu2SVgRz7a@q>%SRz-? z0N6T106eWTu6|}Xqb%{v8vtP$4%-0KGaMtd5dc_9mf03VZ;tBd4C%G4GiG02XPio< z8s!Xtm($V6G5|(rIJeI>05)xGiKj<7&IFd26msT2ZvcXvkuf?mDs7yz7?EX~Bb$|m)fO0OfvH)XiIq~kbLV>v zM6}d#oI9BLP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5_9|no;los6~sG$wDD8QS&>#?_GN8sZ+ldMbU>H z9dm>3?oUM7R^;5|N`AOW=!-UD7HhH3)26IJCkFttwZX7G%T0usK+~}TO~cV-#foeE zD2g+s)TVLc#?0QaqvypFPB;N!ST1&VZ>ZTiV<%@}ST0&OY$9{A=7?N9d|`{EJxm2n zr=g7i#Q8~*G}m)62j!b$MmdAyk3TMc>ZxB8qbMG@=bk&TZryqkLIhSpgDjmf(;DgdL8zu8b8$ly|a5f4U$7;9OooAbiUT&W~-I(MiP=Xv$#sIKo#`9B=sRi5~ z*|BLGG5?~iZL%80064i!6Bd{#2b`>ZwgJdrLjH!$5JlY9Hrcj + + 0 : off, 1 : on, 2 : auto. private int stateFlash = 0; + // Flag to know which camera is active. + private int cameraActive = getOrientationOfCamera(); public static final int DEGREE_0 = 0; public static final int DEGREE_90 = 90; @@ -890,6 +892,7 @@ public class CameraActivity extends Activity { this.setResult(3); this.finish(); } +<<<<<<< HEAD /** * Allow to enable or disable the flash of the camera. @@ -991,4 +994,110 @@ public class CameraActivity extends Activity { (supportedFlashModes.size() == 1 && supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) ); } +||||||| merged common ancestors +======= + + /** + * 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. + * @param view The current view. + */ + public void switchCamera(View view) { + if (hasFrontCamera()) { + System.out.println("Camera frontale OK !"); + System.out.println("Camera face : " + Camera.CameraInfo.CAMERA_FACING_FRONT); + System.out.println("Camera back : " + Camera.CameraInfo.CAMERA_FACING_BACK); + + int orientationCamera = getOrientationOfCamera(); + System.out.println("Orientation camera : " + orientationCamera); + + System.out.println("Camera Active : " + cameraActive); + +// int cameraCount = Camera.getNumberOfCameras(); +// System.out.println("nb Camera : " + cameraCount); +// for ( int camIdx = 0; camIdx < cameraCount; camIdx++ ) { +// System.out.println("ok"); +// Camera.getCameraInfo( camIdx, cameraInfo ); +// if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ) { +// System.out.println("Je l'ai trouvé !! "); +// try { +// customCamera = Camera.open(camIdx); +// CameraPreview myPreview = new CameraPreview(this, customCamera); +// cameraPreview.addView(myPreview); +// } catch (RuntimeException e) { +// System.out.println("FAIL"); +// } +// } + ManagerCamera.clearCameraAccess(); + FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview); + cameraPreview.removeAllViews(); + if (cameraActive == Camera.CameraInfo.CAMERA_FACING_BACK) { + try { + cameraActive = 1; + customCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT); + setCameraDisplayOrientation(CameraActivity.this, 1, customCamera); + CameraPreview myPreview = new CameraPreview(this, customCamera); + cameraPreview.addView(myPreview); + } catch (RuntimeException e) { + System.out.println("FAIL"); + } + } else if (cameraActive == Camera.CameraInfo.CAMERA_FACING_FRONT) { + try { + cameraActive = 0; + customCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK); + System.out.println("J'ai réussi !! "); + CameraPreview myPreview = new CameraPreview(this, customCamera); + cameraPreview.addView(myPreview); + } catch (RuntimeException e) { + System.out.println("FAIL"); + } + } + } + } + + /** + * + * @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); + } +>>>>>>> Première implémentation du switch camera -> Marche de camera back à camera front mais pas l'inverse } From 392a07a8924a591d92184bb6ebf1433363865c88 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Wed, 4 Feb 2015 17:44:13 +0100 Subject: [PATCH 02/13] =?UTF-8?q?Impl=C3=A9mentation=20du=20switch=20de=20?= =?UTF-8?q?camera.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../geneanet/customcamera/CameraActivity.java | 40 ++++--------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 8c6519a..b7541ca 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -892,7 +892,6 @@ public class CameraActivity extends Activity { this.setResult(3); this.finish(); } -<<<<<<< HEAD /** * Allow to enable or disable the flash of the camera. @@ -994,9 +993,7 @@ public class CameraActivity extends Activity { (supportedFlashModes.size() == 1 && supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) ); } -||||||| merged common ancestors -======= - + /** * Check if a front camera exist. * return boolean @@ -1018,53 +1015,31 @@ public class CameraActivity extends Activity { * @param view The current view. */ public void switchCamera(View view) { - if (hasFrontCamera()) { - System.out.println("Camera frontale OK !"); - System.out.println("Camera face : " + Camera.CameraInfo.CAMERA_FACING_FRONT); - System.out.println("Camera back : " + Camera.CameraInfo.CAMERA_FACING_BACK); - - int orientationCamera = getOrientationOfCamera(); - System.out.println("Orientation camera : " + orientationCamera); - - System.out.println("Camera Active : " + cameraActive); - -// int cameraCount = Camera.getNumberOfCameras(); -// System.out.println("nb Camera : " + cameraCount); -// for ( int camIdx = 0; camIdx < cameraCount; camIdx++ ) { -// System.out.println("ok"); -// Camera.getCameraInfo( camIdx, cameraInfo ); -// if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ) { -// System.out.println("Je l'ai trouvé !! "); -// try { -// customCamera = Camera.open(camIdx); -// CameraPreview myPreview = new CameraPreview(this, customCamera); -// cameraPreview.addView(myPreview); -// } catch (RuntimeException e) { -// System.out.println("FAIL"); -// } -// } + if (hasFrontCamera() && Camera.getNumberOfCameras() >= 2) { ManagerCamera.clearCameraAccess(); FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview); cameraPreview.removeAllViews(); if (cameraActive == Camera.CameraInfo.CAMERA_FACING_BACK) { try { cameraActive = 1; + customCamera.release(); customCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT); setCameraDisplayOrientation(CameraActivity.this, 1, customCamera); CameraPreview myPreview = new CameraPreview(this, customCamera); cameraPreview.addView(myPreview); } catch (RuntimeException e) { - System.out.println("FAIL"); + System.out.println("FAIL FRONT CAMERA"); } } else if (cameraActive == Camera.CameraInfo.CAMERA_FACING_FRONT) { try { cameraActive = 0; + customCamera.release(); customCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK); - System.out.println("J'ai réussi !! "); + setCameraDisplayOrientation(CameraActivity.this, 0, customCamera); CameraPreview myPreview = new CameraPreview(this, customCamera); cameraPreview.addView(myPreview); } catch (RuntimeException e) { - System.out.println("FAIL"); + System.out.println("FAIL BACK CAMERA"); } } } @@ -1099,5 +1074,4 @@ public class CameraActivity extends Activity { } camera.setDisplayOrientation(result); } ->>>>>>> Première implémentation du switch camera -> Marche de camera back à camera front mais pas l'inverse } From d264c5ebdabdda47b392eec6eaf85ba61618b3bf Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Thu, 5 Feb 2015 15:47:50 +0100 Subject: [PATCH 03/13] Modification pour prendre en compte une langue par defaut. Nouvelle implementation du switch camera. Modifications de ManagerCamera.java. Prise en compte du flash en cas de changement de camera. --- hooks/before_build/generateActivity.js | 3 ++ res/translations.json | 6 +++ .../geneanet/customcamera/CameraActivity.java | 54 ++++++++----------- .../geneanet/customcamera/ManagerCamera.java | 50 +++++++++++++++-- 4 files changed, 76 insertions(+), 37 deletions(-) diff --git a/hooks/before_build/generateActivity.js b/hooks/before_build/generateActivity.js index d43d251..1c0de2f 100644 --- a/hooks/before_build/generateActivity.js +++ b/hooks/before_build/generateActivity.js @@ -125,6 +125,9 @@ var updateConfig = function() { translationsForApplication = JSON.parse(translationsForApplication); for (lang in translationsForApplication) { var pathFileTranslate = pathResAndroidCordova+"values-"+lang+"/"; + if (lang == "0") { + pathFileTranslate = pathResAndroidCordova+"values/"; + } var objToXml; // already exist, get data. diff --git a/res/translations.json b/res/translations.json index 7124c8e..f1c9e1c 100644 --- a/res/translations.json +++ b/res/translations.json @@ -1,4 +1,10 @@ { + "0": { + "miniature": "Miniature", + "capture": "Capture", + "acceptePicture": "Valid the picture", + "declinePicture": "Decline the picture" + }, "fr": { "miniature": "Miniature", "capture": "Photo", diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index b7541ca..63510d5 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -59,8 +59,6 @@ public class CameraActivity extends Activity { private Boolean opacity = true; // Flag to save state of flash -> 0 : off, 1 : on, 2 : auto. private int stateFlash = 0; - // Flag to know which camera is active. - private int cameraActive = getOrientationOfCamera(); public static final int DEGREE_0 = 0; public static final int DEGREE_90 = 90; @@ -77,7 +75,8 @@ public class CameraActivity extends Activity { * @return boolean */ protected boolean initCameraResource() { - customCamera = ManagerCamera.getCameraInstance(); + int defaultCamera = ManagerCamera.determinePositionBackCamera(); + customCamera = ManagerCamera.getCameraInstance(defaultCamera); if (customCamera == null) { this.setResult(2, @@ -264,6 +263,12 @@ public class CameraActivity extends Activity { // Assign the render camera to the view CameraPreview myPreview = new CameraPreview(this, customCamera); cameraPreview.addView(myPreview); + + // Hide the switch camera button if the number of cameras is lower than 2. + if(Camera.getNumberOfCameras() < 2){ + ImageButton switchCamera = (ImageButton) findViewById(R.id.switchCamera); + switchCamera.setVisibility(View.INVISIBLE); + } // The zoom bar progress final SeekBar zoomLevel = (SeekBar) findViewById(R.id.zoomLevel); @@ -748,9 +753,10 @@ public class CameraActivity extends Activity { ImageButton flash = (ImageButton)findViewById(R.id.flash); flash.setVisibility(View.VISIBLE); } - Camera.Parameters params = customCamera.getParameters(); - params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); + if (hasFlash()) { + params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); + } customCamera.setParameters(params); photoTaken = null; displayPicture(); @@ -941,6 +947,7 @@ public class CameraActivity extends Activity { break; } + flash.setVisibility(View.VISIBLE); flash.setImageResource(imgResource); customCamera.setParameters(params); @@ -1015,34 +1022,15 @@ public class CameraActivity extends Activity { * @param view The current view. */ public void switchCamera(View view) { - if (hasFrontCamera() && Camera.getNumberOfCameras() >= 2) { - ManagerCamera.clearCameraAccess(); - FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview); - cameraPreview.removeAllViews(); - if (cameraActive == Camera.CameraInfo.CAMERA_FACING_BACK) { - try { - cameraActive = 1; - customCamera.release(); - customCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT); - setCameraDisplayOrientation(CameraActivity.this, 1, customCamera); - CameraPreview myPreview = new CameraPreview(this, customCamera); - cameraPreview.addView(myPreview); - } catch (RuntimeException e) { - System.out.println("FAIL FRONT CAMERA"); - } - } else if (cameraActive == Camera.CameraInfo.CAMERA_FACING_FRONT) { - try { - cameraActive = 0; - customCamera.release(); - customCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK); - setCameraDisplayOrientation(CameraActivity.this, 0, customCamera); - CameraPreview myPreview = new CameraPreview(this, customCamera); - cameraPreview.addView(myPreview); - } catch (RuntimeException e) { - System.out.println("FAIL BACK CAMERA"); - } - } - } + int oppositeCamera = ManagerCamera.determineOppositeCamera(); + customCamera = ManagerCamera.getCameraInstance(oppositeCamera); + setCameraDisplayOrientation(CameraActivity.this, oppositeCamera, customCamera); + FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview); + cameraPreview.removeAllViews(); + CameraPreview myPreview = new CameraPreview(this, customCamera); + cameraPreview.addView(myPreview); + // To re-display the flash. + updateStateFlash(stateFlash); } /** diff --git a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java index cda4e23..a654c62 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java @@ -1,6 +1,7 @@ package org.geneanet.customcamera; import android.hardware.Camera; +import android.hardware.Camera.CameraInfo; import android.util.Log; /** @@ -14,26 +15,29 @@ public class ManagerCamera { public static final int LANDSCAPE = 1; public static final int PORTRAIT_INVERSED = 2; public static final int LANDSCAPE_INVERSED = 3; + private static Integer currentCameraPosition = null; /** * A safe way to get an instance of the Camera object. * * @return Camera | null */ - public static Camera getCameraInstance() { + public static Camera getCameraInstance(int position) { // If camera is already instanced and available, return this resource. - if (ManagerCamera.mCamera != null) { + if (ManagerCamera.mCamera != null && position == currentCameraPosition) { return ManagerCamera.mCamera; + } else if (ManagerCamera.mCamera != null) { + clearCameraAccess(); } // Start back camera. Camera cam = null; try { - cam = Camera.open(0); + cam = Camera.open(position); + currentCameraPosition = position; } catch (RuntimeException e) { Log.e("customCamera", "Can't open the camera back."); } - ManagerCamera.mCamera = cam; return cam; // returns null if camera is unavailable @@ -49,4 +53,42 @@ public class ManagerCamera { ManagerCamera.mCamera = null; } } + + public static int determinePositionFrontCamera() { + return determineCamera(Camera.CameraInfo.CAMERA_FACING_FRONT); + } + + public static int determinePositionBackCamera() { + return determineCamera(Camera.CameraInfo.CAMERA_FACING_BACK); + } + + protected static Integer determineCamera(int position) { + CameraInfo info = new Camera.CameraInfo(); + if (Camera.getNumberOfCameras() == 0) { + return null; + } + if (Camera.getNumberOfCameras() == 1) { + return 0; + } + for (int i = 0; i < Camera.getNumberOfCameras(); i++) { + Camera.getCameraInfo(i, info); + if (info.facing == position) { + return i; + } + } + + return 0; + } + + private static int getCurrentFacingCamera() { + return currentCameraPosition; + } + + public static int determineOppositeCamera() { + if (getCurrentFacingCamera() == Camera.CameraInfo.CAMERA_FACING_BACK) { + return determinePositionFrontCamera(); + } else { + return determinePositionBackCamera(); + } + } } From 8fb6b04f790575eec226808b8cc461f134c1083c Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Fri, 6 Feb 2015 15:20:14 +0100 Subject: [PATCH 04/13] =?UTF-8?q?Impl=C3=A9mentation=20du=20switch=20camer?= =?UTF-8?q?a=20avec=20prise=20en=20compte=20des=20rotations=20de=20la=20pr?= =?UTF-8?q?eview=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; + } } From 04286312f7d2bca8b6e1b45710c85ee2c28ba824 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Fri, 6 Feb 2015 16:29:31 +0100 Subject: [PATCH 05/13] Rajout d'un commentaire --- .../src/org/geneanet/customcamera/ManagerCamera.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java index fc1c713..95c3782 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java @@ -73,7 +73,7 @@ public class ManagerCamera { } /** - * + * Determine the cameraId of the camera currently in use. * * @param position Back or front camera. * From 91349dc4ed73739cda505aec784b4e1540d1d453 Mon Sep 17 00:00:00 2001 From: Christophe BOUCAUT Date: Mon, 9 Feb 2015 10:28:16 +0100 Subject: [PATCH 06/13] =?UTF-8?q?Ajout=20des=20options=20JS=20pour=20:=20?= =?UTF-8?q?=20+=20Activer=20/=20desactiver=20le=20switch=20de=20camera.=20?= =?UTF-8?q?=20+=20Choisir=20une=20camera=20par=20d=C3=A9faut.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/android/CameraLauncher.java | 3 +++ .../org/geneanet/customcamera/CameraActivity.java | 15 ++++++++++++++- www/customCamera.js | 11 ++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index 47908af..faa065c 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -87,6 +87,9 @@ public class CameraLauncher extends CordovaPlugin { intent.putExtra("defaultFlash", args.getInt(8)); intent.putExtra("switchFlash", args.getBoolean(9)); + intent.putExtra("defaultCamera", args.getInt(10)); + intent.putExtra("switchCamera", args.getBoolean(11)); + cordova.startActivityForResult((CordovaPlugin) this, intent, CameraLauncher.REQUEST_CODE); diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 7d9c20d..3d0a66a 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -68,6 +68,9 @@ public class CameraActivity extends Activity { public static final int FLASH_DISABLE = 0; public static final int FLASH_ENABLE = 1; public static final int FLASH_AUTO = 2; + + public static final int CAMERA_BACK = 0; + public static final int CAMERA_FRONT = 1; /** * To get camera resource or stop this activity. @@ -75,7 +78,12 @@ public class CameraActivity extends Activity { * @return boolean */ protected boolean initCameraResource() { - int defaultCamera = ManagerCamera.determinePositionBackCamera(); + int defaultCamera; + if (this.getIntent().getIntExtra("defaultCamera", CameraActivity.CAMERA_BACK) == CameraActivity.CAMERA_FRONT) { + defaultCamera = ManagerCamera.determinePositionFrontCamera(); + } else { + defaultCamera = ManagerCamera.determinePositionBackCamera(); + } customCamera = ManagerCamera.getCameraInstance(defaultCamera); if (customCamera == null) { @@ -115,6 +123,11 @@ public class CameraActivity extends Activity { ImageButton flash = (ImageButton)findViewById(R.id.flash); flash.setVisibility(View.INVISIBLE); } + + if (!this.getIntent().getBooleanExtra("switchCamera", true)) { + ImageButton switchCamera = (ImageButton)findViewById(R.id.switchCamera); + switchCamera.setVisibility(View.INVISIBLE); + } // The opacity bar SeekBar switchOpacity = (SeekBar) findViewById(R.id.switchOpacity); diff --git a/www/customCamera.js b/www/customCamera.js index b179b79..92137fb 100644 --- a/www/customCamera.js +++ b/www/customCamera.js @@ -8,6 +8,7 @@ function CustomCameraExport() {} CustomCameraExport.prototype.FlashModes = {DISABLE: 0, ACTIVE: 1, AUTO: 2}; + CustomCameraExport.prototype.CameraFacings = {BACK: 0, FRONT: 1}; /** * Start custom camera. @@ -27,8 +28,10 @@ // To get supported color formats, go to see method parseColor : http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String) quality: 100, // picture's quality : range 0 - 100 : http://developer.android.com/reference/android/graphics/Bitmap.html#compress(android.graphics.Bitmap.CompressFormat, int, java.io.OutputStream) (parameter "quality") opacity: true, // active or disable the opacity function. - defaultFlash: this.FlashModes.DISABLE, // default state for flash. Corrects values = 0 (disable) / 1 (active) / 2 (auto) - switchFlash: true // active or disable the switch flash button. + defaultFlash: this.FlashModes.DISABLE, // default state for flash. See CustomCamera.FlashModes for corrects values. + switchFlash: true, // active or disable the switch flash button. + defaultCamera: this.CameraFacings.BACK, // default camera used. See CustomCamera.CameraFacings for corrects values. + switchCamera: true // active or disable the switch camera button. }; for (var nameOption in defaultOptions) { @@ -60,7 +63,9 @@ options.quality, options.opacity, options.defaultFlash, - options.switchFlash + options.switchFlash, + options.defaultCamera, + options.switchCamera ] ); }; From e4fd766f2017accfa278f2d12a5eb8d365f77d2f Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Mon, 9 Feb 2015 11:16:58 +0100 Subject: [PATCH 07/13] Correctifs de codes (commentaires, deplacement). Deplacement de setDisplayOrientation dans ManagerCamera et appel dans initCameraResource. Modification du hook pour la langue par defaut. --- hooks/before_build/generateActivity.js | 2 +- res/translations.json | 2 +- .../geneanet/customcamera/CameraActivity.java | 74 ++++--------------- .../geneanet/customcamera/ManagerCamera.java | 74 ++++++++++++++----- 4 files changed, 69 insertions(+), 83 deletions(-) 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); + } } From edc3b221e86ef7d2906d4797034d88e7056e9027 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Mon, 9 Feb 2015 12:24:57 +0100 Subject: [PATCH 08/13] Ajout d'un getter. --- .../src/org/geneanet/customcamera/ManagerCamera.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java index e86a53f..9d52760 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java @@ -176,4 +176,13 @@ public class ManagerCamera { } ManagerCamera.mCamera.setDisplayOrientation(result); } + + /** + * Get the value of currentCameraPosition. + * + * @return Integer. + */ + public static int getCurrentCameraPosition() { + return ManagerCamera.currentCameraPosition; + } } From e7016f24e1c1dea74735b1bff2a0596c34fd5204 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Mon, 9 Feb 2015 15:33:34 +0100 Subject: [PATCH 09/13] =?UTF-8?q?Fix=20bug=20:=20+=20Bouton=20flash=20r?= =?UTF-8?q?=C3=A9apparait=20si=20on=20d=C3=A9cline=20la=20photo=20malgr?= =?UTF-8?q?=C3=A9=20que=20l'on=20pr=C3=A9cise=20en=20JS=20que=20l'on=20veu?= =?UTF-8?q?t=20masquer=20le=20bouton.=20+=20Bar=20de=20zoom=20r=C3=A9appar?= =?UTF-8?q?ait=20si=20on=20d=C3=A9cline=20la=20photo=20malgr=C3=A9=20qu'il?= =?UTF-8?q?=20n'y=20ait=20pas=20de=20zoom=20support=C3=A9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Réalisé : + Gestion du zoom (et de la seekbar) lorsque l'on switch de camera. --- .../geneanet/customcamera/CameraActivity.java | 115 +++++++++--------- .../geneanet/customcamera/ManagerCamera.java | 9 ++ 2 files changed, 67 insertions(+), 57 deletions(-) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index b97399e..b427307 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -88,8 +88,7 @@ public class CameraActivity extends Activity { } } customCamera = ManagerCamera.getCameraInstance(position); - ManagerCamera.setCameraDisplayOrientation(this); - + if (customCamera == null) { this.setResult(2, new Intent().putExtra("errorMessage", "Camera is unavailable.")); @@ -98,6 +97,47 @@ public class CameraActivity extends Activity { return false; } + ManagerCamera.setCameraDisplayOrientation(this); + + // The zoom bar progress + final SeekBar zoomLevel = (SeekBar) findViewById(R.id.zoomLevel); + final Camera.Parameters paramsCamera = customCamera.getParameters(); + if (paramsCamera.isZoomSupported()) { + final int zoom = paramsCamera.getZoom(); + int maxZoom = paramsCamera.getMaxZoom(); + + // Event on change zoom with the bar. + zoomLevel.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { + int progress = 0; + + @Override + public void onProgressChanged(SeekBar seekBar, int progresValue, + boolean fromUser) { + progress = progresValue; + int newZoom = (int) (zoom + progress); + zoomLevel.setProgress(newZoom); + paramsCamera.setZoom(newZoom); + ManagerCamera.getCurrentCameraResource().setParameters(paramsCamera); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); + + zoomLevel.setMax(maxZoom); + zoomLevel.setProgress(zoom); + zoomLevel.setVisibility(View.VISIBLE); + } else { + zoomLevel.setVisibility(View.INVISIBLE); + } + + updateStateFlash(stateFlash); + return true; } @@ -124,9 +164,10 @@ public class CameraActivity extends Activity { } if (!this.getIntent().getBooleanExtra("switchFlash", true)) { - ImageButton flash = (ImageButton)findViewById(R.id.flash); + ImageButton flash = (ImageButton) findViewById(R.id.flash); flash.setVisibility(View.INVISIBLE); } + stateFlash = this.getIntent().getIntExtra("defaultFlash", CameraActivity.FLASH_DISABLE); if (!this.getIntent().getBooleanExtra("switchCamera", true)) { ImageButton switchCamera = (ImageButton)findViewById(R.id.switchCamera); @@ -210,14 +251,11 @@ public class CameraActivity extends Activity { @Override protected void onStart() { super.onStart(); - + // Init camera resource. if (!initCameraResource(null)) { return; } - - stateFlash = this.getIntent().getIntExtra("defaultFlash", CameraActivity.FLASH_DISABLE); - updateStateFlash(stateFlash); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); @@ -265,39 +303,6 @@ public class CameraActivity extends Activity { ImageButton switchCamera = (ImageButton) findViewById(R.id.switchCamera); switchCamera.setVisibility(View.INVISIBLE); } - - // The zoom bar progress - final SeekBar zoomLevel = (SeekBar) findViewById(R.id.zoomLevel); - final Camera.Parameters paramsCamera = customCamera.getParameters(); - final int zoom = paramsCamera.getZoom(); - int maxZoom = paramsCamera.getMaxZoom(); - - zoomLevel.setMax(maxZoom); - zoomLevel.setProgress(zoom); - zoomLevel.setVisibility(View.VISIBLE); - - // Event on change zoom with the bar. - zoomLevel.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { - int progress = 0; - - @Override - public void onProgressChanged(SeekBar seekBar, int progresValue, - boolean fromUser) { - progress = progresValue; - int newZoom = (int) (zoom + progress); - zoomLevel.setProgress(newZoom); - paramsCamera.setZoom(newZoom); - customCamera.setParameters(paramsCamera); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - } - }); } /** Method to pause the activity. */ @@ -529,12 +534,15 @@ public class CameraActivity extends Activity { ImageView background = (ImageView) findViewById(R.id.background); LayoutParams paramsLayoutMiniature = (LinearLayout.LayoutParams) miniature .getLayoutParams(); + ImageButton flash = (ImageButton)findViewById(R.id.flash); + Camera.Parameters paramsCamera = customCamera.getParameters(); if (photoTaken != null) { // Show/hide elements when a photo is taken keepPhoto.setVisibility(View.VISIBLE); photo.setVisibility(View.INVISIBLE); zoomLevel.setVisibility(View.INVISIBLE); + flash.setVisibility(View.INVISIBLE); ((LinearLayout.LayoutParams) paramsLayoutMiniature).gravity = Gravity.TOP; miniature.setLayoutParams(paramsLayoutMiniature); @@ -547,7 +555,12 @@ public class CameraActivity extends Activity { // Show/hide elements when a photo is not taken keepPhoto.setVisibility(View.INVISIBLE); photo.setVisibility(View.VISIBLE); - zoomLevel.setVisibility(View.VISIBLE); + if (paramsCamera.isZoomSupported()) { + zoomLevel.setVisibility(View.VISIBLE); + } + if (this.getIntent().getBooleanExtra("switchFlash", true)) { + flash.setVisibility(View.VISIBLE); + } ((LinearLayout.LayoutParams) paramsLayoutMiniature).gravity = Gravity.BOTTOM; miniature.setLayoutParams(paramsLayoutMiniature); @@ -602,8 +615,6 @@ public class CameraActivity extends Activity { * Method to take picture. */ public void takePhoto() { - ImageButton flash = (ImageButton)findViewById(R.id.flash); - flash.setVisibility(View.INVISIBLE); // Handles the moment where picture is taken ShutterCallback shutterCallback = new ShutterCallback() { public void onShutter() { @@ -754,14 +765,11 @@ public class CameraActivity extends Activity { imgIcon.setEnabled(true); if (hasFlash()) { - ImageButton flash = (ImageButton)findViewById(R.id.flash); - flash.setVisibility(View.VISIBLE); - } - Camera.Parameters params = customCamera.getParameters(); - if (hasFlash()) { + Camera.Parameters params = customCamera.getParameters(); params.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); + customCamera.setParameters(params); } - customCamera.setParameters(params); + photoTaken = null; displayPicture(); } @@ -950,13 +958,10 @@ public class CameraActivity extends Activity { imgResource = R.drawable.flash_auto; break; } - - flash.setVisibility(View.VISIBLE); + flash.setImageResource(imgResource); customCamera.setParameters(params); - } else { - flash.setVisibility(View.INVISIBLE); } } @@ -978,8 +983,6 @@ public class CameraActivity extends Activity { Camera.Parameters params = customCamera.getParameters(); params.setFlashMode(mode); customCamera.setParameters(params); - } else { - flash.setVisibility(View.INVISIBLE); } } @@ -1016,7 +1019,5 @@ public class CameraActivity extends Activity { cameraPreview.removeAllViews(); CameraPreview myPreview = new CameraPreview(this, customCamera); cameraPreview.addView(myPreview); - // To re-display the flash. - updateStateFlash(stateFlash); } } diff --git a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java index 9d52760..c6fe0ce 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/ManagerCamera.java @@ -185,4 +185,13 @@ public class ManagerCamera { public static int getCurrentCameraPosition() { return ManagerCamera.currentCameraPosition; } + + /** + * Get the value of mCamera. + * + * @return Camera. + */ + public static Camera getCurrentCameraResource() { + return ManagerCamera.mCamera; + } } From 8e1f2faa147e4024f61487c5377e67673ad941eb Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Mon, 9 Feb 2015 15:47:29 +0100 Subject: [PATCH 10/13] =?UTF-8?q?D=C3=A9placement=20du=20code=20pour=20reg?= =?UTF-8?q?rouper=20les=20override=20d'activit=C3=A9=20ensemble.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../geneanet/customcamera/CameraActivity.java | 93 ++++++++++--------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index b427307..4347178 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -156,8 +156,6 @@ public class CameraActivity extends Activity { opacity = this.getIntent().getBooleanExtra("opacity", true); - setBackground(); - if (!this.getIntent().getBooleanExtra("miniature", true)) { Button miniature = (Button) findViewById(R.id.miniature); miniature.setVisibility(View.INVISIBLE); @@ -227,36 +225,20 @@ public class CameraActivity extends Activity { } }); } - - /** - * Set the background color of the camera button. - * @param color The color of the background. - */ - protected void setCameraBackgroundColor(String color) { - ImageButton imgIcon = (ImageButton)findViewById(R.id.capture); - GradientDrawable backgroundGradient = (GradientDrawable)imgIcon.getBackground(); - if (color.length() > 0) { - try { - int cameraBackgroundColor = Color.parseColor(color); - backgroundGradient.setColor(cameraBackgroundColor); - } catch (IllegalArgumentException e) { - backgroundGradient.setColor(Color.TRANSPARENT); - } - } else { - backgroundGradient.setColor(Color.TRANSPARENT); - } - } /** Method onStart. Handle the zoom level seekBar and the camera orientation. */ @Override protected void onStart() { super.onStart(); + setBackground(); + // Init camera resource. if (!initCameraResource(null)) { return; } + // Adapt camera_preview to keep a ratio between screen' size and camera' size. DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); @@ -305,6 +287,31 @@ public class CameraActivity extends Activity { } } + /** To save some contains of the activity. */ + @Override + protected void onSaveInstanceState(Bundle outState) { + outState.putBoolean("modeMiniature", modeMiniature); + outState.putParcelable("photoTaken", photoTaken); + outState.putInt("stateFlash", stateFlash); + super.onSaveInstanceState(outState); + } + + /** To restore the contains saved on the method onSaveInstanceState(). */ + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + modeMiniature = savedInstanceState.getBoolean("modeMiniature"); + photoTaken = savedInstanceState.getParcelable("photoTaken"); + stateFlash = savedInstanceState.getInt("stateFlash"); + + if (modeMiniature) { + buttonMiniature(findViewById(R.id.miniature)); + } + + displayPicture(); + updateStateFlash(stateFlash); + super.onRestoreInstanceState(savedInstanceState); + } + /** Method to pause the activity. */ @Override protected void onPause() { @@ -338,6 +345,25 @@ public class CameraActivity extends Activity { return true; } + + /** + * Set the background color of the camera button. + * @param color The color of the background. + */ + protected void setCameraBackgroundColor(String color) { + ImageButton imgIcon = (ImageButton)findViewById(R.id.capture); + GradientDrawable backgroundGradient = (GradientDrawable)imgIcon.getBackground(); + if (color.length() > 0) { + try { + int cameraBackgroundColor = Color.parseColor(color); + backgroundGradient.setColor(cameraBackgroundColor); + } catch (IllegalArgumentException e) { + backgroundGradient.setColor(Color.TRANSPARENT); + } + } else { + backgroundGradient.setColor(Color.TRANSPARENT); + } + } /** * Determine the space between the first two fingers. @@ -773,31 +799,6 @@ public class CameraActivity extends Activity { photoTaken = null; displayPicture(); } - - /** To save some contains of the activity. */ - @Override - protected void onSaveInstanceState(Bundle outState) { - outState.putBoolean("modeMiniature", modeMiniature); - outState.putParcelable("photoTaken", photoTaken); - outState.putInt("stateFlash", stateFlash); - super.onSaveInstanceState(outState); - } - - /** To restore the contains saved on the method onSaveInstanceState(). */ - @Override - protected void onRestoreInstanceState(Bundle savedInstanceState) { - modeMiniature = savedInstanceState.getBoolean("modeMiniature"); - photoTaken = savedInstanceState.getParcelable("photoTaken"); - stateFlash = savedInstanceState.getInt("stateFlash"); - - if (modeMiniature) { - buttonMiniature(findViewById(R.id.miniature)); - } - - displayPicture(); - updateStateFlash(stateFlash); - super.onRestoreInstanceState(savedInstanceState); - } /** To display or not the picture taken. */ protected void displayPicture() { From 3449cea59c0f06ea7e1b6f949a7d3256350a7234 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Mon, 9 Feb 2015 16:05:49 +0100 Subject: [PATCH 11/13] Centralisation de la gestion des affichages pour les boutons. Gestion du bouton de switch camera. --- .../geneanet/customcamera/CameraActivity.java | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 4347178..598eebf 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -137,6 +137,7 @@ public class CameraActivity extends Activity { } updateStateFlash(stateFlash); + manageDisplayButtons(); return true; } @@ -155,28 +156,11 @@ public class CameraActivity extends Activity { setContentView(R.layout.activity_camera_view); opacity = this.getIntent().getBooleanExtra("opacity", true); - - if (!this.getIntent().getBooleanExtra("miniature", true)) { - Button miniature = (Button) findViewById(R.id.miniature); - miniature.setVisibility(View.INVISIBLE); - } - - if (!this.getIntent().getBooleanExtra("switchFlash", true)) { - ImageButton flash = (ImageButton) findViewById(R.id.flash); - flash.setVisibility(View.INVISIBLE); - } stateFlash = this.getIntent().getIntExtra("defaultFlash", CameraActivity.FLASH_DISABLE); - - if (!this.getIntent().getBooleanExtra("switchCamera", true)) { - ImageButton switchCamera = (ImageButton)findViewById(R.id.switchCamera); - switchCamera.setVisibility(View.INVISIBLE); - } - - // The opacity bar - SeekBar switchOpacity = (SeekBar) findViewById(R.id.switchOpacity); if (opacity) { // Event on change opacity. + SeekBar switchOpacity = (SeekBar) findViewById(R.id.switchOpacity); switchOpacity.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { int progress = 0; @@ -195,8 +179,6 @@ public class CameraActivity extends Activity { @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); - } else { - switchOpacity.setVisibility(View.INVISIBLE); } ImageButton imgIcon = (ImageButton)findViewById(R.id.capture); @@ -550,25 +532,35 @@ public class CameraActivity extends Activity { } /** - * Display the layout accept/decline photo + mask photo button. + * Manage to display buttons in function of picture is taken or not. */ - public void displayAcceptDeclineButtons() { - LinearLayout keepPhoto = (LinearLayout) findViewById(R.id.keepPhoto); - ImageButton photo = (ImageButton) findViewById(R.id.capture); - SeekBar zoomLevel = (SeekBar) findViewById(R.id.zoomLevel); - Button miniature = (Button) findViewById(R.id.miniature); - ImageView background = (ImageView) findViewById(R.id.background); - LayoutParams paramsLayoutMiniature = (LinearLayout.LayoutParams) miniature - .getLayoutParams(); - ImageButton flash = (ImageButton)findViewById(R.id.flash); + public void manageDisplayButtons() { + LinearLayout keepPhoto = (LinearLayout) findViewById(R.id.keepPhoto); + Button miniature = (Button) findViewById(R.id.miniature); + ImageButton flash = (ImageButton) findViewById(R.id.flash); + ImageButton photo = (ImageButton) findViewById(R.id.capture); + ImageButton switchCamera = (ImageButton) findViewById(R.id.switchCamera); + ImageView background = (ImageView) findViewById(R.id.background); + SeekBar zoomLevel = (SeekBar) findViewById(R.id.zoomLevel); + SeekBar switchOpacity = (SeekBar) findViewById(R.id.switchOpacity); + + LayoutParams paramsLayoutMiniature = (LinearLayout.LayoutParams) miniature.getLayoutParams(); Camera.Parameters paramsCamera = customCamera.getParameters(); + if (!this.getIntent().getBooleanExtra("miniature", true)) { + miniature.setVisibility(View.INVISIBLE); + } + if (!opacity) { + switchOpacity.setVisibility(View.INVISIBLE); + } + if (photoTaken != null) { // Show/hide elements when a photo is taken keepPhoto.setVisibility(View.VISIBLE); photo.setVisibility(View.INVISIBLE); zoomLevel.setVisibility(View.INVISIBLE); flash.setVisibility(View.INVISIBLE); + switchCamera.setVisibility(View.INVISIBLE); ((LinearLayout.LayoutParams) paramsLayoutMiniature).gravity = Gravity.TOP; miniature.setLayoutParams(paramsLayoutMiniature); @@ -584,8 +576,17 @@ public class CameraActivity extends Activity { if (paramsCamera.isZoomSupported()) { zoomLevel.setVisibility(View.VISIBLE); } + if (this.getIntent().getBooleanExtra("switchFlash", true)) { flash.setVisibility(View.VISIBLE); + } else { + flash.setVisibility(View.INVISIBLE); + } + + if (this.getIntent().getBooleanExtra("switchCamera", true)) { + switchCamera.setVisibility(View.VISIBLE); + } else { + switchCamera.setVisibility(View.INVISIBLE); } ((LinearLayout.LayoutParams) paramsLayoutMiniature).gravity = Gravity.BOTTOM; @@ -820,7 +821,7 @@ public class CameraActivity extends Activity { preview.setVisibility(View.VISIBLE); } - displayAcceptDeclineButtons(); + manageDisplayButtons(); } /** From bc0844f1ed9ffa7d1273d3a98eb47f62697c5582 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Mon, 9 Feb 2015 16:22:57 +0100 Subject: [PATCH 12/13] If we don't have a background image, disable miniature and opacity options since CameraLauncher.java. --- src/android/CameraLauncher.java | 11 +++++++++-- .../src/org/geneanet/customcamera/CameraActivity.java | 5 ----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java index faa065c..9e9d208 100644 --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -74,14 +74,21 @@ public class CameraLauncher extends CordovaPlugin { TransferBigData.setImgBackgroundBase64OtherOrientation(imgBackgroundBase64OtherOrientation); } - intent.putExtra("miniature", args.getBoolean(2)); + // If we don't have a background image, disable miniature and opacity options. + if (TransferBigData.getImgBackgroundBase64() == null) { + intent.putExtra("miniature", false); + intent.putExtra("opacity", false); + } else { + intent.putExtra("miniature", args.getBoolean(2)); + intent.putExtra("opacity", args.getBoolean(7)); + } + intent.putExtra("saveInGallery", args.getBoolean(3)); intent.putExtra("cameraBackgroundColor", args.getString(4)); intent.putExtra("cameraBackgroundColorPressed", args.getString(5)); if (args.getInt(6) >= 0 && args.getInt(6) <= 100) { intent.putExtra("quality", args.getInt(6)); } - intent.putExtra("opacity", args.getBoolean(7)); intent.putExtra("startOrientation", this.cordova.getActivity().getResources().getConfiguration().orientation); intent.putExtra("defaultFlash", args.getInt(8)); diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java index 598eebf..03924c6 100644 --- a/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java +++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraActivity.java @@ -460,11 +460,6 @@ public class CameraActivity extends Activity { RelativeLayout.TRUE); background.setLayoutParams(paramsMiniature); - } else { - Button miniature = (Button) findViewById(R.id.miniature); - miniature.setVisibility(View.INVISIBLE); - SeekBar switchOpacity = (SeekBar) findViewById(R.id.switchOpacity); - switchOpacity.setVisibility(View.INVISIBLE); } } From f764f51da3e2cc2d9834b342c70ef9ce477dd847 Mon Sep 17 00:00:00 2001 From: Thomas BOY Date: Mon, 9 Feb 2015 16:37:41 +0100 Subject: [PATCH 13/13] Modification de la position du bouton switchCamera --- src/android/customCamera/res/layout/activity_camera_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/customCamera/res/layout/activity_camera_view.xml b/src/android/customCamera/res/layout/activity_camera_view.xml index 4fdec41..955e92b 100644 --- a/src/android/customCamera/res/layout/activity_camera_view.xml +++ b/src/android/customCamera/res/layout/activity_camera_view.xml @@ -35,7 +35,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="false" - android:layout_marginTop="300dp" + android:layout_marginTop="150dp" android:src="@drawable/switch_camera" android:onClick="switchCamera" />