diff --git a/app/build.gradle b/app/build.gradle
index 02a2cc2..083ba82 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -42,6 +42,8 @@ dependencies {
def opencv_version = "4.5.3.0"
implementation "com.quickbirdstudios:opencv:${opencv_version}"
+ implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
+
// Required for CameraX
def camerax_version = "1.2.2"
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3ea0c3b..3fe9720 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -24,6 +24,7 @@
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java b/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java
new file mode 100644
index 0000000..49b46c0
--- /dev/null
+++ b/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java
@@ -0,0 +1,164 @@
+package com.example.ueberwachungssystem.Detection;
+
+import android.Manifest;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.os.Binder;
+import android.os.IBinder;
+import android.util.Log;
+import android.widget.ImageView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.camera.core.ExperimentalGetImage;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+import androidx.lifecycle.LifecycleService;
+
+import java.io.File;
+
+@ExperimentalGetImage
+public class DetectorService extends LifecycleService {
+
+ public TestBinder testBinder = new TestBinder();
+ private DetectorService.OnDetectionListener listener;
+ private boolean isServiceRunning = false;
+
+ VideoDetector videoDetector = null;
+ AudioRecorder audioRecorder = null;
+
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (isServiceRunning)
+ return START_NOT_STICKY;
+ videoDetector = new VideoDetector(this);
+ videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
+ @Override
+ public void onDetection(@NonNull DetectionReport detectionReport) {
+ passToServiceListener(detectionReport);
+ }
+ });
+
+ audioRecorder = new AudioRecorder(this);
+
+
+ isServiceRunning = true;
+
+ return super.onStartCommand(intent, flags, startId);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ isServiceRunning = false;
+ }
+
+ /** Service methods */
+ public class TestBinder extends Binder {
+ public DetectorService getBoundService() {
+ // Return an instance of the TestService
+ return DetectorService.this;
+ }
+ }
+ @Nullable
+ @Override
+ public IBinder onBind(Intent intent) {
+ super.onBind(intent);
+ return testBinder;
+ }
+
+
+ /** Video Detection */
+ public void startVideoDetection() {
+ if(videoDetector != null)
+ videoDetector.startDetection();
+ }
+ public void stopVideoDetection() {
+ if(videoDetector != null)
+ videoDetector.stopDetection();
+ }
+ public boolean isVideoDetectionRunning() {
+ if(videoDetector != null)
+ return videoDetector.isDetecting();
+ return false;
+ }
+ public void debugVideoProcessing(ImageView input, ImageView output) {
+ if(videoDetector != null)
+ videoDetector.debugProcessing(input, output);
+ }
+
+ /** Audio Detection */
+ public void startAudioDetection() {
+
+ }
+ public void stopAudioDetection() {
+
+ }
+
+ /** Motion Detection */
+ public void startMotionDetection() {
+
+ }
+ public void stopMotionDetection() {
+
+ }
+
+ /** Video Recording */
+ public void startVideoRecording() {
+ if(videoDetector != null)
+ videoDetector.startRecording();
+ }
+ public void stopVideoRecording() {
+ if(videoDetector != null)
+ videoDetector.stopRecording();
+ }
+ public boolean isVideoRecordingRunning() {
+ if(videoDetector != null)
+ return videoDetector.isRecording();
+ return false;
+ }
+ public void setVideoRecordingDir(File outputDir) {
+ if (videoDetector != null)
+ videoDetector.setOutputDir(outputDir);
+ }
+
+ /** Audio Recording */
+ public void startAudioRecording() {
+ if(audioRecorder != null)
+ audioRecorder.startRecording();
+ }
+ public void stopAudioRecording() {
+ if(audioRecorder != null)
+ audioRecorder.stopRecording();
+ }
+ public boolean isAudioRecordingRunning() {
+ if(videoDetector != null)
+ return audioRecorder.isRecording();
+ return false;
+ }
+ public void setAudioRecordingDir(File outputDir) {
+ if (audioRecorder != null)
+ audioRecorder.setOutputDir(outputDir);
+ }
+
+
+
+
+ /** pass Detection Report to Service Detection Listener and trigger it */
+ public void passToServiceListener(DetectionReport detectionReport) {
+ if (listener != null) {
+ listener.onDetection(detectionReport);
+ }
+ }
+
+
+ /** On Detection Listener - runs when violation is reported */
+ public interface OnDetectionListener {
+ void onDetection(@NonNull DetectionReport detectionReport);
+ }
+ public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) {
+ this.listener = listener;
+ }
+}
diff --git a/app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java b/app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java
index ec7350f..0392220 100644
--- a/app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java
+++ b/app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java
@@ -81,7 +81,7 @@ public class VideoDetector extends Detector {
// Parameters
private static final float ALARM_THRESHOLD = 0.5f; // Percent of pixels changed
private static final float START_DELAY = 20000; // milliseconds
- private static final android.util.Size IMAGE_RES = new android.util.Size(640, 480);
+ private static final android.util.Size IMAGE_RES = new android.util.Size(480, 360);