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"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.org.openseizuredetector"
android:versionCode="46"
android:versionName="2.6.4"
android:allowBackup="false"
android:versionCode="47"
android:versionName="3.0.0"
>
<!--android:allowBackup="false"-->
<uses-permission android:name="android.permission.INTERNET" />
<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.
*/
private void showNotification(int alarmLevel) {
Log.v(TAG, "showNotification()");
Log.v(TAG, "showNotification() - alarmLevel="+alarmLevel);
int iconId;
String titleStr;
switch (alarmLevel) {
case 0:
iconId = R.drawable.star_of_life_24x24;
titleStr = "OK";
break;
case 1:
iconId = R.drawable.star_of_life_yellow_24x24;
titleStr = "WARNING";
break;
case 2:
iconId = R.drawable.star_of_life_red_24x24;
titleStr = "ALARM";
break;
case -1:
iconId = R.drawable.star_of_life_fault_24x24;
titleStr = "FAULT";
break;
default:
iconId = R.drawable.star_of_life_24x24;
titleStr = "OK";
}
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@@ -407,16 +416,20 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
} else {
smsStr = "SMS Location Alarm Disabled";
}
if (mNotificationBuilder != null) {
mNotification = mNotificationBuilder.setContentIntent(contentIntent)
.setSmallIcon(iconId)
.setColor(0x00ffffff)
.setAutoCancel(false)
.setContentTitle("OpenSeizureDetector:"+mSdDataSourceName + " Data Source")
.setContentTitle(titleStr)
.setContentText(smsStr)
.setOnlyAlertOnce(true)
.build();
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.
@@ -521,6 +534,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
Log.v(TAG, "***FALL*** - Logging to SD Card");
writeAlarmToSD();
logData();
showNotification(2);
} else {
Log.v(TAG, "***FALL***");
}
@@ -553,6 +567,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
}
// Make alarm beep tone
alarmBeep();
showNotification(2);
// Display MainActvity
showMainActivity();
// Send SMS Alarm.
@@ -575,6 +590,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
sdData.alarmPhrase = "FAULT";
writeAlarmToSD();
faultWarningBeep();
showNotification(-1);
} else {
stopFaultTimer();
}
@@ -593,6 +609,7 @@ public class SdServer extends Service implements SdDataReceiver, SdLocationRecei
if (mAudibleFaultWarning) {
faultWarningBeep();
}
showNotification(-1);
}
/* 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;
TextView tv;
ProgressBar pb;
boolean smsAlarmsActive = true;
Log.v(TAG,"serverStatusRunnable()");
SharedPreferences SP = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
smsAlarmsActive = SP.getBoolean("SMSAlarm", false);
// Settings ok
tv = (TextView) findViewById(R.id.textItem1);
pb = (ProgressBar) findViewById(R.id.progressBar1);
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.setBackgroundColor(okColour);
tv.setTextColor(okTextColour);
pb.setIndeterminateDrawable(getResources().getDrawable(R.drawable.start_server));
pb.setProgressDrawable(getResources().getDrawable(R.drawable.start_server));
}
} else {
tv.setText("Problem with App Permissions");
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. "
+ "so I can get in touch if necessary.\nThank you! Graham \ngraham@openseizuredetector.org.uk "
+ "\n\nChanges in this version:"
+ "\n- Upgraded to be compatible with Android Version 8 (a requirement of Google Play Store)"
+ "\n- Added support for an experimental Gramin based seizure detector with Heart Rate alarm "
+ "\n- Upgraded to be compatible with Android Version 9"
+ "\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- 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 ."
);
// 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. "
+ "so I can get in touch if necessary.\nThank you! Graham \ngraham@openseizuredetector.org.uk "
+ "\n\nChanges in this version:"
+ "\n- Upgraded to be compatible with Android Version 8 (a requirement of Google Play Store)"
+ "\n- Added support for an experimental Gramin based seizure detector with Heart Rate alarm "
+ "\n- Upgraded to be compatible with Android Version 9"
+ "\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- 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 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...

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