nsclient alarms local
This commit is contained in:
parent
a4864c3d06
commit
d60321b4d1
6 changed files with 60 additions and 30 deletions
|
@ -66,20 +66,6 @@
|
|||
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<receiver
|
||||
android:name=".receivers.NSAlarmReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<!-- Receiver from NSClient -->
|
||||
<action android:name="info.nightscout.client.ANNOUNCEMENT" />
|
||||
<action android:name="info.nightscout.client.ALARM" />
|
||||
<action android:name="info.nightscout.client.URGENT_ALARM" />
|
||||
<action android:name="info.nightscout.client.CLEAR_ALARM" />
|
||||
</intent-filter>
|
||||
|
||||
</receiver>
|
||||
|
||||
<!-- Receiver keepalive, scheduled every 30 min -->
|
||||
<receiver android:name=".receivers.KeepAliveReceiver" />
|
||||
|
||||
|
|
|
@ -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<PluginBase> 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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue