Browse Source

Refactor

bk_video
Bastian Kohler 1 year ago
parent
commit
0a3600d0d6

+ 18
- 0
app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java View File

@@ -1,6 +1,9 @@
package com.example.ueberwachungssystem.Detection;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
@@ -9,6 +12,8 @@ import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.camera.core.ExperimentalGetImage;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleService;

@ExperimentalGetImage
@@ -16,6 +21,7 @@ public class DetectorService extends LifecycleService {

public TestBinder testBinder = new TestBinder();
private DetectorService.OnDetectionListener listener;
private boolean isServiceRunning = false;

VideoDetector videoDetector = null;
AudioRecorder audioRecorder = null;
@@ -23,6 +29,8 @@ public class DetectorService extends LifecycleService {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (isServiceRunning)
return START_NOT_STICKY;
videoDetector = new VideoDetector(this);
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
@Override
@@ -32,9 +40,19 @@ public class DetectorService extends LifecycleService {
});

audioRecorder = new AudioRecorder(this);


isServiceRunning = true;

return super.onStartCommand(intent, flags, startId);
}

@Override
public void onDestroy() {
super.onDestroy();
isServiceRunning = false;
}

/** Service methods */
public class TestBinder extends Binder {
public DetectorService getBoundService() {

+ 1
- 2
app/src/main/java/com/example/ueberwachungssystem/Detection/VideoDetector.java View File

@@ -76,13 +76,12 @@ public class VideoDetector extends Detector {

// Recorder
private File outputDir; // Default: in app files directory
private int rotation = 0;


// Parameters
private static final float ALARM_THRESHOLD = 0.5f; // Percent of pixels changed
private static final float START_DELAY = 20000; // milliseconds
private static final android.util.Size IMAGE_RES = new android.util.Size(640, 480);
private static final android.util.Size IMAGE_RES = new android.util.Size(480, 360);




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

@@ -4,11 +4,16 @@ import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.ExperimentalGetImage;
import androidx.camera.view.PreviewView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
@@ -80,4 +85,14 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onServiceDisconnected(ComponentName name) {}
};


private boolean hasPermissions() {
return ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
}
private void getPermissions() {
if (!hasPermissions())
ActivityCompat.requestPermissions((Activity) this, new String[]{android.Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}, 12345);
}
}

Loading…
Cancel
Save