Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44e056b5fe | ||
|
|
df1fefef5f | ||
|
|
df9b28c830 | ||
|
|
6ec0b175e4 | ||
|
|
5bcd465ecc | ||
|
|
a6fdf3f774 | ||
|
|
b46db4cdfc | ||
|
|
74eb3e0d98 | ||
|
|
5f7e2a43f2 | ||
|
|
07f60f974b | ||
|
|
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 | ||
|
|
57bf2c2fb7 | ||
|
|
5c0263198c |
@@ -36,4 +36,13 @@ dependencies {
|
|||||||
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'
|
||||||
|
|
||||||
|
// 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,32 @@
|
|||||||
<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">
|
||||||
|
|
||||||
|
<!-- <!– If your app targets Android 13 (API level 33)-->
|
||||||
|
<!-- or higher, you must declare the NEARBY_WIFI_DEVICES permission. –>-->
|
||||||
|
<!-- <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"-->
|
||||||
|
<!-- <!– If your app derives location information from Wi-Fi APIs,-->
|
||||||
|
<!-- don't include the "usesPermissionFlags" attribute. –>-->
|
||||||
|
<!-- android:usesPermissionFlags="neverForLocation" />-->
|
||||||
|
|
||||||
|
<uses-permission
|
||||||
|
android:required="true"
|
||||||
|
android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||||
|
<!-- If any feature in your app relies on precise location information,
|
||||||
|
don't include the "maxSdkVersion" attribute. -->
|
||||||
|
<uses-permission
|
||||||
|
android:required="true"
|
||||||
|
android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||||
|
<uses-permission
|
||||||
|
android:required="true"
|
||||||
|
android:name="android.permission.CHANGE_WIFI_STATE"/>
|
||||||
|
<uses-permission
|
||||||
|
android:required="true"
|
||||||
|
android:name="android.permission.INTERNET"/>
|
||||||
|
|
||||||
|
<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"
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.example.ueberwachungssystem.Detection;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
|
||||||
|
abstract public class Detector {
|
||||||
|
private OnDetectionListener listener;
|
||||||
|
|
||||||
|
/** Constructor - takes context of current activity */
|
||||||
|
public Detector() {}
|
||||||
|
|
||||||
|
|
||||||
|
/** 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,196 @@
|
|||||||
|
package com.example.ueberwachungssystem.Detection;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.ImageFormat;
|
||||||
|
import android.media.Image;
|
||||||
|
import android.util.Size;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.camera.core.CameraSelector;
|
||||||
|
import androidx.camera.core.ExperimentalGetImage;
|
||||||
|
import androidx.camera.core.ImageAnalysis;
|
||||||
|
import androidx.camera.core.Preview;
|
||||||
|
import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||||
|
import androidx.camera.view.PreviewView;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
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);
|
||||||
|
* vd.setPreview(previewView); //THIS IS OPTIONAL!
|
||||||
|
* vd.setOnDetectionListener(new Detector.OnDetectionListener{...});
|
||||||
|
* vd.startDetection();
|
||||||
|
* vd.stopDetection
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
|
||||||
|
|
||||||
|
@ExperimentalGetImage
|
||||||
|
public class VideoDetector extends Detector {
|
||||||
|
|
||||||
|
// Calling Activity
|
||||||
|
private final Context context;
|
||||||
|
// Camera Provider
|
||||||
|
private ProcessCameraProvider cameraProvider;
|
||||||
|
private Boolean isDetectionRunning = false;
|
||||||
|
// Preview Camera Image
|
||||||
|
private PreviewView previewView = null;
|
||||||
|
// Detect Violation
|
||||||
|
private static final float PIXEL_THRESHOLD = 30f; // Luminosity (brightness channel of YUV_420_888)
|
||||||
|
private static final float ALARM_THRESHOLD = 0.2f; // Percent of pixels changed
|
||||||
|
private ByteBuffer previousBuffer = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param context: the context of calling activity (usually "this")
|
||||||
|
* */
|
||||||
|
public VideoDetector(Context context) {
|
||||||
|
super();
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the Video Detection
|
||||||
|
* */
|
||||||
|
@Override
|
||||||
|
public void startDetection() {
|
||||||
|
if (isDetectionRunning)
|
||||||
|
return;
|
||||||
|
// Request Camera Provider
|
||||||
|
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(context);
|
||||||
|
//Check for Camera availability
|
||||||
|
cameraProviderFuture.addListener(() -> {
|
||||||
|
try {
|
||||||
|
cameraProvider = cameraProviderFuture.get();
|
||||||
|
bindAnalysis(cameraProvider);
|
||||||
|
isDetectionRunning = true;
|
||||||
|
previousBuffer = null;
|
||||||
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
|
// No errors need to be handled for this Future. This should never be reached.
|
||||||
|
}
|
||||||
|
},ContextCompat.getMainExecutor(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the Video Detection
|
||||||
|
* */
|
||||||
|
@Override
|
||||||
|
public void stopDetection() {
|
||||||
|
if (!isDetectionRunning)
|
||||||
|
return;
|
||||||
|
cameraProvider.unbindAll();
|
||||||
|
isDetectionRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set PreviewView to show video feed while detecting
|
||||||
|
* this is optional and does not need to be called
|
||||||
|
* */
|
||||||
|
public void setPreviewView(PreviewView previewView) {
|
||||||
|
this.previewView = previewView;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds the Luminosity Analyzer (configure and run Analysis)
|
||||||
|
* @param cameraProvider: CameraProvider of Context passed by Constructor
|
||||||
|
* */
|
||||||
|
private void bindAnalysis(@NonNull ProcessCameraProvider cameraProvider) {
|
||||||
|
// Configure and create Image Analysis
|
||||||
|
ImageAnalysis.Builder builder = new ImageAnalysis.Builder();
|
||||||
|
builder.setTargetResolution(new Size(640, 480));
|
||||||
|
builder.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST);
|
||||||
|
builder.setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888);
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Changed Pixel Detection
|
||||||
|
int pixelChanged = getChangedPixelCount(image);
|
||||||
|
int width = image.getWidth();
|
||||||
|
int height = image.getHeight();
|
||||||
|
|
||||||
|
float percentPixelChanged = (float) 100f * pixelChanged / (width * height);
|
||||||
|
|
||||||
|
if (percentPixelChanged > ALARM_THRESHOLD)
|
||||||
|
reportViolation("0", "Video", percentPixelChanged);
|
||||||
|
}
|
||||||
|
imageProxy.close();
|
||||||
|
});
|
||||||
|
// Create Preview
|
||||||
|
Preview preview = new Preview.Builder().build();
|
||||||
|
// Specify which Camera to use
|
||||||
|
CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build();
|
||||||
|
// Update PreviewView if set
|
||||||
|
if (previewView != null)
|
||||||
|
preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
||||||
|
|
||||||
|
cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, imageAnalysis, preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate Amount of Pixels changed using a threshold
|
||||||
|
* @param image
|
||||||
|
* */
|
||||||
|
private int getChangedPixelCount(Image image) {
|
||||||
|
Image.Plane[] planes = image.getPlanes();
|
||||||
|
ByteBuffer buffer = planes[0].getBuffer();
|
||||||
|
|
||||||
|
if (previousBuffer == null) {
|
||||||
|
previousBuffer = ByteBuffer.allocate(buffer.capacity());
|
||||||
|
buffer.rewind();
|
||||||
|
previousBuffer.put(buffer);
|
||||||
|
previousBuffer.rewind();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int width = image.getWidth();
|
||||||
|
int height = image.getHeight();
|
||||||
|
|
||||||
|
int yRowStride = image.getPlanes()[0].getRowStride();
|
||||||
|
int yPixelStride = image.getPlanes()[0].getPixelStride();
|
||||||
|
|
||||||
|
int changedPixelCount = 0;
|
||||||
|
|
||||||
|
// Count changed pixels
|
||||||
|
for (int y = 0; y < height; ++y) {
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
int index = (y * yRowStride) + (x * yPixelStride);
|
||||||
|
int luminosity = (buffer.get(index) & 0xff);
|
||||||
|
int previousLuminosity = (previousBuffer.get(index) & 0xff);
|
||||||
|
int diff = Math.abs(luminosity - previousLuminosity);
|
||||||
|
if (diff > PIXEL_THRESHOLD)
|
||||||
|
changedPixelCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset and copy Byte Buffer
|
||||||
|
buffer.rewind();
|
||||||
|
previousBuffer.rewind();
|
||||||
|
previousBuffer.put(buffer);
|
||||||
|
|
||||||
|
return changedPixelCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,14 +1,220 @@
|
|||||||
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.util.Log;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ScrollView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
||||||
|
import com.example.ueberwachungssystem.Detection.Detector;
|
||||||
|
import com.example.ueberwachungssystem.Detection.VideoDetector;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
|
@ExperimentalGetImage
|
||||||
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
|
private Fragment aktuellesFragment;
|
||||||
|
WifiCommunication communication;
|
||||||
|
private TextView alarm;
|
||||||
|
private String text = "Das ist ein Alarm des Sensors";
|
||||||
|
//Buttons
|
||||||
|
private ToggleButton toggleKamera;
|
||||||
|
private ToggleButton btnAudio;
|
||||||
|
private ToggleButton btnBewegung;
|
||||||
|
//Detektoren
|
||||||
|
VideoDetector vd = new VideoDetector(this);
|
||||||
|
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());
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
alarm = findViewById(R.id.Alarm);
|
||||||
|
alarm.setText(text);
|
||||||
|
toggleKamera = findViewById(R.id.toggleKamera);
|
||||||
|
toggleKamera.setOnClickListener(this);
|
||||||
|
vd.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
|
DetectionReport dr = detectionReport;
|
||||||
|
String drString = dr.toString();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//boolean isRunning = vd.isRunning();
|
||||||
|
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (v == toggleKamera) {
|
||||||
|
if (toggleKamera.isChecked()) {
|
||||||
|
vd.startDetection();
|
||||||
|
} else {
|
||||||
|
vd.stopDetection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
communication.stopCommunication();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
communication = new WifiCommunication(MainActivity.this, 1234);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClickZeigeFragment1(View view) {
|
||||||
|
Button button = (Button) view;
|
||||||
|
log(button.getText() + " ausgewählt");
|
||||||
|
zeigeFragment(Fragment1.erstellen("Fragment 1 wurde angeklickt"));
|
||||||
|
}
|
||||||
|
public void onClickZeigeFragment2(View view) {
|
||||||
|
Button button = (Button) view;
|
||||||
|
log(button.getText() + " ausgewählt");
|
||||||
|
zeigeFragment(Fragment2.erstellen("Fragment 2 wurde angeklickt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClickZeigeFragment3(View view) {
|
||||||
|
Button button = (Button) view;
|
||||||
|
log(button.getText() + " ausgewählt");
|
||||||
|
zeigeFragment(Fragment3.erstellen("Fragment 3 wurde angeklickt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
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 ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static 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.Sensor);
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static class Fragment2 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 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();
|
||||||
|
if (args != null) {
|
||||||
|
text = args.getString(KEY_TEXT);
|
||||||
|
log("onCreate: text=" + text);
|
||||||
|
} else {
|
||||||
|
log("onCreate");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static 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,131 @@
|
|||||||
|
package com.example.ueberwachungssystem;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
|
||||||
|
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;
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
public WifiCommunication(MainActivity mainActivity, 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);
|
||||||
|
}
|
||||||
|
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText("Communication running"));
|
||||||
|
}
|
||||||
|
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];
|
||||||
|
InetAddress fromAdress;
|
||||||
|
int fromPort;
|
||||||
|
DatagramPacket rxPacket = new DatagramPacket(receiveData, receiveData.length);
|
||||||
|
socket.receive(rxPacket);
|
||||||
|
fromAdress = rxPacket.getAddress();
|
||||||
|
fromPort = rxPacket.getPort();
|
||||||
|
rxString = new String(rxPacket.getData());
|
||||||
|
if(!previousRxString.equals(rxString)) {
|
||||||
|
rxStringBuffer.append(rxString).append("\n");
|
||||||
|
//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 = (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 < 500; i++) {
|
||||||
|
socket.send(txPacket);
|
||||||
|
/*try{
|
||||||
|
sleep(10);
|
||||||
|
}catch (InterruptedException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} 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,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,18 +1,123 @@
|
|||||||
<?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="@android:color/holo_green_dark"
|
||||||
|
android:visibility="visible"
|
||||||
|
tools:context="com.example.ueberwachungssystem.MainActivity"
|
||||||
|
tools:visibility="visible">
|
||||||
|
|
||||||
<TextView
|
<ToggleButton
|
||||||
|
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:text="Hello World!"
|
android:layout_alignBottom="@id/toggleAudio"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:layout_marginRight="15dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:layout_toStartOf="@+id/toggleAudio"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:layout_toLeftOf="@id/toggleAudio"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
android:text="Kamera" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
<ToggleButton
|
||||||
|
android:id="@+id/toggleAudio"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:text="Audio" />
|
||||||
|
|
||||||
|
<ToggleButton
|
||||||
|
android:id="@+id/toggleBewegung"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@id/toggleAudio"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_toEndOf="@+id/toggleAudio"
|
||||||
|
android:layout_toRightOf="@id/toggleAudio"
|
||||||
|
android:text="Bewegung" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnAudio"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@id/btnKamera"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:layout_toStartOf="@+id/btnKamera"
|
||||||
|
android:onClick="onClickZeigeFragment1"
|
||||||
|
android:text="Audio" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnKamera"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/toggleAudio"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:onClick="onClickZeigeFragment2"
|
||||||
|
android:text="Kamera" />
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnSensorWeg"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_below="@+id/btn1"
|
||||||
|
android:text="Entferne Sensordarstellung"
|
||||||
|
android:onClick="onClickEntferneFragment"/>
|
||||||
|
-->
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnBewegung"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@id/btnKamera"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:layout_toEndOf="@+id/btnKamera"
|
||||||
|
android:layout_toRightOf="@id/btnKamera"
|
||||||
|
android:onClick="onClickZeigeFragment3"
|
||||||
|
android:text="Bewegung" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnAufnahme"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/btnKamera"
|
||||||
|
android:layout_toLeftOf="@id/btnKamera"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:onClick="onClickEntferneFragment"
|
||||||
|
android:text="Aufnahme" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnWiedergabe"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/btnKamera"
|
||||||
|
android:layout_toRightOf="@id/btnKamera"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:onClick="onClickEntferneFragment"
|
||||||
|
android:text="Wiedergabe" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/frame"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="200dp"
|
||||||
|
android:layout_below="@+id/btnAufnahme"
|
||||||
|
android:layout_alignParentStart="true">
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:id= "@+id/scrollView1"
|
||||||
|
android:layout_width= "wrap_content"
|
||||||
|
android:layout_height= "wrap_content"
|
||||||
|
android:layout_below= "@id/frame">
|
||||||
|
<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" />
|
||||||
|
</LinearLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?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="@android:color/holo_green_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"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -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,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>
|
||||||
+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-7.5-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
|||||||
Reference in New Issue
Block a user