Compare commits
6
Commits
prepareMaster
...
copie2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be1e52a9b0 | ||
|
|
5b042611a5 | ||
|
|
5a0aab0176 | ||
|
|
5f1f127e62 | ||
|
|
35708220f8 | ||
|
|
415af15cb7 |
@@ -3,13 +3,17 @@ package com.example.ueberwachungssystem.Detection;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.camera.core.ExperimentalGetImage;
|
||||
import androidx.lifecycle.LifecycleService;
|
||||
|
||||
import com.example.ueberwachungssystem.WifiCommunication;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ExperimentalGetImage
|
||||
@@ -24,6 +28,10 @@ public class DetectorService extends LifecycleService {
|
||||
public Accelerometer motionDetector = null;
|
||||
public MicrophoneDetector audioDetector = null;
|
||||
|
||||
WifiCommunication wifiCommunication;
|
||||
|
||||
String dataFromWifi;
|
||||
StringBuffer stringBufferFromWifi;
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
@@ -31,6 +39,17 @@ public class DetectorService extends LifecycleService {
|
||||
return START_NOT_STICKY;
|
||||
|
||||
|
||||
/** Wifi Instanz Starten und Listener **/
|
||||
wifiCommunication = new WifiCommunication (1234);
|
||||
wifiCommunication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
|
||||
@Override
|
||||
public void onConnection(String data) {
|
||||
dataFromWifi = data;
|
||||
stringToStringbuffer(data);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/** Video Detection/Recorder **/
|
||||
@@ -38,7 +57,10 @@ public class DetectorService extends LifecycleService {
|
||||
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
passToServiceListener(detectionReport);
|
||||
//passToServiceListener(detectionReport);
|
||||
Log.d("Video", detectionReport.toMessage());
|
||||
wifiCommunication.sendTrue(detectionReport.toMessage());
|
||||
|
||||
}
|
||||
});
|
||||
/** Motion Detection**/
|
||||
@@ -47,7 +69,9 @@ public class DetectorService extends LifecycleService {
|
||||
motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
passToServiceListener(detectionReport);
|
||||
//passToServiceListener(detectionReport);
|
||||
Log.d("Motion", detectionReport.toMessage());
|
||||
wifiCommunication.sendTrue(detectionReport.toMessage());
|
||||
}
|
||||
});
|
||||
/** Audio Detection **/
|
||||
@@ -55,7 +79,9 @@ public class DetectorService extends LifecycleService {
|
||||
audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
passToServiceListener(detectionReport);
|
||||
//passToServiceListener(detectionReport);
|
||||
Log.d("Audio", detectionReport.toMessage());
|
||||
wifiCommunication.sendTrue(detectionReport.toMessage());
|
||||
}
|
||||
});
|
||||
/** Audio Recorder**/
|
||||
@@ -64,8 +90,6 @@ public class DetectorService extends LifecycleService {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
isServiceRunning = true;
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
@@ -92,18 +116,25 @@ public class DetectorService extends LifecycleService {
|
||||
|
||||
|
||||
/** Pass Detection Report to Service Detection Listener and trigger it */
|
||||
public void passToServiceListener(DetectionReport detectionReport) {
|
||||
public void passToServiceListener(StringBuffer stringBuffer) {
|
||||
if (listener != null) {
|
||||
listener.onDetection(detectionReport);
|
||||
listener.onDetection(stringBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** On Detection Listener - runs when violation is reported */
|
||||
public interface OnDetectionListener {
|
||||
void onDetection(@NonNull DetectionReport detectionReport);
|
||||
void onDetection(@NonNull StringBuffer stringBuffer);
|
||||
}
|
||||
public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/** string to stringbuffer **/
|
||||
public void stringToStringbuffer(String dataString){
|
||||
stringBufferFromWifi.append(dataString).append("\n");
|
||||
passToServiceListener(stringBufferFromWifi);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,98 +1,81 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.camera.core.ExperimentalGetImage;
|
||||
import androidx.camera.view.PreviewView;
|
||||
import static android.content.ContentValues.TAG;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import com.example.ueberwachungssystem.Detection.Accelerometer;
|
||||
import com.example.ueberwachungssystem.Detection.AudioRecorder;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.camera.core.ExperimentalGetImage;
|
||||
|
||||
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
||||
import com.example.ueberwachungssystem.Detection.Detector;
|
||||
import com.example.ueberwachungssystem.Detection.DetectorService;
|
||||
import com.example.ueberwachungssystem.Detection.MicrophoneDetector;
|
||||
import com.example.ueberwachungssystem.Detection.VideoDetector;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@ExperimentalGetImage
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
//WifiCommunication communication;
|
||||
PermissionRequest permission;
|
||||
boolean communicationRunning = true;
|
||||
TextView textview1;
|
||||
|
||||
private DetectorService detectorService = new DetectorService();
|
||||
ImageView inputImageView;
|
||||
ImageView outputImageView;
|
||||
ToggleButton toggleButton;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
||||
inputImageView = findViewById(R.id.inputImageView);
|
||||
outputImageView = findViewById(R.id.outputImageView);
|
||||
toggleButton = findViewById(R.id.toggleButton);
|
||||
|
||||
|
||||
PermissionHandler permissionHandler = new PermissionHandler(this);
|
||||
permissionHandler.getPermissions();
|
||||
if (permissionHandler.hasPermissions()) {
|
||||
|
||||
|
||||
Intent serviceIntent = new Intent(this, DetectorService.class);
|
||||
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
startService(serviceIntent);
|
||||
|
||||
|
||||
toggleButton.setOnClickListener(new View.OnClickListener() {
|
||||
ToggleButton button1 = findViewById(R.id.toggleButton);
|
||||
button1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (toggleButton.isChecked())
|
||||
{
|
||||
if(button1.isChecked()){
|
||||
if(detectorService != null){
|
||||
|
||||
detectorService.videoDetector.debugProcessing(inputImageView, outputImageView);
|
||||
detectorService.videoDetector.startDetection();
|
||||
|
||||
detectorService.audioDetector.startDetection();
|
||||
|
||||
detectorService.motionDetector.startDetection();
|
||||
|
||||
detectorService.audioRecorder.stopRecording();
|
||||
|
||||
detectorService.videoDetector.startRecording();
|
||||
}
|
||||
}
|
||||
else {
|
||||
}else{
|
||||
detectorService.videoDetector.stopDetection();
|
||||
|
||||
detectorService.audioDetector.stopDetection();
|
||||
|
||||
detectorService.motionDetector.stopDetection();
|
||||
|
||||
detectorService.audioRecorder.stopRecording();
|
||||
|
||||
detectorService.videoDetector.stopRecording();
|
||||
}
|
||||
}
|
||||
});
|
||||
//textview1 = findViewById(R.id.textView1);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Button button1 = findViewById(R.id.buttonSend);
|
||||
/*button1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
communication.sendTrue("Testmessage");
|
||||
}
|
||||
});*/
|
||||
}
|
||||
|
||||
private ServiceConnection serviceConnection = new ServiceConnection() {
|
||||
@@ -103,12 +86,73 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() {
|
||||
@Override
|
||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||
Log.d("onDetection", detectionReport.toMessage());
|
||||
public void onDetection(StringBuffer stringBuffer) {
|
||||
//textview für oli
|
||||
Log.d("Debugger", stringBuffer.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {}
|
||||
};
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
|
||||
}
|
||||
};
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
/*if (communicationRunning){
|
||||
communication = new WifiCommunication(1234);
|
||||
communication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
|
||||
@Override
|
||||
public void onConnection(String data) {
|
||||
//Log.d("Test", data.toString());
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
textview1.setText(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
communicationRunning = false;
|
||||
}*/
|
||||
permission = new PermissionRequest(MainActivity.this);
|
||||
permission.rechtePruefen();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
//communication.stopCommunication();
|
||||
}
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.options_menu, menu);
|
||||
return true;
|
||||
}
|
||||
/*public boolean onOptionsItemSelected(MenuItem item) {
|
||||
Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
|
||||
PopUpClass popUpClass;
|
||||
switch (item.getItemId()) {
|
||||
case R.id.Rechteverwaltung:
|
||||
popUpClass = new PopUpClass(MainActivity.this);
|
||||
popUpClass.showPopupWindow(textview1);
|
||||
popUpClass.RechtePrüfen();
|
||||
return true;
|
||||
case R.id.Sensoren:
|
||||
popUpClass = new PopUpClass(MainActivity.this);
|
||||
popUpClass.showPopupWindow(textview1);
|
||||
popUpClass.Sensoren();
|
||||
return true;
|
||||
case R.id.Impressum:
|
||||
popUpClass = new PopUpClass(MainActivity.this);
|
||||
popUpClass.showPopupWindow(textview1);
|
||||
popUpClass.Impressum();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,7 @@ public class PopUpClass {
|
||||
Button buttonEdit = popupView.findViewById(R.id.RechteAnfordern);
|
||||
buttonEdit.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
RechteAnfordern();
|
||||
public void onClick(View v) {RechteAnfordern();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.ueberwachungssystem;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -51,13 +52,13 @@ public class WifiCommunication {
|
||||
}
|
||||
|
||||
public interface OnConnectionListener {
|
||||
void onConnection(StringBuffer data);
|
||||
void onConnection(String data);
|
||||
}
|
||||
public void setOnConnectionListener(@NonNull OnConnectionListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void sendWifiData(StringBuffer wifiMessage) {
|
||||
public void sendWifiData(String wifiMessage) {
|
||||
if (listener != null) {
|
||||
listener.onConnection(wifiMessage);
|
||||
}
|
||||
@@ -77,9 +78,11 @@ public class WifiCommunication {
|
||||
socket.receive(rxPacket);
|
||||
rxString = new String(receiveData, 0, rxPacket.getLength());
|
||||
String[] splitrxString = rxString.split(",");
|
||||
Log.d("empfangen", rxString);
|
||||
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) {
|
||||
rxStringBuffer.append(rxString).append("\n");
|
||||
sendWifiData(rxStringBuffer);
|
||||
//rxStringBuffer.append(rxString).append("\n");
|
||||
sendWifiData(rxString);
|
||||
|
||||
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
|
||||
previousRxString = rxString;
|
||||
}
|
||||
@@ -99,17 +102,15 @@ public class WifiCommunication {
|
||||
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);
|
||||
String txString = (messageToSend);
|
||||
send_Data = txString.getBytes();
|
||||
|
||||
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port);
|
||||
|
||||
for(int i = 0; i < 300; i++) {
|
||||
for(int i = 0; i < 500; i++) {
|
||||
socket.send(txPacket);
|
||||
Log.d("senden", txPacket.getData().toString());
|
||||
}
|
||||
}
|
||||
} while (running);
|
||||
|
||||
Reference in New Issue
Block a user