@@ -24,20 +24,16 @@ public class DetectorService extends LifecycleService { | |||
VideoDetector videoDetector = null; | |||
AudioRecorder audioRecorder = null; | |||
Accelerometer accelerometer = null; | |||
MicrophoneDetector microphoneDetector = null; | |||
/** Communication **/ | |||
WifiCommunication wifiCommunication; | |||
StringBuffer dataFromWifi; | |||
@Override | |||
public int onStartCommand(Intent intent, int flags, int startId) { | |||
if (isServiceRunning) | |||
return START_NOT_STICKY; | |||
// Setup Service classes: | |||
/** Video Detection/Recorder **/ | |||
videoDetector = new VideoDetector(this); | |||
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() { | |||
@Override | |||
@@ -45,20 +41,29 @@ public class DetectorService extends LifecycleService { | |||
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); | |||
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); | |||
} | |||
@Override | |||
@@ -103,18 +108,22 @@ public class DetectorService extends LifecycleService { | |||
/** Audio Detection */ | |||
public void startAudioDetection() { | |||
if(microphoneDetector != null) | |||
microphoneDetector.startDetection(); | |||
} | |||
public void stopAudioDetection() { | |||
if(microphoneDetector != null) | |||
microphoneDetector.stopDetection(); | |||
} | |||
/** Motion Detection */ | |||
public void startMotionDetection() { | |||
if(accelerometer != null) | |||
accelerometer.startDetection(); | |||
} | |||
public void stopMotionDetection() { | |||
if(accelerometer != null) | |||
accelerometer.stopDetection(); | |||
} | |||
/** Video Recording */ |
@@ -224,7 +224,7 @@ public class VideoDetector extends Detector { | |||
// Violation Condition | |||
if (percentChanged * 100 > ALARM_THRESHOLD) { | |||
if (allowReportViolation) | |||
reportViolation("Video", percentChanged); | |||
reportViolation("Video", percentChanged * 100); | |||
} | |||
} | |||
imageProxy.close(); |
@@ -1,17 +1,102 @@ | |||
package com.example.ueberwachungssystem; | |||
import androidx.camera.core.ExperimentalGetImage; | |||
import androidx.annotation.NonNull; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
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 | |||
public class MainActivity extends AppCompatActivity{ | |||
public class MainActivity extends AppCompatActivity { | |||
@Override | |||
protected void onCreate(Bundle 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"?> | |||
<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" | |||
android:layout_width="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_alignParentTop="true" | |||
android:layout_centerHorizontal="true" | |||
android:text="Audio" /> | |||
android:backgroundTint="@android:color/black"/> | |||
<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_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_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_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_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> |