Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
870b94e6b1 | ||
|
|
74f0fdb798 | ||
|
|
97c3d2c937 | ||
|
|
5d7b949e54 | ||
|
|
99117277be |
@@ -3,11 +3,8 @@
|
||||
package="com.example.greenwatch">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera"/>
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
@@ -28,7 +27,6 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
||||
|
||||
private SensorManager accelerometerManager;
|
||||
private Sensor accelerometerSensor;
|
||||
private SurfaceView surfaceView;
|
||||
private TextView accelerometerStatusMessage;
|
||||
private TextView accelerometerDataTV;
|
||||
private TextView accelerometerWarningTV;
|
||||
@@ -40,7 +38,6 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_accelerometer);
|
||||
|
||||
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewAccelerometer);
|
||||
accelerometerStatusMessage = (TextView) findViewById(R.id.tvAccelerometerStatusmessage);
|
||||
accelerometerDataTV = (TextView) findViewById(R.id.tvAccelerometerData);
|
||||
accelerometerWarningTV = (TextView) findViewById(R.id.tvAccelerometerWarning);
|
||||
@@ -68,7 +65,7 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
||||
});
|
||||
|
||||
mAccelerometerViewModel = new ViewModelProvider(this).get(AccelerometerViewModel.class);
|
||||
mAccelerometerViewModel.init(surfaceView.getHolder());
|
||||
mAccelerometerViewModel.init();
|
||||
mAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||
@Override
|
||||
public void onChanged(List<Device> devices) {
|
||||
@@ -87,11 +84,9 @@ public class AccelerometerActivity extends AppCompatActivity implements SensorEv
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
mAccelerometerViewModel.startAlarmRecording();
|
||||
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else {
|
||||
mAccelerometerViewModel.stopAlarmRecording(AccelerometerActivity.this);
|
||||
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,122 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
|
||||
import com.example.greenwatch.adapters.DeviceListAdapter;
|
||||
import com.example.greenwatch.models.Device;
|
||||
import com.example.greenwatch.viewmodels.AccelerometerViewModel;
|
||||
import com.example.greenwatch.viewmodels.MicrofonViewModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AudiodetectionActivity extends AppCompatActivity {
|
||||
|
||||
private TextView microfonStatusMessage;
|
||||
private Button backToMainActivityButton;
|
||||
private MicrofonViewModel mMicrofonViewModel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_audiodetection);
|
||||
|
||||
microfonStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionStatusmessage);
|
||||
backToMainActivityButton = (Button) findViewById(R.id.audiodetectorBackToMainActivity);
|
||||
|
||||
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
||||
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
|
||||
recyclerView.setAdapter(deviceListAdapter);
|
||||
|
||||
RecyclerView alarmHistoryListRecyclerView = findViewById(R.id.alarmHistoryListRecyclerView);
|
||||
alarmHistoryListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
alarmHistoryListRecyclerView.setHasFixedSize(true);
|
||||
|
||||
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
|
||||
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
|
||||
|
||||
backToMainActivityButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
mMicrofonViewModel = new ViewModelProvider(this).get(MicrofonViewModel.class);
|
||||
mMicrofonViewModel.init();
|
||||
mMicrofonViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||
@Override
|
||||
public void onChanged(List<Device> devices) {
|
||||
deviceListAdapter.setDevices(devices);
|
||||
}
|
||||
});
|
||||
|
||||
mMicrofonViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
|
||||
@Override
|
||||
public void onChanged(List<Device> devices) {
|
||||
alarmHistoryListAdapter.setAlarmHistoryList(devices);
|
||||
}
|
||||
});
|
||||
|
||||
mMicrofonViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
Toast.makeText(AudiodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else {
|
||||
Toast.makeText(AudiodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mMicrofonViewModel.getMicrofonAlarmDetected().observe(this, new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), true, "Microfon", (int) mMicrofonViewModel.getAmplitudeInDB());
|
||||
microfonStatusMessage.setText("dB value - detected = " + (int) mMicrofonViewModel.getAmplitudeInDB() + " dB");
|
||||
}
|
||||
else {
|
||||
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), false, "Microfon", (int) mMicrofonViewModel.getAmplitudeInDB());
|
||||
if((int) mMicrofonViewModel.getAmplitudeInDB() > 0){
|
||||
microfonStatusMessage.setText("dB value - no longer detected = " + (int) mMicrofonViewModel.getAmplitudeInDB()+ " dB");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mMicrofonViewModel.startMicrofonSensor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (isFinishing()){
|
||||
mMicrofonViewModel.recalibrationMicrofonSensor();
|
||||
}
|
||||
mMicrofonViewModel.stopMicrofonSensor();
|
||||
}
|
||||
}
|
||||
+140
-1
@@ -1,13 +1,34 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity {
|
||||
import com.example.greenwatch.adapters.AlarmHistoryListAdapter;
|
||||
import com.example.greenwatch.adapters.DeviceListAdapter;
|
||||
import com.example.greenwatch.models.Device;
|
||||
import com.example.greenwatch.viewmodels.AudiodetectionAndAccelerometerViewModel;
|
||||
import com.example.greenwatch.viewmodels.VideodetectionAndAccelerometerViewModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity implements SensorEventListener {
|
||||
private SensorManager accelerometerManager;
|
||||
private Sensor accelerometerSensor;
|
||||
private TextView audiodetectionAndAccelerometerStatusMessage;
|
||||
private AudiodetectionAndAccelerometerViewModel mAudiodetectionAndAccelerometerViewModel;
|
||||
private Button backToMainActivity;
|
||||
|
||||
@Override
|
||||
@@ -15,13 +36,131 @@ public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_audiodetection_and_accelerometer);
|
||||
|
||||
audiodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerStatusmessage);
|
||||
backToMainActivity = (Button) findViewById(R.id.audiodetectionAndAccelerometerBackToMainActivity);
|
||||
|
||||
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
||||
final DeviceListAdapter deviceListAdapter = new DeviceListAdapter();
|
||||
recyclerView.setAdapter(deviceListAdapter);
|
||||
|
||||
RecyclerView alarmHistoryListRecyclerView = findViewById(R.id.alarmHistoryListRecyclerView);
|
||||
alarmHistoryListRecyclerView.setLayoutManager(new LinearLayoutManager(this));
|
||||
alarmHistoryListRecyclerView.setHasFixedSize(true);
|
||||
|
||||
final AlarmHistoryListAdapter alarmHistoryListAdapter = new AlarmHistoryListAdapter();
|
||||
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
|
||||
|
||||
backToMainActivity.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
mAudiodetectionAndAccelerometerViewModel = new ViewModelProvider(this).get(AudiodetectionAndAccelerometerViewModel.class);
|
||||
mAudiodetectionAndAccelerometerViewModel.init();
|
||||
mAudiodetectionAndAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||
@Override
|
||||
public void onChanged(List<Device> devices) {
|
||||
deviceListAdapter.setDevices(devices);
|
||||
}
|
||||
});
|
||||
|
||||
mAudiodetectionAndAccelerometerViewModel.getAlarmHistoryList().observe(this, new Observer<List<Device>>() {
|
||||
@Override
|
||||
public void onChanged(List<Device> devices) {
|
||||
alarmHistoryListAdapter.setAlarmHistoryList(devices);
|
||||
}
|
||||
});
|
||||
|
||||
mAudiodetectionAndAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else {
|
||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mAudiodetectionAndAccelerometerViewModel.getAudiodetectionAndAccelerometerAlarmDetected().observe(this, new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedTrue", Toast.LENGTH_LONG).show();
|
||||
if (mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected() && !mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected()) {
|
||||
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", 10);
|
||||
}
|
||||
else if (mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected() && !mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
|
||||
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Audio", (int) mAudiodetectionAndAccelerometerViewModel.getAmplitudeInDB());
|
||||
}
|
||||
else if (mAudiodetectionAndAccelerometerViewModel.getMicrofonAlarmDetected() && mAudiodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
|
||||
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "2AudioAndAccelerometer", 10);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedFalse", Toast.LENGTH_LONG).show();
|
||||
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
accelerometerManager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||
if (accelerometerManager.getSensorList(Sensor.TYPE_GYROSCOPE).size() == 0) {
|
||||
accelerometerSensor = null;
|
||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "No accelerometer sensor available", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else {
|
||||
accelerometerSensor = accelerometerManager.getSensorList(Sensor.TYPE_GYROSCOPE).get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("x=")
|
||||
.append(event.values[0])
|
||||
.append("\ny=")
|
||||
.append(event.values[1])
|
||||
.append("\nz=")
|
||||
.append(event.values[2]);
|
||||
audiodetectionAndAccelerometerStatusMessage.setText(sb.toString());
|
||||
mAudiodetectionAndAccelerometerViewModel.addValueToGesamtBE(event.values[0] + event.values[1] + event.values[2]);
|
||||
mAudiodetectionAndAccelerometerViewModel.meanValueCalculation();
|
||||
mAudiodetectionAndAccelerometerViewModel.calibrateAccelerometerSensor();
|
||||
mAudiodetectionAndAccelerometerViewModel.checkAlarmCondition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mAudiodetectionAndAccelerometerViewModel.startMicrofonSensor();
|
||||
if (accelerometerSensor != null) {
|
||||
if (accelerometerManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_GAME)) {
|
||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "We registered to the sensor", Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Registration did not work", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mAudiodetectionAndAccelerometerViewModel.stopMicrofonSensor();
|
||||
if (accelerometerSensor != null) {
|
||||
accelerometerManager.unregisterListener(this, accelerometerSensor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
@@ -28,7 +27,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
private Button audiodetectionAndAccelerometerButton;
|
||||
private Button videodetectionAndAccelerometerButton;
|
||||
private Button connectionButton;
|
||||
private SurfaceView surfaceView;
|
||||
private MainActivityViewModel mMainActivityViewModel;
|
||||
|
||||
@Override
|
||||
@@ -36,7 +34,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewMainActivity);
|
||||
audiodetectionButton = (Button) findViewById(R.id.audiodetectionButton);
|
||||
videodetectionButton = (Button) findViewById(R.id.videodetectionButton);
|
||||
accelerometerButton = (Button) findViewById(R.id.accelerometerButton);
|
||||
@@ -59,10 +56,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
alarmHistoryListRecyclerView.setAdapter(alarmHistoryListAdapter);
|
||||
|
||||
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
|
||||
mMainActivityViewModel.init(surfaceView.getHolder());
|
||||
mMainActivityViewModel.init();
|
||||
mMainActivityViewModel.accessRequestCamera(this);
|
||||
mMainActivityViewModel.accessRequestAudioRecording(this);
|
||||
mMainActivityViewModel.accessRequestWriteExternalStorage(this);
|
||||
mMainActivityViewModel.accessRequestMicrofon(this);
|
||||
mMainActivityViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||
@Override
|
||||
public void onChanged(List<Device> devices) {
|
||||
@@ -81,11 +77,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
mMainActivityViewModel.startAlarmRecording();
|
||||
Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else {
|
||||
mMainActivityViewModel.stopAlarmRecording(MainActivity.this);
|
||||
Toast.makeText(MainActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
@@ -94,8 +88,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
audiodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//openAudiodetectionActivity();
|
||||
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", false, "Audio", 10);
|
||||
if (mMainActivityViewModel.isMicrofonAccessAllowed(MainActivity.this)) {
|
||||
openAudiodetectionActivity();
|
||||
}
|
||||
else {
|
||||
mMainActivityViewModel.accessRequestMicrofon(MainActivity.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
videodetectionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -119,10 +117,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
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");
|
||||
if (mMainActivityViewModel.isMicrofonAccessAllowed(MainActivity.this)) {
|
||||
openAudiodetectionAndAccelerometerActivity();
|
||||
}
|
||||
else {
|
||||
mMainActivityViewModel.accessRequestMicrofon(MainActivity.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
videodetectionAndAccelerometerButton.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -155,8 +155,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
}
|
||||
public void openVideodetectionAndAccelerometerActivity(){
|
||||
//Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
|
||||
//startActivity(intent);
|
||||
Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
public void openConnectionActivity(){
|
||||
//Intent intent = new Intent(this, ConnectionActivity.class);
|
||||
|
||||
@@ -9,7 +9,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
@@ -27,7 +26,6 @@ import java.util.concurrent.ExecutionException;
|
||||
public class VideodetectionActivity extends AppCompatActivity {
|
||||
|
||||
private Button backToMainActivity;
|
||||
private SurfaceView surfaceView;
|
||||
private VideodetectionViewModel mVideoDetectionViewModel;
|
||||
|
||||
@Override
|
||||
@@ -35,7 +33,6 @@ public class VideodetectionActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_videodetection);
|
||||
|
||||
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewVideodetection);
|
||||
backToMainActivity = (Button) findViewById(R.id.videodetectorBackToMainActivity);
|
||||
|
||||
RecyclerView recyclerView = findViewById(R.id.deviceListRecyclerView);
|
||||
@@ -60,7 +57,7 @@ public class VideodetectionActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
mVideoDetectionViewModel = new ViewModelProvider(this).get(VideodetectionViewModel.class);
|
||||
mVideoDetectionViewModel.init(surfaceView.getHolder());
|
||||
mVideoDetectionViewModel.init();
|
||||
mVideoDetectionViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() {
|
||||
@Override
|
||||
public void onChanged(List<Device> devices) {
|
||||
@@ -79,11 +76,9 @@ public class VideodetectionActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
mVideoDetectionViewModel.startAlarmRecording();
|
||||
Toast.makeText(VideodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
else {
|
||||
mVideoDetectionViewModel.stopAlarmRecording(VideodetectionActivity.this);
|
||||
Toast.makeText(VideodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
+12
-5
@@ -1,4 +1,4 @@
|
||||
/*package com.example.greenwatch;
|
||||
package com.example.greenwatch;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||
@@ -101,12 +101,19 @@ public class VideodetectionAndAccelerometerActivity extends AppCompatActivity im
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", 10);
|
||||
if (mVideodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected() && !mVideodetectionAndAccelerometerViewModel.getVideoAlarmDetected()) {
|
||||
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Accelerometer", 10);
|
||||
}
|
||||
else if (mVideodetectionAndAccelerometerViewModel.getVideoAlarmDetected() && !mVideodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected()) {
|
||||
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "Video", 10);
|
||||
}
|
||||
else if (mVideodetectionAndAccelerometerViewModel.getAccelerometerAlarmDetected() && mVideodetectionAndAccelerometerViewModel.getVideoAlarmDetected()) {
|
||||
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), true, "2VideoAndAccelerometer", 10);
|
||||
}
|
||||
}
|
||||
else {
|
||||
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "Accelerometer", 0);
|
||||
mVideodetectionAndAccelerometerViewModel.updateDevice(mVideodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mVideodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "VideoAndAccelerometer", 0);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
@@ -168,4 +175,4 @@ public class VideodetectionAndAccelerometerActivity extends AppCompatActivity im
|
||||
accelerometerManager.unregisterListener(this, accelerometerSensor);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -1,251 +0,0 @@
|
||||
package com.example.greenwatch.alarmrecorder;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.media.MediaCodec;
|
||||
import android.media.MediaExtractor;
|
||||
import android.media.MediaFormat;
|
||||
import android.media.MediaMuxer;
|
||||
import android.media.MediaRecorder;
|
||||
import android.os.Environment;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.greenwatch.MainActivity;
|
||||
import com.example.greenwatch.alarmrecorder.runnables.AudioRecorder;
|
||||
import com.example.greenwatch.alarmrecorder.runnables.VideoRecorder;
|
||||
import com.example.greenwatch.sensors.AccelerometerSensor;
|
||||
import com.example.greenwatch.sensors.CameraSensor;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class AlarmRecorder {
|
||||
private static AlarmRecorder alarmRecorderInstance;
|
||||
private boolean isRecording;
|
||||
private String videoPath;
|
||||
private String audioPath;
|
||||
private MediaFormat videoFormat;
|
||||
private MediaFormat audioFormat;
|
||||
private MediaExtractor videoExtractor;
|
||||
private MediaExtractor audioExtractor;
|
||||
private Runnable audioRecorderRunnable;
|
||||
private Runnable videoRecorderRunnable;
|
||||
private SurfaceHolder previewHolder;
|
||||
private MediaRecorder videoRecorder;
|
||||
private MediaRecorder audioRecorder;
|
||||
private Thread videoThread; // Video-Thread als Instanzvariable
|
||||
private Thread audioThread; // Audio-Thread als Instanzvariable
|
||||
|
||||
private AlarmRecorder() {
|
||||
audioRecorder = new MediaRecorder();
|
||||
videoRecorder = new MediaRecorder();
|
||||
videoExtractor = new MediaExtractor();
|
||||
audioExtractor = new MediaExtractor();
|
||||
}
|
||||
|
||||
public static synchronized AlarmRecorder getInstance() {
|
||||
if (alarmRecorderInstance == null){
|
||||
alarmRecorderInstance = new AlarmRecorder();
|
||||
}
|
||||
return alarmRecorderInstance;
|
||||
}
|
||||
|
||||
public void setPreviewHolder(SurfaceHolder previewHolder) {
|
||||
this.previewHolder = previewHolder;
|
||||
}
|
||||
|
||||
public void startRecording() {
|
||||
createStoragePaths(); //Speicherort und -namen für Audio- und Video-Datei
|
||||
|
||||
audioRecorderRunnable = new AudioRecorder(audioRecorder, audioPath);
|
||||
videoRecorderRunnable = new VideoRecorder(videoRecorder, videoPath, previewHolder);
|
||||
audioThread = new Thread(audioRecorderRunnable);
|
||||
videoThread = new Thread(videoRecorderRunnable);
|
||||
|
||||
//Threads starten
|
||||
videoThread.start();
|
||||
audioThread.start();
|
||||
}
|
||||
|
||||
public void stopRecording(Context context) {
|
||||
isRecording = false;
|
||||
try {
|
||||
stopVideoRecording();
|
||||
stopAudioRecording();
|
||||
|
||||
Toast.makeText(context, "Video- und Audioaufzeichnung beendet", Toast.LENGTH_SHORT).show();
|
||||
|
||||
waitTillThreadsStopped();
|
||||
File videoFile = new File(videoPath); //Speichere das aufgenommene Video
|
||||
File audioFile = new File(audioPath); //Speichere die aufgenommene Audio
|
||||
|
||||
if (videoFile.exists() && audioFile.exists()) {
|
||||
//Wenn Video- und Audioaufzeichnung gestoppt und abgespeichert sind, beginne mit dem Mergeprozess der beiden
|
||||
mergeVideoWithAudio();
|
||||
Toast.makeText(context, "Video und Audio erfolgreich zusammengeführt", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(context, "Dateien wurden nicht gefunden!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} catch (RuntimeException stopException) {
|
||||
stopException.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void createStoragePaths(){
|
||||
//Pfade zum Zwischenspeichern der aufgenommenen Audio und Video-Datei
|
||||
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();
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
package com.example.greenwatch.alarmrecorder.runnables;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import com.example.greenwatch.viewmodels.ViewModelInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class VideoRecorder implements Runnable{
|
||||
private final MediaRecorder videoRecorder;
|
||||
private final String videoPath;
|
||||
private SurfaceHolder previewHolder;
|
||||
|
||||
public VideoRecorder(MediaRecorder videoRecorder, String videoPath, SurfaceHolder previewHolder) {
|
||||
this.videoRecorder = videoRecorder;
|
||||
this.videoPath = videoPath;
|
||||
this.previewHolder = previewHolder;
|
||||
}
|
||||
@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(previewHolder.getSurface());
|
||||
|
||||
try {
|
||||
videoRecorder.prepare();
|
||||
videoRecorder.start();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.example.greenwatch.sensors;
|
||||
import android.content.Context;
|
||||
import android.graphics.ImageFormat;
|
||||
import android.media.Image;
|
||||
import android.os.Handler;
|
||||
import android.util.Size;
|
||||
|
||||
import androidx.camera.core.CameraSelector;
|
||||
@@ -18,9 +19,18 @@ public class CameraSensor {
|
||||
private final MutableLiveData<Boolean> mVideoAlarmDetected = new MutableLiveData<>();
|
||||
private static CameraSensor cameraSensorInstance;
|
||||
private boolean videoAlarmDetected;
|
||||
private boolean isMotionDetected;
|
||||
private ByteBuffer previousBuffer;
|
||||
private int previousWidth;
|
||||
private int previousHeight;
|
||||
private final int threshold = 50;
|
||||
private int startX;
|
||||
private int startY;
|
||||
private int endX;
|
||||
private int endY;
|
||||
private static final long ALARM_RESET_DELAY = 5000;
|
||||
private Runnable alarmResetRunnable;
|
||||
private final Handler alarmResetHandler = new Handler();
|
||||
|
||||
private CameraSensor() {
|
||||
videoAlarmDetected = false;
|
||||
@@ -59,7 +69,7 @@ public class CameraSensor {
|
||||
|
||||
if (previousHeight != 0) {
|
||||
assert currentImage != null;
|
||||
videoAlarmDetected = compareFrames(currentImage);
|
||||
isMotionDetected = compareFrames(currentImage);
|
||||
}
|
||||
|
||||
assert currentImage != null;
|
||||
@@ -72,6 +82,18 @@ public class CameraSensor {
|
||||
|
||||
currentImage.close();
|
||||
|
||||
if (isMotionDetected) {
|
||||
|
||||
videoAlarmDetected = true;
|
||||
|
||||
if(alarmResetRunnable != null) {
|
||||
alarmResetHandler.removeCallbacks(alarmResetRunnable);
|
||||
}
|
||||
|
||||
alarmResetRunnable = this::resetAlarmStatus;
|
||||
alarmResetHandler.postDelayed(alarmResetRunnable, ALARM_RESET_DELAY);
|
||||
}
|
||||
|
||||
checkAlarmCondition();
|
||||
|
||||
}
|
||||
@@ -85,36 +107,76 @@ public class CameraSensor {
|
||||
}
|
||||
|
||||
private boolean compareFrames(Image currentImage) {
|
||||
|
||||
ByteBuffer currentBuffer = currentImage.getPlanes()[0].getBuffer();
|
||||
|
||||
Image.Plane[] planes = currentImage.getPlanes();
|
||||
ByteBuffer currentBuffer = planes[0].getBuffer();
|
||||
int currentWidth = currentImage.getWidth();
|
||||
int currentHeight = currentImage.getHeight();
|
||||
int yRowStride = planes[0].getRowStride();
|
||||
int yPixelStride = planes[0].getPixelStride();
|
||||
|
||||
if (previousWidth != currentWidth || previousHeight != currentHeight) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int row = 0; row < previousHeight; row++) {
|
||||
for (int col = 0; col < previousWidth; col++) {
|
||||
int blockSize = kleinstesQuadrat(previousHeight, previousWidth) / 8;
|
||||
|
||||
int previousIndex = row * previousWidth + col;
|
||||
int currentIndex = row * currentWidth + col;
|
||||
int numBlocksX = currentWidth / blockSize;
|
||||
int numBlocksY = currentHeight / blockSize;
|
||||
|
||||
int previousPixel = previousBuffer.get(previousIndex) & 0xFF;
|
||||
int currentPixel = currentBuffer.get(currentIndex) & 0xFF;
|
||||
for (int blockY = 0; blockY < numBlocksY; blockY++) {
|
||||
for (int blockX = 0; blockX < numBlocksX; blockX++) {
|
||||
startX = blockX * blockSize;
|
||||
startY = blockY * blockSize;
|
||||
endX = startX + blockSize;
|
||||
endY = startY + blockSize;
|
||||
|
||||
int pixelDifference = Math.abs(previousPixel - currentPixel);
|
||||
int threshold = 120;
|
||||
float currentLuminance = berechneMittlereLuminanz(currentBuffer, yRowStride, yPixelStride);
|
||||
float previousLuminance = berechneMittlereLuminanz(previousBuffer, yRowStride, yPixelStride);
|
||||
|
||||
int pixelDifference = Math.abs((int) previousLuminance - (int) currentLuminance);
|
||||
|
||||
if (pixelDifference > threshold) {
|
||||
System.out.println(pixelDifference);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private float berechneMittlereLuminanz(ByteBuffer buffer, int rowStride, int pixelStride) {
|
||||
int sumLuminance = 0;
|
||||
int countPixels = 0;
|
||||
|
||||
for (int row = startY; row < endY; row++) {
|
||||
for (int col = startX; col < endX; col++) {
|
||||
int bufferIndex = row * rowStride + col * pixelStride;
|
||||
int currentPixel = buffer.get(bufferIndex) & 0xFF;
|
||||
|
||||
sumLuminance += currentPixel;
|
||||
countPixels++;
|
||||
}
|
||||
}
|
||||
|
||||
return (float) sumLuminance / countPixels;
|
||||
}
|
||||
|
||||
private int kleinstesQuadrat(int height, int width) {
|
||||
if (height == width) {
|
||||
return height;
|
||||
} else if (height > width) {
|
||||
return kleinstesQuadrat(height - width, width);
|
||||
} else {
|
||||
return kleinstesQuadrat(height, width - height);
|
||||
}
|
||||
}
|
||||
|
||||
private void resetAlarmStatus() {
|
||||
videoAlarmDetected = false;
|
||||
alarmResetRunnable = null;
|
||||
}
|
||||
|
||||
public void checkAlarmCondition() {
|
||||
if (videoAlarmDetected && !mVideoAlarmDetected.getValue()) {
|
||||
setMutableLiveDataVideoAlarmDetected();
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.example.greenwatch.sensors.MicrofonHelperClasses;
|
||||
|
||||
public class GleitenderMittelwert {
|
||||
private final float wichtungNeuerWert;
|
||||
private final float wichtungAlterWert;
|
||||
private float mittelwert = 0;
|
||||
|
||||
private boolean istMittelwertGesetzt = false;
|
||||
|
||||
public GleitenderMittelwert(float wichtungNeuerWert) {
|
||||
this.wichtungNeuerWert = wichtungNeuerWert;
|
||||
this.wichtungAlterWert = 1 - this.wichtungNeuerWert;
|
||||
}
|
||||
|
||||
public float mittel(float wert) {
|
||||
if (istMittelwertGesetzt) {
|
||||
mittelwert = wert * wichtungNeuerWert + mittelwert * wichtungAlterWert;
|
||||
} else {
|
||||
mittelwert = wert;
|
||||
istMittelwertGesetzt = true;
|
||||
}
|
||||
return mittelwert;
|
||||
}}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.example.greenwatch.sensors.MicrofonHelperClasses;
|
||||
|
||||
public class RingPuffer {
|
||||
|
||||
private short[] puffer;
|
||||
private final int laenge;
|
||||
private int anzahlEnthaltenerDaten;
|
||||
private int position;
|
||||
|
||||
|
||||
public RingPuffer(int n) {
|
||||
laenge = n;
|
||||
anzahlEnthaltenerDaten = 0;
|
||||
position = 0;
|
||||
puffer = new short[laenge];
|
||||
}
|
||||
|
||||
public void hinzufuegen(short wert) {
|
||||
puffer[position] = wert;
|
||||
position++;
|
||||
if (position >= laenge) {
|
||||
position = 0;
|
||||
}
|
||||
if (anzahlEnthaltenerDaten < laenge) {
|
||||
anzahlEnthaltenerDaten++;
|
||||
}
|
||||
}
|
||||
|
||||
public short maximum() {
|
||||
short max = 0;
|
||||
for (int i = 0; i < anzahlEnthaltenerDaten; i++) {
|
||||
if (puffer[i] > max) {
|
||||
max = puffer[i];
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.example.greenwatch.sensors.MicrofonHelperClasses;
|
||||
|
||||
public class Verarbeitungsergebnis {
|
||||
private String status;
|
||||
private short maxAmp;
|
||||
private float db;
|
||||
//
|
||||
public Verarbeitungsergebnis(String status, short maxAmp, int db) {
|
||||
this.status = status;
|
||||
this.maxAmp = maxAmp;
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public short getMaxAmp() {
|
||||
return maxAmp;
|
||||
}
|
||||
|
||||
public void setMaxAmp(short maxAmp) {
|
||||
this.maxAmp = maxAmp;
|
||||
}
|
||||
|
||||
public float getDB() {
|
||||
return db;
|
||||
}
|
||||
|
||||
public void setDB(float db) {
|
||||
this.db = db;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package com.example.greenwatch.sensors;
|
||||
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.MediaRecorder;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.example.greenwatch.sensors.MicrofonHelperClasses.GleitenderMittelwert;
|
||||
import com.example.greenwatch.sensors.MicrofonHelperClasses.RingPuffer;
|
||||
import com.example.greenwatch.sensors.MicrofonHelperClasses.Verarbeitungsergebnis;
|
||||
|
||||
public class MicrofonSensor {
|
||||
|
||||
private MutableLiveData<Boolean> mMicrofonAlarmDetected = new MutableLiveData<>();
|
||||
private AufnahmeTask aufnahmeTask;
|
||||
private static MicrofonSensor microfonSensorInstance;
|
||||
private boolean microfonAlarmDetected = false;
|
||||
private boolean kalibrierung_do = true;
|
||||
private float threshold = 40;
|
||||
private float sensitivity = 10;
|
||||
|
||||
private float amplitudeInDB = 0;
|
||||
|
||||
private RingPuffer ringPuffer = new RingPuffer(10);
|
||||
|
||||
private MicrofonSensor() {
|
||||
}
|
||||
|
||||
public static synchronized MicrofonSensor getInstance() {
|
||||
if (microfonSensorInstance == null){
|
||||
microfonSensorInstance = new MicrofonSensor();
|
||||
}
|
||||
return microfonSensorInstance;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
aufnahmeTask = new AufnahmeTask();
|
||||
aufnahmeTask.execute();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if(aufnahmeTask !=null) {
|
||||
aufnahmeTask.cancel(true);
|
||||
aufnahmeTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void doRecalibration() {
|
||||
stop();
|
||||
microfonAlarmDetected = false;
|
||||
kalibrierung_do = true;
|
||||
threshold = 40;
|
||||
sensitivity = 10;
|
||||
amplitudeInDB = 0;
|
||||
}
|
||||
|
||||
public float getAmplitudeInDB() {
|
||||
return amplitudeInDB;
|
||||
}
|
||||
|
||||
private void setAmplitudeInDB(float amplitudeInDB) {
|
||||
this.amplitudeInDB = amplitudeInDB;
|
||||
}
|
||||
|
||||
public MutableLiveData<Boolean> getAccelerometerAlarmDetected() {
|
||||
setMutableLiveDataMicrofonAlarmDetected();
|
||||
return mMicrofonAlarmDetected;
|
||||
}
|
||||
|
||||
private void setMutableLiveDataMicrofonAlarmDetected() {
|
||||
mMicrofonAlarmDetected.setValue(microfonAlarmDetected);
|
||||
}
|
||||
|
||||
class AufnahmeTask extends AsyncTask<Long, Verarbeitungsergebnis, Void> {
|
||||
private AudioRecord recorder;
|
||||
private final int sampleRateInHz = 44100;
|
||||
private final int channelConfig = AudioFormat.CHANNEL_IN_MONO;
|
||||
private final int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||
private int minPufferGroesseInBytes;
|
||||
private int pufferGroesseInBytes;
|
||||
public AufnahmeTask() {
|
||||
minPufferGroesseInBytes = AudioRecord.getMinBufferSize(sampleRateInHz, channelConfig, audioFormat);
|
||||
pufferGroesseInBytes = minPufferGroesseInBytes * 2;
|
||||
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRateInHz, channelConfig, audioFormat, pufferGroesseInBytes);
|
||||
}
|
||||
public float kalibrieren(short[] puffer){
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
int anzahlIterationen = 100;
|
||||
float sum = 0.0f;
|
||||
for(int i = 0; i < anzahlIterationen; i++){
|
||||
int z = recorder.read(puffer, 0, puffer.length);
|
||||
Verarbeitungsergebnis kalibrierung = verarbeiten(puffer, z);
|
||||
System.out.println("Kalibrierung" + kalibrierung.getDB());
|
||||
sum += kalibrierung.getDB();
|
||||
}
|
||||
return sum/anzahlIterationen;
|
||||
}
|
||||
|
||||
public void Detektion(Verarbeitungsergebnis ergebnis){
|
||||
if(ergebnis.getDB() >= (threshold+sensitivity)){
|
||||
microfonAlarmDetected = true;
|
||||
}
|
||||
else if (ergebnis.getDB() <= (threshold)) {
|
||||
microfonAlarmDetected = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Long... params) {
|
||||
|
||||
recorder.startRecording();
|
||||
short[] puffer = new short[pufferGroesseInBytes / 2];
|
||||
GleitenderMittelwert gleitenderMittelwertdB = new GleitenderMittelwert(0.2f);
|
||||
float db = 0.0f;
|
||||
|
||||
//kalibrierung
|
||||
if(kalibrierung_do){
|
||||
threshold = kalibrieren(puffer);
|
||||
kalibrierung_do = false;
|
||||
}
|
||||
|
||||
|
||||
for (; ; ) {
|
||||
if (isCancelled()) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
//ergebnis ermitteln
|
||||
int n = recorder.read(puffer, 0, puffer.length);
|
||||
Verarbeitungsergebnis ergebnis = verarbeiten(puffer, n);
|
||||
|
||||
//Mittelwertberechnnung
|
||||
db = ergebnis.getDB();
|
||||
db = gleitenderMittelwertdB.mittel(db);
|
||||
ergebnis.setDB(db);
|
||||
|
||||
//Db Wert mit Schwellwert vergleichen und Warnung setzen
|
||||
Detektion(ergebnis);
|
||||
publishProgress(ergebnis);
|
||||
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
recorder.release();
|
||||
return null;
|
||||
}
|
||||
|
||||
private Verarbeitungsergebnis verarbeiten(short[] daten, int n) {
|
||||
String status;
|
||||
short maxAmp = -1;
|
||||
int db = 0, db_wert = 0;
|
||||
|
||||
if (n == AudioRecord.ERROR_INVALID_OPERATION) {
|
||||
status = "ERROR_INVALID_OPERATION";
|
||||
} else if (n == AudioRecord.ERROR_BAD_VALUE) {
|
||||
status = "ERROR_BAD_VALUE";
|
||||
} else {
|
||||
status = "OK";
|
||||
short max = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (daten[i] > max) {
|
||||
max = daten[i];
|
||||
}
|
||||
}
|
||||
ringPuffer.hinzufuegen(max);
|
||||
maxAmp = ringPuffer.maximum();
|
||||
}
|
||||
//Umwandlung Amplitudenwert in dB
|
||||
db_wert = (int) (20*Math.log10(maxAmp));
|
||||
if (db_wert > 0){
|
||||
db = db_wert;
|
||||
}
|
||||
|
||||
|
||||
return new Verarbeitungsergebnis(status, maxAmp, db);
|
||||
}
|
||||
@Override
|
||||
protected void onProgressUpdate(Verarbeitungsergebnis... progress) {
|
||||
super.onProgressUpdate(progress);
|
||||
|
||||
setAmplitudeInDB(progress[0].getDB());
|
||||
|
||||
if (microfonAlarmDetected != mMicrofonAlarmDetected.getValue()){
|
||||
setMutableLiveDataMicrofonAlarmDetected();
|
||||
}
|
||||
//textViewMaxAmpdb.setText("" + progress[0].db);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
package com.example.greenwatch.viewmodels;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.example.greenwatch.alarmrecorder.AlarmRecorder;
|
||||
import com.example.greenwatch.models.Device;
|
||||
import com.example.greenwatch.repositories.DeviceRepository;
|
||||
import com.example.greenwatch.sensors.AccelerometerSensor;
|
||||
@@ -15,26 +11,21 @@ import com.example.greenwatch.sensors.AccelerometerSensor;
|
||||
import java.util.List;
|
||||
|
||||
public class AccelerometerViewModel extends ViewModel implements ViewModelInterface {
|
||||
|
||||
private MutableLiveData<List<Device>> mDeviceList;
|
||||
private MutableLiveData<Boolean> mAccelerometerAlarmDetected;
|
||||
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||
private MutableLiveData<Boolean> mStartAlarmRecording;
|
||||
private AccelerometerSensor mAccelerometerSensor;
|
||||
private AlarmRecorder mAlarmRecorder;
|
||||
private DeviceRepository mDeviceRepository;
|
||||
|
||||
@Override
|
||||
public void init(SurfaceHolder previewHolder) {
|
||||
public void init() {
|
||||
if (mDeviceRepository == null) {
|
||||
mDeviceRepository = DeviceRepository.getInstance();
|
||||
}
|
||||
if (mAccelerometerSensor == null) {
|
||||
mAccelerometerSensor = AccelerometerSensor.getInstance();
|
||||
}
|
||||
if (mAlarmRecorder == null) {
|
||||
mAlarmRecorder = AlarmRecorder.getInstance();
|
||||
}
|
||||
if (mDeviceList == null) {
|
||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||
}
|
||||
@@ -47,7 +38,6 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
|
||||
if (mAccelerometerAlarmDetected == null) {
|
||||
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected();
|
||||
}
|
||||
setAlarmRecordingPreviewHolder(previewHolder);
|
||||
}
|
||||
|
||||
public void addValueToGesamtBE(float newValue) {
|
||||
@@ -149,19 +139,4 @@ public class AccelerometerViewModel extends ViewModel implements ViewModelInterf
|
||||
public String getSystemTimeStamp() {
|
||||
return mDeviceRepository.getSystemTimeStamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAlarmRecording() {
|
||||
mAlarmRecorder.startRecording();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAlarmRecording(Context context) {
|
||||
mAlarmRecorder.stopRecording(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder) {
|
||||
mAlarmRecorder.setPreviewHolder(previewHolder);
|
||||
}
|
||||
}
|
||||
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
package com.example.greenwatch.viewmodels;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.example.greenwatch.models.Device;
|
||||
import com.example.greenwatch.repositories.DeviceRepository;
|
||||
import com.example.greenwatch.sensors.AccelerometerSensor;
|
||||
import com.example.greenwatch.sensors.MicrofonSensor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AudiodetectionAndAccelerometerViewModel extends ViewModel implements ViewModelInterface {
|
||||
private MutableLiveData<List<Device>> mDeviceList;
|
||||
private MutableLiveData<Boolean> mAccelerometerAlarmDetected;
|
||||
private MutableLiveData<Boolean> mMicrofonAlarmDetected;
|
||||
private MutableLiveData<Boolean> mAudiodetectionAndAccelerometerAlarmDetected = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||
private MutableLiveData<Boolean> mStartAlarmRecording;
|
||||
private AccelerometerSensor mAccelerometerSensor;
|
||||
private MicrofonSensor mMicrofonSensor;
|
||||
private DeviceRepository mDeviceRepository;
|
||||
private boolean microfonAlarmDetected;
|
||||
private boolean accelerometerAlarmDetected;
|
||||
private boolean microfondetectionAndAccelerometerAlarmDetected;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (mDeviceRepository == null) {
|
||||
mDeviceRepository = DeviceRepository.getInstance();
|
||||
}
|
||||
if (mAccelerometerSensor == null) {
|
||||
mAccelerometerSensor = AccelerometerSensor.getInstance();
|
||||
}
|
||||
if (mMicrofonSensor == null) {
|
||||
mMicrofonSensor = MicrofonSensor.getInstance();
|
||||
}
|
||||
if (mDeviceList == null) {
|
||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||
}
|
||||
if (mAlarmHistoryList == null) {
|
||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||
}
|
||||
if (mStartAlarmRecording == null) {
|
||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
|
||||
}
|
||||
if (mAccelerometerAlarmDetected == null) {
|
||||
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected();
|
||||
}
|
||||
if (mMicrofonAlarmDetected == null) {
|
||||
mMicrofonAlarmDetected = mMicrofonSensor.getAccelerometerAlarmDetected();
|
||||
}
|
||||
microfondetectionAndAccelerometerAlarmDetected = false;
|
||||
accelerometerAlarmDetected = false;
|
||||
microfonAlarmDetected = false;
|
||||
registerAlarmObserver();
|
||||
}
|
||||
|
||||
public void addValueToGesamtBE(float newValue) {
|
||||
mAccelerometerSensor.addValueToGesamtBE(newValue);
|
||||
}
|
||||
|
||||
public void meanValueCalculation() {
|
||||
mAccelerometerSensor.meanValueCalculation();
|
||||
}
|
||||
|
||||
public void calibrateAccelerometerSensor() {
|
||||
mAccelerometerSensor.calibrateAccelerometerSensor();
|
||||
}
|
||||
|
||||
public void checkAlarmCondition() {
|
||||
mAccelerometerSensor.checkAlarmCondition();
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getAudiodetectionAndAccelerometerAlarmDetected() {
|
||||
setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected();
|
||||
return mAudiodetectionAndAccelerometerAlarmDetected;
|
||||
}
|
||||
|
||||
public void startMicrofonSensor() {
|
||||
mMicrofonSensor.start();
|
||||
}
|
||||
|
||||
public void stopMicrofonSensor() {
|
||||
mMicrofonSensor.stop();
|
||||
}
|
||||
|
||||
public void recalibrationMicrofonSensor() {
|
||||
mMicrofonSensor.doRecalibration();
|
||||
}
|
||||
|
||||
public float getAmplitudeInDB() {
|
||||
return mMicrofonSensor.getAmplitudeInDB();
|
||||
}
|
||||
|
||||
private void setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected() {
|
||||
mAudiodetectionAndAccelerometerAlarmDetected.setValue(microfondetectionAndAccelerometerAlarmDetected);
|
||||
}
|
||||
|
||||
private void setAccelerometerAlarmDetected(boolean accelerometerAlarmDetected) {
|
||||
this.accelerometerAlarmDetected = accelerometerAlarmDetected;
|
||||
}
|
||||
|
||||
public boolean getAccelerometerAlarmDetected() {
|
||||
return accelerometerAlarmDetected;
|
||||
}
|
||||
|
||||
private void setMicrofonAlarmDetected(boolean microfonAlarmDetected) {
|
||||
this.microfonAlarmDetected = microfonAlarmDetected;
|
||||
}
|
||||
|
||||
public boolean getMicrofonAlarmDetected() {
|
||||
return microfonAlarmDetected;
|
||||
}
|
||||
|
||||
Observer<Boolean> observer = new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
setAccelerometerAlarmDetected(mAccelerometerAlarmDetected.getValue());
|
||||
setMicrofonAlarmDetected(mMicrofonAlarmDetected.getValue());
|
||||
if (microfonAlarmDetected || accelerometerAlarmDetected) {
|
||||
microfondetectionAndAccelerometerAlarmDetected = true;
|
||||
setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected();
|
||||
|
||||
}
|
||||
else if (!microfonAlarmDetected && !accelerometerAlarmDetected) {
|
||||
microfondetectionAndAccelerometerAlarmDetected = false;
|
||||
setMutableLiveDataMicrofondetectionAndAccelerometerAlarmDetected();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void registerAlarmObserver() {
|
||||
mMicrofonAlarmDetected.observeForever(observer);
|
||||
mAccelerometerAlarmDetected.observeForever(observer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCleared() {
|
||||
super.onCleared();
|
||||
mMicrofonAlarmDetected.removeObserver(observer);
|
||||
mAccelerometerAlarmDetected.removeObserver(observer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<List<Device>> getConnectedDeviceList() {
|
||||
return mDeviceList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<List<Device>> getAlarmHistoryList() {
|
||||
return mAlarmHistoryList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<Boolean> getStartAlarmRecording() {
|
||||
return mStartAlarmRecording;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeStamp(String deviceID, String timeStamp) {
|
||||
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTimeStamp(String deviceID) {
|
||||
return mDeviceRepository.getTimeStamp(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceID(String deviceID, String newDeviceID) {
|
||||
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeviceID(String deviceID) {
|
||||
return mDeviceRepository.getDeviceID(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSensorStatus(String deviceID, boolean sensorStatus) {
|
||||
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSensorStatus(String deviceID) {
|
||||
return mDeviceRepository.getSensorStatus(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSensorType(String deviceID, String sensorType) {
|
||||
mDeviceRepository.setSensorType(deviceID, sensorType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSensorType(String deviceID) {
|
||||
return mDeviceRepository.getSensorType(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSensorMassage(String deviceID, int sensorMessage) {
|
||||
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSensorMassage(String deviceID) {
|
||||
return mDeviceRepository.getSensorMassage(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalDeviceUUID() {
|
||||
return mDeviceRepository.getLocalDeviceUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSystemTimeStamp() {
|
||||
return mDeviceRepository.getSystemTimeStamp();
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
@@ -12,7 +11,6 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.example.greenwatch.alarmrecorder.AlarmRecorder;
|
||||
import com.example.greenwatch.communication.WiFiCommunication;
|
||||
import com.example.greenwatch.models.Device;
|
||||
import com.example.greenwatch.repositories.DeviceRepository;
|
||||
@@ -25,29 +23,32 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
|
||||
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||
private MutableLiveData<Boolean> mStartAlarmRecording;
|
||||
private DeviceRepository mDeviceRepository;
|
||||
private AlarmRecorder mAlarmRecorder;
|
||||
private static final int RIGHTS_REQUEST_CAMERA = 10;
|
||||
private static final int REQUEST_PERMISSION = 200;
|
||||
private static final int RIGHTS_REQUEST_CAMERA_MICROFON = 1;
|
||||
|
||||
@Override
|
||||
public void init(SurfaceHolder previewHolder) {
|
||||
public void init() {
|
||||
WiFiCommunication mWiFiCommunication;
|
||||
if(mDeviceList != null) {
|
||||
return;
|
||||
}
|
||||
if (mAlarmRecorder == null) {
|
||||
mAlarmRecorder = AlarmRecorder.getInstance();
|
||||
}
|
||||
//todo: check if WiFi instanz can be hold only by the repository
|
||||
mDeviceRepository = DeviceRepository.getInstance();
|
||||
mWiFiCommunication = WiFiCommunication.getInstance();
|
||||
mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
|
||||
mWiFiCommunication.setDeviceRepository(mDeviceRepository);
|
||||
//mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
|
||||
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
|
||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
|
||||
setAlarmRecordingPreviewHolder(previewHolder);
|
||||
}
|
||||
|
||||
public boolean isMicrofonAccessAllowed(Context context) {
|
||||
return ContextCompat.checkSelfPermission(context, android.Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
public void accessRequestMicrofon(Activity activity) {
|
||||
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.RECORD_AUDIO}, RIGHTS_REQUEST_CAMERA_MICROFON);
|
||||
}
|
||||
|
||||
public boolean isCameraAccessAllowed(Context context) {
|
||||
@@ -58,22 +59,6 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
|
||||
ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.CAMERA}, RIGHTS_REQUEST_CAMERA);
|
||||
}
|
||||
|
||||
public boolean isAudioRecordingAccessAllowed(Context context) {
|
||||
return ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
public void accessRequestAudioRecording(Activity activity) {
|
||||
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.RECORD_AUDIO}, REQUEST_PERMISSION);
|
||||
}
|
||||
|
||||
public boolean isWriteExternalStorageAccessAllowed(Context context) {
|
||||
return ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
public void accessRequestWriteExternalStorage(Activity activity) {
|
||||
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<List<Device>> getConnectedDeviceList() {
|
||||
return mDeviceList;
|
||||
@@ -153,19 +138,4 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
|
||||
public String getSystemTimeStamp() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAlarmRecording() {
|
||||
mAlarmRecorder.startRecording();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAlarmRecording(Context context) {
|
||||
mAlarmRecorder.stopRecording(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder) {
|
||||
mAlarmRecorder.setPreviewHolder(previewHolder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.example.greenwatch.viewmodels;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.example.greenwatch.models.Device;
|
||||
import com.example.greenwatch.repositories.DeviceRepository;
|
||||
import com.example.greenwatch.sensors.MicrofonSensor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MicrofonViewModel extends ViewModel implements ViewModelInterface {
|
||||
private MutableLiveData<List<Device>> mDeviceList;
|
||||
private MutableLiveData<Boolean> mMicrofonAlarmDetected;
|
||||
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||
private MutableLiveData<Boolean> mStartAlarmRecording;
|
||||
private MicrofonSensor mMicrofonSensor;
|
||||
private DeviceRepository mDeviceRepository;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
if (mDeviceRepository == null) {
|
||||
mDeviceRepository = DeviceRepository.getInstance();
|
||||
}
|
||||
if (mMicrofonSensor == null) {
|
||||
mMicrofonSensor = MicrofonSensor.getInstance();
|
||||
}
|
||||
if (mDeviceList == null) {
|
||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||
}
|
||||
if (mAlarmHistoryList == null) {
|
||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
|
||||
}
|
||||
if (mStartAlarmRecording == null) {
|
||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
|
||||
}
|
||||
if (mMicrofonAlarmDetected == null) {
|
||||
mMicrofonAlarmDetected = mMicrofonSensor.getAccelerometerAlarmDetected();
|
||||
}
|
||||
}
|
||||
|
||||
public void startMicrofonSensor() {
|
||||
mMicrofonSensor.start();
|
||||
}
|
||||
|
||||
public void stopMicrofonSensor() {
|
||||
mMicrofonSensor.stop();
|
||||
}
|
||||
|
||||
public void recalibrationMicrofonSensor() {
|
||||
mMicrofonSensor.doRecalibration();
|
||||
}
|
||||
|
||||
public float getAmplitudeInDB() {
|
||||
return mMicrofonSensor.getAmplitudeInDB();
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getMicrofonAlarmDetected() {
|
||||
return mMicrofonAlarmDetected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<List<Device>> getConnectedDeviceList() {
|
||||
return mDeviceList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<List<Device>> getAlarmHistoryList() {
|
||||
return mAlarmHistoryList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveData<Boolean> getStartAlarmRecording() {
|
||||
return mStartAlarmRecording;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) {
|
||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeStamp(String deviceID, String timeStamp) {
|
||||
mDeviceRepository.setTimeStamp(deviceID, timeStamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTimeStamp(String deviceID) {
|
||||
return mDeviceRepository.getTimeStamp(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDeviceID(String deviceID, String newDeviceID) {
|
||||
mDeviceRepository.setDeviceID(deviceID, newDeviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeviceID(String deviceID) {
|
||||
return mDeviceRepository.getDeviceID(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSensorStatus(String deviceID, boolean sensorStatus) {
|
||||
mDeviceRepository.setSensorStatus(deviceID, sensorStatus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getSensorStatus(String deviceID) {
|
||||
return mDeviceRepository.getSensorStatus(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSensorType(String deviceID, String sensorType) {
|
||||
mDeviceRepository.setSensorType(deviceID, sensorType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSensorType(String deviceID) {
|
||||
return mDeviceRepository.getSensorType(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSensorMassage(String deviceID, int sensorMessage) {
|
||||
mDeviceRepository.setSensorMassage(deviceID, sensorMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSensorMassage(String deviceID) {
|
||||
return mDeviceRepository.getSensorMassage(deviceID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalDeviceUUID() {
|
||||
return mDeviceRepository.getLocalDeviceUUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSystemTimeStamp() {
|
||||
return mDeviceRepository.getSystemTimeStamp();
|
||||
}
|
||||
}
|
||||
+31
-9
@@ -16,7 +16,7 @@ import com.example.greenwatch.sensors.CameraSensor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/*public class VideodetectionAndAccelerometerViewModel extends ViewModel implements ViewModelInterface{
|
||||
public class VideodetectionAndAccelerometerViewModel extends ViewModel implements ViewModelInterface{
|
||||
private MutableLiveData<List<Device>> mDeviceList;
|
||||
private MutableLiveData<Boolean> mAccelerometerAlarmDetected;
|
||||
private MutableLiveData<Boolean> mVideoAlarmDetected;
|
||||
@@ -26,7 +26,9 @@ import java.util.List;
|
||||
private AccelerometerSensor mAccelerometerSensor;
|
||||
private CameraSensor mCameraSensor;
|
||||
private DeviceRepository mDeviceRepository;
|
||||
private boolean VideodetectionAndAccelerometerAlarmDetected;
|
||||
private boolean videoAlarmDetected;
|
||||
private boolean accelerometerAlarmDetected;
|
||||
private boolean videodetectionAndAccelerometerAlarmDetected;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
@@ -54,7 +56,9 @@ import java.util.List;
|
||||
if (mVideoAlarmDetected == null) {
|
||||
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue();
|
||||
}
|
||||
VideodetectionAndAccelerometerAlarmDetected = false;
|
||||
videodetectionAndAccelerometerAlarmDetected = false;
|
||||
videoAlarmDetected = false;
|
||||
accelerometerAlarmDetected = false;
|
||||
registerAlarmObserver();
|
||||
}
|
||||
|
||||
@@ -84,19 +88,37 @@ import java.util.List;
|
||||
}
|
||||
|
||||
private void setMutableLiveDataVideodetectionAndAccelerometerAlarmDetected() {
|
||||
mVideodetectionAndAccelerometerAlarmDetected.setValue(VideodetectionAndAccelerometerAlarmDetected);
|
||||
mVideodetectionAndAccelerometerAlarmDetected.setValue(videodetectionAndAccelerometerAlarmDetected);
|
||||
}
|
||||
|
||||
private void setAccelerometerAlarmDetected(boolean accelerometerAlarmDetected) {
|
||||
this.accelerometerAlarmDetected = accelerometerAlarmDetected;
|
||||
}
|
||||
|
||||
public boolean getAccelerometerAlarmDetected() {
|
||||
return accelerometerAlarmDetected;
|
||||
}
|
||||
|
||||
private void setVideoAlarmDetected(boolean videoAlarmDetected) {
|
||||
this.videoAlarmDetected = videoAlarmDetected;
|
||||
}
|
||||
|
||||
public boolean getVideoAlarmDetected() {
|
||||
return videoAlarmDetected;
|
||||
}
|
||||
|
||||
Observer<Boolean> observer = new Observer<Boolean>() {
|
||||
@Override
|
||||
public void onChanged(Boolean aBoolean) {
|
||||
if (mVideoAlarmDetected.getValue() || mAccelerometerAlarmDetected.getValue() && !VideodetectionAndAccelerometerAlarmDetected) {
|
||||
VideodetectionAndAccelerometerAlarmDetected = true;
|
||||
setAccelerometerAlarmDetected(mAccelerometerAlarmDetected.getValue());
|
||||
setVideoAlarmDetected(mVideoAlarmDetected.getValue());
|
||||
if (videoAlarmDetected || accelerometerAlarmDetected && !videodetectionAndAccelerometerAlarmDetected) {
|
||||
videodetectionAndAccelerometerAlarmDetected = true;
|
||||
setMutableLiveDataVideodetectionAndAccelerometerAlarmDetected();
|
||||
|
||||
}
|
||||
else if (!mVideoAlarmDetected.getValue() && !mAccelerometerAlarmDetected.getValue() && VideodetectionAndAccelerometerAlarmDetected) {
|
||||
VideodetectionAndAccelerometerAlarmDetected = false;
|
||||
else if (!videoAlarmDetected && !accelerometerAlarmDetected && videodetectionAndAccelerometerAlarmDetected) {
|
||||
videodetectionAndAccelerometerAlarmDetected = false;
|
||||
setMutableLiveDataVideodetectionAndAccelerometerAlarmDetected();
|
||||
}
|
||||
}
|
||||
@@ -193,4 +215,4 @@ import java.util.List;
|
||||
public String getSystemTimeStamp() {
|
||||
return mDeviceRepository.getSystemTimeStamp();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.example.greenwatch.viewmodels;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
@@ -9,7 +8,6 @@ import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.example.greenwatch.alarmrecorder.AlarmRecorder;
|
||||
import com.example.greenwatch.models.Device;
|
||||
import com.example.greenwatch.repositories.DeviceRepository;
|
||||
import com.example.greenwatch.sensors.CameraSensor;
|
||||
@@ -23,7 +21,6 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
|
||||
private MutableLiveData<List<Device>> mAlarmHistoryList;
|
||||
private MutableLiveData<Boolean> mStartAlarmRecording;
|
||||
private DeviceRepository mDeviceRepository;
|
||||
private AlarmRecorder mAlarmRecorder;
|
||||
private CameraSensor mCameraSensor;
|
||||
|
||||
|
||||
@@ -32,16 +29,13 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(SurfaceHolder previewHolder) {
|
||||
public void init() {
|
||||
if (mDeviceRepository == null) {
|
||||
mDeviceRepository = DeviceRepository.getInstance();
|
||||
}
|
||||
if (mCameraSensor == null) {
|
||||
mCameraSensor = CameraSensor.getInstance();
|
||||
}
|
||||
if (mAlarmRecorder == null) {
|
||||
mAlarmRecorder = AlarmRecorder.getInstance();
|
||||
}
|
||||
if (mDeviceList == null) {
|
||||
mDeviceList = mDeviceRepository.getConnectedDeviceList();
|
||||
}
|
||||
@@ -54,7 +48,6 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
|
||||
if (mVideoAlarmDetected == null) {
|
||||
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue();
|
||||
}
|
||||
setAlarmRecordingPreviewHolder(previewHolder);
|
||||
}
|
||||
|
||||
public void bindImageAnalysis(ProcessCameraProvider cameraProvider, LifecycleOwner lifecycleOwner, Context context) {
|
||||
@@ -144,19 +137,4 @@ public class VideodetectionViewModel extends ViewModel implements ViewModelInter
|
||||
public String getSystemTimeStamp() {
|
||||
return mDeviceRepository.getSystemTimeStamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAlarmRecording() {
|
||||
mAlarmRecorder.startRecording();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAlarmRecording(Context context) {
|
||||
mAlarmRecorder.stopRecording(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder) {
|
||||
mAlarmRecorder.setPreviewHolder(previewHolder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.example.greenwatch.viewmodels;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.example.greenwatch.models.Device;
|
||||
@@ -10,7 +7,7 @@ import com.example.greenwatch.models.Device;
|
||||
import java.util.List;
|
||||
|
||||
public interface ViewModelInterface {
|
||||
void init(SurfaceHolder previewHolder);
|
||||
void init();
|
||||
LiveData<List<Device>> getConnectedDeviceList();
|
||||
LiveData<List<Device>> getAlarmHistoryList();
|
||||
LiveData<Boolean> getStartAlarmRecording();
|
||||
@@ -27,7 +24,4 @@ public interface ViewModelInterface {
|
||||
int getSensorMassage(String deviceID);
|
||||
String getLocalDeviceUUID();
|
||||
String getSystemTimeStamp();
|
||||
void startAlarmRecording();
|
||||
void stopAlarmRecording(Context context);
|
||||
void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,6 @@
|
||||
android:padding="10dp"
|
||||
tools:context=".AccelerometerActivity">
|
||||
|
||||
<SurfaceView
|
||||
android:id="@+id/surfaceViewAccelerometer"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="1dp"
|
||||
android:visibility="visible">
|
||||
</SurfaceView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvAccelerometerStatusmessage"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
android:id="@+id/tvAudiodetectionStatusmessage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Audiodetection Activity">
|
||||
android:text="">
|
||||
</TextView>
|
||||
|
||||
<Button
|
||||
@@ -22,4 +22,27 @@
|
||||
android:text="Back to MainActivity">
|
||||
</Button>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/deviceListRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/device_item"
|
||||
android:layout_weight="1">
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/alarmHistoryListRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/alarm_history_item"
|
||||
android:layout_weight="1">
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -22,4 +22,27 @@
|
||||
android:text="Back to MainActivity">
|
||||
</Button>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/deviceListRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/device_item"
|
||||
android:layout_weight="1">
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/alarmHistoryListRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:listitem="@layout/alarm_history_item"
|
||||
android:layout_weight="1">
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -12,7 +12,7 @@
|
||||
android:id="@+id/alarmHistoryListRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="4"
|
||||
android:layout_weight="3"
|
||||
tools:listitem="@layout/alarm_history_item">
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
@@ -20,15 +20,9 @@
|
||||
android:id="@+id/deviceListRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="4"
|
||||
android:layout_weight="3"
|
||||
tools:listitem="@layout/device_item">
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
<SurfaceView
|
||||
android:id="@+id/surfaceViewMainActivity"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="1dp">
|
||||
</SurfaceView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -8,13 +8,6 @@
|
||||
android:padding="10dp"
|
||||
tools:context=".VideodetectionActivity">
|
||||
|
||||
<SurfaceView
|
||||
android:id="@+id/surfaceViewVideodetection"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="1dp"
|
||||
android:visibility="visible">
|
||||
</SurfaceView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvVideodetectionStatusmessage"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user