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.RECORD_AUDIO" /> | |||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | <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.RECORD_AUDIO" /> | |||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> | ||||
<uses-permission android:name="android.permission.CAMERA" /> | |||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | |||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> | |||||
<uses-feature android:name="android.hardware.camera"/> | <uses-feature android:name="android.hardware.camera"/> | ||||
import android.hardware.SensorEventListener; | import android.hardware.SensorEventListener; | ||||
import android.hardware.SensorManager; | import android.hardware.SensorManager; | ||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.view.SurfaceView; | |||||
import android.view.View; | import android.view.View; | ||||
import android.widget.Button; | import android.widget.Button; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
private SensorManager accelerometerManager; | private SensorManager accelerometerManager; | ||||
private Sensor accelerometerSensor; | private Sensor accelerometerSensor; | ||||
private SurfaceView surfaceView; | |||||
private TextView accelerometerStatusMessage; | private TextView accelerometerStatusMessage; | ||||
private TextView accelerometerDataTV; | private TextView accelerometerDataTV; | ||||
private TextView tvAccelerometerdeviceListRecyclerView; | private TextView tvAccelerometerdeviceListRecyclerView; | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setContentView(R.layout.activity_accelerometer); | setContentView(R.layout.activity_accelerometer); | ||||
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewAccelerometer); | |||||
accelerometerStatusMessage = (TextView) findViewById(R.id.tvAccelerometerStatusmessage); | accelerometerStatusMessage = (TextView) findViewById(R.id.tvAccelerometerStatusmessage); | ||||
accelerometerDataTV = (TextView) findViewById(R.id.tvAccelerometerData); | accelerometerDataTV = (TextView) findViewById(R.id.tvAccelerometerData); | ||||
tvAccelerometerdeviceListRecyclerView = (TextView) findViewById(R.id.tvAccelerometerdeviceListRecyclerView); | tvAccelerometerdeviceListRecyclerView = (TextView) findViewById(R.id.tvAccelerometerdeviceListRecyclerView); | ||||
}); | }); | ||||
mAccelerometerViewModel = new ViewModelProvider(this).get(AccelerometerViewModel.class); | mAccelerometerViewModel = new ViewModelProvider(this).get(AccelerometerViewModel.class); | ||||
mAccelerometerViewModel.init(); | |||||
mAccelerometerViewModel.init(surfaceView.getHolder()); | |||||
mAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | mAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | ||||
@Override | @Override | ||||
public void onChanged(List<Device> devices) { | public void onChanged(List<Device> devices) { | ||||
if (aBoolean) { | if (aBoolean) { | ||||
if(permission.alarmRechtePruefen(AccelerometerActivity.this, AccelerometerActivity.this)){ | if(permission.alarmRechtePruefen(AccelerometerActivity.this, AccelerometerActivity.this)){ | ||||
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mAccelerometerViewModel.startAlarmRecording(); | |||||
//todo AlarmHandling einfügen | //todo AlarmHandling einfügen | ||||
} else { | |||||
} | |||||
else { | |||||
permission.alarmRechteAnfordern(AccelerometerActivity.this); | permission.alarmRechteAnfordern(AccelerometerActivity.this); | ||||
if(permission.alarmRechtePruefen(AccelerometerActivity.this, AccelerometerActivity.this)){ | if(permission.alarmRechtePruefen(AccelerometerActivity.this, AccelerometerActivity.this)){ | ||||
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mAccelerometerViewModel.startAlarmRecording(); | |||||
//todo Alarmhandling einfügen | //todo Alarmhandling einfügen | ||||
} else { | |||||
} | |||||
else { | |||||
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mAccelerometerViewModel.stopAlarmRecording(AccelerometerActivity.this); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
mAccelerometerViewModel.stopAlarmRecording(AccelerometerActivity.this); | |||||
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
} | } | ||||
} | } |
import androidx.recyclerview.widget.LinearLayoutManager; | import androidx.recyclerview.widget.LinearLayoutManager; | ||||
import androidx.recyclerview.widget.RecyclerView; | import androidx.recyclerview.widget.RecyclerView; | ||||
import android.hardware.SensorManager; | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.view.SurfaceView; | |||||
import android.view.View; | import android.view.View; | ||||
import android.widget.Button; | import android.widget.Button; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import com.example.greenwatch.adapters.AlarmHistoryListAdapter; | import com.example.greenwatch.adapters.AlarmHistoryListAdapter; | ||||
import com.example.greenwatch.adapters.DeviceListAdapter; | import com.example.greenwatch.adapters.DeviceListAdapter; | ||||
import com.example.greenwatch.models.Device; | import com.example.greenwatch.models.Device; | ||||
import com.example.greenwatch.viewmodels.AccelerometerViewModel; | |||||
import com.example.greenwatch.viewmodels.MicrofonViewModel; | import com.example.greenwatch.viewmodels.MicrofonViewModel; | ||||
import java.util.List; | import java.util.List; | ||||
private TextView tvAAudiodetectionAlarmHistoryListRecyclerView; | private TextView tvAAudiodetectionAlarmHistoryListRecyclerView; | ||||
private TextView tvAudiodetectionDeviceListRecyclerView; | private TextView tvAudiodetectionDeviceListRecyclerView; | ||||
private Button backToMainActivityButton; | private Button backToMainActivityButton; | ||||
private SurfaceView surfaceView; | |||||
private Permission permission = new Permission(); | private Permission permission = new Permission(); | ||||
private MicrofonViewModel mMicrofonViewModel; | private MicrofonViewModel mMicrofonViewModel; | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setContentView(R.layout.activity_audiodetection); | setContentView(R.layout.activity_audiodetection); | ||||
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewAudio); | |||||
microfonStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionStatusmessage); | microfonStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionStatusmessage); | ||||
tvAAudiodetectionAlarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionAlarmHistoryListRecyclerView); | tvAAudiodetectionAlarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionAlarmHistoryListRecyclerView); | ||||
tvAudiodetectionDeviceListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionDeviceListRecyclerView); | tvAudiodetectionDeviceListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionDeviceListRecyclerView); | ||||
}); | }); | ||||
mMicrofonViewModel = new ViewModelProvider(this).get(MicrofonViewModel.class); | mMicrofonViewModel = new ViewModelProvider(this).get(MicrofonViewModel.class); | ||||
mMicrofonViewModel.init(); | |||||
mMicrofonViewModel.init(surfaceView.getHolder()); | |||||
mMicrofonViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | mMicrofonViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | ||||
@Override | @Override | ||||
public void onChanged(List<Device> devices) { | public void onChanged(List<Device> devices) { | ||||
if (aBoolean) { | if (aBoolean) { | ||||
if(permission.alarmRechtePruefen(AudiodetectionActivity.this, AudiodetectionActivity.this)){ | if(permission.alarmRechtePruefen(AudiodetectionActivity.this, AudiodetectionActivity.this)){ | ||||
Toast.makeText(AudiodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AudiodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mMicrofonViewModel.startAlarmRecording(); | |||||
//todo AlarmHandling einfügen | //todo AlarmHandling einfügen | ||||
} else { | } else { | ||||
permission.alarmRechteAnfordern(AudiodetectionActivity.this); | permission.alarmRechteAnfordern(AudiodetectionActivity.this); | ||||
if(permission.alarmRechtePruefen(AudiodetectionActivity.this, AudiodetectionActivity.this)){ | if(permission.alarmRechtePruefen(AudiodetectionActivity.this, AudiodetectionActivity.this)){ | ||||
Toast.makeText(AudiodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AudiodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mMicrofonViewModel.startAlarmRecording(); | |||||
//todo Alarmhandling einfügen | //todo Alarmhandling einfügen | ||||
} else { | } else { | ||||
Toast.makeText(AudiodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AudiodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mMicrofonViewModel.stopAlarmRecording(AudiodetectionActivity.this); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
Toast.makeText(AudiodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AudiodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mMicrofonViewModel.stopAlarmRecording(AudiodetectionActivity.this); | |||||
} | } | ||||
} | } | ||||
}); | }); |
import android.hardware.SensorEventListener; | import android.hardware.SensorEventListener; | ||||
import android.hardware.SensorManager; | import android.hardware.SensorManager; | ||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.view.SurfaceView; | |||||
import android.view.View; | import android.view.View; | ||||
import android.widget.Button; | import android.widget.Button; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import com.example.greenwatch.adapters.DeviceListAdapter; | import com.example.greenwatch.adapters.DeviceListAdapter; | ||||
import com.example.greenwatch.models.Device; | import com.example.greenwatch.models.Device; | ||||
import com.example.greenwatch.viewmodels.AudiodetectionAndAccelerometerViewModel; | import com.example.greenwatch.viewmodels.AudiodetectionAndAccelerometerViewModel; | ||||
import com.example.greenwatch.viewmodels.VideodetectionAndAccelerometerViewModel; | |||||
import java.util.List; | import java.util.List; | ||||
public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity implements SensorEventListener { | public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity implements SensorEventListener { | ||||
private SensorManager accelerometerManager; | private SensorManager accelerometerManager; | ||||
private Sensor accelerometerSensor; | private Sensor accelerometerSensor; | ||||
private SurfaceView surfaceView; | |||||
private TextView audiodetectionAndAccelerometerStatusMessage; | private TextView audiodetectionAndAccelerometerStatusMessage; | ||||
private TextView tvAudiodetectionAndAccelerometerDeviceListRecyclerView; | private TextView tvAudiodetectionAndAccelerometerDeviceListRecyclerView; | ||||
private TextView tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView; | private TextView tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView; | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setContentView(R.layout.activity_audiodetection_and_accelerometer); | setContentView(R.layout.activity_audiodetection_and_accelerometer); | ||||
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewAudiodetectionAndAccelerometer); | |||||
audiodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerStatusmessage); | audiodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerStatusmessage); | ||||
tvAudiodetectionAndAccelerometerDeviceListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerDeviceListRecyclerView); | tvAudiodetectionAndAccelerometerDeviceListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerDeviceListRecyclerView); | ||||
tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView); | tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView = (TextView) findViewById(R.id.tvAudiodetectionAndAccelerometerAlarmHistoryListRecyclerView); | ||||
}); | }); | ||||
mAudiodetectionAndAccelerometerViewModel = new ViewModelProvider(this).get(AudiodetectionAndAccelerometerViewModel.class); | mAudiodetectionAndAccelerometerViewModel = new ViewModelProvider(this).get(AudiodetectionAndAccelerometerViewModel.class); | ||||
mAudiodetectionAndAccelerometerViewModel.init(); | |||||
mAudiodetectionAndAccelerometerViewModel.init(surfaceView.getHolder()); | |||||
mAudiodetectionAndAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | mAudiodetectionAndAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | ||||
@Override | @Override | ||||
public void onChanged(List<Device> devices) { | public void onChanged(List<Device> devices) { | ||||
if (aBoolean) { | if (aBoolean) { | ||||
if(permission.alarmRechtePruefen(AudiodetectionAndAccelerometerActivity.this, AudiodetectionAndAccelerometerActivity.this)){ | if(permission.alarmRechtePruefen(AudiodetectionAndAccelerometerActivity.this, AudiodetectionAndAccelerometerActivity.this)){ | ||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mAudiodetectionAndAccelerometerViewModel.startAlarmRecording(); | |||||
//todo AlarmHandling einfügen | //todo AlarmHandling einfügen | ||||
} else { | } else { | ||||
permission.alarmRechteAnfordern(AudiodetectionAndAccelerometerActivity.this); | permission.alarmRechteAnfordern(AudiodetectionAndAccelerometerActivity.this); | ||||
if(permission.alarmRechtePruefen(AudiodetectionAndAccelerometerActivity.this, AudiodetectionAndAccelerometerActivity.this)){ | if(permission.alarmRechtePruefen(AudiodetectionAndAccelerometerActivity.this, AudiodetectionAndAccelerometerActivity.this)){ | ||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mAudiodetectionAndAccelerometerViewModel.startAlarmRecording(); | |||||
//todo Alarmhandling einfügen | //todo Alarmhandling einfügen | ||||
} else { | } else { | ||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mAudiodetectionAndAccelerometerViewModel.stopAlarmRecording(AudiodetectionAndAccelerometerActivity.this); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mAudiodetectionAndAccelerometerViewModel.stopAlarmRecording(AudiodetectionAndAccelerometerActivity.this); | |||||
} | } | ||||
} | } | ||||
}); | }); |
import android.app.Activity; | import android.app.Activity; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.content.Intent; | import android.content.Intent; | ||||
import android.hardware.SensorManager; | |||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.view.SurfaceView; | |||||
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 android.widget.Toast; | ||||
import com.example.greenwatch.adapters.AlarmHistoryListAdapter; | import com.example.greenwatch.adapters.AlarmHistoryListAdapter; | ||||
import com.example.greenwatch.models.Device; | import com.example.greenwatch.models.Device; | ||||
import com.example.greenwatch.viewmodels.MainActivityViewModel; | import com.example.greenwatch.viewmodels.MainActivityViewModel; | ||||
import java.util.List; | import java.util.List; | ||||
public class MainActivity extends AppCompatActivity { | public class MainActivity extends AppCompatActivity { | ||||
permission.startRechtePruefen(this, this); | permission.startRechtePruefen(this, this); | ||||
mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class); | mMainActivityViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class); | ||||
mMainActivityViewModel.init(); | |||||
mMainActivityViewModel.init(surfaceView.getHolder()); | |||||
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) { | ||||
if (aBoolean) { | if (aBoolean) { | ||||
if(permission.alarmRechtePruefen(context, activity)){ | if(permission.alarmRechtePruefen(context, activity)){ | ||||
Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mMainActivityViewModel.startAlarmRecording(); | |||||
//todo AlarmHandling einfügen | //todo AlarmHandling einfügen | ||||
} else { | } else { | ||||
permission.alarmRechteAnfordern(activity); | permission.alarmRechteAnfordern(activity); | ||||
if(permission.alarmRechtePruefen(context, activity)){ | if(permission.alarmRechtePruefen(context, activity)){ | ||||
Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mMainActivityViewModel.startAlarmRecording(); | |||||
//todo Alarmhandling einfügen | //todo Alarmhandling einfügen | ||||
} else { | } else { | ||||
Toast.makeText(MainActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(MainActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mMainActivityViewModel.stopAlarmRecording(MainActivity.this); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class); | Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class); | ||||
startActivity(intent); | startActivity(intent); | ||||
} | } | ||||
@Override | |||||
protected void onPause() { | |||||
super.onPause(); | |||||
} | |||||
} | } |
import androidx.recyclerview.widget.RecyclerView; | import androidx.recyclerview.widget.RecyclerView; | ||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.view.SurfaceView; | |||||
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 android.widget.Toast; | ||||
import com.example.greenwatch.adapters.AlarmHistoryListAdapter; | import com.example.greenwatch.adapters.AlarmHistoryListAdapter; | ||||
import com.example.greenwatch.adapters.DeviceListAdapter; | import com.example.greenwatch.adapters.DeviceListAdapter; | ||||
import com.example.greenwatch.models.Device; | import com.example.greenwatch.models.Device; | ||||
import com.example.greenwatch.viewmodels.AccelerometerViewModel; | |||||
import com.example.greenwatch.viewmodels.VideodetectionViewModel; | import com.example.greenwatch.viewmodels.VideodetectionViewModel; | ||||
import com.google.common.util.concurrent.ListenableFuture; | import com.google.common.util.concurrent.ListenableFuture; | ||||
}); | }); | ||||
mVideoDetectionViewModel = new ViewModelProvider(this).get(VideodetectionViewModel.class); | mVideoDetectionViewModel = new ViewModelProvider(this).get(VideodetectionViewModel.class); | ||||
mVideoDetectionViewModel.init(); | |||||
mVideoDetectionViewModel.init(surfaceView.getHolder()); | |||||
mVideoDetectionViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | mVideoDetectionViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | ||||
@Override | @Override | ||||
public void onChanged(List<Device> devices) { | public void onChanged(List<Device> devices) { | ||||
if (aBoolean) { | if (aBoolean) { | ||||
if(permission.alarmRechtePruefen(VideodetectionActivity.this, VideodetectionActivity.this)){ | if(permission.alarmRechtePruefen(VideodetectionActivity.this, VideodetectionActivity.this)){ | ||||
Toast.makeText(VideodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(VideodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mVideoDetectionViewModel.startAlarmRecording(); | |||||
//todo AlarmHandling einfügen | //todo AlarmHandling einfügen | ||||
} else { | } else { | ||||
permission.alarmRechteAnfordern(VideodetectionActivity.this); | permission.alarmRechteAnfordern(VideodetectionActivity.this); | ||||
if(permission.alarmRechtePruefen(VideodetectionActivity.this, VideodetectionActivity.this)){ | if(permission.alarmRechtePruefen(VideodetectionActivity.this, VideodetectionActivity.this)){ | ||||
Toast.makeText(VideodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(VideodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mVideoDetectionViewModel.startAlarmRecording(); | |||||
//todo Alarmhandling einfügen | //todo Alarmhandling einfügen | ||||
} else { | } else { | ||||
Toast.makeText(VideodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(VideodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mVideoDetectionViewModel.stopAlarmRecording(VideodetectionActivity.this); | |||||
} | } | ||||
} | } | ||||
} | } |
import android.hardware.SensorEventListener; | import android.hardware.SensorEventListener; | ||||
import android.hardware.SensorManager; | import android.hardware.SensorManager; | ||||
import android.os.Bundle; | import android.os.Bundle; | ||||
import android.view.SurfaceView; | |||||
import android.view.View; | import android.view.View; | ||||
import android.widget.Button; | import android.widget.Button; | ||||
import android.widget.TextView; | import android.widget.TextView; | ||||
public class VideodetectionAndAccelerometerActivity extends AppCompatActivity implements SensorEventListener { | public class VideodetectionAndAccelerometerActivity extends AppCompatActivity implements SensorEventListener { | ||||
private SensorManager accelerometerManager; | private SensorManager accelerometerManager; | ||||
private Sensor accelerometerSensor; | private Sensor accelerometerSensor; | ||||
private SurfaceView surfaceView; | |||||
private TextView videodetectionAndAccelerometerStatusMessage; | private TextView videodetectionAndAccelerometerStatusMessage; | ||||
private TextView videodetectionAndAccelerometerDataTV; | private TextView videodetectionAndAccelerometerDataTV; | ||||
private TextView tvVideodetectionAndAccelerometerDeviceListRecyclerView; | private TextView tvVideodetectionAndAccelerometerDeviceListRecyclerView; | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setContentView(R.layout.activity_videodetection_and_accelerometer); | setContentView(R.layout.activity_videodetection_and_accelerometer); | ||||
surfaceView = (SurfaceView) findViewById(R.id.surfaceViewVideodetectionAndAccelerometer); | |||||
videodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerStatusmessage); | videodetectionAndAccelerometerStatusMessage = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerStatusmessage); | ||||
videodetectionAndAccelerometerDataTV = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerData); | videodetectionAndAccelerometerDataTV = (TextView) findViewById(R.id.tvvideodetectionAndAccelerometerData); | ||||
tvVideodetectionAndAccelerometerDeviceListRecyclerView = (TextView) findViewById(R.id.tvVideodetectionAndAccelerometerDeviceListRecyclerView); | tvVideodetectionAndAccelerometerDeviceListRecyclerView = (TextView) findViewById(R.id.tvVideodetectionAndAccelerometerDeviceListRecyclerView); | ||||
}); | }); | ||||
mVideodetectionAndAccelerometerViewModel = new ViewModelProvider(this).get(VideodetectionAndAccelerometerViewModel.class); | mVideodetectionAndAccelerometerViewModel = new ViewModelProvider(this).get(VideodetectionAndAccelerometerViewModel.class); | ||||
mVideodetectionAndAccelerometerViewModel.init(); | |||||
mVideodetectionAndAccelerometerViewModel.init(surfaceView.getHolder()); | |||||
mVideodetectionAndAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | mVideodetectionAndAccelerometerViewModel.getConnectedDeviceList().observe(this, new Observer<List<Device>>() { | ||||
@Override | @Override | ||||
public void onChanged(List<Device> devices) { | public void onChanged(List<Device> devices) { | ||||
if (aBoolean) { | if (aBoolean) { | ||||
if(permission.alarmRechtePruefen(VideodetectionAndAccelerometerActivity.this, VideodetectionAndAccelerometerActivity.this)){ | if(permission.alarmRechtePruefen(VideodetectionAndAccelerometerActivity.this, VideodetectionAndAccelerometerActivity.this)){ | ||||
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mVideodetectionAndAccelerometerViewModel.startAlarmRecording(); | |||||
//todo AlarmHandling einfügen | //todo AlarmHandling einfügen | ||||
} else { | } else { | ||||
permission.alarmRechteAnfordern(VideodetectionAndAccelerometerActivity.this); | permission.alarmRechteAnfordern(VideodetectionAndAccelerometerActivity.this); | ||||
if(permission.alarmRechtePruefen(VideodetectionAndAccelerometerActivity.this, VideodetectionAndAccelerometerActivity.this)){ | if(permission.alarmRechtePruefen(VideodetectionAndAccelerometerActivity.this, VideodetectionAndAccelerometerActivity.this)){ | ||||
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mVideodetectionAndAccelerometerViewModel.startAlarmRecording(); | |||||
//todo Alarmhandling einfügen | //todo Alarmhandling einfügen | ||||
} else { | } else { | ||||
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mVideodetectionAndAccelerometerViewModel.stopAlarmRecording(VideodetectionAndAccelerometerActivity.this); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | Toast.makeText(VideodetectionAndAccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | ||||
mVideodetectionAndAccelerometerViewModel.stopAlarmRecording(VideodetectionAndAccelerometerActivity.this); | |||||
} | } | ||||
} | } | ||||
}); | }); |
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 AudioRecorder audioRecorderRunnable; | |||||
private VideoRecorder 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(); | |||||
audioRecorderRunnable = new AudioRecorder(); | |||||
videoRecorderRunnable = new VideoRecorder(); | |||||
} | |||||
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 | |||||
setAudioPath(audioPath); | |||||
setVideoPath(videoPath); | |||||
setVideoRecorderPreviewHolder(previewHolder); | |||||
audioThread = new Thread(audioRecorderRunnable); | |||||
videoThread = new Thread(videoRecorderRunnable); | |||||
//Threads starten | |||||
videoThread.start(); | |||||
audioThread.start(); | |||||
} | |||||
public void stopRecording(Context context) { | |||||
try { | |||||
stopAudioRecording(); | |||||
stopVideoRecording(); | |||||
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 | |||||
String externalStorageDirectory = Environment.getExternalStorageDirectory().getAbsolutePath(); | |||||
String dcimDirectory = externalStorageDirectory + "/DCIM"; | |||||
videoPath = dcimDirectory + "/video.mp4"; | |||||
audioPath = dcimDirectory + "/audio.mp3"; | |||||
} | |||||
private void setVideoPath(String videoPath) { | |||||
videoRecorderRunnable.setVideoPath(videoPath); | |||||
} | |||||
private void setVideoRecorderPreviewHolder(SurfaceHolder previewHolder) { | |||||
videoRecorderRunnable.setPreviewHolder(previewHolder); | |||||
} | |||||
private void stopVideoRecording(){ | |||||
videoRecorderRunnable.stopVideoRecording(); | |||||
} | |||||
private void setAudioPath(String audioPath) { | |||||
audioRecorderRunnable.setAudioPath(audioPath); | |||||
} | |||||
private void stopAudioRecording(){ | |||||
audioRecorderRunnable.stopAudioRecording(); | |||||
} | |||||
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(); | |||||
} | |||||
} | |||||
} |
package com.example.greenwatch.alarmrecorder.runnables; | |||||
import android.media.MediaRecorder; | |||||
import android.view.SurfaceHolder; | |||||
import android.widget.Toast; | |||||
import com.example.greenwatch.MainActivity; | |||||
import java.io.IOException; | |||||
public class AudioRecorder implements Runnable { | |||||
private MediaRecorder audioRecorder = null; | |||||
private String audioPath; | |||||
public AudioRecorder() { | |||||
} | |||||
public void setAudioPath(String audioPath) { | |||||
this.audioPath = audioPath; | |||||
} | |||||
public void stopAudioRecording(){ | |||||
if (audioRecorder != null) { | |||||
audioRecorder.stop(); | |||||
audioRecorder.reset(); | |||||
audioRecorder.release(); | |||||
audioRecorder = null; | |||||
} | |||||
} | |||||
@Override | |||||
public void run() { | |||||
audioRecorder = new MediaRecorder(); | |||||
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(); | |||||
} | |||||
} | |||||
} |
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 MediaRecorder videoRecorder; | |||||
private String videoPath; | |||||
private SurfaceHolder previewHolder; | |||||
public VideoRecorder() { | |||||
videoRecorder = new MediaRecorder(); | |||||
} | |||||
public void setPreviewHolder(SurfaceHolder previewHolder) { | |||||
this.previewHolder = previewHolder; | |||||
} | |||||
public void setVideoPath(String audioPath) { | |||||
this.videoPath = audioPath; | |||||
} | |||||
public void stopVideoRecording(){ | |||||
if (videoRecorder != null) { | |||||
videoRecorder.stop(); | |||||
videoRecorder.reset(); | |||||
videoRecorder.release(); | |||||
videoRecorder = null; | |||||
} | |||||
} | |||||
@Override | |||||
public void run() { | |||||
videoRecorder = new MediaRecorder(); | |||||
videoRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); | |||||
videoRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); | |||||
videoRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); | |||||
videoRecorder.setOutputFile(videoPath); | |||||
videoRecorder.setOrientationHint(90); | |||||
videoRecorder.setPreviewDisplay(previewHolder.getSurface()); | |||||
try { | |||||
videoRecorder.prepare(); | |||||
videoRecorder.start(); | |||||
} catch (IOException e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
} |
private final InetAddress address; | private final InetAddress address; | ||||
private final DatagramSocket socket; | private final DatagramSocket socket; | ||||
private final int port; | private final int port; | ||||
private String rxString; | |||||
private volatile String rxString; | |||||
private String sendMessage; | private String sendMessage; | ||||
//private String sendMsg = "default"; | //private String sendMsg = "default"; | ||||
private boolean isNewMessage; | private boolean isNewMessage; | ||||
} | } | ||||
public void setDeviceRepository(DeviceRepository deviceRepository) { | public void setDeviceRepository(DeviceRepository deviceRepository) { | ||||
this.mDeviceRepository = deviceRepository; | |||||
if (mDeviceRepository == null) { | |||||
this.mDeviceRepository = deviceRepository; | |||||
} | |||||
} | |||||
public void setRecievedSting(String rxString) { | |||||
this.rxString = rxString; | |||||
mDeviceRepository.getNewReceivedMessage(this.rxString); | |||||
} | } | ||||
public void setNewMessage(String newMessage, boolean isNewMessage){ | public void setNewMessage(String newMessage, boolean isNewMessage){ | ||||
rxString = new String(packet.getData(), 0, packet.getLength()); | rxString = new String(packet.getData(), 0, packet.getLength()); | ||||
if(!previousRxString.equals(rxString)){ | if(!previousRxString.equals(rxString)){ | ||||
mDeviceRepository.getNewReceivedMessage(rxString); | |||||
setRecievedSting(rxString); | |||||
} | } | ||||
previousRxString = rxString; | previousRxString = rxString; |
} | } | ||||
public void setWiFiCommunication(WiFiCommunication wiFiCommunication) { | public void setWiFiCommunication(WiFiCommunication wiFiCommunication) { | ||||
this.mWiFiCommunication = wiFiCommunication; | |||||
if (mWiFiCommunication == null) { | |||||
this.mWiFiCommunication = wiFiCommunication; | |||||
} | |||||
} | } | ||||
public MutableLiveData<List<Device>> getConnectedDeviceList() { | public MutableLiveData<List<Device>> getConnectedDeviceList() { | ||||
public void getNewReceivedMessage(String newMessage) { | public void getNewReceivedMessage(String newMessage) { | ||||
String[] messageString = messageStringSplitter(newMessage); | String[] messageString = messageStringSplitter(newMessage); | ||||
if(messageString[0]=="1" && messageString.length == 7) { | |||||
if(messageString[0].equals("1") && messageString.length == 7) { | |||||
String timeStamp = messageString[1]; | String timeStamp = messageString[1]; | ||||
String deviceID = messageString[3]; | String deviceID = messageString[3]; | ||||
boolean sensorStatus = convertSensorStatus(messageString[4]); | |||||
boolean sensorStatus = convertRecievedSensorStatus(messageString[4]); | |||||
String sensorType = messageString[5]; | String sensorType = messageString[5]; | ||||
float sensorMassage = Float.valueOf(messageString[6]); | float sensorMassage = Float.valueOf(messageString[6]); | ||||
.append(delimiter) | .append(delimiter) | ||||
.append(device.getDeviceID()) | .append(device.getDeviceID()) | ||||
.append(delimiter) | .append(delimiter) | ||||
.append(device.getSensorStatus()) | |||||
.append(convertSendSensorStatus(device.getSensorStatus())) | |||||
.append(delimiter) | .append(delimiter) | ||||
.append(device.getSensorType()) | .append(device.getSensorType()) | ||||
.append(delimiter) | .append(delimiter) | ||||
return message.split(delimiter); | return message.split(delimiter); | ||||
} | } | ||||
private boolean convertSensorStatus(String status) { | |||||
private boolean convertRecievedSensorStatus(String status) { | |||||
return status.equals(sensorStatusKey); | return status.equals(sensorStatusKey); | ||||
} | } | ||||
private String convertSendSensorStatus(boolean status) { | |||||
if (status){ | |||||
return "An"; | |||||
} | |||||
else { | |||||
return "Aus"; | |||||
} | |||||
} | |||||
private void setAlarmHistoryDeviceList(Device device) { | private void setAlarmHistoryDeviceList(Device device) { | ||||
if (alarmHistoryDeviceList.size() == maxAlarmHistoryListSize) { | if (alarmHistoryDeviceList.size() == maxAlarmHistoryListSize) { | ||||
alarmHistoryDeviceList.remove(alarmHistoryDeviceList.size() -1); | alarmHistoryDeviceList.remove(alarmHistoryDeviceList.size() -1); |
package com.example.greenwatch.viewmodels; | package com.example.greenwatch.viewmodels; | ||||
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; | |||||
import androidx.lifecycle.LiveData; | import androidx.lifecycle.LiveData; | ||||
import androidx.lifecycle.MutableLiveData; | import androidx.lifecycle.MutableLiveData; | ||||
import androidx.lifecycle.ViewModel; | import androidx.lifecycle.ViewModel; | ||||
import com.example.greenwatch.alarmrecorder.AlarmRecorder; | |||||
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 com.example.greenwatch.sensors.AccelerometerSensor; | ||||
private MutableLiveData<List<Device>> mAlarmHistoryList; | private MutableLiveData<List<Device>> mAlarmHistoryList; | ||||
private MutableLiveData<Boolean> mStartAlarmRecording; | private MutableLiveData<Boolean> mStartAlarmRecording; | ||||
private AccelerometerSensor mAccelerometerSensor; | private AccelerometerSensor mAccelerometerSensor; | ||||
private AlarmRecorder mAlarmRecorder; | |||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
@Override | @Override | ||||
public void init() { | |||||
public void init(SurfaceHolder previewHolder) { | |||||
if (mDeviceRepository == null) { | if (mDeviceRepository == null) { | ||||
mDeviceRepository = DeviceRepository.getInstance(); | mDeviceRepository = DeviceRepository.getInstance(); | ||||
} | } | ||||
if (mAccelerometerSensor == null) { | if (mAccelerometerSensor == null) { | ||||
mAccelerometerSensor = AccelerometerSensor.getInstance(); | mAccelerometerSensor = AccelerometerSensor.getInstance(); | ||||
} | } | ||||
if (mAlarmRecorder == null) { | |||||
mAlarmRecorder = AlarmRecorder.getInstance(); | |||||
} | |||||
if (mDeviceList == null) { | if (mDeviceList == null) { | ||||
mDeviceList = mDeviceRepository.getConnectedDeviceList(); | mDeviceList = mDeviceRepository.getConnectedDeviceList(); | ||||
} | } | ||||
if (mAccelerometerAlarmDetected == null) { | if (mAccelerometerAlarmDetected == null) { | ||||
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected(); | mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected(); | ||||
} | } | ||||
setAlarmRecordingPreviewHolder(previewHolder); | |||||
} | } | ||||
public void addValueToGesamtBE(float newValue) { | public void addValueToGesamtBE(float newValue) { | ||||
public String getSystemTimeStamp() { | public String getSystemTimeStamp() { | ||||
return mDeviceRepository.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); | |||||
} | |||||
} | } |
package com.example.greenwatch.viewmodels; | package com.example.greenwatch.viewmodels; | ||||
import android.content.Context; | |||||
import android.view.SurfaceHolder; | |||||
import androidx.lifecycle.LiveData; | import androidx.lifecycle.LiveData; | ||||
import androidx.lifecycle.MutableLiveData; | import androidx.lifecycle.MutableLiveData; | ||||
import androidx.lifecycle.Observer; | import androidx.lifecycle.Observer; | ||||
import androidx.lifecycle.ViewModel; | import androidx.lifecycle.ViewModel; | ||||
import com.example.greenwatch.alarmrecorder.AlarmRecorder; | |||||
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 com.example.greenwatch.sensors.AccelerometerSensor; | ||||
private MutableLiveData<Boolean> mStartAlarmRecording; | private MutableLiveData<Boolean> mStartAlarmRecording; | ||||
private AccelerometerSensor mAccelerometerSensor; | private AccelerometerSensor mAccelerometerSensor; | ||||
private MicrofonSensor mMicrofonSensor; | private MicrofonSensor mMicrofonSensor; | ||||
private AlarmRecorder mAlarmRecorder; | |||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
private boolean microfonAlarmDetected; | private boolean microfonAlarmDetected; | ||||
private boolean accelerometerAlarmDetected; | private boolean accelerometerAlarmDetected; | ||||
private boolean microfondetectionAndAccelerometerAlarmDetected; | private boolean microfondetectionAndAccelerometerAlarmDetected; | ||||
@Override | |||||
public void init() { | 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) { | public void addValueToGesamtBE(float newValue) { | ||||
mAccelerometerAlarmDetected.removeObserver(observer); | mAccelerometerAlarmDetected.removeObserver(observer); | ||||
} | } | ||||
@Override | |||||
public void init(SurfaceHolder previewHolder) { | |||||
if (mDeviceRepository == null) { | |||||
mDeviceRepository = DeviceRepository.getInstance(); | |||||
} | |||||
if (mAccelerometerSensor == null) { | |||||
mAccelerometerSensor = AccelerometerSensor.getInstance(); | |||||
} | |||||
if (mMicrofonSensor == null) { | |||||
mMicrofonSensor = MicrofonSensor.getInstance(); | |||||
} | |||||
if (mAlarmRecorder == null) { | |||||
mAlarmRecorder = AlarmRecorder.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(); | |||||
setAlarmRecordingPreviewHolder(previewHolder); | |||||
} | |||||
@Override | @Override | ||||
public LiveData<List<Device>> getConnectedDeviceList() { | public LiveData<List<Device>> getConnectedDeviceList() { | ||||
return mDeviceList; | return mDeviceList; | ||||
public String getSystemTimeStamp() { | public String getSystemTimeStamp() { | ||||
return mDeviceRepository.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); | |||||
} | |||||
} | } |
import android.app.Activity; | import android.app.Activity; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.content.pm.PackageManager; | import android.content.pm.PackageManager; | ||||
import android.view.SurfaceHolder; | |||||
import androidx.core.app.ActivityCompat; | import androidx.core.app.ActivityCompat; | ||||
import androidx.core.content.ContextCompat; | import androidx.core.content.ContextCompat; | ||||
import androidx.lifecycle.MutableLiveData; | import androidx.lifecycle.MutableLiveData; | ||||
import androidx.lifecycle.ViewModel; | import androidx.lifecycle.ViewModel; | ||||
import com.example.greenwatch.alarmrecorder.AlarmRecorder; | |||||
import com.example.greenwatch.communication.WiFiCommunication; | import com.example.greenwatch.communication.WiFiCommunication; | ||||
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.util.List; | import java.util.List; | ||||
private MutableLiveData<List<Device>> mAlarmHistoryList; | private MutableLiveData<List<Device>> mAlarmHistoryList; | ||||
private MutableLiveData<Boolean> mStartAlarmRecording; | private MutableLiveData<Boolean> mStartAlarmRecording; | ||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
private WiFiCommunication mWiFiCommunication; | |||||
private AlarmRecorder mAlarmRecorder; | |||||
@Override | @Override | ||||
public void init() { | |||||
WiFiCommunication mWiFiCommunication; | |||||
if(mDeviceList != null) { | |||||
return; | |||||
public void init(SurfaceHolder previewHolder) { | |||||
if (mDeviceRepository == null) { | |||||
mDeviceRepository = DeviceRepository.getInstance(); | |||||
} | |||||
if (mWiFiCommunication == null) { | |||||
mWiFiCommunication = WiFiCommunication.getInstance(); | |||||
} | |||||
if (mAlarmRecorder == null) { | |||||
mAlarmRecorder = AlarmRecorder.getInstance(); | |||||
} | |||||
if (mDeviceList == null) { | |||||
mDeviceList = mDeviceRepository.getConnectedDeviceList(); | |||||
} | |||||
if (mAlarmHistoryList == null) { | |||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | |||||
} | |||||
if (mStartAlarmRecording == null) { | |||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording(); | |||||
} | } | ||||
mDeviceRepository = DeviceRepository.getInstance(); | |||||
mWiFiCommunication = WiFiCommunication.getInstance(); | |||||
mDeviceRepository.setWiFiCommunication(mWiFiCommunication); | |||||
mWiFiCommunication.setDeviceRepository(mDeviceRepository); | mWiFiCommunication.setDeviceRepository(mDeviceRepository); | ||||
mDeviceRepository.setWiFiCommunication(mWiFiCommunication); | |||||
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0.0f); | mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0.0f); | ||||
mDeviceRepository.setDeviceID(mDeviceRepository.getLocalDeviceUUID(), WiFiCommunication.getLocalIpAddress()); | mDeviceRepository.setDeviceID(mDeviceRepository.getLocalDeviceUUID(), WiFiCommunication.getLocalIpAddress()); | ||||
mDeviceList = mDeviceRepository.getConnectedDeviceList(); | |||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | |||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording(); | |||||
setAlarmRecordingPreviewHolder(previewHolder); | |||||
mWiFiCommunication = null; | |||||
} | } | ||||
@Override | @Override | ||||
public String getSystemTimeStamp() { | public String getSystemTimeStamp() { | ||||
return mDeviceRepository.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); | |||||
} | |||||
} | } |
package com.example.greenwatch.viewmodels; | package com.example.greenwatch.viewmodels; | ||||
import android.content.Context; | |||||
import android.view.SurfaceHolder; | |||||
import androidx.lifecycle.LiveData; | import androidx.lifecycle.LiveData; | ||||
import androidx.lifecycle.MutableLiveData; | import androidx.lifecycle.MutableLiveData; | ||||
import androidx.lifecycle.ViewModel; | import androidx.lifecycle.ViewModel; | ||||
import com.example.greenwatch.alarmrecorder.AlarmRecorder; | |||||
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 com.example.greenwatch.sensors.MicrofonSensor; | import com.example.greenwatch.sensors.MicrofonSensor; | ||||
import java.util.List; | import java.util.List; | ||||
private MutableLiveData<Boolean> mStartAlarmRecording; | private MutableLiveData<Boolean> mStartAlarmRecording; | ||||
private MicrofonSensor mMicrofonSensor; | private MicrofonSensor mMicrofonSensor; | ||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
private AlarmRecorder mAlarmRecorder; | |||||
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 | @Override | ||||
public void init() { | |||||
public void init(SurfaceHolder previewHolder) { | |||||
if (mDeviceRepository == null) { | if (mDeviceRepository == null) { | ||||
mDeviceRepository = DeviceRepository.getInstance(); | mDeviceRepository = DeviceRepository.getInstance(); | ||||
} | } | ||||
if (mMicrofonSensor == null) { | if (mMicrofonSensor == null) { | ||||
mMicrofonSensor = MicrofonSensor.getInstance(); | mMicrofonSensor = MicrofonSensor.getInstance(); | ||||
} | } | ||||
if (mAlarmRecorder == null) { | |||||
mAlarmRecorder = AlarmRecorder.getInstance(); | |||||
} | |||||
if (mDeviceList == null) { | if (mDeviceList == null) { | ||||
mDeviceList = mDeviceRepository.getConnectedDeviceList(); | mDeviceList = mDeviceRepository.getConnectedDeviceList(); | ||||
} | } | ||||
if (mMicrofonAlarmDetected == null) { | if (mMicrofonAlarmDetected == null) { | ||||
mMicrofonAlarmDetected = mMicrofonSensor.getAccelerometerAlarmDetected(); | 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; | |||||
setAlarmRecordingPreviewHolder(previewHolder); | |||||
} | } | ||||
@Override | @Override | ||||
public String getSystemTimeStamp() { | public String getSystemTimeStamp() { | ||||
return mDeviceRepository.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); | |||||
} | |||||
} | } |
package com.example.greenwatch.viewmodels; | package com.example.greenwatch.viewmodels; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.view.SurfaceHolder; | |||||
import androidx.camera.lifecycle.ProcessCameraProvider; | import androidx.camera.lifecycle.ProcessCameraProvider; | ||||
import androidx.lifecycle.LifecycleOwner; | import androidx.lifecycle.LifecycleOwner; | ||||
import androidx.lifecycle.Observer; | import androidx.lifecycle.Observer; | ||||
import androidx.lifecycle.ViewModel; | import androidx.lifecycle.ViewModel; | ||||
import com.example.greenwatch.alarmrecorder.AlarmRecorder; | |||||
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 com.example.greenwatch.sensors.AccelerometerSensor; | ||||
private AccelerometerSensor mAccelerometerSensor; | private AccelerometerSensor mAccelerometerSensor; | ||||
private CameraSensor mCameraSensor; | private CameraSensor mCameraSensor; | ||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
private AlarmRecorder mAlarmRecorder; | |||||
private boolean videoAlarmDetected; | private boolean videoAlarmDetected; | ||||
private boolean accelerometerAlarmDetected; | private boolean accelerometerAlarmDetected; | ||||
private boolean videodetectionAndAccelerometerAlarmDetected; | private boolean videodetectionAndAccelerometerAlarmDetected; | ||||
@Override | |||||
public void init() { | |||||
if (mDeviceRepository == null) { | |||||
mDeviceRepository = DeviceRepository.getInstance(); | |||||
} | |||||
if (mAccelerometerSensor == null) { | |||||
mAccelerometerSensor = AccelerometerSensor.getInstance(); | |||||
} | |||||
if (mCameraSensor == null) { | |||||
mCameraSensor = CameraSensor.getInstance(); | |||||
} | |||||
if (mDeviceList == null) { | |||||
mDeviceList = mDeviceRepository.getConnectedDeviceList(); | |||||
} | |||||
if (mAlarmHistoryList == null) { | |||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | |||||
} | |||||
if (mStartAlarmRecording == null) { | |||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording(); | |||||
} | |||||
if (mAccelerometerAlarmDetected == null) { | |||||
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected(); | |||||
} | |||||
if (mVideoAlarmDetected == null) { | |||||
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue(); | |||||
} | |||||
videodetectionAndAccelerometerAlarmDetected = false; | |||||
videoAlarmDetected = false; | |||||
accelerometerAlarmDetected = false; | |||||
registerAlarmObserver(); | |||||
} | |||||
public void addValueToGesamtBE(float newValue) { | public void addValueToGesamtBE(float newValue) { | ||||
mAccelerometerSensor.addValueToGesamtBE(newValue); | mAccelerometerSensor.addValueToGesamtBE(newValue); | ||||
} | } | ||||
mAccelerometerAlarmDetected.removeObserver(observer); | mAccelerometerAlarmDetected.removeObserver(observer); | ||||
} | } | ||||
@Override | |||||
public void init(SurfaceHolder previewHolder) { | |||||
if (mDeviceRepository == null) { | |||||
mDeviceRepository = DeviceRepository.getInstance(); | |||||
} | |||||
if (mAccelerometerSensor == null) { | |||||
mAccelerometerSensor = AccelerometerSensor.getInstance(); | |||||
} | |||||
if (mCameraSensor == null) { | |||||
mCameraSensor = CameraSensor.getInstance(); | |||||
} | |||||
if (mAlarmRecorder == null) { | |||||
mAlarmRecorder = AlarmRecorder.getInstance(); | |||||
} | |||||
if (mDeviceList == null) { | |||||
mDeviceList = mDeviceRepository.getConnectedDeviceList(); | |||||
} | |||||
if (mAlarmHistoryList == null) { | |||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | |||||
} | |||||
if (mStartAlarmRecording == null) { | |||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording(); | |||||
} | |||||
if (mAccelerometerAlarmDetected == null) { | |||||
mAccelerometerAlarmDetected = mAccelerometerSensor.getAccelerometerAlarmDetected(); | |||||
} | |||||
if (mVideoAlarmDetected == null) { | |||||
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue(); | |||||
} | |||||
videodetectionAndAccelerometerAlarmDetected = false; | |||||
videoAlarmDetected = false; | |||||
accelerometerAlarmDetected = false; | |||||
registerAlarmObserver(); | |||||
setAlarmRecordingPreviewHolder(previewHolder); | |||||
} | |||||
@Override | @Override | ||||
public LiveData<List<Device>> getConnectedDeviceList() { | public LiveData<List<Device>> getConnectedDeviceList() { | ||||
return mDeviceList; | return mDeviceList; | ||||
public String getSystemTimeStamp() { | public String getSystemTimeStamp() { | ||||
return mDeviceRepository.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); | |||||
} | |||||
} | } |
package com.example.greenwatch.viewmodels; | package com.example.greenwatch.viewmodels; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.view.SurfaceHolder; | |||||
import androidx.camera.lifecycle.ProcessCameraProvider; | import androidx.camera.lifecycle.ProcessCameraProvider; | ||||
import androidx.lifecycle.LifecycleOwner; | import androidx.lifecycle.LifecycleOwner; | ||||
import androidx.lifecycle.MutableLiveData; | import androidx.lifecycle.MutableLiveData; | ||||
import androidx.lifecycle.ViewModel; | import androidx.lifecycle.ViewModel; | ||||
import com.example.greenwatch.alarmrecorder.AlarmRecorder; | |||||
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.CameraSensor; | import com.example.greenwatch.sensors.CameraSensor; | ||||
private MutableLiveData<List<Device>> mAlarmHistoryList; | private MutableLiveData<List<Device>> mAlarmHistoryList; | ||||
private MutableLiveData<Boolean> mStartAlarmRecording; | private MutableLiveData<Boolean> mStartAlarmRecording; | ||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
private AlarmRecorder mAlarmRecorder; | |||||
private CameraSensor mCameraSensor; | private CameraSensor mCameraSensor; | ||||
} | } | ||||
@Override | @Override | ||||
public void init() { | |||||
public void init(SurfaceHolder previewHolder) { | |||||
if (mDeviceRepository == null) { | if (mDeviceRepository == null) { | ||||
mDeviceRepository = DeviceRepository.getInstance(); | mDeviceRepository = DeviceRepository.getInstance(); | ||||
} | } | ||||
if (mCameraSensor == null) { | if (mCameraSensor == null) { | ||||
mCameraSensor = CameraSensor.getInstance(); | mCameraSensor = CameraSensor.getInstance(); | ||||
} | } | ||||
if (mAlarmRecorder == null) { | |||||
mAlarmRecorder = AlarmRecorder.getInstance(); | |||||
} | |||||
if (mDeviceList == null) { | if (mDeviceList == null) { | ||||
mDeviceList = mDeviceRepository.getConnectedDeviceList(); | mDeviceList = mDeviceRepository.getConnectedDeviceList(); | ||||
} | } | ||||
if (mVideoAlarmDetected == null) { | if (mVideoAlarmDetected == null) { | ||||
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue(); | mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue(); | ||||
} | } | ||||
setAlarmRecordingPreviewHolder(previewHolder); | |||||
} | } | ||||
public void bindImageAnalysis(ProcessCameraProvider cameraProvider, LifecycleOwner lifecycleOwner, Context context) { | public void bindImageAnalysis(ProcessCameraProvider cameraProvider, LifecycleOwner lifecycleOwner, Context context) { | ||||
public String getSystemTimeStamp() { | public String getSystemTimeStamp() { | ||||
return mDeviceRepository.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); | |||||
} | |||||
} | } |
package com.example.greenwatch.viewmodels; | package com.example.greenwatch.viewmodels; | ||||
import android.content.Context; | |||||
import android.view.SurfaceHolder; | |||||
import androidx.lifecycle.LiveData; | import androidx.lifecycle.LiveData; | ||||
import com.example.greenwatch.models.Device; | import com.example.greenwatch.models.Device; | ||||
import java.util.List; | import java.util.List; | ||||
public interface ViewModelInterface { | public interface ViewModelInterface { | ||||
void init(); | |||||
void init(SurfaceHolder previewHolder); | |||||
LiveData<List<Device>> getConnectedDeviceList(); | LiveData<List<Device>> getConnectedDeviceList(); | ||||
LiveData<List<Device>> getAlarmHistoryList(); | LiveData<List<Device>> getAlarmHistoryList(); | ||||
LiveData<Boolean> getStartAlarmRecording(); | LiveData<Boolean> getStartAlarmRecording(); | ||||
float getSensorMassage(String deviceID); | float getSensorMassage(String deviceID); | ||||
String getLocalDeviceUUID(); | String getLocalDeviceUUID(); | ||||
String getSystemTimeStamp(); | String getSystemTimeStamp(); | ||||
void startAlarmRecording(); | |||||
void stopAlarmRecording(Context context); | |||||
void setAlarmRecordingPreviewHolder(SurfaceHolder previewHolder); | |||||
} | } |