diff --git a/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java b/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java index ea2f28d..68eda9a 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java +++ b/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java @@ -24,20 +24,16 @@ public class DetectorService extends LifecycleService { VideoDetector videoDetector = null; AudioRecorder audioRecorder = null; + Accelerometer accelerometer = null; + MicrophoneDetector microphoneDetector = null; - /** Communication **/ - - WifiCommunication wifiCommunication; - - StringBuffer dataFromWifi; @Override public int onStartCommand(Intent intent, int flags, int startId) { if (isServiceRunning) return START_NOT_STICKY; - - // Setup Service classes: + /** Video Detection/Recorder **/ videoDetector = new VideoDetector(this); videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() { @Override @@ -45,20 +41,29 @@ public class DetectorService extends LifecycleService { passToServiceListener(detectionReport); } }); - + /** Motion Detection**/ + accelerometer = new Accelerometer(this); + accelerometer.getSensor(); + accelerometer.setOnDetectionListener(new Detector.OnDetectionListener() { + @Override + public void onDetection(@NonNull DetectionReport detectionReport) { + passToServiceListener(detectionReport); + } + }); + /** Audio Detection **/ + microphoneDetector = new MicrophoneDetector(this); + microphoneDetector.setOnDetectionListener(new Detector.OnDetectionListener() { + @Override + public void onDetection(@NonNull DetectionReport detectionReport) { + passToServiceListener(detectionReport); + } + }); + /** Audio Recorder**/ audioRecorder = new AudioRecorder(this); isServiceRunning = true; - - wifiCommunication = new WifiCommunication (1234); - wifiCommunication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() { - @Override - public void onConnection(StringBuffer data) { - dataFromWifi = data; - } - }); return super.onStartCommand(intent, flags, startId); } @Override @@ -103,18 +108,22 @@ public class DetectorService extends LifecycleService { /** Audio Detection */ public void startAudioDetection() { - + if(microphoneDetector != null) + microphoneDetector.startDetection(); } public void stopAudioDetection() { - + if(microphoneDetector != null) + microphoneDetector.stopDetection(); } /** Motion Detection */ public void startMotionDetection() { - + if(accelerometer != null) + accelerometer.startDetection(); } public void stopMotionDetection() { - + if(accelerometer != null) + accelerometer.stopDetection(); } /** Video Recording */ 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 9018ddf..78acf1e 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java +++ b/app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java @@ -224,7 +224,7 @@ public class VideoDetector extends Detector { // Violation Condition if (percentChanged * 100 > ALARM_THRESHOLD) { if (allowReportViolation) - reportViolation("Video", percentChanged); + reportViolation("Video", percentChanged * 100); } } imageProxy.close(); diff --git a/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java b/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java index 87f6b71..7df8d28 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java +++ b/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java @@ -1,17 +1,102 @@ package com.example.ueberwachungssystem; - -import androidx.camera.core.ExperimentalGetImage; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; -import android.os.Bundle; +import androidx.camera.core.ExperimentalGetImage; +import androidx.camera.view.PreviewView; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.ImageView; +import android.widget.ToggleButton; + +import com.example.ueberwachungssystem.Detection.Accelerometer; +import com.example.ueberwachungssystem.Detection.AudioRecorder; +import com.example.ueberwachungssystem.Detection.DetectionReport; +import com.example.ueberwachungssystem.Detection.Detector; +import com.example.ueberwachungssystem.Detection.MicrophoneDetector; +import com.example.ueberwachungssystem.Detection.VideoDetector; @ExperimentalGetImage -public class MainActivity extends AppCompatActivity{ +public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - } + setContentView(R.layout.activity_main); + + ImageView inputImageView = findViewById(R.id.inputImageView); + ImageView outputImageView = findViewById(R.id.outputImageView); + PreviewView previewView = findViewById(R.id.previewView); + + + PermissionHandler permissionHandler = new PermissionHandler(this); + + + permissionHandler.getPermissions(); + + if (permissionHandler.hasPermissions()) { + AudioRecorder audioRecorder = new AudioRecorder(this); + + VideoDetector vd = new VideoDetector(this); + //vd.debugProcessing(inputImageView, outputImageView); + vd.setOnDetectionListener(new Detector.OnDetectionListener() { + @Override + public void onDetection(@NonNull DetectionReport detectionReport) { + Log.d("onDetection", detectionReport.toString()); + } + }); + + MicrophoneDetector microphoneDetector = new MicrophoneDetector(this); + microphoneDetector.setOnDetectionListener(new Detector.OnDetectionListener() { + @Override + public void onDetection(@NonNull DetectionReport detectionReport) { + Log.d("onDetection", detectionReport.toString()); + } + }); + + Accelerometer accelerometer = new Accelerometer(this); + accelerometer.getSensor(); + accelerometer.setOnDetectionListener(new Detector.OnDetectionListener() { + @Override + public void onDetection(@NonNull DetectionReport detectionReport) { + Log.d("onDetection", detectionReport.toString()); + } + }); + + + ToggleButton toggleButton = findViewById(R.id.toggleButton); + toggleButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (toggleButton.isChecked()) + { + //vd.startDetection(); + //vd.stopDetection(); + vd.startDetection(); + microphoneDetector.startDetection(); + accelerometer.startDetection(); + + vd.startRecording(); + audioRecorder.startRecording(); + } + else { + //vd.stopDetection(); + vd.stopRecording(); + audioRecorder.stopRecording(); + } + } + }); + + + + + + + + } + + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c0bbb3a..c5abe55 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,123 +1,41 @@ - + android:layout_gravity="center" + android:gravity="top" + android:orientation="vertical" + tools:context=".MainActivity"> - - - - - -