Browse Source

Readded main and main xml

bk_video_test
Bastian Kohler 1 year ago
parent
commit
f98079d431

+ 74
- 0
app/src/main/java/com/example/ueberwachungssystem/MainActivity.java View File

@@ -1,14 +1,88 @@
package com.example.ueberwachungssystem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.view.PreviewView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.camera.core.ExperimentalGetImage;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.example.ueberwachungssystem.Detection.DetectionReport;
import com.example.ueberwachungssystem.Detection.Detector;
import com.example.ueberwachungssystem.Detection.VideoDetector;

@ExperimentalGetImage
public class MainActivity extends AppCompatActivity {

private static final int CAMERA_PERMISSION_REQUEST_CODE = 101;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

TextView textView = findViewById(R.id.textView);
PreviewView previewView = findViewById(R.id.previewView);


VideoDetector vd = new VideoDetector(this);
vd.setPreviewView(previewView);
vd.setOnDetectionListener(new Detector.OnDetectionListener(){
@Override
public void onDetection(@NonNull DetectionReport detectionReport) {
detectionReport.log("OnDetection");
textView.setText(detectionReport.toString());
}
});
//vd.startDetection();


ToggleButton toggleButton = findViewById(R.id.previewButton);
toggleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getCameraAccess();
if (isCameraAccessAllowed() && toggleButton.isChecked())
{
vd.startDetection();
}
else {
vd.stopDetection();
textView.setText("");
}
}
});
}

private boolean isCameraAccessAllowed() {
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
}

private void getCameraAccess() {
if (!isCameraAccessAllowed())
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == CAMERA_PERMISSION_REQUEST_CODE && grantResults.length > 0) {
boolean cameraRights = grantResults[0] == PackageManager.PERMISSION_GRANTED;
if (cameraRights) {
Toast.makeText(this, "camera permission granted", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show();
}
}
}
}

+ 22
- 3
app/src/main/res/layout/activity_main.xml View File

@@ -1,18 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text=""
android:textSize="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

<ToggleButton
android:id="@+id/previewButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton" />


<androidx.camera.view.PreviewView
android:id="@+id/previewView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="@android:color/black"/>

</LinearLayout>

Loading…
Cancel
Save