Search in sources :

Example 6 with MeasurementView

use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.

the class DataEntryActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dataentry);
    Toolbar toolbar = (Toolbar) findViewById(R.id.dataEntryToolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("");
    context = this;
    tableLayoutDataEntry = (TableLayout) findViewById(R.id.tableLayoutDataEntry);
    dataEntryMeasurements = MeasurementView.getMeasurementList(context, MeasurementView.DateTimeOrder.LAST);
    txtDataNr = (TextView) findViewById(R.id.txtDataNr);
    btnLeft = (Button) findViewById(R.id.btnLeft);
    btnRight = (Button) findViewById(R.id.btnRight);
    btnLeft.setVisibility(View.INVISIBLE);
    btnRight.setVisibility(View.INVISIBLE);
    btnLeft.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            moveLeft();
        }
    });
    btnRight.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            moveRight();
        }
    });
    final MeasurementView.MeasurementViewMode mode = isAddActivity() ? MeasurementView.MeasurementViewMode.ADD : MeasurementView.MeasurementViewMode.VIEW;
    for (MeasurementView measurement : dataEntryMeasurements) {
        measurement.setEditMode(mode);
    }
    updateOnView();
    onMeasurementViewUpdateListener updateListener = new onMeasurementViewUpdateListener();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    final boolean expand = isAddActivity() ? false : prefs.getBoolean(PREF_EXPAND, true);
    for (MeasurementView measurement : dataEntryMeasurements) {
        tableLayoutDataEntry.addView(measurement);
        measurement.setOnUpdateListener(updateListener);
        measurement.setExpand(expand);
    }
}
Also used : TimeMeasurementView(com.health.openscale.gui.views.TimeMeasurementView) WeightMeasurementView(com.health.openscale.gui.views.WeightMeasurementView) DateMeasurementView(com.health.openscale.gui.views.DateMeasurementView) MeasurementView(com.health.openscale.gui.views.MeasurementView) SharedPreferences(android.content.SharedPreferences) View(android.view.View) TimeMeasurementView(com.health.openscale.gui.views.TimeMeasurementView) WeightMeasurementView(com.health.openscale.gui.views.WeightMeasurementView) DateMeasurementView(com.health.openscale.gui.views.DateMeasurementView) TextView(android.widget.TextView) MeasurementView(com.health.openscale.gui.views.MeasurementView) Toolbar(android.support.v7.widget.Toolbar)

Example 7 with MeasurementView

use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.

the class OverviewFragment method updateLastLineChart.

private void updateLastLineChart(List<ScaleMeasurement> scaleMeasurementList) {
    final Calendar now = Calendar.getInstance();
    Calendar histCalendar = Calendar.getInstance();
    scaleMeasurementLastDays = new ArrayList<>();
    List<AxisValue> axisValues = new ArrayList<>();
    int max_i = Math.min(7, scaleMeasurementList.size());
    for (int i = 0; i < max_i; ++i) {
        ScaleMeasurement measurement = scaleMeasurementList.get(max_i - i - 1);
        scaleMeasurementLastDays.add(measurement);
        histCalendar.setTime(measurement.getDateTime());
        int days = DateTimeHelpers.daysBetween(now, histCalendar);
        String label = getResources().getQuantityString(R.plurals.label_days, Math.abs(days), days);
        axisValues.add(new AxisValue(i, label.toCharArray()));
    }
    List<Line> diagramLineList = new ArrayList<>();
    for (MeasurementView view : measurementViews) {
        if (!view.isVisible() || !view.getSettings().isInOverviewGraph() || !(view instanceof FloatMeasurementView)) {
            continue;
        }
        FloatMeasurementView measurementView = (FloatMeasurementView) view;
        Stack<PointValue> valuesStack = new Stack<PointValue>();
        for (int i = 0; i < max_i; ++i) {
            ScaleMeasurement measurement = scaleMeasurementList.get(max_i - i - 1);
            measurementView.loadFrom(measurement, null);
            if (measurementView.getValue() != 0.0f) {
                valuesStack.push(new PointValue(i, measurementView.getValue()));
            }
        }
        diagramLineList.add(new Line(valuesStack).setColor(measurementView.getColor()).setHasLabels(prefs.getBoolean("labelsEnable", true)).setHasPoints(prefs.getBoolean("pointsEnable", true)).setFormatter(new SimpleLineChartValueFormatter(1)));
    }
    LineChartData lineData = new LineChartData(diagramLineList);
    lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(txtTitleLastMeasurement.getCurrentTextColor()));
    lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(5).setTextColor(txtTitleLastMeasurement.getCurrentTextColor()));
    lineChartLast.setLineChartData(lineData);
    lineChartLast.setViewportCalculationEnabled(true);
    lineChartLast.setZoomEnabled(false);
}
Also used : BMRMeasurementView(com.health.openscale.gui.views.BMRMeasurementView) FloatMeasurementView(com.health.openscale.gui.views.FloatMeasurementView) MeasurementView(com.health.openscale.gui.views.MeasurementView) PointValue(lecho.lib.hellocharts.model.PointValue) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Stack(java.util.Stack) SimpleLineChartValueFormatter(lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter) Line(lecho.lib.hellocharts.model.Line) AxisValue(lecho.lib.hellocharts.model.AxisValue) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) LineChartData(lecho.lib.hellocharts.model.LineChartData) Axis(lecho.lib.hellocharts.model.Axis) FloatMeasurementView(com.health.openscale.gui.views.FloatMeasurementView)

Example 8 with MeasurementView

use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.

the class OverviewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    overviewView = inflater.inflate(R.layout.fragment_overview, container, false);
    userLineSeparator = overviewView.findViewById(R.id.userLineSeparator);
    context = overviewView.getContext();
    txtTitleUser = (TextView) overviewView.findViewById(R.id.txtTitleUser);
    txtTitleLastMeasurement = (TextView) overviewView.findViewById(R.id.txtTitleLastMeasurment);
    tableOverviewLayout = (TableLayout) overviewView.findViewById(R.id.tableLayoutMeasurements);
    pieChartLast = (PieChartView) overviewView.findViewById(R.id.pieChartLast);
    lineChartLast = (LineChartView) overviewView.findViewById(R.id.lineChartLast);
    spinUser = (Spinner) overviewView.findViewById(R.id.spinUser);
    lineChartLast.setOnValueTouchListener(new LineChartTouchListener());
    pieChartLast.setOnValueTouchListener(new PieChartLastTouchListener());
    pieChartLast.setChartRotationEnabled(false);
    measurementViews = MeasurementView.getMeasurementList(getContext(), MeasurementView.DateTimeOrder.NONE);
    for (MeasurementView measurement : measurementViews) {
        tableOverviewLayout.addView(measurement);
    }
    userSelectedData = null;
    spinUserAdapter = new ArrayAdapter<>(overviewView.getContext(), R.layout.support_simple_spinner_dropdown_item, new ArrayList<String>());
    spinUser.setAdapter(spinUserAdapter);
    // Set item select listener after spinner is created because otherwise item listener fires a lot!?!?
    spinUser.post(new Runnable() {

        public void run() {
            spinUser.setOnItemSelectedListener(new spinUserSelectionListener());
            updateUserSelection();
        }
    });
    txtTitleUser.setText(getResources().getString(R.string.label_title_user).toUpperCase());
    txtTitleLastMeasurement.setText(getResources().getString(R.string.label_title_last_measurement).toUpperCase());
    prefs = PreferenceManager.getDefaultSharedPreferences(overviewView.getContext());
    OpenScale.getInstance(getContext()).registerFragment(this);
    return overviewView;
}
Also used : BMRMeasurementView(com.health.openscale.gui.views.BMRMeasurementView) FloatMeasurementView(com.health.openscale.gui.views.FloatMeasurementView) MeasurementView(com.health.openscale.gui.views.MeasurementView) ArrayList(java.util.ArrayList)

Example 9 with MeasurementView

use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.

the class OverviewFragment method updateOnView.

@Override
public void updateOnView(List<ScaleMeasurement> scaleMeasurementList) {
    if (scaleMeasurementList.isEmpty()) {
        lastScaleMeasurement = new ScaleMeasurement();
    } else if (userSelectedData != null) {
        lastScaleMeasurement = userSelectedData;
    } else {
        lastScaleMeasurement = scaleMeasurementList.get(0);
    }
    ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(context).getTupleScaleData(lastScaleMeasurement.getId());
    ScaleMeasurement prevScaleMeasurement = tupleScaleData[0];
    updateUserSelection();
    updateLastPieChart();
    updateLastLineChart(scaleMeasurementList);
    for (MeasurementView measurement : measurementViews) {
        measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement);
    }
}
Also used : BMRMeasurementView(com.health.openscale.gui.views.BMRMeasurementView) FloatMeasurementView(com.health.openscale.gui.views.FloatMeasurementView) MeasurementView(com.health.openscale.gui.views.MeasurementView) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement)

Example 10 with MeasurementView

use of com.health.openscale.gui.views.MeasurementView in project openScale by oliexdev.

the class OverviewFragment method updateLastPieChart.

private void updateLastPieChart() {
    List<SliceValue> arcValuesLast = new ArrayList<>();
    for (MeasurementView view : measurementViews) {
        if (view instanceof FloatMeasurementView) {
            FloatMeasurementView measurementView = (FloatMeasurementView) view;
            if (measurementView instanceof BMRMeasurementView) {
                continue;
            }
            measurementView.loadFrom(lastScaleMeasurement, null);
            if (measurementView.getValue() != 0) {
                arcValuesLast.add(new SliceValue(measurementView.getValue(), measurementView.getColor()));
            }
        }
    }
    final Converters.WeightUnit unit = currentScaleUser.getScaleUnit();
    PieChartData pieChartData = new PieChartData(arcValuesLast);
    pieChartData.setHasLabels(false);
    pieChartData.setHasCenterCircle(true);
    pieChartData.setCenterText1(String.format("%.2f %s", lastScaleMeasurement.getConvertedWeight(unit), unit.toString()));
    pieChartData.setCenterText2(DateFormat.getDateInstance(DateFormat.MEDIUM).format(lastScaleMeasurement.getDateTime()));
    pieChartData.setCenterText1Color(txtTitleLastMeasurement.getCurrentTextColor());
    pieChartData.setCenterText2Color(txtTitleLastMeasurement.getCurrentTextColor());
    if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
        pieChartData.setCenterText1FontSize(20);
        pieChartData.setCenterText2FontSize(14);
    } else {
        pieChartData.setCenterText1FontSize(15);
        pieChartData.setCenterText2FontSize(12);
        pieChartData.setValueLabelTextSize(12);
    }
    pieChartLast.setPieChartData(pieChartData);
}
Also used : BMRMeasurementView(com.health.openscale.gui.views.BMRMeasurementView) FloatMeasurementView(com.health.openscale.gui.views.FloatMeasurementView) MeasurementView(com.health.openscale.gui.views.MeasurementView) BMRMeasurementView(com.health.openscale.gui.views.BMRMeasurementView) ArrayList(java.util.ArrayList) Converters(com.health.openscale.core.utils.Converters) PieChartData(lecho.lib.hellocharts.model.PieChartData) SliceValue(lecho.lib.hellocharts.model.SliceValue) FloatMeasurementView(com.health.openscale.gui.views.FloatMeasurementView)

Aggregations

MeasurementView (com.health.openscale.gui.views.MeasurementView)14 WeightMeasurementView (com.health.openscale.gui.views.WeightMeasurementView)8 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)5 BMRMeasurementView (com.health.openscale.gui.views.BMRMeasurementView)5 FloatMeasurementView (com.health.openscale.gui.views.FloatMeasurementView)5 ArrayList (java.util.ArrayList)5 DateMeasurementView (com.health.openscale.gui.views.DateMeasurementView)4 TimeMeasurementView (com.health.openscale.gui.views.TimeMeasurementView)4 Calendar (java.util.Calendar)3 SharedPreferences (android.content.SharedPreferences)2 ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 BoneMeasurementView (com.health.openscale.gui.views.BoneMeasurementView)2 FatMeasurementView (com.health.openscale.gui.views.FatMeasurementView)2 HipMeasurementView (com.health.openscale.gui.views.HipMeasurementView)2 LBWMeasurementView (com.health.openscale.gui.views.LBWMeasurementView)2 MuscleMeasurementView (com.health.openscale.gui.views.MuscleMeasurementView)2 WaistMeasurementView (com.health.openscale.gui.views.WaistMeasurementView)2 WaterMeasurementView (com.health.openscale.gui.views.WaterMeasurementView)2