Sensors working together in main
This commit is contained in:
parent
2087edd3e6
commit
54ba3b4862
@ -24,20 +24,16 @@ public class DetectorService extends LifecycleService {
|
|||||||
|
|
||||||
VideoDetector videoDetector = null;
|
VideoDetector videoDetector = null;
|
||||||
AudioRecorder audioRecorder = null;
|
AudioRecorder audioRecorder = null;
|
||||||
|
Accelerometer accelerometer = null;
|
||||||
|
MicrophoneDetector microphoneDetector = null;
|
||||||
|
|
||||||
/** Communication **/
|
|
||||||
|
|
||||||
WifiCommunication wifiCommunication;
|
|
||||||
|
|
||||||
StringBuffer dataFromWifi;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
if (isServiceRunning)
|
if (isServiceRunning)
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
|
|
||||||
|
/** Video Detection/Recorder **/
|
||||||
// Setup Service classes:
|
|
||||||
videoDetector = new VideoDetector(this);
|
videoDetector = new VideoDetector(this);
|
||||||
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -45,20 +41,29 @@ public class DetectorService extends LifecycleService {
|
|||||||
passToServiceListener(detectionReport);
|
passToServiceListener(detectionReport);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
/** Motion Detection**/
|
||||||
|
accelerometer = new Accelerometer(this);
|
||||||
|
accelerometer.getSensor();
|
||||||
|
accelerometer.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
|
passToServiceListener(detectionReport);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/** Audio Detection **/
|
||||||
|
microphoneDetector = new MicrophoneDetector(this);
|
||||||
|
microphoneDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
|
passToServiceListener(detectionReport);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/** Audio Recorder**/
|
||||||
audioRecorder = new AudioRecorder(this);
|
audioRecorder = new AudioRecorder(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
isServiceRunning = true;
|
isServiceRunning = true;
|
||||||
|
|
||||||
wifiCommunication = new WifiCommunication (1234);
|
|
||||||
wifiCommunication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
|
|
||||||
@Override
|
|
||||||
public void onConnection(StringBuffer data) {
|
|
||||||
dataFromWifi = data;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return super.onStartCommand(intent, flags, startId);
|
return super.onStartCommand(intent, flags, startId);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@ -103,18 +108,22 @@ public class DetectorService extends LifecycleService {
|
|||||||
|
|
||||||
/** Audio Detection */
|
/** Audio Detection */
|
||||||
public void startAudioDetection() {
|
public void startAudioDetection() {
|
||||||
|
if(microphoneDetector != null)
|
||||||
|
microphoneDetector.startDetection();
|
||||||
}
|
}
|
||||||
public void stopAudioDetection() {
|
public void stopAudioDetection() {
|
||||||
|
if(microphoneDetector != null)
|
||||||
|
microphoneDetector.stopDetection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Motion Detection */
|
/** Motion Detection */
|
||||||
public void startMotionDetection() {
|
public void startMotionDetection() {
|
||||||
|
if(accelerometer != null)
|
||||||
|
accelerometer.startDetection();
|
||||||
}
|
}
|
||||||
public void stopMotionDetection() {
|
public void stopMotionDetection() {
|
||||||
|
if(accelerometer != null)
|
||||||
|
accelerometer.stopDetection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Video Recording */
|
/** Video Recording */
|
||||||
|
@ -224,7 +224,7 @@ public class VideoDetector extends Detector {
|
|||||||
// Violation Condition
|
// Violation Condition
|
||||||
if (percentChanged * 100 > ALARM_THRESHOLD) {
|
if (percentChanged * 100 > ALARM_THRESHOLD) {
|
||||||
if (allowReportViolation)
|
if (allowReportViolation)
|
||||||
reportViolation("Video", percentChanged);
|
reportViolation("Video", percentChanged * 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
imageProxy.close();
|
imageProxy.close();
|
||||||
|
@ -1,17 +1,102 @@
|
|||||||
package com.example.ueberwachungssystem;
|
package com.example.ueberwachungssystem;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.camera.core.ExperimentalGetImage;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import androidx.camera.core.ExperimentalGetImage;
|
||||||
|
import androidx.camera.view.PreviewView;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
|
import com.example.ueberwachungssystem.Detection.Accelerometer;
|
||||||
|
import com.example.ueberwachungssystem.Detection.AudioRecorder;
|
||||||
|
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
||||||
|
import com.example.ueberwachungssystem.Detection.Detector;
|
||||||
|
import com.example.ueberwachungssystem.Detection.MicrophoneDetector;
|
||||||
|
import com.example.ueberwachungssystem.Detection.VideoDetector;
|
||||||
|
|
||||||
@ExperimentalGetImage
|
@ExperimentalGetImage
|
||||||
public class MainActivity extends AppCompatActivity{
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
|
||||||
|
ImageView inputImageView = findViewById(R.id.inputImageView);
|
||||||
|
ImageView outputImageView = findViewById(R.id.outputImageView);
|
||||||
|
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);
|
||||||
|
//vd.debugProcessing(inputImageView, outputImageView);
|
||||||
|
vd.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
|
Log.d("onDetection", detectionReport.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MicrophoneDetector microphoneDetector = new MicrophoneDetector(this);
|
||||||
|
microphoneDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
|
Log.d("onDetection", detectionReport.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Accelerometer accelerometer = new Accelerometer(this);
|
||||||
|
accelerometer.getSensor();
|
||||||
|
accelerometer.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
|
Log.d("onDetection", detectionReport.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ToggleButton toggleButton = findViewById(R.id.toggleButton);
|
||||||
|
toggleButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (toggleButton.isChecked())
|
||||||
|
{
|
||||||
|
//vd.startDetection();
|
||||||
|
//vd.stopDetection();
|
||||||
|
vd.startDetection();
|
||||||
|
microphoneDetector.startDetection();
|
||||||
|
accelerometer.startDetection();
|
||||||
|
|
||||||
|
vd.startRecording();
|
||||||
|
audioRecorder.startRecording();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//vd.stopDetection();
|
||||||
|
vd.stopRecording();
|
||||||
|
audioRecorder.stopRecording();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,123 +1,41 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@android:color/holo_green_dark"
|
android:layout_gravity="center"
|
||||||
android:visibility="visible"
|
android:gravity="top"
|
||||||
tools:context="com.example.ueberwachungssystem.MainActivity"
|
android:orientation="vertical"
|
||||||
tools:visibility="visible">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<ToggleButton
|
|
||||||
android:id="@+id/toggleKamera"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignBottom="@id/toggleAudio"
|
|
||||||
android:layout_marginRight="15dp"
|
|
||||||
android:layout_toStartOf="@+id/toggleAudio"
|
|
||||||
android:layout_toLeftOf="@id/toggleAudio"
|
|
||||||
android:text="Kamera" />
|
|
||||||
|
|
||||||
<ToggleButton
|
<androidx.camera.view.PreviewView
|
||||||
android:id="@+id/toggleAudio"
|
android:id="@+id/previewView"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:text="Audio" />
|
|
||||||
|
|
||||||
<ToggleButton
|
|
||||||
android:id="@+id/toggleBewegung"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignBottom="@id/toggleAudio"
|
|
||||||
android:layout_marginLeft="15dp"
|
|
||||||
android:layout_toEndOf="@+id/toggleAudio"
|
|
||||||
android:layout_toRightOf="@id/toggleAudio"
|
|
||||||
android:text="Bewegung" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnAudio"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignBottom="@id/btnKamera"
|
|
||||||
android:layout_marginRight="15dp"
|
|
||||||
android:layout_toStartOf="@+id/btnKamera"
|
|
||||||
android:onClick="onClickZeigeFragment1"
|
|
||||||
android:text="Audio" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnKamera"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@id/toggleAudio"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:onClick="onClickZeigeFragment2"
|
|
||||||
android:text="Kamera" />
|
|
||||||
|
|
||||||
<!--
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnSensorWeg"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_centerHorizontal="true"
|
|
||||||
android:layout_below="@+id/btn1"
|
|
||||||
android:text="Entferne Sensordarstellung"
|
|
||||||
android:onClick="onClickEntferneFragment"/>
|
|
||||||
-->
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnBewegung"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignBottom="@id/btnKamera"
|
|
||||||
android:layout_marginLeft="15dp"
|
|
||||||
android:layout_toEndOf="@+id/btnKamera"
|
|
||||||
android:layout_toRightOf="@id/btnKamera"
|
|
||||||
android:onClick="onClickZeigeFragment3"
|
|
||||||
android:text="Bewegung" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnAufnahme"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@+id/btnKamera"
|
|
||||||
android:layout_toLeftOf="@id/btnKamera"
|
|
||||||
android:layout_marginRight="15dp"
|
|
||||||
android:onClick="onClickEntferneFragment"
|
|
||||||
android:text="Aufnahme" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnWiedergabe"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_below="@+id/btnKamera"
|
|
||||||
android:layout_toRightOf="@id/btnKamera"
|
|
||||||
android:layout_marginLeft="15dp"
|
|
||||||
android:onClick="onClickEntferneFragment"
|
|
||||||
android:text="Wiedergabe" />
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/frame"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="200dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/btnAufnahme"
|
android:backgroundTint="@android:color/black"/>
|
||||||
android:layout_alignParentStart="true">
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<ScrollView
|
<ToggleButton
|
||||||
android:id= "@+id/scrollView1"
|
android:id="@+id/toggleButton"
|
||||||
android:layout_width= "wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height= "wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below= "@id/frame">
|
android:text="ToggleButton" />
|
||||||
<LinearLayout
|
|
||||||
android:layout_width= "match_parent"
|
|
||||||
android:layout_height= "match_parent"
|
|
||||||
android:orientation= "vertical" >
|
|
||||||
<TextView
|
|
||||||
android:id= "@+id/Alarm"
|
|
||||||
android:layout_width= "wrap_content"
|
|
||||||
android:layout_height= "wrap_content" />
|
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
<ImageView
|
||||||
|
android:id="@+id/inputImageView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:srcCompat="@tools:sample/avatars" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/outputImageView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:srcCompat="@tools:sample/avatars" />
|
||||||
|
|
||||||
|
<androidx.camera.view.PreviewView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user