|
|
@@ -3,6 +3,7 @@ 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; |
|
|
@@ -10,6 +11,8 @@ import androidx.annotation.Nullable; |
|
|
|
import androidx.camera.core.ExperimentalGetImage; |
|
|
|
import androidx.lifecycle.LifecycleService; |
|
|
|
|
|
|
|
import com.example.ueberwachungssystem.WifiCommunication; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
@ExperimentalGetImage |
|
|
@@ -24,12 +27,34 @@ public class DetectorService extends LifecycleService { |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -38,7 +63,8 @@ public class DetectorService extends LifecycleService { |
|
|
|
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
|
@Override |
|
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
|
passToServiceListener(detectionReport); |
|
|
|
//passToServiceListener(detectionReport); |
|
|
|
wifiCommunication.sendTrue(detectionReport.toMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
/** Motion Detection**/ |
|
|
@@ -47,7 +73,8 @@ public class DetectorService extends LifecycleService { |
|
|
|
motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
|
@Override |
|
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
|
passToServiceListener(detectionReport); |
|
|
|
//passToServiceListener(detectionReport); |
|
|
|
wifiCommunication.sendTrue(detectionReport.toMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
/** Audio Detection **/ |
|
|
@@ -55,7 +82,8 @@ public class DetectorService extends LifecycleService { |
|
|
|
audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
|
@Override |
|
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
|
passToServiceListener(detectionReport); |
|
|
|
//passToServiceListener(detectionReport); |
|
|
|
wifiCommunication.sendTrue(detectionReport.toMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
/** Audio Recorder**/ |
|
|
@@ -92,18 +120,24 @@ public class DetectorService extends LifecycleService { |
|
|
|
|
|
|
|
|
|
|
|
/** Pass Detection Report to Service Detection Listener and trigger it */ |
|
|
|
public void passToServiceListener(DetectionReport detectionReport) { |
|
|
|
public void passToServiceListener(StringBuffer stringBuffer) { |
|
|
|
if (listener != null) { |
|
|
|
listener.onDetection(detectionReport); |
|
|
|
listener.onDetection(stringBuffer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** On Detection Listener - runs when violation is reported */ |
|
|
|
public interface OnDetectionListener { |
|
|
|
void onDetection(@NonNull DetectionReport detectionReport); |
|
|
|
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"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |