diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileGraph.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileGraph.java new file mode 100644 index 0000000000..e8acbd9ddd --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileGraph.java @@ -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 basalSeries = null; + List 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()); + } +} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java index a34146f04a..be8c9f5de6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/ProfileViewerDialog.java @@ -42,6 +42,7 @@ public class ProfileViewerDialog extends DialogFragment { private LinearLayout dateLayout; private TextView dateTextView; private Button refreshButton; + private ProfileGraph basalGraph; public static ProfileViewerDialog newInstance(long time) { ProfileViewerDialog dialog = new ProfileViewerDialog(); @@ -65,6 +66,7 @@ public class ProfileViewerDialog extends DialogFragment { Bundle savedInstanceState) { View layout = inflater.inflate(R.layout.profileviewer_fragment, container, false); + noProfile = (TextView) layout.findViewById(R.id.profileview_noprofile); units = (TextView) layout.findViewById(R.id.profileview_units); 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.setVisibility(View.VISIBLE); dateTextView = (TextView) layout.findViewById(R.id.profileview_date); + basalGraph = (ProfileGraph) layout.findViewById(R.id.basal_graph); setContent(); 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() { Profile profile = null; ProfileSwitch profileSwitch = MainApp.getConfigBuilder().getProfileSwitchFromHistory(time); @@ -101,6 +114,7 @@ public class ProfileViewerDialog extends DialogFragment { isf.setText(profile.getIsfList()); basal.setText(profile.getBasalList()); target.setText(profile.getTargetList()); + basalGraph.show(profile); } else { noProfile.setVisibility(View.VISIBLE); } diff --git a/app/src/main/res/layout/profileviewer_fragment.xml b/app/src/main/res/layout/profileviewer_fragment.xml index f0e385e86b..9f6da2acfb 100644 --- a/app/src/main/res/layout/profileviewer_fragment.xml +++ b/app/src/main/res/layout/profileviewer_fragment.xml @@ -333,7 +333,11 @@ android:textSize="14sp" /> - +