Compare commits
104
Commits
lm
..
koLayoutTest
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
076db89147 | ||
|
|
061646a7d6 | ||
|
|
6f78836c4d | ||
|
|
b667e70fef | ||
|
|
272daf9fae | ||
|
|
55ae95e661 | ||
|
|
8e47934beb | ||
|
|
c60a14b6ac | ||
|
|
b9c66f7533 | ||
|
|
7e1143880e | ||
|
|
4381ae78f8 | ||
|
|
c198292fbf | ||
|
|
35d52088aa | ||
|
|
81e04e370a | ||
|
|
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 | ||
|
|
b94a1d98b7 | ||
|
|
746eec18ba | ||
|
|
44e056b5fe | ||
|
|
df1fefef5f | ||
|
|
df9b28c830 | ||
|
|
6ec0b175e4 | ||
|
|
e89a5d11a1 | ||
|
|
5bcd465ecc | ||
|
|
a6fdf3f774 | ||
|
|
b46db4cdfc | ||
|
|
b246ad8624 | ||
|
|
fb8bdcd895 | ||
|
|
7ef0df48dd | ||
|
|
50b579705e | ||
|
|
8551abfc5d | ||
|
|
bbd333426d | ||
|
|
74eb3e0d98 | ||
|
|
5f7e2a43f2 | ||
|
|
e98ae10267 | ||
|
|
07f60f974b | ||
|
|
7d29ed1ca9 | ||
|
|
f98079d431 | ||
|
|
192f88ede5 | ||
|
|
3c1366bd10 | ||
|
|
11dbcd0362 | ||
|
|
047d45f1cb | ||
|
|
95919a6602 | ||
|
|
19d1bfe1e3 | ||
|
|
e9da712882 | ||
|
|
804c5aba36 | ||
|
|
c5577b125f | ||
|
|
6100d17bd2 | ||
|
|
74a291bdd6 | ||
|
|
ba6765b1fb | ||
|
|
9fce3be6a8 | ||
|
|
9892fc35bc | ||
|
|
62a528d33b | ||
|
|
7c8610facb | ||
|
|
37617dbd54 | ||
|
|
569bd43163 | ||
|
|
fdb0036ea6 | ||
|
|
f9797f2dca | ||
|
|
ba75c58a23 | ||
|
|
3d799ae461 | ||
|
|
2501662737 | ||
|
|
d04d166e14 | ||
|
|
1576719d10 | ||
|
|
362af75b9a | ||
|
|
bef5d03494 | ||
|
|
80ebf77eb6 | ||
|
|
c4ed247a05 | ||
|
|
323786859e | ||
|
|
354bf937b2 | ||
|
|
39bb37f5c3 | ||
|
|
b198dc2e06 | ||
|
|
d83cd3dc32 | ||
|
|
90a2aad491 | ||
|
|
35583a4cdd | ||
|
|
d22952d83b | ||
|
|
57bf2c2fb7 | ||
|
|
5c0263198c |
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
package com.example.ueberwachungssystem.Detection;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
|
|
||||||
/** Detection Report Class */
|
|
||||||
public class DetectionReport {
|
|
||||||
public String timeStamp;
|
|
||||||
public String detectionType;
|
|
||||||
public float detectedValue;
|
|
||||||
public String detectorID;
|
|
||||||
|
|
||||||
public DetectionReport(String detectorID, String detectionType, float detectedAmplitude) {
|
|
||||||
this.timeStamp = String.valueOf(Calendar.getInstance().getTime());
|
|
||||||
this.detectionType = detectionType;
|
|
||||||
this.detectedValue = detectedAmplitude;
|
|
||||||
this.detectorID = detectorID;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Get Detection Report in String format */
|
|
||||||
public String toString() {
|
|
||||||
String time = "Time: " + "[" + this.timeStamp + "]";
|
|
||||||
String type = "Type: " + "[" + this.detectionType + "]";
|
|
||||||
String value = "Value: " + "[" + this.detectedValue + "]";
|
|
||||||
String id = "ID: " + "[" + this.detectorID + "]";
|
|
||||||
|
|
||||||
return String.join("\t", time, type, value, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Debug Report */
|
|
||||||
public void log(String tag) {
|
|
||||||
Log.d(tag, this.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.example.ueberwachungssystem.Detection;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
|
|
||||||
abstract public class Detector {
|
|
||||||
private OnDetectionListener listener;
|
|
||||||
|
|
||||||
/** Constructor - takes context of current activity */
|
|
||||||
public Detector(Context context) {};
|
|
||||||
|
|
||||||
|
|
||||||
/** On Detection Listener - runs when violation is reported */
|
|
||||||
public interface OnDetectionListener {
|
|
||||||
void onDetection(@NonNull DetectionReport detectionReport);
|
|
||||||
}
|
|
||||||
public void setOnDetectionListener(@NonNull OnDetectionListener listener) {
|
|
||||||
this.listener = listener;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Triggers onDetectionListener - call this to trigger violation/alarm */
|
|
||||||
public void reportViolation(String detectorID, String detectionType, float amplitude) {
|
|
||||||
if (listener != null) {
|
|
||||||
DetectionReport detectionReport = new DetectionReport(detectorID, detectionType, amplitude);
|
|
||||||
listener.onDetection(detectionReport);
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("No listener set for violation reporting");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Starts Detection (abstract method: needs to be overridden in child class) */
|
|
||||||
public abstract void startDetection();
|
|
||||||
|
|
||||||
/** Stops Detection (abstract method: needs to be overridden in child class) */
|
|
||||||
public abstract void stopDetection();
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.example.ueberwachungssystem.Fragments;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.VideoView;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.example.ueberwachungssystem.R;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class Fragment1 extends Fragment {
|
||||||
|
private String text;
|
||||||
|
private final static String KEY_TEXT = "KEY_TEXT";
|
||||||
|
private void log(String nachricht) {
|
||||||
|
Log.d(this.getClass().getSimpleName(), nachricht);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
||||||
|
log("onCreateView");
|
||||||
|
View view = inflater.inflate(R.layout.fragment1, container, false);
|
||||||
|
TextView Sensor = (TextView) view.findViewById(R.id.Alarm);
|
||||||
|
Sensor.setText(text);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
public static Fragment1 erstellen(String text) {
|
||||||
|
Fragment1 fragment = new Fragment1();
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putString(KEY_TEXT, text);
|
||||||
|
fragment.setArguments(b);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle bundle) {
|
||||||
|
super.onCreate(bundle);
|
||||||
|
Bundle args = getArguments();
|
||||||
|
if (args != null ) {
|
||||||
|
text = args.getString(KEY_TEXT);
|
||||||
|
log("onCreate: text=" + text);
|
||||||
|
} else {
|
||||||
|
log("onCreate");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.example.ueberwachungssystem.Fragments;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.example.ueberwachungssystem.MeinAdapter;
|
||||||
|
import com.example.ueberwachungssystem.R;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Fragment2 extends Fragment {
|
||||||
|
private String text;
|
||||||
|
private Context c;
|
||||||
|
private final static String KEY_TEXT = "KEY_TEXT" ;
|
||||||
|
private void log(String nachricht) {
|
||||||
|
Log.d(this.getClass().getSimpleName(), nachricht);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
||||||
|
log( "onCreateView" );
|
||||||
|
View view = inflater.inflate(R.layout.fragment2, container, false );
|
||||||
|
// TextView Sensor = (TextView) view.findViewById(R.id.Aufzeichnungen);
|
||||||
|
// Sensor.setText(text);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
public static Fragment2 erstellen(String text) {
|
||||||
|
Fragment2 fragment = new Fragment2();
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putString(KEY_TEXT, text);
|
||||||
|
fragment.setArguments(b);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle bundle) {
|
||||||
|
super.onCreate(bundle);
|
||||||
|
Bundle args = getArguments();
|
||||||
|
c = getContext();
|
||||||
|
ListView listView = new ListView(c);
|
||||||
|
setContentView(R.layout.fragment2);
|
||||||
|
listView.setAdapter(new MeinAdapter(c, getVideoFiles()));
|
||||||
|
if (args != null) {
|
||||||
|
text = args.getString(KEY_TEXT);
|
||||||
|
log("onCreate: text=" + text);
|
||||||
|
} else {
|
||||||
|
log("onCreate");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<File> getVideoFiles(){
|
||||||
|
File directory = c.getFilesDir();
|
||||||
|
File[] files = directory.listFiles();
|
||||||
|
assert files != null;
|
||||||
|
return Arrays.asList(files);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.example.ueberwachungssystem.Fragments;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.example.ueberwachungssystem.R;
|
||||||
|
|
||||||
|
public class Fragment3 extends Fragment {
|
||||||
|
private String text;
|
||||||
|
private final static String KEY_TEXT = "KEY_TEXT" ;
|
||||||
|
private void log(String nachricht) {
|
||||||
|
Log.d(this.getClass().getSimpleName(), nachricht);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
||||||
|
log( "onCreateView" );
|
||||||
|
View view = inflater.inflate(R.layout.fragment2, container, false );
|
||||||
|
TextView Sensor = (TextView) view.findViewById(R.id.Sensor);
|
||||||
|
Sensor.setText(text);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
public static Fragment3 erstellen(String text) {
|
||||||
|
Fragment3 fragment = new Fragment3();
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putString(KEY_TEXT, text);
|
||||||
|
fragment.setArguments(b);
|
||||||
|
return fragment;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle bundle) {
|
||||||
|
super.onCreate(bundle);
|
||||||
|
Bundle args = getArguments();
|
||||||
|
if (args != null) {
|
||||||
|
text = args.getString(KEY_TEXT);
|
||||||
|
log("onCreate: text=" + text);
|
||||||
|
} else {
|
||||||
|
log("onCreate");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.example.ueberwachungssystem.Logger;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
|
||||||
|
public class Logger {
|
||||||
|
private TextView textView;
|
||||||
|
private StringBuffer sb = new StringBuffer();
|
||||||
|
private String tag;
|
||||||
|
|
||||||
|
public Logger(String tag, TextView textView, String logInitText) {
|
||||||
|
this.tag = tag;
|
||||||
|
this.textView = textView;
|
||||||
|
sb.append(logInitText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void log(String s) {
|
||||||
|
Log.d(tag, s);
|
||||||
|
sb.append(s).append("\n");
|
||||||
|
if (textView != null) {
|
||||||
|
textView.setText(sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void log(Exception e) {
|
||||||
|
StringWriter sw = new StringWriter();
|
||||||
|
e.printStackTrace(new PrintWriter(sw));
|
||||||
|
log(sw.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearLog() {
|
||||||
|
sb.setLength(0);
|
||||||
|
if (textView != null) {
|
||||||
|
textView.setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLoggedText() {
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,72 +1,126 @@
|
|||||||
package com.example.ueberwachungssystem;
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.camera.core.ExperimentalGetImage;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.util.Log;
|
||||||
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.ToggleButton;
|
||||||
|
|
||||||
import com.example.ueberwachungssystem.Detection.Accelerometer;
|
import com.example.ueberwachungssystem.Fragments.Fragment1;
|
||||||
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
import com.example.ueberwachungssystem.Fragments.Fragment2;
|
||||||
import com.example.ueberwachungssystem.Detection.Detector;
|
|
||||||
|
|
||||||
|
@ExperimentalGetImage
|
||||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
//Fragmente
|
||||||
|
private Fragment aktuellesFragment;
|
||||||
|
private Fragment1 fragment1;
|
||||||
|
private Fragment2 fragment2;
|
||||||
|
|
||||||
private Accelerometer beschleunigungssensor;
|
//Textviews
|
||||||
private TextView textViewLog;
|
private TextView Auswahl;
|
||||||
private Button button1;
|
private TextView AoderA;
|
||||||
ToggleButton toggleButton1;
|
private String auswahltext = "Wahl des Detektionsmodus";
|
||||||
|
private String auswahlAoderA = "Wahl von Alarmmeldungen oder Auswahl von Alarmaufzeichnungen";
|
||||||
|
|
||||||
|
//Sensoren und Kommunikation
|
||||||
|
WifiCommunication communication;
|
||||||
|
//Buttons
|
||||||
|
private ToggleButton toggleKamera;
|
||||||
|
private ToggleButton toggleAudio;
|
||||||
|
private ToggleButton toggleBewegung;
|
||||||
|
|
||||||
|
//Überprüfungswerte
|
||||||
|
boolean wahr;
|
||||||
|
private void log(String nachricht) {
|
||||||
|
Log.d(this.getClass().getSimpleName(), nachricht);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setTitle(this.getClass().getSimpleName());
|
setTitle(this.getClass().getSimpleName());
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
Auswahl = findViewById(R.id.textAuswahl);
|
||||||
|
Auswahl.setText(auswahltext);
|
||||||
|
AoderA = findViewById(R.id.textAoderA);
|
||||||
|
AoderA.setText(auswahlAoderA);
|
||||||
|
toggleKamera = findViewById(R.id.toggleKamera);
|
||||||
|
toggleKamera.setOnClickListener(this);
|
||||||
|
toggleAudio = findViewById(R.id.toggleAudio);
|
||||||
|
toggleAudio.setOnClickListener(this);
|
||||||
|
toggleBewegung = findViewById(R.id.toggleBewegung);
|
||||||
|
toggleBewegung.setOnClickListener(this);
|
||||||
|
|
||||||
|
}
|
||||||
toggleButton1 = findViewById(R.id.toggleButton1); //togglebutton um Detektion zu steuern
|
@Override
|
||||||
toggleButton1.setOnClickListener(this);
|
public void onClick(View v) {
|
||||||
|
if (v == toggleKamera) {
|
||||||
//Button to clear Log while Debugging
|
if (toggleKamera.isChecked()) {
|
||||||
button1 = (Button) findViewById(R.id.button1);
|
wahr = true;
|
||||||
button1.setOnClickListener(this);
|
} else {
|
||||||
|
wahr = false;
|
||||||
//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) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
if (v == toggleAudio) {
|
||||||
|
if (toggleAudio.isChecked()) {
|
||||||
|
wahr = true;
|
||||||
|
} else {
|
||||||
|
wahr = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (v == toggleBewegung) {
|
||||||
|
if (toggleBewegung.isChecked()) {
|
||||||
|
wahr = true;
|
||||||
|
} else {
|
||||||
|
wahr = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
communication.stopCommunication();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
communication = new WifiCommunication(1234);
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
beschleunigungssensor.stopDetection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void onClickZeigeFragment1(View view) {
|
||||||
public void onClick(View v) {
|
Button button = (Button) view;
|
||||||
if(v == toggleButton1) {
|
log(button.getText() + " ausgewählt");
|
||||||
if (toggleButton1.isChecked()) {
|
zeigeFragment(fragment1.erstellen("Hier stehen dann die Alarme"));
|
||||||
beschleunigungssensor.startDetection();
|
}
|
||||||
|
|
||||||
} else {
|
public void onClickZeigeFragment2(View view) {
|
||||||
beschleunigungssensor.stopDetection();
|
Button button = (Button) view;
|
||||||
}
|
log(button.getText() + " ausgewählt");
|
||||||
} else if (v == button1) {
|
zeigeFragment(fragment2.erstellen("Hier stehen dann die Videos"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClickEntferneFragment(View view) {
|
||||||
|
entferneFragment();
|
||||||
|
}
|
||||||
|
private void zeigeFragment(Fragment fragment) {
|
||||||
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
|
ft.replace(R.id.frame, fragment);
|
||||||
|
ft.commit();
|
||||||
|
aktuellesFragment = fragment;
|
||||||
|
}
|
||||||
|
private void entferneFragment() {
|
||||||
|
if (aktuellesFragment != null) {
|
||||||
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||||
|
ft.remove(aktuellesFragment);
|
||||||
|
ft.commit();
|
||||||
|
aktuellesFragment = null ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MeinAdapter extends ArrayAdapter<File> {
|
||||||
|
private Context context;
|
||||||
|
private File[] files;
|
||||||
|
public MeinAdapter(Context context, List<File> listf) {
|
||||||
|
super(context, android.R.layout.simple_list_item_1, listf);
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(final int pos, View cv, ViewGroup vg) {
|
||||||
|
View v = super.getView(pos, cv, vg);
|
||||||
|
v.setOnClickListener( new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Log.d("DerLog","nicht null");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,36 @@
|
|||||||
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class VideoListAdapter extends ArrayAdapter<File> {
|
||||||
|
|
||||||
|
public VideoListAdapter(Context context, List<File> videoList) {
|
||||||
|
super(context, 0, videoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_video, parent, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
File videoFile = getItem(position);
|
||||||
|
|
||||||
|
ImageView thumbnailImageView = convertView.findViewById(R.id.imageViewThumbnail);
|
||||||
|
TextView titleTextView = convertView.findViewById(R.id.textViewTitle);
|
||||||
|
|
||||||
|
// Set tag to identify the clicked item
|
||||||
|
convertView.setTag(videoFile.getAbsolutePath());
|
||||||
|
|
||||||
|
return convertView;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
package com.example.ueberwachungssystem;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_checked="false" android:drawable="@color/redbright" />
|
||||||
|
<item android:state_checked="true" android:drawable="@color/greenbright" />
|
||||||
|
</selector>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -1,63 +1,129 @@
|
|||||||
<?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"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
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"
|
||||||
tools:context=".MainActivity">
|
android:background="#010C49"
|
||||||
|
android:visibility="visible"
|
||||||
|
tools:context="com.example.ueberwachungssystem.MainActivity"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textViewLog"
|
android:id="@+id/textAuswahl"
|
||||||
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:layout_alignParentTop="true"
|
||||||
android:layout_marginTop="60dp"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_marginEnd="32dp"
|
android:textSize="20sp"
|
||||||
android:maxLines="25"
|
android:textColor="@color/white"/>
|
||||||
android:scrollbars="vertical"
|
|
||||||
android:text="TextViewLoggerMain"
|
<TextView
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:id="@+id/textAoderA"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:layout_width="match_parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textViewWorkerThread"
|
android:layout_below="@+id/toggleAudio"
|
||||||
app:layout_constraintVertical_bias="0.0" />
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
android:textSize="20sp"
|
||||||
|
android:textColor="@color/white"/>
|
||||||
|
|
||||||
<ToggleButton
|
<ToggleButton
|
||||||
android:id="@+id/toggleButton1"
|
android:id="@+id/toggleKamera"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="161dp"
|
android:layout_alignBottom="@id/toggleAudio"
|
||||||
android:layout_marginTop="115dp"
|
android:layout_marginRight="30dp"
|
||||||
android:layout_marginEnd="162dp"
|
android:layout_toLeftOf="@id/toggleAudio"
|
||||||
android:text="ToggleButton"
|
android:textColor="@color/yellow"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:textOn="Kamera an"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:textOff="Kamera aus"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
android:background="@drawable/toggle_btn"/>
|
||||||
|
|
||||||
<TextView
|
<ToggleButton
|
||||||
android:id="@+id/textViewWorkerThread"
|
android:id="@+id/toggleAudio"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="32dp"
|
android:layout_below="@id/textAuswahl"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginTop="5dp"
|
||||||
android:text="textViewWorkerThreadTextView"
|
android:textColor="@color/yellow"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:textOn="Audio an"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:textOff="Audio aus"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/toggleButton1" />
|
android:background="@drawable/toggle_btn"/>
|
||||||
|
|
||||||
|
<ToggleButton
|
||||||
|
android:id="@+id/toggleBewegung"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@id/toggleAudio"
|
||||||
|
android:layout_marginLeft="30dp"
|
||||||
|
android:layout_toEndOf="@+id/toggleAudio"
|
||||||
|
android:layout_toRightOf="@id/toggleAudio"
|
||||||
|
android:textColor="@color/yellow"
|
||||||
|
android:textOn="Bewegung an"
|
||||||
|
android:textOff="Bewegung aus"
|
||||||
|
android:background="@drawable/toggle_btn"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button1"
|
android:id="@+id/btnAlarme"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="35dp"
|
android:layout_alignBottom="@+id/btnAufnahmen"
|
||||||
android:layout_marginTop="31dp"
|
android:layout_toLeftOf="@id/btnAufnahmen"
|
||||||
android:layout_marginEnd="282dp"
|
android:layout_marginRight="15dp"
|
||||||
android:layout_marginBottom="100dp"
|
android:theme="@style/Button.Green"
|
||||||
android:text="Clear Log"
|
android:onClick="onClickZeigeFragment1"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/textViewWorkerThread"
|
android:text="Alarme" />
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
<Button
|
||||||
|
android:id="@+id/btnAufnahmen"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/textAoderA"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginTop="15dp"
|
||||||
|
android:theme="@style/Button.Green"
|
||||||
|
android:onClick="onClickZeigeFragment2"
|
||||||
|
android:text="Aufnahmen" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnAnzeigeVerb"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@+id/btnAufnahmen"
|
||||||
|
android:layout_toRightOf="@id/btnAufnahmen"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:text="Anzeige verbergen"
|
||||||
|
android:onClick="onClickEntferneFragment"/>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/frame"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_below="@+id/btnAufnahmen"
|
||||||
|
android:layout_marginTop="25dp"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:background="@color/white">
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scrollView1"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_below="@id/btnAufnahmen"
|
||||||
|
android:layout_marginTop="25dp">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/Alarm"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@color/red"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
-->
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="@color/bluedark">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scrollView1"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="25dp">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/Alarm"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/yellow"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="@android:color/holo_blue_light" >
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id="@+id/scrollView2"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="250dp"
|
||||||
|
android:layout_marginTop="25dp">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical" >
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/Aufzeichnungen"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/yellow"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
<VideoView
|
||||||
|
android:id="@+id/AusAuf"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/scrollView2"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="@android:color/holo_blue_light" >
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/Sensor"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/Alarm"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/Sensor"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||||
|
|
||||||
|
</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>
|
||||||
@@ -7,4 +7,9 @@
|
|||||||
<color name="teal_700">#FF018786</color>
|
<color name="teal_700">#FF018786</color>
|
||||||
<color name="black">#FF000000</color>
|
<color name="black">#FF000000</color>
|
||||||
<color name="white">#FFFFFFFF</color>
|
<color name="white">#FFFFFFFF</color>
|
||||||
|
<color name="red">#5C0000</color>
|
||||||
|
<color name="redbright">#EF3434</color>
|
||||||
|
<color name="greenbright">#469733</color>
|
||||||
|
<color name="bluedark">#053C8E</color>
|
||||||
|
<color name="yellow">#FFEB3B</color>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -13,4 +13,9 @@
|
|||||||
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
|
||||||
<!-- Customize your theme here. -->
|
<!-- Customize your theme here. -->
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="Button.Green" parent="ThemeOverlay.AppCompat">
|
||||||
|
<item name="colorAccent">#0F3E01</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
#Thu May 11 15:04:30 CEST 2023
|
#Thu May 11 15:19:24 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-8.0-bin.zip
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
rootProject.name = "Ueberwachungssystem"
|
rootProject.name = "Ueberwachungssystem"
|
||||||
include ':app'
|
include ':app'
|
||||||
|
include ':app'
|
||||||
|
|||||||
Reference in New Issue
Block a user