Compare commits
79
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b667e70fef | ||
|
|
c198292fbf | ||
|
|
35d52088aa | ||
|
|
ee61f7042b | ||
|
|
ab54b6d96a | ||
|
|
a85fb1f5ca | ||
|
|
f8f1fd23fb | ||
|
|
e007ad1744 | ||
|
|
292c3457fa | ||
|
|
79c7c16d21 | ||
|
|
e01e23eccd | ||
|
|
a493bafb79 | ||
|
|
aed079377f | ||
|
|
bff6abbd29 | ||
|
|
5d31f0bb46 | ||
|
|
ea0e88ed89 | ||
|
|
7dee124378 | ||
|
|
0ee1446cbc | ||
|
|
bc5227ba4f | ||
|
|
4185cb5200 | ||
|
|
0a3600d0d6 | ||
|
|
9b2d57ad37 | ||
|
|
847e90f5ac | ||
|
|
ab41217f0e | ||
|
|
0782bbdd04 | ||
|
|
e088b0afa3 | ||
|
|
493fa8ca83 | ||
|
|
6954d38143 | ||
|
|
057c7fc139 | ||
|
|
29c193b716 | ||
|
|
76442888f7 | ||
|
|
d32e0a11f5 | ||
|
|
df9b28c830 | ||
|
|
6ec0b175e4 | ||
|
|
e89a5d11a1 | ||
|
|
b246ad8624 | ||
|
|
fb8bdcd895 | ||
|
|
7ef0df48dd | ||
|
|
50b579705e | ||
|
|
8551abfc5d | ||
|
|
bbd333426d | ||
|
|
e98ae10267 | ||
|
|
7d29ed1ca9 | ||
|
|
f98079d431 | ||
|
|
192f88ede5 | ||
|
|
3c1366bd10 | ||
|
|
11dbcd0362 | ||
|
|
047d45f1cb | ||
|
|
95919a6602 | ||
|
|
19d1bfe1e3 | ||
|
|
e9da712882 | ||
|
|
804c5aba36 | ||
|
|
c5577b125f | ||
|
|
6100d17bd2 | ||
|
|
74a291bdd6 | ||
|
|
ba6765b1fb | ||
|
|
9fce3be6a8 | ||
|
|
9892fc35bc | ||
|
|
62a528d33b | ||
|
|
37617dbd54 | ||
|
|
569bd43163 | ||
|
|
fdb0036ea6 | ||
|
|
f9797f2dca | ||
|
|
ba75c58a23 | ||
|
|
3d799ae461 | ||
|
|
2501662737 | ||
|
|
d04d166e14 | ||
|
|
1576719d10 | ||
|
|
362af75b9a | ||
|
|
bef5d03494 | ||
|
|
80ebf77eb6 | ||
|
|
c4ed247a05 | ||
|
|
323786859e | ||
|
|
354bf937b2 | ||
|
|
39bb37f5c3 | ||
|
|
b198dc2e06 | ||
|
|
d83cd3dc32 | ||
|
|
35583a4cdd | ||
|
|
d22952d83b |
@@ -1,3 +0,0 @@
|
|||||||
Sensor als Service einrichten, der aus Activity heraus gestartet werden kann.
|
|
||||||
Stichwort: Intent
|
|
||||||
Siehe Skript Teil 1
|
|
||||||
@@ -26,6 +26,9 @@ android {
|
|||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
buildFeatures {
|
||||||
|
viewBinding true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -33,7 +36,25 @@ dependencies {
|
|||||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'com.google.android.material:material:1.8.0'
|
implementation 'com.google.android.material:material:1.8.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
|
implementation 'com.google.android.gms:play-services-nearby:18.0.0'
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
|
||||||
|
|
||||||
|
// OpenCV (from: https://github.com/QuickBirdEng/opencv-android)
|
||||||
|
def opencv_version = "4.5.3.0"
|
||||||
|
implementation "com.quickbirdstudios:opencv:${opencv_version}"
|
||||||
|
|
||||||
|
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
// Required for CameraX
|
||||||
|
def camerax_version = "1.2.2"
|
||||||
|
implementation "androidx.camera:camera-core:${camerax_version}"
|
||||||
|
implementation "androidx.camera:camera-camera2:${camerax_version}"
|
||||||
|
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
||||||
|
implementation "androidx.camera:camera-video:${camerax_version}"
|
||||||
|
implementation "androidx.camera:camera-view:${camerax_version}"
|
||||||
|
implementation "androidx.camera:camera-extensions:${camerax_version}"
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,14 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<uses-feature android:name="android.hardware.camera"/>
|
||||||
|
<uses-permission android:name="android.permission.CAMERA"/>
|
||||||
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
@@ -20,6 +28,7 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<service android:name=".Detection.DetectorService"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
package com.example.ueberwachungssystem.Detection;
|
|
||||||
|
|
||||||
import static java.lang.Math.sqrt;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.hardware.Sensor;
|
|
||||||
import android.hardware.SensorEvent;
|
|
||||||
import android.hardware.SensorEventListener;
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Accelerometer inherits some methods from abstract Detector class (more info there)
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* USE FROM MAIN ACTIVITY:
|
|
||||||
*
|
|
||||||
* Accelerometer beschleunigungssensor = new Accelerometer(this);
|
|
||||||
* onCreate:
|
|
||||||
* //Accelerometer Setup
|
|
||||||
* beschleunigungssensor = new Accelerometer(this, logger, textViewLog); //logger and textview only for debugging necessary
|
|
||||||
* beschleunigungssensor.getSensor();
|
|
||||||
*
|
|
||||||
* //Starting Detection:
|
|
||||||
* beschleunigungssensor.startDetection();
|
|
||||||
* //Stopping Detection: also recommended at onPause to avoid unnecessary battery consumption
|
|
||||||
* beschleunigungssensor.stopDetection();
|
|
||||||
*
|
|
||||||
* */
|
|
||||||
|
|
||||||
public class Accelerometer extends Detector implements SensorEventListener {
|
|
||||||
|
|
||||||
public SensorManager sensorManager;
|
|
||||||
private static final int sensorType = Sensor.TYPE_LINEAR_ACCELERATION;
|
|
||||||
private Sensor accelerometer;
|
|
||||||
private Context context;
|
|
||||||
boolean alarm = false;
|
|
||||||
//Preallocate memory for the data of each axis of the acceleration sensor
|
|
||||||
float x;
|
|
||||||
float y;
|
|
||||||
float z;
|
|
||||||
float betrag; //Betrag aller drei Achsen sqrt(x*x + y*y + z*z)
|
|
||||||
private DetectionReport detectionReport;
|
|
||||||
|
|
||||||
// In constructor pass Activity, Context and TextView from MainActivity in Accelerometer class
|
|
||||||
public Accelerometer(Context context){
|
|
||||||
super(context); //von Detektor
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getSensor(){
|
|
||||||
sensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
|
|
||||||
if(sensorManager.getSensorList(sensorType).size()==0) {
|
|
||||||
accelerometer = null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
accelerometer = sensorManager.getSensorList(sensorType).get(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSensorChanged(SensorEvent event) {
|
|
||||||
try {
|
|
||||||
checkAlarm(event);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkAlarm (SensorEvent event) throws InterruptedException {
|
|
||||||
x = event.values[0];
|
|
||||||
y = event.values[1];
|
|
||||||
z = event.values[2];
|
|
||||||
betrag = (float) sqrt(x*x + y*y + z*z);
|
|
||||||
float threshold = 1.5F;
|
|
||||||
|
|
||||||
if (!alarm) {
|
|
||||||
if (betrag > threshold) {
|
|
||||||
alarm = true;
|
|
||||||
detectionReport = new DetectionReport("Accelerometer1", "Bewegung", betrag);
|
|
||||||
reportViolation("Accelo1", "Bewegung", betrag);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (betrag < threshold) {
|
|
||||||
alarm = false;
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void startDetection() {
|
|
||||||
// entspricht void start()
|
|
||||||
//getSensor();
|
|
||||||
if (accelerometer != null) {
|
|
||||||
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stopDetection() {
|
|
||||||
// entspricht void stop()
|
|
||||||
sensorManager.unregisterListener(this, accelerometer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.example.ueberwachungssystem.Detection;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
|
import android.media.MediaRecorder;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
public class AudioRecorder {
|
||||||
|
private final Context context;
|
||||||
|
private MediaRecorder mediaRecorder = null;
|
||||||
|
private boolean isRecording = false;
|
||||||
|
private File outputDir; // Default: in app files directory
|
||||||
|
|
||||||
|
|
||||||
|
public AudioRecorder (Context context) {
|
||||||
|
this.context = context;
|
||||||
|
this.outputDir = context.getFilesDir();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startRecording() {
|
||||||
|
// Handle logic
|
||||||
|
if (outputDir == null)
|
||||||
|
return;
|
||||||
|
if (isRecording)
|
||||||
|
return;
|
||||||
|
isRecording = true;
|
||||||
|
|
||||||
|
// Setup Audio Recorder for output Format: 3GP
|
||||||
|
mediaRecorder = new MediaRecorder();
|
||||||
|
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
||||||
|
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
||||||
|
mediaRecorder.setOutputFile(outputDir + "/" + generateFileName() + ".3gp");
|
||||||
|
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
|
||||||
|
try {
|
||||||
|
mediaRecorder.prepare();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
mediaRecorder.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopRecording() {
|
||||||
|
if (mediaRecorder != null) {
|
||||||
|
mediaRecorder.stop();
|
||||||
|
mediaRecorder.reset();
|
||||||
|
mediaRecorder.release();
|
||||||
|
mediaRecorder = null;
|
||||||
|
isRecording = false;
|
||||||
|
Toast.makeText(context, "audio recording saved", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRecording(){
|
||||||
|
return isRecording;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutputDir(File outputDir) {
|
||||||
|
this.outputDir = outputDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateFileName(){
|
||||||
|
// Get the current timestamp
|
||||||
|
LocalDateTime currentTime = LocalDateTime.now();
|
||||||
|
// Define the format for the timestamp
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss");
|
||||||
|
// Return the timestamp as a string
|
||||||
|
return currentTime.format(formatter);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,24 +9,26 @@ public class DetectionReport {
|
|||||||
public String timeStamp;
|
public String timeStamp;
|
||||||
public String detectionType;
|
public String detectionType;
|
||||||
public float detectedValue;
|
public float detectedValue;
|
||||||
public String detectorID;
|
public boolean detectionState;
|
||||||
|
|
||||||
public DetectionReport(String detectorID, String detectionType, float detectedAmplitude) {
|
public DetectionReport(boolean detectionState, String detectionType, float detectedAmplitude) {
|
||||||
this.timeStamp = String.valueOf(Calendar.getInstance().getTime());
|
this.timeStamp = String.valueOf(Calendar.getInstance().getTime());
|
||||||
this.detectionType = detectionType;
|
this.detectionType = detectionType;
|
||||||
this.detectedValue = detectedAmplitude;
|
this.detectedValue = detectedAmplitude;
|
||||||
this.detectorID = detectorID;
|
this.detectionState = detectionState;
|
||||||
|
|
||||||
|
//this.detectorID = detectorID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Get Detection Report in String format */
|
/** Get Detection Report in String format */
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
String state = "State: " + "[" + this.detectionState + "]";
|
||||||
String time = "Time: " + "[" + this.timeStamp + "]";
|
String time = "Time: " + "[" + this.timeStamp + "]";
|
||||||
String type = "Type: " + "[" + this.detectionType + "]";
|
String type = "Type: " + "[" + this.detectionType + "]";
|
||||||
String value = "Value: " + "[" + this.detectedValue + "]";
|
String value = "Value: " + "[" + this.detectedValue + "]";
|
||||||
String id = "ID: " + "[" + this.detectorID + "]";
|
|
||||||
|
|
||||||
return String.join("\t", time, type, value, id);
|
return String.join("\t", state, time, type, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Debug Report */
|
/** Debug Report */
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
package com.example.ueberwachungssystem.Detection;
|
package com.example.ueberwachungssystem.Detection;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.os.CountDownTimer;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.camera.core.ExperimentalGetImage;
|
||||||
|
|
||||||
|
|
||||||
abstract public class Detector {
|
abstract public class Detector {
|
||||||
private OnDetectionListener listener;
|
private OnDetectionListener listener;
|
||||||
|
private boolean isDetecting = false;
|
||||||
|
private boolean extendViolation = false;
|
||||||
|
|
||||||
|
// Countdown parameters
|
||||||
|
private final int COUNTDOWN_TIME = 10000; // milliseconds
|
||||||
|
private final int COUNTDOWN_POLLING_TIME = 100; // milliseconds
|
||||||
|
|
||||||
/** Constructor - takes context of current activity */
|
/** Constructor - takes context of current activity */
|
||||||
public Detector(Context context) {};
|
public Detector() {}
|
||||||
|
|
||||||
|
|
||||||
/** On Detection Listener - runs when violation is reported */
|
/** On Detection Listener - runs when violation is reported */
|
||||||
@@ -19,17 +27,46 @@ abstract public class Detector {
|
|||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Triggers onDetectionListener - call this to trigger violation/alarm */
|
/** Triggers onDetectionListener - call this to trigger violation/alarm */
|
||||||
public void reportViolation(String detectorID, String detectionType, float amplitude) {
|
public void reportViolation(String detectionType, float amplitude) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
DetectionReport detectionReport = new DetectionReport(detectorID, detectionType, amplitude);
|
if (!isDetecting) {
|
||||||
listener.onDetection(detectionReport);
|
isDetecting = true;
|
||||||
|
DetectionReport detectionReport = new DetectionReport(true, detectionType, amplitude);
|
||||||
|
listener.onDetection(detectionReport);
|
||||||
|
startDetectionTimer(detectionType, amplitude);
|
||||||
|
} else {
|
||||||
|
extendViolation = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException("No listener set for violation reporting");
|
isDetecting = false;
|
||||||
|
extendViolation = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startDetectionTimer(String detectionType, float amplitude) {
|
||||||
|
isDetecting = true;
|
||||||
|
new CountDownTimer((long) COUNTDOWN_TIME, COUNTDOWN_POLLING_TIME) {
|
||||||
|
@Override
|
||||||
|
public void onTick(long millisUntilFinished) {
|
||||||
|
if (extendViolation) {
|
||||||
|
extendViolation = false;
|
||||||
|
startDetectionTimer(detectionType, amplitude);
|
||||||
|
this.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
isDetecting = false;
|
||||||
|
DetectionReport detectionReport = new DetectionReport(false, detectionType, amplitude);
|
||||||
|
listener.onDetection(detectionReport);
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void extendViolation(){
|
||||||
|
this.extendViolation = true;
|
||||||
|
}
|
||||||
|
|
||||||
/** Starts Detection (abstract method: needs to be overridden in child class) */
|
/** Starts Detection (abstract method: needs to be overridden in child class) */
|
||||||
public abstract void startDetection();
|
public abstract void startDetection();
|
||||||
|
|||||||
@@ -0,0 +1,174 @@
|
|||||||
|
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 android.widget.Toast;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
VideoDetector videoDetector = null;
|
||||||
|
AudioRecorder audioRecorder = 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:
|
||||||
|
videoDetector = new VideoDetector(this);
|
||||||
|
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
|
passToServiceListener(detectionReport);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Video Detection */
|
||||||
|
public void startVideoDetection() {
|
||||||
|
if(videoDetector != null)
|
||||||
|
videoDetector.startDetection();
|
||||||
|
}
|
||||||
|
public void stopVideoDetection() {
|
||||||
|
if(videoDetector != null)
|
||||||
|
videoDetector.stopDetection();
|
||||||
|
}
|
||||||
|
public boolean isVideoDetectionRunning() {
|
||||||
|
if(videoDetector != null)
|
||||||
|
return videoDetector.isDetecting();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void debugVideoProcessing(ImageView input, ImageView output) {
|
||||||
|
if(videoDetector != null)
|
||||||
|
videoDetector.debugProcessing(input, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Audio Detection */
|
||||||
|
public void startAudioDetection() {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void stopAudioDetection() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Motion Detection */
|
||||||
|
public void startMotionDetection() {
|
||||||
|
|
||||||
|
}
|
||||||
|
public void stopMotionDetection() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Video Recording */
|
||||||
|
public void startVideoRecording() {
|
||||||
|
if(videoDetector != null)
|
||||||
|
videoDetector.startRecording();
|
||||||
|
}
|
||||||
|
public void stopVideoRecording() {
|
||||||
|
if(videoDetector != null)
|
||||||
|
videoDetector.stopRecording();
|
||||||
|
}
|
||||||
|
public boolean isVideoRecordingRunning() {
|
||||||
|
if(videoDetector != null)
|
||||||
|
return videoDetector.isRecording();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void setVideoRecordingDir(File outputDir) {
|
||||||
|
if (videoDetector != null)
|
||||||
|
videoDetector.setOutputDir(outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Audio Recording */
|
||||||
|
public void startAudioRecording() {
|
||||||
|
if(audioRecorder != null)
|
||||||
|
audioRecorder.startRecording();
|
||||||
|
}
|
||||||
|
public void stopAudioRecording() {
|
||||||
|
if(audioRecorder != null)
|
||||||
|
audioRecorder.stopRecording();
|
||||||
|
}
|
||||||
|
public boolean isAudioRecordingRunning() {
|
||||||
|
if(videoDetector != null)
|
||||||
|
return audioRecorder.isRecording();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void setAudioRecordingDir(File outputDir) {
|
||||||
|
if (audioRecorder != null)
|
||||||
|
audioRecorder.setOutputDir(outputDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** pass Detection Report to Service Detection Listener and trigger it */
|
||||||
|
public void passToServiceListener(DetectionReport detectionReport) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onDetection(detectionReport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** On Detection Listener - runs when violation is reported */
|
||||||
|
public interface OnDetectionListener {
|
||||||
|
void onDetection(@NonNull DetectionReport detectionReport);
|
||||||
|
}
|
||||||
|
public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package com.example.ueberwachungssystem.Detection;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.media.Image;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.camera.core.ExperimentalGetImage;
|
||||||
|
import androidx.camera.core.ImageProxy;
|
||||||
|
|
||||||
|
import org.opencv.android.Utils;
|
||||||
|
import org.opencv.core.Core;
|
||||||
|
import org.opencv.core.CvType;
|
||||||
|
import org.opencv.core.Mat;
|
||||||
|
import org.opencv.core.MatOfPoint;
|
||||||
|
import org.opencv.core.Scalar;
|
||||||
|
import org.opencv.core.Size;
|
||||||
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@ExperimentalGetImage
|
||||||
|
public class OpenCVHelper {
|
||||||
|
|
||||||
|
/** OpenCV helper methods **/
|
||||||
|
public static Mat addGaussianBlur(Mat inputMat, Size kernelSize){
|
||||||
|
Mat outputMat = new Mat();
|
||||||
|
Imgproc.GaussianBlur(inputMat, outputMat, kernelSize, 0);
|
||||||
|
return outputMat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Mat addBlur(Mat inputMat, Size kernelSize){
|
||||||
|
Mat outputMat = new Mat();
|
||||||
|
Imgproc.blur(inputMat, outputMat, kernelSize);
|
||||||
|
return outputMat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Mat extractYChannel(@NonNull ImageProxy imgProxy) {
|
||||||
|
Image img = imgProxy.getImage();
|
||||||
|
|
||||||
|
assert img != null;
|
||||||
|
ByteBuffer yBuffer = img.getPlanes()[0].getBuffer();
|
||||||
|
byte[] yData = new byte[yBuffer.remaining()];
|
||||||
|
yBuffer.get(yData);
|
||||||
|
|
||||||
|
Mat yMat = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC1);
|
||||||
|
yMat.put(0, 0, yData);
|
||||||
|
|
||||||
|
return yMat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Mat thresholdPixels(Mat inputMat, Mat previousImage, int threshold){
|
||||||
|
Mat diffImage = new Mat();
|
||||||
|
Core.absdiff(inputMat, previousImage, diffImage);
|
||||||
|
Mat binaryMat = new Mat();
|
||||||
|
Imgproc.threshold(diffImage, binaryMat, threshold, 255, Imgproc.THRESH_BINARY);
|
||||||
|
return binaryMat;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Mat thresholdContourArea(Mat inputMat, float areaThreshold){
|
||||||
|
List<MatOfPoint> contours = new ArrayList<>();
|
||||||
|
Mat hierarchy = new Mat();
|
||||||
|
Imgproc.findContours(inputMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
|
||||||
|
|
||||||
|
Mat outputMat = new Mat(inputMat.size(), inputMat.type(), new Scalar(0));
|
||||||
|
// Iterate over the contours and draw only the larger contours on the outputMat
|
||||||
|
for (MatOfPoint contour : contours) {
|
||||||
|
double contourArea = Imgproc.contourArea(contour);
|
||||||
|
if (contourArea > areaThreshold) {
|
||||||
|
Imgproc.drawContours(outputMat, Collections.singletonList(contour), 0, new Scalar(255), -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Apply the outputMat as a mask to the dilatedImage
|
||||||
|
Mat maskedImage = new Mat();
|
||||||
|
inputMat.copyTo(maskedImage, outputMat);
|
||||||
|
return outputMat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Mat dilateBinaryMat(Mat inputMat, Size kernelSize){
|
||||||
|
Mat dilatedMat = new Mat();
|
||||||
|
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, kernelSize);
|
||||||
|
Imgproc.dilate(inputMat, dilatedMat, kernel);
|
||||||
|
return dilatedMat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int countNonZeroPixels(Mat inputImage) {
|
||||||
|
if (inputImage != null)
|
||||||
|
return Core.countNonZero(inputImage);
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void debugMat(Mat mat, ImageView imageView) {
|
||||||
|
if (imageView == null || mat == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(mat.cols(), mat.rows(), Bitmap.Config.ARGB_8888);
|
||||||
|
Utils.matToBitmap(mat, bitmap);
|
||||||
|
|
||||||
|
// Display the bitmap in an ImageView
|
||||||
|
imageView.setImageBitmap(bitmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
package com.example.ueberwachungssystem.Detection;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.graphics.ImageFormat;
|
||||||
|
import android.media.Image;
|
||||||
|
import android.os.CountDownTimer;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.Display;
|
||||||
|
import android.view.Surface;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.camera.core.CameraSelector;
|
||||||
|
import androidx.camera.core.ExperimentalGetImage;
|
||||||
|
import androidx.camera.core.ImageAnalysis;
|
||||||
|
import androidx.camera.core.ImageProxy;
|
||||||
|
import androidx.camera.core.Preview;
|
||||||
|
import androidx.camera.core.VideoCapture;
|
||||||
|
import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||||
|
import androidx.camera.view.PreviewView;
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
import org.opencv.android.OpenCVLoader;
|
||||||
|
import org.opencv.core.Mat;
|
||||||
|
import org.opencv.core.Size;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Video Detector inherits some methods from abstract Detector class (more info there)
|
||||||
|
* USE FROM MAIN ACTIVITY:
|
||||||
|
* VideoDetector vd = new VideoDetector(this);
|
||||||
|
* */
|
||||||
|
|
||||||
|
|
||||||
|
@ExperimentalGetImage
|
||||||
|
public class VideoDetector extends Detector {
|
||||||
|
// Calling Activity
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
// Camera Provider
|
||||||
|
private ProcessCameraProvider cameraProvider;
|
||||||
|
private ImageAnalysis imageAnalysis;
|
||||||
|
private VideoCapture videoCapture;
|
||||||
|
//private Preview preview;
|
||||||
|
|
||||||
|
// Logic
|
||||||
|
private boolean isDetecting = false;
|
||||||
|
private boolean isRecording = false;
|
||||||
|
private boolean allowReportViolation = false;
|
||||||
|
|
||||||
|
// Image Processing
|
||||||
|
private Mat previousImage = null;
|
||||||
|
|
||||||
|
// Debugging
|
||||||
|
private ImageView inputImageView = null;
|
||||||
|
private ImageView outputImageView = null;
|
||||||
|
|
||||||
|
// Recorder
|
||||||
|
private File outputDir; // Default: in app files directory
|
||||||
|
|
||||||
|
|
||||||
|
// Parameters
|
||||||
|
private static final float ALARM_THRESHOLD = 0f; // Percent of pixels changed
|
||||||
|
private static final float AREA_THRESHOLD = 10f;
|
||||||
|
private static final int DILATE_ITERATIONS = 2;
|
||||||
|
private static final float START_DELAY = 20000; // milliseconds
|
||||||
|
private static final android.util.Size IMAGE_RES = new android.util.Size(640, 480);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** Constructor */
|
||||||
|
public VideoDetector(Context context) {
|
||||||
|
super();
|
||||||
|
this.context = context;
|
||||||
|
this.imageAnalysis = setupImageAnalysis();
|
||||||
|
this.videoCapture = setupVideoCapture();
|
||||||
|
this.outputDir = context.getFilesDir();
|
||||||
|
//this.preview = new Preview.Builder().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Get States */
|
||||||
|
public boolean isDetecting() {
|
||||||
|
return isDetecting;
|
||||||
|
}
|
||||||
|
public boolean isRecording(){
|
||||||
|
return isRecording;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Starts the Video Detection */
|
||||||
|
@Override
|
||||||
|
public void startDetection() {
|
||||||
|
// Check States
|
||||||
|
if (isDetecting)
|
||||||
|
return;
|
||||||
|
// Configure Image Analysis
|
||||||
|
imageAnalysis = setupImageAnalysis();
|
||||||
|
// Open CV startup check
|
||||||
|
if (!OpenCVLoader.initDebug()) {
|
||||||
|
Log.e("OpenCV", "Unable to load OpenCV!");
|
||||||
|
return;
|
||||||
|
} else
|
||||||
|
Log.d("OpenCV", "OpenCV loaded Successfully!");
|
||||||
|
// Get Process Camera Provider and start
|
||||||
|
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(context);
|
||||||
|
cameraProviderFuture.addListener(() -> {
|
||||||
|
try {
|
||||||
|
cameraProvider = cameraProviderFuture.get();
|
||||||
|
isDetecting = true;
|
||||||
|
bindCameraProvider();
|
||||||
|
} catch (ExecutionException | InterruptedException e) {}
|
||||||
|
}, ContextCompat.getMainExecutor(context));
|
||||||
|
// Disable Violation Calling for Setup Time
|
||||||
|
startViolationTimer(START_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Starts the Recorder */
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
public void startRecording() {
|
||||||
|
// Check States
|
||||||
|
if (isRecording){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
videoCapture = setupVideoCapture();
|
||||||
|
|
||||||
|
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(context);
|
||||||
|
cameraProviderFuture.addListener(() -> {
|
||||||
|
try {
|
||||||
|
cameraProvider = cameraProviderFuture.get();
|
||||||
|
isRecording = true;
|
||||||
|
bindCameraProvider();
|
||||||
|
|
||||||
|
File vidFile = new File(context.getFilesDir() + "/" + generateFileName() + ".mp4");
|
||||||
|
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
videoCapture.startRecording(
|
||||||
|
new VideoCapture.OutputFileOptions.Builder(vidFile).build(),
|
||||||
|
context.getMainExecutor(),
|
||||||
|
new VideoCapture.OnVideoSavedCallback() {
|
||||||
|
@Override
|
||||||
|
public void onVideoSaved(@NonNull VideoCapture.OutputFileResults outputFileResults) {
|
||||||
|
isRecording = false;
|
||||||
|
Toast.makeText(context, "video recording saved", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
|
||||||
|
isRecording = false;
|
||||||
|
Toast.makeText(context, "video recording failed", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (ExecutionException | InterruptedException ignored) {}
|
||||||
|
}, ContextCompat.getMainExecutor(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Stops the Video Detection */
|
||||||
|
@Override
|
||||||
|
public void stopDetection() {
|
||||||
|
if (!isDetecting || imageAnalysis == null)
|
||||||
|
return;
|
||||||
|
cameraProvider.unbind(imageAnalysis);
|
||||||
|
isDetecting = false;
|
||||||
|
allowReportViolation = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Stops the Recording */
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
public void stopRecording(){
|
||||||
|
if(!isRecording)
|
||||||
|
return;
|
||||||
|
|
||||||
|
videoCapture.stopRecording();
|
||||||
|
cameraProvider.unbind(videoCapture);
|
||||||
|
isRecording = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bind Camera Provider */
|
||||||
|
private void bindCameraProvider() {
|
||||||
|
// Specify which Camera to use
|
||||||
|
CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build();
|
||||||
|
cameraProvider.unbindAll();
|
||||||
|
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, imageAnalysis, videoCapture);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Setup Use Cases */
|
||||||
|
private ImageAnalysis setupImageAnalysis() {
|
||||||
|
// Configure and create Image Analysis
|
||||||
|
ImageAnalysis.Builder builder = new ImageAnalysis.Builder();
|
||||||
|
builder.setTargetResolution(IMAGE_RES);
|
||||||
|
builder.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST);
|
||||||
|
builder.setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888);
|
||||||
|
builder.setTargetRotation(Surface.ROTATION_90);
|
||||||
|
ImageAnalysis imageAnalysis = builder.build();
|
||||||
|
// Set Analyzer
|
||||||
|
imageAnalysis.setAnalyzer(ContextCompat.getMainExecutor(context), imageProxy -> {
|
||||||
|
if (imageProxy.getFormat() == ImageFormat.YUV_420_888) {
|
||||||
|
Image image = imageProxy.getImage();
|
||||||
|
assert image != null;
|
||||||
|
|
||||||
|
// Violation Handling
|
||||||
|
Mat processed = processImage(imageProxy);
|
||||||
|
|
||||||
|
int n = OpenCVHelper.countNonZeroPixels(processed);
|
||||||
|
int pixelCount = image.getWidth() * image.getHeight();
|
||||||
|
float percentChanged = (float) n / pixelCount;
|
||||||
|
|
||||||
|
// Violation Condition
|
||||||
|
if (percentChanged * 100 > ALARM_THRESHOLD) {
|
||||||
|
if (allowReportViolation)
|
||||||
|
reportViolation("Video", percentChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imageProxy.close();
|
||||||
|
});
|
||||||
|
return imageAnalysis;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
private VideoCapture setupVideoCapture() {
|
||||||
|
int rotation = getDisplayRotation();
|
||||||
|
return new VideoCapture.Builder()
|
||||||
|
.setTargetRotation(rotation)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Process Image to be used for Motion Detection */
|
||||||
|
private Mat processImage(ImageProxy imageProxy){
|
||||||
|
if (imageProxy == null)
|
||||||
|
return null;
|
||||||
|
// Image Transformation
|
||||||
|
Mat imageMat = OpenCVHelper.extractYChannel(imageProxy);
|
||||||
|
// Show Input Image
|
||||||
|
if (inputImageView != null)
|
||||||
|
OpenCVHelper.debugMat(imageMat, inputImageView);
|
||||||
|
// Preprocess Image
|
||||||
|
Mat preprocessed = imageMat;
|
||||||
|
preprocessed = OpenCVHelper.addGaussianBlur(preprocessed, new Size(21, 21));
|
||||||
|
preprocessed = OpenCVHelper.addBlur(preprocessed, new Size(3, 3));
|
||||||
|
// Set Previous Image
|
||||||
|
if (previousImage == null) {
|
||||||
|
previousImage = preprocessed;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Process Image
|
||||||
|
Mat processed = preprocessed.clone();
|
||||||
|
processed = OpenCVHelper.thresholdPixels(processed, previousImage, 25);
|
||||||
|
|
||||||
|
for(int i = 0; i < DILATE_ITERATIONS; i++)
|
||||||
|
processed = OpenCVHelper.dilateBinaryMat(processed, new Size(3,3));
|
||||||
|
|
||||||
|
processed = OpenCVHelper.thresholdContourArea(processed, AREA_THRESHOLD);
|
||||||
|
// Output
|
||||||
|
previousImage = preprocessed.clone();
|
||||||
|
// Show Output Image
|
||||||
|
if (outputImageView != null)
|
||||||
|
OpenCVHelper.debugMat(processed, outputImageView);
|
||||||
|
return processed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Debug input and result of processing */
|
||||||
|
public void debugProcessing(@NonNull ImageView inputImageView, @NonNull ImageView outputImageView){
|
||||||
|
this.inputImageView = inputImageView;
|
||||||
|
this.outputImageView = outputImageView;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
private void setPreviewView(@NonNull PreviewView previewView) {
|
||||||
|
// Create Preview
|
||||||
|
if (this.preview != null)
|
||||||
|
this.preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** Generate File Name */
|
||||||
|
private String generateFileName(){
|
||||||
|
// Get the current timestamp
|
||||||
|
LocalDateTime currentTime = LocalDateTime.now();
|
||||||
|
// Define the format for the timestamp
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss");
|
||||||
|
// Return the timestamp as a string
|
||||||
|
return currentTime.format(formatter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Get current Display Rotation */
|
||||||
|
private int getDisplayRotation() {
|
||||||
|
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||||
|
Display display = windowManager.getDefaultDisplay();
|
||||||
|
return display.getRotation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Start delay until Violation Report is allowed */
|
||||||
|
private void startViolationTimer(float setupTime) {
|
||||||
|
new CountDownTimer((long) (START_DELAY), 100) {
|
||||||
|
@Override
|
||||||
|
public void onTick(long millisUntilFinished) {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
allowReportViolation = true;
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutputDir(File outputDir) {
|
||||||
|
this.outputDir = outputDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,72 +1,113 @@
|
|||||||
package com.example.ueberwachungssystem;
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import static android.content.ContentValues.TAG;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.net.wifi.WifiInfo;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.net.wifi.WifiInfo;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.util.Log;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.example.ueberwachungssystem.Detection.Accelerometer;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
import java.net.InetAddress;
|
||||||
import com.example.ueberwachungssystem.Detection.Detector;
|
import java.net.UnknownHostException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
@SuppressLint("SetTextI18n")
|
||||||
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private Accelerometer beschleunigungssensor;
|
WifiCommunication communication;
|
||||||
private TextView textViewLog;
|
PermissionRequest permission;
|
||||||
private Button button1;
|
boolean communicationRunning = true;
|
||||||
ToggleButton toggleButton1;
|
String dataRecieved;
|
||||||
|
TextView textview1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setTitle(this.getClass().getSimpleName());
|
setContentView(R.layout.activity_main);
|
||||||
setContentView(R.layout.activity_main);
|
textview1 = findViewById(R.id.textView1);
|
||||||
|
|
||||||
|
|
||||||
toggleButton1 = findViewById(R.id.toggleButton1); //togglebutton um Detektion zu steuern
|
|
||||||
toggleButton1.setOnClickListener(this);
|
|
||||||
|
|
||||||
//Button to clear Log while Debugging
|
|
||||||
button1 = (Button) findViewById(R.id.button1);
|
|
||||||
button1.setOnClickListener(this);
|
|
||||||
|
|
||||||
//Accelerometer Setup
|
|
||||||
beschleunigungssensor = new Accelerometer(this); //logger and textview only for debugging necessary
|
|
||||||
beschleunigungssensor.getSensor();
|
|
||||||
beschleunigungssensor.setOnDetectionListener(new Detector.OnDetectionListener() {
|
|
||||||
@Override
|
|
||||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Button button1 = findViewById(R.id.buttonSend);
|
||||||
|
button1.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
communication.sendTrue("Testmessage");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
if (communicationRunning){
|
||||||
|
communication = new WifiCommunication(1234);
|
||||||
|
communication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onConnection(StringBuffer data) {
|
||||||
|
//Log.d("Test", data.toString());
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
textview1.setText(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
communicationRunning = false;
|
||||||
|
}
|
||||||
|
permission = new PermissionRequest(MainActivity.this);
|
||||||
|
permission.rechtePruefen();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
beschleunigungssensor.stopDetection();
|
//communication.stopCommunication();
|
||||||
}
|
}
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
@Override
|
getMenuInflater().inflate(R.menu.options_menu, menu);
|
||||||
public void onClick(View v) {
|
return true;
|
||||||
if(v == toggleButton1) {
|
}
|
||||||
if (toggleButton1.isChecked()) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
beschleunigungssensor.startDetection();
|
Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
|
||||||
|
PopUpClass popUpClass;
|
||||||
} else {
|
switch (item.getItemId()) {
|
||||||
beschleunigungssensor.stopDetection();
|
case R.id.Rechteverwaltung:
|
||||||
}
|
popUpClass = new PopUpClass(MainActivity.this);
|
||||||
} else if (v == button1) {
|
//popUpClass.showPopupWindow(tvMessages);
|
||||||
|
popUpClass.RechtePrüfen();
|
||||||
|
return true;
|
||||||
|
case R.id.Sensoren:
|
||||||
|
popUpClass = new PopUpClass(MainActivity.this);
|
||||||
|
//popUpClass.showPopupWindow(tvMessages);
|
||||||
|
popUpClass.Sensoren();
|
||||||
|
return true;
|
||||||
|
case R.id.Impressum:
|
||||||
|
popUpClass = new PopUpClass(MainActivity.this);
|
||||||
|
//popUpClass.showPopupWindow(tvMessages);
|
||||||
|
popUpClass.Impressum();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
private String getLocalIpAddress() throws UnknownHostException {
|
||||||
|
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
|
||||||
|
assert wifiManager != null;
|
||||||
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||||
|
int ipInt = wifiInfo.getIpAddress();
|
||||||
|
return InetAddress.getByAddress(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(ipInt).array()).getHostAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
public class PermissionHandler {
|
||||||
|
private final Context context;
|
||||||
|
private static final int PERMISSION_REQUEST_CODE = 23409;
|
||||||
|
private static final String[] permissions = new String[]{
|
||||||
|
android.Manifest.permission.CAMERA,
|
||||||
|
android.Manifest.permission.RECORD_AUDIO
|
||||||
|
};
|
||||||
|
|
||||||
|
public PermissionHandler(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermissions() {
|
||||||
|
boolean permissionState = true;
|
||||||
|
for (String permission: permissions) {
|
||||||
|
permissionState = permissionState && ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
}
|
||||||
|
return permissionState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getPermissions() {
|
||||||
|
if (!hasPermissions())
|
||||||
|
ActivityCompat.requestPermissions((Activity) context, permissions, PERMISSION_REQUEST_CODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showPermissionToast() {
|
||||||
|
if (hasPermissions())
|
||||||
|
Toast.makeText(context, "permissions available", Toast.LENGTH_SHORT).show();
|
||||||
|
else
|
||||||
|
Toast.makeText(context, "permissions missing", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.INTERNET;
|
||||||
|
import static android.Manifest.permission.CAMERA;
|
||||||
|
import static android.Manifest.permission.RECORD_AUDIO;
|
||||||
|
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
public class PermissionRequest extends AppCompatActivity{
|
||||||
|
private static final int PERMISSION_REQUEST_CODE = 123;
|
||||||
|
private final MainActivity mainActivity;
|
||||||
|
|
||||||
|
Handler handler = new Handler();
|
||||||
|
|
||||||
|
public PermissionRequest(MainActivity mainActivity) {
|
||||||
|
this.mainActivity = mainActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringBuilder rechtePruefen() {
|
||||||
|
boolean rechtKamera = ContextCompat.checkSelfPermission(mainActivity, CAMERA) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
boolean rechtMikrofon = ContextCompat.checkSelfPermission(mainActivity, RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
boolean rechtInternet = ContextCompat.checkSelfPermission(mainActivity, INTERNET) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("Rechte prüfen:")
|
||||||
|
.append("\nKamera: ").append(rechtKamera)
|
||||||
|
.append("\nMikrofon: ").append(rechtMikrofon)
|
||||||
|
.append("\nInternet: ").append(rechtInternet);
|
||||||
|
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(sb));
|
||||||
|
if (!(rechtKamera && rechtMikrofon && rechtInternet)){
|
||||||
|
handler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(mainActivity.getApplicationContext(),"Es werden Rechte benötigt", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return sb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rechteAnfordern() {
|
||||||
|
mainActivity.requestPermissions(new String[]{CAMERA, RECORD_AUDIO, INTERNET}, PERMISSION_REQUEST_CODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.PopupWindow;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
public class PopUpClass {
|
||||||
|
private final MainActivity mainActivity;
|
||||||
|
|
||||||
|
PermissionRequest permission;
|
||||||
|
TextView PopUpText;
|
||||||
|
|
||||||
|
|
||||||
|
public PopUpClass(MainActivity mainActivity) {
|
||||||
|
this.mainActivity = mainActivity;
|
||||||
|
permission = new PermissionRequest(mainActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
//PopupWindow display method
|
||||||
|
|
||||||
|
public void showPopupWindow(final View view) {
|
||||||
|
|
||||||
|
|
||||||
|
//Create a View object yourself through inflater
|
||||||
|
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(view.getContext().LAYOUT_INFLATER_SERVICE);
|
||||||
|
View popupView = inflater.inflate(R.layout.popup_window, null);
|
||||||
|
|
||||||
|
//Specify the length and width through constants
|
||||||
|
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||||
|
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
|
||||||
|
|
||||||
|
//Make Inactive Items Outside Of PopupWindow
|
||||||
|
boolean focusable = true;
|
||||||
|
|
||||||
|
//Create a window with our parameters
|
||||||
|
final PopupWindow popupWindow = new PopupWindow(popupView,width*1, height*1, focusable);
|
||||||
|
|
||||||
|
//Set the location of the window on the screen
|
||||||
|
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
|
||||||
|
|
||||||
|
//Initialize the elements of our window, install the handler
|
||||||
|
|
||||||
|
PopUpText = popupView.findViewById(R.id.titleText);
|
||||||
|
|
||||||
|
Button buttonEdit = popupView.findViewById(R.id.RechteAnfordern);
|
||||||
|
buttonEdit.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
RechteAnfordern();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Handler for clicking on the inactive zone of the window
|
||||||
|
|
||||||
|
popupView.setOnTouchListener(new View.OnTouchListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
|
||||||
|
//Close the window when clicked
|
||||||
|
popupWindow.dismiss();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public void RechtePrüfen(){
|
||||||
|
StringBuilder Text = permission.rechtePruefen();
|
||||||
|
PopUpText.setText(Text);
|
||||||
|
}
|
||||||
|
public void RechteAnfordern(){
|
||||||
|
permission.rechteAnfordern();
|
||||||
|
StringBuilder Text = permission.rechtePruefen();
|
||||||
|
PopUpText.setText(Text);
|
||||||
|
}
|
||||||
|
public void Sensoren(){
|
||||||
|
PopUpText.setText("Es können 3 verschiedene Sensoren verwendet werden \n -1. Beschleunigungssensor\n -2. Mikrofon\n -3. Kamera");
|
||||||
|
}
|
||||||
|
public void Impressum(){
|
||||||
|
PopUpText.setText("Die Ueberwachungsapp wurde im Rahmen eines Praktikums der TH-Nürnberg programmiert");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
package com.example.ueberwachungssystem;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
||||||
|
import com.example.ueberwachungssystem.Detection.Detector;
|
||||||
|
import com.example.ueberwachungssystem.Detection.DetectorService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
public class WifiCommunication {
|
||||||
|
//private final MainActivity mainActivity;
|
||||||
|
private final InetAddress address;
|
||||||
|
private final int port;
|
||||||
|
|
||||||
|
private String messageToSend;
|
||||||
|
volatile private boolean send;
|
||||||
|
private final DatagramSocket socket;
|
||||||
|
volatile private boolean running;
|
||||||
|
|
||||||
|
private OnConnectionListener listener;
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
public WifiCommunication(int port) {
|
||||||
|
//this.mainActivity = mainActivity;
|
||||||
|
this.port = port;
|
||||||
|
try {
|
||||||
|
socket = new DatagramSocket(this.port);
|
||||||
|
socket.setBroadcast(true);
|
||||||
|
address = InetAddress.getByName("255.255.255.255"); //100.82.255.255
|
||||||
|
running = true;
|
||||||
|
send = false;
|
||||||
|
new ReceiveThread().start();
|
||||||
|
new SendThread().start();
|
||||||
|
} catch (SocketException | UnknownHostException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
//Toast.makeText(mainActivity.getApplicationContext(),"Communication running", Toast.LENGTH_SHORT).show();
|
||||||
|
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText("Communication running"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnConnectionListener {
|
||||||
|
void onConnection(StringBuffer data);
|
||||||
|
}
|
||||||
|
public void setOnConnectionListener(@NonNull OnConnectionListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendWifiData(StringBuffer wifiMessage) {
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onConnection(wifiMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ReceiveThread extends Thread {
|
||||||
|
private StringBuffer rxStringBuffer = new StringBuffer();
|
||||||
|
private String rxString="";
|
||||||
|
private String previousRxString = "";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
byte[] receiveData = new byte[512];
|
||||||
|
DatagramPacket rxPacket = new DatagramPacket(receiveData, receiveData.length);
|
||||||
|
socket.receive(rxPacket);
|
||||||
|
rxString = new String(receiveData, 0, rxPacket.getLength());
|
||||||
|
String[] splitrxString = rxString.split(",");
|
||||||
|
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) {
|
||||||
|
rxStringBuffer.append(rxString).append("\n");
|
||||||
|
sendWifiData(rxStringBuffer);
|
||||||
|
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
|
||||||
|
previousRxString = rxString;
|
||||||
|
}
|
||||||
|
} while (running);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private class SendThread extends Thread {
|
||||||
|
private int tmpCnt = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
if(send)
|
||||||
|
{
|
||||||
|
send = false;
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
Date curDate = new Date(System.currentTimeMillis());
|
||||||
|
String str = formatter.format(curDate);
|
||||||
|
byte[] send_Data = new byte[512];
|
||||||
|
String txString = ("1," +str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video," +messageToSend);
|
||||||
|
send_Data = txString.getBytes();
|
||||||
|
|
||||||
|
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port);
|
||||||
|
|
||||||
|
for(int i = 0; i < 300; i++) {
|
||||||
|
socket.send(txPacket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (running);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static String getLocalIpAddress() {
|
||||||
|
try {
|
||||||
|
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
||||||
|
NetworkInterface networkInterface = (NetworkInterface) ((Enumeration<?>) en).nextElement();
|
||||||
|
for (Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements();) {
|
||||||
|
InetAddress inetAddress = addresses.nextElement();
|
||||||
|
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
|
||||||
|
return inetAddress.getHostAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SocketException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendTrue(String message){
|
||||||
|
send = true;
|
||||||
|
messageToSend = message;
|
||||||
|
}
|
||||||
|
public void stopCommunication() {
|
||||||
|
running = false;
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,63 +1,53 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="top"
|
||||||
|
android:orientation="vertical"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textViewLog"
|
<androidx.camera.view.PreviewView
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/previewView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="32dp"
|
android:backgroundTint="@android:color/black"/>
|
||||||
android:layout_marginTop="60dp"
|
|
||||||
android:layout_marginEnd="32dp"
|
|
||||||
android:maxLines="25"
|
|
||||||
android:scrollbars="vertical"
|
|
||||||
android:text="TextViewLoggerMain"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textViewWorkerThread"
|
|
||||||
app:layout_constraintVertical_bias="0.0" />
|
|
||||||
|
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
android:id="@+id/toggleButton1"
|
android:id="@+id/toggleButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="ToggleButton" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/inputImageView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="161dp"
|
tools:srcCompat="@tools:sample/avatars" />
|
||||||
android:layout_marginTop="115dp"
|
|
||||||
android:layout_marginEnd="162dp"
|
<ImageView
|
||||||
android:text="ToggleButton"
|
android:id="@+id/outputImageView"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:layout_width="wrap_content"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
tools:srcCompat="@tools:sample/avatars" />
|
||||||
|
|
||||||
|
<androidx.camera.view.PreviewView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewWorkerThread"
|
android:id="@+id/textView1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="32dp"
|
android:text="TextView" />
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:layout_marginEnd="32dp"
|
|
||||||
android:text="textViewWorkerThreadTextView"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/toggleButton1" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button1"
|
android:id="@+id/buttonSend"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="35dp"
|
android:text="Button" />
|
||||||
android:layout_marginTop="31dp"
|
|
||||||
android:layout_marginEnd="282dp"
|
|
||||||
android:layout_marginBottom="100dp"
|
|
||||||
android:text="Clear Log"
|
|
||||||
app:layout_constraintBottom_toTopOf="@+id/textViewWorkerThread"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</LinearLayout>
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="10dp"
|
||||||
|
android:paddingRight="10dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:background="#A5ACB2">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/titleText"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textStyle="italic"
|
||||||
|
android:padding="10dp"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/RechteAnfordern"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Rechte Anfordern" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<item android:id="@+id/Rechteverwaltung"
|
||||||
|
android:title="Rechteverwaltung" />
|
||||||
|
<item android:id="@+id/Sensoren"
|
||||||
|
android:title="Sensoren" />
|
||||||
|
<item android:id="@+id/Impressum"
|
||||||
|
android:title="Impressum" />
|
||||||
|
</menu>
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.android.application' version '8.0.0' apply false
|
id 'com.android.application' version '7.4.2' apply false
|
||||||
id 'com.android.library' version '8.0.0' apply false
|
id 'com.android.library' version '7.4.2' apply false
|
||||||
}
|
}
|
||||||
+1
-3
@@ -18,6 +18,4 @@ android.useAndroidX=true
|
|||||||
# Enables namespacing of each library's R class so that its R class includes only the
|
# Enables namespacing of each library's R class so that its R class includes only the
|
||||||
# resources declared in the library itself and none from the library's dependencies,
|
# resources declared in the library itself and none from the library's dependencies,
|
||||||
# thereby reducing the size of the R class for that library
|
# thereby reducing the size of the R class for that library
|
||||||
android.nonTransitiveRClass=true
|
android.nonTransitiveRClass=true
|
||||||
android.defaults.buildfeatures.buildconfig=true
|
|
||||||
android.nonFinalResIds=false
|
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
#Thu May 11 15:04:30 CEST 2023
|
#Thu May 11 15:04:30 CEST 2023
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
rootProject.name = "Ueberwachungssystem"
|
rootProject.name = "Ueberwachungssystem"
|
||||||
include ':app'
|
include ':app'
|
||||||
|
include ':app'
|
||||||
|
|||||||
Reference in New Issue
Block a user