123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package com.example.ueberwachungssystem.Detection;
-
- import android.content.Intent;
- 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.lifecycle.LifecycleService;
-
- import com.example.ueberwachungssystem.WifiCommunication;
-
- import java.io.File;
-
- @ExperimentalGetImage
- public class DetectorService extends LifecycleService {
- public ServiceBinder serviceBinder = new ServiceBinder();
- private DetectorService.OnDetectionListener listener;
- private boolean isServiceRunning = false;
-
- // Used Objects:
- public VideoDetector videoDetector = null;
- public AudioRecorder audioRecorder = null;
- public Accelerometer motionDetector = null;
- public MicrophoneDetector audioDetector = null;
-
- public WifiCommunication wifiCommunication;
-
- String wifiData;
- StringBuffer stringBufferWifi = new StringBuffer();
-
-
- @Override
- public int onStartCommand(Intent intent, int flags, int startId) {
- if (isServiceRunning)
- return START_NOT_STICKY;
-
- /** Wifi Instanz **/
- wifiCommunication = new WifiCommunication(1234);
- wifiCommunication.sendTrue("TEst");
-
- wifiCommunication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
- @Override
- public void onConnection(String data) {
- Log.d("Listener", data);
- wifiData = data;
- stringToStringbuffer(data);
- Log.d("buffer",stringBufferWifi.toString());
- passToServiceListener(stringBufferWifi);
-
- }
- });
-
-
-
-
-
- /** Video Detection/Recorder **/
- videoDetector = new VideoDetector(this);
- videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
- @Override
- public void onDetection(@NonNull DetectionReport detectionReport) {
- //passToServiceListener(detectionReport);
- wifiCommunication.sendTrue(detectionReport.toMessage());
- }
- });
- /** Motion Detection**/
- motionDetector = new Accelerometer(this);
- motionDetector.getSensor();
- motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
- @Override
- public void onDetection(@NonNull DetectionReport detectionReport) {
- //passToServiceListener(detectionReport);
- wifiCommunication.sendTrue(detectionReport.toMessage());
- }
- });
- /** Audio Detection **/
- audioDetector = new MicrophoneDetector(this);
- audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
- @Override
- public void onDetection(@NonNull DetectionReport detectionReport) {
- //passToServiceListener(detectionReport);
- wifiCommunication.sendTrue(detectionReport.toMessage());
- }
- });
- /** Audio Recorder**/
- audioRecorder = new AudioRecorder(this);
-
-
-
-
-
-
- isServiceRunning = true;
- return super.onStartCommand(intent, flags, startId);
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- isServiceRunning = false;
- }
-
- /** Service methods */
- public class ServiceBinder 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 serviceBinder;
- }
-
-
- /** Pass Detection Report to Service Detection Listener and trigger it */
- public void passToServiceListener(StringBuffer stringBuffer) {
- if (listener != null) {
- listener.onDetection(stringBuffer);
- }
- }
-
-
- /** On Detection Listener - runs when violation is reported */
- public interface OnDetectionListener {
- void onDetection(@NonNull StringBuffer stringBuffer);
- }
- public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) {
- this.listener = listener;
- }
-
- public void stringToStringbuffer(String string){
- if(string != null) {
- stringBufferWifi.append(string).append("\n");
- }
- }
- }
|