Skip to content

Commit

Permalink
don't stop camera when surface/fragment is paused - keep it going!
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Jan 20, 2018
1 parent 64587a6 commit 6b20f29
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
41 changes: 24 additions & 17 deletions src/main/java/org/havenapp/main/sensors/motion/Preview.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,15 @@ public Preview (Context context) {
prefs = new PreferenceManager(context);

motionSensitivity = prefs.getCameraSensitivity();
}


/*
* We bind to the alert service
*/
context.bindService(new Intent(context,
MonitorService.class), mConnection, Context.BIND_ABOVE_CLIENT);

}

public void setMotionSensitivity (int motionSensitivity)
{
Expand All @@ -137,13 +145,7 @@ public void addListener(MotionAsyncTask.MotionListener listener) {
* 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.
Expand Down Expand Up @@ -336,17 +338,22 @@ public void onProcess(Bitmap oldBitmap, Bitmap newBitmap,

public void surfaceDestroyed(SurfaceHolder holder) {

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
// important to release it when the activity is paused.
context.unbindService(mConnection);
camera.setPreviewCallback(null);
camera.stopPreview();
camera.release();
}

}

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
// important to release it when the activity is paused.
context.unbindService(mConnection);
camera.setPreviewCallback(null);
camera.stopPreview();
camera.release();
}
}

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (camera != null) {

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/havenapp/main/ui/CameraFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ public void onProcess(Bitmap oldBitmap, Bitmap newBitmap, Bitmap rawBitmap,
}
}
}

@Override
public void onDestroy() {
super.onDestroy();

preview.stopCamera();
}

public void onSensorChanged(SensorEvent event) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ protected void onCreate(Bundle savedInstanceState) {

mNumberTrigger.setMinValue(0);
mNumberTrigger.setMaxValue(MAX_SLIDER_VALUE);

if (!mPrefManager.getMicrophoneSensitivity().equals(PreferenceManager.MEDIUM))
mNumberTrigger.setValue(Integer.parseInt(mPrefManager.getMicrophoneSensitivity()));
else
Expand All @@ -68,8 +69,6 @@ protected void onCreate(Bundle savedInstanceState) {
});




initWave();
startMic();
}
Expand Down

0 comments on commit 6b20f29

Please sign in to comment.