Removed Permission Handling from Video Detector, Added PermissionHandler.java class
This commit is contained in:
parent
5d31f0bb46
commit
bff6abbd29
@ -112,11 +112,6 @@ public class VideoDetector extends Detector {
|
|||||||
// Check States
|
// Check States
|
||||||
if (isDetecting)
|
if (isDetecting)
|
||||||
return;
|
return;
|
||||||
// Return On Request Permissions
|
|
||||||
if (!hasPermissions()) {
|
|
||||||
getPermissions();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Configure Image Analysis
|
// Configure Image Analysis
|
||||||
imageAnalysis = setupImageAnalysis();
|
imageAnalysis = setupImageAnalysis();
|
||||||
// Open CV startup check
|
// Open CV startup check
|
||||||
@ -145,11 +140,6 @@ public class VideoDetector extends Detector {
|
|||||||
if (isRecording){
|
if (isRecording){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Return On Request Permissions
|
|
||||||
if (!hasPermissions()) {
|
|
||||||
getPermissions();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
videoCapture = setupVideoCapture();
|
videoCapture = setupVideoCapture();
|
||||||
|
|
||||||
@ -324,7 +314,6 @@ public class VideoDetector extends Detector {
|
|||||||
return display.getRotation();
|
return display.getRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Start delay until Violation Report is allowed */
|
/** Start delay until Violation Report is allowed */
|
||||||
private void startViolationTimer(float setupTime) {
|
private void startViolationTimer(float setupTime) {
|
||||||
new CountDownTimer((long) (START_DELAY), 100) {
|
new CountDownTimer((long) (START_DELAY), 100) {
|
||||||
@ -338,16 +327,6 @@ public class VideoDetector extends Detector {
|
|||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Permission handling */
|
|
||||||
private boolean hasPermissions() {
|
|
||||||
return ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED &&
|
|
||||||
ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
|
|
||||||
}
|
|
||||||
private void getPermissions() {
|
|
||||||
if (!hasPermissions())
|
|
||||||
ActivityCompat.requestPermissions((Activity) context, new String[]{android.Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}, PERMISSION_REQUEST_CODE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOutputDir(File outputDir) {
|
public void setOutputDir(File outputDir) {
|
||||||
this.outputDir = outputDir;
|
this.outputDir = outputDir;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
PreviewView previewView = findViewById(R.id.previewView);
|
PreviewView previewView = findViewById(R.id.previewView);
|
||||||
|
|
||||||
|
|
||||||
|
PermissionHandler permissionHandler = new PermissionHandler(this);
|
||||||
|
|
||||||
|
|
||||||
|
permissionHandler.getPermissions();
|
||||||
|
|
||||||
|
if (permissionHandler.hasPermissions()) {
|
||||||
|
AudioRecorder audioRecorder = new AudioRecorder(this);
|
||||||
VideoDetector vd = new VideoDetector(this);
|
VideoDetector vd = new VideoDetector(this);
|
||||||
//vd.setPreviewView(previewView);
|
//vd.setPreviewView(previewView);
|
||||||
vd.debugProcessing(inputImageView, outputImageView);
|
vd.debugProcessing(inputImageView, outputImageView);
|
||||||
@ -41,11 +48,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
vd.startDetection();
|
vd.startDetection();
|
||||||
|
|
||||||
|
|
||||||
AudioRecorder audioRecorder = new AudioRecorder(this);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ToggleButton toggleButton = findViewById(R.id.toggleButton);
|
ToggleButton toggleButton = findViewById(R.id.toggleButton);
|
||||||
toggleButton.setOnClickListener(new View.OnClickListener() {
|
toggleButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -64,5 +66,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
public class PermissionHandler {
|
||||||
|
private final Context context;
|
||||||
|
private static final int PERMISSION_REQUEST_CODE = 23409;
|
||||||
|
private static final String[] permissions = new String[]{
|
||||||
|
android.Manifest.permission.CAMERA,
|
||||||
|
android.Manifest.permission.RECORD_AUDIO
|
||||||
|
};
|
||||||
|
|
||||||
|
public PermissionHandler(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermissions() {
|
||||||
|
boolean permissionState = true;
|
||||||
|
for (String permission: permissions) {
|
||||||
|
permissionState = permissionState && ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
}
|
||||||
|
return permissionState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getPermissions() {
|
||||||
|
if (!hasPermissions())
|
||||||
|
ActivityCompat.requestPermissions((Activity) context, permissions, PERMISSION_REQUEST_CODE);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user