Search in sources :

Example 11 with MeasurementView

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

the class DataEntryActivity method setViewMode.

private void setViewMode(MeasurementView.MeasurementViewMode viewMode) {
    measurementViewMode = viewMode;
    int dateTimeVisibility = View.VISIBLE;
    switch(viewMode) {
        case VIEW:
            saveButton.setVisible(false);
            editButton.setVisible(true);
            expandButton.setVisible(true);
            deleteButton.setVisible(true);
            ((LinearLayout) txtDataNr.getParent()).setVisibility(View.VISIBLE);
            btnLeft.setVisibility(View.VISIBLE);
            btnRight.setVisibility(View.VISIBLE);
            btnLeft.setEnabled(previousMeasurement != null);
            btnRight.setEnabled(nextMeasurement != null);
            dateTimeVisibility = View.GONE;
            break;
        case EDIT:
            saveButton.setVisible(true);
            editButton.setVisible(false);
            expandButton.setVisible(true);
            deleteButton.setVisible(true);
            ((LinearLayout) txtDataNr.getParent()).setVisibility(View.VISIBLE);
            btnLeft.setVisibility(View.VISIBLE);
            btnRight.setVisibility(View.VISIBLE);
            btnLeft.setEnabled(false);
            btnRight.setEnabled(false);
            break;
        case ADD:
            saveButton.setVisible(true);
            editButton.setVisible(false);
            expandButton.setVisible(false);
            deleteButton.setVisible(false);
            ((LinearLayout) txtDataNr.getParent()).setVisibility(View.GONE);
            break;
    }
    for (MeasurementView measurement : dataEntryMeasurements) {
        if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) {
            measurement.setVisibility(dateTimeVisibility);
        }
        measurement.setEditMode(viewMode);
    }
}
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) TimeMeasurementView(com.health.openscale.gui.views.TimeMeasurementView) DateMeasurementView(com.health.openscale.gui.views.DateMeasurementView) LinearLayout(android.widget.LinearLayout)

Example 12 with MeasurementView

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

the class DataEntryActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.saveButton:
            final boolean isEdit = scaleMeasurement.getId() > 0;
            saveScaleData();
            if (isEdit) {
                setViewMode(MeasurementView.MeasurementViewMode.VIEW);
            } else {
                finish();
            }
            return true;
        case R.id.expandButton:
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            final boolean expand = !prefs.getBoolean(PREF_EXPAND, true);
            prefs.edit().putBoolean(PREF_EXPAND, expand).apply();
            for (MeasurementView measurement : dataEntryMeasurements) {
                measurement.setExpand(expand);
            }
            return true;
        case R.id.editButton:
            setViewMode(MeasurementView.MeasurementViewMode.EDIT);
            return true;
        case R.id.deleteButton:
            deleteMeasurement();
            return true;
        // (e.g. the table view) and not always go to the overview.
        case android.R.id.home:
            onBackPressed();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
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)

Example 13 with MeasurementView

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

the class DataEntryActivity method updateOnView.

private void updateOnView() {
    int id = 0;
    if (getIntent().hasExtra(EXTRA_ID)) {
        id = getIntent().getExtras().getInt(EXTRA_ID);
    }
    if (scaleMeasurement == null || scaleMeasurement.getId() != id) {
        isDirty = false;
        scaleMeasurement = null;
        previousMeasurement = null;
        nextMeasurement = null;
    }
    OpenScale openScale = OpenScale.getInstance(context);
    if (id > 0) {
        // Show selected scale data
        if (scaleMeasurement == null) {
            ScaleMeasurement[] tupleScaleData = openScale.getTupleScaleData(id);
            previousMeasurement = tupleScaleData[0];
            scaleMeasurement = tupleScaleData[1].clone();
            nextMeasurement = tupleScaleData[2];
            btnLeft.setEnabled(previousMeasurement != null);
            btnRight.setEnabled(nextMeasurement != null);
        }
    } else {
        if (openScale.getScaleMeasurementList().isEmpty()) {
            // Show default values
            scaleMeasurement = new ScaleMeasurement();
            scaleMeasurement.setWeight(openScale.getSelectedScaleUser().getInitialWeight());
        } else {
            // Show the last scale data as default
            scaleMeasurement = openScale.getScaleMeasurementList().get(0).clone();
            scaleMeasurement.setId(0);
            scaleMeasurement.setDateTime(new Date());
            scaleMeasurement.setComment("");
        }
        isDirty = true;
        // clears these values.
        for (MeasurementView measurement : dataEntryMeasurements) {
            if (!measurement.isVisible()) {
                measurement.clearIn(scaleMeasurement);
            }
        }
    }
    for (MeasurementView measurement : dataEntryMeasurements) {
        measurement.loadFrom(scaleMeasurement, previousMeasurement);
    }
    txtDataNr.setMinWidth(txtDataNr.getWidth());
    txtDataNr.setText(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(scaleMeasurement.getDateTime()));
}
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) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) OpenScale(com.health.openscale.core.OpenScale) Date(java.util.Date)

Example 14 with MeasurementView

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

the class MeasurementPreferences method updateMeasurementPreferences.

private void updateMeasurementPreferences() {
    measurementCategory.removeAll();
    List<MeasurementView> measurementViews = MeasurementView.getMeasurementList(getActivity(), MeasurementView.DateTimeOrder.NONE);
    for (MeasurementView measurement : measurementViews) {
        Preference preference = new MeasurementOrderPreference(getActivity(), measurementCategory, measurement);
        preference.setKey(measurement.getSettings().getEnabledKey());
        preference.setDefaultValue(measurement.getSettings().isEnabledIgnoringDependencies());
        preference.setPersistent(true);
        preference.setEnabled(measurement.getSettings().areDependenciesEnabled());
        Drawable icon = measurement.getIcon();
        icon.setColorFilter(measurement.getForegroundColor(), PorterDuff.Mode.SRC_IN);
        preference.setIcon(icon);
        preference.setTitle(measurement.getName());
        preference.setSummary(measurement.getPreferenceSummary());
        measurementCategory.addPreference(preference);
    }
}
Also used : WeightMeasurementView(com.health.openscale.gui.views.WeightMeasurementView) MeasurementView(com.health.openscale.gui.views.MeasurementView) Preference(android.preference.Preference) Drawable(android.graphics.drawable.Drawable)

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