diff --git a/src/android/AndroidManifest.xml b/src/android/AndroidManifest.xml index 7c92807..55cab20 100644 --- a/src/android/AndroidManifest.xml +++ b/src/android/AndroidManifest.xml @@ -8,6 +8,11 @@ android:minSdkVersion="14" android:targetSdkVersion="14" /> + + + + + - - - diff --git a/src/android/src/org/geneanet/customcamera/CameraView.java b/src/android/src/org/geneanet/customcamera/CameraView.java index 8732f28..8d36075 100644 --- a/src/android/src/org/geneanet/customcamera/CameraView.java +++ b/src/android/src/org/geneanet/customcamera/CameraView.java @@ -8,13 +8,15 @@ import org.geneanet.customcamera.utils.CustomCamera; import org.geneanet.testcustomcamera.R; import android.app.Activity; -import android.content.pm.ActivityInfo; import android.hardware.Camera; +import android.hardware.Camera.Parameters; import android.os.Bundle; +import android.util.Log; import android.view.Display; import android.view.Gravity; import android.view.MotionEvent; +import android.view.SurfaceHolder; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.Window; @@ -28,13 +30,19 @@ import android.widget.SeekBar.OnSeekBarChangeListener; public class CameraView extends Activity { private float mDist; - private Camera mCamera; private int modeMiniature = 0; private CameraPreview mPreview; + static boolean clickOn = false; + private static Camera mCamera = null; public static final int MEDIA_TYPE_IMAGE = 1; @Override protected void onCreate(Bundle savedInstanceState) { + + + System.out.println("ON RENTRE DANS L'APPLICATION"); + + super.onCreate(savedInstanceState); /* Remove title bar */ @@ -51,21 +59,23 @@ public class CameraView extends Activity { /* Get object which use the camera and orient it in function of the screen */ mCamera = CustomCamera.getCameraInstance(); - switch (display.getRotation()) { - case CustomCamera.LANDSCAPE: - mCamera.setDisplayOrientation(0); - break; - case CustomCamera.PORTRAIT: - mCamera.setDisplayOrientation(90); - break; - case CustomCamera.LANDSCAPE_INVERSED: - mCamera.setDisplayOrientation(180); - break; - case CustomCamera.PORTRAIT_INVERSED: - mCamera.setDisplayOrientation(270); - break; + if (getResources().getConfiguration().orientation == 0){ + switch (display.getRotation()) { + case CustomCamera.LANDSCAPE: + mCamera.setDisplayOrientation(0); + break; + case CustomCamera.PORTRAIT: + mCamera.setDisplayOrientation(90); + break; + case CustomCamera.LANDSCAPE_INVERSED: + mCamera.setDisplayOrientation(180); + break; + case CustomCamera.PORTRAIT_INVERSED: + mCamera.setDisplayOrientation(270); + break; + } } - + /* Assign the render to the view */ mPreview = new CameraPreview(this, mCamera); FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview); @@ -120,23 +130,21 @@ public class CameraView extends Activity { /*******************************************************/ /** BLOCK THE ROTATION IN FUNCTION OF THE POSTAL CARD **/ /*******************************************************/ - @Override - public void onWindowFocusChanged(boolean hasFocus){ - ImageView imageView = (ImageView) findViewById(R.id.normal); - int widthImage=imageView.getWidth(); - int heightImage=imageView.getHeight(); - - System.out.println("Largeur : "+widthImage); - System.out.println("Hauteur : "+heightImage); - - if(heightImage < widthImage || imageView.getRotation() != 0){ - this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); - imageView.setRotation(0); - } - else{ - this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - } - } +// @Override +// public void onWindowFocusChanged(boolean hasFocus){ +// +// ImageView imageView = (ImageView) findViewById(R.id.normal); +// int widthImage=imageView.getWidth(); +// int heightImage=imageView.getHeight(); +// +// if(heightImage < widthImage || imageView.getRotation() != 0){ +// this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); +// imageView.setRotation(0); +// } +// else{ +// this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); +// } +// } /******************/ /** FOR THE ZOOM **/ @@ -242,4 +250,28 @@ public class CameraView extends Activity { }); } } + + /****************************************************/ + /** METHODE POUR DETRUIRE LA VUE (ICI, l'ACTIVITE) **/ + /****************************************************/ + protected void onDestroy(){ + System.out.println("onDestroy -> JE DETRUIS LA VUE ! "); + super.onDestroy(); + if(mCamera!=null){ + System.out.println("onDestroy -> LA CAMERA N'EST PAS NULL "); + mCamera.stopPreview(); + mCamera = null; + System.out.println("onDestroy -> DESTRUCTION TERMINEE "); + } + } + + /********************************************************/ + /** METHODE POUR METTRE LA NOUVELLE VUE APRES ROTATION **/ + /********************************************************/ + protected void onResume(){ + System.out.println("onResume -> JE REMET LA VUE ! "); + super.onResume(); +// mPreview.getHolder().removeCallback(mPreview); + System.out.println("onResume -> test "); + } } \ No newline at end of file diff --git a/src/android/src/org/geneanet/customcamera/MainActivity.java b/src/android/src/org/geneanet/customcamera/MainActivity.java index f47f11e..0c8e626 100644 --- a/src/android/src/org/geneanet/customcamera/MainActivity.java +++ b/src/android/src/org/geneanet/customcamera/MainActivity.java @@ -6,12 +6,15 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.hardware.Camera; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; public class MainActivity extends Activity { + + Camera mCamera; @Override protected void onCreate(Bundle savedInstanceState) { @@ -35,7 +38,7 @@ public class MainActivity extends Activity { } private boolean checkCameraHardware(Context context) { - if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){ + if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA) || Camera.getNumberOfCameras() > 0){ // this device has a camera return true; } else { diff --git a/src/android/src/org/geneanet/customcamera/utils/CameraPreview.java b/src/android/src/org/geneanet/customcamera/utils/CameraPreview.java index 7d57cfe..9dea8a3 100644 --- a/src/android/src/org/geneanet/customcamera/utils/CameraPreview.java +++ b/src/android/src/org/geneanet/customcamera/utils/CameraPreview.java @@ -26,19 +26,19 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback 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.setPreviewDisplay(holder); mCamera.startPreview(); } catch (IOException e) { + mCamera.release(); + mCamera = null; Log.d("error", "Error setting camera preview: " + e.getMessage()); } } - public void surfaceDestroyed(SurfaceHolder holder) { - // empty. Take care of releasing the Camera preview in your activity. - } - 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. @@ -46,17 +46,19 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback // preview surface does not exist return; } - +// // stop preview before making changes try { + System.out.println("SHIT"); + mCamera.setPreviewCallback(null); mCamera.stopPreview(); } catch (Exception e){ // ignore: tried to stop a non-existent preview } - - // set preview size and make any resize, rotate or - // reformatting changes here - +// +// // set preview size and make any resize, rotate or +// // reformatting changes here +// // start preview with new settings try { mCamera.setPreviewDisplay(mHolder); @@ -66,4 +68,19 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback Log.d("error", "Error starting camera preview: " + e.getMessage()); } } + + /********************************************/ + /** POUR DETRUIRE LA SURFACE DE LA PREVIEW **/ + /********************************************/ + public void surfaceDestroyed(SurfaceHolder holder) { + System.out.println("SURFACE DESTROYED"); + if(mCamera!=null){ + System.out.println("surfaceDestroyed -> LA CAMERA N'EST PAS NULLE"); + mCamera.setPreviewCallback(null); + mCamera.stopPreview(); +// mCamera.release(); + mCamera = null; + System.out.println("surfaceDestroy -> DESTRUCTION TERMINEE "); + } + } }