Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0423a56117 | ||
|
|
a13f4e295b | ||
|
|
c57d277dfb | ||
|
|
e3df8b63b8 | ||
|
|
6c4b6b67a4 | ||
|
|
1094b0f75d | ||
|
|
8dd4c6d56a | ||
|
|
317bef2b59 | ||
|
|
032ab2788d | ||
|
|
792c650400 | ||
|
|
d21c22cd02 | ||
|
|
a054b2a068 | ||
|
|
db74988f3d | ||
|
|
ccdff78a4a | ||
|
|
373ca2d106 | ||
|
|
28c98ba766 | ||
|
|
559a95b1c2 | ||
|
|
9f253b655c | ||
|
|
d38e05a4b6 | ||
|
|
595d97ef57 | ||
|
|
1c360e8604 | ||
|
|
bd2927ed64 | ||
|
|
30f9c6c3f4 | ||
|
|
9e3652e275 |
@@ -35,4 +35,10 @@ dependencies {
|
|||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
|
||||||
|
def camerax_version = "1.2.3"
|
||||||
|
implementation "androidx.camera:camera-camera2:${camerax_version}"
|
||||||
|
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
|
||||||
|
implementation "androidx.camera:camera-view:${camerax_version}"
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,11 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.greenwatch">
|
package="com.example.greenwatch">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.CAMERA"/>
|
||||||
|
|
||||||
|
<uses-feature android:name="android.hardware.camera"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
@@ -10,7 +15,19 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.GreenWatch">
|
android:theme="@style/Theme.GreenWatch">
|
||||||
<activity
|
<activity
|
||||||
android:name=".Beschleunigungssensor"
|
android:name=".VideodetectionAndAccelerometerActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".AudiodetectionAndAccelerometerActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".VideodetectionActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".AudiodetectionActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
android:name=".AccelerometerActivity"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
package com.example.greenwatch;
|
||||||
|
|
||||||
|
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.view.View;
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
public class AccelerometerActivity extends AppCompatActivity implements SensorEventListener {
|
||||||
|
|
||||||
|
private SensorManager accelerometerManager;
|
||||||
|
private Sensor accelerometerSensor;
|
||||||
|
private TextView accelerometerStatusMessage;
|
||||||
|
private TextView accelerometerDataTV;
|
||||||
|
private TextView accelerometerWarningTV;
|
||||||
|
private Button backToMainActivityButton;
|
||||||
|
private AccelerometerViewModel mAccelerometerViewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_accelerometer);
|
||||||
|
|
||||||
|
accelerometerStatusMessage = (TextView) findViewById(R.id.tvAccelerometerStatusmessage);
|
||||||
|
accelerometerDataTV = (TextView) findViewById(R.id.tvAccelerometerData);
|
||||||
|
accelerometerWarningTV = (TextView) findViewById(R.id.tvAccelerometerWarning);
|
||||||
|
backToMainActivityButton = (Button) findViewById(R.id.accelerometerBackToMainActivity);
|
||||||
|
|
||||||
|
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() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mAccelerometerViewModel = new ViewModelProvider(this).get(AccelerometerViewModel.class);
|
||||||
|
mAccelerometerViewModel.init();
|
||||||
|
mAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(List<Device> devices) {
|
||||||
|
deviceListAdapter.setDevices(devices);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mAccelerometerViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(List<Device> devices) {
|
||||||
|
alarmHistoryListAdapter.setAlarmHistoryList(devices);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(Boolean aBoolean) {
|
||||||
|
if (aBoolean) {
|
||||||
|
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(Boolean aBoolean) {
|
||||||
|
if (aBoolean) {
|
||||||
|
mAccelerometerViewModel.updateDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", 10);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mAccelerometerViewModel.updateDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), false, "Accelerometer", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
accelerometerManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||||
|
if (accelerometerManager.getSensorList(Sensor.TYPE_GYROSCOPE).size() == 0) {
|
||||||
|
accelerometerSensor = null;
|
||||||
|
Toast.makeText(AccelerometerActivity.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]);
|
||||||
|
accelerometerDataTV.setText(sb.toString());
|
||||||
|
mAccelerometerViewModel.addValueToGesamtBE(event.values[0] + event.values[1] + event.values[2]);
|
||||||
|
mAccelerometerViewModel.meanValueCalculation();
|
||||||
|
mAccelerometerViewModel.calibrateAccelerometerSensor();
|
||||||
|
mAccelerometerViewModel.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(AccelerometerActivity.this, "We registered to the sensor", Toast.LENGTH_LONG).show();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(AccelerometerActivity.this, "Registration did not work", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
if (accelerometerSensor != null) {
|
||||||
|
accelerometerManager.unregisterListener(this, accelerometerSensor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.example.greenwatch;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
public class AudiodetectionActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private Button backToMainActivityButton;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_audiodetection);
|
||||||
|
|
||||||
|
backToMainActivityButton = (Button) findViewById(R.id.audiodetectorBackToMainActivity);
|
||||||
|
|
||||||
|
backToMainActivityButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.example.greenwatch;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private Button backToMainActivity;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_audiodetection_and_accelerometer);
|
||||||
|
|
||||||
|
backToMainActivity = (Button) findViewById(R.id.audiodetectionAndAccelerometerBackToMainActivity);
|
||||||
|
|
||||||
|
backToMainActivity.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,188 +1,4 @@
|
|||||||
package com.example.greenwatch;
|
package com.example.greenwatch;
|
||||||
|
|
||||||
|
public class Beschleunigungssensor {
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.hardware.Sensor;
|
|
||||||
import android.hardware.SensorEvent;
|
|
||||||
import android.hardware.SensorEventListener;
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class Beschleunigungssensor extends AppCompatActivity implements SensorEventListener{
|
|
||||||
|
|
||||||
private SensorManager bsmanager;
|
|
||||||
private ArrayList<Float> Gesamt_be;
|
|
||||||
private int sensorType = Sensor.TYPE_GYROSCOPE, zaehler_runde =0, listen_groesse = 500, kalibrieren, Offset_shared = 0, shared_merk, mittelwertsumme_shared;
|
|
||||||
private Sensor sens, sensor_l;
|
|
||||||
private float x_value = 0, y_value, z_value, Vorbesetzung = 0, gesamt_runde =0;
|
|
||||||
private double Schwellwert = 0.15, mittelwertsumme = 0.0, Offset = 0.1;
|
|
||||||
String Daten, Warnung, Zeitstempel, Array_shared;
|
|
||||||
private final static String KEY_kalibirieren = "KEY_KALIBRIEREN_"+Beschleunigungssensor.class.getSimpleName();
|
|
||||||
private final static String KEY_Gesamt_be = "KEY_GESAMT_BE_"+Beschleunigungssensor.class.getSimpleName();
|
|
||||||
private final static String KEY_Offset = "KEY_OFFSET_"+Beschleunigungssensor.class.getSimpleName();
|
|
||||||
private final static String KEY_Mittelwertsumme = "KEY_MITTELWERTSUMME_"+Beschleunigungssensor.class.getSimpleName();
|
|
||||||
TextView Daten_Bsensor, Warnung_Bsensor, test;
|
|
||||||
private boolean toggle = true, ts_setzen = true, start_messen;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_beschleunigungssensor);
|
|
||||||
|
|
||||||
Daten_Bsensor = (TextView) findViewById(R.id.DatenBsensor);
|
|
||||||
Warnung_Bsensor = (TextView) findViewById(R.id.WarnungBsensor);
|
|
||||||
test = (TextView) findViewById(R.id.test);
|
|
||||||
|
|
||||||
bsmanager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
|
||||||
if (bsmanager.getSensorList(Sensor.TYPE_GYROSCOPE).size() == 0) {
|
|
||||||
sens = null;
|
|
||||||
Daten = "kein B Sensor voranden";
|
|
||||||
} else {
|
|
||||||
sens = bsmanager.getSensorList(sensorType).get(0);
|
|
||||||
}
|
|
||||||
Gesamt_be = new ArrayList<Float>();
|
|
||||||
for (int i = 0; i < listen_groesse ; i++){
|
|
||||||
Gesamt_be.add(Vorbesetzung);
|
|
||||||
}
|
|
||||||
kalibrieren = 0;
|
|
||||||
start_messen = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getTimestamp(){
|
|
||||||
Long tslong = System.currentTimeMillis();
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
|
||||||
Date date = new Date(tslong);
|
|
||||||
String result = sdf.format(date);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSensorChanged(SensorEvent event) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("x=").append(event.values[0])//.append(event.timestamp)
|
|
||||||
.append("\ny=").append(event.values[1])
|
|
||||||
.append("\nz=").append(event.values[2]);
|
|
||||||
Daten = sb.toString();
|
|
||||||
Daten_Bsensor.setText(Daten);
|
|
||||||
gesamt_runde = event.values[0] + event.values[1] + event.values[2];
|
|
||||||
Gesamt_be.remove(zaehler_runde);
|
|
||||||
Gesamt_be.add(zaehler_runde, gesamt_runde);
|
|
||||||
mittelwertsumme = 0.0;
|
|
||||||
|
|
||||||
//Mittelwert des Arrays berechnen
|
|
||||||
for (int i = 0; i < listen_groesse; i++){
|
|
||||||
if (Gesamt_be.get(i) < 0){
|
|
||||||
mittelwertsumme += (Gesamt_be.get(i) * (-1));
|
|
||||||
}else {
|
|
||||||
mittelwertsumme += Gesamt_be.get(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mittelwertsumme = mittelwertsumme/listen_groesse;
|
|
||||||
if (kalibrieren < listen_groesse){
|
|
||||||
Offset = mittelwertsumme;
|
|
||||||
kalibrieren++;
|
|
||||||
}else {
|
|
||||||
start_messen = true;
|
|
||||||
}
|
|
||||||
StringBuilder testsb = new StringBuilder();
|
|
||||||
testsb.append(mittelwertsumme);
|
|
||||||
String tests = testsb.toString();
|
|
||||||
test.setText(tests);
|
|
||||||
|
|
||||||
if((mittelwertsumme > (Schwellwert+Offset) ) & (ts_setzen == true) &(start_messen == true)){
|
|
||||||
Zeitstempel = getTimestamp();
|
|
||||||
StringBuilder ts = new StringBuilder();
|
|
||||||
ts.append(Zeitstempel)
|
|
||||||
.append(", Gruppe3")
|
|
||||||
.append(", An")
|
|
||||||
.append(", Bewegung, ")
|
|
||||||
.append(mittelwertsumme);
|
|
||||||
Warnung = ts.toString();
|
|
||||||
Warnung_Bsensor.setText(Warnung);
|
|
||||||
ts_setzen = false;
|
|
||||||
}else if((mittelwertsumme > (Schwellwert+Offset)) & (ts_setzen == false)){
|
|
||||||
} else if ((mittelwertsumme < (Schwellwert+Offset)) & (ts_setzen == false)) {
|
|
||||||
Warnung_Bsensor.setText("");
|
|
||||||
ts_setzen = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (zaehler_runde < (listen_groesse -1)){
|
|
||||||
zaehler_runde++;
|
|
||||||
}else {
|
|
||||||
zaehler_runde = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//mittelwertsumme ist kein int in diesem programm
|
|
||||||
//shared prefenrences: bei Kippen speichern -> nochmal neu klalibrieren? -> eig ja, weil neuer Standort
|
|
||||||
//Vorbelegung nicht nochmal neu vornehmen -> aus onCreate Funktion raus -> hilfsvariablen auch in shared preferences speichern
|
|
||||||
@Override
|
|
||||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
if (sens != null) {
|
|
||||||
if (bsmanager.registerListener(this, sens, SensorManager.SENSOR_DELAY_GAME)) {
|
|
||||||
Daten = "Wir haben uns beim Sensor angemeldet";
|
|
||||||
} else {
|
|
||||||
Daten = "Das anmelden hat nicht geklappt";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//SharedPreferences p = getPreferences(Context.MODE_PRIVATE);
|
|
||||||
//mittelwertsumme_shared = p.getInt(KEY_Mittelwertsumme, 0);
|
|
||||||
//kalibrieren = p.getInt(KEY_kalibirieren, 0);
|
|
||||||
//Offset_shared = p.getInt(KEY_Offset, 0 );
|
|
||||||
//Array_shared = p.getString(KEY_Gesamt_be, "");
|
|
||||||
|
|
||||||
//mittelwertsumme = (double) mittelwertsumme_shared;
|
|
||||||
//mittelwertsumme /= 1000000.0;
|
|
||||||
|
|
||||||
//Offset = (double) Offset_shared;
|
|
||||||
//Offset /= 1000000.0;
|
|
||||||
|
|
||||||
//String zw[] = Array_shared.split(";", listen_groesse);
|
|
||||||
|
|
||||||
//if(shared_merk == 2){
|
|
||||||
//for (int i=0; i<listen_groesse; i++){
|
|
||||||
//float wert = Float.valueOf(zw[i]);
|
|
||||||
//Gesamt_be.add(i, wert);
|
|
||||||
//}}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause () {
|
|
||||||
super.onPause();
|
|
||||||
if (sens != null) {
|
|
||||||
bsmanager.unregisterListener(this, sens);
|
|
||||||
}
|
|
||||||
//shared_merk = 2;
|
|
||||||
// Offset_shared = (int) (Offset * 1000000.0);
|
|
||||||
//mittelwertsumme_shared = (int) (mittelwertsumme * 1000000.0);
|
|
||||||
|
|
||||||
//StringBuilder ar = new StringBuilder();
|
|
||||||
//for (int z=0; z < listen_groesse; z++){
|
|
||||||
//ar.append(Gesamt_be.get(z)).append(";");
|
|
||||||
//}
|
|
||||||
//Array_shared = ar.toString();
|
|
||||||
|
|
||||||
//SharedPreferences p = getPreferences(Context.MODE_PRIVATE);
|
|
||||||
//SharedPreferences.Editor editor = p.edit();
|
|
||||||
//editor.putInt(KEY_Mittelwertsumme, mittelwertsumme_shared);
|
|
||||||
//editor.putInt(KEY_kalibirieren, kalibrieren);
|
|
||||||
//editor.putInt(KEY_Offset, Offset_shared);
|
|
||||||
//editor.putString(KEY_Gesamt_be, Array_shared);
|
|
||||||
//editor.commit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,41 +1,160 @@
|
|||||||
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.content.Intent;
|
import android.content.Intent;
|
||||||
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.Toast;
|
||||||
|
|
||||||
|
import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
|
||||||
|
import com.example.greenwatch.adapters.DeviceListAdapter;
|
||||||
|
import com.example.greenwatch.models.Device;
|
||||||
|
import com.example.greenwatch.viewmodels.MainActivityViewModel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private Button Beschleunigungssensor;
|
private Button audiodetectionButton;
|
||||||
|
private Button videodetectionButton;
|
||||||
|
private Button accelerometerButton;
|
||||||
|
private Button audiodetectionAndAccelerometerButton;
|
||||||
|
private Button videodetectionAndAccelerometerButton;
|
||||||
|
private Button connectionButton;
|
||||||
|
private MainActivityViewModel mMainActivityViewModel;
|
||||||
|
|
||||||
@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);
|
||||||
|
|
||||||
final Button Beschleunigungssensor = (Button) findViewById(R.id.beschleunigungssensor);
|
audiodetectionButton = (Button) findViewById(R.id.audiodetectionButton);
|
||||||
Beschleunigungssensor.setOnClickListener(new View.OnClickListener() {
|
videodetectionButton = (Button) findViewById(R.id.videodetectionButton);
|
||||||
|
accelerometerButton = (Button) findViewById(R.id.accelerometerButton);
|
||||||
|
audiodetectionAndAccelerometerButton = (Button) findViewById(R.id.audiodetectionAndAccelerometerButton);
|
||||||
|
videodetectionAndAccelerometerButton = (Button) findViewById(R.id.videodetectionAndAccelerometerButton);
|
||||||
|
connectionButton = (Button) findViewById(R.id.connectionButton);
|
||||||
|
|
||||||
|
RecyclerView deviceListRecyclerView = findViewById(R.id.deviceListRecyclerView);
|
||||||
|
deviceListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
deviceListRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
|
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
|
||||||
|
deviceListRecyclerView.setAdapter(deviceListAdapter);
|
||||||
|
|
||||||
|
RecyclerView alarmHistoryListRecyclerView = findViewById(R.id.alarmHistoryListRecyclerView);
|
||||||
|
alarmHistoryListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||||
|
alarmHistoryListRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
|
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
|
||||||
|
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
|
||||||
|
|
||||||
|
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
|
||||||
|
mMainActivityViewModel.init();
|
||||||
|
mMainActivityViewModel.accessRequestCamera(this);
|
||||||
|
mMainActivityViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(List<Device> devices) {
|
||||||
|
deviceListAdapter.setDevices(devices);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMainActivityViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(List<Device> devices) {
|
||||||
|
alarmHistoryListAdapter.setAlarmHistoryList(devices);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mMainActivityViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(Boolean aBoolean) {
|
||||||
|
if (aBoolean) {
|
||||||
|
Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Toast.makeText(MainActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
audiodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(MainActivity.this, Beschleunigungssensor.class);
|
//openAudiodetectionActivity();
|
||||||
startActivity(intent);
|
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", false, "Audio", 10);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
videodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
if (mMainActivityViewModel.isCameraAccessAllowed(MainActivity.this)) {
|
||||||
|
openVideodetectionActivity();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mMainActivityViewModel.accessRequestCamera(MainActivity.this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
accelerometerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
openAccelerometerActivity();
|
||||||
|
mMainActivityViewModel.setSensorType(mMainActivityViewModel.getLocalDeviceUUID(), "Accelerometer");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
audiodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//openAudiodetectionAndAccelerometerActivity();
|
||||||
|
mMainActivityViewModel.setSensorType(mMainActivityViewModel.getLocalDeviceUUID(), "AudiodetectionAndAccelerometer");
|
||||||
|
mMainActivityViewModel.setTimeStamp(mMainActivityViewModel.getLocalDeviceUUID(), "00:00");
|
||||||
|
mMainActivityViewModel.setDeviceID(mMainActivityViewModel.getLocalDeviceUUID(), "6789");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
videodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
openVideodetectionAndAccelerometerActivity();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
openConnectionActivity();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
public void openAudiodetectionActivity(){
|
||||||
@Override
|
Intent intent = new Intent(this, AudiodetectionActivity.class);
|
||||||
protected void onResume() {
|
startActivity(intent);
|
||||||
super.onResume();
|
}
|
||||||
|
public void openVideodetectionActivity(){
|
||||||
|
Intent intent = new Intent(this, VideodetectionActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
public void openAccelerometerActivity(){
|
||||||
|
Intent intent = new Intent(this, AccelerometerActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
public void openAudiodetectionAndAccelerometerActivity(){
|
||||||
|
Intent intent = new Intent(this, AudiodetectionAndAccelerometerActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
public void openVideodetectionAndAccelerometerActivity(){
|
||||||
|
Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
public void openConnectionActivity(){
|
||||||
|
//Intent intent = new Intent(this, ConnectionActivity.class);
|
||||||
|
//startActivity(intent);
|
||||||
|
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", true, "Audio", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package com.example.greenwatch;
|
||||||
|
|
||||||
|
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.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
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.VideodetectionViewModel;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
public class VideodetectionActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private Button backToMainActivity;
|
||||||
|
private VideodetectionViewModel mVideoDetectionViewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_videodetection);
|
||||||
|
|
||||||
|
backToMainActivity = (Button) findViewById(R.id.videodetectorBackToMainActivity);
|
||||||
|
|
||||||
|
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() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mVideoDetectionViewModel = new ViewModelProvider(this).get(VideodetectionViewModel.class);
|
||||||
|
mVideoDetectionViewModel.init();
|
||||||
|
mVideoDetectionViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(List<Device> devices) {
|
||||||
|
deviceListAdapter.setDevices(devices);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mVideoDetectionViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(List<Device> devices) {
|
||||||
|
alarmHistoryListAdapter.setAlarmHistoryList(devices);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mVideoDetectionViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(Boolean aBoolean) {
|
||||||
|
if (aBoolean) {
|
||||||
|
Toast.makeText(VideodetectionActivity.this, "Start 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>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(Boolean aBoolean) {
|
||||||
|
if (aBoolean) {
|
||||||
|
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), true, "Video", 10);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), false, "Video", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(this);
|
||||||
|
cameraProviderFuture.addListener(() -> {
|
||||||
|
try {
|
||||||
|
mVideoDetectionViewModel.bindImageAnalysis(cameraProviderFuture.get(), this, this);
|
||||||
|
} catch (ExecutionException | InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}, ContextCompat.getMainExecutor(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
package com.example.greenwatch;
|
||||||
|
|
||||||
|
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.view.View;
|
||||||
|
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.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 VideodetectionAndAccelerometerViewModel mVideodetectionAndAccelerometerViewModel;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
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);
|
||||||
|
|
||||||
|
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() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
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) {
|
||||||
|
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Start 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) {
|
||||||
|
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", 10);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "Accelerometer", 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.example.greenwatch.adapters;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.example.greenwatch.R;
|
||||||
|
import com.example.greenwatch.models.Device;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AlarmHistoryListAdapter extends RecyclerView.Adapter<AlarmHistoryListAdapter.AlarmHistoryListHolder> {
|
||||||
|
private List<Device> alarmHistoryList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public AlarmHistoryListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View itemView = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.alarm_history_item, parent, false);
|
||||||
|
return new AlarmHistoryListHolder(itemView);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull AlarmHistoryListHolder holder, int position) {
|
||||||
|
Device currentDevice = alarmHistoryList.get(position);
|
||||||
|
holder.textViewSensorType.setText(holder.itemView.getContext().getString(R.string.sensor_type_placeholder, currentDevice.getSensorType()));
|
||||||
|
holder.textViewDeviceID.setText(holder.itemView.getContext().getString(R.string.deviceID_placeholder, currentDevice.getDeviceID()));
|
||||||
|
holder.textViewTimeStamp.setText(holder.itemView.getContext().getString(R.string.sensor_time_stamp_placeholder, currentDevice.getTimeStamp()));
|
||||||
|
holder.textViewSensorMessage.setText(holder.itemView.getContext().getString(R.string.sensor_message_placeholder, currentDevice.getSensorMassage()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return alarmHistoryList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlarmHistoryList(List<Device> alarmHistoryList) {
|
||||||
|
this.alarmHistoryList = alarmHistoryList;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
class AlarmHistoryListHolder extends RecyclerView.ViewHolder {
|
||||||
|
private TextView textViewSensorType;
|
||||||
|
private TextView textViewDeviceID;
|
||||||
|
private TextView textViewTimeStamp;
|
||||||
|
private TextView textViewSensorMessage;
|
||||||
|
|
||||||
|
public AlarmHistoryListHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
textViewSensorType = (TextView) itemView.findViewById(R.id.tvAlarmHistoryDeviceSensorType);
|
||||||
|
textViewDeviceID = (TextView) itemView.findViewById(R.id.tvAlarmHistoryDeviceID);
|
||||||
|
textViewTimeStamp = (TextView) itemView.findViewById(R.id.tvAlarmHistoryDeviceTimeStamp);
|
||||||
|
textViewSensorMessage = (TextView) itemView.findViewById(R.id.tvAlarmHistoryDeviceSensorMassage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package com.example.greenwatch.adapters;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.example.greenwatch.R;
|
||||||
|
import com.example.greenwatch.models.Device;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceListAdapter extends RecyclerView.Adapter<DeviceListAdapter.DeviceListHolder> {
|
||||||
|
private List<Device> devices = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public DeviceListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View itemView = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.device_item, parent, false);
|
||||||
|
return new DeviceListHolder(itemView);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull DeviceListHolder holder, int position) {
|
||||||
|
Device currentDevice = devices.get(position);
|
||||||
|
holder.textViewSensorType.setText(holder.itemView.getContext().getString(R.string.sensor_type_placeholder, currentDevice.getSensorType()));
|
||||||
|
holder.textViewDeviceID.setText(holder.itemView.getContext().getString(R.string.deviceID_placeholder, currentDevice.getDeviceID()));
|
||||||
|
holder.textViewTimeStamp.setText(holder.itemView.getContext().getString(R.string.sensor_time_stamp_placeholder, currentDevice.getTimeStamp()));
|
||||||
|
holder.textViewSensorMessage.setText(holder.itemView.getContext().getString(R.string.sensor_message_placeholder, currentDevice.getSensorMassage()));
|
||||||
|
holder.setDeviceSensorStatus(currentDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return devices.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevices(List<Device> devices) {
|
||||||
|
this.devices = devices;
|
||||||
|
Collections.sort(this.devices, new Comparator<Device>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Device device1, Device device2) {
|
||||||
|
if (device1.getSensorStatus() && !device2.getSensorStatus()) {
|
||||||
|
return -1;
|
||||||
|
} else if (!device1.getSensorStatus() && device2.getSensorStatus()) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
class DeviceListHolder extends RecyclerView.ViewHolder {
|
||||||
|
private TextView textViewSensorType;
|
||||||
|
private TextView textViewSensorStatus;
|
||||||
|
private TextView textViewDeviceID;
|
||||||
|
private TextView textViewTimeStamp;
|
||||||
|
private TextView textViewSensorMessage;
|
||||||
|
|
||||||
|
public DeviceListHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
textViewSensorType = (TextView) itemView.findViewById(R.id.tvDeviceSensorType);
|
||||||
|
textViewSensorStatus = (TextView) itemView.findViewById(R.id.tvDeviceSensorStatus);
|
||||||
|
textViewDeviceID = (TextView) itemView.findViewById(R.id.tvDeviceID);
|
||||||
|
textViewTimeStamp = (TextView) itemView.findViewById(R.id.tvDeviceTimeStamp);
|
||||||
|
textViewSensorMessage = (TextView) itemView.findViewById(R.id.tvDeviceSensorMassage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceSensorStatus(Device device) {
|
||||||
|
if (device.getSensorStatus()) {
|
||||||
|
textViewSensorStatus.setText(itemView.getContext().getString(R.string.sensor_status_placeholder, "AN"));
|
||||||
|
itemView.setBackgroundColor(Color.RED);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
textViewSensorStatus.setText(itemView.getContext().getString(R.string.sensor_status_placeholder, "AUS"));
|
||||||
|
itemView.setBackgroundColor(Color.WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package com.example.greenwatch.communication;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.example.greenwatch.repositories.DeviceRepository;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.DatagramPacket;
|
||||||
|
import java.net.DatagramSocket;
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
|
public class WiFiCommunication {
|
||||||
|
|
||||||
|
private final InetAddress address;
|
||||||
|
private final DatagramSocket socket;
|
||||||
|
private final int port;
|
||||||
|
private String rxString;
|
||||||
|
private String sendMessage;
|
||||||
|
//private String sendMsg = "default";
|
||||||
|
private boolean isNewMessage;
|
||||||
|
volatile private boolean running;
|
||||||
|
private static WiFiCommunication wifiCommunicationInstance;
|
||||||
|
private DeviceRepository mDeviceRepository;
|
||||||
|
|
||||||
|
private WiFiCommunication() {
|
||||||
|
port = 1234;
|
||||||
|
try {
|
||||||
|
socket = new DatagramSocket(port);
|
||||||
|
socket.setBroadcast(true);
|
||||||
|
address = InetAddress.getByName("255.255.255.255");
|
||||||
|
running = true;
|
||||||
|
isNewMessage = false;
|
||||||
|
new ReceiveThread().start();
|
||||||
|
new SendThread().start();
|
||||||
|
} catch (SocketException | UnknownHostException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized WiFiCommunication getInstance() {
|
||||||
|
if (wifiCommunicationInstance == null){
|
||||||
|
wifiCommunicationInstance = new WiFiCommunication();
|
||||||
|
}
|
||||||
|
return wifiCommunicationInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceRepository(DeviceRepository deviceRepository) {
|
||||||
|
this.mDeviceRepository = deviceRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewMessage(String newMessage, boolean isNewMessage){
|
||||||
|
this.sendMessage = newMessage;
|
||||||
|
this.isNewMessage = isNewMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopCommunication() {
|
||||||
|
running = false;
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SendThread extends Thread {
|
||||||
|
private int tmpCnt = 0;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
|
||||||
|
if(isNewMessage)
|
||||||
|
{
|
||||||
|
isNewMessage = false;
|
||||||
|
//todo: adapt send String
|
||||||
|
String txString = sendMessage;
|
||||||
|
byte[] txBuffer = txString.getBytes();
|
||||||
|
|
||||||
|
DatagramPacket txPacket = new DatagramPacket(txBuffer, txBuffer.length, address, port);
|
||||||
|
|
||||||
|
for(int i = 0; i < 20; i++) {
|
||||||
|
socket.send(txPacket);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (running);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ReceiveThread extends Thread {
|
||||||
|
private String rxString = "";
|
||||||
|
private String previousRxString = "";
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
do {
|
||||||
|
byte[] rxBuffer = new byte[1024];
|
||||||
|
DatagramPacket packet = new DatagramPacket(rxBuffer, rxBuffer.length);
|
||||||
|
socket.receive(packet);
|
||||||
|
rxString = new String(packet.getData(), 0, packet.getLength());
|
||||||
|
|
||||||
|
if(!previousRxString.equals(rxString)){
|
||||||
|
mDeviceRepository.getNewReceivedMessage(rxString);
|
||||||
|
|
||||||
|
}
|
||||||
|
previousRxString = rxString;
|
||||||
|
|
||||||
|
} while (running);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.example.greenwatch.models;
|
||||||
|
|
||||||
|
|
||||||
|
public class Device {
|
||||||
|
|
||||||
|
private String timeStamp;
|
||||||
|
private String deviceID;
|
||||||
|
private boolean sensorStatus;
|
||||||
|
private String sensorType;
|
||||||
|
private int sensorMassage;
|
||||||
|
|
||||||
|
public Device(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
|
this.timeStamp = timeStamp;
|
||||||
|
this.deviceID = deviceID;
|
||||||
|
this.sensorStatus = sensorStatus;
|
||||||
|
this.sensorType = sensorType;
|
||||||
|
this.sensorMassage = sensorMassage;
|
||||||
|
}
|
||||||
|
public void setTimeStamp(String timeStamp) {
|
||||||
|
this.timeStamp = timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimeStamp() {
|
||||||
|
return timeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceID(String deviceID) {
|
||||||
|
this.deviceID = deviceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceID() {
|
||||||
|
return deviceID;
|
||||||
|
}
|
||||||
|
public void setSensorType(String sensorType) {
|
||||||
|
this.sensorType = sensorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSensorType() {
|
||||||
|
return sensorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorStatus(boolean sensorStatus) {
|
||||||
|
this.sensorStatus = sensorStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getSensorStatus() {
|
||||||
|
return sensorStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorMassage(int sensorMassage) {
|
||||||
|
this.sensorMassage = sensorMassage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSensorMassage() {
|
||||||
|
return sensorMassage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,361 @@
|
|||||||
|
package com.example.greenwatch.repositories;
|
||||||
|
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import com.example.greenwatch.models.Device;
|
||||||
|
import com.example.greenwatch.communication.WiFiCommunication;
|
||||||
|
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DeviceRepository {
|
||||||
|
|
||||||
|
private final int maxAlarmHistoryListSize = 20;
|
||||||
|
private final String delimiter = ", ";
|
||||||
|
private final String sensorStatusKey = "An";
|
||||||
|
private String localDeviceUUID;
|
||||||
|
private static DeviceRepository deviceRepositoryInstance;
|
||||||
|
private WiFiCommunication mWiFiCommunication;
|
||||||
|
private boolean startAlarmRecordingValue;
|
||||||
|
private MutableLiveData<Boolean> startAlarmRecording = new MutableLiveData<>();
|
||||||
|
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>();
|
||||||
|
private MutableLiveData<List<Device>> alarmHistoryList = new MutableLiveData<>();
|
||||||
|
private HashMap<String, Device> connectedDevicesList = new HashMap<>();
|
||||||
|
private HashMap<String, String> deviceIDMapper = new HashMap<>();
|
||||||
|
private List<Device> alarmHistoryDeviceList = new ArrayList<>();
|
||||||
|
|
||||||
|
private DeviceRepository() {
|
||||||
|
setLocalDeviceUUID();
|
||||||
|
startAlarmRecordingValue = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized DeviceRepository getInstance() {
|
||||||
|
if (deviceRepositoryInstance == null){
|
||||||
|
deviceRepositoryInstance = new DeviceRepository();
|
||||||
|
}
|
||||||
|
return deviceRepositoryInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWiFiCommunication(WiFiCommunication wiFiCommunication) {
|
||||||
|
this.mWiFiCommunication = wiFiCommunication;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<List<Device>> getConnectedDeviceList() {
|
||||||
|
setMutableLiveDataDeviceList();
|
||||||
|
return deviceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<List<Device>> getAlarmHistoryDeviceList() {
|
||||||
|
setMutableLiveDataAlarmHistoryList();
|
||||||
|
return alarmHistoryList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<Boolean> getStartAlarmRecording() {
|
||||||
|
setMutableLiveDataStartAlarmRecording();
|
||||||
|
return startAlarmRecording;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){
|
||||||
|
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
||||||
|
if (sensorStatus) {
|
||||||
|
setAlarmHistoryDeviceList(newDevice);
|
||||||
|
}
|
||||||
|
boolean newStartAlarmRecordingValue = checkDeviceStatus();
|
||||||
|
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
|
||||||
|
startAlarmRecordingValue = newStartAlarmRecordingValue;
|
||||||
|
setMutableLiveDataStartAlarmRecording();
|
||||||
|
}
|
||||||
|
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice);
|
||||||
|
setMutableLiveDataDeviceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getNewReceivedMessage(String newMessage) {
|
||||||
|
String[] messageString = messageStringSplitter(newMessage);
|
||||||
|
if(messageString[0]=="1" && messageString.length == 7){
|
||||||
|
String timeStamp = messageString[1];
|
||||||
|
String deviceID = messageString[3];
|
||||||
|
boolean sensorStatus = convertSensorStatus(messageString[4]);
|
||||||
|
String sensorType = messageString[5];
|
||||||
|
int sensorMassage = Integer.valueOf(messageString[6]);
|
||||||
|
|
||||||
|
if (deviceID.equals(checkDeviceID(localDeviceUUID))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!connectedDevicesList.containsKey(deviceID)) {
|
||||||
|
createNewDevice(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String messageStringBuilder(String deviceID) {
|
||||||
|
StringBuilder message = new StringBuilder();
|
||||||
|
Device device = connectedDevicesList.get(deviceID);
|
||||||
|
if(device != null) {
|
||||||
|
message.append("1")
|
||||||
|
.append(delimiter)
|
||||||
|
.append(device.getTimeStamp())
|
||||||
|
.append(delimiter)
|
||||||
|
.append("Gruppe3")
|
||||||
|
.append(delimiter)
|
||||||
|
//.append(device.getDeviceID())
|
||||||
|
.append(getLocalIpAddress(deviceID))
|
||||||
|
.append(delimiter)
|
||||||
|
.append(device.getSensorStatus())
|
||||||
|
.append(delimiter)
|
||||||
|
.append(device.getSensorType())
|
||||||
|
.append(delimiter)
|
||||||
|
.append(device.getSensorMassage());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
message.append("")
|
||||||
|
.append(delimiter)
|
||||||
|
.append("")
|
||||||
|
.append(delimiter)
|
||||||
|
.append("")
|
||||||
|
.append(delimiter)
|
||||||
|
.append("")
|
||||||
|
.append(delimiter)
|
||||||
|
.append("")
|
||||||
|
.append(delimiter)
|
||||||
|
.append("")
|
||||||
|
.append(delimiter)
|
||||||
|
.append("");
|
||||||
|
}
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocalDeviceUUID() {
|
||||||
|
return localDeviceUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
device.setTimeStamp(timeStamp);
|
||||||
|
device.setSensorType(sensorType);
|
||||||
|
device.setSensorMassage(sensorMassage);
|
||||||
|
if (!device.getSensorStatus() && sensorStatus) {
|
||||||
|
setAlarmHistoryDeviceList(device);
|
||||||
|
}
|
||||||
|
device.setSensorStatus(sensorStatus);
|
||||||
|
boolean newStartAlarmRecordingValue = checkDeviceStatus();
|
||||||
|
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
|
||||||
|
startAlarmRecordingValue = newStartAlarmRecordingValue;
|
||||||
|
setMutableLiveDataStartAlarmRecording();
|
||||||
|
}
|
||||||
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
|
setMutableLiveDataDeviceList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeStamp(String deviceID, String timeStamp) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
device.setTimeStamp(timeStamp);
|
||||||
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
|
setMutableLiveDataDeviceList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimeStamp(String deviceID) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
return device.getTimeStamp();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceID(String deviceID, String newDeviceID) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
device.setDeviceID(newDeviceID);
|
||||||
|
setDeviceIDMapper(newDeviceID);
|
||||||
|
connectedDevicesList.remove(checkedDeviceID);
|
||||||
|
addToConnectedDeviceList(newDeviceID, device);
|
||||||
|
setMutableLiveDataDeviceList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceID(String deviceID) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
return device.getDeviceID();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorStatus(String deviceID, boolean sensorStatus) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
if (!device.getSensorStatus() && sensorStatus) {
|
||||||
|
setAlarmHistoryDeviceList(device);
|
||||||
|
}
|
||||||
|
device.setSensorStatus(sensorStatus);
|
||||||
|
boolean newStartAlarmRecordingValue = checkDeviceStatus();
|
||||||
|
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
|
||||||
|
startAlarmRecordingValue = newStartAlarmRecordingValue;
|
||||||
|
setMutableLiveDataStartAlarmRecording();
|
||||||
|
}
|
||||||
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
|
setMutableLiveDataDeviceList();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getSensorStatus(String deviceID) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
return device.getSensorStatus();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorType(String deviceID, String sensorType) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
device.setSensorType(sensorType);
|
||||||
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
|
setMutableLiveDataDeviceList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSensorType(String deviceID) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
return device.getSensorType();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorMassage(String deviceID, int sensorMessage) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
device.setSensorMassage(sensorMessage);
|
||||||
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
|
setMutableLiveDataDeviceList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSensorMassage(String deviceID) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
return device.getSensorMassage();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSystemTimeStamp() {
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
Date date = new Date(System.currentTimeMillis());
|
||||||
|
return formatter.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMutableLiveDataDeviceList() {
|
||||||
|
List<Device> list = new ArrayList<>(connectedDevicesList.values());
|
||||||
|
deviceList.setValue(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMutableLiveDataAlarmHistoryList() {
|
||||||
|
alarmHistoryList.setValue(alarmHistoryDeviceList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMutableLiveDataStartAlarmRecording() {
|
||||||
|
startAlarmRecording.setValue(startAlarmRecordingValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToConnectedDeviceList(String key, Device device) {
|
||||||
|
connectedDevicesList.put(key, device);
|
||||||
|
if (key.equals(checkDeviceID(localDeviceUUID))) {
|
||||||
|
mWiFiCommunication.setNewMessage(messageStringBuilder(device.getDeviceID()),true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String checkDeviceID(String deviceID) {
|
||||||
|
if(!deviceIDMapper.isEmpty() && deviceID.equals(localDeviceUUID)) {
|
||||||
|
return deviceIDMapper.get(deviceID);
|
||||||
|
}
|
||||||
|
return deviceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDeviceIDMapper(String deviceID) {
|
||||||
|
deviceIDMapper.put(localDeviceUUID, deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setLocalDeviceUUID(){
|
||||||
|
this.localDeviceUUID = UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] messageStringSplitter(String message) {
|
||||||
|
return message.split(delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean convertSensorStatus(String status) {
|
||||||
|
return status.equals(sensorStatusKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAlarmHistoryDeviceList(Device device) {
|
||||||
|
if (alarmHistoryDeviceList.size() == maxAlarmHistoryListSize) {
|
||||||
|
alarmHistoryDeviceList.remove(alarmHistoryDeviceList.size() -1);
|
||||||
|
}
|
||||||
|
Device alarmHistoryDevice = new Device(device.getTimeStamp(), device.getDeviceID(), device.getSensorStatus(), device.getSensorType(), device.getSensorMassage());
|
||||||
|
alarmHistoryDeviceList.add(0, alarmHistoryDevice);
|
||||||
|
setMutableLiveDataAlarmHistoryList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkDeviceStatus() {
|
||||||
|
for (Device device : connectedDevicesList.values()) {
|
||||||
|
if (device.getSensorStatus()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocalIpAddress(String deviceID) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null){
|
||||||
|
try {
|
||||||
|
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
||||||
|
NetworkInterface networkInterface = (NetworkInterface) ((Enumeration<?>) en).nextElement();
|
||||||
|
for (Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements();) {
|
||||||
|
InetAddress inetAddress = addresses.nextElement();
|
||||||
|
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
|
||||||
|
return inetAddress.getHostAddress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SocketException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
package com.example.greenwatch.sensors;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.ImageFormat;
|
||||||
|
import android.media.Image;
|
||||||
|
import android.util.Size;
|
||||||
|
|
||||||
|
import androidx.camera.core.CameraSelector;
|
||||||
|
import androidx.camera.core.ImageAnalysis;
|
||||||
|
import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
public class CameraSensor {
|
||||||
|
private final MutableLiveData<Boolean> mVideoAlarmDetected = new MutableLiveData<>();
|
||||||
|
private static CameraSensor cameraSensorInstance;
|
||||||
|
private boolean videoAlarmDetected;
|
||||||
|
private ByteBuffer previousBuffer;
|
||||||
|
private int previousWidth;
|
||||||
|
private int previousHeight;
|
||||||
|
|
||||||
|
private CameraSensor() {
|
||||||
|
videoAlarmDetected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized CameraSensor getInstance() {
|
||||||
|
if (cameraSensorInstance == null){
|
||||||
|
cameraSensorInstance = new CameraSensor();
|
||||||
|
}
|
||||||
|
return cameraSensorInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<Boolean> getVideoAlarmDetectedValue() {
|
||||||
|
setMutableLiveDataVideoAlarmDetected();
|
||||||
|
return mVideoAlarmDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMutableLiveDataVideoAlarmDetected() {
|
||||||
|
mVideoAlarmDetected.setValue(videoAlarmDetected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindImageAnalysis(ProcessCameraProvider cameraProvider, LifecycleOwner lifecycleOwner, Context context) {
|
||||||
|
ImageAnalysis.Builder builder = new ImageAnalysis.Builder();
|
||||||
|
builder.setTargetResolution(new Size(640, 480));
|
||||||
|
builder.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST);
|
||||||
|
ImageAnalysis imageAnalysis = builder.build();
|
||||||
|
imageAnalysis.setAnalyzer(
|
||||||
|
ContextCompat.getMainExecutor(context),
|
||||||
|
imageProxy -> {
|
||||||
|
|
||||||
|
int imageFormat = imageProxy.getFormat();
|
||||||
|
|
||||||
|
if (imageFormat == ImageFormat.YUV_420_888) {
|
||||||
|
|
||||||
|
Image currentImage = imageProxy.getImage();
|
||||||
|
|
||||||
|
if (previousHeight != 0) {
|
||||||
|
assert currentImage != null;
|
||||||
|
videoAlarmDetected = compareFrames(currentImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert currentImage != null;
|
||||||
|
Image.Plane[] planes = currentImage.getPlanes();
|
||||||
|
ByteBuffer buffer = planes[0].getBuffer().duplicate();
|
||||||
|
previousBuffer = ByteBuffer.allocateDirect(buffer.remaining());
|
||||||
|
previousBuffer.put(buffer);
|
||||||
|
previousWidth = currentImage.getWidth();
|
||||||
|
previousHeight = currentImage.getHeight();
|
||||||
|
|
||||||
|
currentImage.close();
|
||||||
|
|
||||||
|
checkAlarmCondition();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
imageProxy.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
CameraSelector cameraSelector = new CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_BACK).build();
|
||||||
|
|
||||||
|
cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, imageAnalysis);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean compareFrames(Image currentImage) {
|
||||||
|
|
||||||
|
ByteBuffer currentBuffer = currentImage.getPlanes()[0].getBuffer();
|
||||||
|
|
||||||
|
int currentWidth = currentImage.getWidth();
|
||||||
|
int currentHeight = currentImage.getHeight();
|
||||||
|
|
||||||
|
if (previousWidth != currentWidth || previousHeight != currentHeight) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int row = 0; row < previousHeight; row++) {
|
||||||
|
for (int col = 0; col < previousWidth; col++) {
|
||||||
|
|
||||||
|
int previousIndex = row * previousWidth + col;
|
||||||
|
int currentIndex = row * currentWidth + col;
|
||||||
|
|
||||||
|
int previousPixel = previousBuffer.get(previousIndex) & 0xFF;
|
||||||
|
int currentPixel = currentBuffer.get(currentIndex) & 0xFF;
|
||||||
|
|
||||||
|
int pixelDifference = Math.abs(previousPixel - currentPixel);
|
||||||
|
int threshold = 120;
|
||||||
|
|
||||||
|
if (pixelDifference > threshold) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkAlarmCondition() {
|
||||||
|
if (videoAlarmDetected && !mVideoAlarmDetected.getValue()) {
|
||||||
|
setMutableLiveDataVideoAlarmDetected();
|
||||||
|
}
|
||||||
|
else if (!videoAlarmDetected && mVideoAlarmDetected.getValue()){
|
||||||
|
setMutableLiveDataVideoAlarmDetected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
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 java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AccelerometerViewModel extends ViewModel implements ViewModelInterface {
|
||||||
|
|
||||||
|
private MutableLiveData<List<Device>> mDeviceList;
|
||||||
|
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>();
|
||||||
|
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||||
|
private MutableLiveData<Boolean> mStartAlarmRecording;
|
||||||
|
private DeviceRepository mDeviceRepository;
|
||||||
|
private ArrayList<Float> Gesamt_be;
|
||||||
|
int arraySize = 500;
|
||||||
|
int functionCallCount;
|
||||||
|
float meanValue;
|
||||||
|
float offsetValue;
|
||||||
|
float thresholdValue;
|
||||||
|
boolean startMeasuring;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
if (mDeviceList == null) {
|
||||||
|
mDeviceRepository = DeviceRepository.getInstance();
|
||||||
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
|
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||||
|
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
|
||||||
|
}
|
||||||
|
initGesamtBE();
|
||||||
|
mMovementDetected.setValue(false);
|
||||||
|
functionCallCount = 0;
|
||||||
|
meanValue = 0f;
|
||||||
|
offsetValue = 0.1f;
|
||||||
|
thresholdValue = 0.15f;
|
||||||
|
startMeasuring = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initGesamtBE() {
|
||||||
|
Gesamt_be = new ArrayList<>(arraySize);
|
||||||
|
for (int i = 0; i < arraySize; i++) {
|
||||||
|
Gesamt_be.add(0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 && !mMovementDetected.getValue()) {
|
||||||
|
mMovementDetected.setValue(true);
|
||||||
|
}
|
||||||
|
else if (meanValue < (thresholdValue + offsetValue) && mMovementDetected.getValue()){
|
||||||
|
mMovementDetected.setValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Boolean> getMovementDetectedValue() {
|
||||||
|
return mMovementDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
package com.example.greenwatch.viewmodels;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
|
||||||
|
import com.example.greenwatch.communication.WiFiCommunication;
|
||||||
|
import com.example.greenwatch.models.Device;
|
||||||
|
import com.example.greenwatch.repositories.DeviceRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MainActivityViewModel extends ViewModel implements ViewModelInterface {
|
||||||
|
|
||||||
|
private MutableLiveData<List<Device>> mDeviceList;
|
||||||
|
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||||
|
private MutableLiveData<Boolean> mStartAlarmRecording;
|
||||||
|
private DeviceRepository mDeviceRepository;
|
||||||
|
private static final int RIGHTS_REQUEST_CAMERA = 10;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
WiFiCommunication mWiFiCommunication;
|
||||||
|
if(mDeviceList != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//todo: check if WiFi instanz can be hold only by the repository
|
||||||
|
mDeviceRepository = DeviceRepository.getInstance();
|
||||||
|
mWiFiCommunication = WiFiCommunication.getInstance();
|
||||||
|
mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
|
||||||
|
mWiFiCommunication.setDeviceRepository(mDeviceRepository);
|
||||||
|
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
|
||||||
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
|
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}, RIGHTS_REQUEST_CAMERA);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+196
@@ -0,0 +1,196 @@
|
|||||||
|
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 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;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Observer<Boolean> observer = new Observer<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(Boolean aBoolean) {
|
||||||
|
if (mVideoAlarmDetected.getValue() || mAccelerometerAlarmDetected.getValue() && !VideodetectionAndAccelerometerAlarmDetected) {
|
||||||
|
VideodetectionAndAccelerometerAlarmDetected = true;
|
||||||
|
setMutableLiveDataVideodetectionAndAccelerometerAlarmDetected();
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (!mVideoAlarmDetected.getValue() && !mAccelerometerAlarmDetected.getValue() && 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
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.ViewModel;
|
||||||
|
|
||||||
|
import com.example.greenwatch.models.Device;
|
||||||
|
import com.example.greenwatch.repositories.DeviceRepository;
|
||||||
|
import com.example.greenwatch.sensors.CameraSensor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class VideodetectionViewModel extends ViewModel implements ViewModelInterface {
|
||||||
|
|
||||||
|
private MutableLiveData<List<Device>> mDeviceList;
|
||||||
|
private MutableLiveData<Boolean> mVideoAlarmDetected;
|
||||||
|
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||||
|
private MutableLiveData<Boolean> mStartAlarmRecording;
|
||||||
|
private DeviceRepository mDeviceRepository;
|
||||||
|
private CameraSensor mCameraSensor;
|
||||||
|
|
||||||
|
|
||||||
|
public LiveData<Boolean> getVideoMovementDetectedValue() {
|
||||||
|
return mVideoAlarmDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
if (mDeviceRepository == null) {
|
||||||
|
mDeviceRepository = DeviceRepository.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 (mVideoAlarmDetected == null) {
|
||||||
|
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindImageAnalysis(ProcessCameraProvider cameraProvider, LifecycleOwner lifecycleOwner, Context context) {
|
||||||
|
mCameraSensor.bindImageAnalysis(cameraProvider, lifecycleOwner, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Boolean> getVideoAlarmDetectedValue() {
|
||||||
|
return mVideoAlarmDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.example.greenwatch.viewmodels;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import com.example.greenwatch.models.Device;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ViewModelInterface {
|
||||||
|
void init();
|
||||||
|
LiveData<List<Device>> getConnectedDeviceList();
|
||||||
|
LiveData<List<Device>> getAlarmHistoryList();
|
||||||
|
LiveData<Boolean> getStartAlarmRecording();
|
||||||
|
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage);
|
||||||
|
void setTimeStamp(String deviceID, String timeStamp);
|
||||||
|
String getTimeStamp(String deviceID);
|
||||||
|
void setDeviceID(String deviceID, String newDeviceID);
|
||||||
|
String getDeviceID(String deviceID);
|
||||||
|
void setSensorStatus(String deviceID, boolean sensorStatus);
|
||||||
|
boolean getSensorStatus(String deviceID);
|
||||||
|
void setSensorType(String deviceID, String sensorType);
|
||||||
|
String getSensorType(String deviceID);
|
||||||
|
void setSensorMassage(String deviceID, int sensorMessage);
|
||||||
|
int getSensorMassage(String deviceID);
|
||||||
|
String getLocalDeviceUUID();
|
||||||
|
String getSystemTimeStamp();
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp"
|
||||||
|
tools:context=".AccelerometerActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAccelerometerStatusmessage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAccelerometerData"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAccelerometerWarning"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/accelerometerBackToMainActivity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Back to MainActivity">
|
||||||
|
</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>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp"
|
||||||
|
tools:context=".AudiodetectionActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAudiodetectionStatusmessage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Audiodetection Activity">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/audiodetectorBackToMainActivity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Back to MainActivity">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp"
|
||||||
|
tools:context=".AudiodetectionAndAccelerometerActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAudiodetectionAndAccelerometerStatusmessage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Audiodetection + Accelerometer Activity">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/audiodetectionAndAccelerometerBackToMainActivity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Back to MainActivity">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:context=".Beschleunigungssensor">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/DatenBsensor"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/WarnungBsensor"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/test"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="" />
|
|
||||||
</LinearLayout>
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
@@ -1,47 +1,83 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/alarmHistoryListRecyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="3"
|
||||||
|
tools:listitem="@layout/alarm_history_item">
|
||||||
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/deviceListRecyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="3"
|
||||||
|
tools:listitem="@layout/device_item">
|
||||||
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:layout_weight="3">
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="TextView"
|
|
||||||
tools:layout_editor_absoluteX="171dp"
|
|
||||||
tools:layout_editor_absoluteY="186dp" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView2"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="TextView" />
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/beschleunigungssensor"
|
android:id="@+id/audiodetectionButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Beschleunigungssensor" />
|
android:layout_weight="1"
|
||||||
|
android:text="Audiodetection">
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/aufnahme"
|
android:id="@+id/videodetectionButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Aufnahme Start" />
|
android:layout_weight="1"
|
||||||
|
android:text="Videodetection">
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/wiedergabe"
|
android:id="@+id/accelerometerButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Wiedergabe" />
|
android:layout_weight="1"
|
||||||
|
android:text="Accelerometer">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/audiodetectionAndAccelerometerButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Audiodetection + Accelerometer">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/videodetectionAndAccelerometerButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Videodetection + Accelerometer">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/connectionButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Connect to Devices">
|
||||||
|
</Button>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</LinearLayout>
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp"
|
||||||
|
tools:context=".VideodetectionActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvVideodetectionStatusmessage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Videodetection Activity">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/videodetectorBackToMainActivity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Back to MainActivity">
|
||||||
|
</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>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="10dp"
|
||||||
|
tools:context=".VideodetectionAndAccelerometerActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvvideodetectionAndAccelerometerStatusmessage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="">
|
||||||
|
</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>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/videodetectionAndAccelerometerBackToMainActivity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Back to MainActivity">
|
||||||
|
</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>
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="8dp">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAlarmHistoryDeviceSensorType"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/sensor_type_placeholder"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:ellipsize="end">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAlarmHistoryDeviceID"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/tvAlarmHistoryDeviceSensorType"
|
||||||
|
android:text="@string/deviceID_placeholder">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAlarmHistoryDeviceTimeStamp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/tvAlarmHistoryDeviceID"
|
||||||
|
android:text="@string/sensor_time_stamp_placeholder">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAlarmHistoryDeviceSensorMassage"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/tvAlarmHistoryDeviceTimeStamp"
|
||||||
|
android:text="@string/sensor_message_placeholder">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="8dp"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginTop="8dp">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvDeviceSensorStatus"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:text="@string/sensor_status_placeholder"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvDeviceSensorType"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/sensor_type_placeholder"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:layout_toStartOf="@id/tvDeviceSensorStatus"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:ellipsize="end">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvDeviceID"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/tvDeviceSensorType"
|
||||||
|
android:text="@string/deviceID_placeholder">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvDeviceTimeStamp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/tvDeviceID"
|
||||||
|
android:text="@string/sensor_time_stamp_placeholder">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvDeviceSensorMassage"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/tvDeviceTimeStamp"
|
||||||
|
android:text="@string/sensor_message_placeholder">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">GreenWatch</string>
|
<string name="app_name">GreenWatch</string>
|
||||||
|
<string name="sensor_type_placeholder">Sensortyp: %s</string>
|
||||||
|
<string name="sensor_status_placeholder">Sensorstatus: %s</string>
|
||||||
|
<string name="deviceID_placeholder">Sensor-ID: %s</string>
|
||||||
|
<string name="sensor_time_stamp_placeholder">Timestamp: %s</string>
|
||||||
|
<string name="sensor_message_placeholder">Sensormessage: %d</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user