GUI improvements
This commit is contained in:
parent
a66ece9af5
commit
b310310511
7 changed files with 137 additions and 42 deletions
|
@ -21,6 +21,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
||||
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
private static Logger log = LoggerFactory.getLogger(DatabaseHelper.class);
|
||||
|
@ -171,13 +172,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0");
|
||||
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
|
||||
|
||||
return "{\"glucose\"=" + formatNumber0decimalplaces.format(glucose) +
|
||||
",\"delta\"=" + formatNumber0decimalplaces.format(delta) +
|
||||
",\"avgdelta\"=" + formatNumber2decimalplaces.format(avgdelta) +
|
||||
"}";
|
||||
return context.getString(R.string.glucose) + " " + formatNumber0decimalplaces.format(glucose) + "\n" +
|
||||
context.getString(R.string.delta) + " " + formatNumber0decimalplaces.format(delta) + "\n" +
|
||||
context.getString(R.string.avgdelta) + " " + formatNumber2decimalplaces.format(avgdelta);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ public class APSResult {
|
|||
DecimalFormat formatNumber2decimalplaces = new DecimalFormat("0.00");
|
||||
|
||||
if (changeRequested)
|
||||
return context.getString(R.string.rate) + " " + formatNumber2decimalplaces.format(rate) + " U/h\n" +
|
||||
context.getString(R.string.duration) + " " + formatNumber0decimalplaces.format(duration) + " min\n" +
|
||||
context.getString(R.string.reason) + " " + reason;
|
||||
return context.getString(R.string.rate) + " " + formatNumber2decimalplaces.format(rate) + " U/h\n" +
|
||||
context.getString(R.string.duration) + " " + formatNumber0decimalplaces.format(duration) + " min\n" +
|
||||
context.getString(R.string.reason) + " " + reason;
|
||||
else
|
||||
return MainApp.instance().getApplicationContext().getString(R.string.nochangerequested);
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener
|
|||
}
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
|
@ -187,7 +188,7 @@ public class LowSuspendFragment extends Fragment implements View.OnClickListener
|
|||
request.changeRequested = false;
|
||||
request.reason = getString(R.string.nochangerequested);
|
||||
}
|
||||
} else if (tempBasalRate == 0d){
|
||||
} else if (tempBasalRate == 0d) {
|
||||
request.changeRequested = true;
|
||||
request.rate = baseBasalRate;
|
||||
request.duration = 30;
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.Overview;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -18,15 +19,17 @@ import com.squareup.otto.Subscribe;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
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.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.plugins.PluginBase;
|
||||
|
@ -36,7 +39,9 @@ import info.nightscout.client.data.NSProfile;
|
|||
public class OverviewFragment extends Fragment implements PluginBase {
|
||||
private static Logger log = LoggerFactory.getLogger(OverviewFragment.class);
|
||||
|
||||
TextView bg;
|
||||
TextView bgView;
|
||||
TextView timeAgoView;
|
||||
TextView deltaView;
|
||||
GraphView bgGraph;
|
||||
|
||||
|
||||
|
@ -65,7 +70,9 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.overview_fragment, container, false);
|
||||
bg = (TextView) view.findViewById(R.id.overview_bg);
|
||||
bgView = (TextView) view.findViewById(R.id.overview_bg);
|
||||
timeAgoView = (TextView) view.findViewById(R.id.overview_timeago);
|
||||
deltaView = (TextView) view.findViewById(R.id.overview_delta);
|
||||
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
|
||||
|
||||
updateData();
|
||||
|
@ -82,18 +89,39 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
}
|
||||
|
||||
private void updateData() {
|
||||
BgReading bgReading = MainApp.getDbHelper().lastBg();
|
||||
BgReading actualBG = MainApp.getDbHelper().actualBg();
|
||||
BgReading lastBG = MainApp.getDbHelper().lastBg();
|
||||
NSProfile profile = MainApp.getNSProfile();
|
||||
if (profile != null && bgReading != null && bg != null) {
|
||||
bg.setText(bgReading.valueToUnitsToString(profile.getUnits()));
|
||||
BgReading.units = profile.getUnits();
|
||||
} else
|
||||
if (profile == null)
|
||||
return;
|
||||
|
||||
String units = profile.getUnits();
|
||||
|
||||
// Skip if not initialized yet
|
||||
if (bgGraph == null)
|
||||
return;
|
||||
|
||||
if (profile != null && lastBG != null && bgView != null) {
|
||||
bgView.setText(lastBG.valueToUnitsToString(profile.getUnits()));
|
||||
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
|
||||
deltaView.setText(NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units);
|
||||
BgReading.units = profile.getUnits();
|
||||
} else
|
||||
return;
|
||||
|
||||
// **** BG value ****
|
||||
Integer flag = bgView.getPaintFlags();
|
||||
if (actualBG == null) {
|
||||
flag |= Paint.STRIKE_THRU_TEXT_FLAG;
|
||||
} else
|
||||
flag &= ~Paint.STRIKE_THRU_TEXT_FLAG;
|
||||
bgView.setPaintFlags(flag);
|
||||
|
||||
Long agoMsec = new Date().getTime() - lastBG.timestamp;
|
||||
int agoMin = (int) (agoMsec / 60d / 60d / 1000d);
|
||||
timeAgoView.setText(agoMin + " " + getString(R.string.minago));
|
||||
|
||||
// **** BG graph ****
|
||||
// allign to hours
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(new Date().getTime());
|
||||
|
@ -105,29 +133,30 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
long toTime = calendar.getTimeInMillis();
|
||||
long fromTime = toTime - hoursToFetch * 60 * 60 * 1000l;
|
||||
|
||||
Double lowLine = 80d; // TODO: make this customisable
|
||||
Double highLine = 180d;
|
||||
Double maxY = 400d; // TODO: add some scale support
|
||||
|
||||
String units = profile.getUnits();
|
||||
if (units.equals(Constants.MMOL)) {
|
||||
lowLine = 4d;
|
||||
highLine = 10d;
|
||||
maxY = 20d;
|
||||
}
|
||||
Double lowLine = NSProfile.toUnits(80d, 4d, units); // TODO: make this customisable
|
||||
Double highLine = NSProfile.toUnits(180d, 10d, units);
|
||||
Double maxY = NSProfile.toUnits(400d , 20d, units); // TODO: add some scale support
|
||||
|
||||
List<BgReading> bgReadingsArray = MainApp.getDbHelper().getDataFromTime(fromTime);
|
||||
BgReading[] bgReadings = new BgReading[bgReadingsArray.size()];
|
||||
bgReadings = bgReadingsArray.toArray(bgReadings);
|
||||
List<BgReading> inRangeArray = new ArrayList<BgReading>();
|
||||
List<BgReading> outOfRangeArray = new ArrayList<BgReading>();
|
||||
|
||||
if (bgReadings.length == 0)
|
||||
if (bgReadingsArray.size() == 0)
|
||||
return;
|
||||
|
||||
PointsGraphSeries<BgReading> series = new PointsGraphSeries<BgReading>(bgReadings);
|
||||
bgGraph.addSeries(series);
|
||||
series.setShape(PointsGraphSeries.Shape.POINT);
|
||||
series.setSize(5);
|
||||
series.setColor(Color.GREEN);
|
||||
Iterator<BgReading> it = bgReadingsArray.iterator();
|
||||
while (it.hasNext()) {
|
||||
BgReading bg = it.next();
|
||||
if (bg.valueToUnits(units) < lowLine || bg.valueToUnits(units) > highLine)
|
||||
outOfRangeArray.add(bg);
|
||||
else
|
||||
inRangeArray.add(bg);
|
||||
}
|
||||
BgReading[] inRange = new BgReading[inRangeArray.size()];
|
||||
BgReading[] outOfRange = new BgReading[outOfRangeArray.size()];
|
||||
inRange = inRangeArray.toArray(inRange);
|
||||
outOfRange = outOfRangeArray.toArray(outOfRange);
|
||||
|
||||
|
||||
// targets
|
||||
LineGraphSeries<DataPoint> seriesLow = new LineGraphSeries<DataPoint>(new DataPoint[]{
|
||||
|
@ -145,6 +174,22 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
bgGraph.addSeries(seriesHigh);
|
||||
|
||||
|
||||
if (inRange.length > 0) {
|
||||
PointsGraphSeries<BgReading> seriesInRage = new PointsGraphSeries<BgReading>(inRange);
|
||||
bgGraph.addSeries(seriesInRage);
|
||||
seriesInRage.setShape(PointsGraphSeries.Shape.POINT);
|
||||
seriesInRage.setSize(5);
|
||||
seriesInRage.setColor(Color.GREEN);
|
||||
}
|
||||
|
||||
if (outOfRange.length > 0) {
|
||||
PointsGraphSeries<BgReading> seriesOutOfRange = new PointsGraphSeries<BgReading>(outOfRange);
|
||||
bgGraph.addSeries(seriesOutOfRange);
|
||||
seriesOutOfRange.setShape(PointsGraphSeries.Shape.POINT);
|
||||
seriesOutOfRange.setSize(5);
|
||||
seriesOutOfRange.setColor(Color.RED);
|
||||
}
|
||||
|
||||
// set manual x bounds to have nice steps
|
||||
bgGraph.getViewport().setMaxX(toTime);
|
||||
bgGraph.getViewport().setMinX(fromTime);
|
||||
|
@ -152,8 +197,6 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
bgGraph.getGridLabelRenderer().setLabelFormatter(new TimeAsXAxisLabelFormatter(getActivity(), "HH"));
|
||||
bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
|
||||
|
||||
String test = new SimpleDateFormat("HH").format(calendar.getTimeInMillis());
|
||||
|
||||
// set manual y bounds to have nice steps
|
||||
bgGraph.getViewport().setMaxY(maxY);
|
||||
bgGraph.getViewport().setMinY(0);
|
||||
|
|
|
@ -299,4 +299,21 @@ public class NSProfile {
|
|||
if (units.equals(Constants.MGDL)) return value;
|
||||
else return value * Constants.MMOLL_TO_MGDL;
|
||||
}
|
||||
|
||||
public static Double fromMgdlToUnits(Double value, String units) {
|
||||
if (units.equals(Constants.MGDL)) return value;
|
||||
else return value * Constants.MGDL_TO_MMOLL;
|
||||
}
|
||||
|
||||
public static Double toUnits(Double valueInMgdl, Double valueInMmol, String units) {
|
||||
if (units.equals(Constants.MGDL)) return valueInMgdl;
|
||||
else return valueInMmol;
|
||||
}
|
||||
|
||||
public static String toUnitsString(Double valueInMgdl, Double valueInMmol, String units) {
|
||||
DecimalFormat formatNumber0decimalplaces = new DecimalFormat("0");
|
||||
DecimalFormat formatNumber1decimalplaces = new DecimalFormat("0.0");
|
||||
if (units.equals(Constants.MGDL)) return formatNumber0decimalplaces.format(valueInMgdl);
|
||||
else return formatNumber1decimalplaces.format(valueInMmol);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,41 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_bg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="left|top"
|
||||
android:textSize="100dp" />
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/overview_bg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="left|top"
|
||||
android:textSize="100dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="top"
|
||||
android:layout_marginTop="10dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:id="@+id/overview_timeago"
|
||||
android:layout_marginLeft="10dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:id="@+id/overview_delta"
|
||||
android:layout_marginLeft="10dp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.jjoe64.graphview.GraphView
|
||||
android:id="@+id/overview_bggraph"
|
||||
|
|
|
@ -83,5 +83,9 @@
|
|||
<string name="rate">Rate:</string>
|
||||
<string name="duration">Duration:</string>
|
||||
<string name="reason">Reason:</string>
|
||||
<string name="glucose">Glucose:</string>
|
||||
<string name="delta">Delta:</string>
|
||||
<string name="avgdelta">Avg. delta:</string>
|
||||
<string name="minago">min ago</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue