Browse Source

Sensors working together in main

bk_service
Bastian Kohler 1 year ago
parent
commit
54ba3b4862

+ 29
- 20
app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java View File



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;



// Setup Service classes:
/** Video Detection/Recorder **/
videoDetector = new VideoDetector(this); videoDetector = new VideoDetector(this);
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() { videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
@Override @Override
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


/** 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 */

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

// 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();

+ 89
- 4
app/src/main/java/com/example/ueberwachungssystem/MainActivity.java View File

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



import androidx.camera.core.ExperimentalGetImage;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.ExperimentalGetImage;
import androidx.camera.view.PreviewView;

import android.os.Bundle; 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();
}
}
});







}

}
} }

+ 22
- 104
app/src/main/res/layout/activity_main.xml View File

<?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:visibility="visible"
tools:context="com.example.ueberwachungssystem.MainActivity"
tools:visibility="visible">
android:layout_gravity="center"
android:gravity="top"
android:orientation="vertical"
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
android:id="@+id/toggleAudio"
android:layout_width="wrap_content"
<androidx.camera.view.PreviewView
android:id="@+id/previewView"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Audio" />
android:backgroundTint="@android:color/black"/>


<ToggleButton <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:id="@+id/toggleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/toggleAudio"
android:layout_centerHorizontal="true"
android:onClick="onClickZeigeFragment2"
android:text="Kamera" />
android:text="ToggleButton" />


<!--
<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"
<ImageView
android:id="@+id/inputImageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="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" />
tools:srcCompat="@tools:sample/avatars" />


<Button
android:id="@+id/btnAufnahme"
<ImageView
android:id="@+id/outputImageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="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" />
tools:srcCompat="@tools:sample/avatars" />


<Button
android:id="@+id/btnWiedergabe"
<androidx.camera.view.PreviewView
android:layout_width="wrap_content" 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_height="200dp"
android:layout_below="@+id/btnAufnahme"
android:layout_alignParentStart="true">
</FrameLayout>

<ScrollView
android:id= "@+id/scrollView1"
android:layout_width= "wrap_content"
android:layout_height= "wrap_content"
android:layout_below= "@id/frame">
<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>
android:layout_height="wrap_content" />


</RelativeLayout>
</LinearLayout>

Loading…
Cancel
Save