diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java
index e2e7eabd89..b647e9b6d1 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainApp.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java
@@ -39,6 +39,7 @@ import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.androidaps.plugins.VirtualPump.VirtualPumpFragment;
import info.nightscout.androidaps.plugins.Wear.WearFragment;
+import info.nightscout.androidaps.plugins.persistentnotification.PersistentNotificationPlugin;
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
import io.fabric.sdk.android.Fabric;
@@ -93,6 +94,7 @@ public class MainApp extends Application {
pluginsList.add(SmsCommunicatorFragment.getPlugin());
if (Config.WEAR) pluginsList.add(WearFragment.getPlugin(this));
+ pluginsList.add(new PersistentNotificationPlugin(this));
pluginsList.add(sConfigBuilder = ConfigBuilderFragment.getPlugin());
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationFragment.java
new file mode 100644
index 0000000000..6834124167
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationFragment.java
@@ -0,0 +1,14 @@
+package info.nightscout.androidaps.plugins.persistentnotification;
+
+import android.support.v4.app.Fragment;
+
+import info.nightscout.androidaps.interfaces.FragmentBase;
+
+/**
+ * Created by adrian on 23/12/16.
+ */
+
+public class PersistentNotificationFragment extends Fragment implements FragmentBase {
+
+
+}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java
new file mode 100644
index 0000000000..dffe461ead
--- /dev/null
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/persistentnotification/PersistentNotificationPlugin.java
@@ -0,0 +1,241 @@
+package info.nightscout.androidaps.plugins.persistentnotification;
+
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.support.v4.app.TaskStackBuilder;
+import android.support.v7.app.NotificationCompat;
+
+import com.squareup.otto.Subscribe;
+
+import info.nightscout.androidaps.Constants;
+import info.nightscout.androidaps.MainActivity;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.db.BgReading;
+import info.nightscout.androidaps.db.DatabaseHelper;
+import info.nightscout.androidaps.db.TempBasal;
+import info.nightscout.androidaps.events.EventInitializationChanged;
+import info.nightscout.androidaps.events.EventNewBG;
+import info.nightscout.androidaps.events.EventNewBasalProfile;
+import info.nightscout.androidaps.events.EventPreferenceChange;
+import info.nightscout.androidaps.events.EventRefreshGui;
+import info.nightscout.androidaps.events.EventTempBasalChange;
+import info.nightscout.androidaps.events.EventTreatmentChange;
+import info.nightscout.androidaps.interfaces.PluginBase;
+import info.nightscout.androidaps.interfaces.PumpInterface;
+import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
+import info.nightscout.androidaps.plugins.Overview.Notification;
+import info.nightscout.client.data.NSProfile;
+import info.nightscout.utils.DecimalFormatter;
+
+/**
+ * Created by adrian on 23/12/16.
+ */
+
+public class PersistentNotificationPlugin implements PluginBase{
+
+ private static final int ONGOING_NOTIFICATION_ID = 4711;
+ static boolean fragmentEnabled = false;
+ private final Context ctx;
+
+ public PersistentNotificationPlugin(Context ctx) {
+ this.ctx = ctx;
+ }
+
+
+ @Override
+ public int getType() {
+ return GENERAL;
+ }
+
+ @Override
+ public String getFragmentClass() {
+ return PersistentNotificationFragment.class.getName();
+ }
+
+ @Override
+ public String getName() {
+ return ctx.getString(R.string.ongoingnotificaction);
+ }
+
+ @Override
+ public boolean isEnabled(int type) {
+ return fragmentEnabled;
+ }
+
+ @Override
+ public boolean isVisibleInTabs(int type) {
+ return false;
+ }
+
+ @Override
+ public boolean canBeHidden(int type) {
+ return true;
+ }
+
+ @Override
+ public void setFragmentEnabled(int type, boolean fragmentEnabled) {
+
+ if(getType() == type){
+ this.fragmentEnabled = fragmentEnabled;
+ checkBusRegistration();
+ updateNotification();
+ }
+
+ }
+
+ private void updateNotification() {
+
+ if(!fragmentEnabled){
+ NotificationManager mNotificationManager =
+ (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
+ mNotificationManager.cancel(ONGOING_NOTIFICATION_ID);
+ return;
+ }
+
+
+ String line1 = ctx.getString(R.string.noprofile);
+ NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
+
+
+ BgReading lastBG = MainApp.getDbHelper().lastBg();
+ DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
+
+ if(profile != null && lastBG != null) {
+ line1 = lastBG.valueToUnitsToString(profile.getUnits());
+ }
+ if (glucoseStatus != null) {
+ line1 += " Δ" + deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, profile.getUnits())
+ + " avgΔ" + deltastring(glucoseStatus.avgdelta, glucoseStatus.avgdelta * Constants.MGDL_TO_MMOLL, profile.getUnits());
+ } else {
+ line1 += " " +
+ ctx.getString(R.string.old_data) +
+ " ";
+ }
+
+ PumpInterface pump = MainApp.getConfigBuilder();
+
+ if (pump.isTempBasalInProgress()) {
+ TempBasal activeTemp = pump.getTempBasal();
+ line1 += " " + activeTemp.toStringShort();
+ }
+
+ //IOB
+ MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
+ IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
+ if (bolusIob == null) bolusIob = new IobTotal();
+ MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
+ IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
+ if (basalIob == null) basalIob = new IobTotal();
+ String line2 = ctx.getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ + ctx.getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
+ + ctx.getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
+
+
+ String line3 = DecimalFormatter.to2Decimal(pump.getBaseBasalRate()) + " U/h";
+
+
+ if (profile != null && profile.getActiveProfile() != null)
+ line3 += " - " + profile.getActiveProfile();
+
+
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
+ builder.setOngoing(true);
+ builder.setCategory(NotificationCompat.CATEGORY_STATUS);
+ builder.setSmallIcon(R.drawable.ic_notification);
+ Bitmap largeIcon = BitmapFactory.decodeResource(ctx.getResources(), R.mipmap.ic_launcher);
+ builder.setLargeIcon(largeIcon);
+ builder.setContentTitle(line1);
+ builder.setContentText(line2);
+ builder.setSubText(line3);
+
+ Intent resultIntent = new Intent(ctx, MainActivity.class);
+
+ TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx);
+ stackBuilder.addParentStack(MainActivity.class);
+ stackBuilder.addNextIntent(resultIntent);
+ PendingIntent resultPendingIntent =
+ stackBuilder.getPendingIntent(
+ 0,
+ PendingIntent.FLAG_UPDATE_CURRENT
+ );
+ builder.setContentIntent(resultPendingIntent);
+ NotificationManager mNotificationManager =
+ (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
+
+ android.app.Notification notification = builder.build();
+ mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification);
+
+ }
+
+ private void checkBusRegistration() {
+ if(fragmentEnabled){
+ MainApp.bus().register(this);
+ } else {
+ MainApp.bus().unregister(this);
+ }
+ }
+
+ @Override
+ public void setFragmentVisible(int type, boolean fragmentVisible) {
+ //no visible fragment
+ }
+
+ private String deltastring(double deltaMGDL, double deltaMMOL, String units) {
+ String deltastring = "";
+ if (deltaMGDL >=0){
+ deltastring += "+";
+ } else{
+ deltastring += "-";
+
+ }
+ if (units.equals(Constants.MGDL)){
+ deltastring += DecimalFormatter.to1Decimal(Math.abs(deltaMGDL));
+ }
+ else {
+ deltastring += DecimalFormatter.to1Decimal(Math.abs(deltaMMOL));
+ }
+ return deltastring;
+ }
+
+
+ @Subscribe
+ public void onStatusEvent(final EventPreferenceChange ev) {
+ updateNotification();
+ }
+
+ @Subscribe
+ public void onStatusEvent(final EventTreatmentChange ev) {
+ updateNotification();
+ }
+
+ @Subscribe
+ public void onStatusEvent(final EventTempBasalChange ev) {
+ updateNotification();
+ }
+
+ @Subscribe
+ public void onStatusEvent(final EventNewBG ev) {
+ updateNotification();
+ }
+
+ @Subscribe
+ public void onStatusEvent(final EventNewBasalProfile ev) {
+ updateNotification();
+ }
+
+ @Subscribe
+ public void onStatusEvent(final EventInitializationChanged ev) {
+ updateNotification();
+ }
+
+ @Subscribe
+ public void onStatusEvent(final EventRefreshGui ev) {
+ updateNotification();
+ }
+
+}
diff --git a/app/src/main/res/drawable-hdpi-v11/ic_notification.png b/app/src/main/res/drawable-hdpi-v11/ic_notification.png
new file mode 100644
index 0000000000..1e28cbeb7a
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v11/ic_notification.png differ
diff --git a/app/src/main/res/drawable-hdpi-v9/ic_notification.png b/app/src/main/res/drawable-hdpi-v9/ic_notification.png
new file mode 100644
index 0000000000..ad1bcf514f
Binary files /dev/null and b/app/src/main/res/drawable-hdpi-v9/ic_notification.png differ
diff --git a/app/src/main/res/drawable-hdpi/ic_notification.png b/app/src/main/res/drawable-hdpi/ic_notification.png
new file mode 100644
index 0000000000..bb8248c78f
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_notification.png differ
diff --git a/app/src/main/res/drawable-mdpi-v11/ic_notification.png b/app/src/main/res/drawable-mdpi-v11/ic_notification.png
new file mode 100644
index 0000000000..fbed7675b1
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v11/ic_notification.png differ
diff --git a/app/src/main/res/drawable-mdpi-v9/ic_notification.png b/app/src/main/res/drawable-mdpi-v9/ic_notification.png
new file mode 100644
index 0000000000..3be3f1383f
Binary files /dev/null and b/app/src/main/res/drawable-mdpi-v9/ic_notification.png differ
diff --git a/app/src/main/res/drawable-mdpi/ic_notification.png b/app/src/main/res/drawable-mdpi/ic_notification.png
new file mode 100644
index 0000000000..c19b973e2a
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_notification.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v11/ic_notification.png b/app/src/main/res/drawable-xhdpi-v11/ic_notification.png
new file mode 100644
index 0000000000..0427fc6b02
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v11/ic_notification.png differ
diff --git a/app/src/main/res/drawable-xhdpi-v9/ic_notification.png b/app/src/main/res/drawable-xhdpi-v9/ic_notification.png
new file mode 100644
index 0000000000..b779bd4090
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi-v9/ic_notification.png differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_notification.png b/app/src/main/res/drawable-xhdpi/ic_notification.png
new file mode 100644
index 0000000000..9eb0dcf193
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_notification.png differ
diff --git a/app/src/main/res/drawable-xxhdpi-v11/ic_notification.png b/app/src/main/res/drawable-xxhdpi-v11/ic_notification.png
new file mode 100644
index 0000000000..8a586cce76
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi-v11/ic_notification.png differ
diff --git a/app/src/main/res/drawable-xxhdpi-v9/ic_notification.png b/app/src/main/res/drawable-xxhdpi-v9/ic_notification.png
new file mode 100644
index 0000000000..b3cd107f78
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi-v9/ic_notification.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_notification.png b/app/src/main/res/drawable-xxhdpi/ic_notification.png
new file mode 100644
index 0000000000..9da9b83a84
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_notification.png differ
diff --git a/app/src/main/res/drawable/notif_icon.png b/app/src/main/res/drawable/notif_icon.png
new file mode 100644
index 0000000000..1b89799dc6
Binary files /dev/null and b/app/src/main/res/drawable/notif_icon.png differ
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 87b200db28..ab184438f9 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -387,4 +387,6 @@
BG:
Last BG:
MDI
+ Ongoing Notification
+ OLD DATA