mirror of
https://gitee.com/shuto/customCamera.git
synced 2026-05-02 00:07:24 +08:00
Correctifs de codes (commentaires, deplacement). Deplacement de setDisplayOrientation dans ManagerCamera et appel dans initCameraResource. Modification du hook pour la langue par defaut.
This commit is contained in:
@@ -125,7 +125,7 @@ var updateConfig = function() {
|
|||||||
translationsForApplication = JSON.parse(translationsForApplication);
|
translationsForApplication = JSON.parse(translationsForApplication);
|
||||||
for (lang in translationsForApplication) {
|
for (lang in translationsForApplication) {
|
||||||
var pathFileTranslate = pathResAndroidCordova+"values-"+lang+"/";
|
var pathFileTranslate = pathResAndroidCordova+"values-"+lang+"/";
|
||||||
if (lang == "0") {
|
if (lang == "default") {
|
||||||
pathFileTranslate = pathResAndroidCordova+"values/";
|
pathFileTranslate = pathResAndroidCordova+"values/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"0": {
|
"default": {
|
||||||
"miniature": "Miniature",
|
"miniature": "Miniature",
|
||||||
"capture": "Capture",
|
"capture": "Capture",
|
||||||
"acceptePicture": "Valid the picture",
|
"acceptePicture": "Valid the picture",
|
||||||
|
|||||||
@@ -75,16 +75,20 @@ public class CameraActivity extends Activity {
|
|||||||
/**
|
/**
|
||||||
* To get camera resource or stop this activity.
|
* To get camera resource or stop this activity.
|
||||||
*
|
*
|
||||||
|
* @param position The position of the camera.
|
||||||
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected boolean initCameraResource() {
|
protected boolean initCameraResource(Integer position) {
|
||||||
int defaultCamera;
|
if (position == null) {
|
||||||
if (this.getIntent().getIntExtra("defaultCamera", CameraActivity.CAMERA_BACK) == CameraActivity.CAMERA_FRONT) {
|
if (this.getIntent().getIntExtra("defaultCamera", CameraActivity.CAMERA_BACK) == CameraActivity.CAMERA_FRONT) {
|
||||||
defaultCamera = ManagerCamera.determinePositionFrontCamera();
|
position = ManagerCamera.determinePositionFrontCamera();
|
||||||
} else {
|
} else {
|
||||||
defaultCamera = ManagerCamera.determinePositionBackCamera();
|
position = ManagerCamera.determinePositionBackCamera();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
customCamera = ManagerCamera.getCameraInstance(defaultCamera);
|
customCamera = ManagerCamera.getCameraInstance(position);
|
||||||
|
ManagerCamera.setCameraDisplayOrientation(this);
|
||||||
|
|
||||||
if (customCamera == null) {
|
if (customCamera == null) {
|
||||||
this.setResult(2,
|
this.setResult(2,
|
||||||
@@ -208,34 +212,13 @@ public class CameraActivity extends Activity {
|
|||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
||||||
// Init camera resource.
|
// Init camera resource.
|
||||||
if (!initCameraResource()) {
|
if (!initCameraResource(null)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stateFlash = this.getIntent().getIntExtra("defaultFlash", CameraActivity.FLASH_DISABLE);
|
stateFlash = this.getIntent().getIntExtra("defaultFlash", CameraActivity.FLASH_DISABLE);
|
||||||
|
|
||||||
updateStateFlash(stateFlash);
|
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();
|
DisplayMetrics dm = new DisplayMetrics();
|
||||||
getWindowManager().getDefaultDisplay().getMetrics(dm);
|
getWindowManager().getDefaultDisplay().getMetrics(dm);
|
||||||
|
|
||||||
@@ -1028,8 +1011,7 @@ public class CameraActivity extends Activity {
|
|||||||
*/
|
*/
|
||||||
public void switchCamera(View view) {
|
public void switchCamera(View view) {
|
||||||
int oppositeCamera = ManagerCamera.determineOppositeCamera();
|
int oppositeCamera = ManagerCamera.determineOppositeCamera();
|
||||||
customCamera = ManagerCamera.getCameraInstance(oppositeCamera);
|
initCameraResource(oppositeCamera);
|
||||||
setCameraDisplayOrientation(CameraActivity.this, oppositeCamera, customCamera);
|
|
||||||
FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview);
|
FrameLayout cameraPreview = (FrameLayout) findViewById(R.id.camera_preview);
|
||||||
cameraPreview.removeAllViews();
|
cameraPreview.removeAllViews();
|
||||||
CameraPreview myPreview = new CameraPreview(this, customCamera);
|
CameraPreview myPreview = new CameraPreview(this, customCamera);
|
||||||
@@ -1037,34 +1019,4 @@ public class CameraActivity extends Activity {
|
|||||||
// To re-display the flash.
|
// To re-display the flash.
|
||||||
updateStateFlash(stateFlash);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package org.geneanet.customcamera;
|
package org.geneanet.customcamera;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.hardware.Camera;
|
import android.hardware.Camera;
|
||||||
import android.hardware.Camera.CameraInfo;
|
import android.hardware.Camera.CameraInfo;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Surface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage camera resource.
|
* 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() {
|
public static int determinePositionFrontCamera() {
|
||||||
return determineCamera(Camera.CameraInfo.CAMERA_FACING_FRONT);
|
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() {
|
public static int determinePositionBackCamera() {
|
||||||
return determineCamera(Camera.CameraInfo.CAMERA_FACING_BACK);
|
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.
|
* 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() {
|
private static int getCurrentFacingCamera() {
|
||||||
return currentCameraPosition;
|
CameraInfo info = new Camera.CameraInfo();
|
||||||
}
|
Camera.getCameraInfo(currentCameraPosition, info);
|
||||||
|
|
||||||
/**
|
return info.facing;
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,4 +147,33 @@ public class ManagerCamera {
|
|||||||
}
|
}
|
||||||
return false;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user