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
Merge branch 'master' into video-recording-dev
percy-g21d66e86dc9a3
diff --cc src/main/java/org/havenapp/main/sensors/motion/Preview.javaindex 415049b,71856a2..96ec3fa--- a/src/main/java/org/havenapp/main/sensors/motion/Preview.java+++ b/src/main/java/org/havenapp/main/sensors/motion/Preview.java@@@ -122,14 -117,20 +122,18 @@@ public class Preview extends SurfaceViemHolder.addCallback(this);prefs = new PreferenceManager(context);- motionSensitivity =prefs.getCameraSensitivity();- }+ motionSensitivity = prefs.getCameraSensitivity();--- /*++ /*+ * We bind to the alert service+ */+ context.bindService(new Intent(context,- MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT);-- }++ MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT);}- public void setMotionSensitivity (int motionSensitivity)- {- this.motionSensitivity = motionSensitivity;+ public void setMotionSensitivity (int+ motionSensitivity )+ {+ this.+ motionSensitivity = motionSensitivity;}public void addListener(MotionAsyncTask.MotionListener listener) {@@@ -137,20 -138,14 +141,16 @@@}- /**- * Called on the creation of the surface:- * setting camera parameters to lower possible resolution- * (preferred is 640x480)- * in order to minimize CPU usage- */- public void surfaceCreated(SurfaceHolder holder) {+ /**+ * Called on the creation of the surface:+ * setting camera parameters to lower possible resolution+ * (preferred is 640x480)+ * in order to minimize CPU usage+ */+ public void surfaceCreated(SurfaceHolder holder) {+- /*- * We bind to the alert service- */- context.bindService(new Intent(context,- MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT);++/** The Surface has been created, acquire the camera and tell it where* to draw.@@@ -305,87 -300,49 +305,91 @@@ if (!doingVideoProcessing && prefs.getVstream.flush();stream.close();- message.getData().putString("path", fileImage.getAbsolutePath());- **/-- serviceMessenger.send(message);-- } catch (Exception e) {- // Cannot happen- Log.e("Preview", "error creating imnage", e);- }- }- }- Log.i("MotionListener", "Allowing further processing");- doingProcessing = false;- }- });- task.start();- lastPic = data;-- try {-- Camera.Parameters parameters = cam.getParameters();- parameters.setExposureCompensation(parameters.getMaxExposureCompensation());- cam.setParameters(parameters);-- }- catch (Exception e){}- }- }- });-- } catch (IOException e) {- e.printStackTrace();- }- }- }-- public void surfaceDestroyed(SurfaceHolder holder) {+ message.getData().putString("path", fileImage.getAbsolutePath());+ **/+ serviceMessenger.send(message);++ } catch (Exception e) {+ // Cannot happen+ Log.e("Preview", "error creating imnage", e);+ }+ }+ }+ Log.i("MotionListener", "Allowing further processing");+ doingProcessing = false;+ }+ });+ task.start();+ lastPic = data;+ try {++ Camera.Parameters parameters = cam.getParameters();+ parameters.setExposureCompensation(parameters.getMaxExposureCompensation());+ cam.setParameters(parameters);++ } catch (Exception e) {+ }+ }+ }+ });++ } catch (IOException e) {+ e.printStackTrace();+ }+ }+ }+ Handler handler = new Handler();+ void record(Camera cam, Messenger messenger) {+ String ts1 = String.valueOf(new Date().getTime());+ videoFile = Environment.getExternalStorageDirectory() + File.separator + prefs.getImagePath() + File.separator + ts1 + ".mp4";+ int seconds = prefs.getMonitoringTime() * 1000;+ MediaRecorderTask mediaRecorderTask = new MediaRecorderTask(cam, videoFile, seconds);+ mediaRecorder = mediaRecorderTask.getPreparedMediaRecorder();+ AudioManager audioManager = (AudioManager) context.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);+ if (audioManager != null) {+ audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);+ audioManager.setStreamMute(AudioManager.STREAM_MUSIC,true);+ }+ mediaRecorder.start();+ doingVideoProcessing = true;+ handler.postDelayed(() -> {+ if (messenger != null) {+ Message message = new Message();+ message.what = EventTrigger.CAMERA_VIDEO;+ message.getData().putString("path", videoFile);+ try {+ messenger.send(message);+ } catch (RemoteException e) {+ e.printStackTrace();+ }+ if (audioManager != null) {+ audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, false);+ audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);+ }+ mediaRecorder.stop();+ mediaRecorder.reset();+ mediaRecorder.release();+ doingVideoProcessing = false;+ }+ }, seconds);+ }+ public void surfaceDestroyed(SurfaceHolder holder) {- }+ if (doingVideoProcessing && serviceMessenger != null && prefs.getVideoMonitoringActive()) {+ Message message = new Message();+ message.what = EventTrigger.CAMERA_VIDEO;+ message.getData().putString("path", videoFile);+ try {+ serviceMessenger.send(message);+ } catch (RemoteException e) {+ e.printStackTrace();+ }+ }++ }+- public void stopCamera ()++ public void stopCamera ()+ {if (camera != null) {// Surface will be destroyed when we return, so stop the preview.// Because the CameraDevice object is not a shared resource, it's very