|
|
@@ -10,17 +10,21 @@ import androidx.camera.core.ExperimentalGetImage; |
|
|
|
import android.Manifest; |
|
|
|
import android.content.pm.PackageManager; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Environment; |
|
|
|
import android.view.View; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.Toast; |
|
|
|
import android.widget.ToggleButton; |
|
|
|
|
|
|
|
import com.example.ueberwachungssystem.VideoDetection.VideoDetector; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.lang.reflect.Array; |
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
@ExperimentalGetImage |
|
|
|
public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
private static final int CAMERA_PERMISSION_REQUEST_CODE = 101; |
|
|
|
private static final int PERMISSION_REQUEST_CODE = 111; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@@ -32,54 +36,66 @@ public class MainActivity extends AppCompatActivity { |
|
|
|
PreviewView previewView = findViewById(R.id.previewView); |
|
|
|
|
|
|
|
|
|
|
|
VideoDetector vd = new VideoDetector(this); |
|
|
|
vd.setPreviewView(previewView); |
|
|
|
vd.setOnDetectionListener(new VideoDetector.OnDetectionListener() { |
|
|
|
@Override |
|
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
|
detectionReport.log("OnDetection"); |
|
|
|
textView.setText(detectionReport.toString()); |
|
|
|
} |
|
|
|
}); |
|
|
|
//vd.startDetection(); |
|
|
|
File directory = getFilesDir(); |
|
|
|
|
|
|
|
|
|
|
|
Recorder recorder = new Recorder(this); |
|
|
|
|
|
|
|
|
|
|
|
ToggleButton toggleButton = findViewById(R.id.previewButton); |
|
|
|
toggleButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
getCameraAccess(); |
|
|
|
if (isCameraAccessAllowed() && toggleButton.isChecked()) |
|
|
|
getRecordVideoAccess(); |
|
|
|
|
|
|
|
if (isRecordVideoAllowed() && toggleButton.isChecked()) |
|
|
|
{ |
|
|
|
vd.startDetection(); |
|
|
|
//textView.setText(file.getAbsolutePath()); |
|
|
|
recorder.startRecording(); |
|
|
|
|
|
|
|
File file = new File(directory, "file.txt"); |
|
|
|
|
|
|
|
try { |
|
|
|
file.createNewFile(); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RuntimeException(e); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
else { |
|
|
|
vd.stopDetection(); |
|
|
|
textView.setText(""); |
|
|
|
File[] files = directory.listFiles(); |
|
|
|
textView.setText(Arrays.toString(files)); |
|
|
|
recorder.stopRecording(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean isCameraAccessAllowed() { |
|
|
|
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED; |
|
|
|
private boolean isRecordVideoAllowed() { |
|
|
|
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED && |
|
|
|
ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED; |
|
|
|
} |
|
|
|
|
|
|
|
private void getCameraAccess() { |
|
|
|
if (!isCameraAccessAllowed()) |
|
|
|
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CAMERA}, CAMERA_PERMISSION_REQUEST_CODE); |
|
|
|
private void getRecordVideoAccess() { |
|
|
|
if (!isRecordVideoAllowed()) { |
|
|
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}, 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) { |
|
|
|
if (requestCode == 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(); |
|
|
|
boolean recordAudioRights = grantResults[1] == PackageManager.PERMISSION_GRANTED; |
|
|
|
|
|
|
|
if (cameraRights && recordAudioRights) { |
|
|
|
Toast.makeText(this, "permissions granted", Toast.LENGTH_LONG).show(); |
|
|
|
} else { |
|
|
|
Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show(); |
|
|
|
Toast.makeText(this, "permissions denied", Toast.LENGTH_LONG).show(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |