Merge pull request #765 from AdrianLxM/dev190315
Draw basals in Profile Viewer
This commit is contained in:
commit
390e5d6d11
|
@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
|||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileGraph;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
|
||||
/**
|
||||
|
@ -42,6 +43,8 @@ public class ProfileViewDialog extends DialogFragment {
|
|||
private TextView isf;
|
||||
private TextView basal;
|
||||
private TextView target;
|
||||
private ProfileGraph basalGraph;
|
||||
|
||||
|
||||
private Button refreshButton;
|
||||
|
||||
|
@ -70,7 +73,7 @@ public class ProfileViewDialog extends DialogFragment {
|
|||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
basalGraph = (ProfileGraph) layout.findViewById(R.id.basal_graph);
|
||||
setContent();
|
||||
return layout;
|
||||
}
|
||||
|
@ -99,6 +102,7 @@ public class ProfileViewDialog extends DialogFragment {
|
|||
isf.setText(profile.getIsfList());
|
||||
basal.setText(profile.getBasalList());
|
||||
target.setText(profile.getTargetList());
|
||||
basalGraph.show(store.getDefaultProfile());
|
||||
} else {
|
||||
noProfile.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package info.nightscout.androidaps.plugins.Treatments.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
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.Profile;
|
||||
|
||||
/**
|
||||
* 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 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,21 @@ 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() {
|
||||
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 +113,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);
|
||||
}
|
||||
|
|
|
@ -333,7 +333,11 @@
|
|||
android:textSize="14sp" />
|
||||
|
||||
</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
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
|
|
Loading…
Reference in a new issue