Skip to content

Commit

Permalink
enscure motion detect sensivity is updated as the user changes it
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Jul 6, 2018
1 parent 7070dbb commit f095929
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class CameraViewHolder {
* Last frame captured
*/
private int imageCount = 0;

/**
* Sensitivity of motion detection
*/
Expand Down Expand Up @@ -122,9 +122,6 @@ public CameraViewHolder(Activity context, CameraView cameraView) {
this.renderScript = RenderScript.create(context); // where context can be your activity, application, etc.

prefs = new PreferenceManager(context);

motionSensitivity = prefs.getCameraSensitivity();


task = new MotionDetector(
renderScript,
Expand All @@ -133,12 +130,12 @@ public CameraViewHolder(Activity context, CameraView cameraView) {

task.addListener((sourceImage, detectedImage, rawBitmap, motionDetected) -> {

for (MotionDetector.MotionListener listener : listeners)
listener.onProcess(sourceImage,detectedImage,rawBitmap,motionDetected);

if (motionDetected) {
Log.i("MotionListener", "Motion detected");

for (MotionDetector.MotionListener listener : listeners)
listener.onProcess(sourceImage,detectedImage,rawBitmap,motionDetected);

if (serviceMessenger != null) {
Message message = new Message();
message.what = EventTrigger.CAMERA;
Expand All @@ -158,9 +155,6 @@ public CameraViewHolder(Activity context, CameraView cameraView) {
stream.close();
message.getData().putString("path", fileImage.getAbsolutePath());

// sourceImage.recycle();
// detectedImage.recycle();

//store the still match frame, even if doing video
serviceMessenger.send(message);

Expand All @@ -176,7 +170,6 @@ public CameraViewHolder(Activity context, CameraView cameraView) {
}
}

Log.i("MotionListener", "Allowing further processing");

});
/*
Expand All @@ -191,6 +184,7 @@ public void setMotionSensitivity (int
{
this.
motionSensitivity = motionSensitivity;
task.setMotionSensitivity(motionSensitivity);
}

public void addListener(MotionDetector.MotionListener listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ public void detect(byte[] rawOldPic,

handler.post(() -> {
for (MotionListener listener : listeners) {
Log.i("MotionDetector", "Updating back view");
listener.onProcess(
lastBitmap,
newBitmap,
Expand All @@ -153,7 +152,17 @@ public void detect(byte[] rawOldPic,
}
else
{
//nothing changed
handler.post(() -> {
for (MotionListener listener : listeners) {
listener.onProcess(
null,
null,
null,
hasChanged);
}

});
}

}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/havenapp/main/ui/CameraFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.hardware.SensorEvent;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -26,6 +27,7 @@ public final class CameraFragment extends Fragment {

private CameraViewHolder cameraViewHolder;
private ImageView newImage;
private PreferenceManager prefs;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand All @@ -43,6 +45,7 @@ public void setMotionSensitivity (int threshold)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = new PreferenceManager(getContext());
}

@Override
Expand All @@ -57,6 +60,8 @@ public void onResume() {
initCamera();
else
resetCamera();

cameraViewHolder.setMotionSensitivity(prefs.getCameraSensitivity());
}

public void stopCamera ()
Expand Down Expand Up @@ -90,6 +95,8 @@ private void initCamera ()
cameraViewHolder.addListener((oldBitmap, newBitmap, rawBitmap, motionDetected) -> {
if (motionDetected)
newImage.setImageBitmap(newBitmap);
else
newImage.setImageResource(R.drawable.blankimage);
});
}

Expand Down

0 comments on commit f095929

Please sign in to comment.