Add pref to raise urgent alarms as system notifications.
This commit is contained in:
parent
bdc61765ce
commit
d423c8ae2a
|
@ -18,6 +18,7 @@ public class Constants {
|
|||
public static final Integer carbsOnlyForCheckLimit = 10101010;
|
||||
|
||||
public static final Integer notificationID = 556677;
|
||||
public static final Integer urgentAlarmNotificationID = 556678;
|
||||
|
||||
public static final int hoursToKeepInDatabase = 72;
|
||||
public static final int daysToKeepHistoryInDatabase = 30;
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.Overview;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -8,14 +13,14 @@ import org.slf4j.LoggerFactory;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.Services.AlarmSoundService;
|
||||
import info.nightscout.androidaps.plugins.Wear.WearPlugin;
|
||||
//Added by Rumen for snooze time
|
||||
//Added by Rumen for snooze time
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
/**
|
||||
|
@ -49,11 +54,16 @@ public class NotificationStore {
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (n.soundId != null) {
|
||||
|
||||
if (SP.getBoolean("raise_urgent_alarms_as_android_notification", false)
|
||||
&& n.level == Notification.URGENT) {
|
||||
raiseSystemNotification(n);
|
||||
} else if (n.soundId != null) {
|
||||
Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
|
||||
alarm.putExtra("soundid", n.soundId);
|
||||
MainApp.instance().startService(alarm);
|
||||
}
|
||||
|
||||
store.add(n);
|
||||
|
||||
WearPlugin wearPlugin = MainApp.getSpecificPlugin(WearPlugin.class);
|
||||
|
@ -64,6 +74,20 @@ public class NotificationStore {
|
|||
Collections.sort(store, new NotificationComparator());
|
||||
}
|
||||
|
||||
private void raiseSystemNotification(Notification n) {
|
||||
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationCompat.Builder notificationBuilder =
|
||||
new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.notif_icon)
|
||||
.setContentTitle("Urgent alarm")
|
||||
.setContentText(n.text)
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
.setSound(uri);
|
||||
mgr.notify(Constants.urgentAlarmNotificationID, notificationBuilder.build());
|
||||
}
|
||||
|
||||
public boolean remove(int id) {
|
||||
for (int i = 0; i < store.size(); i++) {
|
||||
if (get(i).id == id) {
|
||||
|
|
|
@ -777,5 +777,6 @@
|
|||
<string name="combo_action_idle">Idle</string>
|
||||
<string name="pump_unreachable">Pump unreachable</string>
|
||||
<string name="missed_bg_readings">Missed BG readings</string>
|
||||
<string name="raise_urgent_alarms_as_android_notification">Use system notifications for alerts</string>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -71,5 +71,9 @@
|
|||
android:defaultValue="false"
|
||||
android:key="short_tabtitles"
|
||||
android:title="@string/short_tabtitles"/>
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="raise_urgent_alarms_as_android_notification"
|
||||
android:title="@string/raise_urgent_alarms_as_android_notification"/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
|
Loading…
Reference in a new issue