diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ee77a2e..657aba1 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -24,7 +24,8 @@
+ android:label="@string/title_activity_camera_view"
+ android:screenOrientation="fullSensor">
diff --git a/res/drawable-hdpi/labs.png b/res/drawable-hdpi/labs.png
new file mode 100644
index 0000000..e4fada3
Binary files /dev/null and b/res/drawable-hdpi/labs.png differ
diff --git a/res/drawable-mdpi/labs.png b/res/drawable-mdpi/labs.png
new file mode 100644
index 0000000..e4fada3
Binary files /dev/null and b/res/drawable-mdpi/labs.png differ
diff --git a/res/drawable-xhdpi/labs.png b/res/drawable-xhdpi/labs.png
new file mode 100644
index 0000000..e4fada3
Binary files /dev/null and b/res/drawable-xhdpi/labs.png differ
diff --git a/res/drawable-xxhdpi/labs.png b/res/drawable-xxhdpi/labs.png
new file mode 100644
index 0000000..e4fada3
Binary files /dev/null and b/res/drawable-xxhdpi/labs.png differ
diff --git a/res/layout/activity_camera_view.xml b/res/layout/activity_camera_view.xml
index aaf3608..acd80d5 100644
--- a/res/layout/activity_camera_view.xml
+++ b/res/layout/activity_camera_view.xml
@@ -7,16 +7,23 @@
+ android:layout_height="fill_parent">
+
-
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 47f0384..5b19d38 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6,5 +6,8 @@
SettingsCameraViewStart Custom Camera
+ Capture
+ TODO
+ sss
diff --git a/src/org/geneanet/testcustomcamera/CameraView.java b/src/org/geneanet/testcustomcamera/CameraView.java
index 54f6be3..5a2e8bb 100644
--- a/src/org/geneanet/testcustomcamera/CameraView.java
+++ b/src/org/geneanet/testcustomcamera/CameraView.java
@@ -1,39 +1,62 @@
package org.geneanet.testcustomcamera;
+import org.geneanet.testcustomcamera.utils.CameraPreview;
import org.geneanet.testcustomcamera.utils.CustomCamera;
import android.app.Activity;
+import android.content.res.Configuration;
+import android.graphics.Matrix;
+import android.graphics.Point;
import android.hardware.Camera;
import android.os.Bundle;
+import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.ImageView.ScaleType;
public class CameraView extends Activity {
+
+ private Camera mCamera;
+ private CameraPreview mPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ //Remove title bar
+ this.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ //Remove notification bar
+ this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
+
setContentView(R.layout.activity_camera_view);
- Camera cameraTest = CustomCamera.getCameraInstance();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.camera_view, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
+ // Récupère les infos sur le device.
+ Display display = getWindowManager().getDefaultDisplay();
+
+ // récupère l'objet gérant la camera puis l'oriente en fonction de l'écran.
+ 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;
}
- return super.onOptionsItemSelected(item);
+
+ // On assigne le rendu à la vue.
+ mPreview = new CameraPreview(this, mCamera);
+ FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
+ preview.addView(mPreview);
}
}
diff --git a/src/org/geneanet/testcustomcamera/utils/CustomCamera.java b/src/org/geneanet/testcustomcamera/utils/CustomCamera.java
index 8d5532a..a96cffb 100644
--- a/src/org/geneanet/testcustomcamera/utils/CustomCamera.java
+++ b/src/org/geneanet/testcustomcamera/utils/CustomCamera.java
@@ -3,8 +3,22 @@ package org.geneanet.testcustomcamera.utils;
import android.hardware.Camera;
public class CustomCamera {
+
+ protected static Camera mCamera = null;
+
+ // constantes sur les orientations de téléphones.
+ public final static int PORTRAIT = 0;
+ public final static int LANDSCAPE = 1;
+ public final static int PORTRAIT_INVERSED = 2;
+ public final static int LANDSCAPE_INVERSED = 3;
+
/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
+ // si on a déjà une camera récupérée dans l'application, on la retourne directement.
+ if (CustomCamera.mCamera != null) {
+ return mCamera;
+ }
+ // si non, on va chercher la camera de derrière.
Camera c = null;
try {
c = Camera.open(0); // attempt to get a Camera instance
@@ -14,6 +28,9 @@ public class CustomCamera {
// Camera is not available (in use or does not exist)
System.err.println("rt"+e);
}
+
+ CustomCamera.mCamera = c;
+
return c; // returns null if camera is unavailable
}
}