Search in sources :

Example 1 with BMIMeasurementView

use of com.health.openscale.gui.measurement.BMIMeasurementView 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;
}
Also used : Legend(com.github.mikephil.charting.components.Legend) BoneMeasurementView(com.health.openscale.gui.measurement.BoneMeasurementView) ArrayList(java.util.ArrayList) ChartMarkerView(com.health.openscale.gui.measurement.ChartMarkerView) WeightMeasurementView(com.health.openscale.gui.measurement.WeightMeasurementView) BMIMeasurementView(com.health.openscale.gui.measurement.BMIMeasurementView) WaterMeasurementView(com.health.openscale.gui.measurement.WaterMeasurementView) ChartMarkerView(com.health.openscale.gui.measurement.ChartMarkerView) MarkerView(com.github.mikephil.charting.components.MarkerView) FatMeasurementView(com.health.openscale.gui.measurement.FatMeasurementView) OnBackPressedCallback(androidx.activity.OnBackPressedCallback) MuscleMeasurementView(com.health.openscale.gui.measurement.MuscleMeasurementView) LegendEntry(com.github.mikephil.charting.components.LegendEntry) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

OnBackPressedCallback (androidx.activity.OnBackPressedCallback)1 Legend (com.github.mikephil.charting.components.Legend)1 LegendEntry (com.github.mikephil.charting.components.LegendEntry)1 MarkerView (com.github.mikephil.charting.components.MarkerView)1 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)1 BMIMeasurementView (com.health.openscale.gui.measurement.BMIMeasurementView)1 BoneMeasurementView (com.health.openscale.gui.measurement.BoneMeasurementView)1 ChartMarkerView (com.health.openscale.gui.measurement.ChartMarkerView)1 FatMeasurementView (com.health.openscale.gui.measurement.FatMeasurementView)1 MuscleMeasurementView (com.health.openscale.gui.measurement.MuscleMeasurementView)1 WaterMeasurementView (com.health.openscale.gui.measurement.WaterMeasurementView)1 WeightMeasurementView (com.health.openscale.gui.measurement.WeightMeasurementView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1