Merge branch 'dev' into newautosens
This commit is contained in:
commit
240f9618f5
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -188,12 +188,54 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_iob"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/iob"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text=":"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_iob"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="5dp"
|
||||
android:text=""
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="10dp"
|
||||
android:text="@string/cob" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text=":" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_cob"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="23 g" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -182,12 +182,54 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_iob"
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/iob"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text=":"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_iob"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="5dp"
|
||||
android:text=""
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="10dp"
|
||||
android:text="@string/cob" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:text=":" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_cob"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="23 g" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -320,7 +320,7 @@
|
|||
android:gravity="start"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="0.50U/h @17:35 1/30min - 0.40U/h"
|
||||
android:text=""
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="14sp" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue