Browse Source

Kommunikation Version 1.4 UDP Socket

Kommunikation
Miguel Siebenhaar 11 months ago
parent
commit
e007ad1744

+ 127
- 0
app/src/main/java/com/example/ueberwachungssystem/PermissionRequest.java View File

@@ -0,0 +1,127 @@
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.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
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;

boolean prüfen= false;

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() {
/*handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mainActivity.getApplicationContext(),"Fordere Rechte an", Toast.LENGTH_LONG).show();
}
});*/
mainActivity.requestPermissions(new String[]{CAMERA, RECORD_AUDIO, INTERNET}, PERMISSION_REQUEST_CODE);
}

@Override
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)
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mainActivity.getApplicationContext(),"Alle benötigten Rechte sind gewährt.", Toast.LENGTH_LONG).show();
}
});
else {
if (!rechtKamera) {
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mainActivity.getApplicationContext(),"Kein Recht auf Kamera gewährt.", Toast.LENGTH_SHORT).show();
}
});
if (shouldShowRequestPermissionRationale(CAMERA)) {
zeigeDialog("Du musst uns Zugriff auf deine Kamera gestatten, damit wir dich besser sehen können.");
}
}
if (!rechtMikrofon) {
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mainActivity.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 wir dich besser hören können.");
}
}
if (!rechtInternet) {
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(mainActivity.getApplicationContext(),"Kein Recht auf Ortung gewährt.", 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(mainActivity.getApplicationContext())
.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();
}
}

+ 86
- 0
app/src/main/java/com/example/ueberwachungssystem/PopUpClass.java View File

@@ -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");
}

}

+ 30
- 0
app/src/main/res/layout/popup_window.xml View File

@@ -0,0 +1,30 @@
<?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:text="Aktualisieren"
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
- 0
app/src/main/res/menu/options_menu.xml 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>

Loading…
Cancel
Save