Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f7e2a43f2 | ||
|
|
07f60f974b | ||
|
|
57bf2c2fb7 | ||
|
|
5c0263198c |
No files matched your search
+4
-7
@@ -3,11 +3,11 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace 'com.example.ueberwachungssystem'
|
namespace 'de.oklein.android.ueberwachungssystem'
|
||||||
compileSdk 33
|
compileSdk 33
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.example.ueberwachungssystem"
|
applicationId "de.oklein.android.ueberwachungssystem"
|
||||||
minSdk 28
|
minSdk 28
|
||||||
targetSdk 33
|
targetSdk 33
|
||||||
versionCode 1
|
versionCode 1
|
||||||
@@ -26,18 +26,15 @@ 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 {
|
||||||
|
|
||||||
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.9.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'
|
||||||
|
implementation "androidx.startup:startup-runtime:1.1.1"
|
||||||
}
|
}
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package com.example.ueberwachungssystem;
|
package de.oklein.android.ueberwachungssystem;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
@@ -21,6 +21,6 @@ public class ExampleInstrumentedTest {
|
|||||||
public void useAppContext() {
|
public void useAppContext() {
|
||||||
// Context of the app under test.
|
// Context of the app under test.
|
||||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
assertEquals("com.example.ueberwachungssystem", appContext.getPackageName());
|
assertEquals("de.oklein.android.ueberwachungssystem", appContext.getPackageName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,11 +2,27 @@
|
|||||||
<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-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<!-- <!– If your app targets Android 13 (API level 33)-->
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<!-- or higher, you must declare the NEARBY_WIFI_DEVICES permission. –>-->
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<!-- <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES"-->
|
||||||
<uses-permission android:name="android.permission.CAMERA" /> <!-- §permissionCamera§ -->
|
<!-- <!– If your app derives location information from Wi-Fi APIs,-->
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<!-- 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"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -14,14 +30,12 @@
|
|||||||
android:fullBackupContent="@xml/backup_rules"
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.Ueberwachungssystem"
|
android:theme="@style/Theme.Ueberwachungssystem"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true">
|
||||||
android:label="Ueberwachungsapp">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
package com.example.ueberwachungssystem;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.net.wifi.WifiInfo;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
|
||||||
TextView tvMessages;
|
|
||||||
TextView tvConnectionInfos;
|
|
||||||
WifiCommunication communication;
|
|
||||||
PermissionRequest permission;
|
|
||||||
public static String SERVER_IP = "";
|
|
||||||
public static final int SERVER_PORT = 1234;
|
|
||||||
//private static final int PERMISSION_REQUEST_CODE = 123;
|
|
||||||
float i=0;
|
|
||||||
|
|
||||||
boolean communicationRunning = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_main);
|
|
||||||
tvMessages = findViewById(R.id.tvMessages);
|
|
||||||
tvConnectionInfos = findViewById(R.id.tvConnectionInfos);
|
|
||||||
try {
|
|
||||||
SERVER_IP = getLocalIpAddress();
|
|
||||||
tvConnectionInfos.setText("Connection Infos: \n Own IP-Adress: " + SERVER_IP+ " Port: " + SERVER_PORT);
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Button btnSend = findViewById(R.id.btnSend);
|
|
||||||
btnSend.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
i++;
|
|
||||||
communication.sendTrue(String.valueOf(i));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
if (!communicationRunning){
|
|
||||||
communication = new WifiCommunication(MainActivity.this, SERVER_PORT);
|
|
||||||
communicationRunning = true;
|
|
||||||
}
|
|
||||||
permission = new PermissionRequest(MainActivity.this);
|
|
||||||
permission.rechtePruefen();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
communication.stopCommunication();
|
|
||||||
}
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
package com.example.ueberwachungssystem;
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
Toast.makeText(mainActivity.getApplicationContext(),"Communication running", Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
//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];
|
|
||||||
DatagramPacket rxPacket = new DatagramPacket(receiveData, receiveData.length);
|
|
||||||
socket.receive(rxPacket);
|
|
||||||
rxString = new String(rxPacket.getData());
|
|
||||||
String[] splitrxString = rxString.split(",");
|
|
||||||
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) {
|
|
||||||
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 = ("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 < 500; 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,44 @@
|
|||||||
|
package de.oklein.android.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
package de.oklein.android.ueberwachungssystem;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
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.TextView;
|
||||||
|
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
private Fragment aktuellesFragment;
|
||||||
|
private void log(String nachricht) {
|
||||||
|
Log.d(this.getClass().getSimpleName(), nachricht);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setTitle(this.getClass().getSimpleName());
|
||||||
|
setContentView(R.layout.activity_main);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
TextView Alarm = (TextView) view.findViewById(R.id.Alarm);
|
||||||
|
Alarm.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);
|
||||||
|
TextView Alarm = (TextView) view.findViewById(R.id.Alarm);
|
||||||
|
Alarm.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);
|
||||||
|
TextView Alarm = (TextView) view.findViewById(R.id.Alarm);
|
||||||
|
Alarm.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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,37 +1,70 @@
|
|||||||
<?xml version = "1.0" encoding = "utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools = "http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width = "match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height = "match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_margin = "16dp"
|
tools:context="de.oklein.android.ueberwachungssystem.MainActivity"
|
||||||
tools:context = ".MainActivity">
|
android:background="@android:color/holo_orange_light">
|
||||||
<TextView
|
|
||||||
android:id = "@+id/tvConnectionInfos"
|
|
||||||
android:layout_width = "match_parent"
|
|
||||||
android:layout_height = "wrap_content"
|
|
||||||
android:inputType = "textMultiLine"
|
|
||||||
android:hint="ConnectionInfos"
|
|
||||||
android:textAppearance = "@style/Base.TextAppearance.AppCompat.Medium" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btnSend"
|
android:id="@+id/btn1"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@id/scrollView"
|
android:layout_alignBottom="@id/btn2"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_toLeftOf="@id/btn2"
|
||||||
android:text="SEND" />
|
android:text="Audio"
|
||||||
|
android:onClick="onClickZeigeFragment1"/>
|
||||||
|
|
||||||
<ScrollView
|
<Button
|
||||||
android:id="@+id/scrollView"
|
android:id="@+id/btn2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:text="Kamera"
|
||||||
|
android:onClick="onClickZeigeFragment2"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn3"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBottom="@id/btn2"
|
||||||
|
android:layout_toRightOf="@id/btn2"
|
||||||
|
android:text="Bewegung"
|
||||||
|
android:onClick="onClickZeigeFragment3"/>
|
||||||
|
|
||||||
|
<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/btnAufnahme"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@+id/btnSensorWeg"
|
||||||
|
android:text="Aufnahme"
|
||||||
|
android:onClick="onClickEntferneFragment"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnWiedergabe"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_toRightOf="@id/btnAufnahme"
|
||||||
|
android:layout_below="@+id/btnSensorWeg"
|
||||||
|
android:text="Wiedergabe"
|
||||||
|
android:onClick="onClickEntferneFragment"/>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/frame"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_below="@id/tvConnectionInfos"
|
android:layout_height="match_parent"
|
||||||
android:layout_height="300dp">
|
android:layout_alignParentStart="true"
|
||||||
<TextView
|
android:layout_below="@+id/btnAufnahme">
|
||||||
android:id = "@+id/tvMessages"
|
</FrameLayout>
|
||||||
android:layout_width = "match_parent"
|
|
||||||
android:layout_height = "wrap_content"
|
</RelativeLayout>
|
||||||
android:hint="Messages"
|
|
||||||
android:inputType = "textMultiLine"
|
|
||||||
android:textAppearance = "@style/Base.TextAppearance.AppCompat.Medium" />
|
|
||||||
</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,29 +0,0 @@
|
|||||||
<?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>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<?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
-1
@@ -1,4 +1,4 @@
|
|||||||
package com.example.ueberwachungssystem;
|
package de.oklein.android.ueberwachungssystem;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
+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
|
||||||
|
|||||||
@@ -14,4 +14,3 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
rootProject.name = "Ueberwachungssystem"
|
rootProject.name = "Ueberwachungssystem"
|
||||||
include ':app'
|
include ':app'
|
||||||
include ':app'
|
|
||||||
Reference in new issue
Block a user