1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-30 19:49:59 +02:00

Move isMale to gender enum

This commit is contained in:
Erik Johansson
2018-01-17 20:25:02 +01:00
parent 613d24db65
commit 29ef63a830
23 changed files with 35 additions and 33 deletions

View File

@@ -208,7 +208,7 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
(byte) selectedUser.getBirthday().getMonth(),
(byte) selectedUser.getBirthday().getDate(),
(byte) selectedUser.getBodyHeight(),
(byte) (((selectedUser.isMale() ? 1 : 0) << 7) | activity)
(byte) (((selectedUser.getGender().isMale() ? 1 : 0) << 7) | activity)
});
} else {
// Get existing user information

View File

@@ -104,7 +104,7 @@ public class BluetoothDigooDGSO38H extends BluetoothCommunication {
if (weightStabilized) {
//The weight is stabilized, now we want to measure all available values
byte gender = selectedUser.isMale() ? (byte)0x00: (byte)0x01;
byte gender = selectedUser.getGender().isMale() ? (byte)0x00: (byte)0x01;
byte height = (byte) (selectedUser.getBodyHeight() & 0xFF);
byte age = (byte)(selectedUser.getAge(new Date()) & 0xff);
byte unit = 0x01; // kg

View File

@@ -61,7 +61,7 @@ public class BluetoothExcelvanCF369BLE extends BluetoothCommunication {
case 0:
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
byte sex = selectedUser.isMale() ? (byte)0x01 : (byte)0x00; // 01 - male; 00 - female
byte sex = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0x00; // 01 - male; 00 - female
byte height = (byte)(selectedUser.getBodyHeight() & 0xff); // cm
byte age = (byte)(selectedUser.getAge(new Date()) & 0xff);
byte unit = 0x01; // kg

View File

@@ -58,7 +58,7 @@ public class BluetoothExingtechY1 extends BluetoothCommunication {
case 1:
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
byte gender = selectedUser.isMale() ? (byte)0x00 : (byte)0x01; // 00 - male; 01 - female
byte gender = selectedUser.getGender().isMale() ? (byte)0x00 : (byte)0x01; // 00 - male; 01 - female
byte height = (byte)(selectedUser.getBodyHeight() & 0xff); // cm
byte age = (byte)(selectedUser.getAge(new Date()) & 0xff);

View File

@@ -117,7 +117,7 @@ public class BluetoothMGB extends BluetoothCommunication {
break;
case 3:
writeCfg(0xFB, (user.isMale() ? 1 : 2), user.getAge(new Date()), user.getBodyHeight());
writeCfg(0xFB, (user.getGender().isMale() ? 1 : 2), user.getAge(new Date()), user.getBodyHeight());
break;
case 4:

View File

@@ -202,7 +202,7 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication {
(byte) selectedUser.getBirthday().getMonth(),
(byte) selectedUser.getBirthday().getDate(),
(byte) selectedUser.getBodyHeight(),
(byte) (((selectedUser.isMale() ? 1 : 0) << 7) | activity)
(byte) (((selectedUser.getGender().isMale() ? 1 : 0) << 7) | activity)
});
} else {
// Get existing user information

View File

@@ -69,7 +69,7 @@ public class BluetoothYunmaiMini extends BluetoothCommunication {
int user_id = getUniqueNumber();
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
byte sex = selectedUser.isMale() ? (byte)0x01 : (byte)0x02;
byte sex = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0x02;
byte display_unit = selectedUser.getScaleUnit() == Converters.WeightUnit.KG ? (byte) 0x01 : (byte) 0x02;
byte[] user_add_or_query = new byte[]{(byte)0x0d, (byte)0x12, (byte)0x10, (byte)0x01, (byte)0x00, (byte) 0x00, (byte) ((user_id & 0xFF00) >> 8), (byte) ((user_id & 0xFF) >> 0), (byte)selectedUser.getBodyHeight(), (byte)sex, (byte) selectedUser.getAge(new Date()), (byte) 0x55, (byte) 0x5a, (byte) 0x00, (byte)0x00, (byte) display_unit, (byte) 0x03, (byte) 0x00 };

View File

@@ -69,7 +69,7 @@ public class BluetoothYunmaiSE extends BluetoothCommunication {
int user_id = getUniqueNumber();
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
byte sex = selectedUser.isMale() ? (byte)0x01 : (byte)0x02;
byte sex = selectedUser.getGender().isMale() ? (byte)0x01 : (byte)0x02;
byte display_unit = selectedUser.getScaleUnit() == Converters.WeightUnit.KG ? (byte) 0x01 : (byte) 0x02;
byte[] user_add_or_query = new byte[]{(byte)0x0d, (byte)0x12, (byte)0x10, (byte)0x01, (byte)0x00, (byte) 0x00, (byte) ((user_id & 0xFF00) >> 8), (byte) ((user_id & 0xFF) >> 0), (byte)selectedUser.getBodyHeight(), (byte)sex, (byte) selectedUser.getAge(new Date()), (byte) 0x55, (byte) 0x5a, (byte) 0x00, (byte)0x00, (byte) display_unit, (byte) 0x03, (byte) 0x00 };

View File

@@ -26,7 +26,7 @@ public class BFDeurenberg extends EstimatedFatMetric {
@Override
public float getFat(ScaleUser user, ScaleMeasurement data) {
final int gender = user.isMale() ? 1 : 0;
final int gender = user.getGender().isMale() ? 1 : 0;
if (user.getAge(data.getDateTime()) >= 16) {
return (1.2f * data.getBMI(user.getBodyHeight())) + (0.23f*user.getAge(data.getDateTime())) - (10.8f * gender) - 5.4f;
}

View File

@@ -26,7 +26,7 @@ public class BFDeurenbergII extends EstimatedFatMetric {
@Override
public float getFat(ScaleUser user, ScaleMeasurement data) {
if (user.isMale()) {
if (user.getGender().isMale()) {
return (data.getBMI(user.getBodyHeight()) * 1.2f) + (user.getAge(data.getDateTime()) * 0.23f) - 16.2f;
}

View File

@@ -26,7 +26,7 @@ public class BFEddy extends EstimatedFatMetric {
@Override
public float getFat(ScaleUser user, ScaleMeasurement data) {
if (user.isMale()) {
if (user.getGender().isMale()) {
return (1.281f* data.getBMI(user.getBodyHeight())) - 10.13f;
}

View File

@@ -26,7 +26,7 @@ public class BFGallagher extends EstimatedFatMetric {
@Override
public float getFat(ScaleUser user, ScaleMeasurement data) {
if (user.isMale()) {
if (user.getGender().isMale()) {
// non-asian male
return 64.5f - 848.0f * (1.0f / data.getBMI(user.getBodyHeight())) + 0.079f * user.getAge(data.getDateTime()) - 16.4f + 0.05f * user.getAge(data.getDateTime()) + 39.0f * (1.0f / data.getBMI(user.getBodyHeight()));
}

View File

@@ -26,7 +26,7 @@ public class BFGallagherAsian extends EstimatedFatMetric {
@Override
public float getFat(ScaleUser user, ScaleMeasurement data) {
if (user.isMale()) {
if (user.getGender().isMale()) {
// asian male
return 51.9f - 740.0f * (1.0f / data.getBMI(user.getBodyHeight())) + 0.029f * user.getAge(data.getDateTime());
}

View File

@@ -27,7 +27,7 @@ public class LBWBoer extends EstimatedLBWMetric {
@Override
public float getLBW(ScaleUser user, ScaleMeasurement data) {
if (user.isMale()) {
if (user.getGender().isMale()) {
return (0.4071f * data.getWeight()) + (0.267f * user.getBodyHeight()) - 19.2f;
}

View File

@@ -27,7 +27,7 @@ public class LBWHume extends EstimatedLBWMetric {
@Override
public float getLBW(ScaleUser user, ScaleMeasurement data) {
if (user.isMale()) {
if (user.getGender().isMale()) {
return (0.32810f * data.getWeight()) + (0.33929f * user.getBodyHeight()) - 29.5336f;
}

View File

@@ -26,7 +26,7 @@ public class TBWBehnke extends EstimatedWaterMetric {
@Override
public float getWater(ScaleUser user, ScaleMeasurement data) {
if (user.isMale()) {
if (user.getGender().isMale()) {
return 0.72f * (0.204f * user.getBodyHeight() * user.getBodyHeight()) / 100.0f;
}

View File

@@ -26,7 +26,7 @@ public class TBWHumeWeyers extends EstimatedWaterMetric {
@Override
public float getWater(ScaleUser user, ScaleMeasurement data) {
if (user.isMale()) {
if (user.getGender().isMale()) {
return (0.194786f * user.getBodyHeight()) + (0.296785f * data.getWeight()) - 14.012934f;
}

View File

@@ -26,7 +26,7 @@ public class TBWLeeSongKim extends EstimatedWaterMetric {
@Override
public float getWater(ScaleUser user, ScaleMeasurement data) {
if (user.isMale()) {
if (user.getGender().isMale()) {
return -28.3497f + (0.243057f * user.getBodyHeight()) + (0.366248f * data.getWeight());
}

View File

@@ -234,7 +234,7 @@ public class ScaleMeasurement implements Cloneable {
float bmr = 0.0f;
// BMR formula by Mifflin, St Jeor et al: A new predictive equation for resting energy expenditure in healthy individuals
if (scaleUser.isMale()) {
if (scaleUser.getGender().isMale()) {
bmr = 10.0f * weight + 6.25f * scaleUser.getBodyHeight() - 5.0f * scaleUser.getAge(dateTime) + 5.0f;
} else {
bmr = 10.0f * weight + 6.25f * scaleUser.getBodyHeight() - 5.0f * scaleUser.getAge(dateTime) - 161.0f;

View File

@@ -126,13 +126,6 @@ public class ScaleUser {
this.goalDate = goalDate;
}
public boolean isMale() {
if (gender == Converters.Gender.MALE) {
return true;
}
return false;
}
public int getAge(Date todayDate) {
Calendar calToday = Calendar.getInstance();
calToday.setTime(todayDate);

View File

@@ -170,7 +170,7 @@ public class EvaluationSheet {
float lowLimit = 0.0f;
float highLimit = 0.0f;
if (evalUser.isMale()) {
if (evalUser.getGender().isMale()) {
lowLimit = body_height_squared * 20.0f;
highLimit = body_height_squared * 25.0f;
} else {
@@ -193,7 +193,7 @@ public class EvaluationSheet {
public EvaluationResult evaluateBodyFat(float fat) {
List<sheetEntry> bodyEvaluateSheet;
if (evalUser.isMale()) {
if (evalUser.getGender().isMale()) {
bodyEvaluateSheet = fatEvaluateSheet_Man;
} else {
bodyEvaluateSheet = fatEvaluateSheet_Woman;
@@ -205,7 +205,7 @@ public class EvaluationSheet {
public EvaluationResult evaluateBodyWater(float water) {
List<sheetEntry> bodyEvaluateSheet;
if (evalUser.isMale()) {
if (evalUser.getGender().isMale()) {
bodyEvaluateSheet = waterEvaluateSheet_Man;
} else {
bodyEvaluateSheet = waterEvaluateSheet_Woman;
@@ -217,7 +217,7 @@ public class EvaluationSheet {
public EvaluationResult evaluateBodyMuscle(float muscle) {
List<sheetEntry> bodyEvaluateSheet;
if (evalUser.isMale()) {
if (evalUser.getGender().isMale()) {
bodyEvaluateSheet = muscleEvaluateSheet_Man;
} else {
bodyEvaluateSheet = muscleEvaluateSheet_Woman;
@@ -229,7 +229,7 @@ public class EvaluationSheet {
public EvaluationResult evaluateBMI(float bmi) {
List<sheetEntry> bodyEvaluateSheet;
if (evalUser.isMale()) {
if (evalUser.getGender().isMale()) {
bodyEvaluateSheet = bmiEvaluateSheet_Man;
} else {
bodyEvaluateSheet = bmiEvaluateSheet_Woman;
@@ -241,7 +241,7 @@ public class EvaluationSheet {
public EvaluationResult evaluateWaist(float waist) {
List<sheetEntry> bodyEvaluateSheet;
if (evalUser.isMale()) {
if (evalUser.getGender().isMale()) {
bodyEvaluateSheet = waistEvaluateSheet_Man;
} else {
bodyEvaluateSheet = waistEvaluateSheet_Woman;
@@ -257,7 +257,7 @@ public class EvaluationSheet {
public EvaluationResult evaluateWHR(float whr) {
List<sheetEntry> bodyEvaluateSheet;
if (evalUser.isMale()) {
if (evalUser.getGender().isMale()) {
bodyEvaluateSheet = whrEvaluateSheet_Man;
} else {
bodyEvaluateSheet = whrEvaluateSheet_Woman;

View File

@@ -58,6 +58,10 @@ public class Converters {
public enum Gender {
MALE, FEMALE;
public boolean isMale() {
return this == MALE;
}
public static Gender fromInt(int gender) {
return gender == 0 ? MALE : FEMALE;
}

View File

@@ -21,6 +21,8 @@ import com.health.openscale.core.utils.Converters;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
public class ConvertersTest {
@@ -65,6 +67,9 @@ public class ConvertersTest {
assertEquals("MALE", Converters.Gender.MALE.toString());
assertEquals("FEMALE", Converters.Gender.FEMALE.toString());
assertTrue(Converters.Gender.MALE.isMale());
assertFalse(Converters.Gender.FEMALE.isMale());
}
@Test