@Override | @Override | ||||
public void onChanged(List<Device> devices) { | public void onChanged(List<Device> devices) { | ||||
deviceListAdapter.setDevices(devices); | deviceListAdapter.setDevices(devices); | ||||
Toast.makeText(AccelerometerActivity.this, "onChanged", Toast.LENGTH_LONG).show(); | |||||
} | } | ||||
}); | }); | ||||
} | } | ||||
}); | }); | ||||
mAccelerometerViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() { | |||||
@Override | |||||
public void onChanged(Boolean aBoolean) { | |||||
if (aBoolean) { | |||||
Toast.makeText(AccelerometerActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | |||||
} | |||||
else { | |||||
Toast.makeText(AccelerometerActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | |||||
} | |||||
} | |||||
}); | |||||
mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() { | mAccelerometerViewModel.getMovementDetectedValue().observe(this, new Observer<Boolean>() { | ||||
@Override | @Override | ||||
public void onChanged(Boolean aBoolean) { | public void onChanged(Boolean aBoolean) { |
@Override | @Override | ||||
public void onChanged(List<Device> devices) { | public void onChanged(List<Device> devices) { | ||||
deviceListAdapter.setDevices(devices); | deviceListAdapter.setDevices(devices); | ||||
Toast.makeText(MainActivity.this, "onChanged", Toast.LENGTH_LONG).show(); | |||||
} | } | ||||
}); | }); | ||||
} | } | ||||
}); | }); | ||||
mMainActivityViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() { | |||||
@Override | |||||
public void onChanged(Boolean aBoolean) { | |||||
if (aBoolean) { | |||||
Toast.makeText(MainActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | |||||
} | |||||
else { | |||||
Toast.makeText(MainActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | |||||
} | |||||
} | |||||
}); | |||||
audiodetectionButton.setOnClickListener(new View.OnClickListener() { | audiodetectionButton.setOnClickListener(new View.OnClickListener() { | ||||
@Override | @Override | ||||
public void onClick(View v) { | public void onClick(View v) { | ||||
else { | else { | ||||
mMainActivityViewModel.accessRequestCamera(MainActivity.this); | mMainActivityViewModel.accessRequestCamera(MainActivity.this); | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
accelerometerButton.setOnClickListener(new View.OnClickListener() { | accelerometerButton.setOnClickListener(new View.OnClickListener() { |
@Override | @Override | ||||
public void onChanged(List<Device> devices) { | public void onChanged(List<Device> devices) { | ||||
deviceListAdapter.setDevices(devices); | deviceListAdapter.setDevices(devices); | ||||
Toast.makeText(VideodetectionActivity.this, "onChanged", Toast.LENGTH_LONG).show(); | |||||
} | } | ||||
}); | }); | ||||
} | } | ||||
}); | }); | ||||
mVideoDetectionViewModel.getStartAlarmRecording().observe(this, new Observer<Boolean>() { | |||||
@Override | |||||
public void onChanged(Boolean aBoolean) { | |||||
if (aBoolean) { | |||||
Toast.makeText(VideodetectionActivity.this, "Start Alarm Recording", Toast.LENGTH_LONG).show(); | |||||
} | |||||
else { | |||||
Toast.makeText(VideodetectionActivity.this, "Stop Alarm Recording", Toast.LENGTH_LONG).show(); | |||||
} | |||||
} | |||||
}); | |||||
mVideoDetectionViewModel.getVideoAlarmDetectedValue().observe(this, new Observer<Boolean>() { | mVideoDetectionViewModel.getVideoAlarmDetectedValue().observe(this, new Observer<Boolean>() { | ||||
@Override | @Override | ||||
public void onChanged(Boolean aBoolean) { | public void onChanged(Boolean aBoolean) { |
private final int maxAlarmHistoryListSize = 20; | private final int maxAlarmHistoryListSize = 20; | ||||
private final String delimiter = ", "; | private final String delimiter = ", "; | ||||
private final String SensorStatusKey = "An"; | |||||
private final String sensorStatusKey = "An"; | |||||
private String localDeviceUUID; | private String localDeviceUUID; | ||||
private static DeviceRepository deviceRepositoryInstance; | private static DeviceRepository deviceRepositoryInstance; | ||||
private WiFiCommunication mWiFiCommunication; | private WiFiCommunication mWiFiCommunication; | ||||
private boolean startAlarmRecordingValue; | |||||
private MutableLiveData<Boolean> startAlarmRecording = new MutableLiveData<>(); | |||||
private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>(); | private MutableLiveData<List<Device>> deviceList = new MutableLiveData<>(); | ||||
private MutableLiveData<List<Device>> alarmHistoryList = new MutableLiveData<>(); | private MutableLiveData<List<Device>> alarmHistoryList = new MutableLiveData<>(); | ||||
private HashMap<String, Device> connectedDevicesList = new HashMap<>(); | private HashMap<String, Device> connectedDevicesList = new HashMap<>(); | ||||
private DeviceRepository() { | private DeviceRepository() { | ||||
setLocalDeviceUUID(); | setLocalDeviceUUID(); | ||||
startAlarmRecordingValue = false; | |||||
} | } | ||||
public static synchronized DeviceRepository getInstance() { | public static synchronized DeviceRepository getInstance() { | ||||
return alarmHistoryList; | return alarmHistoryList; | ||||
} | } | ||||
public MutableLiveData<Boolean> getStartAlarmRecording() { | |||||
setMutableLiveDataStartAlarmRecording(); | |||||
return startAlarmRecording; | |||||
} | |||||
public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){ | public void createNewDevice(String timeStamp, String deviceID, boolean sensorStatus, String sensorType, int sensorMassage){ | ||||
Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage); | Device newDevice = new Device(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage); | ||||
if (sensorStatus) { | if (sensorStatus) { | ||||
setAlarmHistoryDeviceList(newDevice); | setAlarmHistoryDeviceList(newDevice); | ||||
} | } | ||||
boolean newStartAlarmRecordingValue = checkDeviceStatus(); | |||||
if (startAlarmRecordingValue != newStartAlarmRecordingValue) { | |||||
startAlarmRecordingValue = newStartAlarmRecordingValue; | |||||
setMutableLiveDataStartAlarmRecording(); | |||||
} | |||||
addToConnectedDeviceList(newDevice.getDeviceID(), newDevice); | addToConnectedDeviceList(newDevice.getDeviceID(), newDevice); | ||||
setMutableLiveDataDeviceList(); | setMutableLiveDataDeviceList(); | ||||
} | } | ||||
setAlarmHistoryDeviceList(device); | setAlarmHistoryDeviceList(device); | ||||
} | } | ||||
device.setSensorStatus(sensorStatus); | device.setSensorStatus(sensorStatus); | ||||
boolean newStartAlarmRecordingValue = checkDeviceStatus(); | |||||
if (startAlarmRecordingValue != newStartAlarmRecordingValue) { | |||||
startAlarmRecordingValue = newStartAlarmRecordingValue; | |||||
setMutableLiveDataStartAlarmRecording(); | |||||
} | |||||
addToConnectedDeviceList(checkedDeviceID, device); | addToConnectedDeviceList(checkedDeviceID, device); | ||||
setMutableLiveDataDeviceList(); | setMutableLiveDataDeviceList(); | ||||
} | } | ||||
setAlarmHistoryDeviceList(device); | setAlarmHistoryDeviceList(device); | ||||
} | } | ||||
device.setSensorStatus(sensorStatus); | device.setSensorStatus(sensorStatus); | ||||
boolean newStartAlarmRecordingValue = checkDeviceStatus(); | |||||
if (startAlarmRecordingValue != newStartAlarmRecordingValue) { | |||||
startAlarmRecordingValue = newStartAlarmRecordingValue; | |||||
setMutableLiveDataStartAlarmRecording(); | |||||
} | |||||
addToConnectedDeviceList(checkedDeviceID, device); | addToConnectedDeviceList(checkedDeviceID, device); | ||||
setMutableLiveDataDeviceList(); | setMutableLiveDataDeviceList(); | ||||
alarmHistoryList.setValue(alarmHistoryDeviceList); | alarmHistoryList.setValue(alarmHistoryDeviceList); | ||||
} | } | ||||
private void setMutableLiveDataStartAlarmRecording() { | |||||
startAlarmRecording.setValue(startAlarmRecordingValue); | |||||
} | |||||
private void addToConnectedDeviceList(String key, Device device) { | private void addToConnectedDeviceList(String key, Device device) { | ||||
connectedDevicesList.put(key, device); | connectedDevicesList.put(key, device); | ||||
if (key.equals(checkDeviceID(localDeviceUUID))) { | if (key.equals(checkDeviceID(localDeviceUUID))) { | ||||
} | } | ||||
private boolean convertSensorStatus(String status) { | private boolean convertSensorStatus(String status) { | ||||
return status.equals(SensorStatusKey); | |||||
return status.equals(sensorStatusKey); | |||||
} | } | ||||
private void setAlarmHistoryDeviceList(Device device) { | private void setAlarmHistoryDeviceList(Device device) { | ||||
alarmHistoryDeviceList.add(0, alarmHistoryDevice); | alarmHistoryDeviceList.add(0, alarmHistoryDevice); | ||||
setMutableLiveDataAlarmHistoryList(); | setMutableLiveDataAlarmHistoryList(); | ||||
} | } | ||||
private boolean checkDeviceStatus() { | |||||
for (Device device : connectedDevicesList.values()) { | |||||
if (device.getSensorStatus()) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
} | } |
private MutableLiveData<List<Device>> mDeviceList; | private MutableLiveData<List<Device>> mDeviceList; | ||||
private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>(); | private MutableLiveData<Boolean> mMovementDetected = new MutableLiveData<>(); | ||||
private MutableLiveData<List<Device>> mAlarmHistoryList; | private MutableLiveData<List<Device>> mAlarmHistoryList; | ||||
private MutableLiveData<Boolean> mStartAlarmRecording; | |||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
private ArrayList<Float> Gesamt_be; | private ArrayList<Float> Gesamt_be; | ||||
int arraySize = 500; | int arraySize = 500; | ||||
mDeviceRepository = DeviceRepository.getInstance(); | mDeviceRepository = DeviceRepository.getInstance(); | ||||
mDeviceList = mDeviceRepository.getConnectedDeviceList(); | mDeviceList = mDeviceRepository.getConnectedDeviceList(); | ||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | ||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording(); | |||||
} | } | ||||
initGesamtBE(); | initGesamtBE(); | ||||
mMovementDetected.setValue(false); | mMovementDetected.setValue(false); | ||||
return mAlarmHistoryList; | return mAlarmHistoryList; | ||||
} | } | ||||
@Override | |||||
public LiveData<Boolean> getStartAlarmRecording() { | |||||
return mStartAlarmRecording; | |||||
} | |||||
@Override | @Override | ||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | ||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); | mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); |
private MutableLiveData<List<Device>> mDeviceList; | private MutableLiveData<List<Device>> mDeviceList; | ||||
private MutableLiveData<List<Device>> mAlarmHistoryList; | private MutableLiveData<List<Device>> mAlarmHistoryList; | ||||
private MutableLiveData<Boolean> mStartAlarmRecording; | |||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
private static final int RECHTEANFORDERUNG_KAMERA = 10; | |||||
private static final int RIGHTS_REQUEST_CAMERA = 10; | |||||
@Override | @Override | ||||
public void init() { | public void init() { | ||||
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(); | mDeviceList = mDeviceRepository.getConnectedDeviceList(); | ||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | ||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording(); | |||||
} | } | ||||
public boolean isCameraAccessAllowed(Context context) { | public boolean isCameraAccessAllowed(Context context) { | ||||
} | } | ||||
public void accessRequestCamera(Activity activity) { | public void accessRequestCamera(Activity activity) { | ||||
ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.CAMERA}, RECHTEANFORDERUNG_KAMERA); | |||||
ActivityCompat.requestPermissions(activity, new String[]{android.Manifest.permission.CAMERA}, RIGHTS_REQUEST_CAMERA); | |||||
} | } | ||||
@Override | @Override | ||||
return mAlarmHistoryList; | return mAlarmHistoryList; | ||||
} | } | ||||
@Override | |||||
public LiveData<Boolean> getStartAlarmRecording() { | |||||
return mStartAlarmRecording; | |||||
} | |||||
@Override | @Override | ||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | ||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); | mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); |
private MutableLiveData<List<Device>> mDeviceList; | private MutableLiveData<List<Device>> mDeviceList; | ||||
private MutableLiveData<Boolean> mVideoAlarmDetected; | private MutableLiveData<Boolean> mVideoAlarmDetected; | ||||
private MutableLiveData<List<Device>> mAlarmHistoryList; | private MutableLiveData<List<Device>> mAlarmHistoryList; | ||||
private MutableLiveData<Boolean> mStartAlarmRecording; | |||||
private DeviceRepository mDeviceRepository; | private DeviceRepository mDeviceRepository; | ||||
private CameraSensor mCameraSensor; | private CameraSensor mCameraSensor; | ||||
if (mAlarmHistoryList == null) { | if (mAlarmHistoryList == null) { | ||||
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); | ||||
} | } | ||||
if (mStartAlarmRecording == null) { | |||||
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording(); | |||||
} | |||||
if (mVideoAlarmDetected == null) { | if (mVideoAlarmDetected == null) { | ||||
mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue(); | mVideoAlarmDetected = mCameraSensor.getVideoAlarmDetectedValue(); | ||||
} | } | ||||
return mAlarmHistoryList; | return mAlarmHistoryList; | ||||
} | } | ||||
@Override | |||||
public LiveData<Boolean> getStartAlarmRecording() { | |||||
return mStartAlarmRecording; | |||||
} | |||||
@Override | @Override | ||||
public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | public void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage) { | ||||
mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); | mDeviceRepository.updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage); |
void init(); | void init(); | ||||
LiveData<List<Device>> getConnectedDeviceList(); | LiveData<List<Device>> getConnectedDeviceList(); | ||||
LiveData<List<Device>> getAlarmHistoryList(); | LiveData<List<Device>> getAlarmHistoryList(); | ||||
LiveData<Boolean> getStartAlarmRecording(); | |||||
void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage); | void updateDevice(String deviceID, String timeStamp, boolean sensorStatus, String sensorType, int sensorMassage); | ||||
void setTimeStamp(String deviceID, String timeStamp); | void setTimeStamp(String deviceID, String timeStamp); | ||||
String getTimeStamp(String deviceID); | String getTimeStamp(String deviceID); |