9
0
mirror of https://gitee.com/shuto/customCamera.git synced 2026-04-14 00:00:03 +08:00

Mise au propre du code (commentaires, suppression d'espaces ...)

This commit is contained in:
Thomas Boy
2014-11-14 17:32:41 +01:00
parent a674443551
commit a896c2cd66
3 changed files with 30 additions and 60 deletions
+1 -1
View File
@@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target. # Project target.
target=android-16 target=Google Inc.:Google APIs:14
@@ -15,17 +15,15 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
public CameraPreview(Context context, Camera camera) { public CameraPreview(Context context, Camera camera) {
super(context); super(context);
mCamera = camera; mCamera = camera;
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder(); mHolder = getHolder();
mHolder.addCallback(this); mHolder.addCallback(this);
// deprecated setting, but required on Android versions prior to 3.0
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
} }
/******************************/
/** WHEN THE VIEW IS CREATED **/
/******************************/
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
// The Surface has been created, now tell the camera where to draw the preview.
try { try {
mCamera.setPreviewCallback(null); mCamera.setPreviewCallback(null);
mCamera.setPreviewDisplay(holder); mCamera.setPreviewDisplay(holder);
@@ -36,51 +34,36 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
Log.d("error", "Error setting camera preview: " + e.getMessage()); Log.d("error", "Error setting camera preview: " + e.getMessage());
} }
} }
/******************************/
/** WHEN THE VIEW IS CHANGED **/
/******************************/
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
System.out.println("surfaceChanged");
// If your preview can change or rotate, take care of those events here.
// Make sure to stop the preview before resizing or reformatting it.
if (mHolder.getSurface() == null){ if (mHolder.getSurface() == null){
// preview surface does not exist
return; return;
} }
//
// stop preview before making changes
try { try {
System.out.println("SHIT");
mCamera.setPreviewCallback(null); mCamera.setPreviewCallback(null);
mCamera.stopPreview(); mCamera.stopPreview();
} catch (Exception e){ } catch (Exception e){}
// ignore: tried to stop a non-existent preview
}
//
// // set preview size and make any resize, rotate or
// // reformatting changes here
//
// start preview with new settings
try { try {
mCamera.setPreviewDisplay(mHolder); mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview(); mCamera.startPreview();
} catch (Exception e){ } catch (Exception e){
Log.d("error", "Error starting camera preview: " + e.getMessage()); Log.d("error", "Error starting camera preview: " + e.getMessage());
} }
} }
/********************************************/ /*******************************************/
/** POUR DETRUIRE LA SURFACE DE LA PREVIEW **/ /** TO DESTROY THE SURFACE OF THE PREVIEW **/
/********************************************/ /*******************************************/
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
System.out.println("SURFACE DESTROYED");
if(mCamera!=null){ if(mCamera!=null){
System.out.println("surfaceDestroyed -> LA CAMERA N'EST PAS NULLE");
mCamera.setPreviewCallback(null); mCamera.setPreviewCallback(null);
mCamera.stopPreview(); mCamera.stopPreview();
// mCamera.release();
mCamera = null; mCamera = null;
System.out.println("surfaceDestroy -> DESTRUCTION TERMINEE ");
} }
} }
} }
@@ -32,11 +32,6 @@ public class CameraView extends Activity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
System.out.println("ON RENTRE DANS L'APPLICATION");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
/* Remove title bar */ /* Remove title bar */
@@ -165,9 +160,9 @@ public class CameraView extends Activity {
return true; return true;
} }
/******************/ /*********************/
/** GERE LE ZOOM **/ /** MANAGE THE ZOOM **/
/******************/ /*********************/
private void handleZoom(MotionEvent event, Camera.Parameters params, float mDist) { private void handleZoom(MotionEvent event, Camera.Parameters params, float mDist) {
int maxZoom = params.getMaxZoom(); int maxZoom = params.getMaxZoom();
int zoom = params.getZoom(); int zoom = params.getZoom();
@@ -187,9 +182,9 @@ public class CameraView extends Activity {
mCamera.setParameters(params); mCamera.setParameters(params);
} }
/*******************/ /**********************/
/** GERE LE FOCUS **/ /** MANAGE THE FOCUS **/
/*******************/ /**********************/
public void handleFocus(MotionEvent event, Camera.Parameters params) { public void handleFocus(MotionEvent event, Camera.Parameters params) {
List<String> supportedFocusModes = params.getSupportedFocusModes(); List<String> supportedFocusModes = params.getSupportedFocusModes();
if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) { if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
@@ -201,7 +196,7 @@ public class CameraView extends Activity {
} }
/*******************************************************/ /*******************************************************/
/** DETERMINE L'ESPACE ENTRE LES DEUX PREMIERS DOIGTS **/ /** DETERMINE THE SPACE BETWEEN THE FIRST TWO FINGERS **/
/*******************************************************/ /*******************************************************/
private float getFingerSpacing(MotionEvent event) { private float getFingerSpacing(MotionEvent event) {
float x = event.getX(0) - event.getX(1); float x = event.getX(0) - event.getX(1);
@@ -210,7 +205,7 @@ public class CameraView extends Activity {
} }
/***************************/ /***************************/
/** AFFICHER LA MINIATURE **/ /** DISPLAY THE MINIATURE **/
/***************************/ /***************************/
public void showMiniature(View view){ public void showMiniature(View view){
ImageView imageView = (ImageView) findViewById(R.id.normal); ImageView imageView = (ImageView) findViewById(R.id.normal);
@@ -218,10 +213,8 @@ public class CameraView extends Activity {
if(modeMiniature == 0){ if(modeMiniature == 0){
FrameLayout.LayoutParams paramsMiniature = new FrameLayout.LayoutParams(imageView.getWidth()/4, imageView.getHeight()/4); FrameLayout.LayoutParams paramsMiniature = new FrameLayout.LayoutParams(imageView.getWidth()/4, imageView.getHeight()/4);
paramsMiniature.gravity=Gravity.BOTTOM; paramsMiniature.gravity=Gravity.BOTTOM;
imageView.setAlpha(imageView.getAlpha()); imageView.setAlpha(imageView.getAlpha());
modeMiniature = 1; modeMiniature = 1;
imageView.setLayoutParams(paramsMiniature); imageView.setLayoutParams(paramsMiniature);
@@ -245,27 +238,21 @@ public class CameraView extends Activity {
} }
} }
/****************************************************/ /*****************************************************/
/** METHODE POUR DETRUIRE LA VUE (ICI, l'ACTIVITE) **/ /** METHOD TO DESTROY THE VIEW (HERE, THE ACTIVITY) **/
/****************************************************/ /*****************************************************/
protected void onDestroy(){ protected void onDestroy(){
System.out.println("onDestroy -> JE DETRUIS LA VUE ! ");
super.onDestroy(); super.onDestroy();
if(mCamera!=null){ if(mCamera!=null){
System.out.println("onDestroy -> LA CAMERA N'EST PAS NULL ");
mCamera.stopPreview(); mCamera.stopPreview();
mCamera = null; mCamera = null;
System.out.println("onDestroy -> DESTRUCTION TERMINEE ");
} }
} }
/********************************************************/ /*************************************************/
/** METHODE POUR METTRE LA NOUVELLE VUE APRES ROTATION **/ /** METHOD TO APPLY THE NEW VIEW AFTER ROTATION **/
/********************************************************/ /*************************************************/
protected void onResume(){ protected void onResume(){
System.out.println("onResume -> JE REMET LA VUE ! ");
super.onResume(); super.onResume();
// mPreview.getHolder().removeCallback(mPreview);
System.out.println("onResume -> test ");
} }
} }