mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-19 23:12:12 +02:00
added support for activity level
This commit is contained in:
@@ -210,7 +210,7 @@ public class BluetoothBeurerSanitas extends BluetoothCommunication {
|
||||
int maxIdx = Math.min(3, selectedUser.getUserName().length());
|
||||
byte[] nick = selectedUser.getUserName().toUpperCase().substring(0, maxIdx).getBytes();
|
||||
|
||||
byte activity = 2; // activity level: 1 - 5
|
||||
byte activity = (byte)(selectedUser.getActivityLevel().toInt() + 1); // activity level: 1 - 5
|
||||
Timber.d("Create User: %s", selectedUser.getUserName());
|
||||
|
||||
writeBytes(new byte[]{
|
||||
|
@@ -20,6 +20,7 @@ import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.content.Context;
|
||||
|
||||
import com.health.openscale.R;
|
||||
import com.health.openscale.core.OpenScale;
|
||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
@@ -58,8 +59,24 @@ public class BluetoothExcelvanCF369BLE extends BluetoothCommunication {
|
||||
|
||||
byte userId = (byte) 0x01;
|
||||
byte sex = selectedUser.getGender().isMale() ? (byte) 0x01 : (byte) 0x00;
|
||||
|
||||
// 0x00 = ordinary, 0x01 = amateur, 0x02 = professional
|
||||
byte exerciseLevel = (byte) 0x01;
|
||||
|
||||
switch (selectedUser.getActivityLevel()) {
|
||||
case SEDENTARY:
|
||||
case MILD:
|
||||
exerciseLevel = (byte) 0x00;
|
||||
break;
|
||||
case MODERATE:
|
||||
exerciseLevel = (byte) 0x01;
|
||||
break;
|
||||
case HEAVY:
|
||||
case EXTREME:
|
||||
exerciseLevel = (byte) 0x02;
|
||||
break;
|
||||
}
|
||||
|
||||
byte height = (byte) selectedUser.getBodyHeight();
|
||||
byte age = (byte) selectedUser.getAge();
|
||||
|
||||
|
@@ -22,6 +22,7 @@ import android.arch.persistence.room.ForeignKey;
|
||||
import android.arch.persistence.room.Index;
|
||||
import android.arch.persistence.room.PrimaryKey;
|
||||
|
||||
import com.health.openscale.R;
|
||||
import com.health.openscale.core.utils.Converters;
|
||||
import com.j256.simplecsv.common.CsvColumn;
|
||||
|
||||
@@ -361,6 +362,25 @@ public class ScaleMeasurement implements Cloneable {
|
||||
|
||||
public float getBMR(ScaleUser scaleUser) {
|
||||
float bmr;
|
||||
float factor = 1.0f;
|
||||
|
||||
switch (scaleUser.getActivityLevel()) {
|
||||
case SEDENTARY:
|
||||
factor = 1.2f;
|
||||
break;
|
||||
case MILD:
|
||||
factor = 1.3f;
|
||||
break;
|
||||
case MODERATE:
|
||||
factor = 1.5f;
|
||||
break;
|
||||
case HEAVY:
|
||||
factor = 1.7f;
|
||||
break;
|
||||
case EXTREME:
|
||||
factor = 1.9f;
|
||||
break;
|
||||
}
|
||||
|
||||
// BMR formula by Mifflin, St Jeor et al: A new predictive equation for resting energy expenditure in healthy individuals
|
||||
if (scaleUser.getGender().isMale()) {
|
||||
@@ -369,7 +389,7 @@ public class ScaleMeasurement implements Cloneable {
|
||||
bmr = 10.0f * weight + 6.25f * scaleUser.getBodyHeight() - 5.0f * scaleUser.getAge(dateTime) - 161.0f;
|
||||
}
|
||||
|
||||
return bmr; // kCal / day
|
||||
return bmr * factor; // kCal / day
|
||||
}
|
||||
|
||||
public float getWHtR(float body_height) {
|
||||
|
@@ -56,8 +56,9 @@ public class ScaleUser {
|
||||
@NonNull
|
||||
@ColumnInfo(name = "measureUnit")
|
||||
private Converters.MeasureUnit measureUnit;
|
||||
@NonNull
|
||||
@ColumnInfo(name = "activityLevel")
|
||||
private int activityLevel;
|
||||
private Converters.ActivityLevel activityLevel;
|
||||
|
||||
public ScaleUser() {
|
||||
userName = "";
|
||||
@@ -69,7 +70,7 @@ public class ScaleUser {
|
||||
goalWeight = -1;
|
||||
goalDate = new Date();
|
||||
measureUnit = Converters.MeasureUnit.CM;
|
||||
activityLevel = 0;
|
||||
activityLevel = Converters.ActivityLevel.SEDENTARY;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@@ -168,11 +169,11 @@ public class ScaleUser {
|
||||
return measureUnit;
|
||||
}
|
||||
|
||||
public void setActivityLevel(int level) {
|
||||
public void setActivityLevel(Converters.ActivityLevel level) {
|
||||
activityLevel = level;
|
||||
}
|
||||
|
||||
public int getActivityLevel() {
|
||||
public Converters.ActivityLevel getActivityLevel() {
|
||||
return activityLevel;
|
||||
}
|
||||
|
||||
|
@@ -107,6 +107,44 @@ public class Converters {
|
||||
}
|
||||
}
|
||||
|
||||
public enum ActivityLevel {
|
||||
SEDENTARY, MILD, MODERATE, HEAVY, EXTREME;
|
||||
|
||||
public static ActivityLevel fromInt(int unit) {
|
||||
switch (unit) {
|
||||
case 0:
|
||||
return SEDENTARY;
|
||||
case 1:
|
||||
return MILD;
|
||||
case 2:
|
||||
return MODERATE;
|
||||
case 3:
|
||||
return HEAVY;
|
||||
case 4:
|
||||
return EXTREME;
|
||||
}
|
||||
|
||||
return SEDENTARY;
|
||||
}
|
||||
|
||||
public int toInt() {
|
||||
switch (this) {
|
||||
case SEDENTARY:
|
||||
return 0;
|
||||
case MILD:
|
||||
return 1;
|
||||
case MODERATE:
|
||||
return 2;
|
||||
case HEAVY:
|
||||
return 3;
|
||||
case EXTREME:
|
||||
return 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static final float KG_LB = 2.20462f;
|
||||
private static final float KG_ST = 0.157473f;
|
||||
private static final float CM_IN = 0.393701f;
|
||||
@@ -151,6 +189,16 @@ public class Converters {
|
||||
return gender.toInt();
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static ActivityLevel fromActivityLevelInt(int level) {
|
||||
return ActivityLevel.fromInt(level);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static int toActivityLevelInt(ActivityLevel level) {
|
||||
return level.toInt();
|
||||
}
|
||||
|
||||
public static float toCentimeter(float value, MeasureUnit unit) {
|
||||
switch (unit) {
|
||||
case INCH:
|
||||
|
@@ -63,6 +63,7 @@ public class UserSettingsActivity extends BaseAppCompatActivity {
|
||||
private RadioGroup radioScaleUnit;
|
||||
private RadioGroup radioGender;
|
||||
private RadioGroup radioMeasurementUnit;
|
||||
private RadioGroup radioActivityLevel;
|
||||
|
||||
private final DateFormat dateFormat = DateFormat.getDateInstance();
|
||||
|
||||
@@ -86,6 +87,7 @@ public class UserSettingsActivity extends BaseAppCompatActivity {
|
||||
radioScaleUnit = findViewById(R.id.groupScaleUnit);
|
||||
radioGender = findViewById(R.id.groupGender);
|
||||
radioMeasurementUnit = findViewById(R.id.groupMeasureUnit);
|
||||
radioActivityLevel = findViewById(R.id.groupActivityLevel);
|
||||
txtInitialWeight = findViewById(R.id.txtInitialWeight);
|
||||
txtGoalWeight = findViewById(R.id.txtGoalWeight);
|
||||
|
||||
@@ -244,6 +246,24 @@ public class UserSettingsActivity extends BaseAppCompatActivity {
|
||||
radioGender.check(R.id.btnRadioWoman);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (scaleUser.getActivityLevel()) {
|
||||
case SEDENTARY:
|
||||
radioActivityLevel.check(R.id.btnRadioSedentary);
|
||||
break;
|
||||
case MILD:
|
||||
radioActivityLevel.check(R.id.btnRadioMild);
|
||||
break;
|
||||
case MODERATE:
|
||||
radioActivityLevel.check(R.id.btnRadioModerate);
|
||||
break;
|
||||
case HEAVY:
|
||||
radioActivityLevel.check(R.id.btnRadioHeavy);
|
||||
break;
|
||||
case EXTREME:
|
||||
radioActivityLevel.check(R.id.btnRadioExtreme);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validateInput()
|
||||
@@ -389,6 +409,26 @@ public class UserSettingsActivity extends BaseAppCompatActivity {
|
||||
break;
|
||||
}
|
||||
|
||||
Converters.ActivityLevel activity_level = Converters.ActivityLevel.SEDENTARY;
|
||||
|
||||
switch (radioActivityLevel.getCheckedRadioButtonId()) {
|
||||
case R.id.btnRadioSedentary:
|
||||
activity_level = Converters.ActivityLevel.SEDENTARY;
|
||||
break;
|
||||
case R.id.btnRadioMild:
|
||||
activity_level = Converters.ActivityLevel.MILD;
|
||||
break;
|
||||
case R.id.btnRadioModerate:
|
||||
activity_level = Converters.ActivityLevel.MODERATE;
|
||||
break;
|
||||
case R.id.btnRadioHeavy:
|
||||
activity_level = Converters.ActivityLevel.HEAVY;
|
||||
break;
|
||||
case R.id.btnRadioExtreme:
|
||||
activity_level = Converters.ActivityLevel.EXTREME;
|
||||
break;
|
||||
}
|
||||
|
||||
final ScaleUser scaleUser = new ScaleUser();
|
||||
|
||||
scaleUser.setUserName(name);
|
||||
@@ -396,6 +436,7 @@ public class UserSettingsActivity extends BaseAppCompatActivity {
|
||||
scaleUser.setBodyHeight(Converters.toCentimeter(body_height, measure_unit));
|
||||
scaleUser.setScaleUnit(scale_unit);
|
||||
scaleUser.setMeasureUnit(measure_unit);
|
||||
scaleUser.setActivityLevel(activity_level);
|
||||
scaleUser.setGender(gender);
|
||||
scaleUser.setInitialWeight(Converters.toKilogram(initial_weight, scale_unit));
|
||||
scaleUser.setGoalWeight(Converters.toKilogram(goal_weight, scale_unit));
|
||||
|
@@ -168,6 +168,59 @@
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/rowActivityLevel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lblActivityLevel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/label_activity_level" />
|
||||
|
||||
<RadioGroup
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_column="1"
|
||||
android:orientation="horizontal"
|
||||
android:id="@+id/groupActivityLevel">
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="0"
|
||||
android:id="@+id/btnRadioSedentary"
|
||||
android:checked="true" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="1"
|
||||
android:id="@+id/btnRadioMild" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="2"
|
||||
android:id="@+id/btnRadioModerate" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="3"
|
||||
android:id="@+id/btnRadioHeavy" />
|
||||
|
||||
<RadioButton
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="4"
|
||||
android:id="@+id/btnRadioExtreme" />
|
||||
</RadioGroup>
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/rowBodyHeight"
|
||||
android:layout_width="wrap_content"
|
||||
|
@@ -236,4 +236,5 @@
|
||||
<string name="label_caliper2_female">Abdominal skinfold</string>
|
||||
<string name="label_caliper3_female">Hip skinfold</string>
|
||||
<string name="label_measure_unit">Measurement unit</string>
|
||||
<string name="label_activity_level">Activity level</string>
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user