123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package com.example.ueberwachungssystem;
-
- import androidx.annotation.NonNull;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.camera.core.ExperimentalGetImage;
- import androidx.camera.view.PreviewView;
-
- import android.content.ComponentName;
- import android.content.Context;
- import android.content.Intent;
- import android.content.ServiceConnection;
- import android.os.Bundle;
- import android.os.IBinder;
- 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.DetectorService;
- import com.example.ueberwachungssystem.Detection.MicrophoneDetector;
- import com.example.ueberwachungssystem.Detection.VideoDetector;
-
- @ExperimentalGetImage
- public class MainActivity extends AppCompatActivity {
-
- private DetectorService detectorService = new DetectorService();
- ImageView inputImageView;
- ImageView outputImageView;
- ToggleButton toggleButton;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
-
- inputImageView = findViewById(R.id.inputImageView);
- outputImageView = findViewById(R.id.outputImageView);
- toggleButton = findViewById(R.id.toggleButton);
-
-
- PermissionHandler permissionHandler = new PermissionHandler(this);
- permissionHandler.getPermissions();
- if (permissionHandler.hasPermissions()) {
-
-
- Intent serviceIntent = new Intent(this, DetectorService.class);
- bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
- startService(serviceIntent);
-
-
- toggleButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (toggleButton.isChecked())
- {
- if (detectorService != null){
-
- detectorService.videoDetector.debugProcessing(inputImageView, outputImageView);
- detectorService.videoDetector.startDetection();
-
- detectorService.audioDetector.startDetection();
-
- detectorService.motionDetector.startDetection();
-
- detectorService.audioRecorder.stopRecording();
-
- detectorService.videoDetector.startRecording();
- }
- }
- else {
- detectorService.videoDetector.stopDetection();
-
- detectorService.audioDetector.stopDetection();
-
- detectorService.motionDetector.stopDetection();
-
- detectorService.audioRecorder.stopRecording();
-
- detectorService.videoDetector.stopRecording();
- }
- }
- });
-
-
-
-
-
-
-
- }
- }
-
- private ServiceConnection serviceConnection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- DetectorService.ServiceBinder binder = (DetectorService.ServiceBinder) service;
- detectorService = binder.getBoundService();
-
- detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() {
- @Override
- public void onDetection(@NonNull DetectionReport detectionReport) {
- Log.d("onDetection", detectionReport.toMessage());
- }
- });
- }
- @Override
- public void onServiceDisconnected(ComponentName name) {}
- };
- }
|