From f9797f2dcacff3166a53d66edfa57d157c7eaf8d Mon Sep 17 00:00:00 2001 From: Bastian Kohler Date: Wed, 24 May 2023 23:51:49 +0200 Subject: [PATCH] Added Abstract class Detector --- .../{VideoDetection => }/DetectionReport.java | 2 +- .../example/ueberwachungssystem/Detector.java | 30 +++++++++++++++++++ .../ueberwachungssystem/MainActivity.java | 2 -- .../VideoDetection/VideoDetector.java | 1 + 4 files changed, 32 insertions(+), 3 deletions(-) rename app/src/main/java/com/example/ueberwachungssystem/{VideoDetection => }/DetectionReport.java (94%) create mode 100644 app/src/main/java/com/example/ueberwachungssystem/Detector.java diff --git a/app/src/main/java/com/example/ueberwachungssystem/VideoDetection/DetectionReport.java b/app/src/main/java/com/example/ueberwachungssystem/DetectionReport.java similarity index 94% rename from app/src/main/java/com/example/ueberwachungssystem/VideoDetection/DetectionReport.java rename to app/src/main/java/com/example/ueberwachungssystem/DetectionReport.java index fff61dd..bfcb52c 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/VideoDetection/DetectionReport.java +++ b/app/src/main/java/com/example/ueberwachungssystem/DetectionReport.java @@ -1,4 +1,4 @@ -package com.example.ueberwachungssystem.VideoDetection; +package com.example.ueberwachungssystem; import android.util.Log; diff --git a/app/src/main/java/com/example/ueberwachungssystem/Detector.java b/app/src/main/java/com/example/ueberwachungssystem/Detector.java new file mode 100644 index 0000000..2d83cfe --- /dev/null +++ b/app/src/main/java/com/example/ueberwachungssystem/Detector.java @@ -0,0 +1,30 @@ +package com.example.ueberwachungssystem; + +import android.content.Context; + +import androidx.annotation.NonNull; + +abstract public class Detector { + private OnDetectionListener listener; + + public Detector(Context context) {}; + + public interface OnDetectionListener { + void onDetection(@NonNull DetectionReport detectionReport); + } + public void setOnDetectionListener(@NonNull OnDetectionListener listener) { + this.listener = listener; + } + + private void reportViolation(String detectorID, String detectionType, float amplitude) { + if (listener != null) { + DetectionReport detectionReport = new DetectionReport(detectorID, detectionType, amplitude); + listener.onDetection(detectionReport); + } else { + throw new IllegalStateException("No listener set for violation reporting"); + } + } + + public abstract void startDetection(); + public abstract void stopDetection(); +} \ No newline at end of file diff --git a/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java b/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java index 9fbbb65..2c99287 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java +++ b/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java @@ -9,14 +9,12 @@ import androidx.camera.core.ExperimentalGetImage; import android.Manifest; import android.content.pm.PackageManager; -import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.TextView; import android.widget.Toast; import android.widget.ToggleButton; -import com.example.ueberwachungssystem.VideoDetection.DetectionReport; import com.example.ueberwachungssystem.VideoDetection.VideoDetector; @ExperimentalGetImage diff --git a/app/src/main/java/com/example/ueberwachungssystem/VideoDetection/VideoDetector.java b/app/src/main/java/com/example/ueberwachungssystem/VideoDetection/VideoDetector.java index 14537b3..efbb0d9 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/VideoDetection/VideoDetector.java +++ b/app/src/main/java/com/example/ueberwachungssystem/VideoDetection/VideoDetector.java @@ -17,6 +17,7 @@ import androidx.camera.view.PreviewView; import androidx.core.content.ContextCompat; import androidx.lifecycle.LifecycleOwner; +import com.example.ueberwachungssystem.DetectionReport; import com.google.common.util.concurrent.ListenableFuture; import java.nio.ByteBuffer;