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);
}
}
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);
}
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()));
}
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);
}
}
Aggregations