mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-23 00:33:09 +02:00
added options to estimate body fat and body water
This commit is contained in:
@@ -27,6 +27,8 @@ import android.widget.Toast;
|
||||
import com.health.openscale.R;
|
||||
import com.health.openscale.core.alarm.AlarmHandler;
|
||||
import com.health.openscale.core.bluetooth.BluetoothCommunication;
|
||||
import com.health.openscale.core.bodymetric.EstimatedFatMetric;
|
||||
import com.health.openscale.core.bodymetric.EstimatedWaterMetric;
|
||||
import com.health.openscale.core.database.ScaleDatabase;
|
||||
import com.health.openscale.core.database.ScaleUserDatabase;
|
||||
import com.health.openscale.core.datatypes.ScaleData;
|
||||
@@ -188,6 +190,18 @@ public class OpenScale {
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("estimateFatEnable", false)) {
|
||||
EstimatedFatMetric fatMetric = EstimatedFatMetric.getEstimatedFatMetric(EstimatedFatMetric.FORMULA_FAT.valueOf(prefs.getString("estimateFatFormula", "BF_DEURENBERG_II")));
|
||||
|
||||
scaleData.setFat(fatMetric.getFat(getScaleUser(scaleData.getUserId()), scaleData));
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("estimateWaterEnable", false)) {
|
||||
EstimatedWaterMetric waterMetric = EstimatedWaterMetric.getEstimatedWaterMetric(EstimatedWaterMetric.FORMULA_WATER.valueOf(prefs.getString("estimateWaterFormula", "TBW_BEHNKE")));
|
||||
|
||||
scaleData.setWater(waterMetric.getWater(getScaleUser(scaleData.getUserId()), scaleData));
|
||||
}
|
||||
|
||||
if (scaleDB.insertEntry(scaleData)) {
|
||||
ScaleUser scaleUser = getScaleUser(scaleData.getUserId());
|
||||
|
||||
|
@@ -0,0 +1,35 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public class BFBJoN extends EstimatedFatMetric {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "British Journal of Nutrition (1991)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFat(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return (data.getBMI(user.body_height) * 1.2f) + (user.getAge() * 0.23f) - 16.2f;
|
||||
}
|
||||
|
||||
return (data.getBMI(user.body_height) * 1.2f) + (user.getAge() * 0.23f) - 5.4f;
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public class BFDeurenberg extends EstimatedFatMetric {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Deurenberg et. al (1998)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFat(ScaleUser user, ScaleData data) {
|
||||
if (user.getAge() >= 16) {
|
||||
return (1.2f * data.getBMI(user.body_height)) + (0.23f*user.getAge()) - (10.8f*(1-user.gender)) - 5.4f;
|
||||
}
|
||||
|
||||
return (1.294f * data.getBMI(user.body_height)) + (0.20f*user.getAge()) - (11.4f*(1-user.gender)) - 8.0f;
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public class BFEddy extends EstimatedFatMetric {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Eddy et. al (1976)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFat(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return (1.281f* data.getBMI(user.body_height)) - 10.13f;
|
||||
}
|
||||
|
||||
return (1.48f* data.getBMI(user.body_height)) - 7.0f;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public class BFGallagher extends EstimatedFatMetric {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Gallagher et. al [non-asian] (2000)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFat(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
// non-asian male
|
||||
return 64.5f - 848.0f * (1.0f / data.getBMI(user.body_height)) + 0.079f * user.getAge() - 16.4f + 0.05f * user.getAge() + 39.0f * (1.0f / data.getBMI(user.body_height));
|
||||
}
|
||||
|
||||
// non-asian female
|
||||
return 64.5f - 848.0f * (1.0f / data.getBMI(user.body_height)) + 0.079f * user.getAge();
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public class BFGallagherAsian extends EstimatedFatMetric {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Gallagher et. al [asian] (2000)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFat(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
// asian male
|
||||
return 51.9f - 740.0f * (1.0f / data.getBMI(user.body_height)) + 0.029f * user.getAge();
|
||||
}
|
||||
|
||||
// asian female
|
||||
return 64.8f - 752.0f * (1.0f / data.getBMI(user.body_height)) + 0.016f * user.getAge();
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public abstract class EstimatedFatMetric {
|
||||
public enum FORMULA_FAT { BF_DEURENBERG, BF_BJoN, BF_EDDY, BF_GALLAGHER, BF_GALLAGHER_ASIAN };
|
||||
|
||||
public static EstimatedFatMetric getEstimatedFatMetric( FORMULA_FAT fatMetric) {
|
||||
switch (fatMetric) {
|
||||
case BF_DEURENBERG:
|
||||
return new BFDeurenberg();
|
||||
case BF_BJoN:
|
||||
return new BFBJoN();
|
||||
case BF_EDDY:
|
||||
return new BFEddy();
|
||||
case BF_GALLAGHER:
|
||||
return new BFGallagher();
|
||||
case BF_GALLAGHER_ASIAN:
|
||||
return new BFGallagherAsian();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
public abstract float getFat(ScaleUser user, ScaleData data);
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public abstract class EstimatedWaterMetric {
|
||||
public enum FORMULA_WATER { TBW_BEHNKE, TBW_DELWAIDECRENIER, TBW_HUMEWEYERS, TBW_LEESONGKIM };
|
||||
|
||||
public static EstimatedWaterMetric getEstimatedWaterMetric( FORMULA_WATER waterMetric) {
|
||||
switch (waterMetric) {
|
||||
case TBW_BEHNKE:
|
||||
return new TBWBehnke();
|
||||
case TBW_DELWAIDECRENIER:
|
||||
return new TBWDelwaideCrenier();
|
||||
case TBW_HUMEWEYERS:
|
||||
return new TBWHumeWeyers();
|
||||
case TBW_LEESONGKIM:
|
||||
return new TBWLeeSongKim();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
public abstract float getWater(ScaleUser user, ScaleData data);
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public class TBWBehnke extends EstimatedWaterMetric {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Behnke et. al (1963)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWater(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return 0.72f * (0.204f * user.body_height * user.body_height) / 100.0f;
|
||||
}
|
||||
|
||||
return 0.72f * (0.18f * user.body_height * user.body_height) / 100.0f;
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public class TBWDelwaideCrenier extends EstimatedWaterMetric {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Delwaide-Crenier et. al (1973)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWater(ScaleUser user, ScaleData data) {
|
||||
return 0.72f * (-1.976f + 0.907f * data.getWeight());
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public class TBWHumeWeyers extends EstimatedWaterMetric {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Hume & Weyers (1971)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWater(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return (0.194786f * user.body_height) + (0.296785f * data.getWeight()) - 14.012934f;
|
||||
}
|
||||
|
||||
return (0.34454f * user.body_height) + (0.183809f * data.getWeight()) - 35.270121f;
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
/* Copyright (C) 2017 olie.xdev <olie.xdev@googlemail.com>
|
||||
*
|
||||
* 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 com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
public class TBWLeeSongKim extends EstimatedWaterMetric {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Lee, Song, Kim, Lee et. al (1999)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWater(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return -28.3497f + (0.243057f * user.body_height) + (0.366248f * data.getWeight());
|
||||
}
|
||||
|
||||
return -26.6224f + (0.262513f * user.body_height) + (0.232948f * data.getWeight());
|
||||
}
|
||||
}
|
@@ -19,18 +19,37 @@ import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.MultiSelectListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.health.openscale.R;
|
||||
import com.health.openscale.core.OpenScale;
|
||||
import com.health.openscale.core.bodymetric.EstimatedFatMetric;
|
||||
import com.health.openscale.core.bodymetric.EstimatedWaterMetric;
|
||||
|
||||
public class MeasurementPreferences extends PreferenceFragment {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MeasurementPreferences extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public static final String PREFERENCE_KEY_DELETE_ALL = "deleteAll";
|
||||
public static final String PREFERENCE_KEY_ESTIMATE_FAT = "estimateFatEnable";
|
||||
public static final String PREFERENCE_KEY_ESTIMATE_FAT_FORMULA = "estimateFatFormula";
|
||||
public static final String PREFERENCE_KEY_ESTIMATE_WATER = "estimateWaterEnable";
|
||||
public static final String PREFERENCE_KEY_ESTIMATE_WATER_FORMULA = "estimateWaterFormula";
|
||||
|
||||
private Preference deleteAll;
|
||||
private CheckBoxPreference estimateFatEnable;
|
||||
private ListPreference estimateFatFormula;
|
||||
private CheckBoxPreference estimateWaterEnable;
|
||||
private ListPreference estimateWaterFormula;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -40,6 +59,109 @@ public class MeasurementPreferences extends PreferenceFragment {
|
||||
|
||||
deleteAll = (Preference) findPreference(PREFERENCE_KEY_DELETE_ALL);
|
||||
deleteAll.setOnPreferenceClickListener(new onClickListenerDeleteAll());
|
||||
|
||||
estimateFatEnable = (CheckBoxPreference) findPreference(PREFERENCE_KEY_ESTIMATE_FAT);
|
||||
estimateFatFormula = (ListPreference) findPreference(PREFERENCE_KEY_ESTIMATE_FAT_FORMULA);
|
||||
estimateWaterEnable = (CheckBoxPreference) findPreference(PREFERENCE_KEY_ESTIMATE_WATER);
|
||||
estimateWaterFormula = (ListPreference) findPreference(PREFERENCE_KEY_ESTIMATE_WATER_FORMULA);
|
||||
|
||||
updateFatListPreferences();
|
||||
updateWaterListPreferences();
|
||||
initSummary(getPreferenceScreen());
|
||||
}
|
||||
|
||||
public void updateFatListPreferences() {
|
||||
ArrayList<String> listEntries = new ArrayList();
|
||||
ArrayList<String> listEntryValues = new ArrayList();
|
||||
|
||||
for (EstimatedFatMetric.FORMULA_FAT formulaFat : EstimatedFatMetric.FORMULA_FAT.values()) {
|
||||
EstimatedFatMetric fatMetric = EstimatedFatMetric.getEstimatedFatMetric(formulaFat);
|
||||
|
||||
listEntries.add(fatMetric.getName());
|
||||
listEntryValues.add(formulaFat.toString());
|
||||
}
|
||||
|
||||
estimateFatFormula.setEntries(listEntries.toArray(new CharSequence[listEntries.size()]));
|
||||
estimateFatFormula.setEntryValues(listEntryValues.toArray(new CharSequence[listEntryValues.size()]));
|
||||
}
|
||||
|
||||
public void updateWaterListPreferences() {
|
||||
ArrayList<String> listEntries = new ArrayList();
|
||||
ArrayList<String> listEntryValues = new ArrayList();
|
||||
|
||||
for (EstimatedWaterMetric.FORMULA_WATER formulaWater : EstimatedWaterMetric.FORMULA_WATER.values()) {
|
||||
EstimatedWaterMetric waterMetric = EstimatedWaterMetric.getEstimatedWaterMetric(formulaWater);
|
||||
|
||||
listEntries.add(waterMetric.getName());
|
||||
listEntryValues.add(formulaWater.toString());
|
||||
}
|
||||
|
||||
estimateWaterFormula.setEntries(listEntries.toArray(new CharSequence[listEntries.size()]));
|
||||
estimateWaterFormula.setEntryValues(listEntryValues.toArray(new CharSequence[listEntryValues.size()]));
|
||||
}
|
||||
|
||||
private void initSummary(Preference p) {
|
||||
if (p instanceof PreferenceGroup) {
|
||||
PreferenceGroup pGrp = (PreferenceGroup) p;
|
||||
for (int i = 0; i < pGrp.getPreferenceCount(); i++) {
|
||||
initSummary(pGrp.getPreference(i));
|
||||
}
|
||||
} else {
|
||||
updatePrefSummary(p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
updatePrefSummary(findPreference(key));
|
||||
}
|
||||
|
||||
private void updatePrefSummary(Preference p) {
|
||||
if (estimateFatEnable.isChecked()) {
|
||||
estimateFatFormula.setEnabled(true);
|
||||
} else {
|
||||
estimateFatFormula.setEnabled(false);
|
||||
}
|
||||
|
||||
if (estimateWaterEnable.isChecked()) {
|
||||
estimateWaterFormula.setEnabled(true);
|
||||
} else {
|
||||
estimateWaterFormula.setEnabled(false);
|
||||
}
|
||||
|
||||
estimateFatFormula.setSummary(EstimatedFatMetric.getEstimatedFatMetric(EstimatedFatMetric.FORMULA_FAT.valueOf(estimateFatFormula.getValue())).getName());
|
||||
estimateWaterFormula.setSummary(EstimatedWaterMetric.getEstimatedWaterMetric(EstimatedWaterMetric.FORMULA_WATER.valueOf(estimateWaterFormula.getValue())).getName());
|
||||
|
||||
if (p instanceof EditTextPreference) {
|
||||
EditTextPreference editTextPref = (EditTextPreference) p;
|
||||
if (p.getTitle().toString().contains("assword"))
|
||||
{
|
||||
p.setSummary("******");
|
||||
} else {
|
||||
p.setSummary(editTextPref.getText());
|
||||
}
|
||||
}
|
||||
|
||||
if (p instanceof MultiSelectListPreference) {
|
||||
MultiSelectListPreference editMultiListPref = (MultiSelectListPreference) p;
|
||||
|
||||
CharSequence[] entries = editMultiListPref.getEntries();
|
||||
CharSequence[] entryValues = editMultiListPref.getEntryValues();
|
||||
List<String> currentEntries = new ArrayList<>();
|
||||
Set<String> currentEntryValues = editMultiListPref.getValues();
|
||||
|
||||
for (int i = 0; i < entries.length; i++)
|
||||
if (currentEntryValues.contains(entryValues[i]))
|
||||
currentEntries.add(entries[i].toString());
|
||||
|
||||
p.setSummary(currentEntries.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private class onClickListenerDeleteAll implements Preference.OnPreferenceClickListener {
|
||||
|
@@ -26,13 +26,27 @@ import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||
|
||||
public class FatMeasurementView extends MeasurementView {
|
||||
|
||||
private boolean estimateFatEnable;
|
||||
|
||||
public FatMeasurementView(Context context) {
|
||||
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(ScaleData updateData) {
|
||||
setValueOnView(updateData.getFat());
|
||||
if (estimateFatEnable && getMeasurementMode() == MeasurementViewMode.ADD) {
|
||||
setValueOnView((getContext().getString(R.string.label_automatic)));
|
||||
} else {
|
||||
setValueOnView(updateData.getFat());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,6 +62,7 @@ public class FatMeasurementView extends MeasurementView {
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("fatEnable", true));
|
||||
estimateFatEnable = preferences.getBoolean("estimateFatEnable", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -21,6 +21,7 @@ import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.Html;
|
||||
import android.text.InputType;
|
||||
@@ -28,7 +29,6 @@ import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
@@ -38,11 +38,6 @@ import android.widget.Space;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
import android.os.Handler;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnTouchListener;
|
||||
|
||||
import com.health.openscale.R;
|
||||
import com.health.openscale.core.OpenScale;
|
||||
@@ -213,8 +208,11 @@ public abstract class MeasurementView extends TableLayout {
|
||||
if (value.length() == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return Float.valueOf(value);
|
||||
try {
|
||||
return Float.valueOf(value);
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void incValue() {
|
||||
|
@@ -26,13 +26,27 @@ import com.health.openscale.core.evaluation.EvaluationSheet;
|
||||
|
||||
public class WaterMeasurementView extends MeasurementView {
|
||||
|
||||
private boolean estimateWaterEnable;
|
||||
|
||||
public WaterMeasurementView(Context context) {
|
||||
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(ScaleData updateData) {
|
||||
setValueOnView(updateData.getWater());
|
||||
if (estimateWaterEnable && getMeasurementMode() == MeasurementViewMode.ADD) {
|
||||
setValueOnView((getContext().getString(R.string.label_automatic)));
|
||||
} else {
|
||||
setValueOnView(updateData.getWater());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,6 +62,7 @@ public class WaterMeasurementView extends MeasurementView {
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("waterEnable", true));
|
||||
estimateWaterEnable = preferences.getBoolean("estimateWaterEnable", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -120,6 +120,13 @@
|
||||
|
||||
<string name="label_delete_confirmation">Delete confirmation</string>
|
||||
|
||||
<string name="label_estimate_fat">Estimate body fat</string>
|
||||
<string name="label_estimate_water">Estimate body water</string>
|
||||
|
||||
<string name="label_estimate_fat_formula">Body fat formula</string>
|
||||
<string name="label_estimate_water_formula">Body water formula</string>
|
||||
<string name="label_automatic">auto</string>
|
||||
|
||||
<string name="label_reminder">Reminder</string>
|
||||
<string name="label_reminder_weekdays">Weekdays</string>
|
||||
<string name="label_reminder_time">Time</string>
|
||||
|
@@ -6,5 +6,9 @@
|
||||
<CheckBoxPreference android:title="@string/label_bone" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="boneEnable" android:defaultValue="false"/>
|
||||
<CheckBoxPreference android:title="@string/label_waist" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="waistEnable" android:defaultValue="false"/>
|
||||
<CheckBoxPreference android:title="@string/label_hip" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="hipEnable" android:defaultValue="false"/>
|
||||
<CheckBoxPreference android:title="@string/label_estimate_fat" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="estimateFatEnable" android:defaultValue="false"/>
|
||||
<ListPreference android:title="@string/label_estimate_fat_formula" android:key="estimateFatFormula" android:defaultValue="BF_GALLAGHER"/>
|
||||
<CheckBoxPreference android:title="@string/label_estimate_water" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="estimateWaterEnable" android:defaultValue="false"/>
|
||||
<ListPreference android:title="@string/label_estimate_water_formula" android:key="estimateWaterFormula" android:defaultValue="TBW_LEESONGKIM"/>
|
||||
<Preference android:title="@string/label_delete_all" android:key="deleteAll"></Preference>
|
||||
</PreferenceScreen>
|
Reference in New Issue
Block a user