use of com.health.openscale.gui.measurement.WeightMeasurementView in project openScale by oliexdev.
the class StatisticsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
statisticsView = inflater.inflate(R.layout.fragment_statistics, container, false);
txtGoalWeight = statisticsView.findViewById(R.id.txtGoalWeight);
txtGoalWeight.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtGoalDiff = statisticsView.findViewById(R.id.txtGoalDiff);
txtGoalDiff.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtGoalDayLeft = statisticsView.findViewById(R.id.txtGoalDayLeft);
txtGoalDayLeft.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtLabelGoalWeight = statisticsView.findViewById(R.id.txtLabelGoalWeight);
txtLabelGoalWeight.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtLabelGoalDiff = statisticsView.findViewById(R.id.txtLabelGoalDiff);
txtLabelGoalDiff.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtLabelDayLeft = statisticsView.findViewById(R.id.txtLabelDayLeft);
txtLabelDayLeft.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
viewMeasurementsStatistics = new ArrayList<>();
viewMeasurementsStatistics.add(new WeightMeasurementView(statisticsView.getContext()));
viewMeasurementsStatistics.add(new WaterMeasurementView(statisticsView.getContext()));
viewMeasurementsStatistics.add(new MuscleMeasurementView(statisticsView.getContext()));
viewMeasurementsStatistics.add(new FatMeasurementView(statisticsView.getContext()));
viewMeasurementsStatistics.add(new BoneMeasurementView(statisticsView.getContext()));
viewMeasurementsStatistics.add(new BMIMeasurementView(statisticsView.getContext()));
ArrayList<LegendEntry> legendEntriesWeek = new ArrayList<>();
for (int i = 0; i < viewMeasurementsStatistics.size(); i++) {
LegendEntry legendEntry = new LegendEntry();
legendEntry.label = i + " - " + viewMeasurementsStatistics.get(i).getName().toString();
legendEntriesWeek.add(legendEntry);
}
MarkerView mv = new ChartMarkerView(statisticsView.getContext(), R.layout.chart_markerview);
radarChartWeek = statisticsView.findViewById(R.id.radarPastWeek);
radarChartWeek.getXAxis().setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
radarChartWeek.getDescription().setEnabled(false);
radarChartWeek.getYAxis().setEnabled(false);
radarChartWeek.setExtraTopOffset(10);
radarChartWeek.setRotationEnabled(false);
Legend weekLegend = radarChartWeek.getLegend();
weekLegend.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
weekLegend.setWordWrapEnabled(true);
weekLegend.setExtra(legendEntriesWeek);
weekLegend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
mv.setChartView(radarChartWeek);
radarChartWeek.setMarker(mv);
radarChartMonth = statisticsView.findViewById(R.id.radarPastMonth);
radarChartMonth.getXAxis().setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
radarChartMonth.getDescription().setEnabled(false);
radarChartMonth.getYAxis().setEnabled(false);
radarChartMonth.setExtraTopOffset(10);
radarChartMonth.setRotationEnabled(false);
Legend monthLegend = radarChartMonth.getLegend();
monthLegend.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
monthLegend.setWordWrapEnabled(true);
monthLegend.setExtra(legendEntriesWeek);
monthLegend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
mv.setChartView(radarChartMonth);
radarChartMonth.setMarker(mv);
OpenScale.getInstance().getScaleMeasurementsLiveData().observe(getViewLifecycleOwner(), new Observer<List<ScaleMeasurement>>() {
@Override
public void onChanged(List<ScaleMeasurement> scaleMeasurements) {
updateOnView(scaleMeasurements);
}
});
OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
requireActivity().finish();
}
};
requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), onBackPressedCallback);
return statisticsView;
}
Aggregations