diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
index f1e80abeba..c46a13c91e 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
@@ -80,9 +80,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
registerBus();
setUpTabs(false);
- Intent alarm = new Intent(this, AlarmSoundService.class);
- alarm.putExtra("soundid", R.raw.staledataalarm);
- //startService(alarm);
}
@Subscribe
diff --git a/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java b/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java
index 79b647b5f5..41587e79b9 100644
--- a/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java
+++ b/app/src/main/java/info/nightscout/androidaps/Services/AlarmSoundService.java
@@ -18,7 +18,7 @@ public class AlarmSoundService extends Service {
private static Logger log = LoggerFactory.getLogger(AlarmSoundService.class);
MediaPlayer player;
- int resourceId = R.raw.bgalarm;
+ int resourceId = R.raw.error;
public AlarmSoundService() {
}
@@ -36,9 +36,11 @@ public class AlarmSoundService extends Service {
}
public int onStartCommand(Intent intent, int flags, int startId) {
+ if (player != null && player.isPlaying())
+ player.stop();
log.debug("onStartCommand");
if (intent != null && intent.hasExtra("soundid"))
- resourceId = intent.getIntExtra("soundid", R.raw.bgalarm);
+ resourceId = intent.getIntExtra("soundid", R.raw.error);
player = new MediaPlayer();
AssetFileDescriptor afd = MainApp.sResources.openRawResourceFd(resourceId);
diff --git a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
index 33b56d125f..4d0685a00f 100644
--- a/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
+++ b/app/src/main/java/info/nightscout/androidaps/Services/DataService.java
@@ -262,18 +262,12 @@ public class DataService extends IntentService {
NSStatus.getInstance().setData(statusJson);
if (Config.logIncommingData)
log.debug("Received status: " + statusJson.toString());
- if (statusJson.has("settings")) {
- JSONObject settings = statusJson.getJSONObject("settings");
- if (settings.has("thresholds")) {
- JSONObject thresholds = settings.getJSONObject("thresholds");
- if (thresholds.has("bgTargetTop")) {
- OverviewPlugin.bgTargetHigh = thresholds.getDouble("bgTargetTop");
- }
- if (thresholds.has("bgTargetBottom")) {
- OverviewPlugin.bgTargetLow = thresholds.getDouble("bgTargetBottom");
- }
- }
- }
+ Double targetHigh = NSStatus.getInstance().getThreshold("bgTargetTop");
+ Double targetlow = NSStatus.getInstance().getThreshold("bgTargetBottom");
+ if (targetHigh != null)
+ OverviewPlugin.bgTargetHigh = targetHigh;
+ if (targetlow != null)
+ OverviewPlugin.bgTargetLow = targetlow;
} catch (JSONException e) {
e.printStackTrace();
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSStatus.java
index 3261e32318..e89dee8db5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSStatus.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSStatus.java
@@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.NSClientInternal.data;
+import android.support.annotation.Nullable;
+
import org.json.JSONException;
import org.json.JSONObject;
@@ -104,9 +106,10 @@ public class NSStatus {
return instance;
}
- private JSONObject data;
+ private JSONObject data = null;
- public NSStatus() {}
+ public NSStatus() {
+ }
public NSStatus setData(JSONObject obj) {
this.data = obj;
@@ -157,6 +160,32 @@ public class NSStatus {
return getStringOrNull("activeProfile");
}
+ // "bgHigh": 252,
+ // "bgTargetTop": 180,
+ // "bgTargetBottom": 72,
+ // "bgLow": 71
+ @Nullable
+ public Double getThreshold(String what) {
+ try {
+ if (data == null)
+ return null;
+ String settings = getSettings();
+ if (settings != null) {
+ JSONObject settingsO = new JSONObject(settings);
+ if (settingsO.has("thresholds")) {
+ JSONObject tObject = settingsO.getJSONObject("thresholds");
+ if (tObject.has(what)) {
+ Double result = tObject.getDouble(what);
+ return result;
+ }
+ }
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
private String getStringOrNull(String key) {
String ret = null;
if (data.has(key)) {
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java
index 23e72a0446..bfa1f6e3f5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java
@@ -2,7 +2,12 @@ package info.nightscout.androidaps.plugins.Overview;
import java.util.Date;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSAlarm;
+import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus;
+import info.nightscout.utils.SP;
/**
* Created by mike on 03.12.2016.
@@ -44,6 +49,7 @@ public class Notification {
public Date validTo = new Date(0);
public NSAlarm nsAlarm = null;
+ public Integer soundId = null;
public Notification() {
}
@@ -87,12 +93,52 @@ public class Notification {
this.id = NSALARM;
this.level = NORMAL;
this.text = nsAlarm.getTile();
+ if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false))
+ this.soundId = R.raw.alarm;
break;
case 2:
this.id = NSURGENTALARM;
this.level = URGENT;
this.text = nsAlarm.getTile();
+ if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_urgent_high, false))
+ this.soundId = R.raw.urgentalarm;
break;
}
}
+
+ public boolean isEnabled() {
+ if (nsAlarm == null)
+ return true;
+ if (level == ANNOUNCEMENT)
+ return true;
+ if (level == NORMAL && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false))
+ return true;
+ if (level == URGENT && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_urgent_high, false))
+ return true;
+ return false;
+ }
+
+ boolean isAlarmForLow() {
+ BgReading bgReading = MainApp.getDbHelper().lastBg();
+ if (bgReading == null)
+ return false;
+ Double threshold = NSStatus.getInstance().getThreshold("bgTargetTop");
+ if (threshold == null)
+ return false;
+ if (bgReading.value <= threshold)
+ return true;
+ return false;
+ }
+
+ boolean isAlarmForHigh() {
+ BgReading bgReading = MainApp.getDbHelper().lastBg();
+ if (bgReading == null)
+ return false;
+ Double threshold = NSStatus.getInstance().getThreshold("bgTargetBottom");
+ if (threshold == null)
+ return false;
+ if (bgReading.value >= threshold)
+ return true;
+ return false;
+ }
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/NotificationStore.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/NotificationStore.java
index 8a046c59e5..b836f99be5 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/NotificationStore.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/NotificationStore.java
@@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.Overview;
+import android.content.Intent;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -9,6 +11,10 @@ import java.util.Comparator;
import java.util.Date;
import java.util.List;
+import info.nightscout.androidaps.MainApp;
+import info.nightscout.androidaps.R;
+import info.nightscout.androidaps.Services.AlarmSoundService;
+
/**
* Created by mike on 03.12.2016.
@@ -41,6 +47,11 @@ public class NotificationStore {
return;
}
}
+ 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);
Collections.sort(store, new NotificationComparator());
}
@@ -48,6 +59,10 @@ public class NotificationStore {
public boolean remove(int id) {
for (int i = 0; i < store.size(); i++) {
if (get(i).id == id) {
+ if (get(i).soundId != null) {
+ Intent alarm = new Intent(MainApp.instance().getApplicationContext(), AlarmSoundService.class);
+ MainApp.instance().stopService(alarm);
+ }
store.remove(i);
return true;
}
diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
index 74ebd6c5f0..31aacc3d0a 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/OverviewFragment.java
@@ -854,7 +854,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (scheduledUpdate != null)
scheduledUpdate.cancel(false);
Runnable task = new UpdateRunnable();
- final int msec = 2000;
+ final int msec = 500;
scheduledUpdate = worker.schedule(task, msec, TimeUnit.MILLISECONDS);
}
@@ -946,7 +946,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
tempTargetView.setTextColor(Color.WHITE);
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetDisabledBackground));
- tempTargetView.setText(SP.getDouble("openapsma_min_bg", minBgDefault) + " - " + SP.getDouble("openapsma_max_bg", maxBgDefault));
+ double low = SP.getDouble("openapsma_min_bg", minBgDefault);
+ double high = SP.getDouble("openapsma_max_bg", maxBgDefault);
+ if (low == high)
+ tempTargetView.setText("" + low);
+ else
+ tempTargetView.setText(low + " - " + high);
tempTargetView.setVisibility(View.VISIBLE);
}
if (Config.NSCLIENT && tempTarget == null) {
@@ -1106,17 +1111,24 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
- String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
- + getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
- + getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
- iobView.setText(iobtext);
+ if (MainApp.sResources.getBoolean(R.bool.isTablet)) {
+ String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ + getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
+ + getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
+ iobView.setText(iobtext);
+ } else {
+ String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ + DecimalFormatter.to2Decimal(bolusIob.iob) + "/"
+ + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")";
+ iobView.setText(iobtext);
+ }
// cob
if (cobView != null) { // view must not exists
String cobText = "";
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis());
if (autosensData != null)
- cobText = (int) autosensData.cob + " g " + String.format(MainApp.sResources.getString(R.string.minago), autosensData.minOld());
+ cobText = (int) autosensData.cob + " g";
cobView.setText(cobText);
}
diff --git a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java
index 41f8eb5297..bff2e6695a 100644
--- a/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java
+++ b/app/src/main/java/info/nightscout/androidaps/receivers/NSAlarmReceiver.java
@@ -36,7 +36,8 @@ public class NSAlarmReceiver extends BroadcastReceiver {
case Intents.ACTION_ALARM:
case Intents.ACTION_URGENT_ALARM:
Notification notification = new Notification(nsAlarm);
- MainApp.bus().post(new EventNewNotification(notification));
+ if (notification.isEnabled())
+ MainApp.bus().post(new EventNewNotification(notification));
break;
case Intents.ACTION_CLEAR_ALARM:
MainApp.bus().post(new EventDismissNotification(Notification.NSALARM));
diff --git a/app/src/main/res/layout/overview_fragment.xml b/app/src/main/res/layout/overview_fragment.xml
index 8ecf3ae128..a89065c01e 100644
--- a/app/src/main/res/layout/overview_fragment.xml
+++ b/app/src/main/res/layout/overview_fragment.xml
@@ -188,12 +188,54 @@
-
+ android:gravity="center_horizontal"
+ android:orientation="horizontal"
+ android:paddingTop="5dp">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+ android:gravity="center_horizontal"
+ android:orientation="horizontal"
+ android:paddingTop="5dp">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/raw/staledataalarm.mp3 b/app/src/main/res/raw/alarm.mp3
similarity index 100%
rename from app/src/main/res/raw/staledataalarm.mp3
rename to app/src/main/res/raw/alarm.mp3
diff --git a/app/src/main/res/raw/bgalarm.mp3 b/app/src/main/res/raw/urgentalarm.mp3
similarity index 100%
rename from app/src/main/res/raw/bgalarm.mp3
rename to app/src/main/res/raw/urgentalarm.mp3