Gruppe 1
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainActivity.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.example.ueberwachungssystem;
  2. import androidx.annotation.NonNull;
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.camera.core.ExperimentalGetImage;
  5. import androidx.camera.view.PreviewView;
  6. import android.content.ComponentName;
  7. import android.content.Context;
  8. import android.content.Intent;
  9. import android.content.ServiceConnection;
  10. import android.os.Bundle;
  11. import android.os.IBinder;
  12. import android.util.Log;
  13. import android.view.View;
  14. import android.widget.ImageView;
  15. import android.widget.ToggleButton;
  16. import com.example.ueberwachungssystem.Detection.Accelerometer;
  17. import com.example.ueberwachungssystem.Detection.AudioRecorder;
  18. import com.example.ueberwachungssystem.Detection.DetectionReport;
  19. import com.example.ueberwachungssystem.Detection.Detector;
  20. import com.example.ueberwachungssystem.Detection.DetectorService;
  21. import com.example.ueberwachungssystem.Detection.MicrophoneDetector;
  22. import com.example.ueberwachungssystem.Detection.VideoDetector;
  23. @ExperimentalGetImage
  24. public class MainActivity extends AppCompatActivity {
  25. private DetectorService detectorService = new DetectorService();
  26. ImageView inputImageView;
  27. ImageView outputImageView;
  28. ToggleButton toggleButton;
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.activity_main);
  33. inputImageView = findViewById(R.id.inputImageView);
  34. outputImageView = findViewById(R.id.outputImageView);
  35. toggleButton = findViewById(R.id.toggleButton);
  36. PermissionHandler permissionHandler = new PermissionHandler(this);
  37. permissionHandler.getPermissions();
  38. if (permissionHandler.hasPermissions()) {
  39. Intent serviceIntent = new Intent(this, DetectorService.class);
  40. bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
  41. startService(serviceIntent);
  42. toggleButton.setOnClickListener(new View.OnClickListener() {
  43. @Override
  44. public void onClick(View v) {
  45. if (toggleButton.isChecked())
  46. {
  47. if (detectorService != null){
  48. detectorService.videoDetector.debugProcessing(inputImageView, outputImageView);
  49. detectorService.videoDetector.startDetection();
  50. detectorService.audioDetector.startDetection();
  51. detectorService.motionDetector.startDetection();
  52. detectorService.audioRecorder.stopRecording();
  53. detectorService.videoDetector.startRecording();
  54. }
  55. }
  56. else {
  57. detectorService.videoDetector.stopDetection();
  58. detectorService.audioDetector.stopDetection();
  59. detectorService.motionDetector.stopDetection();
  60. detectorService.audioRecorder.stopRecording();
  61. detectorService.videoDetector.stopRecording();
  62. }
  63. }
  64. });
  65. }
  66. }
  67. private ServiceConnection serviceConnection = new ServiceConnection() {
  68. @Override
  69. public void onServiceConnected(ComponentName name, IBinder service) {
  70. DetectorService.ServiceBinder binder = (DetectorService.ServiceBinder) service;
  71. detectorService = binder.getBoundService();
  72. detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() {
  73. @Override
  74. public void onDetection(@NonNull DetectionReport detectionReport) {
  75. Log.d("onDetection", detectionReport.toMessage());
  76. }
  77. });
  78. }
  79. @Override
  80. public void onServiceDisconnected(ComponentName name) {}
  81. };
  82. }