Improved notification title - shows alarm state.

This commit is contained in:
Graham Jones
2019-02-15 19:00:43 +00:00
parent a874e2b83c
commit 9a231298e1
5 changed files with 53 additions and 29 deletions

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.org.openseizuredetector" package="uk.org.openseizuredetector"
android:versionCode="46" android:versionCode="47"
android:versionName="2.6.4" android:versionName="3.0.0"
android:allowBackup="false"
> >
<!--android:allowBackup="false"-->
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

View File

@@ -381,20 +381,29 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
* Show a notification while this service is running. * Show a notification while this service is running.
*/ */
private void showNotification(int alarmLevel) { private void showNotification(int alarmLevel) {
Log.v(TAG, "showNotification()"); Log.v(TAG, "showNotification() - alarmLevel="+alarmLevel);
int iconId; int iconId;
String titleStr;
switch (alarmLevel) { switch (alarmLevel) {
case 0: case 0:
iconId = R.drawable.star_of_life_24x24; iconId = R.drawable.star_of_life_24x24;
titleStr = "OK";
break; break;
case 1: case 1:
iconId = R.drawable.star_of_life_yellow_24x24; iconId = R.drawable.star_of_life_yellow_24x24;
titleStr = "WARNING";
break; break;
case 2: case 2:
iconId = R.drawable.star_of_life_red_24x24; iconId = R.drawable.star_of_life_red_24x24;
titleStr = "ALARM";
break;
case -1:
iconId = R.drawable.star_of_life_fault_24x24;
titleStr = "FAULT";
break; break;
default: default:
iconId = R.drawable.star_of_life_24x24; iconId = R.drawable.star_of_life_24x24;
titleStr = "OK";
} }
Intent i = new Intent(getApplicationContext(), MainActivity.class); Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@@ -407,16 +416,20 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
} else { } else {
smsStr = "SMS Location Alarm Disabled"; smsStr = "SMS Location Alarm Disabled";
} }
if (mNotificationBuilder != null) {
mNotification = mNotificationBuilder.setContentIntent(contentIntent) mNotification = mNotificationBuilder.setContentIntent(contentIntent)
.setSmallIcon(iconId) .setSmallIcon(iconId)
.setColor(0x00ffffff) .setColor(0x00ffffff)
.setAutoCancel(false) .setAutoCancel(false)
.setContentTitle("OpenSeizureDetector:"+mSdDataSourceName + " Data Source") .setContentTitle(titleStr)
.setContentText(smsStr) .setContentText(smsStr)
.setOnlyAlertOnce(true) .setOnlyAlertOnce(true)
.build(); .build();
mNM.notify(NOTIFICATION_ID, mNotification); mNM.notify(NOTIFICATION_ID, mNotification);
} else {
Log.i(TAG, "showNotification() - notification builder is null, so not showing notification.");
}
} }
// Show the main activity on the user's screen. // Show the main activity on the user's screen.
@@ -521,6 +534,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
Log.v(TAG, "***FALL*** - Logging to SD Card"); Log.v(TAG, "***FALL*** - Logging to SD Card");
writeAlarmToSD(); writeAlarmToSD();
logData(); logData();
showNotification(2);
} else { } else {
Log.v(TAG, "***FALL***"); Log.v(TAG, "***FALL***");
} }
@@ -553,6 +567,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
} }
// Make alarm beep tone // Make alarm beep tone
alarmBeep(); alarmBeep();
showNotification(2);
// Display MainActvity // Display MainActvity
showMainActivity(); showMainActivity();
// Send SMS Alarm. // Send SMS Alarm.
@@ -575,6 +590,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
sdData.alarmPhrase = "FAULT"; sdData.alarmPhrase = "FAULT";
writeAlarmToSD(); writeAlarmToSD();
faultWarningBeep(); faultWarningBeep();
showNotification(-1);
} else { } else {
stopFaultTimer(); stopFaultTimer();
} }
@@ -593,6 +609,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
if (mAudibleFaultWarning) { if (mAudibleFaultWarning) {
faultWarningBeep(); faultWarningBeep();
} }
showNotification(-1);
} }
/* from http://stackoverflow.com/questions/12154940/how-to-make-a-beep-in-android */ /* from http://stackoverflow.com/questions/12154940/how-to-make-a-beep-in-android */

View File

@@ -268,18 +268,31 @@ public class StartupActivity extends Activity {
Boolean allOk = true; Boolean allOk = true;
TextView tv; TextView tv;
ProgressBar pb; ProgressBar pb;
boolean smsAlarmsActive = true;
Log.v(TAG,"serverStatusRunnable()"); Log.v(TAG,"serverStatusRunnable()");
SharedPreferences SP = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
smsAlarmsActive = SP.getBoolean("SMSAlarm", false);
// Settings ok // Settings ok
tv = (TextView) findViewById(R.id.textItem1); tv = (TextView) findViewById(R.id.textItem1);
pb = (ProgressBar) findViewById(R.id.progressBar1); pb = (ProgressBar) findViewById(R.id.progressBar1);
if (mUtil.arePermissionsOK()) { if (mUtil.arePermissionsOK()) {
if (smsAlarmsActive && !mUtil.areSMSPermissionsOK()) {
tv.setText("Problem with SMS Permissions");
tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
mUtil.requestSMSPermissions(StartupActivity.this);
} else {
tv.setText("App Permissions OK"); tv.setText("App Permissions OK");
tv.setBackgroundColor(okColour); tv.setBackgroundColor(okColour);
tv.setTextColor(okTextColour); tv.setTextColor(okTextColour);
pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server)); pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server)); pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
}
} else { } else {
tv.setText("Problem with App Permissions"); tv.setText("Problem with App Permissions");
tv.setBackgroundColor(alarmColour); tv.setBackgroundColor(alarmColour);
@@ -488,14 +501,10 @@ public class StartupActivity extends Activity {
+ "http://openseizuredetector.org.uk, or the app Facebook page at https://www.facebook.com/openseizuredetector. " + "http://openseizuredetector.org.uk, or the app Facebook page at https://www.facebook.com/openseizuredetector. "
+ "so I can get in touch if necessary.\nThank you! Graham \ngraham@openseizuredetector.org.uk " + "so I can get in touch if necessary.\nThank you! Graham \ngraham@openseizuredetector.org.uk "
+ "\n\nChanges in this version:" + "\n\nChanges in this version:"
+ "\n- Upgraded to be compatible with Android Version 8 (a requirement of Google Play Store)" + "\n- Upgraded to be compatible with Android Version 9"
+ "\n- Added support for an experimental Gramin based seizure detector with Heart Rate alarm " + "\n- Added support a Garmin based seizure detector with Heart Rate alarm "
+ "\n Fixed problem with app not restarting properly when settings were changed" + "\n Fixed problem with app not restarting properly when settings were changed"
+ "\n- Explicitly asks for SMS permission, and displays warning in notification if SMS alarms are active" + "\n- Explicitly asks for SMS permission, and displays warning in notification if SMS alarms are active"
+ "\n Added FOREGROUND_SERVICE permission, which seems to be necessary for Android V9."
+ "\n Restored support for Android 4.0.x"
+ "\n "
+ "\n PLEASE NOTE - THIS IS A BETA TEST VERSION SO MAY NOT WORK!"
+ "\n ." + "\n ."
); );
// This makes the links display as links, but they do not respond to clicks for some reason... // This makes the links display as links, but they do not respond to clicks for some reason...
@@ -526,14 +535,12 @@ public class StartupActivity extends Activity {
+ "http://openseizuredetector.org.uk, or the app Facebook page at https://www.facebook.com/openseizuredetector. " + "http://openseizuredetector.org.uk, or the app Facebook page at https://www.facebook.com/openseizuredetector. "
+ "so I can get in touch if necessary.\nThank you! Graham \ngraham@openseizuredetector.org.uk " + "so I can get in touch if necessary.\nThank you! Graham \ngraham@openseizuredetector.org.uk "
+ "\n\nChanges in this version:" + "\n\nChanges in this version:"
+ "\n- Upgraded to be compatible with Android Version 8 (a requirement of Google Play Store)" + "\n- Upgraded to be compatible with Android Version 9"
+ "\n- Added support for an experimental Gramin based seizure detector with Heart Rate alarm " + "\n- Added support for a Garmin based seizure detector with Heart Rate alarm "
+ "\n- Fixed problem with app not restarting properly when settings were changed" + "\n- Fixed problem with app not restarting properly when settings were changed"
+ "\n- Explicitly asks for SMS permission, and displays warning in notification if SMS alarms are active" + "\n- Explicitly asks for SMS permission, and displays warning in notification if SMS alarms are active"
+ "\n Added FOREGROUND_SERVICE permission, which seems to be necessary for Android V9."
+ "\n Restored support for Android V4.0.x"
+ "\n " + "\n "
+ "\n PLEASE NOTE - THIS IS A BETA TEST VERSION SO MAY NOT WORK!" + "\n "
+ "\n " + "\n "
); );
// This makes the links display as links, but they do not respond to clicks for some reason... // This makes the links display as links, but they do not respond to clicks for some reason...

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 B

After

Width:  |  Height:  |  Size: 241 B