Merge branch 'dev' into newautosens

This commit is contained in:
Milos Kozak 2017-06-21 09:04:38 +02:00
commit 240f9618f5
13 changed files with 218 additions and 38 deletions

View file

@ -80,9 +80,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
registerBus(); registerBus();
setUpTabs(false); setUpTabs(false);
Intent alarm = new Intent(this, AlarmSoundService.class);
alarm.putExtra("soundid", R.raw.staledataalarm);
//startService(alarm);
} }
@Subscribe @Subscribe

View file

@ -18,7 +18,7 @@ public class AlarmSoundService extends Service {
private static Logger log = LoggerFactory.getLogger(AlarmSoundService.class); private static Logger log = LoggerFactory.getLogger(AlarmSoundService.class);
MediaPlayer player; MediaPlayer player;
int resourceId = R.raw.bgalarm; int resourceId = R.raw.error;
public AlarmSoundService() { public AlarmSoundService() {
} }
@ -36,9 +36,11 @@ public class AlarmSoundService extends Service {
} }
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (player != null && player.isPlaying())
player.stop();
log.debug("onStartCommand"); log.debug("onStartCommand");
if (intent != null && intent.hasExtra("soundid")) if (intent != null && intent.hasExtra("soundid"))
resourceId = intent.getIntExtra("soundid", R.raw.bgalarm); resourceId = intent.getIntExtra("soundid", R.raw.error);
player = new MediaPlayer(); player = new MediaPlayer();
AssetFileDescriptor afd = MainApp.sResources.openRawResourceFd(resourceId); AssetFileDescriptor afd = MainApp.sResources.openRawResourceFd(resourceId);

View file

@ -262,18 +262,12 @@ public class DataService extends IntentService {
NSStatus.getInstance().setData(statusJson); NSStatus.getInstance().setData(statusJson);
if (Config.logIncommingData) if (Config.logIncommingData)
log.debug("Received status: " + statusJson.toString()); log.debug("Received status: " + statusJson.toString());
if (statusJson.has("settings")) { Double targetHigh = NSStatus.getInstance().getThreshold("bgTargetTop");
JSONObject settings = statusJson.getJSONObject("settings"); Double targetlow = NSStatus.getInstance().getThreshold("bgTargetBottom");
if (settings.has("thresholds")) { if (targetHigh != null)
JSONObject thresholds = settings.getJSONObject("thresholds"); OverviewPlugin.bgTargetHigh = targetHigh;
if (thresholds.has("bgTargetTop")) { if (targetlow != null)
OverviewPlugin.bgTargetHigh = thresholds.getDouble("bgTargetTop"); OverviewPlugin.bgTargetLow = targetlow;
}
if (thresholds.has("bgTargetBottom")) {
OverviewPlugin.bgTargetLow = thresholds.getDouble("bgTargetBottom");
}
}
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.NSClientInternal.data; package info.nightscout.androidaps.plugins.NSClientInternal.data;
import android.support.annotation.Nullable;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -104,9 +106,10 @@ public class NSStatus {
return instance; return instance;
} }
private JSONObject data; private JSONObject data = null;
public NSStatus() {} public NSStatus() {
}
public NSStatus setData(JSONObject obj) { public NSStatus setData(JSONObject obj) {
this.data = obj; this.data = obj;
@ -157,6 +160,32 @@ public class NSStatus {
return getStringOrNull("activeProfile"); 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) { private String getStringOrNull(String key) {
String ret = null; String ret = null;
if (data.has(key)) { if (data.has(key)) {

View file

@ -2,7 +2,12 @@ package info.nightscout.androidaps.plugins.Overview;
import java.util.Date; 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.NSAlarm;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSStatus;
import info.nightscout.utils.SP;
/** /**
* Created by mike on 03.12.2016. * Created by mike on 03.12.2016.
@ -44,6 +49,7 @@ public class Notification {
public Date validTo = new Date(0); public Date validTo = new Date(0);
public NSAlarm nsAlarm = null; public NSAlarm nsAlarm = null;
public Integer soundId = null;
public Notification() { public Notification() {
} }
@ -87,12 +93,52 @@ public class Notification {
this.id = NSALARM; this.id = NSALARM;
this.level = NORMAL; this.level = NORMAL;
this.text = nsAlarm.getTile(); 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; break;
case 2: case 2:
this.id = NSURGENTALARM; this.id = NSURGENTALARM;
this.level = URGENT; this.level = URGENT;
this.text = nsAlarm.getTile(); 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; 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;
}
} }

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.plugins.Overview; package info.nightscout.androidaps.plugins.Overview;
import android.content.Intent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -9,6 +11,10 @@ import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; 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. * Created by mike on 03.12.2016.
@ -41,6 +47,11 @@ public class NotificationStore {
return; 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); store.add(n);
Collections.sort(store, new NotificationComparator()); Collections.sort(store, new NotificationComparator());
} }
@ -48,6 +59,10 @@ public class NotificationStore {
public boolean remove(int id) { public boolean remove(int id) {
for (int i = 0; i < store.size(); i++) { for (int i = 0; i < store.size(); i++) {
if (get(i).id == id) { 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); store.remove(i);
return true; return true;
} }

View file

@ -854,7 +854,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (scheduledUpdate != null) if (scheduledUpdate != null)
scheduledUpdate.cancel(false); scheduledUpdate.cancel(false);
Runnable task = new UpdateRunnable(); Runnable task = new UpdateRunnable();
final int msec = 2000; final int msec = 500;
scheduledUpdate = worker.schedule(task, msec, TimeUnit.MILLISECONDS); scheduledUpdate = worker.schedule(task, msec, TimeUnit.MILLISECONDS);
} }
@ -946,7 +946,12 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
} }
tempTargetView.setTextColor(Color.WHITE); tempTargetView.setTextColor(Color.WHITE);
tempTargetView.setBackgroundColor(MainApp.sResources.getColor(R.color.tempTargetDisabledBackground)); 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); tempTargetView.setVisibility(View.VISIBLE);
} }
if (Config.NSCLIENT && tempTarget == null) { if (Config.NSCLIENT && tempTarget == null) {
@ -1106,17 +1111,24 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round(); IobTotal bolusIob = MainApp.getConfigBuilder().getLastCalculationTreatments().round();
IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round(); IobTotal basalIob = MainApp.getConfigBuilder().getLastCalculationTempBasals().round();
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U (" if (MainApp.sResources.getBoolean(R.bool.isTablet)) {
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U " String iobtext = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)"; + getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
iobView.setText(iobtext); + 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 // cob
if (cobView != null) { // view must not exists if (cobView != null) { // view must not exists
String cobText = ""; String cobText = "";
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis()); AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(System.currentTimeMillis());
if (autosensData != null) 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); cobView.setText(cobText);
} }

View file

@ -36,7 +36,8 @@ public class NSAlarmReceiver extends BroadcastReceiver {
case Intents.ACTION_ALARM: case Intents.ACTION_ALARM:
case Intents.ACTION_URGENT_ALARM: case Intents.ACTION_URGENT_ALARM:
Notification notification = new Notification(nsAlarm); Notification notification = new Notification(nsAlarm);
MainApp.bus().post(new EventNewNotification(notification)); if (notification.isEnabled())
MainApp.bus().post(new EventNewNotification(notification));
break; break;
case Intents.ACTION_CLEAR_ALARM: case Intents.ACTION_CLEAR_ALARM:
MainApp.bus().post(new EventDismissNotification(Notification.NSALARM)); MainApp.bus().post(new EventDismissNotification(Notification.NSALARM));

View file

@ -188,12 +188,54 @@
</LinearLayout> </LinearLayout>
<TextView <LinearLayout
android:id="@+id/overview_iob" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceSmall" /> 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 <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -182,12 +182,54 @@
</LinearLayout> </LinearLayout>
<TextView <LinearLayout
android:id="@+id/overview_iob" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceSmall" /> 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 <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -320,7 +320,7 @@
android:gravity="start" android:gravity="start"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingLeft="5dp" android:paddingLeft="5dp"
android:text="0.50U/h @17:35 1/30min - 0.40U/h" android:text=""
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:textSize="14sp" /> android:textSize="14sp" />