1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-26 09:44:31 +02:00

Introduce an enum for weight unit

This commit is contained in:
Erik Johansson
2018-01-16 23:24:44 +01:00
parent 81ff03802a
commit 4b05f27a6e
20 changed files with 181 additions and 121 deletions

View File

@@ -39,6 +39,7 @@ import com.health.openscale.core.database.ScaleUserDAO;
import com.health.openscale.core.database.ScaleUserDatabase;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters;
import com.health.openscale.core.utils.CsvHelper;
import com.health.openscale.gui.fragments.FragmentUpdateListener;
@@ -217,9 +218,9 @@ public class OpenScale {
final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
final Date dateTime = scaleMeasurement.getDateTime();
final Converters.WeightUnit unit = scaleUser.getScaleUnit();
String infoText = String.format(context.getString(R.string.info_new_data_added),
scaleMeasurement.getConvertedWeight(scaleUser.getScaleUnit()),
ScaleUser.UNIT_STRING[scaleUser.getScaleUnit()],
scaleMeasurement.getConvertedWeight(unit), unit.toString(),
dateFormat.format(dateTime) + " " + timeFormat.format(dateTime),
scaleUser.getUserName());
Toast.makeText(context, infoText, Toast.LENGTH_LONG).show();

View File

@@ -612,21 +612,18 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
byte[] command = SET_UNIT_COMMAND;
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
switch ((byte) selectedUser.getScaleUnit()) {
case 0:
// Kg
switch (selectedUser.getScaleUnit()) {
case KG:
command[2] = (byte) 0x01;
break;
case 1:
// Lb
case LB:
command[2] = (byte) 0x02;
break;
case 2:
// St
case ST:
command[3] = (byte) 0x04;
break;
}
Log.d(TAG, "Setting unit " + ScaleUser.UNIT_STRING[selectedUser.getScaleUnit()]);
Log.d(TAG, "Setting unit " + selectedUser.getScaleUnit().toString());
writeBytes(command);
}

View File

@@ -107,19 +107,14 @@ public class BluetoothDigooDGSO38H extends BluetoothCommunication {
byte gender = selectedUser.isMale() ? (byte)0x00: (byte)0x01;
byte height = (byte) (selectedUser.getBodyHeight() & 0xFF);
byte age = (byte)(selectedUser.getAge(new Date()) & 0xff);
byte unit;
byte unit = 0x01; // kg
switch (selectedUser.getScaleUnit()) {
case 0:
unit = 0x1;
break;
case 1:
case LB:
unit = 0x02;
break;
case 2:
case ST:
unit = 0x8;
break;
default:
unit = 0x1;
}
byte configBytes[] = new byte[]{(byte)0x09, (byte)0x10, (byte)0x12, (byte)0x11, (byte)0x0d, (byte)0x01, height, age, gender, unit, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00};
//Write checksum is sum of all bytes % 256

View File

@@ -64,20 +64,15 @@ public class BluetoothExcelvanCF369BLE extends BluetoothCommunication {
byte sex = selectedUser.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;
byte unit = 0x01; // kg
switch (selectedUser.getScaleUnit()) {
case 0:
unit = 0x01; // kg
case LB:
unit = 0x02;
break;
case 1:
unit = 0x02; // lb
case ST:
unit = 0x04;
break;
case 2:
unit = 0x04; // st
break;
default:
unit = 0x01; // kg
}
byte xor_checksum = (byte)((byte)(0x01) ^ sex ^ (byte)(0x01) ^ height ^ age ^ unit);

View File

@@ -26,6 +26,7 @@ import android.util.Log;
import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -95,7 +96,7 @@ public class BluetoothMiScale2 extends BluetoothCommunication {
case 0:
// set scale units
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
byte[] setUnitCmd = new byte[]{(byte)0x06, (byte)0x04, (byte)0x00, (byte) selectedUser.getScaleUnit()};
byte[] setUnitCmd = new byte[]{(byte)0x06, (byte)0x04, (byte)0x00, (byte) Converters.toInt(selectedUser.getScaleUnit())};
writeBytes(WEIGHT_CUSTOM_SERVICE, WEIGHT_CUSTOM_CONFIG, setUnitCmd);
break;
case 1:

View File

@@ -607,21 +607,18 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication {
byte[] command = SET_UNIT_COMMAND;
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
switch ((byte) selectedUser.getScaleUnit()) {
case 0:
// Kg
switch (selectedUser.getScaleUnit()) {
case KG:
command[2] = (byte) 0x01;
break;
case 1:
// Lb
case LB:
command[2] = (byte) 0x02;
break;
case 2:
// St
case ST:
command[3] = (byte) 0x04;
break;
}
Log.d(TAG, "Setting unit " + ScaleUser.UNIT_STRING[selectedUser.getScaleUnit()]);
Log.d(TAG, "Setting unit " + selectedUser.getScaleUnit().toString());
writeBytes(command);
}

View File

@@ -25,6 +25,7 @@ import android.preference.PreferenceManager;
import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters;
import java.util.Date;
import java.util.Random;
@@ -69,7 +70,7 @@ public class BluetoothYunmaiMini extends BluetoothCommunication {
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
byte sex = selectedUser.isMale() ? (byte)0x01 : (byte)0x02;
byte display_unit = selectedUser.getScaleUnit() == 0 ? (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 };
user_add_or_query[17] = xor_checksum(user_add_or_query);

View File

@@ -25,6 +25,7 @@ import android.preference.PreferenceManager;
import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters;
import java.util.Date;
import java.util.Random;
@@ -69,7 +70,7 @@ public class BluetoothYunmaiSE extends BluetoothCommunication {
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
byte sex = selectedUser.isMale() ? (byte)0x01 : (byte)0x02;
byte display_unit = selectedUser.getScaleUnit() == 0 ? (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 };
user_add_or_query[17] = xor_checksum(user_add_or_query);

View File

@@ -25,6 +25,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -111,7 +112,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
values.put(COLUMN_NAME_USER_NAME, scaleUser.getUserName());
values.put(COLUMN_NAME_BIRTHDAY, formatDateTime.format(scaleUser.getBirthday()));
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.getBodyHeight());
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.getScaleUnit());
values.put(COLUMN_NAME_SCALE_UNIT, Converters.toInt(scaleUser.getScaleUnit()));
values.put(COLUMN_NAME_GENDER, scaleUser.getGender());
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.getInitialWeight());
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.getGoalWeight());
@@ -144,7 +145,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
values.put(COLUMN_NAME_USER_NAME, scaleUser.getUserName());
values.put(COLUMN_NAME_BIRTHDAY, formatDateTime.format(scaleUser.getBirthday()));
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.getBodyHeight());
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.getScaleUnit());
values.put(COLUMN_NAME_SCALE_UNIT, Converters.toInt(scaleUser.getScaleUnit()));
values.put(COLUMN_NAME_GENDER, scaleUser.getGender());
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.getInitialWeight());
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.getGoalWeight());
@@ -213,7 +214,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
scaleUser.setUserName(cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_USER_NAME)));
String birthday = cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_BIRTHDAY));
scaleUser.setBodyHeight(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_BODY_HEIGHT)));
scaleUser.setScaleUnit(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_SCALE_UNIT)));
scaleUser.setScaleUnit(Converters.fromInt(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_SCALE_UNIT))));
scaleUser.setGender(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_GENDER)));
double initial_weight = cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_INITIAL_WEIGHT));
double goal_weight = cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_GOAL_WEIGHT));

View File

@@ -21,14 +21,13 @@ import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Index;
import android.arch.persistence.room.PrimaryKey;
import com.health.openscale.core.utils.Converters;
import com.j256.simplecsv.common.CsvColumn;
import java.util.Date;
@Entity(tableName = "scaleMeasurements", indices = {@Index(value = {"datetime"}, unique = true)})
public class ScaleMeasurement implements Cloneable {
private static float KG_LB = 2.20462f;
private static float KG_ST = 0.157473f;
@PrimaryKey(autoGenerate = true)
private int id;
@@ -155,40 +154,16 @@ public class ScaleMeasurement implements Cloneable {
return weight;
}
public float getConvertedWeight(int scale_unit) {
float converted_weight = 0.0f;
switch (ScaleUser.UNIT_STRING[scale_unit]) {
case "kg":
converted_weight = weight;
break;
case "lb":
converted_weight = weight * KG_LB;
break;
case "st":
converted_weight = weight * KG_ST;
break;
}
return converted_weight;
public float getConvertedWeight(Converters.WeightUnit unit) {
return Converters.fromKilogram(weight, unit);
}
public void setWeight(float weight) {
this.weight = weight;
}
public void setConvertedWeight(float weight, int scale_unit) {
switch (ScaleUser.UNIT_STRING[scale_unit]) {
case "kg":
this.weight = weight;
break;
case "lb":
this.weight = weight / KG_LB;
break;
case "st":
this.weight = weight / KG_ST;
break;
}
public void setConvertedWeight(float weight, Converters.WeightUnit unit) {
this.weight = Converters.toKilogram(weight, unit);
}
public float getFat() {
@@ -283,6 +258,10 @@ public class ScaleMeasurement implements Cloneable {
@Override
public String toString()
{
return "ID : " + id + " USER_ID: " + userId + " DATE_TIME: " + dateTime.toString() + " WEIGHT: " + weight + " FAT: " + fat + " WATER: " + water + " MUSCLE: " + muscle + " LBW: " + lbw + " WAIST: " + waist + " HIP: " + hip + " BONE: " + bone + " COMMENT: " + comment;
return String.format(
"ID: %d, USER_ID: %d, DATE_TIME: %s, WEIGHT: %.2f, FAT: %.2f, WATER: %.2f, " +
"MUSCLE: %.2f, LBW: %.2f, WAIST: %.2f, HIP: %.2f, BONE: %.2f, COMMENT: %s",
id, userId, dateTime.toString(), weight, fat, water,
muscle, lbw, waist, hip, bone, comment);
}
}

View File

@@ -19,7 +19,9 @@ package com.health.openscale.core.datatypes;
import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull;
import com.health.openscale.core.utils.Converters;
import com.health.openscale.core.utils.DateTimeHelpers;
import java.util.Calendar;
@@ -27,10 +29,6 @@ import java.util.Date;
@Entity(tableName = "scaleUsers")
public class ScaleUser {
public static final String[] UNIT_STRING = new String[] {"kg", "lb", "st"};
private static float KG_LB = 2.20462f;
private static float KG_ST = 0.157473f;
@PrimaryKey(autoGenerate = true)
private int id;
@@ -41,7 +39,8 @@ public class ScaleUser {
@ColumnInfo(name = "bodyHeight")
private int bodyHeight;
@ColumnInfo(name = "scaleUnit")
private int scaleUnit;
@NonNull
private Converters.WeightUnit scaleUnit;
@ColumnInfo(name = "gender")
private int gender;
@ColumnInfo(name = "initialWeight")
@@ -55,7 +54,7 @@ public class ScaleUser {
userName = new String();
birthday = new Date();
bodyHeight = -1;
scaleUnit = 0;
scaleUnit = Converters.WeightUnit.KG;
gender = 0;
initialWeight = -1;
goalWeight = -1;
@@ -94,11 +93,11 @@ public class ScaleUser {
this.bodyHeight = bodyHeight;
}
public int getScaleUnit() {
public Converters.WeightUnit getScaleUnit() {
return scaleUnit;
}
public void setScaleUnit(int scaleUnit) {
public void setScaleUnit(Converters.WeightUnit scaleUnit) {
this.scaleUnit = scaleUnit;
}
@@ -148,17 +147,7 @@ public class ScaleUser {
}
public void setConvertedInitialWeight(float weight) {
switch (ScaleUser.UNIT_STRING[scaleUnit]) {
case "kg":
this.initialWeight = weight;
break;
case "lb":
this.initialWeight = weight / KG_LB;
break;
case "st":
this.initialWeight = weight / KG_ST;
break;
}
initialWeight = Converters.toKilogram(weight, scaleUnit);
}
public float getInitialWeight() {
@@ -166,26 +155,16 @@ public class ScaleUser {
}
public float getConvertedInitialWeight() {
float converted_weight = 0.0f;
switch (ScaleUser.UNIT_STRING[scaleUnit]) {
case "kg":
converted_weight = initialWeight;
break;
case "lb":
converted_weight = initialWeight * KG_LB;
break;
case "st":
converted_weight = initialWeight * KG_ST;
break;
}
return converted_weight;
return Converters.fromKilogram(initialWeight, scaleUnit);
}
@Override
public String toString()
{
return "ID : " + id + " NAME: " + userName + " BIRTHDAY: " + birthday.toString() + " BODY_HEIGHT: " + bodyHeight + " SCALE_UNIT: " + UNIT_STRING[scaleUnit] + " GENDER " + gender + " INITIAL WEIGHT " + initialWeight + " GOAL WEIGHT " + goalWeight + " GOAL DATE " + goalDate.toString();
return String.format(
"ID: %d, NAME: %s, BIRTHDAY: %s, BODY_HEIGHT: %d, SCALE_UNIT: %s, GENDER: %d, " +
"INITIAL_WEIGHT: %.2f, GOAL_WEIGHT: %.2f, GOAL_DATE: %s",
id, userName, birthday.toString(), bodyHeight, scaleUnit.toString(),
gender, initialWeight, goalWeight, goalDate.toString());
}
}

View File

@@ -21,6 +21,23 @@ import android.arch.persistence.room.TypeConverter;
import java.util.Date;
public class Converters {
public enum WeightUnit {
KG, LB, ST;
public String toString() {
switch (this) {
case LB:
return "lb";
case ST:
return "st";
}
return "kg";
}
}
private static float KG_LB = 2.20462f;
private static float KG_ST = 0.157473f;
@TypeConverter
public static Date fromTimestamp(Long value) {
return value == null ? null : new Date(value);
@@ -30,4 +47,46 @@ public class Converters {
public static Long dateToTimestamp(Date date) {
return date == null ? null : date.getTime();
}
@TypeConverter
public static WeightUnit fromInt(int unit) {
switch (unit) {
case 1:
return WeightUnit.LB;
case 2:
return WeightUnit.ST;
}
return WeightUnit.KG;
}
@TypeConverter
public static int toInt(WeightUnit unit) {
switch (unit) {
case LB:
return 1;
case ST:
return 2;
}
return 0;
}
public static float toKilogram(float value, WeightUnit unit) {
switch (unit) {
case LB:
return value / KG_LB;
case ST:
return value / KG_ST;
}
return value;
}
public static float fromKilogram(float kg, WeightUnit unit) {
switch (unit) {
case LB:
return kg * KG_LB;
case ST:
return kg * KG_ST;
}
return kg;
}
}

View File

@@ -34,6 +34,7 @@ import android.widget.Toast;
import com.health.openscale.R;
import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters;
import java.text.DateFormat;
import java.util.Calendar;
@@ -147,13 +148,13 @@ public class UserSettingsActivity extends Activity {
switch (scaleUser.getScaleUnit())
{
case 0:
case KG:
radioScaleUnit.check(R.id.btnRadioKG);
break;
case 1:
case LB:
radioScaleUnit.check(R.id.btnRadioLB);
break;
case 2:
case ST:
radioScaleUnit.check(R.id.btnRadioST);
break;
}
@@ -311,7 +312,7 @@ public class UserSettingsActivity extends Activity {
scaleUser.setUserName(name);
scaleUser.setBirthday(birthday);
scaleUser.setBodyHeight(body_height);
scaleUser.setScaleUnit(scale_unit);
scaleUser.setScaleUnit(Converters.fromInt(scale_unit));
scaleUser.setGender(gender);
scaleUser.setConvertedInitialWeight(initial_weight);
scaleUser.setGoalWeight(goal_weight);

View File

@@ -37,6 +37,7 @@ 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;
import com.health.openscale.core.utils.Converters;
import com.health.openscale.core.utils.DateTimeHelpers;
import com.health.openscale.gui.activities.DataEntryActivity;
import com.health.openscale.gui.views.BMIMeasurementView;
@@ -398,10 +399,11 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
arcValuesLast.add(new SliceValue(lastScaleMeasurement.getMuscle(), ChartUtils.COLOR_GREEN));
}
final Converters.WeightUnit unit = currentScaleUser.getScaleUnit();
PieChartData pieChartData = new PieChartData(arcValuesLast);
pieChartData.setHasLabels(false);
pieChartData.setHasCenterCircle(true);
pieChartData.setCenterText1(String.format("%.2f %s", lastScaleMeasurement.getConvertedWeight(currentScaleUser.getScaleUnit()), ScaleUser.UNIT_STRING[currentScaleUser.getScaleUnit()]));
pieChartData.setCenterText1(String.format("%.2f %s", lastScaleMeasurement.getConvertedWeight(unit), unit.toString()));
pieChartData.setCenterText2(DateFormat.getDateInstance(DateFormat.MEDIUM).format(lastScaleMeasurement.getDateTime()));

View File

@@ -31,6 +31,7 @@ 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;
import com.health.openscale.core.utils.Converters;
import com.health.openscale.core.utils.DateTimeHelpers;
import com.health.openscale.gui.views.BoneMeasurementView;
import com.health.openscale.gui.views.FatMeasurementView;
@@ -169,10 +170,11 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
ScaleMeasurement goalScaleMeasurement = new ScaleMeasurement();
goalScaleMeasurement.setConvertedWeight(currentScaleUser.getGoalWeight(), currentScaleUser.getScaleUnit());
txtGoalWeight.setText(goalScaleMeasurement.getConvertedWeight(currentScaleUser.getScaleUnit()) + " " + ScaleUser.UNIT_STRING[currentScaleUser.getScaleUnit()]);
final Converters.WeightUnit unit = currentScaleUser.getScaleUnit();
txtGoalWeight.setText(goalScaleMeasurement.getConvertedWeight(unit) + " " + unit.toString());
double weight_diff = goalScaleMeasurement.getConvertedWeight(currentScaleUser.getScaleUnit()) - lastScaleMeasurement.getConvertedWeight(currentScaleUser.getScaleUnit());
txtGoalDiff.setText(String.format("%.1f " + ScaleUser.UNIT_STRING[currentScaleUser.getScaleUnit()], weight_diff));
double weight_diff = goalScaleMeasurement.getConvertedWeight(unit) - lastScaleMeasurement.getConvertedWeight(unit);
txtGoalDiff.setText(String.format("%.1f %s", weight_diff, unit.toString()));
Calendar goalCalendar = Calendar.getInstance();
goalCalendar.setTime(currentScaleUser.getGoalDate());
@@ -182,7 +184,7 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
lastScaleMeasurement.setUserId(currentScaleUser.getId());
ScaleMeasurement goalData = new ScaleMeasurement();
goalData.setConvertedWeight(currentScaleUser.getGoalWeight(), currentScaleUser.getScaleUnit());
goalData.setConvertedWeight(currentScaleUser.getGoalWeight(), unit);
goalData.setUserId(currentScaleUser.getId());
txtLabelGoalWeight.setText(

View File

@@ -65,7 +65,7 @@ public class FatMeasurementView extends FloatMeasurementView {
return "%";
}
return ScaleUser.UNIT_STRING[getScaleUser().getScaleUnit()];
return getScaleUser().getScaleUnit().toString();
}
@Override

View File

@@ -63,7 +63,7 @@ public class MuscleMeasurementView extends FloatMeasurementView {
return "%";
}
return ScaleUser.UNIT_STRING[getScaleUser().getScaleUnit()];
return getScaleUser().getScaleUnit().toString();
}
@Override

View File

@@ -65,7 +65,7 @@ public class WaterMeasurementView extends FloatMeasurementView {
return "%";
}
return ScaleUser.UNIT_STRING[getScaleUser().getScaleUnit()];
return getScaleUser().getScaleUnit().toString();
}
@Override

View File

@@ -48,7 +48,7 @@ public class WeightMeasurementView extends FloatMeasurementView {
@Override
protected String getUnit() {
return ScaleUser.UNIT_STRING[getScaleUser().getScaleUnit()];
return getScaleUser().getScaleUnit().toString();
}
@Override

View File

@@ -0,0 +1,49 @@
/* 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;
import com.health.openscale.core.utils.Converters;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
public class ConvertersTest {
@Test
public void weightUnitTypeConverters() throws Exception {
assertEquals(0, Converters.toInt(Converters.WeightUnit.KG));
assertEquals(1, Converters.toInt(Converters.WeightUnit.LB));
assertEquals(2, Converters.toInt(Converters.WeightUnit.ST));
assertEquals(Converters.WeightUnit.KG, Converters.fromInt(0));
assertEquals(Converters.WeightUnit.LB, Converters.fromInt(1));
assertEquals(Converters.WeightUnit.ST, Converters.fromInt(2));
assertEquals("kg", Converters.WeightUnit.KG.toString());
assertEquals("lb", Converters.WeightUnit.LB.toString());
assertEquals("st", Converters.WeightUnit.ST.toString());
}
@Test
public void weightConverters() throws Exception {
for (Converters.WeightUnit unit : Converters.WeightUnit.values()) {
assertEquals(10.0f,
Converters.toKilogram(Converters.fromKilogram(10.0f, unit), unit));
}
}
}