Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccdff78a4a | ||
|
|
373ca2d106 | ||
|
|
28c98ba766 | ||
|
|
559a95b1c2 | ||
|
|
9f253b655c | ||
|
|
d38e05a4b6 | ||
|
|
595d97ef57 | ||
|
|
1c360e8604 | ||
|
|
bd2927ed64 | ||
|
|
30f9c6c3f4 | ||
|
|
9e3652e275 |
No files matched your search
@@ -2,8 +2,6 @@
|
|||||||
<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" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
@@ -11,6 +9,24 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.GreenWatch">
|
android:theme="@style/Theme.GreenWatch">
|
||||||
|
<activity
|
||||||
|
android:name=".ConnectionActivity"
|
||||||
|
android:exported="false" />
|
||||||
|
<activity
|
||||||
|
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" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
|
|||||||
@@ -0,0 +1,137 @@
|
|||||||
|
package com.example.greenwatch;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.lifecycle.Observer;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
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.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);
|
||||||
|
|
||||||
|
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) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("Time Stamp: ");
|
||||||
|
sb.append(mAccelerometerViewModel.getTimeStamp(mAccelerometerViewModel.getLocalDeviceUUID()));
|
||||||
|
sb.append(";\n");
|
||||||
|
sb.append("DeviceID: ");
|
||||||
|
sb.append(mAccelerometerViewModel.getDeviceID(mAccelerometerViewModel.getLocalDeviceUUID()));
|
||||||
|
sb.append(";\n");
|
||||||
|
sb.append("Sensor Status: ");
|
||||||
|
sb.append(mAccelerometerViewModel.getSensorStatus(mAccelerometerViewModel.getLocalDeviceUUID()));
|
||||||
|
sb.append(";\n");
|
||||||
|
sb.append("Sensor Type: ");
|
||||||
|
sb.append(mAccelerometerViewModel.getSensorType(mAccelerometerViewModel.getLocalDeviceUUID()));
|
||||||
|
sb.append(";\n");
|
||||||
|
sb.append("Sensor Massage: ");
|
||||||
|
sb.append(mAccelerometerViewModel.getSensorMassage(mAccelerometerViewModel.getLocalDeviceUUID()));
|
||||||
|
accelerometerStatusMessage.setText(sb);
|
||||||
|
Toast.makeText(AccelerometerActivity.this, "onChanged", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(Boolean aBoolean) {
|
||||||
|
if (aBoolean) {
|
||||||
|
mAccelerometerViewModel.setDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), mAccelerometerViewModel.getLocalDeviceUUID(), true, "Accelerometer", 10);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mAccelerometerViewModel.setDevice(mAccelerometerViewModel.getLocalDeviceUUID(), mAccelerometerViewModel.getSystemTimeStamp(), mAccelerometerViewModel.getLocalDeviceUUID(), 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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 ConnectionActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private Button backToMainActivity;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_connection);
|
||||||
|
|
||||||
|
backToMainActivity = (Button) findViewById(R.id.connectionBackToMainActivity);
|
||||||
|
|
||||||
|
backToMainActivity.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,56 +1,138 @@
|
|||||||
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 android.annotation.SuppressLint;
|
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.EditText;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import java.net.SocketException;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
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 {
|
||||||
WifiCommunication communication; //Member WifiCommunication
|
|
||||||
TextView tvReceivedData; //Test Textview um empfangene Daten anzuzeigen -> Gegen finale Textview in der Anzeige austauschen
|
|
||||||
//ToDo: Falls finale Textview zum Anzeigen der Nachricht anders heißt, muss das in der Klasse WifiCommunication.java angepasst werden!
|
|
||||||
// Wo anpassen: Receive Thread, Zeile 58
|
|
||||||
private EditText etSendMessage; //Test Edittext um eine Nachricht zu senden -> gegen Nachricht von den Sensoren austauschen
|
|
||||||
private Button btnSend; //Test Sendebutton
|
|
||||||
|
|
||||||
private String sendmsg = "default";
|
private TextView tvstatusmessage;
|
||||||
|
private Button audiodetectionButton;
|
||||||
|
private Button videodetectionButton;
|
||||||
|
private Button accelerometerButton;
|
||||||
|
private Button audiodetectionAndAccelerometerButton;
|
||||||
|
private Button videodetectionAndAccelerometerButton;
|
||||||
|
private Button connectionButton;
|
||||||
|
private MainActivityViewModel mMainActivityViewModel;
|
||||||
|
|
||||||
@SuppressLint("MissingInflatedId")
|
|
||||||
@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);
|
||||||
|
|
||||||
xmlToJava(); //Funktionsaufruf, wo die Testbuttons etc angelegt sind
|
tvstatusmessage = (TextView) findViewById(R.id.tvStatusmessage);
|
||||||
|
audiodetectionButton = (Button) findViewById(R.id.audiodetectionButton);
|
||||||
|
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);
|
||||||
|
|
||||||
|
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
|
||||||
|
mMainActivityViewModel.init();
|
||||||
|
mMainActivityViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(List<Device> devices) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("Time Stamp: ");
|
||||||
|
sb.append(mMainActivityViewModel.getTimeStamp(mMainActivityViewModel.getLocalDeviceUUID()));
|
||||||
|
sb.append(";\n");
|
||||||
|
sb.append("DeviceID: ");
|
||||||
|
sb.append(mMainActivityViewModel.getDeviceID(mMainActivityViewModel.getLocalDeviceUUID()));
|
||||||
|
sb.append(";\n");
|
||||||
|
sb.append("Sensor Status: ");
|
||||||
|
sb.append(mMainActivityViewModel.getSensorStatus(mMainActivityViewModel.getLocalDeviceUUID()));
|
||||||
|
sb.append(";\n");
|
||||||
|
sb.append("Sensor Type: ");
|
||||||
|
sb.append(mMainActivityViewModel.getSensorType(mMainActivityViewModel.getLocalDeviceUUID()));
|
||||||
|
sb.append(";\n");
|
||||||
|
sb.append("Sensor Massage: ");
|
||||||
|
sb.append(mMainActivityViewModel.getSensorMassage(mMainActivityViewModel.getLocalDeviceUUID()));
|
||||||
|
tvstatusmessage.setText(sb);
|
||||||
|
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
audiodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//openAudiodetectionActivity();
|
||||||
|
mMainActivityViewModel.setDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", "12345", false, "Audio", 10);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
videodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//openVideodetectionActivity();
|
||||||
|
mMainActivityViewModel.setSensorType(mMainActivityViewModel.getLocalDeviceUUID(), "Video");
|
||||||
|
mMainActivityViewModel.setTimeStamp(mMainActivityViewModel.getLocalDeviceUUID(), "12:50");
|
||||||
|
mMainActivityViewModel.setDeviceID(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getLocalDeviceUUID());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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(){
|
||||||
|
Intent intent = new Intent(this, AudiodetectionActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void xmlToJava(){
|
|
||||||
tvReceivedData = findViewById(R.id.tvRecTxt); //Test Textview
|
|
||||||
etSendMessage = findViewById(R.id.sendMessage); //Test Nachricht
|
|
||||||
btnSend = findViewById(R.id.btnSend); //Test Sendebefehl
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClickSend(View view) throws SocketException{ //ToDo: Sendebefehl mit boolscher Variable lösen --> wo setzen?
|
|
||||||
sendmsg = etSendMessage.getText().toString(); //ToDo: hier String von Sensoren übergeben
|
|
||||||
communication.setMessage(sendmsg, true); //übergibt zu sendenden String und setzt die entscheidende Boolsche Variable fürs Senden
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
//Erstellen des Members
|
|
||||||
communication = new WifiCommunication(MainActivity.this, MainActivity.this, 1234);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
//schließt socket
|
|
||||||
communication.stopCommunication();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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 VideodetectionActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private Button backToMainActivity;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_videodetection);
|
||||||
|
|
||||||
|
backToMainActivity = (Button) findViewById(R.id.videodetectorBackToMainActivity);
|
||||||
|
|
||||||
|
backToMainActivity.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 VideodetectionAndAccelerometerActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private Button backToMainActivity;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_videodetection_and_accelerometer);
|
||||||
|
|
||||||
|
backToMainActivity = (Button) findViewById(R.id.videodetectionAndAccelerometerBackToMainActivity);
|
||||||
|
|
||||||
|
backToMainActivity.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
package com.example.greenwatch;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
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 MainActivity mainActivity;
|
|
||||||
private final InetAddress address;
|
|
||||||
private final int port;
|
|
||||||
private final Context context;
|
|
||||||
private boolean newMsg;
|
|
||||||
private String rxString;
|
|
||||||
private String sendMsg;
|
|
||||||
//private String sendMsg = "default";
|
|
||||||
private final DatagramSocket socket;
|
|
||||||
volatile private boolean running;
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
public WifiCommunication(MainActivity mainActivity, Context context, int port) {
|
|
||||||
this.mainActivity = mainActivity;
|
|
||||||
this.port = port;
|
|
||||||
this.context = context;
|
|
||||||
try {
|
|
||||||
socket = new DatagramSocket(this.port);
|
|
||||||
socket.setBroadcast(true);
|
|
||||||
address = InetAddress.getByName("255.255.255.255");
|
|
||||||
running = true;
|
|
||||||
new ReceiveThread().start();
|
|
||||||
new SendThread().start();
|
|
||||||
} catch (SocketException | UnknownHostException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
mainActivity.runOnUiThread(() -> Toast.makeText(context,"Communication running", Toast.LENGTH_SHORT).show());
|
|
||||||
}
|
|
||||||
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))
|
|
||||||
mainActivity.runOnUiThread(() -> mainActivity.tvReceivedData.setText(rxString));
|
|
||||||
|
|
||||||
previousRxString = rxString;
|
|
||||||
|
|
||||||
} while (running);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String showMessage(){
|
|
||||||
return rxString;
|
|
||||||
}
|
|
||||||
public void setMessage(String message, boolean newMsg){
|
|
||||||
this.sendMsg=message;
|
|
||||||
this.newMsg = newMsg;
|
|
||||||
}
|
|
||||||
private class SendThread extends Thread {
|
|
||||||
private int tmpCnt = 0;
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
do {
|
|
||||||
|
|
||||||
if(newMsg == true)
|
|
||||||
{
|
|
||||||
newMsg = false;
|
|
||||||
|
|
||||||
String txString = getLocalIpAddress() + " sends. #" + tmpCnt++ + sendMsg;
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static String getLocalIpAddress() {
|
|
||||||
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 null;
|
|
||||||
}
|
|
||||||
public void stopCommunication() {
|
|
||||||
running = false;
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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,216 @@
|
|||||||
|
package com.example.greenwatch.repositories;
|
||||||
|
|
||||||
|
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import com.example.greenwatch.models.Device;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class DeviceRepository {
|
||||||
|
|
||||||
|
private String delimiter = ", ";
|
||||||
|
private String deviceUUID;
|
||||||
|
private static DeviceRepository deviceRepositoryInstance;
|
||||||
|
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>();
|
||||||
|
private HashMap<String, Device> connectedDevicesList = new HashMap<>();
|
||||||
|
private HashMap<String, String> deviceIDMapper = new HashMap<>();
|
||||||
|
|
||||||
|
public static synchronized DeviceRepository getInstance() {
|
||||||
|
if (deviceRepositoryInstance == null){
|
||||||
|
deviceRepositoryInstance = new DeviceRepository();
|
||||||
|
deviceRepositoryInstance.setDeviceUUID();
|
||||||
|
}
|
||||||
|
return deviceRepositoryInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<List<Device>> getConnectedDeviceList() {
|
||||||
|
setMutableLiveDataValue();
|
||||||
|
return deviceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){
|
||||||
|
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
||||||
|
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice);
|
||||||
|
setMutableLiveDataValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createNewRemoteDevice(String message) {
|
||||||
|
String[] messageString = messageStringSplitter(message);
|
||||||
|
String timeStamp = messageString[0];
|
||||||
|
String deviceID = messageString[1];
|
||||||
|
boolean sensorStatus = Boolean.valueOf(messageString[1]);
|
||||||
|
String sensorType = messageString[3];
|
||||||
|
int sensorMassage = Integer.valueOf(messageString[4]);
|
||||||
|
|
||||||
|
if(!connectedDevicesList.containsKey(deviceID)) {
|
||||||
|
createNewDevice(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String messageStringBuilder(String deviceID) {
|
||||||
|
StringBuilder message = new StringBuilder();
|
||||||
|
Device device = connectedDevicesList.get(deviceID);
|
||||||
|
if(device != null) {
|
||||||
|
message.append(device.getTimeStamp())
|
||||||
|
.append(delimiter)
|
||||||
|
.append(device.getDeviceID())
|
||||||
|
.append(delimiter)
|
||||||
|
.append(device.getSensorStatus())
|
||||||
|
.append(delimiter)
|
||||||
|
.append(device.getSensorType())
|
||||||
|
.append(delimiter)
|
||||||
|
.append(device.getSensorMassage());
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocalDeviceUUID() {
|
||||||
|
return deviceUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevice(String deviceID, String timeStamp, String newDeviceID, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
device.setTimeStamp(timeStamp);
|
||||||
|
device.setDeviceID(newDeviceID);
|
||||||
|
device.setSensorStatus(sensorStatus);
|
||||||
|
device.setSensorType(sensorType);
|
||||||
|
device.setSensorMassage(sensorMassage);
|
||||||
|
setDeviceIDMapper(newDeviceID);
|
||||||
|
connectedDevicesList.remove(checkedDeviceID);
|
||||||
|
addToConnectedDeviceList(newDeviceID, device);
|
||||||
|
setMutableLiveDataValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
setMutableLiveDataValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
setMutableLiveDataValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
device.setSensorStatus(sensorStatus);
|
||||||
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
|
setMutableLiveDataValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
setMutableLiveDataValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
setMutableLiveDataValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSensorMassage(String deviceID) {
|
||||||
|
String checkedDeviceID = checkDeviceID(deviceID);
|
||||||
|
Device device = connectedDevicesList.get(checkedDeviceID);
|
||||||
|
if(device != null) {
|
||||||
|
return device.getSensorMassage();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setMutableLiveDataValue() {
|
||||||
|
List<Device> list = new ArrayList<>(connectedDevicesList.values());
|
||||||
|
deviceList.setValue(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToConnectedDeviceList(String key, Device device) {
|
||||||
|
connectedDevicesList.put(key, device);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String checkDeviceID(String deviceID) {
|
||||||
|
if(!deviceIDMapper.isEmpty() && deviceID.equals(deviceUUID)) {
|
||||||
|
return deviceIDMapper.get(deviceID);
|
||||||
|
}
|
||||||
|
return deviceID;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDeviceIDMapper(String deviceID) {
|
||||||
|
deviceIDMapper.put(deviceUUID, deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setDeviceUUID(){
|
||||||
|
this.deviceUUID = UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String[] messageStringSplitter(String message) {
|
||||||
|
return message.split(delimiter);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
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 {
|
||||||
|
|
||||||
|
private MutableLiveData<List<Device>> mDeviceList;
|
||||||
|
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>();
|
||||||
|
private DeviceRepository mDeviceRepository;
|
||||||
|
private ArrayList<Float> Gesamt_be;
|
||||||
|
int arraySize = 500;
|
||||||
|
int functionCallCount;
|
||||||
|
float meanValue;
|
||||||
|
float offsetValue;
|
||||||
|
float thresholdValue;
|
||||||
|
boolean startMeasuring;
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
if (mDeviceList == null) {
|
||||||
|
mDeviceRepository = DeviceRepository.getInstance();
|
||||||
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
|
}
|
||||||
|
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 String getSystemTimeStamp() {
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
||||||
|
Date date = new Date(System.currentTimeMillis());
|
||||||
|
return formatter.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Boolean> getMovementDetectedValue() {
|
||||||
|
return mMovementDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<List<Device>> getConnectedDeviceList() {
|
||||||
|
return mDeviceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevice(String deviceID, String timeStamp, String newDeviceID, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
|
mDeviceRepository.setDevice(deviceID, timeStamp,newDeviceID, sensorStatus, sensorType, sensorMassage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeStamp(String deviceID, String timeStamp) {
|
||||||
|
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimeStamp(String deviceID) {
|
||||||
|
return mDeviceRepository.getTimeStamp(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceID(String deviceID, String newDeviceID) {
|
||||||
|
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceID(String deviceID) {
|
||||||
|
return mDeviceRepository.getDeviceID(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorStatus(String deviceID, boolean sensorStatus) {
|
||||||
|
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getSensorStatus(String deviceID) {
|
||||||
|
return mDeviceRepository.getSensorStatus(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorType(String deviceID, String sensorType) {
|
||||||
|
mDeviceRepository.setSensorType(deviceID, sensorType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSensorType(String deviceID) {
|
||||||
|
return mDeviceRepository.getSensorType(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorMassage(String deviceID, int sensorMessage) {
|
||||||
|
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSensorMassage(String deviceID) {
|
||||||
|
return mDeviceRepository.getSensorMassage(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocalDeviceUUID() {
|
||||||
|
return mDeviceRepository.getLocalDeviceUUID();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
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.util.List;
|
||||||
|
|
||||||
|
public class MainActivityViewModel extends ViewModel {
|
||||||
|
|
||||||
|
private MutableLiveData<List<Device>> mDeviceList;
|
||||||
|
private DeviceRepository mDeviceRepository;
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
if(mDeviceList != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mDeviceRepository = DeviceRepository.getInstance();
|
||||||
|
mDeviceRepository.createNewDevice("", mDeviceRepository.getLocalDeviceUUID(), false, "", 0);
|
||||||
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<List<Device>> getConnectedDeviceList() {
|
||||||
|
return mDeviceList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDevice(String deviceID, String timeStamp, String newDeviceID, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
|
mDeviceRepository.setDevice(deviceID, timeStamp,newDeviceID, sensorStatus, sensorType, sensorMassage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeStamp(String deviceID, String timeStamp) {
|
||||||
|
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTimeStamp(String deviceID) {
|
||||||
|
return mDeviceRepository.getTimeStamp(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceID(String deviceID, String newDeviceID) {
|
||||||
|
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceID(String deviceID) {
|
||||||
|
return mDeviceRepository.getDeviceID(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorStatus(String deviceID, boolean sensorStatus) {
|
||||||
|
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getSensorStatus(String deviceID) {
|
||||||
|
return mDeviceRepository.getSensorStatus(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorType(String deviceID, String sensorType) {
|
||||||
|
mDeviceRepository.setSensorType(deviceID, sensorType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSensorType(String deviceID) {
|
||||||
|
return mDeviceRepository.getSensorType(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSensorMassage(String deviceID, int sensorMessage) {
|
||||||
|
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSensorMassage(String deviceID) {
|
||||||
|
return mDeviceRepository.getSensorMassage(deviceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocalDeviceUUID() {
|
||||||
|
return mDeviceRepository.getLocalDeviceUUID();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?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>
|
||||||
@@ -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>
|
||||||
@@ -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=".ConnectionActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvConnectionStatusmessage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Connection Activity">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/connectionBackToMainActivity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Back to MainActivity">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -1,36 +1,75 @@
|
|||||||
<?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">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvRecTxt"
|
android:id="@+id/tvStatusmessage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:text="Received Message"
|
android:text="Hello World!"
|
||||||
app:layout_constraintTop_toBottomOf="@id/sendMessage"
|
android:layout_weight="1">
|
||||||
app:layout_constraintStart_toStartOf="parent"/>
|
</TextView>
|
||||||
|
|
||||||
<EditText
|
<LinearLayout
|
||||||
android:id="@+id/sendMessage"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:layout_height="50dp"
|
android:orientation="vertical"
|
||||||
android:ems="10"
|
android:layout_weight="1">
|
||||||
android:inputType="textPersonName"
|
|
||||||
android:text="Send Message"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"/>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/btnSend"
|
android:id="@+id/audiodetectionButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Send"
|
android:layout_weight="1"
|
||||||
android:onClick="onClickSend"
|
android:text="Audiodetection">
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
</Button>
|
||||||
app:layout_constraintStart_toEndOf="@id/sendMessage"/>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
<Button
|
||||||
|
android:id="@+id/videodetectionButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Videodetection">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/accelerometerButton"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
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>
|
||||||
@@ -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=".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>
|
||||||
@@ -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=".VideodetectionAndAccelerometerActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvVideodetectionAndAccelerometerStatusmessage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Videodetection + Accelerometer Activity">
|
||||||
|
</TextView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/videodetectionAndAccelerometerBackToMainActivity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Back to MainActivity">
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
Reference in new issue
Block a user