Split preferences into different screens to make them simpler, and enable and disable screens depending on options selected.

This commit is contained in:
Graham Jones
2015-11-17 17:07:13 +00:00
parent f5e5c7e093
commit 16a9207ded
8 changed files with 446 additions and 3 deletions

View File

@@ -24,14 +24,138 @@
*/ */
package uk.org.openseizuredetector; package uk.org.openseizuredetector;
import android.content.SharedPreferences;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import java.util.List;
public class PrefActivity extends PreferenceActivity { public class PrefActivity extends PreferenceActivity {
@Override private String TAG = "PreferenceActivity";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs); @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
} }
/**
* Populate the activity with the top-level headers.
*/
@Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.preference_headers, target);
SharedPreferences SP = PreferenceManager
.getDefaultSharedPreferences(this.getApplicationContext());
String dataSourceStr = SP.getString("DataSource", "pebble");
Log.v(TAG, "onBuildHeaders DataSource = " + dataSourceStr);
Boolean cameraEnabled = SP.getBoolean("UseIpCamera", false);
Log.v(TAG, "onBuildHeaders cameraEnabled = " + cameraEnabled);
for (int i = 0; i < target.size(); i++) {
Header h = target.get(i);
Log.v(TAG,"found - "+h.title.toString());
if (h.title.toString().equals("Pebble Datasource")) {
Log.v(TAG, "found Pebble Datasource Header");
if (!dataSourceStr.equals("pebble")) {
Log.v(TAG, "Removing pebble settings header");
target.remove(i);
i = i-1;
}
}
if (h.title.toString().equals("Network Datasource")) {
Log.v(TAG, "found Network Datasource Header");
if (!dataSourceStr.equals("network")) {
Log.v(TAG, "Removing network settings header");
target.remove(i);
i = i -1;
}
}
if (h.title.toString().equals("Camera Settings")) {
Log.v(TAG, "found Camera Settings Header");
if (!cameraEnabled) {
Log.v(TAG, "Removing camera settings header");
target.remove(i);
i = i-1;
}
}
}
}
@Override
public void onStart() {
super.onStart();
invalidateHeaders();
Log.v(TAG, "onStart()");
}
@Override
public void onResume() {
super.onResume();
Log.v(TAG, "onStart()");
}
/**
* This fragment shows the preferences for the first header.
*/
public static class GeneralPrefsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.general_prefs);
}
}
/**
* This fragment contains a second-level set of preference that you
* can get to by tapping an item in the first preferences fragment.
*/
public static class AlarmPrefsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.alarm_prefs);
}
}
public static class PebbleDatasourcePrefsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.pebble_datasource_prefs);
}
}
public static class NetworkDatasourcePrefsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.network_datasource_prefs);
}
}
public static class CameraPrefsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.camera_prefs);
}
}
} }

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="datasource_list">
<item>"Pebble Watch"</item>
<item>"Network"</item>
</string-array>
<string-array name="datasource_list_values">
<item>"pebble"</item>
<item>"network"</item>
</string-array>
</resources>

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Alarm Functionality Settings">
<CheckBoxPreference
android:defaultValue="false"
android:key="LatchAlarms"
android:summary="Require manual reset of alarms to reset them to silence them."
android:title="Latch Alarms" />
</PreferenceCategory>
<PreferenceCategory android:title="Audible Alarm Settings">
<CheckBoxPreference
android:defaultValue="true"
android:key="AudibleAlarm"
android:summary="Issue an audible alarm if the seizure detector enters an alarm condition."
android:title="Enable Audible Alarm" />
<CheckBoxPreference
android:defaultValue="true"
android:key="AudibleWarning"
android:summary="Issue an audible alarm if the seizure detector enters a warning (pre-alarm) condition."
android:title="Enable Audible Warnings" />
<CheckBoxPreference
android:defaultValue="true"
android:key="AudibleFaultWarning"
android:summary="Issue an audible alarm if the system detects a fault (e.g. can not talk to Pebble)."
android:title="Enable Audible System FaultWarnings" />
</PreferenceCategory>
<PreferenceCategory android:title="SMS Alarm Settings">
<CheckBoxPreference
android:defaultValue="false"
android:key="SMSAlarm"
android:summary="Issue a SMS (Text Message) alarm if the seizure detector enters an alarm condition."
android:title="Enable SMS Alarm" />
<EditTextPreference
android:defaultValue=""
android:key="SMSNumbers"
android:summary="Telephone number(s) to notify by SMS of Alarm (comma separated)."
android:title="SMS Alarm numbers" />
<EditTextPreference
android:defaultValue="**SEIZURE DETECTED**"
android:key="SMSMsg"
android:summary="Message to be Sent by SMS when a Seizure is Detected."
android:title="SMS Message" />
</PreferenceCategory>
<PreferenceCategory android:title="Alarm Logging">
<CheckBoxPreference
android:defaultValue="true"
android:key="LogAlarms"
android:summary="Log Alarm events to SD Card"
android:title="Log Alarm events to SD Card" />
<CheckBoxPreference
android:defaultValue="false"
android:key="LogData"
android:summary="Log Data to SD Card Regularly"
android:title="Log Data to SD Card" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:defaultValue="true"
android:key="UseIpCamera"
android:summary=""
android:title="Use IP Camera to show images" />
<EditTextPreference
android:defaultValue="192.168.1.25"
android:key="CameraIp"
android:summary="IP Address of the IP Camera (e.g. 192.168.1.175)."
android:title="Camera IP Address." />
<EditTextPreference
android:defaultValue="0"
android:key="CameraCmdSet"
android:numeric="integer"
android:summary="Camera Command Set Number (0=mjpeg,1=h264)"
android:title="Camera Command Set Number" />
<EditTextPreference
android:defaultValue="guest"
android:key="CameraUname"
android:summary=""
android:title="Camera User Name" />
<EditTextPreference
android:defaultValue="guest"
android:key="CameraPasswd"
android:summary=""
android:title="Camera User Password" />
<EditTextPreference
android:defaultValue="2000"
android:key="DataUpdatePeriod"
android:numeric="integer"
android:summary="Period between server data requests in miliseconds."
android:title="Data Update Period (ms)" />
<EditTextPreference
android:defaultValue="2000"
android:key="ConnTimeout"
android:numeric="integer"
android:summary=""
android:title="Connection Timeout (ms)" />
<EditTextPreference
android:defaultValue="2000"
android:key="SoTimeout"
android:numeric="integer"
android:summary=""
android:title="So Timeout (ms)" />
</PreferenceScreen>

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:key="DataSource"
android:title="Select Data Source"
android:summary="Select whether to use a Pebble Watch or network connection as the seizure detector data source."
android:entries="@array/datasource_list"
android:entryValues="@array/datasource_list_values"
android:dialogTitle="Select Data Source" />
<CheckBoxPreference
android:defaultValue="true"
android:key="LogAlarms"
android:summary="Log Alarm events to SD Card"
android:title="Log Alarm events to SD Card" />
<CheckBoxPreference
android:defaultValue="false"
android:key="LogData"
android:summary="Log Data to SD Card Regularly"
android:title="Log Data to SD Card" />
<EditTextPreference
android:key="FaultTimerPeriod"
android:title="Fault Timer Duration (sec)"
android:summary="Duration that fault alarms are muted before initiating."
android:numeric="integer"
android:defaultValue="30" />
<CheckBoxPreference
android:defaultValue="false"
android:key="PreventSleep"
android:summary="Prevent the screen from blanking while the application is running."
android:title="Prevent the screen from blanking." />
<EditTextPreference
android:defaultValue="1000"
android:key="UpdatePeriod"
android:summary="Display update period in miliseconds."
android:title="Display Update Period (ms)." />
<CheckBoxPreference
android:defaultValue="true"
android:key="UseIpCamera"
android:summary="Use IP Camera to View Images"
android:title="Enable IP Camera" />
</PreferenceScreen>

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:defaultValue="192.168.1.175"
android:key="ServerIP"
android:summary="IP Address of OpenSeizureDetector Server (e.g. 192.168.1.175)."
android:title="Server IP Address." />
<CheckBoxPreference
android:defaultValue="true"
android:key="UseIpCamera"
android:summary=""
android:title="Use IP Camera to show images" />
<EditTextPreference
android:defaultValue="192.168.1.25"
android:key="CameraIp"
android:summary="IP Address of the IP Camera (e.g. 192.168.1.175)."
android:title="Camera IP Address." />
<EditTextPreference
android:defaultValue="0"
android:key="CameraCmdSet"
android:numeric="integer"
android:summary="Camera Command Set Number (0=mjpeg,1=h264)"
android:title="Camera Command Set Number" />
<EditTextPreference
android:defaultValue="guest"
android:key="CameraUname"
android:summary=""
android:title="Camera User Name" />
<EditTextPreference
android:defaultValue="guest"
android:key="CameraPasswd"
android:summary=""
android:title="Camera User Password" />
<EditTextPreference
android:defaultValue="2000"
android:key="UiUpdatePeriod"
android:numeric="integer"
android:summary="Update period for User Interface in miliseconds."
android:title="UI Update Period (ms)" />
<EditTextPreference
android:defaultValue="2000"
android:key="DataUpdatePeriod"
android:numeric="integer"
android:summary="Period between server data requests in miliseconds."
android:title="Data Update Period (ms)" />
<EditTextPreference
android:defaultValue="2000"
android:key="ConnTimeout"
android:numeric="integer"
android:summary=""
android:title="Connection Timeout (ms)" />
<EditTextPreference
android:defaultValue="2000"
android:key="SoTimeout"
android:numeric="integer"
android:summary=""
android:title="So Timeout (ms)" />
</PreferenceScreen>

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Seizure Detector Settings">
<EditTextPreference
android:defaultValue="5"
android:key="AlarmFreqMin"
android:summary="Minimum Frequency of ROI (Hz) (Default = 5 Hz)"
android:title="AlarmFreqMin (Hz)" />
<EditTextPreference
android:defaultValue="10"
android:key="AlarmFreqMax"
android:summary="Maximum Frequency of ROI (Hz) (Default = 10 Hz)"
android:title="AlarmFreqMax (Hz)" />
<EditTextPreference
android:defaultValue="5"
android:key="WarnTime"
android:summary="Time to wait before initiating warning (Default = 5 sec)"
android:title="WarnTime (sec)" />
<EditTextPreference
android:defaultValue="10"
android:key="AlarmTime"
android:summary="Time to wait before initiating alarm (Default = 10 sec)"
android:title="AlarmTime (sec)" />
<EditTextPreference
android:defaultValue="100"
android:key="AlarmThresh"
android:summary="Alarm Threshold (Default = 100)"
android:title="AlarmThresh" />
<EditTextPreference
android:defaultValue="30"
android:key="AlarmRatioThresh"
android:summary="Alarm Ratio Threshold (Default = 30)"
android:title="AlarmRatioThresh" />
</PreferenceCategory>
<PreferenceCategory android:title="Fall Detector Settings">
<CheckBoxPreference
android:defaultValue="false"
android:key="FallActive"
android:summary=""
android:title="Activate Fall Detection Function" />
<EditTextPreference
android:defaultValue="200"
android:key="FallThreshMin"
android:summary=""
android:title="Fall Detection Lower Threshold (milli-g)" />
<EditTextPreference
android:defaultValue="1200"
android:key="FallThreshMax"
android:summary=""
android:title="Fall Detection Upper Threshold (milli-g)" />
<EditTextPreference
android:defaultValue="1500"
android:key="FallWindow"
android:summary=""
android:title="Fall Detection Window (milli-seconds)" />
</PreferenceCategory>
<PreferenceCategory
android:title="Watch Communications Settings">
<EditTextPreference
android:defaultValue="10"
android:key="AppRestartTimeout"
android:numeric="integer"
android:summary="Period (seconds) that we wait for data from the watch before assuming the watch app is not running and re-starting it."
android:title="Period (sec) we wait for data before restarting watch app." />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<preference-headers
xmlns:android="http://schemas.android.com/apk/res/android">
<header android:fragment="uk.org.openseizuredetector.PrefActivity$GeneralPrefsFragment"
android:icon="@drawable/icon_24x24"
android:title="General"
android:summary="General Preferences" />
<header android:fragment="uk.org.openseizuredetector.PrefActivity$AlarmPrefsFragment"
android:icon="@drawable/icon_24x24"
android:title="Alarms"
android:summary="Alarms Preferences" />
<header android:fragment="uk.org.openseizuredetector.PrefActivity$PebbleDatasourcePrefsFragment"
android:icon="@drawable/icon_24x24"
android:title="Pebble Datasource"
android:summary="Pebble Datasource Preferences" />
<header android:fragment="uk.org.openseizuredetector.PrefActivity$NetworkDatasourcePrefsFragment"
android:icon="@drawable/icon_24x24"
android:title="Network Datasource"
android:summary="Network Datasource Preferences" />
<header android:fragment="uk.org.openseizuredetector.PrefActivity$CameraPrefsFragment"
android:icon="@drawable/icon_24x24"
android:title="Camera Settings"
android:summary="IP Camera Preferences" />
</preference-headers>