diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 46327d28de..125d4107ed 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -66,20 +66,6 @@ - - - - - - - - - - - diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 9e47a2f494..001cb41222 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -64,6 +64,7 @@ import info.nightscout.androidaps.plugins.Wear.WearFragment; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.receivers.DataReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver; +import info.nightscout.androidaps.receivers.NSAlarmReceiver; import info.nightscout.utils.NSUpload; import io.fabric.sdk.android.Fabric; @@ -82,6 +83,8 @@ public class MainApp extends Application { private static ArrayList pluginsList = null; private static DataReceiver dataReceiver = new DataReceiver(); + private static NSAlarmReceiver alarmReciever = new NSAlarmReceiver(); + private LocalBroadcastManager lbm; @Override @@ -179,6 +182,15 @@ public class MainApp extends Application { lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_DEVICESTATUS)); lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL)); + //register alarms + lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ALARM)); + lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ANNOUNCEMENT)); + lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_CLEAR_ALARM)); + lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_URGENT_ALARM)); + + + //register ack alarm + } private void startKeepAliveService() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java index 03fe04f8fe..685bf1d7cb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAlarm.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONObject; import org.slf4j.Logger; @@ -11,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -21,14 +23,20 @@ public class BroadcastAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastAlarm.class); public static void handleAlarm(JSONObject alarm, Context context) { - - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("data", alarm.toString()); Intent intent = new Intent(Intents.ACTION_ALARM); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean("nsclient_localbroadcasts", true)) { + bundle = new Bundle(); + bundle.putString("data", alarm.toString()); + intent = new Intent(Intents.ACTION_ALARM); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java index 3f9a43a14a..834b47eb1e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastAnnouncement.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONArray; import org.json.JSONObject; @@ -12,6 +13,7 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -22,14 +24,20 @@ public class BroadcastAnnouncement { private static Logger log = LoggerFactory.getLogger(BroadcastAnnouncement.class); public static void handleAnnouncement(JSONObject announcement, Context context) { - - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("data", announcement.toString()); Intent intent = new Intent(Intents.ACTION_ANNOUNCEMENT); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean("nsclient_localbroadcasts", true)) { + bundle = new Bundle(); + bundle.putString("data", announcement.toString()); + intent = new Intent(Intents.ACTION_ANNOUNCEMENT); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java index 4f2716cf85..bc1b9978e6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastClearAlarm.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONObject; import org.slf4j.Logger; @@ -11,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -21,14 +23,20 @@ public class BroadcastClearAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastClearAlarm.class); public static void handleClearAlarm(JSONObject clearalarm, Context context) { - - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("data", clearalarm.toString()); Intent intent = new Intent(Intents.ACTION_CLEAR_ALARM); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean("nsclient_localbroadcasts", true)) { + bundle = new Bundle(); + bundle.putString("data", clearalarm.toString()); + intent = new Intent(Intents.ACTION_CLEAR_ALARM); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java index 442eb729c0..449fdd1398 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/broadcasts/BroadcastUrgentAlarm.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.os.Bundle; +import android.support.v4.content.LocalBroadcastManager; import org.json.JSONObject; import org.slf4j.Logger; @@ -11,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.util.List; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.Services.Intents; import info.nightscout.utils.SP; @@ -21,14 +23,20 @@ public class BroadcastUrgentAlarm { private static Logger log = LoggerFactory.getLogger(BroadcastUrgentAlarm.class); public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) { - - if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; - Bundle bundle = new Bundle(); bundle.putString("data", urgentalarm.toString()); Intent intent = new Intent(Intents.ACTION_URGENT_ALARM); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); - context.sendBroadcast(intent); + LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent); + + if(SP.getBoolean("nsclient_localbroadcasts", true)) { + bundle = new Bundle(); + bundle.putString("data", urgentalarm.toString()); + intent = new Intent(Intents.ACTION_URGENT_ALARM); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); + context.sendBroadcast(intent); + } } }