Added 'Report Seizure' activity. UI seems to work, but database part that looks for the closest datapoint is not working.
This commit is contained in:
@@ -66,6 +66,7 @@
|
|||||||
|
|
||||||
<activity android:name=".LogManagerControlActivity" />
|
<activity android:name=".LogManagerControlActivity" />
|
||||||
<activity android:name=".RemoteDbActivity" />
|
<activity android:name=".RemoteDbActivity" />
|
||||||
|
<activity android:name=".ReportSeizureActivity" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".BootBroadcastReceiver"
|
android:name=".BootBroadcastReceiver"
|
||||||
|
|||||||
@@ -330,6 +330,8 @@ public class LogManager implements AuthCallbackInterface, EventCallbackInterface
|
|||||||
statusListStr = "2,3,5"; // Alarm, Fall, Manual Alarm
|
statusListStr = "2,3,5"; // Alarm, Fall, Manual Alarm
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
//FIXME: We need to exclude very recent records from this, otherwise the system might upload
|
||||||
|
// a seizure while it is still occurring and we will miss out on the post-seizure date.
|
||||||
SQLStr = "SELECT * from "+ mDbTableName + " where uploaded=false and Status in ("+statusListStr+");";
|
SQLStr = "SELECT * from "+ mDbTableName + " where uploaded=false and Status in ("+statusListStr+");";
|
||||||
Cursor resultSet = mOSDDb.getWritableDatabase().rawQuery(SQLStr,null);
|
Cursor resultSet = mOSDDb.getWritableDatabase().rawQuery(SQLStr,null);
|
||||||
resultSet.moveToFirst();
|
resultSet.moveToFirst();
|
||||||
@@ -350,6 +352,42 @@ public class LogManager implements AuthCallbackInterface, EventCallbackInterface
|
|||||||
return (recordId);
|
return (recordId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ID of the datapoint that is closest to date/time string dateStr
|
||||||
|
* Based on https://stackoverflow.com/questions/45749046/sql-get-nearest-date-record
|
||||||
|
*/
|
||||||
|
public int getNearestDatapointToDate(String dateStr) {
|
||||||
|
Log.v(TAG, "getNearestDatapointToDate()");
|
||||||
|
String SQLStr = "SQLStr";
|
||||||
|
String recordStr;
|
||||||
|
int recordId;
|
||||||
|
|
||||||
|
try {
|
||||||
|
SQLStr = "SELECT *, (dataTime-date('"+dateStr+"')) as ddiff from "+ mDbTableName + " order by ABS(ddiff) desc;";
|
||||||
|
SQLStr = "SELECT * from "+ mDbTableName + " ;";
|
||||||
|
Cursor resultSet = mOSDDb.getWritableDatabase().rawQuery(SQLStr,null);
|
||||||
|
resultSet.moveToFirst();
|
||||||
|
if (resultSet.getCount() == 0) {
|
||||||
|
Log.v(TAG,"getNearestDatapointToDate() - no datapoints found - exiting");
|
||||||
|
recordId = -1;
|
||||||
|
} else {
|
||||||
|
recordId = resultSet.getInt(0);
|
||||||
|
resultSet.moveToFirst();
|
||||||
|
recordStr = cursor2Json(resultSet); //getDatapointById(recordId);
|
||||||
|
Log.d(TAG, "getNearestDatapointToDate(): id=" + recordId + ", count="+resultSet.getCount()+", recordStr=" + recordStr);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Log.e(TAG,"getNearestDatapointToDate(): Error selecting Data: " + e.toString());
|
||||||
|
Log.e(TAG,"SQLStr was "+SQLStr);
|
||||||
|
recordStr = "ERROR";
|
||||||
|
recordId = -1;
|
||||||
|
}
|
||||||
|
return (recordId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the number of events stored in the local database
|
* Return the number of events stored in the local database
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -294,6 +294,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
Log.i(TAG, "exception starting log manager activity " + ex.toString());
|
Log.i(TAG, "exception starting log manager activity " + ex.toString());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.action_report_seizure:
|
||||||
|
Log.i(TAG, "action_report_seizure");
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent(
|
||||||
|
MainActivity.this,
|
||||||
|
ReportSeizureActivity.class);
|
||||||
|
this.startActivity(intent);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Log.i(TAG, "exception starting Report Seizure activity " + ex.toString());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
case R.id.action_settings:
|
case R.id.action_settings:
|
||||||
Log.i(TAG, "action_settings");
|
Log.i(TAG, "action_settings");
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,217 @@
|
|||||||
|
package uk.org.openseizuredetector;
|
||||||
|
|
||||||
|
//import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.app.DatePickerDialog;
|
||||||
|
import android.app.TimePickerDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.CountDownTimer;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.webkit.WebSettings;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.DatePicker;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.TimePicker;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ReportSeizureActivity - Allows the user to report a seizure manually, which is saved in the database for
|
||||||
|
* future analysis - particularlly useful if OpenSeizureDetector did not detect the seizure automatically as this
|
||||||
|
* will ensure the data for the missed seizure is saved.
|
||||||
|
* Based on: https://www.journaldev.com/9976/android-date-time-picker-dialog
|
||||||
|
*/
|
||||||
|
public class ReportSeizureActivity extends AppCompatActivity {
|
||||||
|
private String TAG = "ReportSeizureActivity";
|
||||||
|
private Context mContext;
|
||||||
|
private UiTimer mUiTimer;
|
||||||
|
private LogManager mLm;
|
||||||
|
private int mYear, mMonth, mDay, mHour, mMinute;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
Log.v(TAG, "onCreate()");
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
mContext = this;
|
||||||
|
setContentView(R.layout.activity_report_seizure);
|
||||||
|
mLm= new LogManager(mContext);
|
||||||
|
|
||||||
|
Button okBtn =
|
||||||
|
(Button) findViewById(R.id.OKBtn);
|
||||||
|
okBtn.setOnClickListener(onOk);
|
||||||
|
|
||||||
|
Button cancelBtn =
|
||||||
|
(Button) findViewById(R.id.cancelBtn);
|
||||||
|
cancelBtn.setOnClickListener(onCancel);
|
||||||
|
|
||||||
|
Button setDateBtn =
|
||||||
|
(Button) findViewById(R.id.select_date_button);
|
||||||
|
setDateBtn.setOnClickListener(onSelectDate);
|
||||||
|
|
||||||
|
Button setTimeBtn =
|
||||||
|
(Button) findViewById(R.id.select_time_button);
|
||||||
|
setTimeBtn.setOnClickListener(onSelectTime);
|
||||||
|
|
||||||
|
// Get Current Date
|
||||||
|
final Calendar c = Calendar.getInstance();
|
||||||
|
mYear = c.get(Calendar.YEAR);
|
||||||
|
mMonth = c.get(Calendar.MONTH);
|
||||||
|
mDay = c.get(Calendar.DAY_OF_MONTH);
|
||||||
|
mHour = c.get(Calendar.HOUR_OF_DAY);
|
||||||
|
mMinute = c.get(Calendar.MINUTE);
|
||||||
|
|
||||||
|
|
||||||
|
updateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
//startUiTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
stopUiTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
startUiTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateUi() {
|
||||||
|
Log.v(TAG,"updateUi()");
|
||||||
|
TextView tv;
|
||||||
|
Button btn;
|
||||||
|
|
||||||
|
tv = (TextView)findViewById(R.id.date_day_tv);
|
||||||
|
tv.setText(String.format("%02d",mDay));
|
||||||
|
tv = (TextView)findViewById(R.id.date_mon_tv);
|
||||||
|
tv.setText(String.format("%02d",mMonth+1)); // Month counted from zero
|
||||||
|
tv = (TextView)findViewById(R.id.date_year_tv);
|
||||||
|
tv.setText(String.format("%04d",mYear));
|
||||||
|
tv = (TextView)findViewById(R.id.time_hh_tv);
|
||||||
|
tv.setText(String.format("%02d",mHour));
|
||||||
|
tv = (TextView)findViewById(R.id.time_mm_tv);
|
||||||
|
tv.setText(String.format("%02d",mMinute));
|
||||||
|
}
|
||||||
|
|
||||||
|
View.OnClickListener onOk =
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Log.v(TAG, "onOk");
|
||||||
|
String dateStr=String.format("%4d-%02d-%02d %02d:%02d:30",mYear,mMonth+1,mDay, mHour, mMinute);
|
||||||
|
Log.v(TAG, "onOk() - dateSTr="+dateStr);
|
||||||
|
int id = mLm.getNearestDatapointToDate(dateStr);
|
||||||
|
Log.v(TAG, "onOK() - nearest datapoint is "+id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
View.OnClickListener onCancel =
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Log.v(TAG, "onCancel");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
View.OnClickListener onSelectDate =
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Log.v(TAG, "onSelectDate()");
|
||||||
|
DatePickerDialog datePickerDialog = new DatePickerDialog(mContext,
|
||||||
|
new DatePickerDialog.OnDateSetListener() {
|
||||||
|
@Override
|
||||||
|
public void onDateSet(DatePicker view, int year,
|
||||||
|
int monthOfYear, int dayOfMonth) {
|
||||||
|
|
||||||
|
mYear = year;
|
||||||
|
mMonth = monthOfYear;
|
||||||
|
mDay = dayOfMonth;
|
||||||
|
}
|
||||||
|
}, mYear, mMonth, mDay);
|
||||||
|
datePickerDialog.show();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
View.OnClickListener onSelectTime =
|
||||||
|
new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
Log.v(TAG, "onSelectTime()");
|
||||||
|
TimePickerDialog timePickerDialog = new TimePickerDialog(mContext,
|
||||||
|
new TimePickerDialog.OnTimeSetListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTimeSet(TimePicker view, int hourOfDay,
|
||||||
|
int minute) {
|
||||||
|
|
||||||
|
mHour = hourOfDay;
|
||||||
|
mMinute = minute;
|
||||||
|
}
|
||||||
|
}, mHour, mMinute, true);
|
||||||
|
timePickerDialog.show();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Start the timer that will upload data to the remote server after a given period.
|
||||||
|
*/
|
||||||
|
private void startUiTimer() {
|
||||||
|
if (mUiTimer != null) {
|
||||||
|
Log.v(TAG, "startUiTimer -timer already running - cancelling it");
|
||||||
|
mUiTimer.cancel();
|
||||||
|
mUiTimer = null;
|
||||||
|
}
|
||||||
|
Log.v(TAG, "startUiTimer() - starting UiTimer");
|
||||||
|
mUiTimer =
|
||||||
|
new UiTimer(1000, 1000);
|
||||||
|
mUiTimer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cancel the remote logging timer to prevent attempts to upload to remote database.
|
||||||
|
*/
|
||||||
|
public void stopUiTimer() {
|
||||||
|
if (mUiTimer != null) {
|
||||||
|
Log.v(TAG, "stopUiTimer(): cancelling Ui timer");
|
||||||
|
mUiTimer.cancel();
|
||||||
|
mUiTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update User Interface Periodically
|
||||||
|
*/
|
||||||
|
private class UiTimer extends CountDownTimer {
|
||||||
|
public UiTimer(long startTime, long interval) {
|
||||||
|
super(startTime, interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTick(long l) {
|
||||||
|
// Do Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
Log.v(TAG, "UiTimer - onFinish - Updating UI");
|
||||||
|
updateUi();
|
||||||
|
// Restart this timer.
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
109
app/src/main/res/layout/activity_report_seizure.xml
Normal file
109
app/src/main/res/layout/activity_report_seizure.xml
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||||
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
|
tools:context="uk.org.openseizuredetector.LogManager">
|
||||||
|
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/report_seizure"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/date" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="dd"
|
||||||
|
android:id="@+id/date_day_tv"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="/"
|
||||||
|
android:enabled = "false"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="mm"
|
||||||
|
android:id="@+id/date_mon_tv"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="/"
|
||||||
|
android:enabled = "false"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="yyyy"
|
||||||
|
android:id="@+id/date_year_tv"/>
|
||||||
|
<Button
|
||||||
|
android:id="@+id/select_date_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/select_date" />
|
||||||
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/time" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="hh"
|
||||||
|
android:id="@+id/time_hh_tv"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text=":"
|
||||||
|
android:enabled = "false"/>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="mm"
|
||||||
|
android:id="@+id/time_mm_tv"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/select_time_button"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/select_time" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<Button
|
||||||
|
android:id="@+id/OKBtn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/okBtnTxt" />
|
||||||
|
<Button
|
||||||
|
android:id="@+id/cancelBtn"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/cancelBtnTxt" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
@@ -53,6 +53,14 @@
|
|||||||
android:showAsAction="never|withText"
|
android:showAsAction="never|withText"
|
||||||
android:title="@string/test_phone_alarm_notification" />
|
android:title="@string/test_phone_alarm_notification" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:enabled="true"
|
||||||
|
android:id="@+id/action_report_seizure"
|
||||||
|
android:icon="@drawable/ic_action_settings"
|
||||||
|
android:showAsAction="never|withText"
|
||||||
|
android:title="@string/report_seizure"
|
||||||
|
/>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:id="@+id/action_logmanager"
|
android:id="@+id/action_logmanager"
|
||||||
|
|||||||
@@ -299,4 +299,10 @@
|
|||||||
<string name="num_local_events">Number of Stored Events: </string>
|
<string name="num_local_events">Number of Stored Events: </string>
|
||||||
<string name="num_local_datapoints">"Number of Stored Datapoints: "</string>
|
<string name="num_local_datapoints">"Number of Stored Datapoints: "</string>
|
||||||
<string name="view_remote_db_btn">View Remote DB Data</string>
|
<string name="view_remote_db_btn">View Remote DB Data</string>
|
||||||
|
<string name="report_seizure">Report Seizure</string>
|
||||||
|
<string name="date">"Date: "</string>
|
||||||
|
<string name="select_date">Select Date</string>
|
||||||
|
<string name="time">"Time: "</string>
|
||||||
|
<string name="cancelBtnTxt">Cancel</string>
|
||||||
|
<string name="select_time">Select Time</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user