Compare commits

...

19 Commits

Author SHA1 Message Date
3e2b8e7830 Merge branch 'Benutzeroberflaeche' of bauseweinfr74630/mMDT5_GreenWatch into master 2023-06-23 16:20:58 +00:00
fb873406f9 Adaptation of the receive logic 2023-06-23 17:46:50 +02:00
f1f90952d2 Aufzeichnung ohne Audio 2023-06-22 16:06:52 +02:00
f56973547b added AlarmRecording 2023-06-22 11:50:11 +02:00
efb6dc9787 adapted Layout Activitys 2023-06-22 11:49:37 +02:00
60bf036b40 adapted Layout MainActivity 2023-06-22 08:40:24 +02:00
6eb28765c9 Merge branch 'Benutzeroberflaeche_Permission' into Benutzeroberflaeche 2023-06-22 01:07:07 +02:00
cca1311b74 adapted datahandling and communication strings 2023-06-22 00:48:18 +02:00
14c30a1c80 Permissions 2023-06-22 00:38:17 +02:00
c6d33925be adapted SensorMessage Type to float 2023-06-22 00:00:09 +02:00
ac971d3f08 Merge branch 'Benutzeroberflaeche' of https://git.efi.th-nuernberg.de/gitea/bauseweinfr74630/mMDT5_GreenWatch into Benutzeroberflaeche 2023-06-21 18:44:17 +02:00
cb425cce56 Improved Microfon and Accelerometer detection in Project 2023-06-21 18:43:20 +02:00
74f0fdb798 Improved Microfon and Accelerometer detection in Project 2023-06-21 18:40:49 +02:00
97c3d2c937 Improved Video and Accelerometer detection in Project 2023-06-21 17:47:32 +02:00
5d7b949e54 Add Microfon and Accelerometer Aktivity to Project 2023-06-21 17:29:15 +02:00
99117277be Add Microfon Sensor to Project 2023-06-21 16:54:21 +02:00
e3df8b63b8 Added Video and Accelerometer to Project 2023-06-19 19:22:49 +02:00
6c4b6b67a4 Move the acceleration sensor to its own class 2023-06-18 23:00:30 +02:00
1094b0f75d Added Alarm Handling to Project 2023-06-18 22:01:52 +02:00
34 changed files with 2813 additions and 244 deletions

View File

@ -3,7 +3,14 @@
package="com.example.greenwatch"> package="com.example.greenwatch">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-feature android:name="android.hardware.camera"/> <uses-feature android:name="android.hardware.camera"/>

View File

@ -11,6 +11,7 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener; import android.hardware.SensorEventListener;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.os.Bundle; import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
@ -27,20 +28,25 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
private SensorManager accelerometerManager; private SensorManager accelerometerManager;
private Sensor accelerometerSensor; private Sensor accelerometerSensor;
private SurfaceView surfaceView;
private TextView accelerometerStatusMessage; private TextView accelerometerStatusMessage;
private TextView accelerometerDataTV; private TextView accelerometerDataTV;
private TextView accelerometerWarningTV; private TextView tvAccelerometerdeviceListRecyclerView;
private TextView tvAccelerometeralarmHistoryListRecyclerView;
private Button backToMainActivityButton; private Button backToMainActivityButton;
private AccelerometerViewModel mAccelerometerViewModel; private AccelerometerViewModel mAccelerometerViewModel;
private Permission permission = new Permission();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accelerometer); setContentView(R.layout.activity_accelerometer);
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewAccelerometer);
accelerometerStatusMessage = (TextView) findViewById(R.id.tvAccelerometerStatusmessage); accelerometerStatusMessage = (TextView) findViewById(R.id.tvAccelerometerStatusmessage);
accelerometerDataTV = (TextView) findViewById(R.id.tvAccelerometerData); accelerometerDataTV = (TextView) findViewById(R.id.tvAccelerometerData);
accelerometerWarningTV = (TextView) findViewById(R.id.tvAccelerometerWarning); tvAccelerometerdeviceListRecyclerView = (TextView) findViewById(R.id.tvAccelerometerdeviceListRecyclerView);
tvAccelerometeralarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvAccelerometeralarmHistoryListRecyclerView);
backToMainActivityButton = (Button) findViewById(R.id.accelerometerBackToMainActivity); backToMainActivityButton = (Button) findViewById(R.id.accelerometerBackToMainActivity);
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView); RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
@ -65,12 +71,11 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
}); });
mAccelerometerViewModel = new ViewModelProvider(this).get(AccelerometerViewModel.class); mAccelerometerViewModel = new ViewModelProvider(this).get(AccelerometerViewModel.class);
mAccelerometerViewModel.init(); mAccelerometerViewModel.init(surfaceView.getHolder());
mAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { mAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
@Override @Override
public void onChanged(List<Device> devices) { public void onChanged(List<Device> devices) {
deviceListAdapter.setDevices(devices); deviceListAdapter.setDevices(devices);
Toast.makeText(AccelerometerActivity.this, "onChanged", Toast.LENGTH_LONG).show();
} }
}); });
@ -81,14 +86,43 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
} }
}); });
mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() { mAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
@Override @Override
public void onChanged(Boolean aBoolean) { public void onChanged(Boolean aBoolean) {
if (aBoolean) { if (aBoolean) {
mAccelerometerViewModel.updateDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", 10); if(permission.alarmRechtePruefen(AccelerometerActivity.this, AccelerometerActivity.this)){
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mAccelerometerViewModel.startAlarmRecording();
//todo AlarmHandling einfügen
}
else {
permission.alarmRechteAnfordern(AccelerometerActivity.this);
if(permission.alarmRechtePruefen(AccelerometerActivity.this, AccelerometerActivity.this)){
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mAccelerometerViewModel.startAlarmRecording();
//todo Alarmhandling einfügen
}
else {
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
mAccelerometerViewModel.stopAlarmRecording(AccelerometerActivity.this);
}
}
} }
else { else {
mAccelerometerViewModel.updateDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), false, "Accelerometer", 0); mAccelerometerViewModel.stopAlarmRecording(AccelerometerActivity.this);
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
}
}
});
mAccelerometerViewModel.getAccelerometerAlarmDetected().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
mAccelerometerViewModel.updateDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", mAccelerometerViewModel.getAccelerometerSensorMeanValue());
}
else {
mAccelerometerViewModel.updateDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), false, "Accelerometer", 0.0f);
} }
} }

View File

@ -1,27 +1,135 @@
package com.example.greenwatch; package com.example.greenwatch;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle; import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
import com.example.greenwatch.adapters.DeviceListAdapter;
import com.example.greenwatch.models.Device;
import com.example.greenwatch.viewmodels.MicrofonViewModel;
import java.util.List;
public class AudiodetectionActivity extends AppCompatActivity { public class AudiodetectionActivity extends AppCompatActivity {
private TextView microfonStatusMessage;
private TextView tvAAudiodetectionAlarmHistoryListRecyclerView;
private TextView tvAudiodetectionDeviceListRecyclerView;
private Button backToMainActivityButton; private Button backToMainActivityButton;
private SurfaceView surfaceView;
private Permission permission = new Permission();
private MicrofonViewModel mMicrofonViewModel;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audiodetection); setContentView(R.layout.activity_audiodetection);
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewAudio);
microfonStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionStatusmessage);
tvAAudiodetectionAlarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionAlarmHistoryListRecyclerView);
tvAudiodetectionDeviceListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionDeviceListRecyclerView);
backToMainActivityButton = (Button) findViewById(R.id.audiodetectorBackToMainActivity); backToMainActivityButton = (Button) findViewById(R.id.audiodetectorBackToMainActivity);
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
recyclerView.setAdapter(deviceListAdapter);
RecyclerView alarmHistoryListRecyclerView = findViewById(R.id.alarmHistoryListRecyclerView);
alarmHistoryListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
alarmHistoryListRecyclerView.setHasFixedSize(true);
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
backToMainActivityButton.setOnClickListener(new View.OnClickListener() { backToMainActivityButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
finish(); finish();
} }
}); });
mMicrofonViewModel = new ViewModelProvider(this).get(MicrofonViewModel.class);
mMicrofonViewModel.init(surfaceView.getHolder());
mMicrofonViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
@Override
public void onChanged(List<Device> devices) {
deviceListAdapter.setDevices(devices);
}
});
mMicrofonViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
@Override
public void onChanged(List<Device> devices) {
alarmHistoryListAdapter.setAlarmHistoryList(devices);
}
});
mMicrofonViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
if(permission.alarmRechtePruefen(AudiodetectionActivity.this, AudiodetectionActivity.this)){
Toast.makeText(AudiodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mMicrofonViewModel.startAlarmRecording();
//todo AlarmHandling einfügen
} else {
permission.alarmRechteAnfordern(AudiodetectionActivity.this);
if(permission.alarmRechtePruefen(AudiodetectionActivity.this, AudiodetectionActivity.this)){
Toast.makeText(AudiodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mMicrofonViewModel.startAlarmRecording();
//todo Alarmhandling einfügen
} else {
Toast.makeText(AudiodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
mMicrofonViewModel.stopAlarmRecording(AudiodetectionActivity.this);
}
}
}
else {
Toast.makeText(AudiodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
mMicrofonViewModel.stopAlarmRecording(AudiodetectionActivity.this);
}
}
});
mMicrofonViewModel.getMicrofonAlarmDetected().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), true, "Audio", mMicrofonViewModel.getAmplitudeInDB());
}
else {
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), false, "Audio", 0.0f);
}
}
});
}
@Override
protected void onResume() {
super.onResume();
mMicrofonViewModel.startMicrofonSensor();
}
@Override
protected void onPause() {
super.onPause();
if (isFinishing()){
mMicrofonViewModel.recalibrationMicrofonSensor();
}
mMicrofonViewModel.stopMicrofonSensor();
} }
} }

View File

@ -1,27 +1,192 @@
package com.example.greenwatch; package com.example.greenwatch;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle; import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity { import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
import com.example.greenwatch.adapters.DeviceListAdapter;
import com.example.greenwatch.models.Device;
import com.example.greenwatch.viewmodels.AudiodetectionAndAccelerometerViewModel;
import java.util.List;
public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity implements SensorEventListener {
private SensorManager accelerometerManager;
private Sensor accelerometerSensor;
private SurfaceView surfaceView;
private TextView audiodetectionAndAccelerometerStatusMessage;
private TextView tvAudiodetectionAndAccelerometerDeviceListRecyclerView;
private TextView tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView;
private AudiodetectionAndAccelerometerViewModel mAudiodetectionAndAccelerometerViewModel;
private Button backToMainActivity; private Button backToMainActivity;
private Permission permission = new Permission();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audiodetection_and_accelerometer); setContentView(R.layout.activity_audiodetection_and_accelerometer);
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewAudiodetectionAndAccelerometer);
audiodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerStatusmessage);
tvAudiodetectionAndAccelerometerDeviceListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerDeviceListRecyclerView);
tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView);
backToMainActivity = (Button) findViewById(R.id.audiodetectionAndAccelerometerBackToMainActivity); backToMainActivity = (Button) findViewById(R.id.audiodetectionAndAccelerometerBackToMainActivity);
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
recyclerView.setAdapter(deviceListAdapter);
RecyclerView alarmHistoryListRecyclerView = findViewById(R.id.alarmHistoryListRecyclerView);
alarmHistoryListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
alarmHistoryListRecyclerView.setHasFixedSize(true);
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
backToMainActivity.setOnClickListener(new View.OnClickListener() { backToMainActivity.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
finish(); finish();
} }
}); });
mAudiodetectionAndAccelerometerViewModel = new ViewModelProvider(this).get(AudiodetectionAndAccelerometerViewModel.class);
mAudiodetectionAndAccelerometerViewModel.init(surfaceView.getHolder());
mAudiodetectionAndAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
@Override
public void onChanged(List<Device> devices) {
deviceListAdapter.setDevices(devices);
}
});
mAudiodetectionAndAccelerometerViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
@Override
public void onChanged(List<Device> devices) {
alarmHistoryListAdapter.setAlarmHistoryList(devices);
}
});
mAudiodetectionAndAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
if(permission.alarmRechtePruefen(AudiodetectionAndAccelerometerActivity.this, AudiodetectionAndAccelerometerActivity.this)){
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mAudiodetectionAndAccelerometerViewModel.startAlarmRecording();
//todo AlarmHandling einfügen
} else {
permission.alarmRechteAnfordern(AudiodetectionAndAccelerometerActivity.this);
if(permission.alarmRechtePruefen(AudiodetectionAndAccelerometerActivity.this, AudiodetectionAndAccelerometerActivity.this)){
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mAudiodetectionAndAccelerometerViewModel.startAlarmRecording();
//todo Alarmhandling einfügen
} else {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
mAudiodetectionAndAccelerometerViewModel.stopAlarmRecording(AudiodetectionAndAccelerometerActivity.this);
}
}
}
else {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
mAudiodetectionAndAccelerometerViewModel.stopAlarmRecording(AudiodetectionAndAccelerometerActivity.this);
}
}
});
mAudiodetectionAndAccelerometerViewModel.getAudiodetectionAndAccelerometerAlarmDetected().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedTrue", Toast.LENGTH_LONG).show();
if (mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected() && !mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected()) {
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", mAudiodetectionAndAccelerometerViewModel.getAccelerometerSensorMeanValue());
}
else if (mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected() && !mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Audio", mAudiodetectionAndAccelerometerViewModel.getAmplitudeInDB());
}
else if (mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected() && mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "AudioAndAccelerometer", mAudiodetectionAndAccelerometerViewModel.getAmplitudeInDB());
}
}
else {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedFalse", Toast.LENGTH_LONG).show();
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0.0f);
}
}
});
accelerometerManager = (SensorManager) getSystemService(SENSOR_SERVICE);
if (accelerometerManager.getSensorList(Sensor.TYPE_GYROSCOPE).size() == 0) {
accelerometerSensor = null;
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "No accelerometer sensor available", Toast.LENGTH_LONG).show();
}
else {
accelerometerSensor = accelerometerManager.getSensorList(Sensor.TYPE_GYROSCOPE).get(0);
}
}
@Override
public void onSensorChanged(SensorEvent event) {
StringBuilder sb = new StringBuilder();
sb.append("x=")
.append(event.values[0])
.append("\ny=")
.append(event.values[1])
.append("\nz=")
.append(event.values[2]);
audiodetectionAndAccelerometerStatusMessage.setText(sb.toString());
mAudiodetectionAndAccelerometerViewModel.addValueToGesamtBE(event.values[0] + event.values[1] + event.values[2]);
mAudiodetectionAndAccelerometerViewModel.meanValueCalculation();
mAudiodetectionAndAccelerometerViewModel.calibrateAccelerometerSensor();
mAudiodetectionAndAccelerometerViewModel.checkAlarmCondition();
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
protected void onResume() {
super.onResume();
mAudiodetectionAndAccelerometerViewModel.startMicrofonSensor();
if (accelerometerSensor != null) {
if (accelerometerManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_GAME)) {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "We registered to the sensor", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Registration did not work", Toast.LENGTH_LONG).show();
}
}
}
@Override
protected void onPause() {
super.onPause();
if (isFinishing()){
mAudiodetectionAndAccelerometerViewModel.recalibrationMicrofonSensor();
}
mAudiodetectionAndAccelerometerViewModel.stopMicrofonSensor();
if (accelerometerSensor != null) {
accelerometerManager.unregisterListener(this, accelerometerSensor);
}
} }
} }

View File

@ -6,10 +6,14 @@ import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.example.greenwatch.adapters.AlarmHistoryListAdapter; import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
@ -26,20 +30,31 @@ public class MainActivity extends AppCompatActivity {
private Button accelerometerButton; private Button accelerometerButton;
private Button audiodetectionAndAccelerometerButton; private Button audiodetectionAndAccelerometerButton;
private Button videodetectionAndAccelerometerButton; private Button videodetectionAndAccelerometerButton;
private Button connectionButton; private TextView tvMainActivityDeviceListRecyclerView;
private TextView tvMainActivityAlarmHistoryListRecyclerView;
private SurfaceView surfaceView;
private MainActivityViewModel mMainActivityViewModel; private MainActivityViewModel mMainActivityViewModel;
private Permission permission = new Permission();
private Activity activity = new Activity();
private Context context;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
activity = MainActivity.this;
context = MainActivity.this;
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewMainActivity);
tvMainActivityDeviceListRecyclerView = (TextView) findViewById(R.id.tvMainActivityDeviceListRecyclerView);
tvMainActivityAlarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvMainActivityAlarmHistoryListRecyclerView);
audiodetectionButton = (Button) findViewById(R.id.audiodetectionButton); audiodetectionButton = (Button) findViewById(R.id.audiodetectionButton);
videodetectionButton = (Button) findViewById(R.id.videodetectionButton); videodetectionButton = (Button) findViewById(R.id.videodetectionButton);
accelerometerButton = (Button) findViewById(R.id.accelerometerButton); accelerometerButton = (Button) findViewById(R.id.accelerometerButton);
audiodetectionAndAccelerometerButton = (Button) findViewById(R.id.audiodetectionAndAccelerometerButton); audiodetectionAndAccelerometerButton = (Button) findViewById(R.id.audiodetectionAndAccelerometerButton);
videodetectionAndAccelerometerButton = (Button) findViewById(R.id.videodetectionAndAccelerometerButton); videodetectionAndAccelerometerButton = (Button) findViewById(R.id.videodetectionAndAccelerometerButton);
connectionButton = (Button) findViewById(R.id.connectionButton);
RecyclerView deviceListRecyclerView = findViewById(R.id.deviceListRecyclerView); RecyclerView deviceListRecyclerView = findViewById(R.id.deviceListRecyclerView);
deviceListRecyclerView.setLayoutManager(new LinearLayoutManager(this)); deviceListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
@ -55,14 +70,15 @@ public class MainActivity extends AppCompatActivity {
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter(); final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter); alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
permission.startRechtePruefen(this, this);
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class); mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
mMainActivityViewModel.init(); mMainActivityViewModel.init(surfaceView.getHolder());
mMainActivityViewModel.accessRequestCamera(this);
mMainActivityViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { mMainActivityViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
@Override @Override
public void onChanged(List<Device> devices) { public void onChanged(List<Device> devices) {
deviceListAdapter.setDevices(devices); deviceListAdapter.setDevices(devices);
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_LONG).show();
} }
}); });
@ -73,23 +89,53 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
mMainActivityViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
if(permission.alarmRechtePruefen(context, activity)){
Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mMainActivityViewModel.startAlarmRecording();
//todo AlarmHandling einfügen
} else {
permission.alarmRechteAnfordern(activity);
if(permission.alarmRechtePruefen(context, activity)){
Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mMainActivityViewModel.startAlarmRecording();
//todo Alarmhandling einfügen
} else {
Toast.makeText(MainActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
mMainActivityViewModel.stopAlarmRecording(MainActivity.this);
}
}
}
else {
Toast.makeText(MainActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
}
}
});
audiodetectionButton.setOnClickListener(new View.OnClickListener() { audiodetectionButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
//openAudiodetectionActivity();
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", false, "Audio", 10); if (permission.microRechtePruefen(context, activity)) {
openAudiodetectionActivity();
}
else {
permission.microRechteAnfordern(activity);
}
} }
}); });
videodetectionButton.setOnClickListener(new View.OnClickListener() { videodetectionButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (mMainActivityViewModel.isCameraAccessAllowed(MainActivity.this)) { if (permission.kameraRechtePruefen(context, activity)) {
openVideodetectionActivity(); openVideodetectionActivity();
} }
else { else {
mMainActivityViewModel.accessRequestCamera(MainActivity.this); permission.kameraRechteAnfordern(activity);
} }
} }
}); });
accelerometerButton.setOnClickListener(new View.OnClickListener() { accelerometerButton.setOnClickListener(new View.OnClickListener() {
@ -102,50 +148,61 @@ public class MainActivity extends AppCompatActivity {
audiodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() { audiodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
//openAudiodetectionAndAccelerometerActivity(); if (permission.microRechtePruefen(context, activity)) {
mMainActivityViewModel.setSensorType(mMainActivityViewModel.getLocalDeviceUUID(), "AudiodetectionAndAccelerometer"); openAudiodetectionAndAccelerometerActivity();
mMainActivityViewModel.setTimeStamp(mMainActivityViewModel.getLocalDeviceUUID(), "00:00"); }
mMainActivityViewModel.setDeviceID(mMainActivityViewModel.getLocalDeviceUUID(), "6789"); else {
permission.microRechteAnfordern(activity);
}
} }
}); });
videodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() { videodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
openVideodetectionAndAccelerometerActivity(); if (permission.kameraRechtePruefen(context, activity)) {
} openVideodetectionAndAccelerometerActivity();
}); }
connectionButton.setOnClickListener(new View.OnClickListener() { else {
@Override permission.kameraRechteAnfordern(activity);
public void onClick(View v) { }
openConnectionActivity();
} }
}); });
} }
public void openAudiodetectionActivity(){
@Override
protected void onResume() {
super.onResume();
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "No Sensor selected", 0.0f);
}
public void openAudiodetectionActivity() {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "Audio", 0.0f);
Intent intent = new Intent(this, AudiodetectionActivity.class); Intent intent = new Intent(this, AudiodetectionActivity.class);
startActivity(intent); startActivity(intent);
} }
public void openVideodetectionActivity(){ public void openVideodetectionActivity() {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "Video", 0.0f);
Intent intent = new Intent(this, VideodetectionActivity.class); Intent intent = new Intent(this, VideodetectionActivity.class);
startActivity(intent); startActivity(intent);
} }
public void openAccelerometerActivity(){ public void openAccelerometerActivity() {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "Accelerometer", 0.0f);
Intent intent = new Intent(this, AccelerometerActivity.class); Intent intent = new Intent(this, AccelerometerActivity.class);
startActivity(intent); startActivity(intent);
} }
public void openAudiodetectionAndAccelerometerActivity(){ public void openAudiodetectionAndAccelerometerActivity() {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0.0f);
Intent intent = new Intent(this, AudiodetectionAndAccelerometerActivity.class); Intent intent = new Intent(this, AudiodetectionAndAccelerometerActivity.class);
startActivity(intent); startActivity(intent);
} }
public void openVideodetectionAndAccelerometerActivity(){ public void openVideodetectionAndAccelerometerActivity() {
//Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class); mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "VideoAndAccelerometer", 0.0f);
//startActivity(intent); Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "24:00", false, "Video", 0); startActivity(intent);
}
public void openConnectionActivity(){
//Intent intent = new Intent(this, ConnectionActivity.class);
//startActivity(intent);
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", true, "Audio", 10);
} }
@Override
protected void onPause() {
super.onPause();
}
} }

View File

@ -0,0 +1,128 @@
package com.example.greenwatch;
import static android.Manifest.permission.CAMERA;
import static android.Manifest.permission.RECORD_AUDIO;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static androidx.core.app.ActivityCompat.requestPermissions;
import static androidx.core.content.ContextCompat.checkSelfPermission;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
public class Permission {
private static final int PERMISSION_REQUEST_MICRO = 1;
private static final int PERMISSION_REQUEST_CAMERA = 2;
private static final int PERMISSION_REQUEST_ALARM = 1234;
private static final int PERMISSION_REQUEST_START = 1235;
public void startRechtePruefen(Context context, Activity activity){
boolean rechtKamera = checkSelfPermission(context, CAMERA) == PackageManager.PERMISSION_GRANTED;
boolean rechtAudio = checkSelfPermission(context, RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
boolean rechtSchreiben = checkSelfPermission(context, WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
boolean rechtLesen = checkSelfPermission(context, READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
Log.d("Kamera Rechte", String.valueOf(rechtKamera));
Log.d("Audio Rechte", String.valueOf(rechtAudio));
Log.d("Schreib Rechte", String.valueOf(rechtSchreiben));
Log.d("Lese Rechte", String.valueOf(rechtLesen));
if(rechtKamera && rechtAudio && rechtSchreiben && rechtLesen){
Log.d("Rechte", "erteilt");
} else {
startRechteAnfordern(activity);
}
}
public boolean kameraRechtePruefen(Context context, Activity activity){
boolean rechtKamera = checkSelfPermission(context, CAMERA) == PackageManager.PERMISSION_GRANTED;
Log.d("Kamera Rechte", String.valueOf(rechtKamera));
if(rechtKamera){
Log.d("Kamerarechte", "erteilt");
return true;
} else {
kameraRechteAnfordern(activity);
if(checkSelfPermission(context, CAMERA) == PackageManager.PERMISSION_GRANTED){
return true;
} else {
return false;
}
}
}
public boolean microRechtePruefen(Context context, Activity activity){
boolean rechtAudio = checkSelfPermission(context, RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
Log.d("Audio Rechte", String.valueOf(rechtAudio));
if(rechtAudio){
Log.d("Rechte", "erteilt");
return true;
} else {
microRechteAnfordern(activity);
if(checkSelfPermission(context, RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED){
return true;
} else {
return false;
}
}
}
public boolean alarmRechtePruefen(Context context, Activity activity){
boolean rechtKamera = checkSelfPermission(context, CAMERA) == PackageManager.PERMISSION_GRANTED;
boolean rechtAudio = checkSelfPermission(context, RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
boolean rechtSchreiben = checkSelfPermission(context, WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
boolean rechtLesen = checkSelfPermission(context, READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
Log.d("Kamera Rechte", String.valueOf(rechtKamera));
Log.d("Audio Rechte", String.valueOf(rechtAudio));
Log.d("Schreib Rechte", String.valueOf(rechtSchreiben));
Log.d("Lese Rechte", String.valueOf(rechtLesen));
if(rechtKamera && rechtAudio && rechtSchreiben && rechtLesen){
Log.d("Rechte", "erteilt");
return true;
} else {
alarmRechteAnfordern(activity);
if(checkSelfPermission(context, CAMERA) == PackageManager.PERMISSION_GRANTED
&& checkSelfPermission(context, RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED
&& checkSelfPermission(context, WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
&& checkSelfPermission(context, READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED){
return true;
} else {
return false;
}
}
}
public void startRechteAnfordern(Activity activity){
ActivityCompat.requestPermissions(activity, new String[]{CAMERA, RECORD_AUDIO, WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_START);
}
public void kameraRechteAnfordern(Activity activity){
ActivityCompat.requestPermissions(activity, new String[]{CAMERA}, PERMISSION_REQUEST_CAMERA);
}
public void microRechteAnfordern(Activity activity){
ActivityCompat.requestPermissions(activity, new String[]{RECORD_AUDIO}, PERMISSION_REQUEST_MICRO);
}
public void alarmRechteAnfordern(Activity activity){
ActivityCompat.requestPermissions(activity, new String[]{CAMERA, RECORD_AUDIO, WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE}, PERMISSION_REQUEST_ALARM);
}
}

View File

@ -9,14 +9,15 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle; import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.example.greenwatch.adapters.AlarmHistoryListAdapter; import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
import com.example.greenwatch.adapters.DeviceListAdapter; import com.example.greenwatch.adapters.DeviceListAdapter;
import com.example.greenwatch.models.Device; import com.example.greenwatch.models.Device;
import com.example.greenwatch.viewmodels.AccelerometerViewModel;
import com.example.greenwatch.viewmodels.VideodetectionViewModel; import com.example.greenwatch.viewmodels.VideodetectionViewModel;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
@ -26,13 +27,20 @@ import java.util.concurrent.ExecutionException;
public class VideodetectionActivity extends AppCompatActivity { public class VideodetectionActivity extends AppCompatActivity {
private Button backToMainActivity; private Button backToMainActivity;
private SurfaceView surfaceView;
private TextView tvVideodetectionDeviceListRecyclerView;
private TextView tvVideodetectionAlarmHistoryListRecyclerView;
private VideodetectionViewModel mVideoDetectionViewModel; private VideodetectionViewModel mVideoDetectionViewModel;
private Permission permission = new Permission();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_videodetection); setContentView(R.layout.activity_videodetection);
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewVideodetection);
tvVideodetectionDeviceListRecyclerView = (TextView) findViewById(R.id.tvVideodetectionDeviceListRecyclerView);
tvVideodetectionAlarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvVideodetectionAlarmHistoryListRecyclerView);
backToMainActivity = (Button) findViewById(R.id.videodetectorBackToMainActivity); backToMainActivity = (Button) findViewById(R.id.videodetectorBackToMainActivity);
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView); RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
@ -57,12 +65,11 @@ public class VideodetectionActivity extends AppCompatActivity {
}); });
mVideoDetectionViewModel = new ViewModelProvider(this).get(VideodetectionViewModel.class); mVideoDetectionViewModel = new ViewModelProvider(this).get(VideodetectionViewModel.class);
mVideoDetectionViewModel.init(); mVideoDetectionViewModel.init(surfaceView.getHolder());
mVideoDetectionViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { mVideoDetectionViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
@Override @Override
public void onChanged(List<Device> devices) { public void onChanged(List<Device> devices) {
deviceListAdapter.setDevices(devices); deviceListAdapter.setDevices(devices);
Toast.makeText(VideodetectionActivity.this, "onChanged", Toast.LENGTH_LONG).show();
} }
}); });
@ -73,14 +80,40 @@ public class VideodetectionActivity extends AppCompatActivity {
} }
}); });
mVideoDetectionViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
if(permission.alarmRechtePruefen(VideodetectionActivity.this, VideodetectionActivity.this)){
Toast.makeText(VideodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mVideoDetectionViewModel.startAlarmRecording();
//todo AlarmHandling einfügen
} else {
permission.alarmRechteAnfordern(VideodetectionActivity.this);
if(permission.alarmRechtePruefen(VideodetectionActivity.this, VideodetectionActivity.this)){
Toast.makeText(VideodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mVideoDetectionViewModel.startAlarmRecording();
//todo Alarmhandling einfügen
} else {
Toast.makeText(VideodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
mVideoDetectionViewModel.stopAlarmRecording(VideodetectionActivity.this);
}
}
}
else {
Toast.makeText(VideodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
}
}
});
mVideoDetectionViewModel.getVideoAlarmDetectedValue().observe(this, new Observer<Boolean>() { mVideoDetectionViewModel.getVideoAlarmDetectedValue().observe(this, new Observer<Boolean>() {
@Override @Override
public void onChanged(Boolean aBoolean) { public void onChanged(Boolean aBoolean) {
if (aBoolean) { if (aBoolean) {
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), true, "Video", 10); mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), true, "Video", 1.0f);
} }
else { else {
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), false, "Video", 0); mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), false, "Video", 0.0f);
} }
} }

View File

@ -1,27 +1,199 @@
package com.example.greenwatch; package com.example.greenwatch;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle; import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class VideodetectionAndAccelerometerActivity extends AppCompatActivity { import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
import com.example.greenwatch.adapters.DeviceListAdapter;
import com.example.greenwatch.models.Device;
import com.example.greenwatch.viewmodels.AccelerometerViewModel;
import com.example.greenwatch.viewmodels.VideodetectionAndAccelerometerViewModel;
import com.example.greenwatch.viewmodels.VideodetectionViewModel;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.List;
import java.util.concurrent.ExecutionException;
public class VideodetectionAndAccelerometerActivity extends AppCompatActivity implements SensorEventListener {
private SensorManager accelerometerManager;
private Sensor accelerometerSensor;
private SurfaceView surfaceView;
private TextView videodetectionAndAccelerometerStatusMessage;
private TextView videodetectionAndAccelerometerDataTV;
private TextView tvVideodetectionAndAccelerometerDeviceListRecyclerView;
private TextView tvVideodetectionAndAccelerometerAlarmHistoryListRecyclerView;
private Button backToMainActivity; private Button backToMainActivity;
private VideodetectionAndAccelerometerViewModel mVideodetectionAndAccelerometerViewModel;
private Permission permission = new Permission();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_videodetection_and_accelerometer); setContentView(R.layout.activity_videodetection_and_accelerometer);
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewVideodetectionAndAccelerometer);
videodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerStatusmessage);
videodetectionAndAccelerometerDataTV = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerData);
tvVideodetectionAndAccelerometerDeviceListRecyclerView = (TextView) findViewById(R.id.tvVideodetectionAndAccelerometerDeviceListRecyclerView);
tvVideodetectionAndAccelerometerAlarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvVideodetectionAndAccelerometerAlarmHistoryListRecyclerView);
backToMainActivity = (Button) findViewById(R.id.videodetectionAndAccelerometerBackToMainActivity); backToMainActivity = (Button) findViewById(R.id.videodetectionAndAccelerometerBackToMainActivity);
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
recyclerView.setAdapter(deviceListAdapter);
RecyclerView alarmHistoryListRecyclerView = findViewById(R.id.alarmHistoryListRecyclerView);
alarmHistoryListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
alarmHistoryListRecyclerView.setHasFixedSize(true);
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
backToMainActivity.setOnClickListener(new View.OnClickListener() { backToMainActivity.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
finish(); finish();
} }
}); });
mVideodetectionAndAccelerometerViewModel = new ViewModelProvider(this).get(VideodetectionAndAccelerometerViewModel.class);
mVideodetectionAndAccelerometerViewModel.init(surfaceView.getHolder());
mVideodetectionAndAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
@Override
public void onChanged(List<Device> devices) {
deviceListAdapter.setDevices(devices);
}
});
mVideodetectionAndAccelerometerViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
@Override
public void onChanged(List<Device> devices) {
alarmHistoryListAdapter.setAlarmHistoryList(devices);
}
});
mVideodetectionAndAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
if(permission.alarmRechtePruefen(VideodetectionAndAccelerometerActivity.this, VideodetectionAndAccelerometerActivity.this)){
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mVideodetectionAndAccelerometerViewModel.startAlarmRecording();
//todo AlarmHandling einfügen
} else {
permission.alarmRechteAnfordern(VideodetectionAndAccelerometerActivity.this);
if(permission.alarmRechtePruefen(VideodetectionAndAccelerometerActivity.this, VideodetectionAndAccelerometerActivity.this)){
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
mVideodetectionAndAccelerometerViewModel.startAlarmRecording();
//todo Alarmhandling einfügen
} else {
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
mVideodetectionAndAccelerometerViewModel.stopAlarmRecording(VideodetectionAndAccelerometerActivity.this);
}
}
}
else {
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
mVideodetectionAndAccelerometerViewModel.stopAlarmRecording(VideodetectionAndAccelerometerActivity.this);
}
}
});
mVideodetectionAndAccelerometerViewModel.getVideodetectionAndAccelerometerAlarmDetected().observe(this, new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
if (mVideodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected() && !mVideodetectionAndAccelerometerViewModel.getVideoAlarmDetected()) {
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", mVideodetectionAndAccelerometerViewModel.getAccelerometerSensorMeanValue());
}
else if (mVideodetectionAndAccelerometerViewModel.getVideoAlarmDetected() && !mVideodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Video", 1.0f);
}
else if (mVideodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected() && mVideodetectionAndAccelerometerViewModel.getVideoAlarmDetected()) {
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "VideoAndAccelerometer", mVideodetectionAndAccelerometerViewModel.getAccelerometerSensorMeanValue());
}
}
else {
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "VideoAndAccelerometer", 0.0f);
}
}
});
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this);
cameraProviderFuture.addListener(() -> {
try {
mVideodetectionAndAccelerometerViewModel.bindImageAnalysis(cameraProviderFuture.get(), this, this);
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
}, ContextCompat.getMainExecutor(this));
accelerometerManager = (SensorManager) getSystemService(SENSOR_SERVICE);
if (accelerometerManager.getSensorList(Sensor.TYPE_GYROSCOPE).size() == 0) {
accelerometerSensor = null;
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "No accelerometer sensor available", Toast.LENGTH_LONG).show();
}
else {
accelerometerSensor = accelerometerManager.getSensorList(Sensor.TYPE_GYROSCOPE).get(0);
}
}
@Override
public void onSensorChanged(SensorEvent event) {
StringBuilder sb = new StringBuilder();
sb.append("x=")
.append(event.values[0])
.append("\ny=")
.append(event.values[1])
.append("\nz=")
.append(event.values[2]);
videodetectionAndAccelerometerDataTV.setText(sb.toString());
mVideodetectionAndAccelerometerViewModel.addValueToGesamtBE(event.values[0] + event.values[1] + event.values[2]);
mVideodetectionAndAccelerometerViewModel.meanValueCalculation();
mVideodetectionAndAccelerometerViewModel.calibrateAccelerometerSensor();
mVideodetectionAndAccelerometerViewModel.checkAlarmCondition();
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
protected void onResume() {
super.onResume();
if (accelerometerSensor != null) {
if (accelerometerManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_GAME)) {
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "We registered to the sensor", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Registration did not work", Toast.LENGTH_LONG).show();
}
}
}
@Override
protected void onPause() {
super.onPause();
if (accelerometerSensor != null) {
accelerometerManager.unregisterListener(this, accelerometerSensor);
}
} }
} }

View File

@ -0,0 +1,256 @@
package com.example.greenwatch.alarmrecorder;
import android.app.Activity;
import android.content.Context;
import android.media.MediaCodec;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import android.media.MediaRecorder;
import android.os.Environment;
import android.view.SurfaceHolder;
import android.widget.Toast;
import com.example.greenwatch.MainActivity;
import com.example.greenwatch.alarmrecorder.runnables.AudioRecorder;
import com.example.greenwatch.alarmrecorder.runnables.VideoRecorder;
import com.example.greenwatch.sensors.AccelerometerSensor;
import com.example.greenwatch.sensors.CameraSensor;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
public class AlarmRecorder {
private static AlarmRecorder alarmRecorderInstance;
private boolean isRecording;
private String videoPath;
private String audioPath;
private MediaFormat videoFormat;
private MediaFormat audioFormat;
private MediaExtractor videoExtractor;
private MediaExtractor audioExtractor;
private AudioRecorder audioRecorderRunnable;
private VideoRecorder videoRecorderRunnable;
private SurfaceHolder previewHolder;
private MediaRecorder videoRecorder;
//private MediaRecorder audioRecorder;
private Thread videoThread; // Video-Thread als Instanzvariable
private Thread audioThread; // Audio-Thread als Instanzvariable
private AlarmRecorder() {
//audioRecorder = new MediaRecorder();
//videoRecorder = new MediaRecorder();
videoExtractor = new MediaExtractor();
audioExtractor = new MediaExtractor();
audioRecorderRunnable = new AudioRecorder();
videoRecorderRunnable = new VideoRecorder();
}
public static synchronized AlarmRecorder getInstance() {
if (alarmRecorderInstance == null){
alarmRecorderInstance = new AlarmRecorder();
}
return alarmRecorderInstance;
}
public void setPreviewHolder(SurfaceHolder previewHolder) {
this.previewHolder = previewHolder;
}
public void startRecording() {
createStoragePaths(); //Speicherort und -namen für Audio- und Video-Datei
setAudioPath(audioPath);
setVideoPath(videoPath);
setVideoRecorderPreviewHolder(previewHolder);
//audioThread = new Thread(audioRecorderRunnable);
videoThread = new Thread(videoRecorderRunnable);
//Threads starten
videoThread.start();
//audioThread.start();
}
public void stopRecording(Context context) {
try {
//stopAudioRecording();
stopVideoRecording();
Toast.makeText(context, "Video- und Audioaufzeichnung beendet", Toast.LENGTH_SHORT).show();
waitTillThreadsStopped();
File videoFile = new File(videoPath); //Speichere das aufgenommene Video
File audioFile = new File(audioPath); //Speichere die aufgenommene Audio
if (videoFile.exists() && audioFile.exists()) {
//Wenn Video- und Audioaufzeichnung gestoppt und abgespeichert sind, beginne mit dem Mergeprozess der beiden
// mergeVideoWithAudio();
Toast.makeText(context, "Video und Audio erfolgreich zusammengeführt", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Dateien wurden nicht gefunden!", Toast.LENGTH_SHORT).show();
}
} catch (RuntimeException stopException) {
stopException.printStackTrace();
}
}
private void createStoragePaths(){
//Pfade zum Zwischenspeichern der aufgenommenen Audio und Video-Datei
String externalStorageDirectory = Environment.getExternalStorageDirectory().getAbsolutePath();
String dcimDirectory = externalStorageDirectory + "/DCIM";
videoPath = dcimDirectory + "/video.mp4";
audioPath = dcimDirectory + "/audio.mp3";
}
private void setVideoPath(String videoPath) {
videoRecorderRunnable.setVideoPath(videoPath);
}
private void setVideoRecorderPreviewHolder(SurfaceHolder previewHolder) {
videoRecorderRunnable.setPreviewHolder(previewHolder);
}
private void stopVideoRecording(){
videoRecorderRunnable.stopVideoRecording();
}
private void setAudioPath(String audioPath) {
audioRecorderRunnable.setAudioPath(audioPath);
}
private void stopAudioRecording(){
audioRecorderRunnable.stopAudioRecording();
}
private void waitTillThreadsStopped(){
try {
videoThread.join();
audioThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void mergeVideoWithAudio() {
try {
setVideoExtractorDataSource(); //extrahieren der Video Datei, die zuvor zwischengespeichert wurde
setAudioExtractorDataSource(); //extrahieren der Audio Datei, die zuvor zwischengespeichert wurde
//Speicherort der später zusammengeführten Datei
String outputFilePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath() + "/merged_video.mp4";
//MediaMuxer zum Zusammenführen einer Audio- und einer Videodatei
MediaMuxer muxer = new MediaMuxer(outputFilePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
int videoTrack = muxer.addTrack(videoFormat);
int audioTrack = muxer.addTrack(audioFormat);
muxer.start();
ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
videoExtraction(buffer, videoTrack, bufferInfo, muxer);
audioExtraction(buffer, audioTrack, bufferInfo, muxer);
muxer.stop();
muxer.release();
// Löschen der separaten Video- und Audio-Dateien
deleteVideoFile();
deleteAudioFile();
} catch (IOException e) {
e.printStackTrace();
}
}
private void setVideoExtractorDataSource() {
try {
videoExtractor.setDataSource(videoPath);
int videoTrackIndex = getTrackIndex(videoExtractor, "video/");
if (videoTrackIndex < 0) {
// Video-Track nicht gefunden
return;
}
videoExtractor.selectTrack(videoTrackIndex);
videoFormat = videoExtractor.getTrackFormat(videoTrackIndex);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private void setAudioExtractorDataSource() {
try {
audioExtractor.setDataSource(audioPath);
int audioTrackIndex = getTrackIndex(audioExtractor, "audio/");
if (audioTrackIndex < 0) {
// Audio-Track nicht gefunden
return;
}
audioExtractor.selectTrack(audioTrackIndex);
audioFormat = audioExtractor.getTrackFormat(audioTrackIndex);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private int getTrackIndex(MediaExtractor extractor, String mimeType) {
int trackCount = extractor.getTrackCount();
for (int i = 0; i < trackCount; i++) {
MediaFormat format = extractor.getTrackFormat(i);
String trackMimeType = format.getString(MediaFormat.KEY_MIME);
if (trackMimeType.startsWith(mimeType)) {
return i;
}
}
return -1;
}
private void videoExtraction(ByteBuffer buffer, int videoTrack, MediaCodec.BufferInfo bufferInfo, MediaMuxer muxer) {
videoExtractor.seekTo(0, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
while (true) {
int sampleSize = videoExtractor.readSampleData(buffer, 0);
if (sampleSize < 0) {
break;
}
long presentationTimeUs = videoExtractor.getSampleTime();
bufferInfo.offset = 0;
bufferInfo.size = sampleSize;
bufferInfo.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME;
bufferInfo.presentationTimeUs = presentationTimeUs;
muxer.writeSampleData(videoTrack, buffer, bufferInfo);
videoExtractor.advance();
}
}
private void audioExtraction(ByteBuffer buffer, int audioTrack, MediaCodec.BufferInfo bufferInfo, MediaMuxer muxer) {
audioExtractor.seekTo(0, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
while (true) {
int sampleSize = audioExtractor.readSampleData(buffer, 0);
if (sampleSize < 0) {
break;
}
long presentationTimeUs = audioExtractor.getSampleTime();
bufferInfo.offset = 0;
bufferInfo.size = sampleSize;
bufferInfo.flags = 0; // or MediaCodec.BUFFER_FLAG_KEY_FRAME
bufferInfo.presentationTimeUs = presentationTimeUs;
muxer.writeSampleData(audioTrack, buffer, bufferInfo);
audioExtractor.advance();
}
}
private void deleteVideoFile(){
File videoFile = new File(videoPath);
if (videoFile.exists()) {
videoFile.delete();
}
}
private void deleteAudioFile(){
File audioFile = new File(audioPath);
if (audioFile.exists()) {
audioFile.delete();
}
}
}

View File

@ -0,0 +1,47 @@
package com.example.greenwatch.alarmrecorder.runnables;
import android.media.MediaRecorder;
import android.view.SurfaceHolder;
import android.widget.Toast;
import com.example.greenwatch.MainActivity;
import java.io.IOException;
public class AudioRecorder implements Runnable {
private MediaRecorder audioRecorder;
private String audioPath;
public AudioRecorder() {
audioRecorder = new MediaRecorder();
}
public void setAudioPath(String audioPath) {
this.audioPath = audioPath;
}
public void stopAudioRecording(){
if (audioRecorder != null) {
audioRecorder.stop();
audioRecorder.reset();
audioRecorder.release();
audioRecorder = null;
}
}
@Override
public void run() {
audioRecorder = new MediaRecorder();
audioRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
audioRecorder.setOutputFile(audioPath);
try {
audioRecorder.prepare();
audioRecorder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,54 @@
package com.example.greenwatch.alarmrecorder.runnables;
import android.media.MediaRecorder;
import android.view.SurfaceHolder;
import com.example.greenwatch.viewmodels.ViewModelInterface;
import java.io.IOException;
public class VideoRecorder implements Runnable{
private MediaRecorder videoRecorder;
private String videoPath;
private SurfaceHolder previewHolder;
public VideoRecorder() {
videoRecorder = new MediaRecorder();
}
public void setPreviewHolder(SurfaceHolder previewHolder) {
this.previewHolder = previewHolder;
}
public void setVideoPath(String audioPath) {
this.videoPath = audioPath;
}
public void stopVideoRecording(){
if (videoRecorder != null) {
videoRecorder.stop();
videoRecorder.reset();
videoRecorder.release();
videoRecorder = null;
}
}
@Override
public void run() {
videoRecorder = new MediaRecorder();
videoRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
videoRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
videoRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
videoRecorder.setOutputFile(videoPath);
videoRecorder.setOrientationHint(90);
videoRecorder.setPreviewDisplay(previewHolder.getSurface());
try {
videoRecorder.prepare();
videoRecorder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -17,7 +17,7 @@ public class WiFiCommunication {
private final InetAddress address; private final InetAddress address;
private final DatagramSocket socket; private final DatagramSocket socket;
private final int port; private final int port;
private String rxString; private volatile String rxString;
private String sendMessage; private String sendMessage;
//private String sendMsg = "default"; //private String sendMsg = "default";
private boolean isNewMessage; private boolean isNewMessage;
@ -48,7 +48,9 @@ public class WiFiCommunication {
} }
public void setDeviceRepository(DeviceRepository deviceRepository) { public void setDeviceRepository(DeviceRepository deviceRepository) {
this.mDeviceRepository = deviceRepository; if (mDeviceRepository == null) {
this.mDeviceRepository = deviceRepository;
}
} }
public void setNewMessage(String newMessage, boolean isNewMessage){ public void setNewMessage(String newMessage, boolean isNewMessage){
@ -88,8 +90,7 @@ public class WiFiCommunication {
if(isNewMessage) if(isNewMessage)
{ {
isNewMessage = false; isNewMessage = false;
//todo: adapt send String String txString = sendMessage;
String txString = getLocalIpAddress() + " sends. #" + tmpCnt++ + sendMessage;
byte[] txBuffer = txString.getBytes(); byte[] txBuffer = txString.getBytes();
DatagramPacket txPacket = new DatagramPacket(txBuffer, txBuffer.length, address, port); DatagramPacket txPacket = new DatagramPacket(txBuffer, txBuffer.length, address, port);

View File

@ -7,9 +7,9 @@ public class Device {
private String deviceID; private String deviceID;
private boolean sensorStatus; private boolean sensorStatus;
private String sensorType; private String sensorType;
private int sensorMassage; private float sensorMassage;
public Device(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage) { public Device(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, float sensorMassage) {
this.timeStamp = timeStamp; this.timeStamp = timeStamp;
this.deviceID = deviceID; this.deviceID = deviceID;
this.sensorStatus = sensorStatus; this.sensorStatus = sensorStatus;
@ -47,11 +47,11 @@ public class Device {
return sensorStatus; return sensorStatus;
} }
public void setSensorMassage(int sensorMassage) { public void setSensorMassage(float sensorMassage) {
this.sensorMassage = sensorMassage; this.sensorMassage = sensorMassage;
} }
public int getSensorMassage() { public float getSensorMassage() {
return sensorMassage; return sensorMassage;
} }
} }

View File

@ -1,6 +1,8 @@
package com.example.greenwatch.repositories; package com.example.greenwatch.repositories;
import android.os.Looper;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import com.example.greenwatch.models.Device; import com.example.greenwatch.models.Device;
@ -17,10 +19,12 @@ public class DeviceRepository {
private final int maxAlarmHistoryListSize = 20; private final int maxAlarmHistoryListSize = 20;
private final String delimiter = ", "; private final String delimiter = ", ";
private final String SensorStatusKey = "An"; private final String sensorStatusKey = "An";
private String localDeviceUUID; private String localDeviceUUID;
private static DeviceRepository deviceRepositoryInstance; private static DeviceRepository deviceRepositoryInstance;
private WiFiCommunication mWiFiCommunication; private WiFiCommunication mWiFiCommunication;
private boolean startAlarmRecordingValue;
private MutableLiveData<Boolean> startAlarmRecording = new MutableLiveData<>();
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>(); private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>();
private MutableLiveData<List<Device>> alarmHistoryList = new MutableLiveData<>(); private MutableLiveData<List<Device>> alarmHistoryList = new MutableLiveData<>();
private HashMap<String, Device> connectedDevicesList = new HashMap<>(); private HashMap<String, Device> connectedDevicesList = new HashMap<>();
@ -29,6 +33,7 @@ public class DeviceRepository {
private DeviceRepository() { private DeviceRepository() {
setLocalDeviceUUID(); setLocalDeviceUUID();
startAlarmRecordingValue = false;
} }
public static synchronized DeviceRepository getInstance() { public static synchronized DeviceRepository getInstance() {
@ -39,7 +44,10 @@ public class DeviceRepository {
} }
public void setWiFiCommunication(WiFiCommunication wiFiCommunication) { public void setWiFiCommunication(WiFiCommunication wiFiCommunication) {
this.mWiFiCommunication = wiFiCommunication; if (mWiFiCommunication == null) {
this.mWiFiCommunication = wiFiCommunication;
}
} }
public MutableLiveData<List<Device>> getConnectedDeviceList() { public MutableLiveData<List<Device>> getConnectedDeviceList() {
@ -52,32 +60,43 @@ public class DeviceRepository {
return alarmHistoryList; return alarmHistoryList;
} }
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){ public MutableLiveData<Boolean> getStartAlarmRecording() {
setMutableLiveDataStartAlarmRecording();
return startAlarmRecording;
}
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, float sensorMassage){
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage); Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
if (sensorStatus) { if (sensorStatus) {
setAlarmHistoryDeviceList(newDevice); setAlarmHistoryDeviceList(newDevice);
} }
boolean newStartAlarmRecordingValue = checkDeviceStatus();
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
startAlarmRecordingValue = newStartAlarmRecordingValue;
setMutableLiveDataStartAlarmRecording();
}
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice); addToConnectedDeviceList(newDevice.getDeviceID(), newDevice);
setMutableLiveDataDeviceList(); setMutableLiveDataDeviceList();
} }
public void getNewReceivedMessage(String newMessage) { public void getNewReceivedMessage(String newMessage) {
String[] messageString = messageStringSplitter(newMessage); String[] messageString = messageStringSplitter(newMessage);
String timeStamp = messageString[0]; if(messageString[0].equals("1") && messageString.length == 7) {
String deviceID = messageString[1]; String timeStamp = messageString[1];
boolean sensorStatus = convertSensorStatus(messageString[2]); String deviceID = messageString[3];
String sensorType = messageString[3]; boolean sensorStatus = convertRecievedSensorStatus(messageString[4]);
int sensorMassage = Integer.valueOf(messageString[4]); String sensorType = messageString[5];
float sensorMassage = Float.valueOf(messageString[6]);
if (deviceID.equals(checkDeviceID(localDeviceUUID))) { if (deviceID.equals(checkDeviceID(localDeviceUUID))) {
return; return;
} }
if(!connectedDevicesList.containsKey(deviceID)) { if (!connectedDevicesList.containsKey(deviceID)) {
createNewDevice(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage); createNewDevice(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
} } else {
else { updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); }
} }
} }
@ -85,18 +104,26 @@ public class DeviceRepository {
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
Device device = connectedDevicesList.get(deviceID); Device device = connectedDevicesList.get(deviceID);
if(device != null) { if(device != null) {
message.append(device.getTimeStamp()) message.append("1")
.append(delimiter)
.append(device.getTimeStamp())
.append(delimiter)
.append("Gruppe3")
.append(delimiter) .append(delimiter)
.append(device.getDeviceID()) .append(device.getDeviceID())
.append(delimiter) .append(delimiter)
.append(device.getSensorStatus()) .append(convertSendSensorStatus(device.getSensorStatus()))
.append(delimiter) .append(delimiter)
.append(device.getSensorType()) .append(device.getSensorType())
.append(delimiter) .append(delimiter)
.append(device.getSensorMassage()); .append(device.getSensorMassage());
} }
else { else {
message.append("") message.append("1")
.append(delimiter)
.append("")
.append(delimiter)
.append("Gruppe3")
.append(delimiter) .append(delimiter)
.append("") .append("")
.append(delimiter) .append(delimiter)
@ -113,7 +140,7 @@ public class DeviceRepository {
return localDeviceUUID; return localDeviceUUID;
} }
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, float sensorMassage) {
String checkedDeviceID = checkDeviceID(deviceID); String checkedDeviceID = checkDeviceID(deviceID);
Device device = connectedDevicesList.get(checkedDeviceID); Device device = connectedDevicesList.get(checkedDeviceID);
if(device != null) { if(device != null) {
@ -124,6 +151,11 @@ public class DeviceRepository {
setAlarmHistoryDeviceList(device); setAlarmHistoryDeviceList(device);
} }
device.setSensorStatus(sensorStatus); device.setSensorStatus(sensorStatus);
boolean newStartAlarmRecordingValue = checkDeviceStatus();
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
startAlarmRecordingValue = newStartAlarmRecordingValue;
setMutableLiveDataStartAlarmRecording();
}
addToConnectedDeviceList(checkedDeviceID, device); addToConnectedDeviceList(checkedDeviceID, device);
setMutableLiveDataDeviceList(); setMutableLiveDataDeviceList();
} }
@ -177,6 +209,11 @@ public class DeviceRepository {
setAlarmHistoryDeviceList(device); setAlarmHistoryDeviceList(device);
} }
device.setSensorStatus(sensorStatus); device.setSensorStatus(sensorStatus);
boolean newStartAlarmRecordingValue = checkDeviceStatus();
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
startAlarmRecordingValue = newStartAlarmRecordingValue;
setMutableLiveDataStartAlarmRecording();
}
addToConnectedDeviceList(checkedDeviceID, device); addToConnectedDeviceList(checkedDeviceID, device);
setMutableLiveDataDeviceList(); setMutableLiveDataDeviceList();
@ -211,7 +248,7 @@ public class DeviceRepository {
return ""; return "";
} }
public void setSensorMassage(String deviceID, int sensorMessage) { public void setSensorMassage(String deviceID, float sensorMessage) {
String checkedDeviceID = checkDeviceID(deviceID); String checkedDeviceID = checkDeviceID(deviceID);
Device device = connectedDevicesList.get(checkedDeviceID); Device device = connectedDevicesList.get(checkedDeviceID);
if(device != null) { if(device != null) {
@ -221,7 +258,7 @@ public class DeviceRepository {
} }
} }
public int getSensorMassage(String deviceID) { public float getSensorMassage(String deviceID) {
String checkedDeviceID = checkDeviceID(deviceID); String checkedDeviceID = checkDeviceID(deviceID);
Device device = connectedDevicesList.get(checkedDeviceID); Device device = connectedDevicesList.get(checkedDeviceID);
if(device != null) { if(device != null) {
@ -238,13 +275,22 @@ public class DeviceRepository {
private void setMutableLiveDataDeviceList() { private void setMutableLiveDataDeviceList() {
List<Device> list = new ArrayList<>(connectedDevicesList.values()); List<Device> list = new ArrayList<>(connectedDevicesList.values());
deviceList.setValue(list); if (Looper.myLooper() == Looper.getMainLooper()){
deviceList.setValue(list);
}
else {
deviceList.postValue(list);
}
} }
private void setMutableLiveDataAlarmHistoryList() { private void setMutableLiveDataAlarmHistoryList() {
alarmHistoryList.setValue(alarmHistoryDeviceList); alarmHistoryList.setValue(alarmHistoryDeviceList);
} }
private void setMutableLiveDataStartAlarmRecording() {
startAlarmRecording.setValue(startAlarmRecordingValue);
}
private void addToConnectedDeviceList(String key, Device device) { private void addToConnectedDeviceList(String key, Device device) {
connectedDevicesList.put(key, device); connectedDevicesList.put(key, device);
if (key.equals(checkDeviceID(localDeviceUUID))) { if (key.equals(checkDeviceID(localDeviceUUID))) {
@ -271,8 +317,17 @@ public class DeviceRepository {
return message.split(delimiter); return message.split(delimiter);
} }
private boolean convertSensorStatus(String status) { private boolean convertRecievedSensorStatus(String status) {
return status.equals(SensorStatusKey); return status.equals(sensorStatusKey);
}
private String convertSendSensorStatus(boolean status) {
if (status){
return "An";
}
else {
return "Aus";
}
} }
private void setAlarmHistoryDeviceList(Device device) { private void setAlarmHistoryDeviceList(Device device) {
@ -283,4 +338,13 @@ public class DeviceRepository {
alarmHistoryDeviceList.add(0, alarmHistoryDevice); alarmHistoryDeviceList.add(0, alarmHistoryDevice);
setMutableLiveDataAlarmHistoryList(); setMutableLiveDataAlarmHistoryList();
} }
private boolean checkDeviceStatus() {
for (Device device : connectedDevicesList.values()) {
if (device.getSensorStatus()) {
return true;
}
}
return false;
}
} }

View File

@ -0,0 +1,89 @@
package com.example.greenwatch.sensors;
import androidx.lifecycle.MutableLiveData;
import java.util.ArrayList;
public class AccelerometerSensor {
private MutableLiveData<Boolean> mAccelerometerAlarmDetected = new MutableLiveData<>();
private static AccelerometerSensor accelerometerSensorInstance;
private boolean accelerometerAlarmDetected;
private ArrayList<Float> Gesamt_be;
int arraySize = 500;
int functionCallCount;
float meanValue;
float offsetValue;
float thresholdValue;
boolean startMeasuring;
private AccelerometerSensor() {
initGesamtBE();
accelerometerAlarmDetected = false;
setMutableLiveDataAccelerometerAlarmDetected();
functionCallCount = 0;
meanValue = 0.0f;
offsetValue = 0.1f;
thresholdValue = 0.15f;
startMeasuring = false;
}
public static synchronized AccelerometerSensor getInstance() {
if (accelerometerSensorInstance == null){
accelerometerSensorInstance = new AccelerometerSensor();
}
return accelerometerSensorInstance;
}
public MutableLiveData<Boolean> getAccelerometerAlarmDetected() {
setMutableLiveDataAccelerometerAlarmDetected();
return mAccelerometerAlarmDetected;
}
private void setMutableLiveDataAccelerometerAlarmDetected() {
mAccelerometerAlarmDetected.setValue(accelerometerAlarmDetected);
}
private void initGesamtBE() {
Gesamt_be = new ArrayList<>(arraySize);
for (int i = 0; i < arraySize; i++) {
Gesamt_be.add(0.0f);
}
}
public void addValueToGesamtBE(float newValue) {
if (Gesamt_be.size() == arraySize) {
Gesamt_be.remove(Gesamt_be.size() -1);
}
Gesamt_be.add(0, newValue);
functionCallCount++;
}
public void meanValueCalculation() {
for (float element : Gesamt_be) {
meanValue += Math.abs(element);
}
meanValue = meanValue/arraySize;
}
public void calibrateAccelerometerSensor() {
if (functionCallCount <= arraySize) {
offsetValue = meanValue;
}
else {
startMeasuring = true;
}
}
public void checkAlarmCondition() {
if (meanValue > (thresholdValue + offsetValue) && startMeasuring && !mAccelerometerAlarmDetected.getValue()) {
mAccelerometerAlarmDetected.setValue(true);
}
else if (meanValue < (thresholdValue + offsetValue) && mAccelerometerAlarmDetected.getValue()){
mAccelerometerAlarmDetected.setValue(false);
}
}
public float getAccelerometerSensorMeanValue() {
return meanValue;
}
}

View File

@ -3,6 +3,7 @@ package com.example.greenwatch.sensors;
import android.content.Context; import android.content.Context;
import android.graphics.ImageFormat; import android.graphics.ImageFormat;
import android.media.Image; import android.media.Image;
import android.os.Handler;
import android.util.Size; import android.util.Size;
import androidx.camera.core.CameraSelector; import androidx.camera.core.CameraSelector;
@ -18,9 +19,18 @@ public class CameraSensor {
private final MutableLiveData<Boolean> mVideoAlarmDetected = new MutableLiveData<>(); private final MutableLiveData<Boolean> mVideoAlarmDetected = new MutableLiveData<>();
private static CameraSensor cameraSensorInstance; private static CameraSensor cameraSensorInstance;
private boolean videoAlarmDetected; private boolean videoAlarmDetected;
private boolean isMotionDetected;
private ByteBuffer previousBuffer; private ByteBuffer previousBuffer;
private int previousWidth; private int previousWidth;
private int previousHeight; private int previousHeight;
private final int threshold = 50;
private int startX;
private int startY;
private int endX;
private int endY;
private static final long ALARM_RESET_DELAY = 5000;
private Runnable alarmResetRunnable;
private final Handler alarmResetHandler = new Handler();
private CameraSensor() { private CameraSensor() {
videoAlarmDetected = false; videoAlarmDetected = false;
@ -34,11 +44,11 @@ public class CameraSensor {
} }
public MutableLiveData<Boolean> getVideoAlarmDetectedValue() { public MutableLiveData<Boolean> getVideoAlarmDetectedValue() {
setMutableLiveDataVideoMovementDetected(); setMutableLiveDataVideoAlarmDetected();
return mVideoAlarmDetected; return mVideoAlarmDetected;
} }
private void setMutableLiveDataVideoMovementDetected() { private void setMutableLiveDataVideoAlarmDetected() {
mVideoAlarmDetected.setValue(videoAlarmDetected); mVideoAlarmDetected.setValue(videoAlarmDetected);
} }
@ -59,7 +69,7 @@ public class CameraSensor {
if (previousHeight != 0) { if (previousHeight != 0) {
assert currentImage != null; assert currentImage != null;
videoAlarmDetected = compareFrames(currentImage); isMotionDetected = compareFrames(currentImage);
} }
assert currentImage != null; assert currentImage != null;
@ -72,6 +82,18 @@ public class CameraSensor {
currentImage.close(); currentImage.close();
if (isMotionDetected) {
videoAlarmDetected = true;
if(alarmResetRunnable != null) {
alarmResetHandler.removeCallbacks(alarmResetRunnable);
}
alarmResetRunnable = this::resetAlarmStatus;
alarmResetHandler.postDelayed(alarmResetRunnable, ALARM_RESET_DELAY);
}
checkAlarmCondition(); checkAlarmCondition();
} }
@ -85,42 +107,82 @@ public class CameraSensor {
} }
private boolean compareFrames(Image currentImage) { private boolean compareFrames(Image currentImage) {
Image.Plane[] planes = currentImage.getPlanes();
ByteBuffer currentBuffer = currentImage.getPlanes()[0].getBuffer(); ByteBuffer currentBuffer = planes[0].getBuffer();
int currentWidth = currentImage.getWidth(); int currentWidth = currentImage.getWidth();
int currentHeight = currentImage.getHeight(); int currentHeight = currentImage.getHeight();
int yRowStride = planes[0].getRowStride();
int yPixelStride = planes[0].getPixelStride();
if (previousWidth != currentWidth || previousHeight != currentHeight) { if (previousWidth != currentWidth || previousHeight != currentHeight) {
return false; return false;
} }
for (int row = 0; row < previousHeight; row++) { int blockSize = kleinstesQuadrat(previousHeight, previousWidth) / 8;
for (int col = 0; col < previousWidth; col++) {
int previousIndex = row * previousWidth + col; int numBlocksX = currentWidth / blockSize;
int currentIndex = row * currentWidth + col; int numBlocksY = currentHeight / blockSize;
int previousPixel = previousBuffer.get(previousIndex) & 0xFF; for (int blockY = 0; blockY < numBlocksY; blockY++) {
int currentPixel = currentBuffer.get(currentIndex) & 0xFF; for (int blockX = 0; blockX < numBlocksX; blockX++) {
startX = blockX * blockSize;
startY = blockY * blockSize;
endX = startX + blockSize;
endY = startY + blockSize;
int pixelDifference = Math.abs(previousPixel - currentPixel); float currentLuminance = berechneMittlereLuminanz(currentBuffer, yRowStride, yPixelStride);
int threshold = 120; float previousLuminance = berechneMittlereLuminanz(previousBuffer, yRowStride, yPixelStride);
int pixelDifference = Math.abs((int) previousLuminance - (int) currentLuminance);
if (pixelDifference > threshold) { if (pixelDifference > threshold) {
System.out.println(pixelDifference);
return true; return true;
} }
} }
} }
return false; return false;
} }
private float berechneMittlereLuminanz(ByteBuffer buffer, int rowStride, int pixelStride) {
int sumLuminance = 0;
int countPixels = 0;
for (int row = startY; row < endY; row++) {
for (int col = startX; col < endX; col++) {
int bufferIndex = row * rowStride + col * pixelStride;
int currentPixel = buffer.get(bufferIndex) & 0xFF;
sumLuminance += currentPixel;
countPixels++;
}
}
return (float) sumLuminance / countPixels;
}
private int kleinstesQuadrat(int height, int width) {
if (height == width) {
return height;
} else if (height > width) {
return kleinstesQuadrat(height - width, width);
} else {
return kleinstesQuadrat(height, width - height);
}
}
private void resetAlarmStatus() {
videoAlarmDetected = false;
alarmResetRunnable = null;
}
public void checkAlarmCondition() { public void checkAlarmCondition() {
if (videoAlarmDetected && !mVideoAlarmDetected.getValue()) { if (videoAlarmDetected && !mVideoAlarmDetected.getValue()) {
setMutableLiveDataVideoMovementDetected(); setMutableLiveDataVideoAlarmDetected();
} }
else if (!videoAlarmDetected && mVideoAlarmDetected.getValue()){ else if (!videoAlarmDetected && mVideoAlarmDetected.getValue()){
setMutableLiveDataVideoMovementDetected(); setMutableLiveDataVideoAlarmDetected();
} }
} }
} }

View File

@ -0,0 +1,23 @@
package com.example.greenwatch.sensors.MicrofonHelperClasses;
public class GleitenderMittelwert {
private final float wichtungNeuerWert;
private final float wichtungAlterWert;
private float mittelwert = 0;
private boolean istMittelwertGesetzt = false;
public GleitenderMittelwert(float wichtungNeuerWert) {
this.wichtungNeuerWert = wichtungNeuerWert;
this.wichtungAlterWert = 1 - this.wichtungNeuerWert;
}
public float mittel(float wert) {
if (istMittelwertGesetzt) {
mittelwert = wert * wichtungNeuerWert + mittelwert * wichtungAlterWert;
} else {
mittelwert = wert;
istMittelwertGesetzt = true;
}
return mittelwert;
}}

View File

@ -0,0 +1,38 @@
package com.example.greenwatch.sensors.MicrofonHelperClasses;
public class RingPuffer {
private short[] puffer;
private final int laenge;
private int anzahlEnthaltenerDaten;
private int position;
public RingPuffer(int n) {
laenge = n;
anzahlEnthaltenerDaten = 0;
position = 0;
puffer = new short[laenge];
}
public void hinzufuegen(short wert) {
puffer[position] = wert;
position++;
if (position >= laenge) {
position = 0;
}
if (anzahlEnthaltenerDaten < laenge) {
anzahlEnthaltenerDaten++;
}
}
public short maximum() {
short max = 0;
for (int i = 0; i < anzahlEnthaltenerDaten; i++) {
if (puffer[i] > max) {
max = puffer[i];
}
}
return max;
}
}

View File

@ -0,0 +1,37 @@
package com.example.greenwatch.sensors.MicrofonHelperClasses;
public class Verarbeitungsergebnis {
private String status;
private short maxAmp;
private float db;
//
public Verarbeitungsergebnis(String status, short maxAmp, int db) {
this.status = status;
this.maxAmp = maxAmp;
this.db = db;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public short getMaxAmp() {
return maxAmp;
}
public void setMaxAmp(short maxAmp) {
this.maxAmp = maxAmp;
}
public float getDB() {
return db;
}
public void setDB(float db) {
this.db = db;
}
}

View File

@ -0,0 +1,201 @@
package com.example.greenwatch.sensors;
import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;
import android.os.AsyncTask;
import androidx.lifecycle.MutableLiveData;
import com.example.greenwatch.sensors.MicrofonHelperClasses.GleitenderMittelwert;
import com.example.greenwatch.sensors.MicrofonHelperClasses.RingPuffer;
import com.example.greenwatch.sensors.MicrofonHelperClasses.Verarbeitungsergebnis;
public class MicrofonSensor {
private MutableLiveData<Boolean> mMicrofonAlarmDetected = new MutableLiveData<>();
private AufnahmeTask aufnahmeTask;
private static MicrofonSensor microfonSensorInstance;
private boolean microfonAlarmDetected = false;
private boolean kalibrierung_do = true;
private float threshold = 40;
private float sensitivity = 10;
private float amplitudeInDB = 0;
private RingPuffer ringPuffer = new RingPuffer(10);
private MicrofonSensor() {
}
public static synchronized MicrofonSensor getInstance() {
if (microfonSensorInstance == null){
microfonSensorInstance = new MicrofonSensor();
}
return microfonSensorInstance;
}
public void start() {
aufnahmeTask = new AufnahmeTask();
aufnahmeTask.execute();
}
public void stop() {
if(aufnahmeTask !=null) {
aufnahmeTask.cancel(true);
aufnahmeTask = null;
}
}
public void doRecalibration() {
stop();
microfonAlarmDetected = false;
kalibrierung_do = true;
threshold = 40;
sensitivity = 10;
amplitudeInDB = 0;
}
public float getAmplitudeInDB() {
return amplitudeInDB;
}
private void setAmplitudeInDB(float amplitudeInDB) {
this.amplitudeInDB = amplitudeInDB;
}
public MutableLiveData<Boolean> getAccelerometerAlarmDetected() {
setMutableLiveDataMicrofonAlarmDetected();
return mMicrofonAlarmDetected;
}
private void setMutableLiveDataMicrofonAlarmDetected() {
mMicrofonAlarmDetected.setValue(microfonAlarmDetected);
}
class AufnahmeTask extends AsyncTask<Long, Verarbeitungsergebnis, Void> {
private AudioRecord recorder;
private final int sampleRateInHz = 44100;
private final int channelConfig = AudioFormat.CHANNEL_IN_MONO;
private final int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
private int minPufferGroesseInBytes;
private int pufferGroesseInBytes;
public AufnahmeTask() {
minPufferGroesseInBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
pufferGroesseInBytes = minPufferGroesseInBytes * 2;
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRateInHz, channelConfig, audioFormat, pufferGroesseInBytes);
}
public float kalibrieren(short[] puffer){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
int anzahlIterationen = 100;
float sum = 0.0f;
for(int i = 0; i < anzahlIterationen; i++){
int z = recorder.read(puffer, 0, puffer.length);
Verarbeitungsergebnis kalibrierung = verarbeiten(puffer, z);
sum += kalibrierung.getDB();
}
return sum/anzahlIterationen;
}
public void Detektion(Verarbeitungsergebnis ergebnis){
if(ergebnis.getDB() >= (threshold+sensitivity)){
microfonAlarmDetected = true;
}
else if (ergebnis.getDB() <= (threshold)) {
microfonAlarmDetected = false;
}
}
@Override
protected Void doInBackground(Long... params) {
recorder.startRecording();
short[] puffer = new short[pufferGroesseInBytes / 2];
GleitenderMittelwert gleitenderMittelwertdB = new GleitenderMittelwert(0.2f);
float db = 0.0f;
//kalibrierung
if(kalibrierung_do){
threshold = kalibrieren(puffer);
kalibrierung_do = false;
}
for (; ; ) {
if (isCancelled()) {
break;
}
else {
//ergebnis ermitteln
int n = recorder.read(puffer, 0, puffer.length);
Verarbeitungsergebnis ergebnis = verarbeiten(puffer, n);
//Mittelwertberechnnung
db = ergebnis.getDB();
db = gleitenderMittelwertdB.mittel(db);
ergebnis.setDB(db);
//Db Wert mit Schwellwert vergleichen und Warnung setzen
Detektion(ergebnis);
publishProgress(ergebnis);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
recorder.release();
return null;
}
private Verarbeitungsergebnis verarbeiten(short[] daten, int n) {
String status;
short maxAmp = -1;
int db = 0, db_wert = 0;
if (n == AudioRecord.ERROR_INVALID_OPERATION) {
status = "ERROR_INVALID_OPERATION";
} else if (n == AudioRecord.ERROR_BAD_VALUE) {
status = "ERROR_BAD_VALUE";
} else {
status = "OK";
short max = 0;
for (int i = 0; i < n; i++) {
if (daten[i] > max) {
max = daten[i];
}
}
ringPuffer.hinzufuegen(max);
maxAmp = ringPuffer.maximum();
}
//Umwandlung Amplitudenwert in dB
db_wert = (int) (20*Math.log10(maxAmp));
if (db_wert > 0){
db = db_wert;
}
return new Verarbeitungsergebnis(status, maxAmp, db);
}
@Override
protected void onProgressUpdate(Verarbeitungsergebnis... progress) {
super.onProgressUpdate(progress);
setAmplitudeInDB(progress[0].getDB());
if (microfonAlarmDetected != mMicrofonAlarmDetected.getValue()){
setMutableLiveDataMicrofonAlarmDetected();
}
//textViewMaxAmpdb.setText("" + progress[0].db);
}
}
}

View File

@ -1,89 +1,81 @@
package com.example.greenwatch.viewmodels; package com.example.greenwatch.viewmodels;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.view.SurfaceHolder;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import com.example.greenwatch.alarmrecorder.AlarmRecorder;
import com.example.greenwatch.models.Device; import com.example.greenwatch.models.Device;
import com.example.greenwatch.repositories.DeviceRepository; import com.example.greenwatch.repositories.DeviceRepository;
import com.example.greenwatch.sensors.AccelerometerSensor;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
public class AccelerometerViewModel extends ViewModel implements ViewModelInterface { public class AccelerometerViewModel extends ViewModel implements ViewModelInterface {
private MutableLiveData<List<Device>> mDeviceList; private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>(); private MutableLiveData<Boolean> mAccelerometerAlarmDetected;
private MutableLiveData<List<Device>> mAlarmHistoryList; private MutableLiveData<List<Device>> mAlarmHistoryList;
private MutableLiveData<Boolean> mStartAlarmRecording;
private AccelerometerSensor mAccelerometerSensor;
private AlarmRecorder mAlarmRecorder;
private DeviceRepository mDeviceRepository; private DeviceRepository mDeviceRepository;
private ArrayList<Float> Gesamt_be;
int arraySize = 500;
int functionCallCount;
float meanValue;
float offsetValue;
float thresholdValue;
boolean startMeasuring;
@Override @Override
public void init() { public void init(SurfaceHolder previewHolder) {
if (mDeviceList == null) { if (mDeviceRepository == null) {
mDeviceRepository = DeviceRepository.getInstance(); mDeviceRepository = DeviceRepository.getInstance();
}
if (mAccelerometerSensor == null) {
mAccelerometerSensor = AccelerometerSensor.getInstance();
}
if (mAlarmRecorder == null) {
mAlarmRecorder = AlarmRecorder.getInstance();
}
if (mDeviceList == null) {
mDeviceList = mDeviceRepository.getConnectedDeviceList(); mDeviceList = mDeviceRepository.getConnectedDeviceList();
}
if (mAlarmHistoryList == null) {
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
} }
initGesamtBE(); if (mStartAlarmRecording == null) {
mMovementDetected.setValue(false); mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
functionCallCount = 0;
meanValue = 0f;
offsetValue = 0.1f;
thresholdValue = 0.15f;
startMeasuring = false;
}
public void initGesamtBE() {
Gesamt_be = new ArrayList<>(arraySize);
for (int i = 0; i < arraySize; i++) {
Gesamt_be.add(0f);
} }
if (mAccelerometerAlarmDetected == null) {
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected();
}
setAlarmRecordingPreviewHolder(previewHolder);
} }
public void addValueToGesamtBE(float newValue) { public void addValueToGesamtBE(float newValue) {
if (Gesamt_be.size() == arraySize) { mAccelerometerSensor.addValueToGesamtBE(newValue);
Gesamt_be.remove(Gesamt_be.size() -1);
}
Gesamt_be.add(0, newValue);
functionCallCount++;
} }
public void meanValueCalculation() { public void meanValueCalculation() {
for (float element : Gesamt_be) { mAccelerometerSensor.meanValueCalculation();
meanValue += Math.abs(element);
}
meanValue = meanValue/arraySize;
} }
public void calibrateAccelerometerSensor() { public void calibrateAccelerometerSensor() {
if (functionCallCount <= arraySize) { mAccelerometerSensor.calibrateAccelerometerSensor();
offsetValue = meanValue;
}
else {
startMeasuring = true;
}
} }
public void checkAlarmCondition() { public void checkAlarmCondition() {
if (meanValue > (thresholdValue + offsetValue) && startMeasuring && !mMovementDetected.getValue()) { mAccelerometerSensor.checkAlarmCondition();
mMovementDetected.setValue(true);
}
else if (meanValue < (thresholdValue + offsetValue) && mMovementDetected.getValue()){
mMovementDetected.setValue(false);
}
} }
public LiveData<Boolean> getMovementDetectedValue() { public float getAccelerometerSensorMeanValue() {
return mMovementDetected; return mAccelerometerSensor.getAccelerometerSensorMeanValue();
}
public LiveData<Boolean> getAccelerometerAlarmDetected() {
return mAccelerometerAlarmDetected;
} }
@Override @Override
@ -97,7 +89,12 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
} }
@Override @Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { public LiveData<Boolean> getStartAlarmRecording() {
return mStartAlarmRecording;
}
@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, float sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
} }
@ -142,12 +139,12 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
} }
@Override @Override
public void setSensorMassage(String deviceID, int sensorMessage) { public void setSensorMassage(String deviceID, float sensorMessage) {
mDeviceRepository.setSensorMassage(deviceID, sensorMessage); mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
} }
@Override @Override
public int getSensorMassage(String deviceID) { public float getSensorMassage(String deviceID) {
return mDeviceRepository.getSensorMassage(deviceID); return mDeviceRepository.getSensorMassage(deviceID);
} }
@ -160,4 +157,19 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
public String getSystemTimeStamp() { public String getSystemTimeStamp() {
return mDeviceRepository.getSystemTimeStamp(); return mDeviceRepository.getSystemTimeStamp();
} }
@Override
public void startAlarmRecording() {
mAlarmRecorder.startRecording();
}
@Override
public void stopAlarmRecording(Context context) {
mAlarmRecorder.stopRecording(context);
}
@Override
public void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder) {
mAlarmRecorder.setPreviewHolder(previewHolder);
}
} }

View File

@ -0,0 +1,258 @@
package com.example.greenwatch.viewmodels;
import android.content.Context;
import android.view.SurfaceHolder;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;
import com.example.greenwatch.alarmrecorder.AlarmRecorder;
import com.example.greenwatch.models.Device;
import com.example.greenwatch.repositories.DeviceRepository;
import com.example.greenwatch.sensors.AccelerometerSensor;
import com.example.greenwatch.sensors.MicrofonSensor;
import java.util.List;
public class AudiodetectionAndAccelerometerViewModel extends ViewModel implements ViewModelInterface {
private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<Boolean> mAccelerometerAlarmDetected;
private MutableLiveData<Boolean> mMicrofonAlarmDetected;
private MutableLiveData<Boolean> mAudiodetectionAndAccelerometerAlarmDetected = new MutableLiveData<>();
private MutableLiveData<List<Device>> mAlarmHistoryList;
private MutableLiveData<Boolean> mStartAlarmRecording;
private AccelerometerSensor mAccelerometerSensor;
private MicrofonSensor mMicrofonSensor;
private AlarmRecorder mAlarmRecorder;
private DeviceRepository mDeviceRepository;
private boolean microfonAlarmDetected;
private boolean accelerometerAlarmDetected;
private boolean microfondetectionAndAccelerometerAlarmDetected;
public void init() {
}
public void addValueToGesamtBE(float newValue) {
mAccelerometerSensor.addValueToGesamtBE(newValue);
}
public void meanValueCalculation() {
mAccelerometerSensor.meanValueCalculation();
}
public void calibrateAccelerometerSensor() {
mAccelerometerSensor.calibrateAccelerometerSensor();
}
public void checkAlarmCondition() {
mAccelerometerSensor.checkAlarmCondition();
}
public float getAccelerometerSensorMeanValue() {
return mAccelerometerSensor.getAccelerometerSensorMeanValue();
}
public LiveData<Boolean> getAudiodetectionAndAccelerometerAlarmDetected() {
setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected();
return mAudiodetectionAndAccelerometerAlarmDetected;
}
public void startMicrofonSensor() {
mMicrofonSensor.start();
}
public void stopMicrofonSensor() {
mMicrofonSensor.stop();
}
public void recalibrationMicrofonSensor() {
mMicrofonSensor.doRecalibration();
}
public float getAmplitudeInDB() {
return mMicrofonSensor.getAmplitudeInDB();
}
private void setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected() {
mAudiodetectionAndAccelerometerAlarmDetected.setValue(microfondetectionAndAccelerometerAlarmDetected);
}
private void setAccelerometerAlarmDetected(boolean accelerometerAlarmDetected) {
this.accelerometerAlarmDetected = accelerometerAlarmDetected;
}
public boolean getAccelerometerAlarmDetected() {
return accelerometerAlarmDetected;
}
private void setMicrofonAlarmDetected(boolean microfonAlarmDetected) {
this.microfonAlarmDetected = microfonAlarmDetected;
}
public boolean getMicrofonAlarmDetected() {
return microfonAlarmDetected;
}
Observer<Boolean> observer = new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
setAccelerometerAlarmDetected(mAccelerometerAlarmDetected.getValue());
setMicrofonAlarmDetected(mMicrofonAlarmDetected.getValue());
if (microfonAlarmDetected || accelerometerAlarmDetected) {
microfondetectionAndAccelerometerAlarmDetected = true;
setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected();
}
else if (!microfonAlarmDetected && !accelerometerAlarmDetected) {
microfondetectionAndAccelerometerAlarmDetected = false;
setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected();
}
}
};
private void registerAlarmObserver() {
mMicrofonAlarmDetected.observeForever(observer);
mAccelerometerAlarmDetected.observeForever(observer);
}
@Override
protected void onCleared() {
super.onCleared();
mMicrofonAlarmDetected.removeObserver(observer);
mAccelerometerAlarmDetected.removeObserver(observer);
}
@Override
public void init(SurfaceHolder previewHolder) {
if (mDeviceRepository == null) {
mDeviceRepository = DeviceRepository.getInstance();
}
if (mAccelerometerSensor == null) {
mAccelerometerSensor = AccelerometerSensor.getInstance();
}
if (mMicrofonSensor == null) {
mMicrofonSensor = MicrofonSensor.getInstance();
}
if (mAlarmRecorder == null) {
mAlarmRecorder = AlarmRecorder.getInstance();
}
if (mDeviceList == null) {
mDeviceList = mDeviceRepository.getConnectedDeviceList();
}
if (mAlarmHistoryList == null) {
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
}
if (mStartAlarmRecording == null) {
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
}
if (mAccelerometerAlarmDetected == null) {
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected();
}
if (mMicrofonAlarmDetected == null) {
mMicrofonAlarmDetected = mMicrofonSensor.getAccelerometerAlarmDetected();
}
microfondetectionAndAccelerometerAlarmDetected = false;
accelerometerAlarmDetected = false;
microfonAlarmDetected = false;
registerAlarmObserver();
setAlarmRecordingPreviewHolder(previewHolder);
}
@Override
public LiveData<List<Device>> getConnectedDeviceList() {
return mDeviceList;
}
@Override
public LiveData<List<Device>> getAlarmHistoryList() {
return mAlarmHistoryList;
}
@Override
public LiveData<Boolean> getStartAlarmRecording() {
return mStartAlarmRecording;
}
@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, float sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
}
@Override
public void setTimeStamp(String deviceID, String timeStamp) {
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
}
@Override
public String getTimeStamp(String deviceID) {
return mDeviceRepository.getTimeStamp(deviceID);
}
@Override
public void setDeviceID(String deviceID, String newDeviceID) {
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
}
@Override
public String getDeviceID(String deviceID) {
return mDeviceRepository.getDeviceID(deviceID);
}
@Override
public void setSensorStatus(String deviceID, boolean sensorStatus) {
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
}
@Override
public boolean getSensorStatus(String deviceID) {
return mDeviceRepository.getSensorStatus(deviceID);
}
@Override
public void setSensorType(String deviceID, String sensorType) {
mDeviceRepository.setSensorType(deviceID, sensorType);
}
@Override
public String getSensorType(String deviceID) {
return mDeviceRepository.getSensorType(deviceID);
}
@Override
public void setSensorMassage(String deviceID, float sensorMessage) {
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
}
@Override
public float getSensorMassage(String deviceID) {
return mDeviceRepository.getSensorMassage(deviceID);
}
@Override
public String getLocalDeviceUUID() {
return mDeviceRepository.getLocalDeviceUUID();
}
@Override
public String getSystemTimeStamp() {
return mDeviceRepository.getSystemTimeStamp();
}
@Override
public void startAlarmRecording() {
mAlarmRecorder.startRecording();
}
@Override
public void stopAlarmRecording(Context context) {
mAlarmRecorder.stopRecording(context);
}
@Override
public void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder) {
mAlarmRecorder.setPreviewHolder(previewHolder);
}
}

View File

@ -1,8 +1,10 @@
package com.example.greenwatch.viewmodels; package com.example.greenwatch.viewmodels;
import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.view.SurfaceHolder;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@ -10,9 +12,11 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import com.example.greenwatch.alarmrecorder.AlarmRecorder;
import com.example.greenwatch.communication.WiFiCommunication; import com.example.greenwatch.communication.WiFiCommunication;
import com.example.greenwatch.models.Device; import com.example.greenwatch.models.Device;
import com.example.greenwatch.repositories.DeviceRepository; import com.example.greenwatch.repositories.DeviceRepository;
import com.example.greenwatch.sensors.AccelerometerSensor;
import java.util.List; import java.util.List;
@ -20,31 +24,38 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
private MutableLiveData<List<Device>> mDeviceList; private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<List<Device>> mAlarmHistoryList; private MutableLiveData<List<Device>> mAlarmHistoryList;
private MutableLiveData<Boolean> mStartAlarmRecording;
private DeviceRepository mDeviceRepository; private DeviceRepository mDeviceRepository;
private static final int RECHTEANFORDERUNG_KAMERA = 10; private WiFiCommunication mWiFiCommunication;
private AlarmRecorder mAlarmRecorder;
@Override @Override
public void init() { public void init(SurfaceHolder previewHolder) {
WiFiCommunication mWiFiCommunication;
if(mDeviceList != null) { if (mDeviceRepository == null) {
return; mDeviceRepository = DeviceRepository.getInstance();
}
if (mWiFiCommunication == null) {
mWiFiCommunication = WiFiCommunication.getInstance();
}
if (mAlarmRecorder == null) {
mAlarmRecorder = AlarmRecorder.getInstance();
}
if (mDeviceList == null) {
mDeviceList = mDeviceRepository.getConnectedDeviceList();
}
if (mAlarmHistoryList == null) {
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
}
if (mStartAlarmRecording == null) {
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
} }
//todo: check if WiFi instanz can be hold only by the repository
mDeviceRepository = DeviceRepository.getInstance();
mWiFiCommunication = WiFiCommunication.getInstance();
mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
mWiFiCommunication.setDeviceRepository(mDeviceRepository); mWiFiCommunication.setDeviceRepository(mDeviceRepository);
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0); mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
mDeviceList = mDeviceRepository.getConnectedDeviceList(); mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0.0f);
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); mDeviceRepository.setDeviceID(mDeviceRepository.getLocalDeviceUUID(), WiFiCommunication.getLocalIpAddress());
} setAlarmRecordingPreviewHolder(previewHolder);
mWiFiCommunication = null;
public boolean isCameraAccessAllowed(Context context) {
return ContextCompat.checkSelfPermission(context, android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
}
public void accessRequestCamera(Activity activity) {
ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.CAMERA}, RECHTEANFORDERUNG_KAMERA);
} }
@Override @Override
@ -58,7 +69,12 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
} }
@Override @Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { public LiveData<Boolean> getStartAlarmRecording() {
return mStartAlarmRecording;
}
@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, float sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
} }
@ -103,12 +119,12 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
} }
@Override @Override
public void setSensorMassage(String deviceID, int sensorMessage) { public void setSensorMassage(String deviceID, float sensorMessage) {
mDeviceRepository.setSensorMassage(deviceID, sensorMessage); mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
} }
@Override @Override
public int getSensorMassage(String deviceID) { public float getSensorMassage(String deviceID) {
return mDeviceRepository.getSensorMassage(deviceID); return mDeviceRepository.getSensorMassage(deviceID);
} }
@ -119,6 +135,21 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
@Override @Override
public String getSystemTimeStamp() { public String getSystemTimeStamp() {
return null; return mDeviceRepository.getSystemTimeStamp();
}
@Override
public void startAlarmRecording() {
mAlarmRecorder.startRecording();
}
@Override
public void stopAlarmRecording(Context context) {
mAlarmRecorder.stopRecording(context);
}
@Override
public void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder) {
mAlarmRecorder.setPreviewHolder(previewHolder);
} }
} }

View File

@ -0,0 +1,167 @@
package com.example.greenwatch.viewmodels;
import android.content.Context;
import android.view.SurfaceHolder;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.example.greenwatch.alarmrecorder.AlarmRecorder;
import com.example.greenwatch.models.Device;
import com.example.greenwatch.repositories.DeviceRepository;
import com.example.greenwatch.sensors.AccelerometerSensor;
import com.example.greenwatch.sensors.MicrofonSensor;
import java.util.List;
public class MicrofonViewModel extends ViewModel implements ViewModelInterface {
private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<Boolean> mMicrofonAlarmDetected;
private MutableLiveData<List<Device>> mAlarmHistoryList;
private MutableLiveData<Boolean> mStartAlarmRecording;
private MicrofonSensor mMicrofonSensor;
private DeviceRepository mDeviceRepository;
private AlarmRecorder mAlarmRecorder;
public void startMicrofonSensor() {
mMicrofonSensor.start();
}
public void stopMicrofonSensor() {
mMicrofonSensor.stop();
}
public void recalibrationMicrofonSensor() {
mMicrofonSensor.doRecalibration();
}
public float getAmplitudeInDB() {
return mMicrofonSensor.getAmplitudeInDB();
}
public LiveData<Boolean> getMicrofonAlarmDetected() {
return mMicrofonAlarmDetected;
}
@Override
public void init(SurfaceHolder previewHolder) {
if (mDeviceRepository == null) {
mDeviceRepository = DeviceRepository.getInstance();
}
if (mMicrofonSensor == null) {
mMicrofonSensor = MicrofonSensor.getInstance();
}
if (mAlarmRecorder == null) {
mAlarmRecorder = AlarmRecorder.getInstance();
}
if (mDeviceList == null) {
mDeviceList = mDeviceRepository.getConnectedDeviceList();
}
if (mAlarmHistoryList == null) {
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
}
if (mStartAlarmRecording == null) {
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
}
if (mMicrofonAlarmDetected == null) {
mMicrofonAlarmDetected = mMicrofonSensor.getAccelerometerAlarmDetected();
}
setAlarmRecordingPreviewHolder(previewHolder);
}
@Override
public LiveData<List<Device>> getConnectedDeviceList() {
return mDeviceList;
}
@Override
public LiveData<List<Device>> getAlarmHistoryList() {
return mAlarmHistoryList;
}
@Override
public LiveData<Boolean> getStartAlarmRecording() {
return mStartAlarmRecording;
}
@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, float sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
}
@Override
public void setTimeStamp(String deviceID, String timeStamp) {
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
}
@Override
public String getTimeStamp(String deviceID) {
return mDeviceRepository.getTimeStamp(deviceID);
}
@Override
public void setDeviceID(String deviceID, String newDeviceID) {
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
}
@Override
public String getDeviceID(String deviceID) {
return mDeviceRepository.getDeviceID(deviceID);
}
@Override
public void setSensorStatus(String deviceID, boolean sensorStatus) {
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
}
@Override
public boolean getSensorStatus(String deviceID) {
return mDeviceRepository.getSensorStatus(deviceID);
}
@Override
public void setSensorType(String deviceID, String sensorType) {
mDeviceRepository.setSensorType(deviceID, sensorType);
}
@Override
public String getSensorType(String deviceID) {
return mDeviceRepository.getSensorType(deviceID);
}
@Override
public void setSensorMassage(String deviceID, float sensorMessage) {
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
}
@Override
public float getSensorMassage(String deviceID) {
return mDeviceRepository.getSensorMassage(deviceID);
}
@Override
public String getLocalDeviceUUID() {
return mDeviceRepository.getLocalDeviceUUID();
}
@Override
public String getSystemTimeStamp() {
return mDeviceRepository.getSystemTimeStamp();
}
@Override
public void startAlarmRecording() {
mAlarmRecorder.startRecording();
}
@Override
public void stopAlarmRecording(Context context) {
mAlarmRecorder.stopRecording(context);
}
@Override
public void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder) {
mAlarmRecorder.setPreviewHolder(previewHolder);
}
}

View File

@ -0,0 +1,244 @@
package com.example.greenwatch.viewmodels;
import android.content.Context;
import android.view.SurfaceHolder;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;
import com.example.greenwatch.alarmrecorder.AlarmRecorder;
import com.example.greenwatch.models.Device;
import com.example.greenwatch.repositories.DeviceRepository;
import com.example.greenwatch.sensors.AccelerometerSensor;
import com.example.greenwatch.sensors.CameraSensor;
import java.util.List;
public class VideodetectionAndAccelerometerViewModel extends ViewModel implements ViewModelInterface{
private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<Boolean> mAccelerometerAlarmDetected;
private MutableLiveData<Boolean> mVideoAlarmDetected;
private MutableLiveData<Boolean> mVideodetectionAndAccelerometerAlarmDetected = new MutableLiveData<>();
private MutableLiveData<List<Device>> mAlarmHistoryList;
private MutableLiveData<Boolean> mStartAlarmRecording;
private AccelerometerSensor mAccelerometerSensor;
private CameraSensor mCameraSensor;
private DeviceRepository mDeviceRepository;
private AlarmRecorder mAlarmRecorder;
private boolean videoAlarmDetected;
private boolean accelerometerAlarmDetected;
private boolean videodetectionAndAccelerometerAlarmDetected;
public void addValueToGesamtBE(float newValue) {
mAccelerometerSensor.addValueToGesamtBE(newValue);
}
public void meanValueCalculation() {
mAccelerometerSensor.meanValueCalculation();
}
public void calibrateAccelerometerSensor() {
mAccelerometerSensor.calibrateAccelerometerSensor();
}
public void checkAlarmCondition() {
mAccelerometerSensor.checkAlarmCondition();
}
public float getAccelerometerSensorMeanValue() {
return mAccelerometerSensor.getAccelerometerSensorMeanValue();
}
public void bindImageAnalysis(ProcessCameraProvider cameraProvider, LifecycleOwner lifecycleOwner, Context context) {
mCameraSensor.bindImageAnalysis(cameraProvider, lifecycleOwner, context);
}
public LiveData<Boolean> getVideodetectionAndAccelerometerAlarmDetected() {
setMutableLiveDataVideodetectionAndAccelerometerAlarmDetected();
return mVideodetectionAndAccelerometerAlarmDetected;
}
private void setMutableLiveDataVideodetectionAndAccelerometerAlarmDetected() {
mVideodetectionAndAccelerometerAlarmDetected.setValue(videodetectionAndAccelerometerAlarmDetected);
}
private void setAccelerometerAlarmDetected(boolean accelerometerAlarmDetected) {
this.accelerometerAlarmDetected = accelerometerAlarmDetected;
}
public boolean getAccelerometerAlarmDetected() {
return accelerometerAlarmDetected;
}
private void setVideoAlarmDetected(boolean videoAlarmDetected) {
this.videoAlarmDetected = videoAlarmDetected;
}
public boolean getVideoAlarmDetected() {
return videoAlarmDetected;
}
Observer<Boolean> observer = new Observer<Boolean>() {
@Override
public void onChanged(Boolean aBoolean) {
setAccelerometerAlarmDetected(mAccelerometerAlarmDetected.getValue());
setVideoAlarmDetected(mVideoAlarmDetected.getValue());
if (videoAlarmDetected || accelerometerAlarmDetected && !videodetectionAndAccelerometerAlarmDetected) {
videodetectionAndAccelerometerAlarmDetected = true;
setMutableLiveDataVideodetectionAndAccelerometerAlarmDetected();
}
else if (!videoAlarmDetected && !accelerometerAlarmDetected && videodetectionAndAccelerometerAlarmDetected) {
videodetectionAndAccelerometerAlarmDetected = false;
setMutableLiveDataVideodetectionAndAccelerometerAlarmDetected();
}
}
};
private void registerAlarmObserver() {
mVideoAlarmDetected.observeForever(observer);
mAccelerometerAlarmDetected.observeForever(observer);
}
@Override
protected void onCleared() {
super.onCleared();
mVideoAlarmDetected.removeObserver(observer);
mAccelerometerAlarmDetected.removeObserver(observer);
}
@Override
public void init(SurfaceHolder previewHolder) {
if (mDeviceRepository == null) {
mDeviceRepository = DeviceRepository.getInstance();
}
if (mAccelerometerSensor == null) {
mAccelerometerSensor = AccelerometerSensor.getInstance();
}
if (mCameraSensor == null) {
mCameraSensor = CameraSensor.getInstance();
}
if (mAlarmRecorder == null) {
mAlarmRecorder = AlarmRecorder.getInstance();
}
if (mDeviceList == null) {
mDeviceList = mDeviceRepository.getConnectedDeviceList();
}
if (mAlarmHistoryList == null) {
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
}
if (mStartAlarmRecording == null) {
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
}
if (mAccelerometerAlarmDetected == null) {
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected();
}
if (mVideoAlarmDetected == null) {
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue();
}
videodetectionAndAccelerometerAlarmDetected = false;
videoAlarmDetected = false;
accelerometerAlarmDetected = false;
registerAlarmObserver();
setAlarmRecordingPreviewHolder(previewHolder);
}
@Override
public LiveData<List<Device>> getConnectedDeviceList() {
return mDeviceList;
}
@Override
public LiveData<List<Device>> getAlarmHistoryList() {
return mAlarmHistoryList;
}
@Override
public LiveData<Boolean> getStartAlarmRecording() {
return mStartAlarmRecording;
}
@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, float sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
}
@Override
public void setTimeStamp(String deviceID, String timeStamp) {
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
}
@Override
public String getTimeStamp(String deviceID) {
return mDeviceRepository.getTimeStamp(deviceID);
}
@Override
public void setDeviceID(String deviceID, String newDeviceID) {
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
}
@Override
public String getDeviceID(String deviceID) {
return mDeviceRepository.getDeviceID(deviceID);
}
@Override
public void setSensorStatus(String deviceID, boolean sensorStatus) {
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
}
@Override
public boolean getSensorStatus(String deviceID) {
return mDeviceRepository.getSensorStatus(deviceID);
}
@Override
public void setSensorType(String deviceID, String sensorType) {
mDeviceRepository.setSensorType(deviceID, sensorType);
}
@Override
public String getSensorType(String deviceID) {
return mDeviceRepository.getSensorType(deviceID);
}
@Override
public void setSensorMassage(String deviceID, float sensorMessage) {
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
}
@Override
public float getSensorMassage(String deviceID) {
return mDeviceRepository.getSensorMassage(deviceID);
}
@Override
public String getLocalDeviceUUID() {
return mDeviceRepository.getLocalDeviceUUID();
}
@Override
public String getSystemTimeStamp() {
return mDeviceRepository.getSystemTimeStamp();
}
@Override
public void startAlarmRecording() {
mAlarmRecorder.startRecording();
}
@Override
public void stopAlarmRecording(Context context) {
mAlarmRecorder.stopRecording(context);
}
@Override
public void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder) {
mAlarmRecorder.setPreviewHolder(previewHolder);
}
}

View File

@ -1,6 +1,7 @@
package com.example.greenwatch.viewmodels; package com.example.greenwatch.viewmodels;
import android.content.Context; import android.content.Context;
import android.view.SurfaceHolder;
import androidx.camera.lifecycle.ProcessCameraProvider; import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
@ -8,6 +9,7 @@ import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import com.example.greenwatch.alarmrecorder.AlarmRecorder;
import com.example.greenwatch.models.Device; import com.example.greenwatch.models.Device;
import com.example.greenwatch.repositories.DeviceRepository; import com.example.greenwatch.repositories.DeviceRepository;
import com.example.greenwatch.sensors.CameraSensor; import com.example.greenwatch.sensors.CameraSensor;
@ -19,7 +21,9 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
private MutableLiveData<List<Device>> mDeviceList; private MutableLiveData<List<Device>> mDeviceList;
private MutableLiveData<Boolean> mVideoAlarmDetected; private MutableLiveData<Boolean> mVideoAlarmDetected;
private MutableLiveData<List<Device>> mAlarmHistoryList; private MutableLiveData<List<Device>> mAlarmHistoryList;
private MutableLiveData<Boolean> mStartAlarmRecording;
private DeviceRepository mDeviceRepository; private DeviceRepository mDeviceRepository;
private AlarmRecorder mAlarmRecorder;
private CameraSensor mCameraSensor; private CameraSensor mCameraSensor;
@ -28,22 +32,29 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
} }
@Override @Override
public void init() { public void init(SurfaceHolder previewHolder) {
if (mDeviceRepository == null) { if (mDeviceRepository == null) {
mDeviceRepository = DeviceRepository.getInstance(); mDeviceRepository = DeviceRepository.getInstance();
} }
if (mCameraSensor == null) { if (mCameraSensor == null) {
mCameraSensor = CameraSensor.getInstance(); mCameraSensor = CameraSensor.getInstance();
} }
if (mAlarmRecorder == null) {
mAlarmRecorder = AlarmRecorder.getInstance();
}
if (mDeviceList == null) { if (mDeviceList == null) {
mDeviceList = mDeviceRepository.getConnectedDeviceList(); mDeviceList = mDeviceRepository.getConnectedDeviceList();
} }
if (mAlarmHistoryList == null) { if (mAlarmHistoryList == null) {
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
} }
if (mStartAlarmRecording == null) {
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
}
if (mVideoAlarmDetected == null) { if (mVideoAlarmDetected == null) {
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue(); mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue();
} }
setAlarmRecordingPreviewHolder(previewHolder);
} }
public void bindImageAnalysis(ProcessCameraProvider cameraProvider, LifecycleOwner lifecycleOwner, Context context) { public void bindImageAnalysis(ProcessCameraProvider cameraProvider, LifecycleOwner lifecycleOwner, Context context) {
@ -65,7 +76,12 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
} }
@Override @Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { public LiveData<Boolean> getStartAlarmRecording() {
return mStartAlarmRecording;
}
@Override
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, float sensorMassage) {
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
} }
@ -110,12 +126,12 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
} }
@Override @Override
public void setSensorMassage(String deviceID, int sensorMessage) { public void setSensorMassage(String deviceID, float sensorMessage) {
mDeviceRepository.setSensorMassage(deviceID, sensorMessage); mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
} }
@Override @Override
public int getSensorMassage(String deviceID) { public float getSensorMassage(String deviceID) {
return mDeviceRepository.getSensorMassage(deviceID); return mDeviceRepository.getSensorMassage(deviceID);
} }
@ -128,4 +144,19 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
public String getSystemTimeStamp() { public String getSystemTimeStamp() {
return mDeviceRepository.getSystemTimeStamp(); return mDeviceRepository.getSystemTimeStamp();
} }
@Override
public void startAlarmRecording() {
mAlarmRecorder.startRecording();
}
@Override
public void stopAlarmRecording(Context context) {
mAlarmRecorder.stopRecording(context);
}
@Override
public void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder) {
mAlarmRecorder.setPreviewHolder(previewHolder);
}
} }

View File

@ -1,5 +1,8 @@
package com.example.greenwatch.viewmodels; package com.example.greenwatch.viewmodels;
import android.content.Context;
import android.view.SurfaceHolder;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import com.example.greenwatch.models.Device; import com.example.greenwatch.models.Device;
@ -7,10 +10,11 @@ import com.example.greenwatch.models.Device;
import java.util.List; import java.util.List;
public interface ViewModelInterface { public interface ViewModelInterface {
void init(); void init(SurfaceHolder previewHolder);
LiveData<List<Device>> getConnectedDeviceList(); LiveData<List<Device>> getConnectedDeviceList();
LiveData<List<Device>> getAlarmHistoryList(); LiveData<List<Device>> getAlarmHistoryList();
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage); LiveData<Boolean> getStartAlarmRecording();
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, float sensorMassage);
void setTimeStamp(String deviceID, String timeStamp); void setTimeStamp(String deviceID, String timeStamp);
String getTimeStamp(String deviceID); String getTimeStamp(String deviceID);
void setDeviceID(String deviceID, String newDeviceID); void setDeviceID(String deviceID, String newDeviceID);
@ -19,8 +23,11 @@ public interface ViewModelInterface {
boolean getSensorStatus(String deviceID); boolean getSensorStatus(String deviceID);
void setSensorType(String deviceID, String sensorType); void setSensorType(String deviceID, String sensorType);
String getSensorType(String deviceID); String getSensorType(String deviceID);
void setSensorMassage(String deviceID, int sensorMessage); void setSensorMassage(String deviceID, float sensorMessage);
int getSensorMassage(String deviceID); float getSensorMassage(String deviceID);
String getLocalDeviceUUID(); String getLocalDeviceUUID();
String getSystemTimeStamp(); String getSystemTimeStamp();
void startAlarmRecording();
void stopAlarmRecording(Context context);
void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder);
} }

View File

@ -8,11 +8,19 @@
android:padding="10dp" android:padding="10dp"
tools:context=".AccelerometerActivity"> tools:context=".AccelerometerActivity">
<SurfaceView
android:id="@+id/surfaceViewAccelerometer"
android:layout_width="1dp"
android:layout_height="1dp"
android:visibility="visible">
</SurfaceView>
<TextView <TextView
android:id="@+id/tvAccelerometerStatusmessage" android:id="@+id/tvAccelerometerStatusmessage"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text=""> android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Accelerometer Activity">
</TextView> </TextView>
<TextView <TextView
@ -22,13 +30,6 @@
android:text=""> android:text="">
</TextView> </TextView>
<TextView
android:id="@+id/tvAccelerometerWarning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="">
</TextView>
<Button <Button
android:id="@+id/accelerometerBackToMainActivity" android:id="@+id/accelerometerBackToMainActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -41,6 +42,14 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:id="@+id/tvAccelerometerdeviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Registered Devices">
</TextView>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/deviceListRecyclerView" android:id="@+id/deviceListRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -49,6 +58,14 @@
android:layout_weight="1"> android:layout_weight="1">
</androidx.recyclerview.widget.RecyclerView> </androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="@+id/tvAccelerometeralarmHistoryListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Alarm History List">
</TextView>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/alarmHistoryListRecyclerView" android:id="@+id/alarmHistoryListRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -8,13 +8,28 @@
android:padding="10dp" android:padding="10dp"
tools:context=".AudiodetectionActivity"> tools:context=".AudiodetectionActivity">
<SurfaceView
android:id="@+id/surfaceViewAudio"
android:layout_width="1dp"
android:layout_height="1dp"
android:visibility="visible">
</SurfaceView>
<TextView <TextView
android:id="@+id/tvAudiodetectionStatusmessage" android:id="@+id/tvAudiodetectionStatusmessage"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Audiodetection Activity"> android:text="Audiodetection Activity">
</TextView> </TextView>
<TextView
android:id="@+id/tvAudiodetectionData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="">
</TextView>
<Button <Button
android:id="@+id/audiodetectorBackToMainActivity" android:id="@+id/audiodetectorBackToMainActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -22,4 +37,43 @@
android:text="Back to MainActivity"> android:text="Back to MainActivity">
</Button> </Button>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tvAudiodetectionDeviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Registered Devices">
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/deviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/device_item"
android:layout_weight="1">
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="@+id/tvAudiodetectionAlarmHistoryListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Alarm History List">
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/alarmHistoryListRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/alarm_history_item"
android:layout_weight="1">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -8,11 +8,19 @@
android:padding="10dp" android:padding="10dp"
tools:context=".AudiodetectionAndAccelerometerActivity"> tools:context=".AudiodetectionAndAccelerometerActivity">
<SurfaceView
android:id="@+id/surfaceViewAudiodetectionAndAccelerometer"
android:layout_width="1dp"
android:layout_height="1dp"
android:visibility="visible">
</SurfaceView>
<TextView <TextView
android:id="@+id/tvAudiodetectionAndAccelerometerStatusmessage" android:id="@+id/tvAudiodetectionAndAccelerometerStatusmessage"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Audiodetection + Accelerometer Activity"> android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Audiodetection+Accelerometer Activity">
</TextView> </TextView>
<Button <Button
@ -22,4 +30,43 @@
android:text="Back to MainActivity"> android:text="Back to MainActivity">
</Button> </Button>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tvAudiodetectionAndAccelerometerDeviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Registered Devices">
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/deviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/device_item"
android:layout_weight="1">
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="@+id/tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Alarm History List">
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/alarmHistoryListRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/alarm_history_item"
android:layout_weight="1">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -5,9 +5,33 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:padding="10dp" android:padding="5dp"
tools:context=".MainActivity"> tools:context=".MainActivity">
<TextView
android:id="@+id/tvMainActivityDeviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Registered Devices">
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/deviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
tools:listitem="@layout/device_item">
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="@+id/tvMainActivityAlarmHistoryListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Alarm History List">
</TextView>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/alarmHistoryListRecyclerView" android:id="@+id/alarmHistoryListRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -16,67 +40,90 @@
tools:listitem="@layout/alarm_history_item"> tools:listitem="@layout/alarm_history_item">
</androidx.recyclerview.widget.RecyclerView> </androidx.recyclerview.widget.RecyclerView>
<androidx.recyclerview.widget.RecyclerView <SurfaceView
android:id="@+id/deviceListRecyclerView" android:id="@+id/surfaceViewMainActivity"
android:layout_width="match_parent" android:layout_width="1dp"
android:layout_height="match_parent" android:layout_height="1dp">
android:layout_weight="3" </SurfaceView>
tools:listitem="@layout/device_item">
</androidx.recyclerview.widget.RecyclerView>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:layout_weight="3"> android:layout_weight="3">
<Button <LinearLayout
android:id="@+id/audiodetectionButton"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:orientation="horizontal"
android:text="Audiodetection"> android:layout_weight="1">
</Button>
<Button <Button
android:id="@+id/videodetectionButton" android:id="@+id/audiodetectionButton"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_marginEnd="2dp"
android:text="Videodetection"> android:layout_gravity="center_vertical"
</Button> android:layout_weight="1"
android:text="Audiodetection">
</Button>
<Button <Button
android:id="@+id/accelerometerButton" android:id="@+id/videodetectionButton"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_marginStart="2dp"
android:text="Accelerometer"> android:layout_gravity="center_vertical"
</Button> android:layout_weight="1"
android:text="Videodetection">
</Button>
<Button </LinearLayout>
android:id="@+id/audiodetectionAndAccelerometerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Audiodetection + Accelerometer">
</Button>
<Button <LinearLayout
android:id="@+id/videodetectionAndAccelerometerButton"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:orientation="horizontal"
android:text="Videodetection + Accelerometer"> android:layout_weight="1">
</Button>
<Button <Button
android:id="@+id/connectionButton" android:id="@+id/accelerometerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="Accelerometer">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_weight="1" android:orientation="horizontal"
android:text="Connect to Devices"> android:layout_weight="1">
</Button>
<Button
android:id="@+id/audiodetectionAndAccelerometerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="2dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="Audiodetection + Accelerometer">
</Button>
<Button
android:id="@+id/videodetectionAndAccelerometerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="Videodetection + Accelerometer">
</Button>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -8,10 +8,18 @@
android:padding="10dp" android:padding="10dp"
tools:context=".VideodetectionActivity"> tools:context=".VideodetectionActivity">
<SurfaceView
android:id="@+id/surfaceViewVideodetection"
android:layout_width="1dp"
android:layout_height="1dp"
android:visibility="visible">
</SurfaceView>
<TextView <TextView
android:id="@+id/tvVideodetectionStatusmessage" android:id="@+id/tvVideodetectionStatusmessage"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Videodetection Activity"> android:text="Videodetection Activity">
</TextView> </TextView>
@ -27,6 +35,14 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<TextView
android:id="@+id/tvVideodetectionDeviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Registered Devices">
</TextView>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/deviceListRecyclerView" android:id="@+id/deviceListRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -35,6 +51,14 @@
android:layout_weight="1"> android:layout_weight="1">
</androidx.recyclerview.widget.RecyclerView> </androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="@+id/tvVideodetectionAlarmHistoryListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Alarm History List">
</TextView>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/alarmHistoryListRecyclerView" android:id="@+id/alarmHistoryListRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -8,11 +8,26 @@
android:padding="10dp" android:padding="10dp"
tools:context=".VideodetectionAndAccelerometerActivity"> tools:context=".VideodetectionAndAccelerometerActivity">
<SurfaceView
android:id="@+id/surfaceViewVideodetectionAndAccelerometer"
android:layout_width="1dp"
android:layout_height="1dp"
android:visibility="visible">
</SurfaceView>
<TextView <TextView
android:id="@+id/tvVideodetectionAndAccelerometerStatusmessage" android:id="@+id/tvvideodetectionAndAccelerometerStatusmessage"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Videodetection + Accelerometer Activity"> android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Videodetection+Accelerometer Activity">
</TextView>
<TextView
android:id="@+id/tvvideodetectionAndAccelerometerData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="">
</TextView> </TextView>
<Button <Button
@ -22,4 +37,43 @@
android:text="Back to MainActivity"> android:text="Back to MainActivity">
</Button> </Button>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tvVideodetectionAndAccelerometerDeviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Registered Devices">
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/deviceListRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/device_item"
android:layout_weight="1">
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="@+id/tvVideodetectionAndAccelerometerAlarmHistoryListRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Alarm History List">
</TextView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/alarmHistoryListRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/alarm_history_item"
android:layout_weight="1">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -4,5 +4,5 @@
<string name="sensor_status_placeholder">Sensorstatus: %s</string> <string name="sensor_status_placeholder">Sensorstatus: %s</string>
<string name="deviceID_placeholder">Sensor-ID: %s</string> <string name="deviceID_placeholder">Sensor-ID: %s</string>
<string name="sensor_time_stamp_placeholder">Timestamp: %s</string> <string name="sensor_time_stamp_placeholder">Timestamp: %s</string>
<string name="sensor_message_placeholder">Sensormessage: %d</string> <string name="sensor_message_placeholder">Sensormessage: %f</string>
</resources> </resources>