Compare commits

...
Author SHA1 Message Date
siebenhaarmi76624 b667e70fef Kommunikationcopie Version 1.8 UDP Socket 2023-06-20 22:30:30 +02:00
siebenhaarmi76624 c198292fbf Merge remote-tracking branch 'origin/master' into Kommunikationcopie
# Conflicts:
#	app/src/main/AndroidManifest.xml
#	app/src/main/java/com/example/ueberwachungssystem/MainActivity.java
#	app/src/main/java/com/example/ueberwachungssystem/WifiCommunication.java
#	app/src/main/res/layout/activity_main.xml
2023-06-20 21:13:26 +02:00
siebenhaarmi76624 35d52088aa merge Kommunikationcopie Version 1.7 UDP Socket 2023-06-20 21:06:51 +02:00
siebenhaarmi76624 ee61f7042b Kommunikation Version 1.6 UDP Socket 2023-06-20 20:50:18 +02:00
siebenhaarmi76624 ab54b6d96a Kommunikation Version 1.5 UDP Socket 2023-06-20 20:47:53 +02:00
siebenhaarmi76624 a85fb1f5ca Kommunikation Version 1.5 UDP Socket 2023-06-20 20:33:46 +02:00
kohlerba68671 f8f1fd23fb Merge branch 'bk_video'
# Conflicts:
#	app/src/main/java/com/example/ueberwachungssystem/MainActivity.java
2023-06-20 15:34:24 +02:00
siebenhaarmi76624 e007ad1744 Kommunikation Version 1.4 UDP Socket 2023-06-20 15:22:27 +02:00
siebenhaarmi76624 292c3457fa Kommunikation Version 1.4 UDP Socket 2023-06-20 15:22:10 +02:00
siebenhaarmi76624 79c7c16d21 Kommunikation Version 1.4 UDP Socket 2023-06-20 15:19:29 +02:00
siebenhaarmi76624 0782bbdd04 merge Kommunikation Version 1.3 UDP Socket 2023-06-19 13:00:22 +02:00
siebenhaarmi76624 df9b28c830 merge Kommunikation Version 1.2 UDP Socket 2023-06-15 16:56:59 +02:00
siebenhaarmi76624 6ec0b175e4 merge Kommunikation Version 1.2 UDP Socket 2023-06-15 16:56:21 +02:00
siebenhaarmi76624 e89a5d11a1 Kommunikation Version 1.2 UDP Socket 2023-06-15 16:38:49 +02:00
siebenhaarmi76624 b246ad8624 Kommunikation Version 1.1 UDP Socket 2023-06-15 15:09:19 +02:00
siebenhaarmi76624 192f88ede5 Kommunikation Version 1 UDP Socket 2023-06-08 18:10:39 +02:00
siebenhaarmi76624 3c1366bd10 Kommunikation Version 1 UDP Socket 2023-06-08 17:59:47 +02:00
kohlerba68671 11dbcd0362 Merge branch 'bk_video' of siebenhaarmi76624/MDT5_1_Ueberwachungssystem_G1 into master 2023-06-02 15:51:55 +00:00
siebenhaarmi76624 35583a4cdd Merge branch 'test' of siebenhaarmi76624/MDT5_1_Ueberwachungssystem_G1 into ms 2023-05-11 13:39:00 +00:00
siebenhaarmi76624 d22952d83b Initial commit Project Version 0 2023-05-11 15:38:14 +02:00
11 changed files with 450 additions and 63 deletions
+4
View File
@@ -26,6 +26,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
@@ -33,6 +36,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.gms:play-services-nearby:18.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
+4
View File
@@ -6,6 +6,10 @@
<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
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
@@ -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
@@ -21,6 +25,11 @@ public class DetectorService extends LifecycleService {
VideoDetector videoDetector = null;
AudioRecorder audioRecorder = null;
/** Communication **/
WifiCommunication wifiCommunication;
StringBuffer dataFromWifi;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
@@ -42,9 +51,16 @@ public class DetectorService extends LifecycleService {
isServiceRunning = true;
wifiCommunication = new WifiCommunication (1234);
wifiCommunication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
@Override
public void onConnection(StringBuffer data) {
dataFromWifi = data;
}
});
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
@@ -140,8 +156,6 @@ public class DetectorService extends LifecycleService {
}
/** pass Detection Report to Service Detection Listener and trigger it */
public void passToServiceListener(DetectionReport detectionReport) {
if (listener != null) {
@@ -1,79 +1,113 @@
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.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
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.ToggleButton;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.example.ueberwachungssystem.Detection.AudioRecorder;
import com.example.ueberwachungssystem.Detection.DetectionReport;
import com.example.ueberwachungssystem.Detection.Detector;
import com.example.ueberwachungssystem.Detection.VideoDetector;
import androidx.appcompat.app.AppCompatActivity;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@ExperimentalGetImage
@SuppressLint("SetTextI18n")
public class MainActivity extends AppCompatActivity {
WifiCommunication communication;
PermissionRequest permission;
boolean communicationRunning = true;
String dataRecieved;
TextView textview1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview1 = findViewById(R.id.textView1);
ImageView inputImageView = findViewById(R.id.inputImageView);
ImageView outputImageView = findViewById(R.id.outputImageView);
PreviewView previewView = findViewById(R.id.previewView);
PermissionHandler permissionHandler = new PermissionHandler(this);
permissionHandler.getPermissions();
if (permissionHandler.hasPermissions()) {
AudioRecorder audioRecorder = new AudioRecorder(this);
VideoDetector vd = new VideoDetector(this);
//vd.setPreviewView(previewView);
vd.debugProcessing(inputImageView, outputImageView);
vd.setOnDetectionListener(new Detector.OnDetectionListener() {
@Override
public void onDetection(@NonNull DetectionReport detectionReport) {
Log.d("onDetection", detectionReport.toString());
}
});
vd.startDetection();
ToggleButton toggleButton = findViewById(R.id.toggleButton);
toggleButton.setOnClickListener(new View.OnClickListener() {
Button button1 = findViewById(R.id.buttonSend);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (toggleButton.isChecked())
{
//vd.startDetection();
//vd.stopDetection();
vd.startRecording();
audioRecorder.startRecording();
}
else {
//vd.stopDetection();
vd.stopRecording();
audioRecorder.stopRecording();
}
communication.sendTrue("Testmessage");
}
});
}
@Override
protected void onResume() {
super.onResume();
if (communicationRunning){
communication = new WifiCommunication(1234);
communication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
@Override
public void onConnection(StringBuffer data) {
//Log.d("Test", data.toString());
runOnUiThread(new Runnable() {
@Override
public void run() {
textview1.setText(data);
}
});
}
});
communicationRunning = false;
}
permission = new PermissionRequest(MainActivity.this);
permission.rechtePruefen();
}
@Override
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(tvMessages);
popUpClass.RechtePrüfen();
return true;
case R.id.Sensoren:
popUpClass = new PopUpClass(MainActivity.this);
//popUpClass.showPopupWindow(tvMessages);
popUpClass.Sensoren();
return true;
case R.id.Impressum:
popUpClass = new PopUpClass(MainActivity.this);
//popUpClass.showPopupWindow(tvMessages);
popUpClass.Impressum();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private String getLocalIpAddress() throws UnknownHostException {
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
assert wifiManager != null;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipInt = wifiInfo.getIpAddress();
return InetAddress.getByAddress(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(ipInt).array()).getHostAddress();
}
}
@@ -0,0 +1,48 @@
package com.example.ueberwachungssystem;
import static android.Manifest.permission.INTERNET;
import static android.Manifest.permission.CAMERA;
import static android.Manifest.permission.RECORD_AUDIO;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
public class PermissionRequest extends AppCompatActivity{
private static final int PERMISSION_REQUEST_CODE = 123;
private final MainActivity mainActivity;
Handler handler = new Handler();
public PermissionRequest(MainActivity mainActivity) {
this.mainActivity = mainActivity;
}
public StringBuilder rechtePruefen() {
boolean rechtKamera = ContextCompat.checkSelfPermission(mainActivity, CAMERA) == PackageManager.PERMISSION_GRANTED;
boolean rechtMikrofon = ContextCompat.checkSelfPermission(mainActivity, RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
boolean rechtInternet = ContextCompat.checkSelfPermission(mainActivity, INTERNET) == PackageManager.PERMISSION_GRANTED;
StringBuilder sb = new StringBuilder();
sb.append("Rechte prüfen:")
.append("\nKamera: ").append(rechtKamera)
.append("\nMikrofon: ").append(rechtMikrofon)
.append("\nInternet: ").append(rechtInternet);
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(sb));
if (!(rechtKamera && rechtMikrofon && rechtInternet)){
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mainActivity.getApplicationContext(),"Es werden Rechte benötigt", Toast.LENGTH_LONG).show();
}
});
}
return sb;
}
public void rechteAnfordern() {
mainActivity.requestPermissions(new String[]{CAMERA, RECORD_AUDIO, INTERNET}, PERMISSION_REQUEST_CODE);
}
}
@@ -0,0 +1,86 @@
package com.example.ueberwachungssystem;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
public class PopUpClass {
private final MainActivity mainActivity;
PermissionRequest permission;
TextView PopUpText;
public PopUpClass(MainActivity mainActivity) {
this.mainActivity = mainActivity;
permission = new PermissionRequest(mainActivity);
}
//PopupWindow display method
public void showPopupWindow(final View view) {
//Create a View object yourself through inflater
LayoutInflater inflater = (LayoutInflater) view.getContext().getSystemService(view.getContext().LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.popup_window, null);
//Specify the length and width through constants
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;
//Make Inactive Items Outside Of PopupWindow
boolean focusable = true;
//Create a window with our parameters
final PopupWindow popupWindow = new PopupWindow(popupView,width*1, height*1, focusable);
//Set the location of the window on the screen
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
//Initialize the elements of our window, install the handler
PopUpText = popupView.findViewById(R.id.titleText);
Button buttonEdit = popupView.findViewById(R.id.RechteAnfordern);
buttonEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RechteAnfordern();
}
});
//Handler for clicking on the inactive zone of the window
popupView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//Close the window when clicked
popupWindow.dismiss();
return true;
}
});
}
public void RechtePrüfen(){
StringBuilder Text = permission.rechtePruefen();
PopUpText.setText(Text);
}
public void RechteAnfordern(){
permission.rechteAnfordern();
StringBuilder Text = permission.rechtePruefen();
PopUpText.setText(Text);
}
public void Sensoren(){
PopUpText.setText("Es können 3 verschiedene Sensoren verwendet werden \n -1. Beschleunigungssensor\n -2. Mikrofon\n -3. Kamera");
}
public void Impressum(){
PopUpText.setText("Die Ueberwachungsapp wurde im Rahmen eines Praktikums der TH-Nürnberg programmiert");
}
}
@@ -0,0 +1,146 @@
package com.example.ueberwachungssystem;
import android.annotation.SuppressLint;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.example.ueberwachungssystem.Detection.DetectionReport;
import com.example.ueberwachungssystem.Detection.Detector;
import com.example.ueberwachungssystem.Detection.DetectorService;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
public class WifiCommunication {
//private final MainActivity mainActivity;
private final InetAddress address;
private final int port;
private String messageToSend;
volatile private boolean send;
private final DatagramSocket socket;
volatile private boolean running;
private OnConnectionListener listener;
@SuppressLint("SetTextI18n")
public WifiCommunication(int port) {
//this.mainActivity = mainActivity;
this.port = port;
try {
socket = new DatagramSocket(this.port);
socket.setBroadcast(true);
address = InetAddress.getByName("255.255.255.255"); //100.82.255.255
running = true;
send = false;
new ReceiveThread().start();
new SendThread().start();
} catch (SocketException | UnknownHostException e) {
throw new RuntimeException(e);
}
//Toast.makeText(mainActivity.getApplicationContext(),"Communication running", Toast.LENGTH_SHORT).show();
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText("Communication running"));
}
public interface OnConnectionListener {
void onConnection(StringBuffer data);
}
public void setOnConnectionListener(@NonNull OnConnectionListener listener) {
this.listener = listener;
}
public void sendWifiData(StringBuffer wifiMessage) {
if (listener != null) {
listener.onConnection(wifiMessage);
}
}
private class ReceiveThread extends Thread {
private StringBuffer rxStringBuffer = new StringBuffer();
private String rxString="";
private String previousRxString = "";
@Override
public void run() {
try {
do {
byte[] receiveData = new byte[512];
DatagramPacket rxPacket = new DatagramPacket(receiveData, receiveData.length);
socket.receive(rxPacket);
rxString = new String(receiveData, 0, rxPacket.getLength());
String[] splitrxString = rxString.split(",");
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) {
rxStringBuffer.append(rxString).append("\n");
sendWifiData(rxStringBuffer);
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
previousRxString = rxString;
}
} while (running);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
private class SendThread extends Thread {
private int tmpCnt = 0;
@Override
public void run() {
try {
do {
if(send)
{
send = false;
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date curDate = new Date(System.currentTimeMillis());
String str = formatter.format(curDate);
byte[] send_Data = new byte[512];
String txString = ("1," +str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video," +messageToSend);
send_Data = txString.getBytes();
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port);
for(int i = 0; i < 300; i++) {
socket.send(txPacket);
}
}
} while (running);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface networkInterface = (NetworkInterface) ((Enumeration<?>) en).nextElement();
for (Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements();) {
InetAddress inetAddress = addresses.nextElement();
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
return inetAddress.getHostAddress();
}
}
}
} catch (SocketException ex) {
ex.printStackTrace();
}
return null;
}
public void sendTrue(String message){
send = true;
messageToSend = message;
}
public void stopCommunication() {
running = false;
socket.close();
}
}
+12
View File
@@ -38,4 +38,16 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="@+id/buttonSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
+29
View File
@@ -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>
+9
View File
@@ -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>
+1
View File
@@ -14,3 +14,4 @@ dependencyResolutionManagement {
}
rootProject.name = "Ueberwachungssystem"
include ':app'
include ':app'