Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7cd6a4027 |
@@ -35,10 +35,4 @@ 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}"
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,11 @@
|
|||||||
package="com.example.greenwatch">
|
package="com.example.greenwatch">
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.CAMERA"/>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||||
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
<uses-feature android:name="android.hardware.camera"/>
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
|||||||
@Override
|
@Override
|
||||||
public void onChanged(List<Device> devices) {
|
public void onChanged(List<Device> devices) {
|
||||||
deviceListAdapter.setDevices(devices);
|
deviceListAdapter.setDevices(devices);
|
||||||
|
Toast.makeText(AccelerometerActivity.this, "onChanged", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -80,19 +81,7 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
|
mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() {
|
||||||
@Override
|
|
||||||
public void onChanged(Boolean aBoolean) {
|
|
||||||
if (aBoolean) {
|
|
||||||
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mAccelerometerViewModel.getAccelerometerAlarmDetected().observe(this, new Observer<Boolean>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(Boolean aBoolean) {
|
public void onChanged(Boolean aBoolean) {
|
||||||
if (aBoolean) {
|
if (aBoolean) {
|
||||||
|
|||||||
@@ -1,23 +1,16 @@
|
|||||||
package com.example.greenwatch;
|
package com.example.greenwatch;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityCompat;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Build;
|
|
||||||
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 android.widget.Toast;
|
||||||
import android.Manifest;
|
|
||||||
|
|
||||||
import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
|
import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
|
||||||
import com.example.greenwatch.adapters.DeviceListAdapter;
|
import com.example.greenwatch.adapters.DeviceListAdapter;
|
||||||
@@ -36,8 +29,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private Button connectionButton;
|
private Button connectionButton;
|
||||||
private MainActivityViewModel mMainActivityViewModel;
|
private MainActivityViewModel mMainActivityViewModel;
|
||||||
|
|
||||||
private static final int REQUEST_PERMISSION_INTERNET = 123;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -66,11 +57,11 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
|
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
|
||||||
mMainActivityViewModel.init();
|
mMainActivityViewModel.init();
|
||||||
mMainActivityViewModel.accessRequestCamera(this);
|
|
||||||
mMainActivityViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
mMainActivityViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(List<Device> devices) {
|
public void onChanged(List<Device> devices) {
|
||||||
deviceListAdapter.setDevices(devices);
|
deviceListAdapter.setDevices(devices);
|
||||||
|
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -81,18 +72,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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() {
|
audiodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@@ -103,12 +82,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
videodetectionButton.setOnClickListener(new View.OnClickListener() {
|
videodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mMainActivityViewModel.isCameraAccessAllowed(MainActivity.this)) {
|
//openVideodetectionActivity();
|
||||||
openVideodetectionActivity();
|
mMainActivityViewModel.setSensorType(mMainActivityViewModel.getLocalDeviceUUID(), "Video");
|
||||||
}
|
mMainActivityViewModel.setTimeStamp(mMainActivityViewModel.getLocalDeviceUUID(), "12:50");
|
||||||
else {
|
mMainActivityViewModel.setDeviceID(mMainActivityViewModel.getLocalDeviceUUID(), "12345");
|
||||||
mMainActivityViewModel.accessRequestCamera(MainActivity.this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
accelerometerButton.setOnClickListener(new View.OnClickListener() {
|
accelerometerButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@@ -136,15 +113,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
connectionButton.setOnClickListener(new View.OnClickListener() {
|
connectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED
|
|
||||||
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED
|
|
||||||
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CHANGE_WIFI_MULTICAST_STATE) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
|
|
||||||
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.INTERNET, Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.CHANGE_WIFI_MULTICAST_STATE}, REQUEST_PERMISSION_INTERNET);
|
|
||||||
} else {
|
|
||||||
openConnectionActivity();
|
openConnectionActivity();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void openAudiodetectionActivity(){
|
public void openAudiodetectionActivity(){
|
||||||
@@ -164,8 +134,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
public void openVideodetectionAndAccelerometerActivity(){
|
public void openVideodetectionAndAccelerometerActivity(){
|
||||||
Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
|
//Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
|
||||||
startActivity(intent);
|
//startActivity(intent);
|
||||||
|
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "24:00", false, "Video", 0);
|
||||||
}
|
}
|
||||||
public void openConnectionActivity(){
|
public void openConnectionActivity(){
|
||||||
//Intent intent = new Intent(this, ConnectionActivity.class);
|
//Intent intent = new Intent(this, ConnectionActivity.class);
|
||||||
@@ -173,20 +144,4 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", true, "Audio", 10);
|
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", true, "Audio", 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
||||||
if (requestCode == REQUEST_PERMISSION_INTERNET) {
|
|
||||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
// Berechtigungen wurden gewährt
|
|
||||||
Toast.makeText(this, "Berechtigungen gewährt", Toast.LENGTH_SHORT).show();
|
|
||||||
openConnectionActivity();
|
|
||||||
} else {
|
|
||||||
// Berechtigungen wurden nicht gewährt
|
|
||||||
Toast.makeText(this, "Berechtigungen nicht gewährt", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,14 @@
|
|||||||
package com.example.greenwatch;
|
package com.example.greenwatch;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import android.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.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 {
|
public class VideodetectionActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private Button backToMainActivity;
|
private Button backToMainActivity;
|
||||||
private VideodetectionViewModel mVideoDetectionViewModel;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -35,75 +17,11 @@ public class VideodetectionActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
backToMainActivity = (Button) findViewById(R.id.videodetectorBackToMainActivity);
|
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() {
|
backToMainActivity.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
finish();
|
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-145
@@ -1,171 +1,27 @@
|
|||||||
package com.example.greenwatch;
|
package com.example.greenwatch;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import android.hardware.Sensor;
|
|
||||||
import android.hardware.SensorEvent;
|
|
||||||
import android.hardware.SensorEventListener;
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
|
public class VideodetectionAndAccelerometerActivity extends AppCompatActivity {
|
||||||
import com.example.greenwatch.adapters.DeviceListAdapter;
|
|
||||||
import com.example.greenwatch.models.Device;
|
|
||||||
import com.example.greenwatch.viewmodels.AccelerometerViewModel;
|
|
||||||
import com.example.greenwatch.viewmodels.VideodetectionAndAccelerometerViewModel;
|
|
||||||
import com.example.greenwatch.viewmodels.VideodetectionViewModel;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
public class VideodetectionAndAccelerometerActivity extends AppCompatActivity implements SensorEventListener {
|
|
||||||
private SensorManager accelerometerManager;
|
|
||||||
private Sensor accelerometerSensor;
|
|
||||||
private TextView videodetectionAndAccelerometerStatusMessage;
|
|
||||||
private TextView videodetectionAndAccelerometerDataTV;
|
|
||||||
private TextView videodetectionAndAccelerometerWarningTV;
|
|
||||||
private Button backToMainActivity;
|
private Button backToMainActivity;
|
||||||
private VideodetectionAndAccelerometerViewModel mVideodetectionAndAccelerometerViewModel;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_videodetection_and_accelerometer);
|
setContentView(R.layout.activity_videodetection_and_accelerometer);
|
||||||
|
|
||||||
videodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerStatusmessage);
|
|
||||||
videodetectionAndAccelerometerDataTV = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerData);
|
|
||||||
videodetectionAndAccelerometerWarningTV = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerWarning);
|
|
||||||
backToMainActivity = (Button) findViewById(R.id.videodetectionAndAccelerometerBackToMainActivity);
|
backToMainActivity = (Button) findViewById(R.id.videodetectionAndAccelerometerBackToMainActivity);
|
||||||
|
|
||||||
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
|
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
||||||
recyclerView.setHasFixedSize(true);
|
|
||||||
|
|
||||||
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
|
|
||||||
recyclerView.setAdapter(deviceListAdapter);
|
|
||||||
|
|
||||||
RecyclerView alarmHistoryListRecyclerView = findViewById(R.id.alarmHistoryListRecyclerView);
|
|
||||||
alarmHistoryListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
|
||||||
alarmHistoryListRecyclerView.setHasFixedSize(true);
|
|
||||||
|
|
||||||
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
|
|
||||||
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
|
|
||||||
|
|
||||||
backToMainActivity.setOnClickListener(new View.OnClickListener() {
|
backToMainActivity.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mVideodetectionAndAccelerometerViewModel = new ViewModelProvider(this).get(VideodetectionAndAccelerometerViewModel.class);
|
|
||||||
mVideodetectionAndAccelerometerViewModel.init();
|
|
||||||
mVideodetectionAndAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
|
||||||
@Override
|
|
||||||
public void onChanged(List<Device> devices) {
|
|
||||||
deviceListAdapter.setDevices(devices);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mVideodetectionAndAccelerometerViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
|
|
||||||
@Override
|
|
||||||
public void onChanged(List<Device> devices) {
|
|
||||||
alarmHistoryListAdapter.setAlarmHistoryList(devices);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mVideodetectionAndAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
|
|
||||||
@Override
|
|
||||||
public void onChanged(Boolean aBoolean) {
|
|
||||||
if (aBoolean) {
|
|
||||||
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,246 @@
|
|||||||
|
package com.example.greenwatch.alarmrecorder;
|
||||||
|
|
||||||
|
import android.media.MediaCodec;
|
||||||
|
import android.media.MediaExtractor;
|
||||||
|
import android.media.MediaFormat;
|
||||||
|
import android.media.MediaMuxer;
|
||||||
|
import android.media.MediaRecorder;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.example.greenwatch.MainActivity;
|
||||||
|
import com.example.greenwatch.alarmrecorder.runnables.AudioRecorder;
|
||||||
|
import com.example.greenwatch.alarmrecorder.runnables.VideoRecorder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
public class AlarmRecorder {
|
||||||
|
|
||||||
|
private boolean isRecording;
|
||||||
|
private String videoPath;
|
||||||
|
private String audioPath;
|
||||||
|
private MediaFormat videoFormat;
|
||||||
|
private MediaFormat audioFormat;
|
||||||
|
private MediaExtractor videoExtractor;
|
||||||
|
private MediaExtractor audioExtractor;
|
||||||
|
private Runnable audioRecorderRunnable;
|
||||||
|
private Runnable videoRecorderRunnable;
|
||||||
|
private MediaRecorder videoRecorder;
|
||||||
|
private MediaRecorder audioRecorder;
|
||||||
|
private Thread videoThread; // Video-Thread als Instanzvariable
|
||||||
|
private Thread audioThread; // Audio-Thread als Instanzvariable
|
||||||
|
|
||||||
|
public AlarmRecorder() {
|
||||||
|
audioRecorder = new MediaRecorder();
|
||||||
|
videoRecorder = new MediaRecorder();
|
||||||
|
videoExtractor = new MediaExtractor();
|
||||||
|
audioExtractor = new MediaExtractor();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void startRecording() {
|
||||||
|
createStoragePaths(); //Speicherort und -namen für Audio- und Video-Datei
|
||||||
|
|
||||||
|
audioRecorderRunnable = new AudioRecorder(audioRecorder, audioPath);
|
||||||
|
videoRecorderRunnable = new VideoRecorder(videoRecorder, videoPath);
|
||||||
|
audioThread = new Thread(audioRecorderRunnable);
|
||||||
|
videoThread = new Thread(videoRecorderRunnable);
|
||||||
|
|
||||||
|
//Threads starten
|
||||||
|
videoThread.start();
|
||||||
|
audioThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopRecording() {
|
||||||
|
isRecording = false;
|
||||||
|
try {
|
||||||
|
stopVideoRecording();
|
||||||
|
stopAudioRecording();
|
||||||
|
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(MainActivity.this, "Video- und Audioaufzeichnung beendet", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
waitTillThreadsStopped();
|
||||||
|
File videoFile = new File(videoPath); //Speichere das aufgenommene Video
|
||||||
|
File audioFile = new File(audioPath); //Speichere die aufgenommene Audio
|
||||||
|
|
||||||
|
if (videoFile.exists() && audioFile.exists()) {
|
||||||
|
//Wenn Video- und Audioaufzeichnung gestoppt und abgespeichert sind, beginne mit dem Mergeprozess der beiden
|
||||||
|
mergeVideoWithAudio();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(MainActivity.this, "Dateien wurden nicht gefunden!", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
} catch (RuntimeException stopException) {
|
||||||
|
stopException.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createStoragePaths(){
|
||||||
|
//Pfade zum Zwischenspeichern der aufgenommenen Audio und Video-Datei
|
||||||
|
isRecording = true;
|
||||||
|
String externalStorageDirectory = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||||
|
String dcimDirectory = externalStorageDirectory + "/DCIM";
|
||||||
|
videoPath = dcimDirectory + "/video.mp4";
|
||||||
|
audioPath = dcimDirectory + "/audio.mp3";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopVideoRecording(){
|
||||||
|
if (videoRecorder != null) {
|
||||||
|
videoRecorder.stop();
|
||||||
|
videoRecorder.release();
|
||||||
|
videoRecorder = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopAudioRecording(){
|
||||||
|
if (audioRecorder != null) {
|
||||||
|
audioRecorder.stop();
|
||||||
|
audioRecorder.release();
|
||||||
|
audioRecorder = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void waitTillThreadsStopped(){
|
||||||
|
try {
|
||||||
|
videoThread.join();
|
||||||
|
audioThread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergeVideoWithAudio() {
|
||||||
|
try {
|
||||||
|
setVideoExtractorDataSource(); //extrahieren der Video Datei, die zuvor zwischengespeichert wurde
|
||||||
|
setAudioExtractorDataSource(); //extrahieren der Audio Datei, die zuvor zwischengespeichert wurde
|
||||||
|
|
||||||
|
//Speicherort der später zusammengeführten Datei
|
||||||
|
String outputFilePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath() + "/merged_video.mp4";
|
||||||
|
//MediaMuxer zum Zusammenführen einer Audio- und einer Videodatei
|
||||||
|
MediaMuxer muxer = new MediaMuxer(outputFilePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
|
||||||
|
int videoTrack = muxer.addTrack(videoFormat);
|
||||||
|
int audioTrack = muxer.addTrack(audioFormat);
|
||||||
|
muxer.start();
|
||||||
|
|
||||||
|
ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
|
||||||
|
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||||
|
|
||||||
|
videoExtraction(buffer, videoTrack, bufferInfo, muxer);
|
||||||
|
audioExtraction(buffer, audioTrack, bufferInfo, muxer);
|
||||||
|
|
||||||
|
muxer.stop();
|
||||||
|
muxer.release();
|
||||||
|
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Toast.makeText(MainActivity.this, "Video und Audio erfolgreich zusammengeführt", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Löschen der separaten Video- und Audio-Dateien
|
||||||
|
deleteVideoFile();
|
||||||
|
deleteAudioFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setVideoExtractorDataSource() {
|
||||||
|
try {
|
||||||
|
videoExtractor.setDataSource(videoPath);
|
||||||
|
int videoTrackIndex = getTrackIndex(videoExtractor, "video/");
|
||||||
|
if (videoTrackIndex < 0) {
|
||||||
|
// Video-Track nicht gefunden
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
videoExtractor.selectTrack(videoTrackIndex);
|
||||||
|
videoFormat = videoExtractor.getTrackFormat(videoTrackIndex);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setAudioExtractorDataSource() {
|
||||||
|
try {
|
||||||
|
audioExtractor.setDataSource(audioPath);
|
||||||
|
int audioTrackIndex = getTrackIndex(audioExtractor, "audio/");
|
||||||
|
if (audioTrackIndex < 0) {
|
||||||
|
// Audio-Track nicht gefunden
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
audioExtractor.selectTrack(audioTrackIndex);
|
||||||
|
audioFormat = audioExtractor.getTrackFormat(audioTrackIndex);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getTrackIndex(MediaExtractor extractor, String mimeType) {
|
||||||
|
int trackCount = extractor.getTrackCount();
|
||||||
|
for (int i = 0; i < trackCount; i++) {
|
||||||
|
MediaFormat format = extractor.getTrackFormat(i);
|
||||||
|
String trackMimeType = format.getString(MediaFormat.KEY_MIME);
|
||||||
|
if (trackMimeType.startsWith(mimeType)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void videoExtraction(ByteBuffer buffer, int videoTrack, MediaCodec.BufferInfo bufferInfo, MediaMuxer muxer) {
|
||||||
|
videoExtractor.seekTo(0, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
|
||||||
|
while (true) {
|
||||||
|
int sampleSize = videoExtractor.readSampleData(buffer, 0);
|
||||||
|
if (sampleSize < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
long presentationTimeUs = videoExtractor.getSampleTime();
|
||||||
|
bufferInfo.offset = 0;
|
||||||
|
bufferInfo.size = sampleSize;
|
||||||
|
bufferInfo.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME;
|
||||||
|
bufferInfo.presentationTimeUs = presentationTimeUs;
|
||||||
|
muxer.writeSampleData(videoTrack, buffer, bufferInfo);
|
||||||
|
videoExtractor.advance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void audioExtraction(ByteBuffer buffer, int audioTrack, MediaCodec.BufferInfo bufferInfo, MediaMuxer muxer) {
|
||||||
|
audioExtractor.seekTo(0, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
|
||||||
|
while (true) {
|
||||||
|
int sampleSize = audioExtractor.readSampleData(buffer, 0);
|
||||||
|
if (sampleSize < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
long presentationTimeUs = audioExtractor.getSampleTime();
|
||||||
|
bufferInfo.offset = 0;
|
||||||
|
bufferInfo.size = sampleSize;
|
||||||
|
bufferInfo.flags = 0; // or MediaCodec.BUFFER_FLAG_KEY_FRAME
|
||||||
|
bufferInfo.presentationTimeUs = presentationTimeUs;
|
||||||
|
muxer.writeSampleData(audioTrack, buffer, bufferInfo);
|
||||||
|
audioExtractor.advance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void deleteVideoFile(){
|
||||||
|
File videoFile = new File(videoPath);
|
||||||
|
if (videoFile.exists()) {
|
||||||
|
videoFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteAudioFile(){
|
||||||
|
File audioFile = new File(audioPath);
|
||||||
|
if (audioFile.exists()) {
|
||||||
|
audioFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.example.greenwatch.alarmrecorder.runnables;
|
||||||
|
|
||||||
|
import android.media.MediaRecorder;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.example.greenwatch.MainActivity;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class AudioRecorder implements Runnable {
|
||||||
|
|
||||||
|
private final MediaRecorder audioRecorder;
|
||||||
|
private final String audioPath;
|
||||||
|
public AudioRecorder(MediaRecorder audioRecorder, String audioPath) {
|
||||||
|
this.audioRecorder = audioRecorder;
|
||||||
|
this.audioPath = audioPath;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
audioRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
|
||||||
|
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
|
||||||
|
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
|
||||||
|
audioRecorder.setOutputFile(audioPath);
|
||||||
|
|
||||||
|
try {
|
||||||
|
audioRecorder.prepare();
|
||||||
|
audioRecorder.start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.example.greenwatch.alarmrecorder.runnables;
|
||||||
|
|
||||||
|
import android.media.MediaRecorder;
|
||||||
|
|
||||||
|
import com.example.greenwatch.viewmodels.ViewModelInterface;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class VideoRecorder implements Runnable{
|
||||||
|
private final MediaRecorder videoRecorder;
|
||||||
|
private final String videoPath;
|
||||||
|
|
||||||
|
public VideoRecorder(MediaRecorder videoRecorder, String videoPath) {
|
||||||
|
this.videoRecorder = videoRecorder;
|
||||||
|
this.videoPath = videoPath;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
videoRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
|
||||||
|
videoRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
|
||||||
|
videoRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
|
||||||
|
videoRecorder.setOutputFile(videoPath);
|
||||||
|
videoRecorder.setOrientationHint(90);
|
||||||
|
//todo find solution for videoView
|
||||||
|
videoRecorder.setPreviewDisplay(videoView.getHolder().getSurface());
|
||||||
|
|
||||||
|
try {
|
||||||
|
videoRecorder.prepare();
|
||||||
|
videoRecorder.start();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,12 +17,10 @@ public class DeviceRepository {
|
|||||||
|
|
||||||
private final int maxAlarmHistoryListSize = 20;
|
private final int maxAlarmHistoryListSize = 20;
|
||||||
private final String delimiter = ", ";
|
private final String delimiter = ", ";
|
||||||
private final String sensorStatusKey = "An";
|
private final String SensorStatusKey = "An";
|
||||||
private String localDeviceUUID;
|
private String localDeviceUUID;
|
||||||
private static DeviceRepository deviceRepositoryInstance;
|
private static DeviceRepository deviceRepositoryInstance;
|
||||||
private WiFiCommunication mWiFiCommunication;
|
private WiFiCommunication mWiFiCommunication;
|
||||||
private boolean startAlarmRecordingValue;
|
|
||||||
private MutableLiveData<Boolean> startAlarmRecording = new MutableLiveData<>();
|
|
||||||
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>();
|
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>();
|
||||||
private MutableLiveData<List<Device>> alarmHistoryList = new MutableLiveData<>();
|
private MutableLiveData<List<Device>> alarmHistoryList = new MutableLiveData<>();
|
||||||
private HashMap<String, Device> connectedDevicesList = new HashMap<>();
|
private HashMap<String, Device> connectedDevicesList = new HashMap<>();
|
||||||
@@ -31,7 +29,6 @@ public class DeviceRepository {
|
|||||||
|
|
||||||
private DeviceRepository() {
|
private DeviceRepository() {
|
||||||
setLocalDeviceUUID();
|
setLocalDeviceUUID();
|
||||||
startAlarmRecordingValue = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized DeviceRepository getInstance() {
|
public static synchronized DeviceRepository getInstance() {
|
||||||
@@ -55,21 +52,11 @@ public class DeviceRepository {
|
|||||||
return alarmHistoryList;
|
return alarmHistoryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<Boolean> getStartAlarmRecording() {
|
|
||||||
setMutableLiveDataStartAlarmRecording();
|
|
||||||
return startAlarmRecording;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){
|
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){
|
||||||
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
|
||||||
if (sensorStatus) {
|
if (sensorStatus) {
|
||||||
setAlarmHistoryDeviceList(newDevice);
|
setAlarmHistoryDeviceList(newDevice);
|
||||||
}
|
}
|
||||||
boolean newStartAlarmRecordingValue = checkDeviceStatus();
|
|
||||||
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
|
|
||||||
startAlarmRecordingValue = newStartAlarmRecordingValue;
|
|
||||||
setMutableLiveDataStartAlarmRecording();
|
|
||||||
}
|
|
||||||
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice);
|
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice);
|
||||||
setMutableLiveDataDeviceList();
|
setMutableLiveDataDeviceList();
|
||||||
}
|
}
|
||||||
@@ -137,11 +124,6 @@ public class DeviceRepository {
|
|||||||
setAlarmHistoryDeviceList(device);
|
setAlarmHistoryDeviceList(device);
|
||||||
}
|
}
|
||||||
device.setSensorStatus(sensorStatus);
|
device.setSensorStatus(sensorStatus);
|
||||||
boolean newStartAlarmRecordingValue = checkDeviceStatus();
|
|
||||||
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
|
|
||||||
startAlarmRecordingValue = newStartAlarmRecordingValue;
|
|
||||||
setMutableLiveDataStartAlarmRecording();
|
|
||||||
}
|
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
setMutableLiveDataDeviceList();
|
setMutableLiveDataDeviceList();
|
||||||
}
|
}
|
||||||
@@ -195,11 +177,6 @@ public class DeviceRepository {
|
|||||||
setAlarmHistoryDeviceList(device);
|
setAlarmHistoryDeviceList(device);
|
||||||
}
|
}
|
||||||
device.setSensorStatus(sensorStatus);
|
device.setSensorStatus(sensorStatus);
|
||||||
boolean newStartAlarmRecordingValue = checkDeviceStatus();
|
|
||||||
if (startAlarmRecordingValue != newStartAlarmRecordingValue) {
|
|
||||||
startAlarmRecordingValue = newStartAlarmRecordingValue;
|
|
||||||
setMutableLiveDataStartAlarmRecording();
|
|
||||||
}
|
|
||||||
addToConnectedDeviceList(checkedDeviceID, device);
|
addToConnectedDeviceList(checkedDeviceID, device);
|
||||||
setMutableLiveDataDeviceList();
|
setMutableLiveDataDeviceList();
|
||||||
|
|
||||||
@@ -268,10 +245,6 @@ public class DeviceRepository {
|
|||||||
alarmHistoryList.setValue(alarmHistoryDeviceList);
|
alarmHistoryList.setValue(alarmHistoryDeviceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setMutableLiveDataStartAlarmRecording() {
|
|
||||||
startAlarmRecording.setValue(startAlarmRecordingValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addToConnectedDeviceList(String key, Device device) {
|
private void addToConnectedDeviceList(String key, Device device) {
|
||||||
connectedDevicesList.put(key, device);
|
connectedDevicesList.put(key, device);
|
||||||
if (key.equals(checkDeviceID(localDeviceUUID))) {
|
if (key.equals(checkDeviceID(localDeviceUUID))) {
|
||||||
@@ -299,7 +272,7 @@ public class DeviceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean convertSensorStatus(String status) {
|
private boolean convertSensorStatus(String status) {
|
||||||
return status.equals(sensorStatusKey);
|
return status.equals(SensorStatusKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAlarmHistoryDeviceList(Device device) {
|
private void setAlarmHistoryDeviceList(Device device) {
|
||||||
@@ -310,13 +283,4 @@ public class DeviceRepository {
|
|||||||
alarmHistoryDeviceList.add(0, alarmHistoryDevice);
|
alarmHistoryDeviceList.add(0, alarmHistoryDevice);
|
||||||
setMutableLiveDataAlarmHistoryList();
|
setMutableLiveDataAlarmHistoryList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkDeviceStatus() {
|
|
||||||
for (Device device : connectedDevicesList.values()) {
|
|
||||||
if (device.getSensorStatus()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
package com.example.greenwatch.sensors;
|
|
||||||
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class AccelerometerSensor {
|
|
||||||
private MutableLiveData<Boolean> mAccelerometerAlarmDetected = new MutableLiveData<>();
|
|
||||||
private static AccelerometerSensor accelerometerSensorInstance;
|
|
||||||
private boolean accelerometerAlarmDetected;
|
|
||||||
private ArrayList<Float> Gesamt_be;
|
|
||||||
int arraySize = 500;
|
|
||||||
int functionCallCount;
|
|
||||||
float meanValue;
|
|
||||||
float offsetValue;
|
|
||||||
float thresholdValue;
|
|
||||||
boolean startMeasuring;
|
|
||||||
|
|
||||||
private AccelerometerSensor() {
|
|
||||||
initGesamtBE();
|
|
||||||
accelerometerAlarmDetected = false;
|
|
||||||
setMutableLiveDataAccelerometerAlarmDetected();
|
|
||||||
functionCallCount = 0;
|
|
||||||
meanValue = 0.0f;
|
|
||||||
offsetValue = 0.1f;
|
|
||||||
thresholdValue = 0.15f;
|
|
||||||
startMeasuring = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized AccelerometerSensor getInstance() {
|
|
||||||
if (accelerometerSensorInstance == null){
|
|
||||||
accelerometerSensorInstance = new AccelerometerSensor();
|
|
||||||
}
|
|
||||||
return accelerometerSensorInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MutableLiveData<Boolean> getAccelerometerAlarmDetected() {
|
|
||||||
setMutableLiveDataAccelerometerAlarmDetected();
|
|
||||||
return mAccelerometerAlarmDetected;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setMutableLiveDataAccelerometerAlarmDetected() {
|
|
||||||
mAccelerometerAlarmDetected.setValue(accelerometerAlarmDetected);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initGesamtBE() {
|
|
||||||
Gesamt_be = new ArrayList<>(arraySize);
|
|
||||||
for (int i = 0; i < arraySize; i++) {
|
|
||||||
Gesamt_be.add(0.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addValueToGesamtBE(float newValue) {
|
|
||||||
if (Gesamt_be.size() == arraySize) {
|
|
||||||
Gesamt_be.remove(Gesamt_be.size() -1);
|
|
||||||
}
|
|
||||||
Gesamt_be.add(0, newValue);
|
|
||||||
functionCallCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void meanValueCalculation() {
|
|
||||||
for (float element : Gesamt_be) {
|
|
||||||
meanValue += Math.abs(element);
|
|
||||||
}
|
|
||||||
meanValue = meanValue/arraySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void calibrateAccelerometerSensor() {
|
|
||||||
if (functionCallCount <= arraySize) {
|
|
||||||
offsetValue = meanValue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
startMeasuring = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkAlarmCondition() {
|
|
||||||
if (meanValue > (thresholdValue + offsetValue) && startMeasuring && !mAccelerometerAlarmDetected.getValue()) {
|
|
||||||
mAccelerometerAlarmDetected.setValue(true);
|
|
||||||
}
|
|
||||||
else if (meanValue < (thresholdValue + offsetValue) && mAccelerometerAlarmDetected.getValue()){
|
|
||||||
mAccelerometerAlarmDetected.setValue(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,59 +6,88 @@ import androidx.lifecycle.ViewModel;
|
|||||||
|
|
||||||
import com.example.greenwatch.models.Device;
|
import com.example.greenwatch.models.Device;
|
||||||
import com.example.greenwatch.repositories.DeviceRepository;
|
import com.example.greenwatch.repositories.DeviceRepository;
|
||||||
import com.example.greenwatch.sensors.AccelerometerSensor;
|
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AccelerometerViewModel extends ViewModel implements ViewModelInterface {
|
public class AccelerometerViewModel extends ViewModel implements ViewModelInterface {
|
||||||
|
|
||||||
private MutableLiveData<List<Device>> mDeviceList;
|
private MutableLiveData<List<Device>> mDeviceList;
|
||||||
private MutableLiveData<Boolean> mAccelerometerAlarmDetected;
|
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>();
|
||||||
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||||
private MutableLiveData<Boolean> mStartAlarmRecording;
|
|
||||||
private AccelerometerSensor mAccelerometerSensor;
|
|
||||||
private DeviceRepository mDeviceRepository;
|
private DeviceRepository mDeviceRepository;
|
||||||
|
private ArrayList<Float> Gesamt_be;
|
||||||
|
int arraySize = 500;
|
||||||
|
int functionCallCount;
|
||||||
|
float meanValue;
|
||||||
|
float offsetValue;
|
||||||
|
float thresholdValue;
|
||||||
|
boolean startMeasuring;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
if (mDeviceRepository == null) {
|
|
||||||
mDeviceRepository = DeviceRepository.getInstance();
|
|
||||||
}
|
|
||||||
if (mAccelerometerSensor == null) {
|
|
||||||
mAccelerometerSensor = AccelerometerSensor.getInstance();
|
|
||||||
}
|
|
||||||
if (mDeviceList == null) {
|
if (mDeviceList == null) {
|
||||||
|
mDeviceRepository = DeviceRepository.getInstance();
|
||||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
}
|
|
||||||
if (mAlarmHistoryList == null) {
|
|
||||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||||
}
|
}
|
||||||
if (mStartAlarmRecording == null) {
|
initGesamtBE();
|
||||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
|
mMovementDetected.setValue(false);
|
||||||
|
functionCallCount = 0;
|
||||||
|
meanValue = 0f;
|
||||||
|
offsetValue = 0.1f;
|
||||||
|
thresholdValue = 0.15f;
|
||||||
|
startMeasuring = false;
|
||||||
}
|
}
|
||||||
if (mAccelerometerAlarmDetected == null) {
|
|
||||||
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected();
|
public void initGesamtBE() {
|
||||||
|
Gesamt_be = new ArrayList<>(arraySize);
|
||||||
|
for (int i = 0; i < arraySize; i++) {
|
||||||
|
Gesamt_be.add(0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addValueToGesamtBE(float newValue) {
|
public void addValueToGesamtBE(float newValue) {
|
||||||
mAccelerometerSensor.addValueToGesamtBE(newValue);
|
if (Gesamt_be.size() == arraySize) {
|
||||||
|
Gesamt_be.remove(Gesamt_be.size() -1);
|
||||||
|
}
|
||||||
|
Gesamt_be.add(0, newValue);
|
||||||
|
functionCallCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void meanValueCalculation() {
|
public void meanValueCalculation() {
|
||||||
mAccelerometerSensor.meanValueCalculation();
|
for (float element : Gesamt_be) {
|
||||||
|
meanValue += Math.abs(element);
|
||||||
|
}
|
||||||
|
meanValue = meanValue/arraySize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calibrateAccelerometerSensor() {
|
public void calibrateAccelerometerSensor() {
|
||||||
mAccelerometerSensor.calibrateAccelerometerSensor();
|
if (functionCallCount <= arraySize) {
|
||||||
|
offsetValue = meanValue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
startMeasuring = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkAlarmCondition() {
|
public void checkAlarmCondition() {
|
||||||
mAccelerometerSensor.checkAlarmCondition();
|
if (meanValue > (thresholdValue + offsetValue) && startMeasuring && !mMovementDetected.getValue()) {
|
||||||
|
mMovementDetected.setValue(true);
|
||||||
|
}
|
||||||
|
else if (meanValue < (thresholdValue + offsetValue) && mMovementDetected.getValue()){
|
||||||
|
mMovementDetected.setValue(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<Boolean> getAccelerometerAlarmDetected() {
|
public String getSystemTimeStamp() {
|
||||||
return mAccelerometerAlarmDetected;
|
return mDeviceRepository.getSystemTimeStamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Boolean> getMovementDetectedValue() {
|
||||||
|
return mMovementDetected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,11 +100,6 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
|
|||||||
return mAlarmHistoryList;
|
return mAlarmHistoryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveData<Boolean> getStartAlarmRecording() {
|
|
||||||
return mStartAlarmRecording;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
||||||
@@ -135,9 +159,4 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
|
|||||||
public String getLocalDeviceUUID() {
|
public String getLocalDeviceUUID() {
|
||||||
return mDeviceRepository.getLocalDeviceUUID();
|
return mDeviceRepository.getLocalDeviceUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSystemTimeStamp() {
|
|
||||||
return mDeviceRepository.getSystemTimeStamp();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
package com.example.greenwatch.viewmodels;
|
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.LiveData;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
import androidx.lifecycle.ViewModel;
|
import androidx.lifecycle.ViewModel;
|
||||||
@@ -20,9 +14,7 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
|
|||||||
|
|
||||||
private MutableLiveData<List<Device>> mDeviceList;
|
private MutableLiveData<List<Device>> mDeviceList;
|
||||||
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||||
private MutableLiveData<Boolean> mStartAlarmRecording;
|
|
||||||
private DeviceRepository mDeviceRepository;
|
private DeviceRepository mDeviceRepository;
|
||||||
private static final int RIGHTS_REQUEST_CAMERA = 10;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
@@ -36,17 +28,9 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
|
|||||||
mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
|
mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
|
||||||
mWiFiCommunication.setDeviceRepository(mDeviceRepository);
|
mWiFiCommunication.setDeviceRepository(mDeviceRepository);
|
||||||
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
|
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
|
||||||
|
mDeviceRepository.createNewDevice("00:00", "1234", true, "Test", 21);
|
||||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCameraAccessAllowed(Context context) {
|
|
||||||
return ContextCompat.checkSelfPermission(context, android.Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void accessRequestCamera(Activity activity) {
|
|
||||||
ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.CAMERA}, RIGHTS_REQUEST_CAMERA);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -59,11 +43,6 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
|
|||||||
return mAlarmHistoryList;
|
return mAlarmHistoryList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveData<Boolean> getStartAlarmRecording() {
|
|
||||||
return mStartAlarmRecording;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
||||||
@@ -123,9 +102,4 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
|
|||||||
public String getLocalDeviceUUID() {
|
public String getLocalDeviceUUID() {
|
||||||
return mDeviceRepository.getLocalDeviceUUID();
|
return mDeviceRepository.getLocalDeviceUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSystemTimeStamp() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
-196
@@ -1,196 +0,0 @@
|
|||||||
package com.example.greenwatch.viewmodels;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.Observer;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
|
|
||||||
import com.example.greenwatch.models.Device;
|
|
||||||
import com.example.greenwatch.repositories.DeviceRepository;
|
|
||||||
import com.example.greenwatch.sensors.AccelerometerSensor;
|
|
||||||
import com.example.greenwatch.sensors.CameraSensor;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class VideodetectionAndAccelerometerViewModel extends ViewModel implements ViewModelInterface{
|
|
||||||
private MutableLiveData<List<Device>> mDeviceList;
|
|
||||||
private MutableLiveData<Boolean> mAccelerometerAlarmDetected;
|
|
||||||
private MutableLiveData<Boolean> mVideoAlarmDetected;
|
|
||||||
private MutableLiveData<Boolean> mVideodetectionAndAccelerometerAlarmDetected = new MutableLiveData<>();
|
|
||||||
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
|
||||||
private MutableLiveData<Boolean> mStartAlarmRecording;
|
|
||||||
private AccelerometerSensor mAccelerometerSensor;
|
|
||||||
private CameraSensor mCameraSensor;
|
|
||||||
private DeviceRepository mDeviceRepository;
|
|
||||||
private boolean 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
package com.example.greenwatch.viewmodels;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@ public interface ViewModelInterface {
|
|||||||
void init();
|
void init();
|
||||||
LiveData<List<Device>> getConnectedDeviceList();
|
LiveData<List<Device>> getConnectedDeviceList();
|
||||||
LiveData<List<Device>> getAlarmHistoryList();
|
LiveData<List<Device>> getAlarmHistoryList();
|
||||||
LiveData<Boolean> getStartAlarmRecording();
|
|
||||||
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage);
|
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage);
|
||||||
void setTimeStamp(String deviceID, String timeStamp);
|
void setTimeStamp(String deviceID, String timeStamp);
|
||||||
String getTimeStamp(String deviceID);
|
String getTimeStamp(String deviceID);
|
||||||
@@ -23,5 +22,4 @@ public interface ViewModelInterface {
|
|||||||
void setSensorMassage(String deviceID, int sensorMessage);
|
void setSensorMassage(String deviceID, int sensorMessage);
|
||||||
int getSensorMassage(String deviceID);
|
int getSensorMassage(String deviceID);
|
||||||
String getLocalDeviceUUID();
|
String getLocalDeviceUUID();
|
||||||
String getSystemTimeStamp();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,27 +22,4 @@
|
|||||||
android:text="Back to MainActivity">
|
android:text="Back to MainActivity">
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/deviceListRecyclerView"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:listitem="@layout/device_item"
|
|
||||||
android:layout_weight="1">
|
|
||||||
</androidx.recyclerview.widget.RecyclerView>
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/alarmHistoryListRecyclerView"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:listitem="@layout/alarm_history_item"
|
|
||||||
android:layout_weight="1">
|
|
||||||
</androidx.recyclerview.widget.RecyclerView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -9,24 +9,10 @@
|
|||||||
tools:context=".VideodetectionAndAccelerometerActivity">
|
tools:context=".VideodetectionAndAccelerometerActivity">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvvideodetectionAndAccelerometerStatusmessage"
|
android:id="@+id/tvVideodetectionAndAccelerometerStatusmessage"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="">
|
android:text="Videodetection + Accelerometer Activity">
|
||||||
</TextView>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvvideodetectionAndAccelerometerData"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="">
|
|
||||||
</TextView>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvvideodetectionAndAccelerometerWarning"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="">
|
|
||||||
</TextView>
|
</TextView>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -36,27 +22,4 @@
|
|||||||
android:text="Back to MainActivity">
|
android:text="Back to MainActivity">
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/deviceListRecyclerView"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:listitem="@layout/device_item"
|
|
||||||
android:layout_weight="1">
|
|
||||||
</androidx.recyclerview.widget.RecyclerView>
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/alarmHistoryListRecyclerView"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
tools:listitem="@layout/alarm_history_item"
|
|
||||||
android:layout_weight="1">
|
|
||||||
</androidx.recyclerview.widget.RecyclerView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user