Merge branch '1_5f' into 'stable'

1 5f - again with target stable

See merge request !10
This commit is contained in:
Johannes Mockenhaupt 2017-07-30 10:04:12 +00:00
commit 127fbc993e
25 changed files with 363 additions and 107 deletions

View file

@ -44,7 +44,7 @@ android {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 23 targetSdkVersion 23
versionCode 1500 versionCode 1500
version "1.5e" version "1.5f"
buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", generateGitBuild() buildConfigField "String", "BUILDVERSION", generateGitBuild()
} }

View file

@ -56,16 +56,6 @@
android:enabled="true" android:enabled="true"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<!-- Receiver from NSClient -->
<action android:name="info.nightscout.client.NEW_SGV" />
<action android:name="info.nightscout.client.NEW_TREATMENT" />
<action android:name="info.nightscout.client.CHANGED_TREATMENT" />
<action android:name="info.nightscout.client.REMOVED_TREATMENT" />
<action android:name="info.nightscout.client.NEW_PROFILE" />
<action android:name="info.nightscout.client.NEW_STATUS" />
<action android:name="info.nightscout.client.NEW_MBG" />
<action android:name="info.nightscout.client.NEW_DEVICESTATUS" />
<action android:name="info.nightscout.client.NEW_CAL" />
<!-- Receive new SMS messages --> <!-- Receive new SMS messages -->
<action android:name="android.provider.Telephony.SMS_RECEIVED" /> <action android:name="android.provider.Telephony.SMS_RECEIVED" />
<!-- Receiver from xDrip --> <!-- Receiver from xDrip -->
@ -76,20 +66,6 @@
<action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" /> <action android:name="it.ct.glicemia.ACTION_GLUCOSE_MEASURED" />
</intent-filter> </intent-filter>
</receiver> </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 keepalive, scheduled every 30 min -->
<receiver android:name=".receivers.KeepAliveReceiver" /> <receiver android:name=".receivers.KeepAliveReceiver" />
@ -120,14 +96,6 @@
<action android:name="info.nightscout.client.DBACCESS" /> <action android:name="info.nightscout.client.DBACCESS" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver
android:name=".plugins.NSClientInternal.receivers.AckAlarmReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="info.nightscout.client.ACK_ALARM" />
</intent-filter>
</receiver>
<!-- Service processing incomming data --> <!-- Service processing incomming data -->
<service <service

View file

@ -2,8 +2,10 @@ package info.nightscout.androidaps;
import android.app.Application; import android.app.Application;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources; import android.content.res.Resources;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import com.crashlytics.android.Crashlytics; import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.answers.Answers; import com.crashlytics.android.answers.Answers;
@ -17,6 +19,7 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.InsulinInterface; import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
@ -32,6 +35,7 @@ import info.nightscout.androidaps.plugins.InsulinFastactingProlonged.InsulinFast
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.LoopFragment; import info.nightscout.androidaps.plugins.Loop.LoopFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.receivers.AckAlarmReceiver;
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAFragment; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment; import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment;
import info.nightscout.androidaps.plugins.Overview.OverviewFragment; import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
@ -60,7 +64,9 @@ import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment; import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.androidaps.plugins.Wear.WearFragment; import info.nightscout.androidaps.plugins.Wear.WearFragment;
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
import info.nightscout.androidaps.receivers.DataReceiver;
import info.nightscout.androidaps.receivers.KeepAliveReceiver; import info.nightscout.androidaps.receivers.KeepAliveReceiver;
import info.nightscout.androidaps.receivers.NSAlarmReceiver;
import info.nightscout.utils.NSUpload; import info.nightscout.utils.NSUpload;
import io.fabric.sdk.android.Fabric; import io.fabric.sdk.android.Fabric;
@ -78,6 +84,11 @@ public class MainApp extends Application {
private static ArrayList<PluginBase> pluginsList = null; private static ArrayList<PluginBase> pluginsList = null;
private static DataReceiver dataReceiver = new DataReceiver();
private static NSAlarmReceiver alarmReciever = new NSAlarmReceiver();
private static AckAlarmReceiver ackAlarmReciever = new AckAlarmReceiver();
private LocalBroadcastManager lbm;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
@ -93,6 +104,8 @@ public class MainApp extends Application {
sInstance = this; sInstance = this;
sResources = getResources(); sResources = getResources();
registerLocalBroadcastReceiver();
if (pluginsList == null) { if (pluginsList == null) {
pluginsList = new ArrayList<>(); pluginsList = new ArrayList<>();
// Register all tabs in app here // Register all tabs in app here
@ -157,6 +170,29 @@ public class MainApp extends Application {
} }
}); });
t.start(); t.start();
}
private void registerLocalBroadcastReceiver() {
lbm = LocalBroadcastManager.getInstance(this);
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_CHANGED_TREATMENT));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_REMOVED_TREATMENT));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_SGV));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_PROFILE));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_STATUS));
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_MBG));
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
lbm.registerReceiver(ackAlarmReciever, new IntentFilter(Intents.ACTION_ACK_ALARM));
} }
private void startKeepAliveService() { private void startKeepAliveService() {

View file

@ -506,7 +506,7 @@ public class DataService extends IntentService {
MainApp.getDbHelper().createCareportalEventFromJsonIfNotExists(trJson); MainApp.getDbHelper().createCareportalEventFromJsonIfNotExists(trJson);
} }
if (trJson.getString("eventType").equals(CareportalEvent.ANNOUNCEMENT)) { if (trJson.has("eventType") && trJson.getString("eventType").equals(CareportalEvent.ANNOUNCEMENT)) {
long date = trJson.getLong("mills"); long date = trJson.getLong("mills");
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (date > now - 15 * 60 * 1000L && trJson.has("notes")) { if (date > now - 15 * 60 * 1000L && trJson.has("notes")) {

View file

@ -159,7 +159,7 @@ public class NSClientInternalPlugin implements PluginBase {
MainApp.bus().post(new EventNSClientUpdateGUI()); MainApp.bus().post(new EventNSClientUpdateGUI());
} }
void clearLog() { synchronized void clearLog() {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -169,7 +169,7 @@ public class NSClientInternalPlugin implements PluginBase {
}); });
} }
private void addToLog(final EventNSClientNewLog ev) { private synchronized void addToLog(final EventNSClientNewLog ev) {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -183,7 +183,7 @@ public class NSClientInternalPlugin implements PluginBase {
}); });
} }
static void updateLog() { static synchronized void updateLog() {
try { try {
StringBuilder newTextLog = new StringBuilder(); StringBuilder newTextLog = new StringBuilder();
List<EventNSClientNewLog> temporaryList = new ArrayList<>(listLog); List<EventNSClientNewLog> temporaryList = new ArrayList<>(listLog);

View file

@ -4,12 +4,15 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -22,7 +25,7 @@ public class BroadcastAckAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastAckAlarm.class); private static Logger log = LoggerFactory.getLogger(BroadcastAckAlarm.class);
public static void handleClearAlarm(NSAlarm originalAlarm, Context context, long silenceTimeInMsec) { public static void handleClearAlarm(NSAlarm originalAlarm, Context context, long silenceTimeInMsec) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putInt("level", originalAlarm.getLevel()); bundle.putInt("level", originalAlarm.getLevel());
bundle.putString("group", originalAlarm.getGroup()); bundle.putString("group", originalAlarm.getGroup());
@ -30,7 +33,18 @@ public class BroadcastAckAlarm {
Intent intent = new Intent(Intents.ACTION_ACK_ALARM); Intent intent = new Intent(Intents.ACTION_ACK_ALARM);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putInt("level", originalAlarm.getLevel());
bundle.putString("group", originalAlarm.getGroup());
bundle.putLong("silenceTime", silenceTimeInMsec);
intent = new Intent(Intents.ACTION_ACK_ALARM);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
}
} }

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -21,14 +24,20 @@ public class BroadcastAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastAlarm.class); private static Logger log = LoggerFactory.getLogger(BroadcastAlarm.class);
public static void handleAlarm(JSONObject alarm, Context context) { public static void handleAlarm(JSONObject alarm, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("data", alarm.toString()); bundle.putString("data", alarm.toString());
Intent intent = new Intent(Intents.ACTION_ALARM); Intent intent = new Intent(Intents.ACTION_ALARM);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_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); context.sendBroadcast(intent);
} }
} }
}

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -12,6 +13,8 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -22,14 +25,20 @@ public class BroadcastAnnouncement {
private static Logger log = LoggerFactory.getLogger(BroadcastAnnouncement.class); private static Logger log = LoggerFactory.getLogger(BroadcastAnnouncement.class);
public static void handleAnnouncement(JSONObject announcement, Context context) { public static void handleAnnouncement(JSONObject announcement, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("data", announcement.toString()); bundle.putString("data", announcement.toString());
Intent intent = new Intent(Intents.ACTION_ANNOUNCEMENT); Intent intent = new Intent(Intents.ACTION_ANNOUNCEMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_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); context.sendBroadcast(intent);
} }
} }
}

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -22,14 +25,22 @@ public class BroadcastCals {
public static void handleNewCal(JSONArray cals, Context context, boolean isDelta) { public static void handleNewCal(JSONArray cals, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("cals", cals.toString()); bundle.putString("cals", cals.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_CAL); Intent intent = new Intent(Intents.ACTION_NEW_CAL);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("cals", cals.toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_CAL);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
} }
}

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -21,14 +24,20 @@ public class BroadcastClearAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastClearAlarm.class); private static Logger log = LoggerFactory.getLogger(BroadcastClearAlarm.class);
public static void handleClearAlarm(JSONObject clearalarm, Context context) { public static void handleClearAlarm(JSONObject clearalarm, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("data", clearalarm.toString()); bundle.putString("data", clearalarm.toString());
Intent intent = new Intent(Intents.ACTION_CLEAR_ALARM); Intent intent = new Intent(Intents.ACTION_CLEAR_ALARM);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_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); context.sendBroadcast(intent);
} }
} }
}

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -12,6 +13,8 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -26,15 +29,33 @@ public class BroadcastDeviceStatus {
Intent intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS); Intent intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("devicestatus", status.toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
}
public static void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) { public static void handleNewDeviceStatus(JSONArray statuses, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
List<JSONArray> splitted = BroadcastTreatment.splitArray(statuses); List<JSONArray> splitted = BroadcastTreatment.splitArray(statuses);
for (JSONArray part: splitted) {
Bundle bundle = new Bundle();
bundle.putString("devicestatuses", part.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_DEVICESTATUS);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
}
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
splitted = BroadcastTreatment.splitArray(statuses);
for (JSONArray part : splitted) { for (JSONArray part : splitted) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("devicestatuses", part.toString()); bundle.putString("devicestatuses", part.toString());
@ -46,3 +67,4 @@ public class BroadcastDeviceStatus {
} }
} }
} }
}

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -22,14 +25,22 @@ public class BroadcastMbgs {
public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) { public static void handleNewMbg(JSONArray mbgs, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("mbgs", mbgs.toString()); bundle.putString("mbgs", mbgs.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_MBG); Intent intent = new Intent(Intents.ACTION_NEW_MBG);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("mbgs", mbgs.toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_MBG);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
} }
}

View file

@ -4,12 +4,15 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.ProfileStore; import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -23,15 +26,23 @@ public class BroadcastProfile {
public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) { public static void handleNewTreatment(ProfileStore profile, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("profile", profile.getData().toString()); bundle.putString("profile", profile.getData().toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_PROFILE); Intent intent = new Intent(Intents.ACTION_NEW_PROFILE);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("profile", profile.getData().toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_PROFILE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
}
} }

View file

@ -5,6 +5,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager; import android.os.PowerManager;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -14,7 +15,7 @@ import info.nightscout.utils.SP;
public class BroadcastQueueStatus { public class BroadcastQueueStatus {
public static void handleNewStatus(int size, Context context) { public static void handleNewStatus(int size, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return; if(!SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) return;
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -12,6 +13,8 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -23,16 +26,24 @@ public class BroadcastSgvs {
public static void handleNewSgv(JSONObject sgv, Context context, boolean isDelta) { public static void handleNewSgv(JSONObject sgv, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("sgv", sgv.toString()); bundle.putString("sgv", sgv.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_SGV); Intent intent = new Intent(Intents.ACTION_NEW_SGV);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("sgv", sgv.toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_SGV);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
}
public static void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) { public static void handleNewSgv(JSONArray sgvs, Context context, boolean isDelta) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -41,7 +52,17 @@ public class BroadcastSgvs {
Intent intent = new Intent(Intents.ACTION_NEW_SGV); Intent intent = new Intent(Intents.ACTION_NEW_SGV);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("sgvs", sgvs.toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_SGV);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
}
} }

View file

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -12,6 +13,7 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus;
import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService; import info.nightscout.androidaps.plugins.NSClientInternal.services.NSClientService;
@ -25,8 +27,6 @@ public class BroadcastStatus {
public static void handleNewStatus(NSSettingsStatus status, Context context, boolean isDelta) { public static void handleNewStatus(NSSettingsStatus status, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
try { try {
bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName); bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName);
@ -41,6 +41,24 @@ public class BroadcastStatus {
Intent intent = new Intent(Intents.ACTION_NEW_STATUS); Intent intent = new Intent(Intents.ACTION_NEW_STATUS);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
try {
bundle.putString("nsclientversionname", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionName);
bundle.putInt("nsclientversioncode", MainApp.instance().getPackageManager().getPackageInfo(MainApp.instance().getPackageName(), 0).versionCode);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
bundle.putString("nightscoutversionname", NSClientService.nightscoutVersionName);
bundle.putInt("nightscoutversioncode", NSClientService.nightscoutVersionCode);
bundle.putString("status", status.getData().toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_STATUS);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
} }
}

View file

@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.TransactionTooLargeException; import android.os.TransactionTooLargeException;
import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -15,9 +16,12 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSTreatment;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils;
/** /**
* Created by mike on 20.02.2016. * Created by mike on 20.02.2016.
@ -27,22 +31,40 @@ public class BroadcastTreatment {
public static void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) { public static void handleNewTreatment(NSTreatment treatment, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.getData().toString()); bundle.putString("treatment", treatment.getData().toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT); Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("treatment", treatment.getData().toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_NEW_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
}
public static void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) { public static void handleNewTreatment(JSONArray treatments, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
List<JSONArray> splitted = splitArray(treatments); List<JSONArray> splitted = splitArray(treatments);
for (JSONArray part: splitted) {
Bundle bundle = new Bundle();
bundle.putString("treatments", part.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_NEW_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
}
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)){
splitted = splitArray(treatments);
for (JSONArray part: splitted) { for (JSONArray part: splitted) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatments", part.toString()); bundle.putString("treatments", part.toString());
@ -53,25 +75,45 @@ public class BroadcastTreatment {
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
} }
}
public void handleChangedTreatment(JSONObject treatment, Context context, boolean isDelta) { public void handleChangedTreatment(JSONObject treatment, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString()); bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT); Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
}
public static void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) { public static void handleChangedTreatment(JSONArray treatments, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
List<JSONArray> splitted = splitArray(treatments); List<JSONArray> splitted = splitArray(treatments);
for (JSONArray part : splitted) {
Bundle bundle = new Bundle();
bundle.putString("treatments", part.toString());
bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_CHANGED_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
}
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
splitted = splitArray(treatments);
for (JSONArray part : splitted) { for (JSONArray part : splitted) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatments", part.toString()); bundle.putString("treatments", part.toString());
@ -82,32 +124,51 @@ public class BroadcastTreatment {
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
} }
}
public static void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) { public static void handleRemovedTreatment(JSONObject treatment, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatment", treatment.toString()); bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("treatment", treatment.toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
}
public static void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) { public static void handleRemovedTreatment(JSONArray treatments, Context context, boolean isDelta) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("treatments", treatments.toString()); bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta); bundle.putBoolean("delta", isDelta);
Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT); Intent intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_nsclient_localbroadcasts, true)) {
bundle = new Bundle();
bundle.putString("treatments", treatments.toString());
bundle.putBoolean("delta", isDelta);
intent = new Intent(Intents.ACTION_REMOVED_TREATMENT);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent); context.sendBroadcast(intent);
} }
}
public static List<JSONArray> splitArray(JSONArray array) { public static List<JSONArray> splitArray(JSONArray array) {

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -11,6 +12,8 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.Services.Intents; import info.nightscout.androidaps.Services.Intents;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
@ -21,14 +24,20 @@ public class BroadcastUrgentAlarm {
private static Logger log = LoggerFactory.getLogger(BroadcastUrgentAlarm.class); private static Logger log = LoggerFactory.getLogger(BroadcastUrgentAlarm.class);
public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) { public static void handleUrgentAlarm(JSONObject urgentalarm, Context context) {
if(!SP.getBoolean("nsclient_localbroadcasts", true)) return;
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("data", urgentalarm.toString()); bundle.putString("data", urgentalarm.toString());
Intent intent = new Intent(Intents.ACTION_URGENT_ALARM); Intent intent = new Intent(Intents.ACTION_URGENT_ALARM);
intent.putExtras(bundle); intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LocalBroadcastManager.getInstance(MainApp.instance()).sendBroadcast(intent);
if(SP.getBoolean(R.string.key_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); context.sendBroadcast(intent);
} }
} }
}

View file

@ -189,6 +189,7 @@ public class ActionStringHandler {
boolean useBG = Boolean.parseBoolean(act[2]); boolean useBG = Boolean.parseBoolean(act[2]);
boolean useBolusIOB = Boolean.parseBoolean(act[3]); boolean useBolusIOB = Boolean.parseBoolean(act[3]);
boolean useBasalIOB = Boolean.parseBoolean(act[4]); boolean useBasalIOB = Boolean.parseBoolean(act[4]);
int percentage = Integer.parseInt(act[5]);
Profile profile = MainApp.getConfigBuilder().getProfile(); Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile == null) { if (profile == null) {
@ -203,7 +204,7 @@ public class ActionStringHandler {
} }
DecimalFormat format = new DecimalFormat("0.00"); DecimalFormat format = new DecimalFormat("0.00");
BolusWizard bolusWizard = new BolusWizard(); BolusWizard bolusWizard = new BolusWizard();
bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, useBolusIOB, useBasalIOB, false, false); bolusWizard.doCalc(profile, carbsAfterConstraints, 0d, useBG ? bgReading.valueToUnits(profile.getUnits()) : 0d, 0d, percentage, useBolusIOB, useBasalIOB, false, false);
Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin); Double insulinAfterConstraints = MainApp.getConfigBuilder().applyBolusConstraints(bolusWizard.calculatedTotalInsulin);
if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) { if (insulinAfterConstraints - bolusWizard.calculatedTotalInsulin != 0) {
@ -233,6 +234,9 @@ public class ActionStringHandler {
rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U"; rMessage += "\nBolus IOB: " + format.format(bolusWizard.insulingFromBolusIOB) + "U";
if (useBasalIOB) if (useBasalIOB)
rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U"; rMessage += "\nBasal IOB: " + format.format(bolusWizard.insulingFromBasalsIOB) + "U";
if(percentage != 100){
rMessage += "\nPercentage: " +format.format(bolusWizard.totalBeforePercentageAdjustment) + "U * " + percentage + "% -> ~" + format.format(bolusWizard.calculatedTotalInsulin) + "U";
}
lastBolusWizard = bolusWizard; lastBolusWizard = bolusWizard;

View file

@ -47,9 +47,14 @@ public class BolusWizard {
// Result // Result
public Double calculatedTotalInsulin = 0d; public Double calculatedTotalInsulin = 0d;
public Double totalBeforePercentageAdjustment = 0d;
public Double carbsEquivalent = 0d; public Double carbsEquivalent = 0d;
public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) { public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) {
return doCalc(specificProfile, carbs, cob, bg, correction, 100d, includeBolusIOB, includeBasalIOB, superBolus, trend);
}
public Double doCalc(Profile specificProfile, Integer carbs, Double cob, Double bg, Double correction, double percentageCorrection, Boolean includeBolusIOB, Boolean includeBasalIOB, Boolean superBolus, Boolean trend) {
this.specificProfile = specificProfile; this.specificProfile = specificProfile;
this.carbs = carbs; this.carbs = carbs;
this.bg = bg; this.bg = bg;
@ -103,7 +108,13 @@ public class BolusWizard {
} }
// Total // Total
calculatedTotalInsulin = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB; calculatedTotalInsulin = totalBeforePercentageAdjustment = insulinFromBG + insulinFromTrend + insulinFromCarbs + insulingFromBolusIOB + insulingFromBasalsIOB + insulinFromCorrection + insulinFromSuperBolus + insulinFromCOB;
//percentage
if(totalBeforePercentageAdjustment > 0){
calculatedTotalInsulin = totalBeforePercentageAdjustment*percentageCorrection/100d;
}
if (calculatedTotalInsulin < 0) { if (calculatedTotalInsulin < 0) {
carbsEquivalent = -calculatedTotalInsulin * ic; carbsEquivalent = -calculatedTotalInsulin * ic;

View file

@ -649,6 +649,7 @@
<string name="openapsama_autosens_period">Interval for autosens [h]</string> <string name="openapsama_autosens_period">Interval for autosens [h]</string>
<string name="openapsama_autosens_period_summary">Amount of hours in the past for sensitivity detection (carbs absorption time is excluded)</string> <string name="openapsama_autosens_period_summary">Amount of hours in the past for sensitivity detection (carbs absorption time is excluded)</string>
<string name="key_openapsama_autosens_period" translatable="false">openapsama_autosens_period</string> <string name="key_openapsama_autosens_period" translatable="false">openapsama_autosens_period</string>
<string name="key_nsclient_localbroadcasts" translatable="false">nsclient_localbroadcasts</string>
<string name="ratio_short">RAT</string> <string name="ratio_short">RAT</string>
<string name="key_do_not_track_profile_switch">do_not_track_profile_switch</string> <string name="key_do_not_track_profile_switch">do_not_track_profile_switch</string>
<string name="do_not_track_profile_switch">Ignore profile switch events</string> <string name="do_not_track_profile_switch">Ignore profile switch events</string>
@ -689,7 +690,7 @@
<string name="combopump">Accu-Chek Combo</string> <string name="combopump">Accu-Chek Combo</string>
<string name="combopump_settings">Accu-Chek Combo settings</string> <string name="combopump_settings">Accu-Chek Combo settings</string>
<string name="combopump_shortname">COMBO</string> <string name="combopump_shortname">COMBO</string>
<string name="ns_localbroadcasts">Enable loacal broadcasts to other apps (like xDrip).</string> <string name="ns_localbroadcasts">Enable broadcasts to other apps (like xDrip).</string>
<string name="ns_localbroadcasts_title">Enable local Broadcasts.</string> <string name="ns_localbroadcasts_title">Enable local Broadcasts.</string>
<string name="careportal_activity_label">ACTIVITY &amp; FEEDBACK</string> <string name="careportal_activity_label">ACTIVITY &amp; FEEDBACK</string>
<string name="careportal_carbsandbolus_label">CARBS &amp; BOLUS</string> <string name="careportal_carbsandbolus_label">CARBS &amp; BOLUS</string>

View file

@ -2,8 +2,10 @@ package info.nightscout.androidaps.interaction.actions;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.wearable.view.DotsPageIndicator; import android.support.wearable.view.DotsPageIndicator;
import android.support.wearable.view.GridPagerAdapter; import android.support.wearable.view.GridPagerAdapter;
import android.support.wearable.view.GridViewPager; import android.support.wearable.view.GridViewPager;
@ -28,10 +30,13 @@ import info.nightscout.androidaps.interaction.utils.SafeParse;
public class WizardActivity extends ViewSelectorActivity { public class WizardActivity extends ViewSelectorActivity {
PlusMinusEditText editCarbs; PlusMinusEditText editCarbs;
PlusMinusEditText editPercentage;
boolean useBG; boolean useBG;
boolean includeBolusIOB; boolean includeBolusIOB;
boolean includeBasalIOB; boolean includeBasalIOB;
boolean hasPercentage;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -43,6 +48,8 @@ public class WizardActivity extends ViewSelectorActivity {
pager.setAdapter(new MyGridViewPagerAdapter()); pager.setAdapter(new MyGridViewPagerAdapter());
DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator); DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
dotsPageIndicator.setPager(pager); dotsPageIndicator.setPager(pager);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
hasPercentage = sp.getBoolean("wizardpercentage", false);
} }
@ -56,7 +63,7 @@ public class WizardActivity extends ViewSelectorActivity {
private class MyGridViewPagerAdapter extends GridPagerAdapter { private class MyGridViewPagerAdapter extends GridPagerAdapter {
@Override @Override
public int getColumnCount(int arg0) { public int getColumnCount(int arg0) {
return 5; return hasPercentage?6:5;
} }
@Override @Override
@ -151,6 +158,17 @@ public class WizardActivity extends ViewSelectorActivity {
}); });
container.addView(view); container.addView(view);
return view; return view;
} else if(col == 4 && hasPercentage){
final View view = getInflatedPlusMinusView(container);
if (editPercentage == null) {
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, 100d, 50d, 150d, 1d, new DecimalFormat("0"), false);
} else {
double def = SafeParse.stringToDouble(editPercentage.editText.getText().toString());
editPercentage = new PlusMinusEditText(view, R.id.amountfield, R.id.plusbutton, R.id.minusbutton, def, 50d, 150d, 1d, new DecimalFormat("0"), false);
}
setLabelToPlusMinusView(view, "percentage");
container.addView(view);
return view;
} else { } else {
final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false); final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.action_send_item, container, false);
@ -162,10 +180,15 @@ public class WizardActivity extends ViewSelectorActivity {
//check if it can happen that the fagment is never created that hold data? //check if it can happen that the fagment is never created that hold data?
// (you have to swipe past them anyways - but still) // (you have to swipe past them anyways - but still)
int percentage = 100;
if (editPercentage != null) percentage = SafeParse.stringToInt(editPercentage.editText.getText().toString());
String actionstring = "wizard " + SafeParse.stringToInt(editCarbs.editText.getText().toString()) String actionstring = "wizard " + SafeParse.stringToInt(editCarbs.editText.getText().toString())
+ " " + useBG + " " + useBG
+ " " + includeBolusIOB + " " + includeBolusIOB
+ " " + includeBasalIOB; + " " + includeBasalIOB
+ " " + percentage;
ListenerService.initiateAction(WizardActivity.this, actionstring); ListenerService.initiateAction(WizardActivity.this, actionstring);
finish(); finish();
} }

View file

@ -142,4 +142,11 @@
android:title="Single Target" android:title="Single Target"
app:wear_iconOff="@drawable/settings_off" app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on"/> app:wear_iconOn="@drawable/settings_on"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="wizardpercentage"
android:summary="Percentage correction."
android:title="Wizard Percentage"
app:wear_iconOff="@drawable/settings_off"
app:wear_iconOn="@drawable/settings_on"/>
</PreferenceScreen> </PreferenceScreen>