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
Avoid re-creating camera preview upon resume
mziccard72eedac673f4
diff --git a/src/main/java/me/ziccard/secureit/fragment/CameraFragment.java b/src/main/java/me/ziccard/secureit/fragment/CameraFragment.javaindex 6e1c1d6..48e9834 100644--- a/src/main/java/me/ziccard/secureit/fragment/CameraFragment.java+++ b/src/main/java/me/ziccard/secureit/fragment/CameraFragment.java@@ -49,31 +49,32 @@ public final class CameraFragment extends Fragment {@Overridepublic void onResume() {super.onResume();-- //Uncomment to see the camera- preview = new Preview(getActivity());- ((FrameLayout) getActivity().findViewById(R.id.preview)).addView(preview);- oldImage = (ImageView) getActivity().findViewById(R.id.old_image);- newImage = (ImageView) getActivity().findViewById(R.id.new_image);-- preview.addListener(new MotionListener() {-- public void onProcess(Bitmap oldBitmap, Bitmap newBitmap,- boolean motionDetected) {- 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));- }- });-+ if (preview == null) {+ //Uncomment to see the camera+ preview = new Preview(getActivity());+ ((FrameLayout) getActivity().findViewById(R.id.preview)).addView(preview);++ oldImage = (ImageView) getActivity().findViewById(R.id.old_image);+ newImage = (ImageView) getActivity().findViewById(R.id.new_image);++ preview.addListener(new MotionListener() {++ public void onProcess(Bitmap oldBitmap, Bitmap newBitmap,+ boolean motionDetected) {+ 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));+ }+ });+ }}public void onSensorChanged(SensorEvent event) {