Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors
Sistemata orientazione bitmap per fotocamera frontale
Luca Bonato96c1970d1ca1
diff --git a/src/me/ziccard/secureit/Preview.java b/src/me/ziccard/secureit/Preview.javaindex 95d616c..29e2d08 100644--- a/src/me/ziccard/secureit/Preview.java+++ b/src/me/ziccard/secureit/Preview.java@@ -33,7 +33,6 @@ import android.view.SurfaceHolder;import android.view.SurfaceView;import android.view.Surface;import android.view.WindowManager;-import android.view.Display;import android.widget.Toast;public class Preview extends SurfaceView implements SurfaceHolder.Callback {@@ -42,6 +41,7 @@ public class Preview extends SurfaceView implements SurfaceHolder.Callback {* Object to retrieve and set shared preferences*/private SecureItPreferences prefs;+ private int cameraFacing = 0;private List<MotionListener> listeners = new ArrayList<MotionListener>();@@ -154,6 +154,7 @@ public class Preview extends SurfaceView implements SurfaceHolder.Callback {if ( cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ) {try {camera = Camera.open( camIdx );+ cameraFacing = Camera.CameraInfo.CAMERA_FACING_FRONT;} catch (RuntimeException e) {Log.e("Preview", "Camera failed to open: " + e.getLocalizedMessage());}@@ -161,7 +162,8 @@ public class Preview extends SurfaceView implements SurfaceHolder.Callback {}} else {camera = Camera.open();- }+ cameraFacing = Camera.CameraInfo.CAMERA_FACING_BACK;+ }final Camera.Parameters parameters = camera.getParameters();List<Size> sizes = parameters.getSupportedPictureSizes();@@ -292,30 +294,21 @@ public class Preview extends SurfaceView implements SurfaceHolder.Callback {Camera.Parameters parameters = camera.getParameters();parameters.setPreviewSize(w, h);- Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();-- if(display.getRotation() == Surface.ROTATION_0)- {- parameters.setPreviewSize(h, w);- camera.setDisplayOrientation(90);- }-- if(display.getRotation() == Surface.ROTATION_90)- {- parameters.setPreviewSize(w, h);- }-- if(display.getRotation() == Surface.ROTATION_180)- {- parameters.setPreviewSize(h, w);- }-- if(display.getRotation() == Surface.ROTATION_270)- {- parameters.setPreviewSize(w, h);- camera.setDisplayOrientation(180);- }+ int degree = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();+ int displayOrientation = 0;+ switch (degree) {+ case Surface.ROTATION_0 : displayOrientation = 90; break;+ case Surface.ROTATION_90 : displayOrientation = 0; break;+ case Surface.ROTATION_180: displayOrientation = 0; break;+ case Surface.ROTATION_270: displayOrientation = 180; break;+ }+ camera.setDisplayOrientation(displayOrientation);+//camera.setParameters(parameters);camera.startPreview();- }+ }++ public int getCameraFacing() {+ return this.cameraFacing;+ }}\ No newline at end of filediff --git a/src/me/ziccard/secureit/codec/ImageCodec.java b/src/me/ziccard/secureit/codec/ImageCodec.javaindex 8c514d2..01a4087 100644--- a/src/me/ziccard/secureit/codec/ImageCodec.java+++ b/src/me/ziccard/secureit/codec/ImageCodec.java@@ -55,16 +55,17 @@ public class ImageCodec {* @param degrees* @return*/- public static Bitmap rotate(Bitmap bmp, int degrees) {+ public static Bitmap rotate(Bitmap bmp, int degrees, boolean reflex) {if (bmp==null) throw new NullPointerException();//getting scales of the imageint width = bmp.getWidth();int height = bmp.getHeight();- //Creating a Matrix and rotating it to 90 degrees- Matrix matrix = new Matrix();- matrix.postRotate(degrees);+ //Creating a Matrix and rotating it to specified degrees+ Matrix matrix = new Matrix();+ matrix.postRotate(degrees);+ if (reflex) matrix.postScale(-1, 1);//Getting the rotated BitmapBitmap rotatedBmp = Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);diff --git a/src/me/ziccard/secureit/fragment/CameraFragment.java b/src/me/ziccard/secureit/fragment/CameraFragment.javaindex 159a8fb..b4c4101 100644--- a/src/me/ziccard/secureit/fragment/CameraFragment.java+++ b/src/me/ziccard/secureit/fragment/CameraFragment.java@@ -7,6 +7,7 @@ import me.ziccard.secureit.codec.ImageCodec;import android.os.Bundle;import android.graphics.Bitmap;import android.support.v4.app.Fragment;+import android.hardware.Camera;import android.hardware.SensorEvent;import android.view.LayoutInflater;import android.view.View;@@ -54,9 +55,16 @@ public final class CameraFragment extends Fragment {public void onProcess(Bitmap oldBitmap, Bitmap newBitmap,boolean motionDetected) {- oldImage.setImageBitmap(ImageCodec.rotate(oldBitmap,90));- newImage.setImageBitmap(ImageCodec.rotate(newBitmap,90));-+ int rotation = 0;+ boolean reflex = false;+ if (preview.getCameraFacing() == Camera.CameraInfo.CAMERA_FACING_BACK) {+ rotation = 90;+ } else {+ rotation = 270;+ reflex = true;+ }+ oldImage.setImageBitmap(ImageCodec.rotate(oldBitmap,rotation,reflex));+ newImage.setImageBitmap(ImageCodec.rotate(newBitmap,rotation,reflex));}});