Added user interface for NDA logging (menu in data log manager)

This commit is contained in:
Graham Jones
2022-10-25 20:21:46 +01:00
parent cc58c0995a
commit b27653dcbb
6 changed files with 178 additions and 32 deletions

View File

@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="uk.org.openseizuredetector"
android:versionCode="113"
android:versionName="4.0.8b">
android:versionName="4.0.8c">
<!-- android:allowBackup="false" -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

View File

@@ -92,8 +92,10 @@ public class LogManager {
static private SQLiteDatabase mOsdDb = null; // SQLite Database for data and log entries.
private RemoteLogTimer mRemoteLogTimer;
private boolean mLogNDA;
private NDATimer mNDATimer;
private long mNDATimerStartTime;
public NDATimer mNDATimer;
private long mNDATimerStartTime; // milliseconds
public double mNDATimeRemaining; // hours
public double mNDALogPeriodHours = 24.0; // hours
private static Context mContext;
private OsdUtil mUtil;
public static WebApiConnection mWac;
@@ -1095,7 +1097,7 @@ public class LogManager {
// We set the timer to timeout after the event duration, so that we record all data
// without a gap.
mNDATimer =
new NDATimer(mEventDuration * 1000, 1000);
new NDATimer(mEventDuration * 1000, 1000, mNDALogPeriodHours);
mNDATimer.start();
// If we do not have a stored start time for NDA logging, set it to current time
@@ -1109,12 +1111,18 @@ public class LogManager {
mNDATimerStartTime = timeNow.toMillis(true);
SharedPreferences.Editor editor = SP.edit();
editor.putLong("NDATimerStartTime", mNDATimerStartTime);
editor.putBoolean("LogNDA", true);
editor.apply();
}
Time timeNow = new Time(Time.getCurrentTimezone());
timeNow.setToNow();
long tNow = timeNow.toMillis(true);
long tDiffMillis = (tNow - mNDATimerStartTime);
mNDATimeRemaining = mNDALogPeriodHours - tDiffMillis / (3600.*1000.);
}
/*
* Cancel the Normal Daily Actity Log timer
*/
@@ -1126,6 +1134,22 @@ public class LogManager {
}
}
public void disableNDATimer() {
SharedPreferences SP = PreferenceManager
.getDefaultSharedPreferences(mContext);
SharedPreferences.Editor editor = SP.edit();
editor.putBoolean("LogNDA", false);
editor.apply();
}
public void enableNDATimer() {
SharedPreferences SP = PreferenceManager
.getDefaultSharedPreferences(mContext);
SharedPreferences.Editor editor = SP.edit();
editor.putBoolean("LogNDA", true);
editor.apply();
}
/*
* Start the timer that will Auto Prune the database
*/
@@ -1246,11 +1270,10 @@ public class LogManager {
* Log Normal Daily Activities periodically.
*/
private class NDATimer extends CountDownTimer {
// FIXME - NDA Log Period hard coded!
private double mNDALogPeriodHours = 24.0;
public NDATimer(long startTime, long interval) {
double mNDALogPeriodHours = 0;
public NDATimer(long startTime, long interval, double logPeriod) {
super(startTime, interval);
mNDALogPeriodHours = logPeriod;
}
@Override
@@ -1262,12 +1285,14 @@ public class LogManager {
public void onFinish() {
Log.d(TAG, "mNDATimer - onFinish - Recording a Normal Daily Activity Event");
createNDAEvent();
// Check if we have been logging NDA events for more than the set limit.
// Check if we have been logging NDA events for more than the set limit. If it has, we disable it
// and set the start time to zero so it is re-set next time NDA logging is enabled.
Time timeNow = new Time(Time.getCurrentTimezone());
timeNow.setToNow();
long tNow = timeNow.toMillis(true);
long tDiffMillis = (tNow - mNDATimerStartTime);
double tDiffHrs = tDiffMillis / (3600.*1000.);
mNDATimeRemaining = mNDALogPeriodHours - tDiffHrs;
if (tDiffHrs >= mNDALogPeriodHours) {
Log.i(TAG, "mNDATimer - onFinish - NDA logging period completed - switching off NDA Logging");
SharedPreferences SP = PreferenceManager

View File

@@ -61,6 +61,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
private Integer mUiTimerPeriodFast = 2000; // 2 seconds - we use fast updating while UI is blank and we are waiting for first data
private Integer mUiTimerPeriodSlow = 60000; // 60 seconds - once data has been received and UI populated we only update once per minute.
private boolean mUpdateSysLog = true;
private Menu mMenu;
//private Integer UI_MODE_LOCAL = 0;
//private Integer UI_MODE_SHARED = 1;
//private Integer mUiMode = UI_MODE_SHARED;
@@ -117,6 +118,9 @@ public class LogManagerControlActivity extends AppCompatActivity {
CheckBox includeWarningsCb =
(CheckBox) findViewById(R.id.include_warnings_cb);
includeWarningsCb.setOnCheckedChangeListener(onIncludeWarningsCb);
CheckBox includeNDACb =
(CheckBox) findViewById(R.id.include_nda_cb);
includeNDACb.setOnCheckedChangeListener(onIncludeNDACb);
ListView lv = (ListView) findViewById(R.id.eventLogListView);
lv.setOnItemClickListener(onEventListClick);
@@ -133,6 +137,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
Log.i(TAG, "onCreateOptionsMenu()");
getMenuInflater().inflate(R.menu.log_manager_activity_menu, menu);
MenuCompat.setGroupDividerEnabled(menu, true);
this.mMenu = menu;
return true;
}
@@ -196,8 +201,10 @@ public class LogManagerControlActivity extends AppCompatActivity {
private void initialiseServiceConnection() {
mLm = mConnection.mSdServer.mLm;
startUiTimer(mUiTimerPeriodFast);
final CheckBox includeWarningsCb = (CheckBox) findViewById(R.id.include_warnings_cb);
getRemoteEvents(includeWarningsCb.isChecked());
final CheckBox includeNDACb = (CheckBox) findViewById(R.id.include_nda_cb);
getRemoteEvents(includeWarningsCb.isChecked(), includeNDACb.isChecked());
ProgressBar pb = (ProgressBar)findViewById(R.id.remoteAccessPb);
pb.setIndeterminate(true);
pb.setVisibility(View.VISIBLE);
@@ -217,7 +224,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
}
private void getRemoteEvents(boolean includeWarnings) {
private void getRemoteEvents(boolean includeWarnings, boolean includeNDA) {
mRemoteEventsList = null; // clear existing data
// Retrieve events from remote database
mLm.mWac.getEvents((JSONObject remoteEventsObj) -> {
@@ -267,10 +274,11 @@ public class LogManagerControlActivity extends AppCompatActivity {
eventHashMap.put("type", typeStr);
eventHashMap.put("subType", subType);
eventHashMap.put("desc", desc);
if (osdAlarmState!=1 | includeWarnings) {
if ((osdAlarmState!=1 | includeWarnings) &&
(osdAlarmState!=6 | includeNDA)) {
mRemoteEventsList.add(eventHashMap);
} else {
Log.v(TAG,"getRemoteEvents - skipping warning");
Log.v(TAG,"getRemoteEvents - skipping warning or NDA record");
}
}
Log.v(TAG, "getRemoteEvents() - set mRemoteEventsList(). Updating UI");
@@ -301,6 +309,9 @@ public class LogManagerControlActivity extends AppCompatActivity {
TextView tv2 = (TextView) findViewById(R.id.num_local_datapoints_tv);
tv2.setText(String.format("%d", datapointsCount));
});
TextView tv3 = (TextView)findViewById(R.id.nda_time_remaining_tv);
tv3.setText(String.format("%.1f hrs",mLm.mNDATimeRemaining));
Log.d(TAG,"mNDATimeRemaining = "+String.format("%.1f hrs",mLm.mNDATimeRemaining));
} else {
stopUpdating = false;
}
@@ -366,6 +377,7 @@ public class LogManagerControlActivity extends AppCompatActivity {
stopUiTimer();
//startUiTimer(mUiTimerPeriodSlow);
}
} //updateUi();
public void onRadioButtonClicked(View view) {
@@ -444,6 +456,55 @@ public class LogManagerControlActivity extends AppCompatActivity {
} catch (Exception ex) {
Log.i(TAG, "exception starting settings activity " + ex.toString());
}
return true;
case R.id.start_stop_nda:
Log.i(TAG,"start/stop NDA");
if (mConnection.mSdServer.mLogNDA) {
new AlertDialog.Builder(this)
.setTitle(R.string.stop_nda_logging_dialog_title)
.setMessage(R.string.stop_nda_logging_dialog_meassage)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
mLm.disableNDATimer();
MenuItem startStopNDAMenuItem = mMenu.findItem(R.id.start_stop_nda);
startStopNDAMenuItem.setTitle(R.string.start_nda_menu_title);
mUtil.stopServer();
// Wait 0.1 second to give the server chance to shutdown, then re-start it
new Handler().postDelayed(new Runnable() {
public void run() {
mUtil.startServer();
}
}, 100);
}
})
.setNegativeButton(android.R.string.no, null)
.show();
} else {
new AlertDialog.Builder(this)
.setTitle(R.string.start_nda_logging_dialog_title)
.setMessage(R.string.start_nda_logging_dialog_meassage)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
mLm.enableNDATimer();
MenuItem startStopNDAMenuItem = mMenu.findItem(R.id.start_stop_nda);
startStopNDAMenuItem.setTitle(R.string.stop_nda_menu_title);
mUtil.stopServer();
// Wait 0.1 second to give the server chance to shutdown, then re-start it
new Handler().postDelayed(new Runnable() {
public void run() {
mUtil.startServer();
}
}, 100);
}
})
.setNegativeButton(android.R.string.no, null)
.show();
}
return true;
case R.id.action_mark_unknown:
Log.i(TAG, "action_mark_unknown");
@@ -542,6 +603,16 @@ public class LogManagerControlActivity extends AppCompatActivity {
}
};
CompoundButton.OnCheckedChangeListener onIncludeNDACb =
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Log.v(TAG, "onIncludeNDACb");
initialiseServiceConnection();
}
};
AdapterView.OnItemClickListener onEventListClick =
new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {

View File

@@ -49,6 +49,25 @@
android:layout_height="wrap_content"
android:text="000" />
</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/NDATimeRemaining" />
<TextView
android:id="@+id/nda_time_remaining_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="000" />
</LinearLayout>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -80,22 +99,23 @@
</RadioGroup>
<LinearLayout
android:visibility="visible"
android:id="@+id/shared_data_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/remote_database"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/check_seizures_message"
/>
android:text="@string/check_seizures_message" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -112,24 +132,36 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/authenticate" />
<Button
android:id="@+id/refresh_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/refreshBtn" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/remoteAccessPb" />
<ProgressBar
android:id="@+id/remoteAccessPb"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<CheckBox
android:id="@+id/include_warnings_cb"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/include_warnings">
</CheckBox>
android:orientation="horizontal">
<CheckBox
android:id="@+id/include_warnings_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/include_warnings"></CheckBox>
<CheckBox
android:id="@+id/include_nda_cb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/include_nda"></CheckBox>
</LinearLayout>
<ListView
android:id="@+id/remoteEventsLv"
@@ -141,11 +173,11 @@
<LinearLayout
android:visibility="gone"
android:id="@+id/local_data_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="fill_parent"
@@ -161,11 +193,11 @@
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/syslog_ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="fill_parent"

View File

@@ -27,5 +27,12 @@
app:showAsAction="never|withText"
android:title="@string/data_sharing_log_in" />
<item
android:id="@+id/start_stop_nda"
android:enabled="true"
android:icon="@drawable/ic_action_settings"
app:showAsAction="never|withText"
android:title="@string/start_nda" />
</group>
</menu>

View File

@@ -312,7 +312,7 @@
<string name="title_activity_authenticate">Log in to OpenSeizureDetector Data Sharing</string>
<string name="logout">Log Out</string>
<string name="logged_in_with_token">Logged in to\nData Sharing</string>
<string name="local_database">Logged Data Manager</string>
<string name="local_database">Data Sharing Manager</string>
<string name="remote_database">Shared Data</string>
<string name="num_local_events">Number of Events Stored on Phone: </string>
<string name="num_local_datapoints">"Number of Datapoints Stored on Phone: "</string>
@@ -441,4 +441,15 @@
<string name="LogNDASummary">Continuously log data to the data sharing system to provide background \'normal daily activity\' data to help reduce false alarms.</string>
<string name="LogNDATitle">Log Normal Daily Activities (NDA)</string>
<string name="NDATimerStartTimeParseError">Error Parsing NDATimerStartTime</string>
<string name="include_nda">Include NDA</string>
<string name="start_nda">Start NDA Logging</string>
<string name="stop_nda">Stop NDA Logging</string>
<string name="stop_nda_logging_dialog_title">Stop NDA Logging?</string>
<string name="stop_nda_logging_dialog_meassage">Stop Normal Daily Activity (NDA) Logging?</string>
<string name="start_nda_logging_dialog_title">Start NDA Logging?</string>
<string name="start_nda_logging_dialog_meassage">Start Normal Daily Activity (NDA) Logging (will stop automatically after 24 hours)?</string>
<string name="NDATimeRemaining">"NDA Logging Time Remaining (hours): "</string>
<string name="stop_nda_menu_title">Stop NDA</string>
<string name="start_nda_menu_title">Start NDA</string>
</resources>