mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-31 20:11:58 +02:00
@@ -286,13 +286,6 @@ public class OpenScale {
|
|||||||
scaleMeasurement.setWater(waterMetric.getWater(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
|
scaleMeasurement.setWater(waterMetric.getWater(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
|
||||||
}
|
}
|
||||||
|
|
||||||
settings = new MeasurementViewSettings(prefs, LBMMeasurementView.KEY);
|
|
||||||
if (settings.isEnabled() && settings.isEstimationEnabled()) {
|
|
||||||
EstimatedLBMMetric lbmMetric = EstimatedLBMMetric.getEstimatedMetric(
|
|
||||||
EstimatedLBMMetric.FORMULA.valueOf(settings.getEstimationFormula()));
|
|
||||||
scaleMeasurement.setLbm(lbmMetric.getLBM(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
|
|
||||||
}
|
|
||||||
|
|
||||||
settings = new MeasurementViewSettings(prefs, FatMeasurementView.KEY);
|
settings = new MeasurementViewSettings(prefs, FatMeasurementView.KEY);
|
||||||
if (settings.isEnabled() && settings.isEstimationEnabled()) {
|
if (settings.isEnabled() && settings.isEstimationEnabled()) {
|
||||||
EstimatedFatMetric fatMetric = EstimatedFatMetric.getEstimatedMetric(
|
EstimatedFatMetric fatMetric = EstimatedFatMetric.getEstimatedMetric(
|
||||||
@@ -300,6 +293,14 @@ public class OpenScale {
|
|||||||
scaleMeasurement.setFat(fatMetric.getFat(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
|
scaleMeasurement.setFat(fatMetric.getFat(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Must be after fat estimation as one formula is based on fat
|
||||||
|
settings = new MeasurementViewSettings(prefs, LBMMeasurementView.KEY);
|
||||||
|
if (settings.isEnabled() && settings.isEstimationEnabled()) {
|
||||||
|
EstimatedLBMMetric lbmMetric = EstimatedLBMMetric.getEstimatedMetric(
|
||||||
|
EstimatedLBMMetric.FORMULA.valueOf(settings.getEstimationFormula()));
|
||||||
|
scaleMeasurement.setLbm(lbmMetric.getLBM(getScaleUser(scaleMeasurement.getUserId()), scaleMeasurement));
|
||||||
|
}
|
||||||
|
|
||||||
if (measurementDAO.insert(scaleMeasurement) != -1) {
|
if (measurementDAO.insert(scaleMeasurement) != -1) {
|
||||||
ScaleUser scaleUser = getScaleUser(scaleMeasurement.getUserId());
|
ScaleUser scaleUser = getScaleUser(scaleMeasurement.getUserId());
|
||||||
|
|
||||||
|
@@ -15,12 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.health.openscale.core.bodymetric;
|
package com.health.openscale.core.bodymetric;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
public abstract class EstimatedLBMMetric {
|
public abstract class EstimatedLBMMetric {
|
||||||
// Don't change enum names, they are stored persistent in preferences
|
// Don't change enum names, they are stored persistent in preferences
|
||||||
public enum FORMULA { LBW_HUME, LBW_BOER }
|
public enum FORMULA { LBW_HUME, LBW_BOER, LBW_WEIGHT_MINUS_FAT }
|
||||||
|
|
||||||
public static EstimatedLBMMetric getEstimatedMetric(FORMULA metric) {
|
public static EstimatedLBMMetric getEstimatedMetric(FORMULA metric) {
|
||||||
switch (metric) {
|
switch (metric) {
|
||||||
@@ -28,11 +30,13 @@ public abstract class EstimatedLBMMetric {
|
|||||||
return new LBMHume();
|
return new LBMHume();
|
||||||
case LBW_BOER:
|
case LBW_BOER:
|
||||||
return new LBMBoer();
|
return new LBMBoer();
|
||||||
|
case LBW_WEIGHT_MINUS_FAT:
|
||||||
|
return new LBMWeightMinusFat();
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getName();
|
public abstract String getName(Context context);
|
||||||
public abstract float getLBM(ScaleUser user, ScaleMeasurement data);
|
public abstract float getLBM(ScaleUser user, ScaleMeasurement data);
|
||||||
}
|
}
|
||||||
|
@@ -16,12 +16,14 @@
|
|||||||
|
|
||||||
package com.health.openscale.core.bodymetric;
|
package com.health.openscale.core.bodymetric;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
public class LBMBoer extends EstimatedLBMMetric {
|
public class LBMBoer extends EstimatedLBMMetric {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName(Context context) {
|
||||||
return "Boer (1984)";
|
return "Boer (1984)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,12 +16,14 @@
|
|||||||
|
|
||||||
package com.health.openscale.core.bodymetric;
|
package com.health.openscale.core.bodymetric;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
public class LBMHume extends EstimatedLBMMetric {
|
public class LBMHume extends EstimatedLBMMetric {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName(Context context) {
|
||||||
return "Hume (1966)";
|
return "Hume (1966)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,42 @@
|
|||||||
|
/* 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.core.bodymetric;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.health.openscale.R;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
|
|
||||||
|
class LBMWeightMinusFat extends EstimatedLBMMetric {
|
||||||
|
@Override
|
||||||
|
public String getName(Context context) {
|
||||||
|
return String.format("%s - %s",
|
||||||
|
context.getResources().getString(R.string.label_weight),
|
||||||
|
context.getResources().getString(R.string.label_fat));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getLBM(ScaleUser user, ScaleMeasurement data) {
|
||||||
|
if (data.getFat() == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float absFat = data.getWeight() * data.getFat() / 100.0f;
|
||||||
|
return data.getWeight() - absFat;
|
||||||
|
}
|
||||||
|
}
|
@@ -75,7 +75,7 @@ public class LBMMeasurementView extends FloatMeasurementView {
|
|||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for (EstimatedLBMMetric.FORMULA formula : EstimatedLBMMetric.FORMULA.values()) {
|
for (EstimatedLBMMetric.FORMULA formula : EstimatedLBMMetric.FORMULA.values()) {
|
||||||
entries[idx] = EstimatedLBMMetric.getEstimatedMetric(formula).getName();
|
entries[idx] = EstimatedLBMMetric.getEstimatedMetric(formula).getName(getContext());
|
||||||
values[idx] = formula.name();
|
values[idx] = formula.name();
|
||||||
++idx;
|
++idx;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user