Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fad1ed3937 |
@@ -4,9 +4,6 @@
|
|||||||
|
|
||||||
<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.CAMERA"/>
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
||||||
|
|
||||||
<uses-feature android:name="android.hardware.camera"/>
|
<uses-feature android:name="android.hardware.camera"/>
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
|||||||
private TextView accelerometerWarningTV;
|
private TextView accelerometerWarningTV;
|
||||||
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) {
|
||||||
@@ -71,6 +70,7 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
|||||||
@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,30 +81,7 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
|
mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() {
|
||||||
@Override
|
|
||||||
public void onChanged(Boolean aBoolean) {
|
|
||||||
if (aBoolean) {
|
|
||||||
if(permission.alarmRechtePruefen(AccelerometerActivity.this, AccelerometerActivity.this)){
|
|
||||||
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
//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();
|
|
||||||
//todo Alarmhandling einfügen
|
|
||||||
} else {
|
|
||||||
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mAccelerometerViewModel.getAccelerometerAlarmDetected().observe(this, new Observer<Boolean>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(Boolean aBoolean) {
|
public void onChanged(Boolean aBoolean) {
|
||||||
if (aBoolean) {
|
if (aBoolean) {
|
||||||
|
|||||||
@@ -1,126 +1,27 @@
|
|||||||
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.SensorManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
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.AccelerometerViewModel;
|
|
||||||
import com.example.greenwatch.viewmodels.MicrofonViewModel;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AudiodetectionActivity extends AppCompatActivity {
|
public class AudiodetectionActivity extends AppCompatActivity {
|
||||||
private TextView microfonStatusMessage;
|
|
||||||
private Button backToMainActivityButton;
|
private Button backToMainActivityButton;
|
||||||
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);
|
||||||
|
|
||||||
microfonStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionStatusmessage);
|
|
||||||
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();
|
|
||||||
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();
|
|
||||||
//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();
|
|
||||||
//todo Alarmhandling einfügen
|
|
||||||
} else {
|
|
||||||
Toast.makeText(AudiodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Toast.makeText(AudiodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mMicrofonViewModel.getMicrofonAlarmDetected().observe(this, new Observer<Boolean>() {
|
|
||||||
@Override
|
|
||||||
public void onChanged(Boolean aBoolean) {
|
|
||||||
if (aBoolean) {
|
|
||||||
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), true, "Microfon", (int) mMicrofonViewModel.getAmplitudeInDB());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), false, "Microfon", (int) mMicrofonViewModel.getAmplitudeInDB());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
mMicrofonViewModel.startMicrofonSensor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
if (isFinishing()){
|
|
||||||
mMicrofonViewModel.recalibrationMicrofonSensor();
|
|
||||||
}
|
|
||||||
mMicrofonViewModel.stopMicrofonSensor();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-156
@@ -1,182 +1,27 @@
|
|||||||
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.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;
|
public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity {
|
||||||
import com.example.greenwatch.adapters.DeviceListAdapter;
|
|
||||||
import com.example.greenwatch.models.Device;
|
|
||||||
import com.example.greenwatch.viewmodels.AudiodetectionAndAccelerometerViewModel;
|
|
||||||
import com.example.greenwatch.viewmodels.VideodetectionAndAccelerometerViewModel;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity implements SensorEventListener {
|
|
||||||
private SensorManager accelerometerManager;
|
|
||||||
private Sensor accelerometerSensor;
|
|
||||||
private TextView audiodetectionAndAccelerometerStatusMessage;
|
|
||||||
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);
|
||||||
|
|
||||||
audiodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerStatusmessage);
|
|
||||||
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();
|
|
||||||
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();
|
|
||||||
//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();
|
|
||||||
//todo Alarmhandling einfügen
|
|
||||||
} else {
|
|
||||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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", 10);
|
|
||||||
}
|
|
||||||
else if (mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected() && !mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
|
|
||||||
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Audio", (int) mAudiodetectionAndAccelerometerViewModel.getAmplitudeInDB());
|
|
||||||
}
|
|
||||||
else if (mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected() && mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
|
|
||||||
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "2AudioAndAccelerometer", 10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedFalse", Toast.LENGTH_LONG).show();
|
|
||||||
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,6 @@ 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.View;
|
import android.view.View;
|
||||||
@@ -19,7 +17,6 @@ import com.example.greenwatch.adapters.DeviceListAdapter;
|
|||||||
import com.example.greenwatch.models.Device;
|
import com.example.greenwatch.models.Device;
|
||||||
import com.example.greenwatch.viewmodels.MainActivityViewModel;
|
import com.example.greenwatch.viewmodels.MainActivityViewModel;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
@@ -31,19 +28,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private Button videodetectionAndAccelerometerButton;
|
private Button videodetectionAndAccelerometerButton;
|
||||||
private Button connectionButton;
|
private Button connectionButton;
|
||||||
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;
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -65,14 +55,14 @@ 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();
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,50 +73,23 @@ 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();
|
|
||||||
//todo AlarmHandling einfügen
|
|
||||||
} else {
|
|
||||||
permission.alarmRechteAnfordern(activity);
|
|
||||||
if(permission.alarmRechtePruefen(context, activity)){
|
|
||||||
Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
//todo Alarmhandling einfügen
|
|
||||||
} else {
|
|
||||||
Toast.makeText(MainActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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();
|
||||||
if (permission.microRechtePruefen(context, activity)) {
|
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", false, "Audio", 10);
|
||||||
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 (permission.kameraRechtePruefen(context, activity)) {
|
if (mMainActivityViewModel.isCameraAccessAllowed(MainActivity.this)) {
|
||||||
openVideodetectionActivity();
|
openVideodetectionActivity();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
permission.kameraRechteAnfordern(activity);
|
mMainActivityViewModel.accessRequestCamera(MainActivity.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
accelerometerButton.setOnClickListener(new View.OnClickListener() {
|
accelerometerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@@ -139,23 +102,16 @@ 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) {
|
||||||
if (permission.microRechtePruefen(context, activity)) {
|
//openAudiodetectionAndAccelerometerActivity();
|
||||||
openAudiodetectionAndAccelerometerActivity();
|
mMainActivityViewModel.setSensorType(mMainActivityViewModel.getLocalDeviceUUID(), "AudiodetectionAndAccelerometer");
|
||||||
}
|
mMainActivityViewModel.setTimeStamp(mMainActivityViewModel.getLocalDeviceUUID(), "00:00");
|
||||||
else {
|
mMainActivityViewModel.setDeviceID(mMainActivityViewModel.getLocalDeviceUUID(), "6789");
|
||||||
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) {
|
||||||
if (permission.kameraRechtePruefen(context, activity)) {
|
openVideodetectionAndAccelerometerActivity();
|
||||||
openVideodetectionAndAccelerometerActivity();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
permission.kameraRechteAnfordern(activity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connectionButton.setOnClickListener(new View.OnClickListener() {
|
connectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@@ -182,8 +138,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
public void openVideodetectionAndAccelerometerActivity(){
|
public void openVideodetectionAndAccelerometerActivity(){
|
||||||
Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
|
//Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
|
||||||
startActivity(intent);
|
//startActivity(intent);
|
||||||
|
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "24:00", false, "Video", 0);
|
||||||
}
|
}
|
||||||
public void openConnectionActivity(){
|
public void openConnectionActivity(){
|
||||||
//Intent intent = new Intent(this, ConnectionActivity.class);
|
//Intent intent = new Intent(this, ConnectionActivity.class);
|
||||||
|
|||||||
@@ -1,128 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -27,7 +27,6 @@ public class VideodetectionActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private Button backToMainActivity;
|
private Button backToMainActivity;
|
||||||
private VideodetectionViewModel mVideoDetectionViewModel;
|
private VideodetectionViewModel mVideoDetectionViewModel;
|
||||||
private Permission permission = new Permission();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -63,6 +62,7 @@ public class VideodetectionActivity extends AppCompatActivity {
|
|||||||
@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,29 +73,6 @@ 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();
|
|
||||||
//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();
|
|
||||||
//todo Alarmhandling einfügen
|
|
||||||
} else {
|
|
||||||
Toast.makeText(VideodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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) {
|
||||||
|
|||||||
+1
-164
@@ -1,190 +1,27 @@
|
|||||||
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.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;
|
public class VideodetectionAndAccelerometerActivity extends AppCompatActivity {
|
||||||
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 TextView videodetectionAndAccelerometerStatusMessage;
|
|
||||||
private TextView videodetectionAndAccelerometerDataTV;
|
|
||||||
private TextView videodetectionAndAccelerometerWarningTV;
|
|
||||||
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);
|
||||||
|
|
||||||
videodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerStatusmessage);
|
|
||||||
videodetectionAndAccelerometerDataTV = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerData);
|
|
||||||
videodetectionAndAccelerometerWarningTV = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerWarning);
|
|
||||||
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();
|
|
||||||
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();
|
|
||||||
//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();
|
|
||||||
//todo Alarmhandling einfügen
|
|
||||||
} else {
|
|
||||||
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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", 10);
|
|
||||||
}
|
|
||||||
else if (mVideodetectionAndAccelerometerViewModel.getVideoAlarmDetected() && !mVideodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
|
|
||||||
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Video", 10);
|
|
||||||
}
|
|
||||||
else if (mVideodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected() && mVideodetectionAndAccelerometerViewModel.getVideoAlarmDetected()) {
|
|
||||||
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "2VideoAndAccelerometer", 10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "VideoAndAccelerometer", 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,12 +17,10 @@ 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<>();
|
||||||
@@ -31,7 +29,6 @@ public class DeviceRepository {
|
|||||||
|
|
||||||
private DeviceRepository() {
|
private DeviceRepository() {
|
||||||
setLocalDeviceUUID();
|
setLocalDeviceUUID();
|
||||||
startAlarmRecordingValue = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized DeviceRepository getInstance() {
|
public static synchronized DeviceRepository getInstance() {
|
||||||
@@ -55,21 +52,11 @@ public class DeviceRepository {
|
|||||||
return alarmHistoryList;
|
return alarmHistoryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<Boolean> getStartAlarmRecording() {
|
|
||||||
setMutableLiveDataStartAlarmRecording();
|
|
||||||
return startAlarmRecording;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){
|
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int 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();
|
||||||
}
|
}
|
||||||
@@ -137,11 +124,6 @@ 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();
|
||||||
}
|
}
|
||||||
@@ -195,11 +177,6 @@ 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();
|
||||||
|
|
||||||
@@ -268,10 +245,6 @@ public class DeviceRepository {
|
|||||||
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))) {
|
||||||
@@ -299,7 +272,7 @@ public class DeviceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean convertSensorStatus(String status) {
|
private boolean convertSensorStatus(String status) {
|
||||||
return status.equals(sensorStatusKey);
|
return status.equals(SensorStatusKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAlarmHistoryDeviceList(Device device) {
|
private void setAlarmHistoryDeviceList(Device device) {
|
||||||
@@ -310,13 +283,4 @@ 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,6 +28,7 @@ public class CameraSensor {
|
|||||||
private int startY;
|
private int startY;
|
||||||
private int endX;
|
private int endX;
|
||||||
private int endY;
|
private int endY;
|
||||||
|
|
||||||
private static final long ALARM_RESET_DELAY = 5000;
|
private static final long ALARM_RESET_DELAY = 5000;
|
||||||
private Runnable alarmResetRunnable;
|
private Runnable alarmResetRunnable;
|
||||||
private final Handler alarmResetHandler = new Handler();
|
private final Handler alarmResetHandler = new Handler();
|
||||||
@@ -44,11 +45,11 @@ public class CameraSensor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<Boolean> getVideoAlarmDetectedValue() {
|
public MutableLiveData<Boolean> getVideoAlarmDetectedValue() {
|
||||||
setMutableLiveDataVideoAlarmDetected();
|
setMutableLiveDataVideoMovementDetected();
|
||||||
return mVideoAlarmDetected;
|
return mVideoAlarmDetected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMutableLiveDataVideoAlarmDetected() {
|
private void setMutableLiveDataVideoMovementDetected() {
|
||||||
mVideoAlarmDetected.setValue(videoAlarmDetected);
|
mVideoAlarmDetected.setValue(videoAlarmDetected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,10 +180,10 @@ public class CameraSensor {
|
|||||||
|
|
||||||
public void checkAlarmCondition() {
|
public void checkAlarmCondition() {
|
||||||
if (videoAlarmDetected && !mVideoAlarmDetected.getValue()) {
|
if (videoAlarmDetected && !mVideoAlarmDetected.getValue()) {
|
||||||
setMutableLiveDataVideoAlarmDetected();
|
setMutableLiveDataVideoMovementDetected();
|
||||||
}
|
}
|
||||||
else if (!videoAlarmDetected && mVideoAlarmDetected.getValue()){
|
else if (!videoAlarmDetected && mVideoAlarmDetected.getValue()){
|
||||||
setMutableLiveDataVideoAlarmDetected();
|
setMutableLiveDataVideoMovementDetected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-23
@@ -1,23 +0,0 @@
|
|||||||
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;
|
|
||||||
}}
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-37
@@ -1,37 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,201 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -6,58 +6,84 @@ import androidx.lifecycle.ViewModel;
|
|||||||
|
|
||||||
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> mAccelerometerAlarmDetected;
|
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>();
|
||||||
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||||
private MutableLiveData<Boolean> mStartAlarmRecording;
|
|
||||||
private AccelerometerSensor mAccelerometerSensor;
|
|
||||||
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() {
|
||||||
if (mDeviceRepository == null) {
|
|
||||||
mDeviceRepository = DeviceRepository.getInstance();
|
|
||||||
}
|
|
||||||
if (mAccelerometerSensor == null) {
|
|
||||||
mAccelerometerSensor = AccelerometerSensor.getInstance();
|
|
||||||
}
|
|
||||||
if (mDeviceList == null) {
|
if (mDeviceList == null) {
|
||||||
|
mDeviceRepository = DeviceRepository.getInstance();
|
||||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
}
|
|
||||||
if (mAlarmHistoryList == null) {
|
|
||||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||||
}
|
}
|
||||||
if (mStartAlarmRecording == null) {
|
initGesamtBE();
|
||||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
|
mMovementDetected.setValue(false);
|
||||||
}
|
functionCallCount = 0;
|
||||||
if (mAccelerometerAlarmDetected == null) {
|
meanValue = 0f;
|
||||||
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addValueToGesamtBE(float newValue) {
|
public void addValueToGesamtBE(float newValue) {
|
||||||
mAccelerometerSensor.addValueToGesamtBE(newValue);
|
if (Gesamt_be.size() == arraySize) {
|
||||||
|
Gesamt_be.remove(Gesamt_be.size() -1);
|
||||||
|
}
|
||||||
|
Gesamt_be.add(0, newValue);
|
||||||
|
functionCallCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void meanValueCalculation() {
|
public void meanValueCalculation() {
|
||||||
mAccelerometerSensor.meanValueCalculation();
|
for (float element : Gesamt_be) {
|
||||||
|
meanValue += Math.abs(element);
|
||||||
|
}
|
||||||
|
meanValue = meanValue/arraySize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calibrateAccelerometerSensor() {
|
public void calibrateAccelerometerSensor() {
|
||||||
mAccelerometerSensor.calibrateAccelerometerSensor();
|
if (functionCallCount <= arraySize) {
|
||||||
|
offsetValue = meanValue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
startMeasuring = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAlarmCondition() {
|
public void checkAlarmCondition() {
|
||||||
mAccelerometerSensor.checkAlarmCondition();
|
if (meanValue > (thresholdValue + offsetValue) && startMeasuring && !mMovementDetected.getValue()) {
|
||||||
|
mMovementDetected.setValue(true);
|
||||||
|
}
|
||||||
|
else if (meanValue < (thresholdValue + offsetValue) && mMovementDetected.getValue()){
|
||||||
|
mMovementDetected.setValue(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<Boolean> getAccelerometerAlarmDetected() {
|
public LiveData<Boolean> getMovementDetectedValue() {
|
||||||
return mAccelerometerAlarmDetected;
|
return mMovementDetected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -70,11 +96,6 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
|
|||||||
return mAlarmHistoryList;
|
return mAlarmHistoryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveData<Boolean> getStartAlarmRecording() {
|
|
||||||
return mStartAlarmRecording;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
||||||
|
|||||||
-226
@@ -1,226 +0,0 @@
|
|||||||
package com.example.greenwatch.viewmodels;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
|
|
||||||
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 DeviceRepository mDeviceRepository;
|
|
||||||
private boolean microfonAlarmDetected;
|
|
||||||
private boolean accelerometerAlarmDetected;
|
|
||||||
private boolean microfondetectionAndAccelerometerAlarmDetected;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
if (mDeviceRepository == null) {
|
|
||||||
mDeviceRepository = DeviceRepository.getInstance();
|
|
||||||
}
|
|
||||||
if (mAccelerometerSensor == null) {
|
|
||||||
mAccelerometerSensor = AccelerometerSensor.getInstance();
|
|
||||||
}
|
|
||||||
if (mMicrofonSensor == null) {
|
|
||||||
mMicrofonSensor = MicrofonSensor.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();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addValueToGesamtBE(float newValue) {
|
|
||||||
mAccelerometerSensor.addValueToGesamtBE(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void meanValueCalculation() {
|
|
||||||
mAccelerometerSensor.meanValueCalculation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void calibrateAccelerometerSensor() {
|
|
||||||
mAccelerometerSensor.calibrateAccelerometerSensor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkAlarmCondition() {
|
|
||||||
mAccelerometerSensor.checkAlarmCondition();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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, int 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, int sensorMessage) {
|
|
||||||
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSensorMassage(String deviceID) {
|
|
||||||
return mDeviceRepository.getSensorMassage(deviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLocalDeviceUUID() {
|
|
||||||
return mDeviceRepository.getLocalDeviceUUID();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSystemTimeStamp() {
|
|
||||||
return mDeviceRepository.getSystemTimeStamp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@@ -21,8 +20,8 @@ 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;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
@@ -38,7 +37,14 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
|
|||||||
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
|
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
|
||||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@@ -51,11 +57,6 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
|
|||||||
return mAlarmHistoryList;
|
return mAlarmHistoryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveData<Boolean> getStartAlarmRecording() {
|
|
||||||
return mStartAlarmRecording;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
||||||
|
|||||||
@@ -1,142 +0,0 @@
|
|||||||
package com.example.greenwatch.viewmodels;
|
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
|
|
||||||
import com.example.greenwatch.models.Device;
|
|
||||||
import com.example.greenwatch.repositories.DeviceRepository;
|
|
||||||
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;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
if (mDeviceRepository == null) {
|
|
||||||
mDeviceRepository = DeviceRepository.getInstance();
|
|
||||||
}
|
|
||||||
if (mMicrofonSensor == null) {
|
|
||||||
mMicrofonSensor = MicrofonSensor.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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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, int 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, int sensorMessage) {
|
|
||||||
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSensorMassage(String deviceID) {
|
|
||||||
return mDeviceRepository.getSensorMassage(deviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLocalDeviceUUID() {
|
|
||||||
return mDeviceRepository.getLocalDeviceUUID();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSystemTimeStamp() {
|
|
||||||
return mDeviceRepository.getSystemTimeStamp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-218
@@ -1,218 +0,0 @@
|
|||||||
package com.example.greenwatch.viewmodels;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
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.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 boolean videoAlarmDetected;
|
|
||||||
private boolean accelerometerAlarmDetected;
|
|
||||||
private boolean videodetectionAndAccelerometerAlarmDetected;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
if (mDeviceRepository == null) {
|
|
||||||
mDeviceRepository = DeviceRepository.getInstance();
|
|
||||||
}
|
|
||||||
if (mAccelerometerSensor == null) {
|
|
||||||
mAccelerometerSensor = AccelerometerSensor.getInstance();
|
|
||||||
}
|
|
||||||
if (mCameraSensor == null) {
|
|
||||||
mCameraSensor = CameraSensor.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();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addValueToGesamtBE(float newValue) {
|
|
||||||
mAccelerometerSensor.addValueToGesamtBE(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void meanValueCalculation() {
|
|
||||||
mAccelerometerSensor.meanValueCalculation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void calibrateAccelerometerSensor() {
|
|
||||||
mAccelerometerSensor.calibrateAccelerometerSensor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkAlarmCondition() {
|
|
||||||
mAccelerometerSensor.checkAlarmCondition();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 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, int 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, int sensorMessage) {
|
|
||||||
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSensorMassage(String deviceID) {
|
|
||||||
return mDeviceRepository.getSensorMassage(deviceID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLocalDeviceUUID() {
|
|
||||||
return mDeviceRepository.getLocalDeviceUUID();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSystemTimeStamp() {
|
|
||||||
return mDeviceRepository.getSystemTimeStamp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,6 @@ 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 CameraSensor mCameraSensor;
|
private CameraSensor mCameraSensor;
|
||||||
|
|
||||||
@@ -42,9 +41,6 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
|
|||||||
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();
|
||||||
}
|
}
|
||||||
@@ -68,11 +64,6 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
|
|||||||
return mAlarmHistoryList;
|
return mAlarmHistoryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveData<Boolean> getStartAlarmRecording() {
|
|
||||||
return mStartAlarmRecording;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ public interface ViewModelInterface {
|
|||||||
void init();
|
void init();
|
||||||
LiveData<List<Device>> getConnectedDeviceList();
|
LiveData<List<Device>> getConnectedDeviceList();
|
||||||
LiveData<List<Device>> getAlarmHistoryList();
|
LiveData<List<Device>> getAlarmHistoryList();
|
||||||
LiveData<Boolean> getStartAlarmRecording();
|
|
||||||
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage);
|
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage);
|
||||||
void setTimeStamp(String deviceID, String timeStamp);
|
void setTimeStamp(String deviceID, String timeStamp);
|
||||||
String getTimeStamp(String deviceID);
|
String getTimeStamp(String deviceID);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
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:text="">
|
android:text="Audiodetection Activity">
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -22,27 +22,4 @@
|
|||||||
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">
|
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<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>
|
||||||
@@ -22,27 +22,4 @@
|
|||||||
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">
|
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<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>
|
||||||
@@ -9,24 +9,10 @@
|
|||||||
tools:context=".VideodetectionAndAccelerometerActivity">
|
tools:context=".VideodetectionAndAccelerometerActivity">
|
||||||
|
|
||||||
<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="">
|
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
|
|
||||||
android:id="@+id/tvvideodetectionAndAccelerometerWarning"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="">
|
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -36,27 +22,4 @@
|
|||||||
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">
|
|
||||||
|
|
||||||
<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>
|
|
||||||
|
|
||||||
<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>
|
||||||
Reference in New Issue
Block a user