diff --git a/src/android/customCamera/project.properties b/src/android/customCamera/project.properties
index 9b84a6b..655eb8f 100644
--- a/src/android/customCamera/project.properties
+++ b/src/android/customCamera/project.properties
@@ -11,4 +11,4 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
-target=android-16
+target=Google Inc.:Google APIs:14
diff --git a/src/android/customCamera/res/layout/activity_camera_view.xml b/src/android/customCamera/res/layout/activity_camera_view.xml
index 1fdb7fa..8fbbed4 100644
--- a/src/android/customCamera/res/layout/activity_camera_view.xml
+++ b/src/android/customCamera/res/layout/activity_camera_view.xml
@@ -1,117 +1,106 @@
+
-
+ android:layout_height="match_parent" >
+
+ android:id="@+id/camera_preview"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_alignParentLeft="true"
+ android:layout_alignParentTop="true" >
-
+
+
+
+
+
+
+ android:columnCount="4" >
-
+ android:layout_height="fill_parent"
+ android:orientation="horizontal" >
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
+ android:columnCount="2" >
-
+ android:alpha="0.6"
+ android:background="@color/black" >
-
+
-
- android:maxHeight="13dp"
- android:minHeight="0dp"
- android:progress="0"
- android:max="7"
- android:secondaryProgress="7"
- android:thumb="@drawable/thumb"
- android:progressDrawable="@drawable/custom_opacity_bar"
- android:alpha="0.6" />
+
-
+
diff --git a/src/android/customCamera/res/raw/cri.mp3 b/src/android/customCamera/res/raw/cri.mp3
new file mode 100644
index 0000000..ab0071b
Binary files /dev/null and b/src/android/customCamera/res/raw/cri.mp3 differ
diff --git a/src/android/customCamera/res/raw/r2d2.mp3 b/src/android/customCamera/res/raw/r2d2.mp3
new file mode 100644
index 0000000..8a8c3c5
Binary files /dev/null and b/src/android/customCamera/res/raw/r2d2.mp3 differ
diff --git a/src/android/customCamera/res/values/colors.xml b/src/android/customCamera/res/values/colors.xml
new file mode 100644
index 0000000..d14ba21
--- /dev/null
+++ b/src/android/customCamera/res/values/colors.xml
@@ -0,0 +1,5 @@
+
+
+ #000000
+ #ffffff
+
diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraPreview.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraPreview.java
index d96ab09..796807d 100644
--- a/src/android/customCamera/src/org/geneanet/customcamera/CameraPreview.java
+++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraPreview.java
@@ -15,17 +15,15 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
public CameraPreview(Context context, Camera camera) {
super(context);
mCamera = camera;
-
- // Install a SurfaceHolder.Callback so we get notified when the
- // underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
- // deprecated setting, but required on Android versions prior to 3.0
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
+ /******************************/
+ /** WHEN THE VIEW IS CREATED **/
+ /******************************/
public void surfaceCreated(SurfaceHolder holder) {
- // The Surface has been created, now tell the camera where to draw the preview.
try {
mCamera.setPreviewCallback(null);
mCamera.setPreviewDisplay(holder);
@@ -36,51 +34,36 @@ public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback
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) {
- 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){
- // 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
-//
- // start preview with new settings
+ } catch (Exception e){}
+
try {
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
-
} catch (Exception e){
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) {
- 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 ");
}
}
-}
+}
\ No newline at end of file
diff --git a/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java b/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java
index 4321859..03605cb 100644
--- a/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java
+++ b/src/android/customCamera/src/org/geneanet/customcamera/CameraView.java
@@ -1,17 +1,24 @@
package org.geneanet.customcamera;
-import org.geneanet.customcamera.*;
-
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.List;
-import java.lang.Math;
import android.app.Activity;
import android.app.AlertDialog;
+import android.content.res.Configuration;
import android.hardware.Camera;
+import android.hardware.Camera.PictureCallback;
+import android.hardware.Camera.ShutterCallback;
+//import android.media.AudioManager;
+//import android.media.MediaPlayer;
+//import android.media.SoundPool;
import android.os.Bundle;
+import android.os.Environment;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
+import android.view.Surface;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
@@ -19,6 +26,7 @@ import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
@@ -30,6 +38,9 @@ public class CameraView extends Activity {
static boolean clickOn = false;
private static Camera mCamera = null;
public static final int MEDIA_TYPE_IMAGE = 1;
+// private SoundPool sounds;
+// private int sSound;
+ FileOutputStream outStream = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -40,16 +51,8 @@ public class CameraView extends Activity {
.setTitle("Delete entry")
.setMessage(imgBackgroundBase64)
.show();
- } else {
- new AlertDialog.Builder(this)
- .setTitle("que neni")
- .setMessage("que neni")
- .show();
}
-
- System.out.println("ON RENTRE DANS L'APPLICATION");
-
-
+
super.onCreate(savedInstanceState);
/* Remove title bar */
@@ -66,23 +69,48 @@ public class CameraView extends Activity {
/* Get object which use the camera and orient it in function of the screen */
mCamera = CustomCamera.getCameraInstance();
- if (getResources().getConfiguration().orientation == 0){
- switch (display.getRotation()) {
- case CustomCamera.LANDSCAPE:
- mCamera.setDisplayOrientation(0);
- break;
- case CustomCamera.PORTRAIT:
+ /* Hide the accept/refuse photo interface */
+ LinearLayout keepPhoto = (LinearLayout)findViewById(R.id.keepPhoto);
+ keepPhoto.setVisibility(View.INVISIBLE);
+
+ /* Get the default orientation of the device */
+ int defaultOrientation = getDeviceDefaultOrientation();
+
+ if (defaultOrientation == 1){ // We are in portrait orientation
+ System.out.println(display.getRotation());
+ switch(display.getRotation()){
+ case 0 :
mCamera.setDisplayOrientation(90);
break;
- case CustomCamera.LANDSCAPE_INVERSED:
- mCamera.setDisplayOrientation(180);
+ case 1 :
+ mCamera.setDisplayOrientation(0);
break;
- case CustomCamera.PORTRAIT_INVERSED:
+ case 2 :
mCamera.setDisplayOrientation(270);
break;
+ case 3 :
+ mCamera.setDisplayOrientation(180);
+ break;
}
}
-
+
+ if (defaultOrientation == 2){ // We are in landscape orientation
+ switch(display.getRotation()){
+ case 0 :
+ mCamera.setDisplayOrientation(0);
+ break;
+ case 1 :
+ mCamera.setDisplayOrientation(270);
+ break;
+ case 2 :
+ mCamera.setDisplayOrientation(180);
+ break;
+ case 3 :
+ mCamera.setDisplayOrientation(90);
+ break;
+ }
+ }
+
/* Assign the render to the view */
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
@@ -98,32 +126,8 @@ public class CameraView extends Activity {
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
progress = progresValue;
ImageView imageView = (ImageView) findViewById(R.id.normal);
- switch(progress){
- case 0 :
- imageView.setAlpha((float)0.2);
- break;
- case 1 :
- imageView.setAlpha((float)0.3);
- break;
- case 2 :
- imageView.setAlpha((float)0.4);
- break;
- case 3 :
- imageView.setAlpha((float)0.5);
- break;
- case 4 :
- imageView.setAlpha((float)0.6);
- break;
- case 5 :
- imageView.setAlpha((float)0.7);
- break;
- case 6 :
- imageView.setAlpha((float)0.8);
- break;
- case 7 :
- imageView.setAlpha((float)0.9);
- break;
- }
+ float newOpacity = (float) (0.2+progress*0.1);
+ imageView.setAlpha(newOpacity);
}
@Override
@@ -178,9 +182,9 @@ public class CameraView extends Activity {
return true;
}
- /******************/
- /** GERE LE ZOOM **/
- /******************/
+ /*********************/
+ /** MANAGE THE ZOOM **/
+ /*********************/
private void handleZoom(MotionEvent event, Camera.Parameters params, float mDist) {
int maxZoom = params.getMaxZoom();
int zoom = params.getZoom();
@@ -200,9 +204,9 @@ public class CameraView extends Activity {
mCamera.setParameters(params);
}
- /*******************/
- /** GERE LE FOCUS **/
- /*******************/
+ /**********************/
+ /** MANAGE THE FOCUS **/
+ /**********************/
public void handleFocus(MotionEvent event, Camera.Parameters params) {
List supportedFocusModes = params.getSupportedFocusModes();
if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
@@ -214,7 +218,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) {
float x = event.getX(0) - event.getX(1);
@@ -223,18 +227,16 @@ public class CameraView extends Activity {
}
/***************************/
- /** AFFICHER LA MINIATURE **/
+ /** DISPLAY THE MINIATURE **/
/***************************/
public void showMiniature(View view){
ImageView imageView = (ImageView) findViewById(R.id.normal);
- Button miniature = (Button) findViewById(R.id.Miniature);
-
+ Button miniature = (Button) findViewById(R.id.miniature);
+
if(modeMiniature == 0){
FrameLayout.LayoutParams paramsMiniature = new FrameLayout.LayoutParams(imageView.getWidth()/4, imageView.getHeight()/4);
-
paramsMiniature.gravity=Gravity.BOTTOM;
- imageView.setAlpha(imageView.getAlpha());
-
+ imageView.setAlpha(imageView.getAlpha());
modeMiniature = 1;
imageView.setLayoutParams(paramsMiniature);
@@ -244,7 +246,7 @@ public class CameraView extends Activity {
imageView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ImageView imageView = (ImageView) findViewById(R.id.normal);
- Button miniature = (Button) findViewById(R.id.Miniature);
+ Button miniature = (Button) findViewById(R.id.miniature);
LayoutParams paramsReagrandissement = (LayoutParams) imageView.getLayoutParams();
paramsReagrandissement.width = -1;
paramsReagrandissement.height = -1;
@@ -258,27 +260,104 @@ public class CameraView extends Activity {
}
}
- /****************************************************/
- /** METHODE POUR DETRUIRE LA VUE (ICI, l'ACTIVITE) **/
- /****************************************************/
+ /*****************************************************/
+ /** METHOD TO DESTROY THE VIEW (HERE, THE ACTIVITY) **/
+ /*****************************************************/
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 **/
- /********************************************************/
+ /*************************************************/
+ /** METHOD TO APPLY THE NEW VIEW AFTER ROTATION **/
+ /*************************************************/
protected void onResume(){
- System.out.println("onResume -> JE REMET LA VUE ! ");
super.onResume();
-// mPreview.getHolder().removeCallback(mPreview);
- System.out.println("onResume -> test ");
}
+
+ /**************************************************/
+ /** METHOD TO GET THE DEVICE DEFAULT ORIENTATION **/
+ /**************************************************/
+ public int getDeviceDefaultOrientation() {
+
+ WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
+ Configuration config = getResources().getConfiguration();
+ int rotation = windowManager.getDefaultDisplay().getRotation();
+
+ if ( ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) &&
+ config.orientation == Configuration.ORIENTATION_LANDSCAPE)
+ || ((rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) &&
+ config.orientation == Configuration.ORIENTATION_PORTRAIT)) {
+ return Configuration.ORIENTATION_LANDSCAPE;
+ } else {
+ return Configuration.ORIENTATION_PORTRAIT;
+ }
+ }
+
+ /****************************/
+ /** METHOD TO TAKE PICTURE **/
+ /****************************/
+ public void takePhoto(View view){
+ /** To custom sound when you shot with the camera - optionnal**/
+// sounds = new SoundPool(10, AudioManager.STREAM_MUSIC,0);
+// sSound = sounds.load(this.getApplicationContext(), R.raw.r2d2, 1);
+ /** Handles the moment where picture is taken **/
+ final ShutterCallback shutterCallback = new ShutterCallback() {
+ public void onShutter() {
+// sounds.play(sSound, 1.0f, 1.0f, 0, 0, 1.0f);
+// sounds.setVolume(1, (float)0.4, (float)0.4);
+ }
+ };
+
+ /** Handles data for raw picture **/
+ final PictureCallback rawCallback = new PictureCallback() {
+ public void onPictureTaken(byte[] data, Camera camera) {}
+ };
+
+ /** Handles data for jpeg picture **/
+ final PictureCallback jpegCallback = new PictureCallback() {
+
+ public void onPictureTaken(final byte[] data, Camera camera) {
+ final LinearLayout keepPhoto = (LinearLayout)findViewById(R.id.keepPhoto);
+ keepPhoto.setVisibility(View.VISIBLE);
+ Button refuser = (Button)findViewById(R.id.refuser);
+ Button accepter = (Button)findViewById(R.id.accepter);
+ final Button photo = (Button)findViewById(R.id.capture);
+// Button miniature = (Button)findViewById(R.id.miniature);
+ photo.setVisibility(View.INVISIBLE);
+ mCamera.stopPreview();
+
+ accepter.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ try {
+ outStream = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + String.format(
+ "/%d.jpg", System.currentTimeMillis()));
+ outStream.write(data);
+ outStream.close();
+ keepPhoto.setVisibility(View.INVISIBLE);
+ photo.setVisibility(View.VISIBLE);
+ mCamera.startPreview();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ refuser.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ keepPhoto.setVisibility(View.INVISIBLE);
+ photo.setVisibility(View.VISIBLE);
+ mCamera.startPreview();
+ }
+ });
+ };
+ };
+ mCamera.takePicture(shutterCallback, rawCallback, jpegCallback);
+ }
}
+