|
|
|
|
|
|
|
|
import android.Manifest; |
|
|
import android.Manifest; |
|
|
import android.content.pm.PackageManager; |
|
|
import android.content.pm.PackageManager; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
|
|
|
import android.os.Environment; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.widget.TextView; |
|
|
import android.widget.TextView; |
|
|
import android.widget.Toast; |
|
|
import android.widget.Toast; |
|
|
import android.widget.ToggleButton; |
|
|
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 |
|
|
@ExperimentalGetImage |
|
|
public class MainActivity extends AppCompatActivity { |
|
|
public class MainActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
|
private static final int CAMERA_PERMISSION_REQUEST_CODE = 101; |
|
|
|
|
|
|
|
|
private static final int PERMISSION_REQUEST_CODE = 111; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
|
|
|
|
|
|
PreviewView previewView = findViewById(R.id.previewView); |
|
|
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 toggleButton = findViewById(R.id.previewButton); |
|
|
toggleButton.setOnClickListener(new View.OnClickListener() { |
|
|
toggleButton.setOnClickListener(new View.OnClickListener() { |
|
|
@Override |
|
|
@Override |
|
|
public void onClick(View v) { |
|
|
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 { |
|
|
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 |
|
|
@Override |
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
|
|
super.onRequestPermissionsResult(requestCode, permissions, 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; |
|
|
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 { |
|
|
} else { |
|
|
Toast.makeText(this, "camera permission denied", Toast.LENGTH_LONG).show(); |
|
|
|
|
|
|
|
|
Toast.makeText(this, "permissions denied", Toast.LENGTH_LONG).show(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |