|
|
|
|
|
|
|
|
package com.example.ueberwachungssystem; |
|
|
package com.example.ueberwachungssystem; |
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint; |
|
|
import android.annotation.SuppressLint; |
|
|
|
|
|
import android.content.DialogInterface; |
|
|
|
|
|
import android.content.pm.PackageManager; |
|
|
import android.net.wifi.WifiInfo; |
|
|
import android.net.wifi.WifiInfo; |
|
|
import android.net.wifi.WifiManager; |
|
|
import android.net.wifi.WifiManager; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
|
|
|
|
|
|
import android.widget.Button; |
|
|
import android.widget.Button; |
|
|
import android.widget.TextView; |
|
|
import android.widget.TextView; |
|
|
import android.widget.Toast; |
|
|
import android.widget.Toast; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog; |
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
import java.net.InetAddress; |
|
|
import java.net.InetAddress; |
|
|
import java.net.UnknownHostException; |
|
|
import java.net.UnknownHostException; |
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity { |
|
|
public class MainActivity extends AppCompatActivity { |
|
|
TextView tvMessages; |
|
|
TextView tvMessages; |
|
|
TextView tvConnectionInfos; |
|
|
TextView tvConnectionInfos; |
|
|
|
|
|
|
|
|
WifiCommunication communication; |
|
|
WifiCommunication communication; |
|
|
PermissionRequest permission; |
|
|
PermissionRequest permission; |
|
|
public static String SERVER_IP = ""; |
|
|
public static String SERVER_IP = ""; |
|
|
public static final int SERVER_PORT = 1234; |
|
|
public static final int SERVER_PORT = 1234; |
|
|
|
|
|
//private static final int PERMISSION_REQUEST_CODE = 123; |
|
|
float i=0; |
|
|
float i=0; |
|
|
|
|
|
|
|
|
|
|
|
boolean communicationRunning = false; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
super.onCreate(savedInstanceState); |
|
|
super.onCreate(savedInstanceState); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*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) { |
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
getMenuInflater().inflate(R.menu.options_menu, menu); |
|
|
getMenuInflater().inflate(R.menu.options_menu, menu); |
|
|
return true; |
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void onResume() { |
|
|
protected void onResume() { |
|
|
super.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 = new PermissionRequest(MainActivity.this); |
|
|
permission.rechtePruefen(); |
|
|
permission.rechtePruefen(); |
|
|
} |
|
|
} |