mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-30 11:40:23 +02:00
Refactor measurement views
Make all float measurements share a common base class and move all float related code there from MeasurementView. Also make DataEntryActivity only save a scale measurement when it has been changed.
This commit is contained in:
@@ -65,22 +65,6 @@ public class DataEntryActivity extends Activity {
|
|||||||
private ArrayList<MeasurementView> dataEntryMeasurements;
|
private ArrayList<MeasurementView> dataEntryMeasurements;
|
||||||
private TableLayout tableLayoutDataEntry;
|
private TableLayout tableLayoutDataEntry;
|
||||||
|
|
||||||
private WeightMeasurementView weightMeasurement;
|
|
||||||
private BMIMeasurementView bmiMeasurementView;
|
|
||||||
private WaterMeasurementView waterMeasurement;
|
|
||||||
private MuscleMeasurementView muscleMeasurement;
|
|
||||||
private LBWMeasurementView lbwMeasurement;
|
|
||||||
private FatMeasurementView fatMeasurement;
|
|
||||||
private WaistMeasurementView waistMeasurement;
|
|
||||||
private WHtRMeasurementView wHtRMeasurementView;
|
|
||||||
private HipMeasurementView hipMeasurement;
|
|
||||||
private WHRMeasurementView whrMeasurementView;
|
|
||||||
private BMRMeasurementView bmrMeasurementView;
|
|
||||||
private BoneMeasurementView boneMeasurementView;
|
|
||||||
private CommentMeasurementView commentMeasurement;
|
|
||||||
private DateMeasurementView dateMeasurement;
|
|
||||||
private TimeMeasurementView timeMeasurement;
|
|
||||||
|
|
||||||
private TextView txtDataNr;
|
private TextView txtDataNr;
|
||||||
private Button btnAdd;
|
private Button btnAdd;
|
||||||
private Button btnOk;
|
private Button btnOk;
|
||||||
@@ -91,7 +75,9 @@ public class DataEntryActivity extends Activity {
|
|||||||
private FloatingActionButton switchEditMode;
|
private FloatingActionButton switchEditMode;
|
||||||
private FloatingActionButton expandButton;
|
private FloatingActionButton expandButton;
|
||||||
|
|
||||||
private int id;
|
private ScaleMeasurement scaleMeasurement;
|
||||||
|
private ScaleMeasurement previousMeasurement;
|
||||||
|
private boolean isDirty;
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
@@ -105,41 +91,27 @@ public class DataEntryActivity extends Activity {
|
|||||||
|
|
||||||
tableLayoutDataEntry = (TableLayout) findViewById(R.id.tableLayoutDataEntry);
|
tableLayoutDataEntry = (TableLayout) findViewById(R.id.tableLayoutDataEntry);
|
||||||
|
|
||||||
weightMeasurement = new WeightMeasurementView(context);
|
|
||||||
bmiMeasurementView = new BMIMeasurementView(context);
|
|
||||||
waterMeasurement = new WaterMeasurementView(context);
|
|
||||||
muscleMeasurement = new MuscleMeasurementView(context);
|
|
||||||
lbwMeasurement = new LBWMeasurementView(context);
|
|
||||||
fatMeasurement = new FatMeasurementView(context);
|
|
||||||
boneMeasurementView = new BoneMeasurementView(context);
|
|
||||||
waistMeasurement = new WaistMeasurementView(context);
|
|
||||||
wHtRMeasurementView = new WHtRMeasurementView(context);
|
|
||||||
hipMeasurement = new HipMeasurementView(context);
|
|
||||||
whrMeasurementView = new WHRMeasurementView(context);
|
|
||||||
bmrMeasurementView = new BMRMeasurementView(context);
|
|
||||||
commentMeasurement = new CommentMeasurementView(context);
|
|
||||||
dateMeasurement = new DateMeasurementView(context);
|
|
||||||
timeMeasurement = new TimeMeasurementView(context);
|
|
||||||
|
|
||||||
dataEntryMeasurements = new ArrayList<>();
|
dataEntryMeasurements = new ArrayList<>();
|
||||||
dataEntryMeasurements.add(weightMeasurement);
|
dataEntryMeasurements.add(new WeightMeasurementView(context));
|
||||||
dataEntryMeasurements.add(bmiMeasurementView);
|
dataEntryMeasurements.add(new BMIMeasurementView(context));
|
||||||
dataEntryMeasurements.add(waterMeasurement);
|
dataEntryMeasurements.add(new WaterMeasurementView(context));
|
||||||
dataEntryMeasurements.add(muscleMeasurement);
|
dataEntryMeasurements.add(new MuscleMeasurementView(context));
|
||||||
dataEntryMeasurements.add(lbwMeasurement);
|
dataEntryMeasurements.add(new LBWMeasurementView(context));
|
||||||
dataEntryMeasurements.add(fatMeasurement);
|
dataEntryMeasurements.add(new FatMeasurementView(context));
|
||||||
dataEntryMeasurements.add(boneMeasurementView);
|
dataEntryMeasurements.add(new BoneMeasurementView(context));
|
||||||
dataEntryMeasurements.add(waistMeasurement);
|
dataEntryMeasurements.add(new WaistMeasurementView(context));
|
||||||
dataEntryMeasurements.add(wHtRMeasurementView);
|
dataEntryMeasurements.add(new WHtRMeasurementView(context));
|
||||||
dataEntryMeasurements.add(hipMeasurement);
|
dataEntryMeasurements.add(new HipMeasurementView(context));
|
||||||
dataEntryMeasurements.add(whrMeasurementView);
|
dataEntryMeasurements.add(new WHRMeasurementView(context));
|
||||||
dataEntryMeasurements.add(bmrMeasurementView);
|
dataEntryMeasurements.add(new BMRMeasurementView(context));
|
||||||
dataEntryMeasurements.add(commentMeasurement);
|
dataEntryMeasurements.add(new CommentMeasurementView(context));
|
||||||
dataEntryMeasurements.add(dateMeasurement);
|
dataEntryMeasurements.add(new DateMeasurementView(context));
|
||||||
dataEntryMeasurements.add(timeMeasurement);
|
dataEntryMeasurements.add(new TimeMeasurementView(context));
|
||||||
|
|
||||||
|
onMeasurementViewUpdateListener updateListener = new onMeasurementViewUpdateListener();
|
||||||
for (MeasurementView measurement : dataEntryMeasurements) {
|
for (MeasurementView measurement : dataEntryMeasurements) {
|
||||||
tableLayoutDataEntry.addView(measurement);
|
tableLayoutDataEntry.addView(measurement);
|
||||||
|
measurement.setOnUpdateListener(updateListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
txtDataNr = (TextView) findViewById(R.id.txtDataNr);
|
txtDataNr = (TextView) findViewById(R.id.txtDataNr);
|
||||||
@@ -165,22 +137,28 @@ public class DataEntryActivity extends Activity {
|
|||||||
updateOnView();
|
updateOnView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateOnView()
|
private void updateOnView()
|
||||||
{
|
{
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
|
||||||
for (MeasurementView measurement : dataEntryMeasurements) {
|
for (MeasurementView measurement : dataEntryMeasurements) {
|
||||||
measurement.setOnUpdateListener(null);
|
|
||||||
measurement.updatePreferences(prefs);
|
measurement.updatePreferences(prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int id = 0;
|
||||||
if (getIntent().hasExtra("id")) {
|
if (getIntent().hasExtra("id")) {
|
||||||
id = getIntent().getExtras().getInt("id");
|
id = getIntent().getExtras().getInt("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
ScaleMeasurement scaleMeasurement;
|
if (scaleMeasurement == null || scaleMeasurement.getId() != id) {
|
||||||
|
isDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
scaleMeasurement = null;
|
||||||
|
previousMeasurement = null;
|
||||||
|
|
||||||
OpenScale openScale = OpenScale.getInstance(context);
|
OpenScale openScale = OpenScale.getInstance(context);
|
||||||
|
boolean doExpand = false;
|
||||||
|
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
// keep edit mode state if we are moving to left or right
|
// keep edit mode state if we are moving to left or right
|
||||||
@@ -192,27 +170,17 @@ public class DataEntryActivity extends Activity {
|
|||||||
switchEditMode.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#D3D3D3")));
|
switchEditMode.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#D3D3D3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean doExpand = prefs.getBoolean(String.valueOf(expandButton.getId()), false);
|
doExpand = prefs.getBoolean(String.valueOf(expandButton.getId()), false);
|
||||||
if (doExpand) {
|
if (doExpand) {
|
||||||
expandButton.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_ORANGE));
|
expandButton.setBackgroundTintList(ColorStateList.valueOf(ChartUtils.COLOR_ORANGE));
|
||||||
} else {
|
} else {
|
||||||
expandButton.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#D3D3D3")));
|
expandButton.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#D3D3D3")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show selected scale data
|
||||||
ScaleMeasurement[] tupleScaleData = openScale.getTupleScaleData(id);
|
ScaleMeasurement[] tupleScaleData = openScale.getTupleScaleData(id);
|
||||||
ScaleMeasurement prevScaleMeasurement = tupleScaleData[0];
|
previousMeasurement = tupleScaleData[0];
|
||||||
scaleMeasurement = tupleScaleData[1];
|
scaleMeasurement = tupleScaleData[1].clone();
|
||||||
|
|
||||||
if (prevScaleMeasurement == null) {
|
|
||||||
prevScaleMeasurement = new ScaleMeasurement();
|
|
||||||
}
|
|
||||||
|
|
||||||
// show selected scale data
|
|
||||||
for (MeasurementView measurement : dataEntryMeasurements) {
|
|
||||||
measurement.updateValue(scaleMeasurement);
|
|
||||||
measurement.updateDiff(scaleMeasurement, prevScaleMeasurement);
|
|
||||||
measurement.setExpand(doExpand);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setViewMode(MeasurementView.MeasurementViewMode.ADD);
|
setViewMode(MeasurementView.MeasurementViewMode.ADD);
|
||||||
|
|
||||||
@@ -223,27 +191,26 @@ public class DataEntryActivity extends Activity {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Show the last scale data as default
|
// Show the last scale data as default
|
||||||
scaleMeasurement = openScale.getScaleMeasurementList().get(0);
|
scaleMeasurement = openScale.getScaleMeasurementList().get(0).clone();
|
||||||
|
scaleMeasurement.setId(0);
|
||||||
scaleMeasurement.setDateTime(new Date());
|
scaleMeasurement.setDateTime(new Date());
|
||||||
scaleMeasurement.setComment("");
|
scaleMeasurement.setComment("");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (MeasurementView measurement : dataEntryMeasurements) {
|
for (MeasurementView measurement : dataEntryMeasurements) {
|
||||||
measurement.updateValue(scaleMeasurement);
|
measurement.loadFrom(scaleMeasurement, previousMeasurement);
|
||||||
}
|
measurement.setExpand(doExpand);
|
||||||
}
|
}
|
||||||
|
|
||||||
txtDataNr.setText(DateFormat.getDateTimeInstance(
|
txtDataNr.setText(DateFormat.getDateTimeInstance(
|
||||||
DateFormat.LONG, DateFormat.SHORT).format(scaleMeasurement.getDateTime()));
|
DateFormat.LONG, DateFormat.SHORT).format(scaleMeasurement.getDateTime()));
|
||||||
|
|
||||||
onMeasurementViewUpdateListener updateListener = new onMeasurementViewUpdateListener();
|
|
||||||
for (MeasurementView measurement : dataEntryMeasurements) {
|
|
||||||
measurement.setOnUpdateListener(updateListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setViewMode(MeasurementView.MeasurementViewMode viewMode)
|
private void setViewMode(MeasurementView.MeasurementViewMode viewMode)
|
||||||
{
|
{
|
||||||
|
int dateTimeVisibility = View.VISIBLE;
|
||||||
|
|
||||||
switch (viewMode) {
|
switch (viewMode) {
|
||||||
case VIEW:
|
case VIEW:
|
||||||
btnOk.setVisibility(View.VISIBLE);
|
btnOk.setVisibility(View.VISIBLE);
|
||||||
@@ -253,8 +220,7 @@ public class DataEntryActivity extends Activity {
|
|||||||
btnRight.setVisibility(View.VISIBLE);
|
btnRight.setVisibility(View.VISIBLE);
|
||||||
expandButton.setVisibility(View.VISIBLE);
|
expandButton.setVisibility(View.VISIBLE);
|
||||||
switchEditMode.setVisibility(View.VISIBLE);
|
switchEditMode.setVisibility(View.VISIBLE);
|
||||||
dateMeasurement.setVisibility(View.GONE);
|
dateTimeVisibility = View.GONE;
|
||||||
timeMeasurement.setVisibility(View.GONE);
|
|
||||||
break;
|
break;
|
||||||
case EDIT:
|
case EDIT:
|
||||||
btnOk.setVisibility(View.VISIBLE);
|
btnOk.setVisibility(View.VISIBLE);
|
||||||
@@ -264,8 +230,6 @@ public class DataEntryActivity extends Activity {
|
|||||||
btnRight.setVisibility(View.VISIBLE);
|
btnRight.setVisibility(View.VISIBLE);
|
||||||
expandButton.setVisibility(View.VISIBLE);
|
expandButton.setVisibility(View.VISIBLE);
|
||||||
switchEditMode.setVisibility(View.VISIBLE);
|
switchEditMode.setVisibility(View.VISIBLE);
|
||||||
dateMeasurement.setVisibility(View.VISIBLE);
|
|
||||||
timeMeasurement.setVisibility(View.VISIBLE);
|
|
||||||
break;
|
break;
|
||||||
case ADD:
|
case ADD:
|
||||||
btnOk.setVisibility(View.GONE);
|
btnOk.setVisibility(View.GONE);
|
||||||
@@ -275,63 +239,29 @@ public class DataEntryActivity extends Activity {
|
|||||||
btnRight.setVisibility(View.GONE);
|
btnRight.setVisibility(View.GONE);
|
||||||
expandButton.setVisibility(View.GONE);
|
expandButton.setVisibility(View.GONE);
|
||||||
switchEditMode.setVisibility(View.GONE);
|
switchEditMode.setVisibility(View.GONE);
|
||||||
dateMeasurement.setVisibility(View.VISIBLE);
|
|
||||||
timeMeasurement.setVisibility(View.VISIBLE);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MeasurementView measurement : dataEntryMeasurements) {
|
for (MeasurementView measurement : dataEntryMeasurements) {
|
||||||
|
if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) {
|
||||||
|
measurement.setVisibility(dateTimeVisibility);
|
||||||
|
}
|
||||||
measurement.setEditMode(viewMode);
|
measurement.setEditMode(viewMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScaleMeasurement createScaleDataFromMeasurement() {
|
|
||||||
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
|
|
||||||
ScaleUser user = openScale.getSelectedScaleUser();
|
|
||||||
|
|
||||||
Calendar time = Calendar.getInstance();
|
|
||||||
time.setTime(timeMeasurement.getDateTime());
|
|
||||||
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
cal.setTime(dateMeasurement.getDateTime());
|
|
||||||
cal.set(Calendar.HOUR_OF_DAY, time.get(Calendar.HOUR_OF_DAY));
|
|
||||||
cal.set(Calendar.MINUTE, time.get(Calendar.MINUTE));
|
|
||||||
cal.set(Calendar.SECOND, 0);
|
|
||||||
cal.set(Calendar.MILLISECOND, 0);
|
|
||||||
|
|
||||||
ScaleMeasurement scaleMeasurement = new ScaleMeasurement();
|
|
||||||
|
|
||||||
scaleMeasurement.setUserId(user.getId());
|
|
||||||
scaleMeasurement.setDateTime(cal.getTime());
|
|
||||||
scaleMeasurement.setConvertedWeight(weightMeasurement.getValue(), user.getScaleUnit());
|
|
||||||
scaleMeasurement.setFat(fatMeasurement.getValue());
|
|
||||||
scaleMeasurement.setWater(waterMeasurement.getValue());
|
|
||||||
scaleMeasurement.setMuscle(muscleMeasurement.getValue());
|
|
||||||
scaleMeasurement.setLbw(lbwMeasurement.getValue());
|
|
||||||
scaleMeasurement.setWaist(waistMeasurement.getValue());
|
|
||||||
scaleMeasurement.setHip(hipMeasurement.getValue());
|
|
||||||
scaleMeasurement.setBone(boneMeasurementView.getValue());
|
|
||||||
scaleMeasurement.setComment(commentMeasurement.getValueAsString());
|
|
||||||
|
|
||||||
return scaleMeasurement;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveScaleData() {
|
private void saveScaleData() {
|
||||||
ScaleMeasurement scaleMeasurement = createScaleDataFromMeasurement();
|
if (isDirty) {
|
||||||
|
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
|
||||||
scaleMeasurement.setId(id);
|
openScale.updateScaleData(scaleMeasurement);
|
||||||
|
isDirty = false;
|
||||||
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
|
}
|
||||||
openScale.updateScaleData(scaleMeasurement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean moveLeft() {
|
private boolean moveLeft() {
|
||||||
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(getApplicationContext()).getTupleScaleData(id);
|
if (previousMeasurement != null) {
|
||||||
ScaleMeasurement prevScaleMeasurement = tupleScaleData[0];
|
|
||||||
|
|
||||||
if (prevScaleMeasurement != null) {
|
|
||||||
saveScaleData();
|
saveScaleData();
|
||||||
getIntent().putExtra("id", prevScaleMeasurement.getId());
|
getIntent().putExtra("id", previousMeasurement.getId());
|
||||||
updateOnView();
|
updateOnView();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -339,9 +269,9 @@ public class DataEntryActivity extends Activity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean moveRight()
|
private boolean moveRight() {
|
||||||
{
|
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(getApplicationContext())
|
||||||
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(getApplicationContext()).getTupleScaleData(id);
|
.getTupleScaleData(scaleMeasurement.getId());
|
||||||
ScaleMeasurement nextScaleMeasurement = tupleScaleData[2];
|
ScaleMeasurement nextScaleMeasurement = tupleScaleData[2];
|
||||||
|
|
||||||
if (nextScaleMeasurement != null) {
|
if (nextScaleMeasurement != null) {
|
||||||
@@ -357,23 +287,12 @@ public class DataEntryActivity extends Activity {
|
|||||||
private class onMeasurementViewUpdateListener implements MeasurementViewUpdateListener {
|
private class onMeasurementViewUpdateListener implements MeasurementViewUpdateListener {
|
||||||
@Override
|
@Override
|
||||||
public void onMeasurementViewUpdate(MeasurementView view) {
|
public void onMeasurementViewUpdate(MeasurementView view) {
|
||||||
ArrayList<MeasurementView> viewsToUpdate = new ArrayList<>();
|
view.saveTo(scaleMeasurement);
|
||||||
if (view == weightMeasurement) {
|
isDirty = true;
|
||||||
viewsToUpdate.add(bmiMeasurementView);
|
|
||||||
viewsToUpdate.add(bmrMeasurementView);
|
|
||||||
} else if (view == waistMeasurement) {
|
|
||||||
viewsToUpdate.add(wHtRMeasurementView);
|
|
||||||
viewsToUpdate.add(whrMeasurementView);
|
|
||||||
} else if (view == hipMeasurement) {
|
|
||||||
viewsToUpdate.add(whrMeasurementView);
|
|
||||||
} else if (view == dateMeasurement) {
|
|
||||||
viewsToUpdate.add(bmrMeasurementView);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!viewsToUpdate.isEmpty()) {
|
for (MeasurementView measurement : dataEntryMeasurements) {
|
||||||
ScaleMeasurement scaleMeasurement = createScaleDataFromMeasurement();
|
if (measurement != view) {
|
||||||
for (MeasurementView measurement : viewsToUpdate) {
|
measurement.loadFrom(scaleMeasurement, previousMeasurement);
|
||||||
measurement.updateValue(scaleMeasurement);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -394,7 +313,9 @@ public class DataEntryActivity extends Activity {
|
|||||||
|
|
||||||
infoDialog.show();
|
infoDialog.show();
|
||||||
} else {
|
} else {
|
||||||
ScaleMeasurement scaleMeasurement = createScaleDataFromMeasurement();
|
for (MeasurementView measurement : dataEntryMeasurements) {
|
||||||
|
measurement.saveTo(scaleMeasurement);
|
||||||
|
}
|
||||||
|
|
||||||
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
|
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
|
||||||
openScale.addScaleData(scaleMeasurement);
|
openScale.addScaleData(scaleMeasurement);
|
||||||
@@ -463,7 +384,7 @@ public class DataEntryActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void deleteMeasurement() {
|
void deleteMeasurement() {
|
||||||
int delId = id;
|
int delId = scaleMeasurement.getId();
|
||||||
|
|
||||||
boolean hasNext = moveLeft();
|
boolean hasNext = moveLeft();
|
||||||
|
|
||||||
|
@@ -179,8 +179,7 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
lastScaleMeasurement = new ScaleMeasurement();
|
lastScaleMeasurement = new ScaleMeasurement();
|
||||||
} else if (userSelectedData != null) {
|
} else if (userSelectedData != null) {
|
||||||
lastScaleMeasurement = userSelectedData;
|
lastScaleMeasurement = userSelectedData;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
lastScaleMeasurement = scaleMeasurementList.get(0);
|
lastScaleMeasurement = scaleMeasurementList.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,14 +196,9 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(context).getTupleScaleData(lastScaleMeasurement.getId());
|
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(context).getTupleScaleData(lastScaleMeasurement.getId());
|
||||||
ScaleMeasurement prevScaleMeasurement = tupleScaleData[0];
|
ScaleMeasurement prevScaleMeasurement = tupleScaleData[0];
|
||||||
|
|
||||||
if (prevScaleMeasurement == null) {
|
|
||||||
prevScaleMeasurement = new ScaleMeasurement();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (MeasurementView measurement : overviewMeasurements) {
|
for (MeasurementView measurement : overviewMeasurements) {
|
||||||
measurement.updatePreferences(prefs);
|
measurement.updatePreferences(prefs);
|
||||||
measurement.updateValue(lastScaleMeasurement);
|
measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement);
|
||||||
measurement.updateDiff(lastScaleMeasurement, prevScaleMeasurement);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -201,31 +201,24 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
|
|
||||||
int displayCount = 0;
|
int displayCount = 0;
|
||||||
|
|
||||||
for (int i = (maxSize * selectedSubpageNr); i< scaleMeasurementList.size(); i++) {
|
for (int i = (maxSize * selectedSubpageNr); i < scaleMeasurementList.size(); i++) {
|
||||||
ScaleMeasurement scaleMeasurement = scaleMeasurementList.get(i);
|
ScaleMeasurement scaleMeasurement = scaleMeasurementList.get(i);
|
||||||
|
|
||||||
ScaleMeasurement prevScaleMeasurement;
|
ScaleMeasurement prevScaleMeasurement = null;
|
||||||
|
if (i < scaleMeasurementList.size() - 1) {
|
||||||
if (i >= scaleMeasurementList.size()-1) {
|
prevScaleMeasurement = scaleMeasurementList.get(i + 1);
|
||||||
prevScaleMeasurement = new ScaleMeasurement();
|
|
||||||
} else {
|
|
||||||
prevScaleMeasurement = scaleMeasurementList.get(i+1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HashMap<Integer,String> dataRow = new HashMap<>();
|
HashMap<Integer,String> dataRow = new HashMap<>();
|
||||||
|
|
||||||
int columnNr = 0;
|
int columnNr = 0;
|
||||||
dataRow.put(columnNr, Long.toString(scaleMeasurement.getId()));
|
dataRow.put(columnNr++, Long.toString(scaleMeasurement.getId()));
|
||||||
|
|
||||||
for (int j=0; j< measurementsList.size(); j++) {
|
for (MeasurementView measurement : measurementsList) {
|
||||||
MeasurementView measurement = measurementsList.get(j);
|
measurement.loadFrom(scaleMeasurement, prevScaleMeasurement);
|
||||||
measurement.updateValue(scaleMeasurement);
|
|
||||||
measurement.updateDiff(scaleMeasurement, prevScaleMeasurement);
|
|
||||||
|
|
||||||
if (measurement.isVisible()) {
|
if (measurement.isVisible()) {
|
||||||
columnNr++;
|
dataRow.put(columnNr++, measurement.getValueAsString() + "<br>" + measurement.getDiffValue());
|
||||||
dataRow.put(columnNr, measurement.getValueAsString() + "<br>" + measurement.getDiffValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,44 +24,44 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class BMIMeasurementView extends MeasurementView {
|
public class BMIMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
public BMIMeasurementView(Context context) {
|
public BMIMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_bmi), ContextCompat.getDrawable(context, R.drawable.ic_bmi));
|
super(context, context.getResources().getString(R.string.label_bmi), ContextCompat.getDrawable(context, R.drawable.ic_bmi));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("weightEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEditable() {
|
public boolean isEditable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getBMI(getScaleUser().getBodyHeight()));
|
return measurement.getBMI(getScaleUser().getBodyHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
setDiffOnView(newMeasurement.getBMI(getScaleUser().getBodyHeight()), lastMeasurement.getBMI(getScaleUser().getBodyHeight()));
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnit() {
|
protected String getUnit() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMaxValue() {
|
||||||
return evalSheet.evaluateBMI(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getMaxValue() {
|
|
||||||
return 50;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
setVisible(preferences.getBoolean("weightEnable", true));
|
return evalSheet.evaluateBMI(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,44 +24,51 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class BMRMeasurementView extends MeasurementView {
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class BMRMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
public BMRMeasurementView(Context context) {
|
public BMRMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_bmr), ContextCompat.getDrawable(context, R.drawable.ic_bmr));
|
super(context, context.getResources().getString(R.string.label_bmr), ContextCompat.getDrawable(context, R.drawable.ic_bmr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("weightEnable", true));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEditable() {
|
public boolean isEditable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
protected String formatValue(float value) {
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getBMR(getScaleUser()));
|
return String.format(Locale.getDefault(), "%d", Math.round(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
setDiffOnView(newMeasurement.getBMR(getScaleUser()), lastMeasurement.getBMR(getScaleUser()));
|
return measurement.getBMR(getScaleUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnit() {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
return "kCal";
|
return "kCal";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMaxValue() {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getMaxValue() {
|
|
||||||
return 5000;
|
return 5000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
setVisible(preferences.getBoolean("weightEnable", true));
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,39 +24,39 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class BoneMeasurementView extends MeasurementView {
|
public class BoneMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
public BoneMeasurementView(Context context) {
|
public BoneMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_bone), ContextCompat.getDrawable(context, R.drawable.ic_bone));
|
super(context, context.getResources().getString(R.string.label_bone), ContextCompat.getDrawable(context, R.drawable.ic_bone));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getBone());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
setDiffOnView(newMeasurement.getBone(), lastMeasurement.getBone());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return "kg";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
setVisible(preferences.getBoolean("boneEnable", false));
|
setVisible(preferences.getBoolean("boneEnable", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
return null;
|
return measurement.getBone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxValue() {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
measurement.setBone(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
|
return "kg";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getMaxValue() {
|
||||||
return 50;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,57 +23,56 @@ import android.widget.EditText;
|
|||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
|
||||||
|
|
||||||
public class CommentMeasurementView extends MeasurementView {
|
public class CommentMeasurementView extends MeasurementView {
|
||||||
|
private String comment;
|
||||||
|
|
||||||
public CommentMeasurementView(Context context) {
|
public CommentMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_comment), ContextCompat.getDrawable(context, R.drawable.ic_comment));
|
super(context, context.getResources().getString(R.string.label_comment), ContextCompat.getDrawable(context, R.drawable.ic_comment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setValue(String newComment, boolean callListener) {
|
||||||
|
if (!newComment.equals(comment)) {
|
||||||
|
comment = newComment;
|
||||||
|
setValueView(comment, callListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean validateInput(EditText view) {
|
public void loadFrom(ScaleMeasurement measurement, ScaleMeasurement previousMeasurement) {
|
||||||
|
setValue(measurement.getComment(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveTo(ScaleMeasurement measurement) {
|
||||||
|
measurement.setComment(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValueAsString() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean validateAndSetInput(EditText view) {
|
||||||
|
setValue(view.getText().toString(), true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getInputType() {
|
protected int getInputType() {
|
||||||
return InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
return InputType.TYPE_CLASS_TEXT
|
||||||
|
| InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE
|
||||||
|
| InputType.TYPE_TEXT_FLAG_MULTI_LINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getHintText() {
|
protected String getHintText() {
|
||||||
return getResources().getString(R.string.info_enter_comment);
|
return getResources().getString(R.string.info_enter_comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getComment());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getMaxValue() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -21,73 +21,91 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.widget.DatePicker;
|
import android.widget.DatePicker;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class DateMeasurementView extends MeasurementView {
|
public class DateMeasurementView extends MeasurementView {
|
||||||
private DateFormat dateFormat = DateFormat.getDateInstance();
|
private static DateFormat dateFormat = DateFormat.getDateInstance();
|
||||||
|
private Date date;
|
||||||
|
|
||||||
public DateMeasurementView(Context context) {
|
public DateMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_date), ContextCompat.getDrawable(context, R.drawable.ic_lastmonth));
|
super(context, context.getResources().getString(R.string.label_date), ContextCompat.getDrawable(context, R.drawable.ic_lastmonth));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setValue(Date newDate, boolean callListener) {
|
||||||
|
if (!newDate.equals(date)) {
|
||||||
|
date = newDate;
|
||||||
|
setValueView(dateFormat.format(date), callListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFrom(ScaleMeasurement measurement, ScaleMeasurement previousMeasurement) {
|
||||||
|
setValue(measurement.getDateTime(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveTo(ScaleMeasurement measurement) {
|
||||||
|
Calendar target = Calendar.getInstance();
|
||||||
|
target.setTime(measurement.getDateTime());
|
||||||
|
|
||||||
|
Calendar source = Calendar.getInstance();
|
||||||
|
source.setTime(date);
|
||||||
|
|
||||||
|
target.set(source.get(Calendar.YEAR), source.get(Calendar.MONTH),
|
||||||
|
source.get(Calendar.DAY_OF_MONTH));
|
||||||
|
|
||||||
|
measurement.setDateTime(target.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValueAsString() {
|
||||||
|
return dateFormat.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean validateAndSetInput(EditText view) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getInputType() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getHintText() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
|
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {
|
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(date);
|
||||||
cal.set(selectedYear, selectedMonth, selectedDay);
|
cal.set(selectedYear, selectedMonth, selectedDay);
|
||||||
Date date = cal.getTime();
|
setValue(cal.getTime(), true);
|
||||||
setValueOnView(date, dateFormat.format(date));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AlertDialog getInputDialog() {
|
protected AlertDialog getInputDialog() {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTime(getDateTime());
|
cal.setTime(date);
|
||||||
|
|
||||||
DatePickerDialog datePicker = new DatePickerDialog(
|
return new DatePickerDialog(
|
||||||
getContext(), datePickerListener, cal.get(Calendar.YEAR),
|
getContext(), datePickerListener, cal.get(Calendar.YEAR),
|
||||||
cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
|
cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
|
||||||
|
|
||||||
return datePicker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), dateFormat.format(newMeasurement.getDateTime()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getMaxValue() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class FatMeasurementView extends MeasurementView {
|
public class FatMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
private boolean estimateFatEnable;
|
private boolean estimateFatEnable;
|
||||||
|
|
||||||
@@ -32,33 +32,6 @@ public class FatMeasurementView extends MeasurementView {
|
|||||||
super(context, context.getResources().getString(R.string.label_fat), ContextCompat.getDrawable(context, R.drawable.ic_fat));
|
super(context, context.getResources().getString(R.string.label_fat), ContextCompat.getDrawable(context, R.drawable.ic_fat));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEditable() {
|
|
||||||
if (estimateFatEnable && getMeasurementMode() == MeasurementViewMode.ADD) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
if (estimateFatEnable && getMeasurementMode() == MeasurementViewMode.ADD) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), (getContext().getString(R.string.label_automatic)));
|
|
||||||
} else {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getFat());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
setDiffOnView(newMeasurement.getFat(), lastMeasurement.getFat());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return "%";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
setVisible(preferences.getBoolean("fatEnable", true));
|
setVisible(preferences.getBoolean("fatEnable", true));
|
||||||
@@ -66,13 +39,32 @@ public class FatMeasurementView extends MeasurementView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
return evalSheet.evaluateBodyFat(value);
|
return measurement.getFat();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxValue() {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
measurement.setFat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
|
return "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getMaxValue() {
|
||||||
return 80;
|
return 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isEstimationEnabled() {
|
||||||
|
return estimateFatEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateBodyFat(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,372 @@
|
|||||||
|
/* Copyright (C) 2018 Erik Johansson <erik@ejohansson.se>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.health.openscale.gui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TableRow;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public abstract class FloatMeasurementView extends MeasurementView {
|
||||||
|
private static String SYMBOL_UP = "➚";
|
||||||
|
private static String SYMBOL_NEUTRAL = "➙";
|
||||||
|
private static String SYMBOL_DOWN = "➘";
|
||||||
|
|
||||||
|
private static float NO_VALUE = -1.0f;
|
||||||
|
private static float AUTO_VALUE = -2.0f;
|
||||||
|
|
||||||
|
Date dateTime;
|
||||||
|
float value = NO_VALUE;
|
||||||
|
float previousValue = NO_VALUE;
|
||||||
|
EvaluationResult evaluationResult;
|
||||||
|
|
||||||
|
private String nameText;
|
||||||
|
|
||||||
|
private Button incButton;
|
||||||
|
private Button decButton;
|
||||||
|
|
||||||
|
public FloatMeasurementView(Context context, String text, Drawable icon) {
|
||||||
|
super(context, text, icon);
|
||||||
|
initView(context);
|
||||||
|
|
||||||
|
nameText = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initView(Context context) {
|
||||||
|
incButton = new Button(context);
|
||||||
|
decButton = new Button(context);
|
||||||
|
|
||||||
|
LinearLayout incDecLayout = getIncDecLayout();
|
||||||
|
incDecLayout.addView(incButton);
|
||||||
|
incDecLayout.addView(decButton);
|
||||||
|
|
||||||
|
incButton.setText("+");
|
||||||
|
incButton.setBackgroundColor(Color.TRANSPARENT);
|
||||||
|
incButton.setPadding(0,0,0,0);
|
||||||
|
incButton.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0.50f));
|
||||||
|
incButton.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
incValue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
incButton.setOnTouchListener(new RepeatListener(400, 100, new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
incValue();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
incButton.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
decButton.setText("-");
|
||||||
|
decButton.setBackgroundColor(Color.TRANSPARENT);
|
||||||
|
decButton.setPadding(0,0,0,0);
|
||||||
|
decButton.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0.50f));
|
||||||
|
decButton.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
decValue();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
decButton.setOnTouchListener(new RepeatListener(400, 100, new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
decValue();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
decButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private float clampValue(float value) {
|
||||||
|
return Math.max(0.0f, Math.min(getMaxValue(), value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setValue(float newValue, float newPreviousValue, boolean callListener) {
|
||||||
|
final String unit = getUnit();
|
||||||
|
final String suffix = unit.isEmpty() ? "" : " " + unit;
|
||||||
|
|
||||||
|
final boolean valueChanged = newValue != value;
|
||||||
|
final boolean previousValueChanged = newPreviousValue != previousValue;
|
||||||
|
|
||||||
|
if (valueChanged) {
|
||||||
|
value = newValue;
|
||||||
|
evaluationResult = null;
|
||||||
|
|
||||||
|
if (value == AUTO_VALUE) {
|
||||||
|
setValueView(getContext().getString(R.string.label_automatic), false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setValueView(formatValue(value) + suffix, callListener);
|
||||||
|
|
||||||
|
if (getMeasurementMode() != MeasurementViewMode.ADD) {
|
||||||
|
EvaluationSheet evalSheet = new EvaluationSheet(getScaleUser(), dateTime);
|
||||||
|
evaluationResult = evaluateSheet(evalSheet, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setEvaluationView(evaluationResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valueChanged || previousValueChanged) {
|
||||||
|
previousValue = newPreviousValue;
|
||||||
|
if (previousValue >= 0.0f) {
|
||||||
|
final float diff = value - previousValue;
|
||||||
|
|
||||||
|
String symbol;
|
||||||
|
|
||||||
|
if (diff > 0.0) {
|
||||||
|
symbol = SYMBOL_UP;
|
||||||
|
} else if (diff < 0.0) {
|
||||||
|
symbol = SYMBOL_DOWN;
|
||||||
|
} else {
|
||||||
|
symbol = SYMBOL_NEUTRAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
setNameView(Html.fromHtml(
|
||||||
|
String.format(
|
||||||
|
"%s <br> <font color='grey'>%s<small>%s%s</small></font>",
|
||||||
|
nameText, symbol, formatValue(diff), suffix)));
|
||||||
|
} else {
|
||||||
|
setNameView(nameText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void incValue() {
|
||||||
|
setValue(clampValue(value + 0.1f), previousValue, true);
|
||||||
|
}
|
||||||
|
private void decValue() {
|
||||||
|
setValue(clampValue(value - 0.1f), previousValue, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String formatValue(float value) {
|
||||||
|
return String.format(Locale.getDefault(), "%.2f", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract float getMeasurementValue(ScaleMeasurement measurement);
|
||||||
|
protected abstract void setMeasurementValue(float value, ScaleMeasurement measurement);
|
||||||
|
|
||||||
|
protected abstract String getUnit();
|
||||||
|
protected abstract float getMaxValue();
|
||||||
|
|
||||||
|
protected boolean isEstimationEnabled() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value);
|
||||||
|
|
||||||
|
private boolean useAutoValue() {
|
||||||
|
return isEstimationEnabled() && getMeasurementMode() == MeasurementViewMode.ADD;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFrom(ScaleMeasurement measurement, ScaleMeasurement previousMeasurement) {
|
||||||
|
dateTime = measurement.getDateTime();
|
||||||
|
|
||||||
|
float newValue = AUTO_VALUE;
|
||||||
|
float newPreviousValue = NO_VALUE;
|
||||||
|
|
||||||
|
if (!useAutoValue()) {
|
||||||
|
newValue = clampValue(getMeasurementValue(measurement));
|
||||||
|
if (previousMeasurement != null) {
|
||||||
|
newPreviousValue = clampValue(getMeasurementValue(previousMeasurement));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(newValue, newPreviousValue, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveTo(ScaleMeasurement measurement) {
|
||||||
|
if (!useAutoValue()) {
|
||||||
|
setMeasurementValue(value, measurement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValueAsString() {
|
||||||
|
if (useAutoValue()) {
|
||||||
|
return getContext().getString(R.string.label_automatic);
|
||||||
|
}
|
||||||
|
return formatValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDiffValue() {
|
||||||
|
if (previousValue < 0.0f) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String symbol;
|
||||||
|
String color;
|
||||||
|
|
||||||
|
final float diff = value - previousValue;
|
||||||
|
if (diff > 0.0f) {
|
||||||
|
symbol = SYMBOL_UP;
|
||||||
|
color = "green";
|
||||||
|
} else if (diff < 0.0f) {
|
||||||
|
symbol = SYMBOL_DOWN;
|
||||||
|
color = "red";
|
||||||
|
} else {
|
||||||
|
symbol = SYMBOL_NEUTRAL;
|
||||||
|
color = "grey";
|
||||||
|
}
|
||||||
|
return String.format(
|
||||||
|
"<font color='%s'>%s</font><font color='grey'><small>%s</small></font>",
|
||||||
|
color, symbol, formatValue(diff));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isEditable() {
|
||||||
|
if (useAutoValue()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEditMode(MeasurementViewMode mode) {
|
||||||
|
super.setEditMode(mode);
|
||||||
|
|
||||||
|
if (mode == MeasurementViewMode.VIEW || !isEditable()) {
|
||||||
|
incButton.setVisibility(View.GONE);
|
||||||
|
decButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
incButton.setVisibility(View.VISIBLE);
|
||||||
|
decButton.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setExpand(boolean state) {
|
||||||
|
final boolean show = state && isVisible() && evaluationResult != null;
|
||||||
|
showEvaluatorRow(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean validateAndSetInput(EditText view) {
|
||||||
|
final String text = view.getText().toString();
|
||||||
|
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
view.setError(getResources().getString(R.string.error_value_required));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float newValue;
|
||||||
|
try {
|
||||||
|
newValue = Float.valueOf(text.replace(',', '.'));
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex) {
|
||||||
|
newValue = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newValue < 0 || newValue > getMaxValue()) {
|
||||||
|
view.setError(getResources().getString(R.string.error_value_range));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(newValue, previousValue, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getInputType() {
|
||||||
|
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getHintText() {
|
||||||
|
return getResources().getString(R.string.info_enter_value_unit) + " " + getUnit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RepeatListener implements OnTouchListener {
|
||||||
|
private Handler handler = new Handler();
|
||||||
|
|
||||||
|
private int initialInterval;
|
||||||
|
private final int normalInterval;
|
||||||
|
private final OnClickListener clickListener;
|
||||||
|
|
||||||
|
private Runnable handlerRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handler.postDelayed(this, normalInterval);
|
||||||
|
clickListener.onClick(downView);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private View downView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RepeatListener cyclically runs a clickListener, emulating keyboard-like behaviour. First
|
||||||
|
* click is fired immediately, next one after the initialInterval, and subsequent ones after the normalInterval.
|
||||||
|
*
|
||||||
|
* @param initialInterval The interval after first click event
|
||||||
|
* @param normalInterval The interval after second and subsequent click events
|
||||||
|
* @param clickListener The OnClickListener, that will be called periodically
|
||||||
|
*/
|
||||||
|
public RepeatListener(int initialInterval, int normalInterval,
|
||||||
|
OnClickListener clickListener) {
|
||||||
|
if (clickListener == null) {
|
||||||
|
throw new IllegalArgumentException("null runnable");
|
||||||
|
}
|
||||||
|
if (initialInterval < 0 || normalInterval < 0) {
|
||||||
|
throw new IllegalArgumentException("negative interval");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initialInterval = initialInterval;
|
||||||
|
this.normalInterval = normalInterval;
|
||||||
|
this.clickListener = clickListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||||
|
switch (motionEvent.getAction()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
handler.removeCallbacks(handlerRunnable);
|
||||||
|
handler.postDelayed(handlerRunnable, initialInterval);
|
||||||
|
downView = view;
|
||||||
|
downView.setPressed(true);
|
||||||
|
clickListener.onClick(view);
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
handler.removeCallbacks(handlerRunnable);
|
||||||
|
downView.setPressed(false);
|
||||||
|
downView = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -24,40 +24,39 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class HipMeasurementView extends MeasurementView {
|
public class HipMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
public HipMeasurementView(Context context) {
|
public HipMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_hip), ContextCompat.getDrawable(context, R.drawable.ic_hip));
|
super(context, context.getResources().getString(R.string.label_hip), ContextCompat.getDrawable(context, R.drawable.ic_hip));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getHip());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
setDiffOnView(newMeasurement.getHip(), lastMeasurement.getHip());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return "cm";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
setVisible(preferences.getBoolean("hipEnable", false));
|
setVisible(preferences.getBoolean("hipEnable", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
return null;
|
return measurement.getHip();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxValue() {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
measurement.setHip(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
|
return "cm";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getMaxValue() {
|
||||||
return 200;
|
return 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class LBWMeasurementView extends MeasurementView {
|
public class LBWMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
private boolean estimateLBWEnable;
|
private boolean estimateLBWEnable;
|
||||||
|
|
||||||
@@ -32,33 +32,6 @@ public class LBWMeasurementView extends MeasurementView {
|
|||||||
super(context, context.getResources().getString(R.string.label_lbw), ContextCompat.getDrawable(context, R.drawable.ic_lbw));
|
super(context, context.getResources().getString(R.string.label_lbw), ContextCompat.getDrawable(context, R.drawable.ic_lbw));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEditable() {
|
|
||||||
if (estimateLBWEnable && getMeasurementMode() == MeasurementViewMode.ADD) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
if (estimateLBWEnable && getMeasurementMode() == MeasurementViewMode.ADD) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), (getContext().getString(R.string.label_automatic)));
|
|
||||||
} else {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getLbw());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
setDiffOnView(newMeasurement.getLbw(), lastMeasurement.getLbw());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return "kg";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
setVisible(preferences.getBoolean("lbwEnable", false));
|
setVisible(preferences.getBoolean("lbwEnable", false));
|
||||||
@@ -66,13 +39,32 @@ public class LBWMeasurementView extends MeasurementView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
return null;
|
return measurement.getLbw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxValue() {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
measurement.setLbw(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
|
return "kg";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getMaxValue() {
|
||||||
return 300;
|
return 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isEstimationEnabled() {
|
||||||
|
return estimateLBWEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,13 +21,9 @@ import android.content.DialogInterface;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Handler;
|
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.Html;
|
|
||||||
import android.text.InputType;
|
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -44,9 +40,6 @@ import com.health.openscale.core.OpenScale;
|
|||||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
import com.health.openscale.core.datatypes.ScaleUser;
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import lecho.lib.hellocharts.util.ChartUtils;
|
import lecho.lib.hellocharts.util.ChartUtils;
|
||||||
|
|
||||||
@@ -56,42 +49,25 @@ import static com.health.openscale.gui.views.MeasurementView.MeasurementViewMode
|
|||||||
|
|
||||||
public abstract class MeasurementView extends TableLayout {
|
public abstract class MeasurementView extends TableLayout {
|
||||||
public enum MeasurementViewMode {VIEW, EDIT, ADD};
|
public enum MeasurementViewMode {VIEW, EDIT, ADD};
|
||||||
private static String SYMBOL_UP = "➚";
|
|
||||||
private static String SYMBOL_NEUTRAL = "➙";
|
|
||||||
private static String SYMBOL_DOWN = "➘";
|
|
||||||
|
|
||||||
private TableRow measurementRow;
|
private TableRow measurementRow;
|
||||||
private ImageView iconView;
|
private ImageView iconView;
|
||||||
private TextView nameView;
|
private TextView nameView;
|
||||||
private TextView valueView;
|
private TextView valueView;
|
||||||
private LinearLayout incdecLayout;
|
private LinearLayout incDecLayout;
|
||||||
private Button incView;
|
|
||||||
private Button decView;
|
|
||||||
private ImageView editModeView;
|
private ImageView editModeView;
|
||||||
private ImageView indicatorView;
|
private ImageView indicatorView;
|
||||||
|
|
||||||
private TableRow evaluatorRow;
|
private TableRow evaluatorRow;
|
||||||
private LinearGaugeView evaluatorView;
|
private LinearGaugeView evaluatorView;
|
||||||
|
|
||||||
private String nameText;
|
|
||||||
|
|
||||||
private Date dateTime;
|
|
||||||
private String value;
|
|
||||||
private float previousValue;
|
|
||||||
private String diffValue;
|
|
||||||
|
|
||||||
private MeasurementViewUpdateListener updateListener = null;
|
private MeasurementViewUpdateListener updateListener = null;
|
||||||
private MeasurementViewMode measurementMode;
|
private MeasurementViewMode measurementMode = VIEW;
|
||||||
|
|
||||||
public MeasurementView(Context context, String text, Drawable icon) {
|
public MeasurementView(Context context, String text, Drawable icon) {
|
||||||
super(context);
|
super(context);
|
||||||
initView(context);
|
initView(context);
|
||||||
|
|
||||||
measurementMode = VIEW;
|
|
||||||
nameText = text;
|
|
||||||
dateTime = new Date();
|
|
||||||
value = new String();
|
|
||||||
diffValue = new String();
|
|
||||||
nameView.setText(text);
|
nameView.setText(text);
|
||||||
iconView.setImageDrawable(icon);
|
iconView.setImageDrawable(icon);
|
||||||
}
|
}
|
||||||
@@ -102,22 +78,20 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
iconView = new ImageView(context);
|
iconView = new ImageView(context);
|
||||||
nameView = new TextView(context);
|
nameView = new TextView(context);
|
||||||
valueView = new TextView(context);
|
valueView = new TextView(context);
|
||||||
incView = new Button(context);
|
|
||||||
decView = new Button(context);
|
|
||||||
editModeView = new ImageView(context);
|
editModeView = new ImageView(context);
|
||||||
indicatorView = new ImageView(context);
|
indicatorView = new ImageView(context);
|
||||||
|
|
||||||
evaluatorRow = new TableRow(context);
|
evaluatorRow = new TableRow(context);
|
||||||
evaluatorView = new LinearGaugeView(context);
|
evaluatorView = new LinearGaugeView(context);
|
||||||
|
|
||||||
incdecLayout = new LinearLayout(context);
|
incDecLayout = new LinearLayout(context);
|
||||||
|
|
||||||
measurementRow.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT, 1.0f));
|
measurementRow.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT, 1.0f));
|
||||||
measurementRow.setGravity(Gravity.CENTER);
|
measurementRow.setGravity(Gravity.CENTER);
|
||||||
measurementRow.addView(iconView);
|
measurementRow.addView(iconView);
|
||||||
measurementRow.addView(nameView);
|
measurementRow.addView(nameView);
|
||||||
measurementRow.addView(valueView);
|
measurementRow.addView(valueView);
|
||||||
measurementRow.addView(incdecLayout);
|
measurementRow.addView(incDecLayout);
|
||||||
measurementRow.addView(editModeView);
|
measurementRow.addView(editModeView);
|
||||||
measurementRow.addView(indicatorView);
|
measurementRow.addView(indicatorView);
|
||||||
|
|
||||||
@@ -138,49 +112,10 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
valueView.setPadding(0,0,20,0);
|
valueView.setPadding(0,0,20,0);
|
||||||
valueView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.29f));
|
valueView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.29f));
|
||||||
|
|
||||||
incdecLayout.setOrientation(VERTICAL);
|
incDecLayout.setOrientation(VERTICAL);
|
||||||
incdecLayout.addView(incView);
|
incDecLayout.setVisibility(View.GONE);
|
||||||
incdecLayout.addView(decView);
|
incDecLayout.setPadding(0,0,0,0);
|
||||||
incdecLayout.setVisibility(View.GONE);
|
incDecLayout.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.05f));
|
||||||
incdecLayout.setPadding(0,0,0,0);
|
|
||||||
incdecLayout.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.05f));
|
|
||||||
|
|
||||||
incView.setText("+");
|
|
||||||
incView.setBackgroundColor(Color.TRANSPARENT);
|
|
||||||
incView.setPadding(0,0,0,0);
|
|
||||||
incView.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0.50f));
|
|
||||||
incView.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
incValue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
incView.setOnTouchListener(new RepeatListener(400, 100, new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
incValue();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
incView.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
decView.setText("-");
|
|
||||||
decView.setBackgroundColor(Color.TRANSPARENT);
|
|
||||||
decView.setPadding(0,0,0,0);
|
|
||||||
decView.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, 0, 0.50f));
|
|
||||||
decView.setOnClickListener(new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
decValue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
decView.setOnTouchListener(new RepeatListener(400, 100, new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
decValue();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
decView.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
editModeView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_editable));
|
editModeView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_editable));
|
||||||
editModeView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
editModeView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||||
@@ -204,48 +139,23 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
evaluatorRow.setOnClickListener(onClickListener);
|
evaluatorRow.setOnClickListener(onClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected LinearLayout getIncDecLayout() {
|
||||||
|
return incDecLayout;
|
||||||
|
}
|
||||||
|
|
||||||
public void setOnUpdateListener(MeasurementViewUpdateListener listener) {
|
public void setOnUpdateListener(MeasurementViewUpdateListener listener) {
|
||||||
updateListener = listener;
|
updateListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void updateValue(ScaleMeasurement newMeasurement);
|
public abstract void loadFrom(ScaleMeasurement measurement, ScaleMeasurement previousMeasurement);
|
||||||
public abstract void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement);
|
public abstract void saveTo(ScaleMeasurement measurement);
|
||||||
|
|
||||||
public abstract void updatePreferences(SharedPreferences preferences);
|
public abstract void updatePreferences(SharedPreferences preferences);
|
||||||
public abstract String getUnit();
|
|
||||||
public abstract EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value);
|
|
||||||
public abstract float getMaxValue();
|
|
||||||
|
|
||||||
public float getValue() {
|
|
||||||
if (value.length() == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return Float.valueOf(value);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void incValue() {
|
|
||||||
float incValue = Math.min(getMaxValue(), getValue() + 0.1f);
|
|
||||||
setValueOnView(dateTime, incValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void decValue() {
|
|
||||||
float decValue = Math.max(0.0f, getValue() - 0.1f);
|
|
||||||
setValueOnView(dateTime, decValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValueAsString() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public abstract String getValueAsString();
|
||||||
|
public String getDiffValue() { return ""; }
|
||||||
public Drawable getIcon() { return iconView.getDrawable(); }
|
public Drawable getIcon() { return iconView.getDrawable(); }
|
||||||
|
|
||||||
public String getDiffValue() { return diffValue; }
|
|
||||||
|
|
||||||
public Date getDateTime() { return dateTime; }
|
|
||||||
|
|
||||||
protected boolean isEditable() {
|
protected boolean isEditable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -257,30 +167,20 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
case VIEW:
|
case VIEW:
|
||||||
indicatorView.setVisibility(View.VISIBLE);
|
indicatorView.setVisibility(View.VISIBLE);
|
||||||
editModeView.setVisibility(View.GONE);
|
editModeView.setVisibility(View.GONE);
|
||||||
incdecLayout.setVisibility(View.GONE);
|
incDecLayout.setVisibility(View.GONE);
|
||||||
incView.setVisibility(View.GONE);
|
|
||||||
decView.setVisibility(View.GONE);
|
|
||||||
break;
|
break;
|
||||||
case EDIT:
|
case EDIT:
|
||||||
case ADD:
|
case ADD:
|
||||||
|
indicatorView.setVisibility(View.GONE);
|
||||||
editModeView.setVisibility(View.VISIBLE);
|
editModeView.setVisibility(View.VISIBLE);
|
||||||
incView.setVisibility(View.VISIBLE);
|
incDecLayout.setVisibility(View.VISIBLE);
|
||||||
decView.setVisibility(View.VISIBLE);
|
|
||||||
incdecLayout.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
if (!isEditable()) {
|
if (!isEditable()) {
|
||||||
editModeView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_noteeditable));
|
editModeView.setImageDrawable(ContextCompat.getDrawable(getContext(),
|
||||||
incView.setVisibility(View.GONE);
|
R.drawable.ic_noteeditable));
|
||||||
decView.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getUnit() == null) {
|
showEvaluatorRow(false);
|
||||||
incView.setVisibility(View.GONE);
|
|
||||||
decView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
indicatorView.setVisibility(View.GONE);
|
|
||||||
evaluatorRow.setVisibility(View.GONE);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,66 +189,28 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
return measurementMode;
|
return measurementMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setValueOnView(Date objTimeDate, Object objValue) {
|
protected void setValueView(String text, boolean callListener) {
|
||||||
dateTime = objTimeDate;
|
valueView.setText(text);
|
||||||
value = String.valueOf(objValue);
|
if (callListener && updateListener != null) {
|
||||||
|
|
||||||
try {
|
|
||||||
Float floatValue = Float.parseFloat(value);
|
|
||||||
if (measurementMode == VIEW || measurementMode == EDIT) {
|
|
||||||
evaluate(floatValue);
|
|
||||||
}
|
|
||||||
valueView.setText(String.format("%.2f ", floatValue) + getUnit());
|
|
||||||
value = String.valueOf(Math.round(floatValue*100.0f)/100.0f);
|
|
||||||
// Only update diff value if setDiffOnView has been called previously
|
|
||||||
if (!diffValue.isEmpty()) {
|
|
||||||
setDiffOnView(floatValue, previousValue);
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
valueView.setText(value);
|
|
||||||
}
|
|
||||||
if (updateListener != null) {
|
|
||||||
updateListener.onMeasurementViewUpdate(this);
|
updateListener.onMeasurementViewUpdate(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setDiffOnView(float value, float prevValue) {
|
protected void setNameView(CharSequence text) {
|
||||||
previousValue = prevValue;
|
nameView.setText(text);
|
||||||
float diff = value - prevValue;
|
}
|
||||||
|
|
||||||
String symbol;
|
protected void showEvaluatorRow(boolean show) {
|
||||||
String symbol_color;
|
if (show) {
|
||||||
|
evaluatorRow.setVisibility(View.VISIBLE);
|
||||||
if (diff > 0.0) {
|
}
|
||||||
symbol = SYMBOL_UP;
|
else {
|
||||||
symbol_color = "<font color='green'>" + SYMBOL_UP + "</font>";
|
evaluatorRow.setVisibility(View.GONE);
|
||||||
} else if (diff < 0.0) {
|
|
||||||
symbol = SYMBOL_DOWN;
|
|
||||||
symbol_color = "<font color='red'>" + SYMBOL_DOWN + "</font>";
|
|
||||||
} else {
|
|
||||||
symbol = SYMBOL_NEUTRAL;
|
|
||||||
symbol_color = "<font color='grey'>" + SYMBOL_NEUTRAL + "</font>";
|
|
||||||
}
|
}
|
||||||
diffValue = symbol_color + "<font color='grey'><small>" + String.format("%.2f", diff) + "</small></font>";
|
|
||||||
|
|
||||||
nameView.setText(
|
|
||||||
Html.fromHtml(
|
|
||||||
nameText +
|
|
||||||
" <br> <font color='grey'>" +
|
|
||||||
symbol +
|
|
||||||
"<small> " +
|
|
||||||
String.format("%.2f ", diff) + getUnit() +
|
|
||||||
"</small></font>"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExpand(boolean state) {
|
public void setExpand(boolean state) {
|
||||||
if (state && isVisible() && evaluateSheet(new EvaluationSheet(getScaleUser(), dateTime), 0.0f) != null) {
|
showEvaluatorRow(false);
|
||||||
evaluatorRow.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
evaluatorRow.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setVisible(boolean isVisible) {
|
protected void setVisible(boolean isVisible) {
|
||||||
@@ -367,35 +229,17 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean validateInput(EditText view) {
|
protected void setEvaluationView(EvaluationResult evalResult) {
|
||||||
if (view.getText().toString().length() == 0) {
|
|
||||||
view.setError(getResources().getString(R.string.error_value_required));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float floatValue = Float.valueOf(view.getText().toString());
|
|
||||||
|
|
||||||
if (!(floatValue >= 0 && floatValue <= getMaxValue())) {
|
|
||||||
view.setError(getResources().getString(R.string.error_value_range));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void evaluate(float value) {
|
|
||||||
EvaluationSheet evalSheet = new EvaluationSheet(getScaleUser(), dateTime);
|
|
||||||
EvaluationResult evalResult = evaluateSheet(evalSheet, value);
|
|
||||||
|
|
||||||
if (evalResult == null) {
|
if (evalResult == null) {
|
||||||
evalResult = new EvaluationResult();
|
evaluatorView.setLimits(-1.0f, -1.0f);
|
||||||
|
indicatorView.setBackgroundColor(Color.GRAY);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluatorView.setLimits(evalResult.lowLimit, evalResult.highLimit);
|
evaluatorView.setLimits(evalResult.lowLimit, evalResult.highLimit);
|
||||||
evaluatorView.setValue(value);
|
evaluatorView.setValue(evalResult.value);
|
||||||
|
|
||||||
switch (evalResult.eval_state)
|
switch (evalResult.eval_state) {
|
||||||
{
|
|
||||||
case LOW:
|
case LOW:
|
||||||
indicatorView.setBackgroundColor(ChartUtils.COLOR_BLUE);
|
indicatorView.setBackgroundColor(ChartUtils.COLOR_BLUE);
|
||||||
break;
|
break;
|
||||||
@@ -417,16 +261,11 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
return openScale.getSelectedScaleUser();
|
return openScale.getSelectedScaleUser();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getInputType() {
|
protected abstract boolean validateAndSetInput(EditText view);
|
||||||
return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
protected abstract int getInputType();
|
||||||
}
|
protected abstract String getHintText();
|
||||||
|
|
||||||
protected String getHintText() {
|
|
||||||
return getResources().getString(R.string.info_enter_value_unit) + " " + getUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AlertDialog getInputDialog() {
|
protected AlertDialog getInputDialog() {
|
||||||
final AlertDialog floatDialog;
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||||
builder.setTitle(nameView.getText());
|
builder.setTitle(nameView.getText());
|
||||||
builder.setIcon(iconView.getDrawable());
|
builder.setIcon(iconView.getDrawable());
|
||||||
@@ -435,14 +274,14 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
|
|
||||||
input.setInputType(getInputType());
|
input.setInputType(getInputType());
|
||||||
input.setHint(getHintText());
|
input.setHint(getHintText());
|
||||||
input.setText(value);
|
input.setText(getValueAsString());
|
||||||
input.setSelectAllOnFocus(true);
|
input.setSelectAllOnFocus(true);
|
||||||
builder.setView(input);
|
builder.setView(input);
|
||||||
|
|
||||||
builder.setPositiveButton(getResources().getString(R.string.label_ok), null);
|
builder.setPositiveButton(getResources().getString(R.string.label_ok), null);
|
||||||
builder.setNegativeButton(getResources().getString(R.string.label_cancel), null);
|
builder.setNegativeButton(getResources().getString(R.string.label_cancel), null);
|
||||||
|
|
||||||
floatDialog = builder.create();
|
final AlertDialog floatDialog = builder.create();
|
||||||
|
|
||||||
floatDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
floatDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||||
|
|
||||||
@@ -454,8 +293,7 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (validateInput(input)) {
|
if (validateAndSetInput(input)) {
|
||||||
setValueOnView(dateTime, input.getText().toString());
|
|
||||||
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
|
||||||
floatDialog.dismiss();
|
floatDialog.dismiss();
|
||||||
@@ -494,65 +332,5 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
setExpand(evaluatorRow.getVisibility() != View.VISIBLE);
|
setExpand(evaluatorRow.getVisibility() != View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RepeatListener implements OnTouchListener {
|
|
||||||
|
|
||||||
private Handler handler = new Handler();
|
|
||||||
|
|
||||||
private int initialInterval;
|
|
||||||
private final int normalInterval;
|
|
||||||
private final OnClickListener clickListener;
|
|
||||||
|
|
||||||
private Runnable handlerRunnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
handler.postDelayed(this, normalInterval);
|
|
||||||
clickListener.onClick(downView);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private View downView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RepeatListener cyclically runs a clickListener, emulating keyboard-like behaviour. First
|
|
||||||
* click is fired immediately, next one after the initialInterval, and subsequent ones after the normalInterval.
|
|
||||||
*
|
|
||||||
* @param initialInterval The interval after first click event
|
|
||||||
* @param normalInterval The interval after second and subsequent click events
|
|
||||||
* @param clickListener The OnClickListener, that will be called periodically
|
|
||||||
*/
|
|
||||||
public RepeatListener(int initialInterval, int normalInterval,
|
|
||||||
OnClickListener clickListener) {
|
|
||||||
if (clickListener == null)
|
|
||||||
throw new IllegalArgumentException("null runnable");
|
|
||||||
if (initialInterval < 0 || normalInterval < 0)
|
|
||||||
throw new IllegalArgumentException("negative interval");
|
|
||||||
|
|
||||||
this.initialInterval = initialInterval;
|
|
||||||
this.normalInterval = normalInterval;
|
|
||||||
this.clickListener = clickListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
||||||
switch (motionEvent.getAction()) {
|
|
||||||
case MotionEvent.ACTION_DOWN:
|
|
||||||
handler.removeCallbacks(handlerRunnable);
|
|
||||||
handler.postDelayed(handlerRunnable, initialInterval);
|
|
||||||
downView = view;
|
|
||||||
downView.setPressed(true);
|
|
||||||
clickListener.onClick(view);
|
|
||||||
return true;
|
|
||||||
case MotionEvent.ACTION_UP:
|
|
||||||
case MotionEvent.ACTION_CANCEL:
|
|
||||||
handler.removeCallbacks(handlerRunnable);
|
|
||||||
downView.setPressed(false);
|
|
||||||
downView = null;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,45 +24,39 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class MuscleMeasurementView extends MeasurementView {
|
public class MuscleMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
public MuscleMeasurementView(Context context) {
|
public MuscleMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_muscle), ContextCompat.getDrawable(context, R.drawable.ic_muscle));
|
super(context, context.getResources().getString(R.string.label_muscle), ContextCompat.getDrawable(context, R.drawable.ic_muscle));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEditable() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getMuscle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
setDiffOnView(newMeasurement.getMuscle(), lastMeasurement.getMuscle());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return "%";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
setVisible(preferences.getBoolean("muscleEnable", true));
|
setVisible(preferences.getBoolean("muscleEnable", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
return evalSheet.evaluateBodyMuscle(value);
|
return measurement.getMuscle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxValue() {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
measurement.setMuscle(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
|
return "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getMaxValue() {
|
||||||
return 80;
|
return 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateBodyMuscle(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,12 +20,11 @@ import android.app.TimePickerDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.TimePicker;
|
import android.widget.TimePicker;
|
||||||
|
|
||||||
import com.health.openscale.R;
|
import com.health.openscale.R;
|
||||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
@@ -33,65 +32,89 @@ import java.util.Date;
|
|||||||
|
|
||||||
public class TimeMeasurementView extends MeasurementView {
|
public class TimeMeasurementView extends MeasurementView {
|
||||||
private DateFormat timeFormat;
|
private DateFormat timeFormat;
|
||||||
|
private Date time;
|
||||||
|
|
||||||
public TimeMeasurementView(Context context) {
|
public TimeMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_time), ContextCompat.getDrawable(context, R.drawable.ic_daysleft));
|
super(context, context.getResources().getString(R.string.label_time), ContextCompat.getDrawable(context, R.drawable.ic_daysleft));
|
||||||
timeFormat = android.text.format.DateFormat.getTimeFormat(context);
|
timeFormat = android.text.format.DateFormat.getTimeFormat(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setValue(Date newTime, boolean callListener) {
|
||||||
|
if (!newTime.equals(time)) {
|
||||||
|
time = newTime;
|
||||||
|
setValueView(timeFormat.format(time), callListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFrom(ScaleMeasurement measurement, ScaleMeasurement previousMeasurement) {
|
||||||
|
setValue(measurement.getDateTime(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveTo(ScaleMeasurement measurement) {
|
||||||
|
Calendar target = Calendar.getInstance();
|
||||||
|
target.setTime(measurement.getDateTime());
|
||||||
|
|
||||||
|
Calendar source = Calendar.getInstance();
|
||||||
|
source.setTime(time);
|
||||||
|
|
||||||
|
target.set(Calendar.HOUR, source.get(Calendar.HOUR));
|
||||||
|
target.set(Calendar.MINUTE, source.get(Calendar.MINUTE));
|
||||||
|
target.set(Calendar.SECOND, 0);
|
||||||
|
target.set(Calendar.MILLISECOND, 0);
|
||||||
|
|
||||||
|
measurement.setDateTime(target.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValueAsString() {
|
||||||
|
return timeFormat.format(time);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean validateAndSetInput(EditText view) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getInputType() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getHintText() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
|
private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTime(time);
|
||||||
|
|
||||||
cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||||
cal.set(Calendar.MINUTE, minute);
|
cal.set(Calendar.MINUTE, minute);
|
||||||
cal.set(Calendar.SECOND, 0);
|
cal.set(Calendar.SECOND, 0);
|
||||||
Date date = cal.getTime();
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
setValueOnView(date, timeFormat.format(date));
|
|
||||||
|
setValue(cal.getTime(), true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AlertDialog getInputDialog() {
|
protected AlertDialog getInputDialog() {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance();
|
||||||
cal.setTime(getDateTime());
|
cal.setTime(time);
|
||||||
|
|
||||||
TimePickerDialog timePicker = new TimePickerDialog(
|
return new TimePickerDialog(
|
||||||
getContext(), timePickerListener,
|
getContext(), timePickerListener,
|
||||||
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE),
|
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE),
|
||||||
android.text.format.DateFormat.is24HourFormat(getContext()));
|
android.text.format.DateFormat.is24HourFormat(getContext()));
|
||||||
|
|
||||||
return timePicker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), timeFormat.format(newMeasurement.getDateTime()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getMaxValue() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -24,45 +24,45 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class WHRMeasurementView extends MeasurementView {
|
public class WHRMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
public WHRMeasurementView(Context context) {
|
public WHRMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_whr), ContextCompat.getDrawable(context, R.drawable.ic_whr));
|
super(context, context.getResources().getString(R.string.label_whr), ContextCompat.getDrawable(context, R.drawable.ic_whr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
|
setVisible(preferences.getBoolean("hipEnable", false)
|
||||||
|
&& preferences.getBoolean("waistEnable", false));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEditable() {
|
public boolean isEditable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getWHR());
|
return measurement.getWHR();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
setDiffOnView(newMeasurement.getWHR(), lastMeasurement.getWHR());
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUnit() {
|
protected String getUnit() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
protected float getMaxValue() {
|
||||||
setVisible(preferences.getBoolean("hipEnable", false) && preferences.getBoolean("waistEnable", false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
|
||||||
return evalSheet.evaluateWHR(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getMaxValue() {
|
|
||||||
return 1.5f;
|
return 1.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateWHR(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,45 +24,44 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class WHtRMeasurementView extends MeasurementView {
|
public class WHtRMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
public WHtRMeasurementView(Context context) {
|
public WHtRMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_whtr), ContextCompat.getDrawable(context, R.drawable.ic_whtr));
|
super(context, context.getResources().getString(R.string.label_whtr), ContextCompat.getDrawable(context, R.drawable.ic_whtr));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEditable() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getWHtR(getScaleUser().getBodyHeight()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
setDiffOnView(newMeasurement.getWHtR(getScaleUser().getBodyHeight()), lastMeasurement.getWHtR(getScaleUser().getBodyHeight()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
setVisible(preferences.getBoolean("waistEnable", false));
|
setVisible(preferences.getBoolean("waistEnable", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
public boolean isEditable() {
|
||||||
return evalSheet.evaluateWHtR(value);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxValue() {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
|
return measurement.getWHtR(getScaleUser().getBodyHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
// Empty
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getMaxValue() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateWHtR(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,40 +24,39 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class WaistMeasurementView extends MeasurementView {
|
public class WaistMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
public WaistMeasurementView(Context context) {
|
public WaistMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_waist), ContextCompat.getDrawable(context, R.drawable.ic_waist));
|
super(context, context.getResources().getString(R.string.label_waist), ContextCompat.getDrawable(context, R.drawable.ic_waist));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getWaist());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
setDiffOnView(newMeasurement.getWaist(), lastMeasurement.getWaist());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return "cm";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
setVisible(preferences.getBoolean("waistEnable", false));
|
setVisible(preferences.getBoolean("waistEnable", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
return evalSheet.evaluateWaist(value);
|
return measurement.getWaist();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxValue() {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
measurement.setWaist(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
|
return "cm";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getMaxValue() {
|
||||||
return 200;
|
return 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateWaist(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class WaterMeasurementView extends MeasurementView {
|
public class WaterMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
private boolean estimateWaterEnable;
|
private boolean estimateWaterEnable;
|
||||||
|
|
||||||
@@ -32,33 +32,6 @@ public class WaterMeasurementView extends MeasurementView {
|
|||||||
super(context, context.getResources().getString(R.string.label_water), ContextCompat.getDrawable(context, R.drawable.ic_water));
|
super(context, context.getResources().getString(R.string.label_water), ContextCompat.getDrawable(context, R.drawable.ic_water));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEditable() {
|
|
||||||
if (estimateWaterEnable && getMeasurementMode() == MeasurementViewMode.ADD) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
if (estimateWaterEnable && getMeasurementMode() == MeasurementViewMode.ADD) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), (getContext().getString(R.string.label_automatic)));
|
|
||||||
} else {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getWater());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
setDiffOnView(newMeasurement.getWater(), lastMeasurement.getWater());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return "%";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
setVisible(preferences.getBoolean("waterEnable", true));
|
setVisible(preferences.getBoolean("waterEnable", true));
|
||||||
@@ -66,12 +39,32 @@ public class WaterMeasurementView extends MeasurementView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
return evalSheet.evaluateBodyWater(value);
|
return measurement.getWater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxValue() {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
measurement.setWater(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
|
return "%";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getMaxValue() {
|
||||||
return 80;
|
return 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isEstimationEnabled() {
|
||||||
|
return estimateWaterEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateBodyWater(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,40 +25,39 @@ import com.health.openscale.core.datatypes.ScaleUser;
|
|||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
import com.health.openscale.core.evaluation.EvaluationSheet;
|
import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||||
|
|
||||||
public class WeightMeasurementView extends MeasurementView {
|
public class WeightMeasurementView extends FloatMeasurementView {
|
||||||
|
|
||||||
public WeightMeasurementView(Context context) {
|
public WeightMeasurementView(Context context) {
|
||||||
super(context, context.getResources().getString(R.string.label_weight), ContextCompat.getDrawable(context, R.drawable.ic_weight));
|
super(context, context.getResources().getString(R.string.label_weight), ContextCompat.getDrawable(context, R.drawable.ic_weight));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateValue(ScaleMeasurement newMeasurement) {
|
|
||||||
setValueOnView(newMeasurement.getDateTime(), newMeasurement.getConvertedWeight(getScaleUser().getScaleUnit()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateDiff(ScaleMeasurement newMeasurement, ScaleMeasurement lastMeasurement) {
|
|
||||||
setDiffOnView(newMeasurement.getConvertedWeight(getScaleUser().getScaleUnit()), lastMeasurement.getConvertedWeight(getScaleUser().getScaleUnit()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUnit() {
|
|
||||||
return ScaleUser.UNIT_STRING[getScaleUser().getScaleUnit()];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePreferences(SharedPreferences preferences) {
|
public void updatePreferences(SharedPreferences preferences) {
|
||||||
setVisible(preferences.getBoolean("weightEnable", true));
|
setVisible(preferences.getBoolean("weightEnable", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||||
return evalSheet.evaluateWeight(value);
|
return measurement.getConvertedWeight(getScaleUser().getScaleUnit());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getMaxValue() {
|
protected void setMeasurementValue(float value, ScaleMeasurement measurement) {
|
||||||
|
measurement.setConvertedWeight(value, getScaleUser().getScaleUnit());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getUnit() {
|
||||||
|
return ScaleUser.UNIT_STRING[getScaleUser().getScaleUnit()];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float getMaxValue() {
|
||||||
return 300;
|
return 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EvaluationResult evaluateSheet(EvaluationSheet evalSheet, float value) {
|
||||||
|
return evalSheet.evaluateWeight(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user