|
|
@@ -1,5 +1,8 @@ |
|
|
|
package com.example.ueberwachungssystem; |
|
|
|
|
|
|
|
import android.annotation.SuppressLint; |
|
|
|
import android.content.DialogInterface; |
|
|
|
import android.content.pm.PackageManager; |
|
|
|
import android.net.wifi.WifiInfo; |
|
|
|
import android.net.wifi.WifiManager; |
|
|
|
import android.os.Bundle; |
|
|
@@ -9,6 +12,8 @@ import android.view.View; |
|
|
|
import android.widget.Button; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
import java.net.InetAddress; |
|
|
|
import java.net.UnknownHostException; |
|
|
@@ -19,13 +24,15 @@ import java.nio.ByteOrder; |
|
|
|
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); |
|
|
@@ -47,6 +54,59 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/*public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { |
|
|
|
if (requestCode == PERMISSION_REQUEST_CODE && grantResults.length > 0) { |
|
|
|
boolean rechtKamera = grantResults[0] == PackageManager.PERMISSION_GRANTED; |
|
|
|
boolean rechtMikrofon = grantResults[1] == PackageManager.PERMISSION_GRANTED; |
|
|
|
boolean rechtInternet = grantResults[2] == PackageManager.PERMISSION_GRANTED; |
|
|
|
|
|
|
|
if (rechtKamera && rechtMikrofon && rechtInternet) { |
|
|
|
|
|
|
|
Toast.makeText(getApplicationContext(), "Alle benötigten Rechte sind gewährt.", Toast.LENGTH_LONG).show(); |
|
|
|
|
|
|
|
|
|
|
|
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText("Alle benötigten Rechte sind gewährt")); |
|
|
|
} |
|
|
|
else { |
|
|
|
if (!rechtKamera) { |
|
|
|
Toast.makeText(getApplicationContext(),"Kein Recht auf Kamera gewährt.", Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
|
|
if (shouldShowRequestPermissionRationale(CAMERA)) { |
|
|
|
zeigeDialog("Du musst uns Zugriff auf deine Kamera gestatten, damit deine Umgebung Ueberwacht werden kann."); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!rechtMikrofon) { |
|
|
|
Toast.makeText(getApplicationContext(),"Kein Recht auf Mikrofon gewährt.", Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
|
|
if (shouldShowRequestPermissionRationale(RECORD_AUDIO)) { |
|
|
|
zeigeDialog("Du musst uns Zugriff auf dein Mikrofon gestatten, damit die Geraeuschueberwachung funktioniert."); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!rechtInternet) { |
|
|
|
Toast.makeText(getApplicationContext(),"Kein Recht auf Internet.", Toast.LENGTH_SHORT).show(); |
|
|
|
|
|
|
|
if (shouldShowRequestPermissionRationale(INTERNET)) { |
|
|
|
zeigeDialog("Du musst uns Zugriff auf dein Internet gestatten, damit wir eine Verbindung aufbauen können."); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
|
|
|
} |
|
|
|
private void zeigeDialog(String begruendung) { |
|
|
|
new AlertDialog.Builder(this) |
|
|
|
.setMessage(begruendung) |
|
|
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
requestPermissions(new String[]{CAMERA, RECORD_AUDIO, INTERNET}, PERMISSION_REQUEST_CODE); |
|
|
|
} |
|
|
|
}) |
|
|
|
.setNegativeButton("Abbruch", null) |
|
|
|
.create() |
|
|
|
.show(); |
|
|
|
}*/ |
|
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
|
getMenuInflater().inflate(R.menu.options_menu, menu); |
|
|
|
return true; |
|
|
@@ -77,7 +137,10 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
protected void onResume() { |
|
|
|
super.onResume(); |
|
|
|
communication = new WifiCommunication(MainActivity.this, SERVER_PORT); |
|
|
|
if (!communicationRunning){ |
|
|
|
communication = new WifiCommunication(MainActivity.this, SERVER_PORT); |
|
|
|
communicationRunning = true; |
|
|
|
} |
|
|
|
permission = new PermissionRequest(MainActivity.this); |
|
|
|
permission.rechtePruefen(); |
|
|
|
} |