draw basal in profile viewer
This commit is contained in:
parent
e9313c5b28
commit
212a9dcc94
3 changed files with 80 additions and 1 deletions
|
@ -0,0 +1,61 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Treatments.fragments;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import com.jjoe64.graphview.GraphView;
|
||||||
|
import com.jjoe64.graphview.series.DataPoint;
|
||||||
|
import com.jjoe64.graphview.series.LineGraphSeries;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.Iob;
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Adrian on 15.04.2018.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ProfileGraph extends GraphView {
|
||||||
|
|
||||||
|
public ProfileGraph(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProfileGraph(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void show(Profile profile) {
|
||||||
|
removeAllSeries();
|
||||||
|
|
||||||
|
LineGraphSeries<DataPoint> basalSeries = null;
|
||||||
|
List<DataPoint> basalArray = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int hour = 0; hour < 24; hour++) {
|
||||||
|
basalArray.add(new DataPoint(hour, profile.getBasal(new Integer(hour*60*60))));
|
||||||
|
basalArray.add(new DataPoint(hour+1, profile.getBasal(new Integer(hour*60*60))));
|
||||||
|
}
|
||||||
|
DataPoint[] basalDataPoints = new DataPoint[basalArray.size()];
|
||||||
|
basalDataPoints = basalArray.toArray(basalDataPoints);
|
||||||
|
addSeries(basalSeries = new LineGraphSeries<>(basalDataPoints));
|
||||||
|
basalSeries.setThickness(8);
|
||||||
|
basalSeries.setDrawBackground(true);
|
||||||
|
|
||||||
|
getViewport().setXAxisBoundsManual(true);
|
||||||
|
getViewport().setMinX(0);
|
||||||
|
getViewport().setMaxX(24);
|
||||||
|
|
||||||
|
getViewport().setYAxisBoundsManual(true);
|
||||||
|
getViewport().setMinY(0);
|
||||||
|
getViewport().setMaxY(profile.getMaxDailyBasal()*1.1);
|
||||||
|
|
||||||
|
getGridLabelRenderer().setNumHorizontalLabels(13);
|
||||||
|
getGridLabelRenderer().setVerticalLabelsColor(basalSeries.getColor());
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,6 +42,7 @@ public class ProfileViewerDialog extends DialogFragment {
|
||||||
private LinearLayout dateLayout;
|
private LinearLayout dateLayout;
|
||||||
private TextView dateTextView;
|
private TextView dateTextView;
|
||||||
private Button refreshButton;
|
private Button refreshButton;
|
||||||
|
private ProfileGraph basalGraph;
|
||||||
|
|
||||||
public static ProfileViewerDialog newInstance(long time) {
|
public static ProfileViewerDialog newInstance(long time) {
|
||||||
ProfileViewerDialog dialog = new ProfileViewerDialog();
|
ProfileViewerDialog dialog = new ProfileViewerDialog();
|
||||||
|
@ -65,6 +66,7 @@ public class ProfileViewerDialog extends DialogFragment {
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View layout = inflater.inflate(R.layout.profileviewer_fragment, container, false);
|
View layout = inflater.inflate(R.layout.profileviewer_fragment, container, false);
|
||||||
|
|
||||||
|
|
||||||
noProfile = (TextView) layout.findViewById(R.id.profileview_noprofile);
|
noProfile = (TextView) layout.findViewById(R.id.profileview_noprofile);
|
||||||
units = (TextView) layout.findViewById(R.id.profileview_units);
|
units = (TextView) layout.findViewById(R.id.profileview_units);
|
||||||
dia = (TextView) layout.findViewById(R.id.profileview_dia);
|
dia = (TextView) layout.findViewById(R.id.profileview_dia);
|
||||||
|
@ -80,11 +82,22 @@ public class ProfileViewerDialog extends DialogFragment {
|
||||||
dateLayout = (LinearLayout) layout.findViewById(R.id.profileview_datelayout);
|
dateLayout = (LinearLayout) layout.findViewById(R.id.profileview_datelayout);
|
||||||
dateLayout.setVisibility(View.VISIBLE);
|
dateLayout.setVisibility(View.VISIBLE);
|
||||||
dateTextView = (TextView) layout.findViewById(R.id.profileview_date);
|
dateTextView = (TextView) layout.findViewById(R.id.profileview_date);
|
||||||
|
basalGraph = (ProfileGraph) layout.findViewById(R.id.basal_graph);
|
||||||
|
|
||||||
setContent();
|
setContent();
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
|
||||||
|
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
|
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
||||||
|
getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
private void setContent() {
|
private void setContent() {
|
||||||
Profile profile = null;
|
Profile profile = null;
|
||||||
ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(time);
|
ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(time);
|
||||||
|
@ -101,6 +114,7 @@ public class ProfileViewerDialog extends DialogFragment {
|
||||||
isf.setText(profile.getIsfList());
|
isf.setText(profile.getIsfList());
|
||||||
basal.setText(profile.getBasalList());
|
basal.setText(profile.getBasalList());
|
||||||
target.setText(profile.getTargetList());
|
target.setText(profile.getTargetList());
|
||||||
|
basalGraph.show(profile);
|
||||||
} else {
|
} else {
|
||||||
noProfile.setVisibility(View.VISIBLE);
|
noProfile.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,7 +333,11 @@
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
<info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph
|
||||||
|
android:id="@+id/basal_graph"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_margin="20dp"
|
||||||
|
android:layout_height="100dip" />
|
||||||
<View
|
<View
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="2dip"
|
android:layout_height="2dip"
|
||||||
|
|
Loading…
Reference in a new issue