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

package com.example.ueberwachungssystem.Detection; package com.example.ueberwachungssystem.Detection;


import android.Manifest;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Binder; import android.os.Binder;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.camera.core.ExperimentalGetImage; import androidx.camera.core.ExperimentalGetImage;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleService; import androidx.lifecycle.LifecycleService;


@ExperimentalGetImage @ExperimentalGetImage


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


VideoDetector videoDetector = null; VideoDetector videoDetector = null;
AudioRecorder audioRecorder = null; AudioRecorder audioRecorder = null;


@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (isServiceRunning)
return START_NOT_STICKY;
videoDetector = new VideoDetector(this); videoDetector = new VideoDetector(this);
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() { videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
@Override @Override
}); });


audioRecorder = new AudioRecorder(this); audioRecorder = new AudioRecorder(this);


isServiceRunning = true;

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


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

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

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



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




// Parameters // Parameters
private static final float ALARM_THRESHOLD = 0.5f; // Percent of pixels changed private static final float ALARM_THRESHOLD = 0.5f; // Percent of pixels changed
private static final float START_DELAY = 20000; // milliseconds 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

import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.ExperimentalGetImage; import androidx.camera.core.ExperimentalGetImage;
import androidx.camera.view.PreviewView; 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.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
@Override @Override
public void onServiceDisconnected(ComponentName name) {} 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