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