mirror of
https://github.com/oliexdev/openScale.git
synced 2025-09-02 21:02:48 +02:00
made ScaleUser class variables private
initial define Room entities, DAO and database interface for ScaleUser and ScaleData
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 24
|
||||
compileSdkVersion 26
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.health.openscale"
|
||||
@@ -23,7 +23,7 @@ android {
|
||||
}
|
||||
}
|
||||
ext {
|
||||
supportLibVersion = '24.1.1' // lib version > 24.1.1 has a floating button bug, which move the button randomly
|
||||
supportLibVersion = '26.1.0'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -32,6 +32,8 @@ dependencies {
|
||||
compile "com.android.support:appcompat-v7:${supportLibVersion}"
|
||||
compile 'com.github.lecho:hellocharts-library:1.5.8@aar'
|
||||
compile 'junit:junit:4.12'
|
||||
compile 'android.arch.persistence.room:runtime:1.0.0'
|
||||
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
|
@@ -16,21 +16,22 @@
|
||||
|
||||
package com.health.openscale.core;
|
||||
|
||||
import android.arch.persistence.room.Room;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
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.EstimatedLBWMetric;
|
||||
import com.health.openscale.core.bodymetric.EstimatedWaterMetric;
|
||||
import com.health.openscale.core.database.AppDatabase;
|
||||
import com.health.openscale.core.database.ScaleDatabase;
|
||||
import com.health.openscale.core.database.ScaleMeasurementDAO;
|
||||
import com.health.openscale.core.database.ScaleUserDAO;
|
||||
import com.health.openscale.core.database.ScaleUserDatabase;
|
||||
import com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
@@ -47,6 +48,7 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@@ -54,6 +56,9 @@ public class OpenScale {
|
||||
|
||||
private static OpenScale instance;
|
||||
|
||||
private AppDatabase appDB;
|
||||
private ScaleMeasurementDAO measurementDAO;
|
||||
private ScaleUserDAO userDAO;
|
||||
private ScaleDatabase scaleDB;
|
||||
private ScaleUserDatabase scaleUserDB;
|
||||
private ArrayList<ScaleData> scaleDataList;
|
||||
@@ -75,6 +80,9 @@ public class OpenScale {
|
||||
alarmHandler = new AlarmHandler();
|
||||
btCom = null;
|
||||
fragmentList = new ArrayList<>();
|
||||
appDB = Room.databaseBuilder(context, AppDatabase.class, "openScaleDatabase").build();
|
||||
measurementDAO = appDB.measurementDAO();
|
||||
userDAO = appDB.userDAO();
|
||||
|
||||
updateScaleData();
|
||||
}
|
||||
@@ -91,14 +99,14 @@ public class OpenScale {
|
||||
{
|
||||
ScaleUser scaleUser = new ScaleUser();
|
||||
|
||||
scaleUser.user_name = name;
|
||||
scaleUser.birthday = birthday;
|
||||
scaleUser.body_height = body_height;
|
||||
scaleUser.scale_unit = scale_unit;
|
||||
scaleUser.gender = gender;
|
||||
scaleUser.setUserName(name);
|
||||
scaleUser.setBirthday(birthday);
|
||||
scaleUser.setBodyHeight(body_height);
|
||||
scaleUser.setScaleUnit(scale_unit);
|
||||
scaleUser.setGender(gender);
|
||||
scaleUser.setConvertedInitialWeight(initial_weight);
|
||||
scaleUser.goal_weight = goal_weight;
|
||||
scaleUser.goal_date = goal_date;
|
||||
scaleUser.setGoalWeight(goal_weight);
|
||||
scaleUser.setGoalDate(goal_date);
|
||||
|
||||
scaleUserDB.insertEntry(scaleUser);
|
||||
}
|
||||
@@ -142,15 +150,15 @@ public class OpenScale {
|
||||
{
|
||||
ScaleUser scaleUser = new ScaleUser();
|
||||
|
||||
scaleUser.id = id;
|
||||
scaleUser.user_name = name;
|
||||
scaleUser.birthday = birthday;
|
||||
scaleUser.body_height = body_height;
|
||||
scaleUser.scale_unit = scale_unit;
|
||||
scaleUser.gender = gender;
|
||||
scaleUser.setId(id);
|
||||
scaleUser.setUserName(name);
|
||||
scaleUser.setBirthday(birthday);
|
||||
scaleUser.setBodyHeight(body_height);
|
||||
scaleUser.setScaleUnit(scale_unit);
|
||||
scaleUser.setGender(gender);
|
||||
scaleUser.setConvertedInitialWeight(initial_weight);
|
||||
scaleUser.goal_weight = goal_weight;
|
||||
scaleUser.goal_date = goal_date;
|
||||
scaleUser.setGoalWeight(goal_weight);
|
||||
scaleUser.setGoalDate(goal_date);
|
||||
|
||||
scaleUserDB.updateScaleUser(scaleUser);
|
||||
}
|
||||
@@ -163,12 +171,33 @@ public class OpenScale {
|
||||
|
||||
public ScaleData[] getTupleScaleData(long id)
|
||||
{
|
||||
return scaleDB.getTupleDataEntry(getSelectedScaleUser().id, id);
|
||||
return scaleDB.getTupleDataEntry(getSelectedScaleUser().getId(), id);
|
||||
}
|
||||
|
||||
public int addScaleData(ScaleData scaleData) {
|
||||
public int addScaleData(final ScaleData scaleData) {
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
AsyncTask.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d("TEST", "ADD START");
|
||||
|
||||
measurementDAO.insert(scaleData);
|
||||
|
||||
Log.d("TEST", "ADD END");
|
||||
|
||||
Log.d("TEST", "READ ALL");
|
||||
|
||||
List<ScaleData> listScaleData = measurementDAO.getAll();
|
||||
|
||||
for(ScaleData nextScaleData : listScaleData) {
|
||||
Log.d("TEST", "DB : " + nextScaleData.getDateTime() + " Weight: " + nextScaleData.getWeight());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return -1;
|
||||
/* SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
if (scaleData.getUserId() == -1) {
|
||||
if (prefs.getBoolean("smartUserAssign", false)) {
|
||||
@@ -192,7 +221,7 @@ public class OpenScale {
|
||||
if (prefs.getBoolean("estimateLBWEnable", false)) {
|
||||
EstimatedLBWMetric lbwMetric = EstimatedLBWMetric.getEstimatedMetric(EstimatedLBWMetric.FORMULA.valueOf(prefs.getString("estimateLBWFormula", "LBW_HUME")));
|
||||
|
||||
scaleData.setLBW(lbwMetric.getLBW(getScaleUser(scaleData.getUserId()), scaleData));
|
||||
scaleData.setLbw(lbwMetric.getLBW(getScaleUser(scaleData.getUserId()), scaleData));
|
||||
}
|
||||
|
||||
if (prefs.getBoolean("estimateFatEnable", false)) {
|
||||
@@ -204,13 +233,13 @@ public class OpenScale {
|
||||
if (scaleDB.insertEntry(scaleData)) {
|
||||
ScaleUser scaleUser = getScaleUser(scaleData.getUserId());
|
||||
|
||||
String infoText = String.format(context.getString(R.string.info_new_data_added), scaleData.getConvertedWeight(scaleUser.scale_unit), scaleUser.UNIT_STRING[scaleUser.scale_unit], dateTimeFormat.format(scaleData.getDateTime()), scaleUser.user_name);
|
||||
String infoText = String.format(context.getString(R.string.info_new_data_added), scaleData.getConvertedWeight(scaleUser.scaleUnit), scaleUser.UNIT_STRING[scaleUser.scaleUnit], dateTimeFormat.format(scaleData.getDateTime()), scaleUser.userName);
|
||||
Toast.makeText(context, infoText, Toast.LENGTH_LONG).show();
|
||||
alarmHandler.entryChanged(context, scaleData);
|
||||
updateScaleData();
|
||||
}
|
||||
|
||||
return scaleData.getUserId();
|
||||
return scaleData.getUserId();*/
|
||||
}
|
||||
|
||||
private int getSmartUserAssignment(float weight, float range) {
|
||||
@@ -218,7 +247,7 @@ public class OpenScale {
|
||||
Map<Float, Integer> inRangeWeights = new TreeMap<>();
|
||||
|
||||
for (int i = 0; i < scaleUser.size(); i++) {
|
||||
ArrayList<ScaleData> scaleUserData = scaleDB.getScaleDataList(scaleUser.get(i).id);
|
||||
ArrayList<ScaleData> scaleUserData = scaleDB.getScaleDataList(scaleUser.get(i).getId());
|
||||
|
||||
float lastWeight = 0;
|
||||
|
||||
@@ -229,7 +258,7 @@ public class OpenScale {
|
||||
}
|
||||
|
||||
if ((lastWeight - range) <= weight && (lastWeight + range) >= weight) {
|
||||
inRangeWeights.put(Math.abs(lastWeight - weight), scaleUser.get(i).id);
|
||||
inRangeWeights.put(Math.abs(lastWeight - weight), scaleUser.get(i).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +275,7 @@ public class OpenScale {
|
||||
}
|
||||
|
||||
// return selected scale user id if not out of range preference is checked and weight is out of range of any user
|
||||
return getSelectedScaleUser().id;
|
||||
return getSelectedScaleUser().getId();
|
||||
}
|
||||
|
||||
public void updateScaleData(ScaleData scaleData) {
|
||||
@@ -288,13 +317,13 @@ public class OpenScale {
|
||||
newScaleData.setFat(Float.parseFloat(csvField[2]));
|
||||
newScaleData.setWater(Float.parseFloat(csvField[3]));
|
||||
newScaleData.setMuscle(Float.parseFloat(csvField[4]));
|
||||
newScaleData.setLBW(Float.parseFloat(csvField[5]));
|
||||
newScaleData.setLbw(Float.parseFloat(csvField[5]));
|
||||
newScaleData.setBone(Float.parseFloat(csvField[6]));
|
||||
newScaleData.setWaist(Float.parseFloat(csvField[7]));
|
||||
newScaleData.setHip(Float.parseFloat(csvField[8]));
|
||||
newScaleData.setComment(csvField[9]);
|
||||
|
||||
newScaleData.setUserId(getSelectedScaleUser().id);
|
||||
newScaleData.setUserId(getSelectedScaleUser().getId());
|
||||
|
||||
scaleDB.insertEntry(newScaleData);
|
||||
|
||||
@@ -329,7 +358,7 @@ public class OpenScale {
|
||||
csvWriter.append(Float.toString(scaleData.getFat()) + ",");
|
||||
csvWriter.append(Float.toString(scaleData.getWater()) + ",");
|
||||
csvWriter.append(Float.toString(scaleData.getMuscle()) + ",");
|
||||
csvWriter.append(Float.toString(scaleData.getLBW()) + ",");
|
||||
csvWriter.append(Float.toString(scaleData.getLbw()) + ",");
|
||||
csvWriter.append(Float.toString(scaleData.getBone()) + ",");
|
||||
csvWriter.append(Float.toString(scaleData.getWaist()) + ",");
|
||||
csvWriter.append(Float.toString(scaleData.getHip()) + ",");
|
||||
|
@@ -182,22 +182,22 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
// We can only use up to 3 characters and have to handle them uppercase
|
||||
int maxIdx = selectedUser.user_name.length() >= 3 ? 3 : selectedUser.user_name.length();
|
||||
byte[] nick = selectedUser.user_name.toUpperCase().substring(0, maxIdx).getBytes();
|
||||
int maxIdx = selectedUser.getUserName().length() >= 3 ? 3 : selectedUser.getUserName().length();
|
||||
byte[] nick = selectedUser.getUserName().toUpperCase().substring(0, maxIdx).getBytes();
|
||||
|
||||
byte activity = 2; // activity level: 1 - 5
|
||||
Log.d(TAG, "Create User:" + selectedUser.user_name);
|
||||
Log.d(TAG, "Create User:" + selectedUser.getUserName());
|
||||
|
||||
writeBytes(new byte[]{
|
||||
(byte) 0xf7, (byte) 0x31, (byte) 0x0, (byte) 0x0, (byte) 0x0,
|
||||
(byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
|
||||
(byte) (seenUsers.size() > 0 ? Collections.max(seenUsers) + 1 : 101),
|
||||
nick[0], nick[1], nick[2],
|
||||
(byte) selectedUser.birthday.getYear(),
|
||||
(byte) selectedUser.birthday.getMonth(),
|
||||
(byte) selectedUser.birthday.getDate(),
|
||||
(byte) selectedUser.body_height,
|
||||
(byte) (((1 - selectedUser.gender) << 7) | activity)
|
||||
(byte) selectedUser.getBirthday().getYear(),
|
||||
(byte) selectedUser.getBirthday().getMonth(),
|
||||
(byte) selectedUser.getBirthday().getDate(),
|
||||
(byte) selectedUser.getBodyHeight(),
|
||||
(byte) (((1 - selectedUser.getGender()) << 7) | activity)
|
||||
});
|
||||
} else {
|
||||
// Get existing user information
|
||||
@@ -307,8 +307,8 @@ public class BluetoothBeurerBF700_800 extends BluetoothCommunication {
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
// Check if we found the currently selected user
|
||||
if (selectedUser.user_name.toLowerCase().startsWith(name.toLowerCase()) &&
|
||||
selectedUser.birthday.getYear() == year) {
|
||||
if (selectedUser.getUserName().toLowerCase().startsWith(name.toLowerCase()) &&
|
||||
selectedUser.getBirthday().getYear() == year) {
|
||||
// Found user
|
||||
currentScaleUserId = userUuid;
|
||||
}
|
||||
|
@@ -105,10 +105,10 @@ public class BluetoothDigooDGSO38H extends BluetoothCommunication {
|
||||
//The weight is stabilized, now we want to measure all available values
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
byte gender = selectedUser.isMale() ? (byte)0x00: (byte)0x01;
|
||||
byte height = (byte) (selectedUser.body_height & 0xFF);
|
||||
byte height = (byte) (selectedUser.getBodyHeight() & 0xFF);
|
||||
byte age = (byte)(selectedUser.getAge(new Date()) & 0xff);
|
||||
byte unit;
|
||||
switch (selectedUser.scale_unit) {
|
||||
switch (selectedUser.getScaleUnit()) {
|
||||
case 0:
|
||||
unit = 0x1;
|
||||
break;
|
||||
|
@@ -62,11 +62,11 @@ public class BluetoothExcelvanCF369BLE extends BluetoothCommunication {
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
byte sex = selectedUser.isMale() ? (byte)0x01 : (byte)0x00; // 01 - male; 00 - female
|
||||
byte height = (byte)(selectedUser.body_height & 0xff); // cm
|
||||
byte height = (byte)(selectedUser.getBodyHeight() & 0xff); // cm
|
||||
byte age = (byte)(selectedUser.getAge(new Date()) & 0xff);
|
||||
byte unit;
|
||||
|
||||
switch (selectedUser.scale_unit) {
|
||||
switch (selectedUser.getScaleUnit()) {
|
||||
case 0:
|
||||
unit = 0x01; // kg
|
||||
break;
|
||||
@@ -130,7 +130,7 @@ public class BluetoothExcelvanCF369BLE extends BluetoothCommunication {
|
||||
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
scaleBtData.setConvertedWeight(weight, selectedUser.scale_unit);
|
||||
scaleBtData.setConvertedWeight(weight, selectedUser.getScaleUnit());
|
||||
scaleBtData.setFat(fat);
|
||||
scaleBtData.setMuscle(muscle);
|
||||
scaleBtData.setWater(water);
|
||||
|
@@ -59,7 +59,7 @@ public class BluetoothExingtechY1 extends BluetoothCommunication {
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
byte gender = selectedUser.isMale() ? (byte)0x00 : (byte)0x01; // 00 - male; 01 - female
|
||||
byte height = (byte)(selectedUser.body_height & 0xff); // cm
|
||||
byte height = (byte)(selectedUser.getBodyHeight() & 0xff); // cm
|
||||
byte age = (byte)(selectedUser.getAge(new Date()) & 0xff);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
@@ -116,7 +116,7 @@ public class BluetoothExingtechY1 extends BluetoothCommunication {
|
||||
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
scaleBtData.setConvertedWeight(weight, selectedUser.scale_unit);
|
||||
scaleBtData.setConvertedWeight(weight, selectedUser.getScaleUnit());
|
||||
scaleBtData.setFat(fat);
|
||||
scaleBtData.setMuscle(muscle);
|
||||
scaleBtData.setWater(water);
|
||||
|
@@ -117,7 +117,7 @@ public class BluetoothMGB extends BluetoothCommunication {
|
||||
break;
|
||||
|
||||
case 3:
|
||||
writeCfg(0xFB, (user.isMale() ? 1 : 2), user.getAge(new Date()), user.body_height);
|
||||
writeCfg(0xFB, (user.isMale() ? 1 : 2), user.getAge(new Date()), user.getBodyHeight());
|
||||
break;
|
||||
|
||||
case 4:
|
||||
|
@@ -95,7 +95,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.scale_unit};
|
||||
byte[] setUnitCmd = new byte[]{(byte)0x06, (byte)0x04, (byte)0x00, (byte) selectedUser.getScaleUnit()};
|
||||
writeBytes(WEIGHT_CUSTOM_SERVICE, WEIGHT_CUSTOM_CONFIG, setUnitCmd);
|
||||
break;
|
||||
case 1:
|
||||
|
@@ -179,22 +179,22 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication {
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
// We can only use up to 3 characters and have to handle them uppercase
|
||||
int maxIdx = selectedUser.user_name.length() >= 3 ? 3 : selectedUser.user_name.length();
|
||||
byte[] nick = selectedUser.user_name.toUpperCase().substring(0, maxIdx).getBytes();
|
||||
int maxIdx = selectedUser.getUserName().length() >= 3 ? 3 : selectedUser.getUserName().length();
|
||||
byte[] nick = selectedUser.getUserName().toUpperCase().substring(0, maxIdx).getBytes();
|
||||
|
||||
byte activity = 2; // activity level: 1 - 5
|
||||
Log.d(TAG, "Create User:" + selectedUser.user_name);
|
||||
Log.d(TAG, "Create User:" + selectedUser.getUserName());
|
||||
|
||||
writeBytes(new byte[]{
|
||||
(byte) 0xe7, (byte) 0x31, (byte) 0x0, (byte) 0x0, (byte) 0x0,
|
||||
(byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
|
||||
(byte) (seenUsers.size() > 0 ? Collections.max(seenUsers) + 1 : 101),
|
||||
nick[0], nick[1], nick[2],
|
||||
(byte) selectedUser.birthday.getYear(),
|
||||
(byte) selectedUser.birthday.getMonth(),
|
||||
(byte) selectedUser.birthday.getDate(),
|
||||
(byte) selectedUser.body_height,
|
||||
(byte) (((1 - selectedUser.gender) << 7) | activity)
|
||||
(byte) selectedUser.getBirthday().getYear(),
|
||||
(byte) selectedUser.getBirthday().getMonth(),
|
||||
(byte) selectedUser.getBirthday().getDate(),
|
||||
(byte) selectedUser.getBodyHeight(),
|
||||
(byte) (((1 - selectedUser.getGender()) << 7) | activity)
|
||||
});
|
||||
} else {
|
||||
// Get existing user information
|
||||
@@ -304,8 +304,8 @@ public class BluetoothSanitasSbf70 extends BluetoothCommunication {
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
// Check if we found the currently selected user
|
||||
if (selectedUser.user_name.toLowerCase().startsWith(name.toLowerCase()) &&
|
||||
selectedUser.birthday.getYear() == year) {
|
||||
if (selectedUser.getUserName().toLowerCase().startsWith(name.toLowerCase()) &&
|
||||
selectedUser.getBirthday().getYear() == year) {
|
||||
// Found user
|
||||
currentScaleUserId = userUuid;
|
||||
}
|
||||
|
@@ -69,9 +69,9 @@ public class BluetoothYunmaiMini extends BluetoothCommunication {
|
||||
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
byte sex = selectedUser.isMale() ? (byte)0x01 : (byte)0x02;
|
||||
byte display_unit = selectedUser.scale_unit == 0 ? (byte) 0x01 : (byte) 0x02;
|
||||
byte display_unit = selectedUser.getScaleUnit() == 0 ? (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.body_height, (byte)sex, (byte) selectedUser.getAge(new Date()), (byte) 0x55, (byte) 0x5a, (byte) 0x00, (byte)0x00, (byte) display_unit, (byte) 0x03, (byte) 0x00 };
|
||||
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);
|
||||
writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, user_add_or_query);
|
||||
break;
|
||||
@@ -132,7 +132,7 @@ public class BluetoothYunmaiMini extends BluetoothCommunication {
|
||||
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
scaleBtData.setConvertedWeight(weight, selectedUser.scale_unit);
|
||||
scaleBtData.setConvertedWeight(weight, selectedUser.getScaleUnit());
|
||||
scaleBtData.setFat(fat);
|
||||
scaleBtData.setDateTime(btDate);
|
||||
|
||||
|
@@ -69,9 +69,9 @@ public class BluetoothYunmaiSE extends BluetoothCommunication {
|
||||
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
byte sex = selectedUser.isMale() ? (byte)0x01 : (byte)0x02;
|
||||
byte display_unit = selectedUser.scale_unit == 0 ? (byte) 0x01 : (byte) 0x02;
|
||||
byte display_unit = selectedUser.getScaleUnit() == 0 ? (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.body_height, (byte)sex, (byte) selectedUser.getAge(new Date()), (byte) 0x55, (byte) 0x5a, (byte) 0x00, (byte)0x00, (byte) display_unit, (byte) 0x03, (byte) 0x00 };
|
||||
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);
|
||||
writeBytes(WEIGHT_CMD_SERVICE, WEIGHT_CMD_CHARACTERISTIC, user_add_or_query);
|
||||
break;
|
||||
@@ -131,7 +131,7 @@ public class BluetoothYunmaiSE extends BluetoothCommunication {
|
||||
|
||||
final ScaleUser selectedUser = OpenScale.getInstance(context).getSelectedScaleUser();
|
||||
|
||||
scaleBtData.setConvertedWeight(weight, selectedUser.scale_unit);
|
||||
scaleBtData.setConvertedWeight(weight, selectedUser.getScaleUnit());
|
||||
scaleBtData.setDateTime(btDate);
|
||||
|
||||
addScaleData(scaleBtData);
|
||||
|
@@ -27,9 +27,9 @@ public class BFDeurenberg extends EstimatedFatMetric {
|
||||
@Override
|
||||
public float getFat(ScaleUser user, ScaleData data) {
|
||||
if (user.getAge(data.getDateTime()) >= 16) {
|
||||
return (1.2f * data.getBMI(user.body_height)) + (0.23f*user.getAge(data.getDateTime())) - (10.8f*(1-user.gender)) - 5.4f;
|
||||
return (1.2f * data.getBMI(user.getBodyHeight())) + (0.23f*user.getAge(data.getDateTime())) - (10.8f*(1-user.getGender())) - 5.4f;
|
||||
}
|
||||
|
||||
return (1.294f * data.getBMI(user.body_height)) + (0.20f*user.getAge(data.getDateTime())) - (11.4f*(1-user.gender)) - 8.0f;
|
||||
return (1.294f * data.getBMI(user.getBodyHeight())) + (0.20f*user.getAge(data.getDateTime())) - (11.4f*(1-user.getGender())) - 8.0f;
|
||||
}
|
||||
}
|
||||
|
@@ -27,9 +27,9 @@ public class BFDeurenbergII extends EstimatedFatMetric {
|
||||
@Override
|
||||
public float getFat(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return (data.getBMI(user.body_height) * 1.2f) + (user.getAge(data.getDateTime()) * 0.23f) - 16.2f;
|
||||
return (data.getBMI(user.getBodyHeight()) * 1.2f) + (user.getAge(data.getDateTime()) * 0.23f) - 16.2f;
|
||||
}
|
||||
|
||||
return (data.getBMI(user.body_height) * 1.2f) + (user.getAge(data.getDateTime()) * 0.23f) - 5.4f;
|
||||
return (data.getBMI(user.getBodyHeight()) * 1.2f) + (user.getAge(data.getDateTime()) * 0.23f) - 5.4f;
|
||||
}
|
||||
}
|
||||
|
@@ -27,9 +27,9 @@ public class BFEddy extends EstimatedFatMetric {
|
||||
@Override
|
||||
public float getFat(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return (1.281f* data.getBMI(user.body_height)) - 10.13f;
|
||||
return (1.281f* data.getBMI(user.getBodyHeight())) - 10.13f;
|
||||
}
|
||||
|
||||
return (1.48f* data.getBMI(user.body_height)) - 7.0f;
|
||||
return (1.48f* data.getBMI(user.getBodyHeight())) - 7.0f;
|
||||
}
|
||||
}
|
||||
|
@@ -28,10 +28,10 @@ public class BFGallagher extends EstimatedFatMetric {
|
||||
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(data.getDateTime()) - 16.4f + 0.05f * user.getAge(data.getDateTime()) + 39.0f * (1.0f / data.getBMI(user.body_height));
|
||||
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()));
|
||||
}
|
||||
|
||||
// non-asian female
|
||||
return 64.5f - 848.0f * (1.0f / data.getBMI(user.body_height)) + 0.079f * user.getAge(data.getDateTime());
|
||||
return 64.5f - 848.0f * (1.0f / data.getBMI(user.getBodyHeight())) + 0.079f * user.getAge(data.getDateTime());
|
||||
}
|
||||
}
|
||||
|
@@ -28,10 +28,10 @@ public class BFGallagherAsian extends EstimatedFatMetric {
|
||||
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(data.getDateTime());
|
||||
return 51.9f - 740.0f * (1.0f / data.getBMI(user.getBodyHeight())) + 0.029f * user.getAge(data.getDateTime());
|
||||
}
|
||||
|
||||
// asian female
|
||||
return 64.8f - 752.0f * (1.0f / data.getBMI(user.body_height)) + 0.016f * user.getAge(data.getDateTime());
|
||||
return 64.8f - 752.0f * (1.0f / data.getBMI(user.getBodyHeight())) + 0.016f * user.getAge(data.getDateTime());
|
||||
}
|
||||
}
|
||||
|
@@ -28,9 +28,9 @@ public class LBWBoer extends EstimatedLBWMetric {
|
||||
@Override
|
||||
public float getLBW(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return (0.4071f * data.getWeight()) + (0.267f * user.body_height) - 19.2f;
|
||||
return (0.4071f * data.getWeight()) + (0.267f * user.getBodyHeight()) - 19.2f;
|
||||
}
|
||||
|
||||
return (0.252f * data.getWeight()) + (0.473f * user.body_height) - 48.3f;
|
||||
return (0.252f * data.getWeight()) + (0.473f * user.getBodyHeight()) - 48.3f;
|
||||
}
|
||||
}
|
||||
|
@@ -28,9 +28,9 @@ public class LBWHume extends EstimatedLBWMetric {
|
||||
@Override
|
||||
public float getLBW(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return (0.32810f * data.getWeight()) + (0.33929f * user.body_height) - 29.5336f;
|
||||
return (0.32810f * data.getWeight()) + (0.33929f * user.getBodyHeight()) - 29.5336f;
|
||||
}
|
||||
|
||||
return (0.29569f * data.getWeight()) + (0.41813f * user.body_height) - 43.2933f;
|
||||
return (0.29569f * data.getWeight()) + (0.41813f * user.getBodyHeight()) - 43.2933f;
|
||||
}
|
||||
}
|
||||
|
@@ -27,9 +27,9 @@ public class TBWBehnke extends EstimatedWaterMetric {
|
||||
@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.204f * user.getBodyHeight() * user.getBodyHeight()) / 100.0f;
|
||||
}
|
||||
|
||||
return 0.72f * (0.18f * user.body_height * user.body_height) / 100.0f;
|
||||
return 0.72f * (0.18f * user.getBodyHeight() * user.getBodyHeight()) / 100.0f;
|
||||
}
|
||||
}
|
||||
|
@@ -27,9 +27,9 @@ public class TBWHumeWeyers extends EstimatedWaterMetric {
|
||||
@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.194786f * user.getBodyHeight()) + (0.296785f * data.getWeight()) - 14.012934f;
|
||||
}
|
||||
|
||||
return (0.34454f * user.body_height) + (0.183809f * data.getWeight()) - 35.270121f;
|
||||
return (0.34454f * user.getBodyHeight()) + (0.183809f * data.getWeight()) - 35.270121f;
|
||||
}
|
||||
}
|
||||
|
@@ -27,9 +27,9 @@ public class TBWLeeSongKim extends EstimatedWaterMetric {
|
||||
@Override
|
||||
public float getWater(ScaleUser user, ScaleData data) {
|
||||
if (user.isMale()) {
|
||||
return -28.3497f + (0.243057f * user.body_height) + (0.366248f * data.getWeight());
|
||||
return -28.3497f + (0.243057f * user.getBodyHeight()) + (0.366248f * data.getWeight());
|
||||
}
|
||||
|
||||
return -26.6224f + (0.262513f * user.body_height) + (0.232948f * data.getWeight());
|
||||
return -26.6224f + (0.262513f * user.getBodyHeight()) + (0.232948f * data.getWeight());
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,33 @@
|
||||
/* Copyright (C) 2018 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.database;
|
||||
|
||||
import android.arch.persistence.room.Database;
|
||||
import android.arch.persistence.room.RoomDatabase;
|
||||
import android.arch.persistence.room.TypeConverters;
|
||||
|
||||
import com.health.openscale.core.datatypes.ScaleData;
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
import com.health.openscale.core.utils.Converters;
|
||||
|
||||
@Database(entities = {ScaleData.class, ScaleUser.class}, version = 1)
|
||||
@TypeConverters({Converters.class})
|
||||
public abstract class AppDatabase extends RoomDatabase {
|
||||
public abstract ScaleMeasurementDAO measurementDAO();
|
||||
public abstract ScaleUserDAO userDAO();
|
||||
}
|
||||
|
@@ -148,7 +148,7 @@ public class ScaleDatabase extends SQLiteOpenHelper {
|
||||
values.put(COLUMN_NAME_FAT, scaleData.getFat());
|
||||
values.put(COLUMN_NAME_WATER, scaleData.getWater());
|
||||
values.put(COLUMN_NAME_MUSCLE, scaleData.getMuscle());
|
||||
values.put(COLUMN_NAME_LBW, scaleData.getLBW());
|
||||
values.put(COLUMN_NAME_LBW, scaleData.getLbw());
|
||||
values.put(COLUMN_NAME_BONE, scaleData.getBone());
|
||||
values.put(COLUMN_NAME_WAIST, scaleData.getWaist());
|
||||
values.put(COLUMN_NAME_HIP, scaleData.getHip());
|
||||
@@ -180,7 +180,7 @@ public class ScaleDatabase extends SQLiteOpenHelper {
|
||||
values.put(COLUMN_NAME_FAT, scaleData.getFat());
|
||||
values.put(COLUMN_NAME_WATER, scaleData.getWater());
|
||||
values.put(COLUMN_NAME_MUSCLE, scaleData.getMuscle());
|
||||
values.put(COLUMN_NAME_LBW, scaleData.getLBW());
|
||||
values.put(COLUMN_NAME_LBW, scaleData.getLbw());
|
||||
values.put(COLUMN_NAME_BONE, scaleData.getBone());
|
||||
values.put(COLUMN_NAME_WAIST, scaleData.getWaist());
|
||||
values.put(COLUMN_NAME_HIP, scaleData.getHip());
|
||||
@@ -404,14 +404,14 @@ public class ScaleDatabase extends SQLiteOpenHelper {
|
||||
ScaleData scaleData = new ScaleData();
|
||||
|
||||
try {
|
||||
scaleData.setId(cur.getLong(cur.getColumnIndexOrThrow(COLUMN_NAME_ID)));
|
||||
scaleData.setId(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_ID)));
|
||||
scaleData.setUserId(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_USER_ID)));
|
||||
String date_time = cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_DATE_TIME));
|
||||
scaleData.setWeight(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_WEIGHT)));
|
||||
scaleData.setFat(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_FAT)));
|
||||
scaleData.setWater(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_WATER)));
|
||||
scaleData.setMuscle(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_MUSCLE)));
|
||||
scaleData.setLBW(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_LBW)));
|
||||
scaleData.setLbw(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_LBW)));
|
||||
scaleData.setBone(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_BONE)));
|
||||
scaleData.setWaist(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_WAIST)));
|
||||
scaleData.setHip(cur.getFloat(cur.getColumnIndexOrThrow(COLUMN_NAME_HIP)));
|
||||
|
@@ -0,0 +1,48 @@
|
||||
/* Copyright (C) 2018 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.database;
|
||||
|
||||
import android.arch.persistence.room.Dao;
|
||||
import android.arch.persistence.room.Delete;
|
||||
import android.arch.persistence.room.Insert;
|
||||
import android.arch.persistence.room.Query;
|
||||
import android.arch.persistence.room.Update;
|
||||
|
||||
import com.health.openscale.core.datatypes.ScaleData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface ScaleMeasurementDAO {
|
||||
@Query("SELECT * FROM scaledata")
|
||||
List<ScaleData> getAll();
|
||||
|
||||
@Query("SELECT * FROM scaledata WHERE id IS :id")
|
||||
ScaleData loadById(int id);
|
||||
|
||||
@Insert
|
||||
void insert(ScaleData measurement);
|
||||
|
||||
@Insert
|
||||
void insertAll(ScaleData... measurements);
|
||||
|
||||
@Update
|
||||
void update(ScaleData measurement);
|
||||
|
||||
@Delete
|
||||
void delete(ScaleData measurement);
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
/* Copyright (C) 2018 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.database;
|
||||
|
||||
import android.arch.persistence.room.Dao;
|
||||
import android.arch.persistence.room.Delete;
|
||||
import android.arch.persistence.room.Insert;
|
||||
import android.arch.persistence.room.Query;
|
||||
|
||||
import com.health.openscale.core.datatypes.ScaleUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Dao
|
||||
public interface ScaleUserDAO {
|
||||
@Query("SELECT * FROM scaleuser")
|
||||
List<ScaleUser> getAll();
|
||||
|
||||
@Query("SELECT * FROM scaleuser WHERE id IS :id")
|
||||
ScaleUser loadById(int id);
|
||||
|
||||
@Insert
|
||||
void insert(ScaleUser user);
|
||||
|
||||
@Insert
|
||||
void insertAll(ScaleUser... users);
|
||||
|
||||
@Delete
|
||||
void delete(ScaleUser user);
|
||||
}
|
@@ -37,14 +37,14 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
|
||||
|
||||
private static final String TABLE_NAME = "scaleuserdata";
|
||||
private static final String COLUMN_NAME_ID = "id";
|
||||
private static final String COLUMN_NAME_USER_NAME = "user_name";
|
||||
private static final String COLUMN_NAME_USER_NAME = "userName";
|
||||
private static final String COLUMN_NAME_BIRTHDAY = "birthday";
|
||||
private static final String COLUMN_NAME_BODY_HEIGHT = "body_height";
|
||||
private static final String COLUMN_NAME_SCALE_UNIT = "scale_unit";
|
||||
private static final String COLUMN_NAME_BODY_HEIGHT = "bodyHeight";
|
||||
private static final String COLUMN_NAME_SCALE_UNIT = "scaleUnit";
|
||||
private static final String COLUMN_NAME_GENDER = "gender";
|
||||
private static final String COLUMN_NAME_INITIAL_WEIGHT = "initial_weight";
|
||||
private static final String COLUMN_NAME_GOAL_WEIGHT = "goal_weight";
|
||||
private static final String COLUMN_NAME_GOAL_DATE = "goal_date";
|
||||
private static final String COLUMN_NAME_GOAL_WEIGHT = "goalWeight";
|
||||
private static final String COLUMN_NAME_GOAL_DATE = "goalDate";
|
||||
|
||||
private static final String SQL_CREATE_ENTRIES =
|
||||
"CREATE TABLE " + TABLE_NAME + " (" +
|
||||
@@ -108,14 +108,14 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_NAME_USER_NAME, scaleUser.user_name);
|
||||
values.put(COLUMN_NAME_BIRTHDAY, formatDateTime.format(scaleUser.birthday));
|
||||
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height);
|
||||
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit);
|
||||
values.put(COLUMN_NAME_GENDER, scaleUser.gender);
|
||||
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_GENDER, scaleUser.getGender());
|
||||
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.getInitialWeight());
|
||||
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight);
|
||||
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date));
|
||||
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.getGoalWeight());
|
||||
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.getGoalDate()));
|
||||
|
||||
try
|
||||
{
|
||||
@@ -141,16 +141,16 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
|
||||
SQLiteDatabase db = getWritableDatabase();
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLUMN_NAME_USER_NAME, scaleUser.user_name);
|
||||
values.put(COLUMN_NAME_BIRTHDAY, formatDateTime.format(scaleUser.birthday));
|
||||
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height);
|
||||
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit);
|
||||
values.put(COLUMN_NAME_GENDER, scaleUser.gender);
|
||||
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_GENDER, scaleUser.getGender());
|
||||
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.getInitialWeight());
|
||||
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight);
|
||||
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date));
|
||||
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.getGoalWeight());
|
||||
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.getGoalDate()));
|
||||
|
||||
db.update(TABLE_NAME, values, COLUMN_NAME_ID + "=" + scaleUser.id, null);
|
||||
db.update(TABLE_NAME, values, COLUMN_NAME_ID + "=" + scaleUser.getId(), null);
|
||||
}
|
||||
|
||||
public ScaleUser getScaleUser(int id)
|
||||
@@ -209,21 +209,21 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
|
||||
ScaleUser scaleUser = new ScaleUser();
|
||||
|
||||
try {
|
||||
scaleUser.id = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_ID));
|
||||
scaleUser.user_name = cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_USER_NAME));
|
||||
scaleUser.setId(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_ID)));
|
||||
scaleUser.setUserName(cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_USER_NAME)));
|
||||
String birthday = cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_BIRTHDAY));
|
||||
scaleUser.body_height = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_BODY_HEIGHT));
|
||||
scaleUser.scale_unit = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_SCALE_UNIT));
|
||||
scaleUser.gender = cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_GENDER));
|
||||
scaleUser.setBodyHeight(cur.getInt(cur.getColumnIndexOrThrow(COLUMN_NAME_BODY_HEIGHT)));
|
||||
scaleUser.setScaleUnit(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));
|
||||
String goal_date = cur.getString(cur.getColumnIndexOrThrow(COLUMN_NAME_GOAL_DATE));
|
||||
|
||||
scaleUser.birthday = formatDateTime.parse(birthday);
|
||||
scaleUser.goal_date = formatDateTime.parse(goal_date);
|
||||
scaleUser.setBirthday(formatDateTime.parse(birthday));
|
||||
scaleUser.setGoalDate(formatDateTime.parse(goal_date));
|
||||
|
||||
scaleUser.setInitialWeight(Math.round(initial_weight * 100.0f) / 100.0f);
|
||||
scaleUser.goal_weight = Math.round(goal_weight * 100.0f) / 100.0f;
|
||||
scaleUser.setGoalWeight(Math.round(goal_weight * 100.0f) / 100.0f);
|
||||
} catch (ParseException ex) {
|
||||
Log.e("ScaleDatabase", "Can't parse the date time string: " + ex.getMessage());
|
||||
}
|
||||
|
@@ -16,30 +16,47 @@
|
||||
|
||||
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 java.util.Date;
|
||||
|
||||
@Entity
|
||||
public class ScaleData {
|
||||
private static float KG_LB = 2.20462f;
|
||||
private static float KG_ST = 0.157473f;
|
||||
|
||||
private long id;
|
||||
private int user_id;
|
||||
private Date date_time;
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private int id;
|
||||
|
||||
@ColumnInfo(name = "userId")
|
||||
private int userId;
|
||||
@ColumnInfo(name = "datetime")
|
||||
private Date dateTime;
|
||||
@ColumnInfo(name = "weight")
|
||||
private float weight;
|
||||
@ColumnInfo(name = "fat")
|
||||
private float fat;
|
||||
@ColumnInfo(name = "water")
|
||||
private float water;
|
||||
@ColumnInfo(name = "muscle")
|
||||
private float muscle;
|
||||
@ColumnInfo(name = "lbw")
|
||||
private float lbw;
|
||||
@ColumnInfo(name = "waist")
|
||||
private float waist;
|
||||
@ColumnInfo(name = "hip")
|
||||
private float hip;
|
||||
@ColumnInfo(name = "bone")
|
||||
private float bone;
|
||||
@ColumnInfo(name = "comment")
|
||||
private String comment;
|
||||
|
||||
public ScaleData()
|
||||
{
|
||||
id = -1;
|
||||
user_id = -1;
|
||||
date_time = new Date();
|
||||
userId = -1;
|
||||
dateTime = new Date();
|
||||
weight = 0.0f;
|
||||
fat = 0.0f;
|
||||
water = 0.0f;
|
||||
@@ -51,28 +68,28 @@ public class ScaleData {
|
||||
comment = new String();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return user_id;
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int user_id) {
|
||||
this.user_id = user_id;
|
||||
this.userId = user_id;
|
||||
}
|
||||
|
||||
public Date getDateTime() {
|
||||
return date_time;
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(Date date_time) {
|
||||
this.date_time = date_time;
|
||||
this.dateTime = date_time;
|
||||
}
|
||||
|
||||
public float getWeight() {
|
||||
@@ -140,11 +157,11 @@ public class ScaleData {
|
||||
this.muscle = muscle;
|
||||
}
|
||||
|
||||
public float getLBW() {
|
||||
public float getLbw() {
|
||||
return lbw;
|
||||
}
|
||||
|
||||
public void setLBW(float lbw) {
|
||||
public void setLbw(float lbw) {
|
||||
this.lbw = lbw;
|
||||
}
|
||||
|
||||
@@ -185,9 +202,9 @@ public class ScaleData {
|
||||
|
||||
// BMR formula by Mifflin, St Jeor et al: A new predictive equation for resting energy expenditure in healthy individuals
|
||||
if (scaleUser.isMale()) {
|
||||
bmr = 10.0f * weight + 6.25f * scaleUser.body_height - 5.0f * scaleUser.getAge(date_time) + 5.0f;
|
||||
bmr = 10.0f * weight + 6.25f * scaleUser.getBodyHeight() - 5.0f * scaleUser.getAge(dateTime) + 5.0f;
|
||||
} else {
|
||||
bmr = 10.0f * weight + 6.25f * scaleUser.body_height - 5.0f * scaleUser.getAge(date_time) - 161.0f;
|
||||
bmr = 10.0f * weight + 6.25f * scaleUser.getBodyHeight() - 5.0f * scaleUser.getAge(dateTime) - 161.0f;
|
||||
}
|
||||
|
||||
return bmr; // kCal / day
|
||||
@@ -208,6 +225,6 @@ public class ScaleData {
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "ID : " + id + " USER_ID: " + user_id + " DATE_TIME: " + date_time.toString() + " WEIGHT: " + weight + " FAT: " + fat + " WATER: " + water + " MUSCLE: " + muscle + " LBW: " + lbw + " WAIST: " + waist + " HIP: " + hip + " BONE: " + bone + " COMMENT: " + comment;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -16,34 +16,112 @@
|
||||
|
||||
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 java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
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;
|
||||
|
||||
public int id;
|
||||
public String user_name;
|
||||
public Date birthday;
|
||||
public int body_height;
|
||||
public int scale_unit;
|
||||
public int gender;
|
||||
private float initial_weight;
|
||||
public float goal_weight;
|
||||
public Date goal_date;
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private int id;
|
||||
|
||||
@ColumnInfo(name = "username")
|
||||
private String userName;
|
||||
@ColumnInfo(name = "birthday")
|
||||
private Date birthday;
|
||||
@ColumnInfo(name = "bodyHeight")
|
||||
private int bodyHeight;
|
||||
@ColumnInfo(name = "scaleUnit")
|
||||
private int scaleUnit;
|
||||
@ColumnInfo(name = "gender")
|
||||
private int gender;
|
||||
@ColumnInfo(name = "initialWeight")
|
||||
private float initialWeight;
|
||||
@ColumnInfo(name = "goalWeight")
|
||||
private float goalWeight;
|
||||
@ColumnInfo(name = "goalDate")
|
||||
private Date goalDate;
|
||||
|
||||
public ScaleUser() {
|
||||
id = -1;
|
||||
user_name = new String();
|
||||
userName = new String();
|
||||
birthday = new Date();
|
||||
body_height = -1;
|
||||
scale_unit = 0;
|
||||
bodyHeight = -1;
|
||||
scaleUnit = 0;
|
||||
gender = 0;
|
||||
initial_weight = -1;
|
||||
goal_weight = -1;
|
||||
goal_date = new Date();
|
||||
initialWeight = -1;
|
||||
goalWeight = -1;
|
||||
goalDate = new Date();
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public Date getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
|
||||
public void setBirthday(Date birthday) {
|
||||
this.birthday = birthday;
|
||||
}
|
||||
|
||||
public int getBodyHeight() {
|
||||
return bodyHeight;
|
||||
}
|
||||
|
||||
public void setBodyHeight(int bodyHeight) {
|
||||
this.bodyHeight = bodyHeight;
|
||||
}
|
||||
|
||||
public int getScaleUnit() {
|
||||
return scaleUnit;
|
||||
}
|
||||
|
||||
public void setScaleUnit(int scaleUnit) {
|
||||
this.scaleUnit = scaleUnit;
|
||||
}
|
||||
|
||||
public int getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(int gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public float getGoalWeight() {
|
||||
return goalWeight;
|
||||
}
|
||||
|
||||
public void setGoalWeight(float goalWeight) {
|
||||
this.goalWeight = goalWeight;
|
||||
}
|
||||
|
||||
public Date getGoalDate() {
|
||||
return goalDate;
|
||||
}
|
||||
|
||||
public void setGoalDate(Date goalDate) {
|
||||
this.goalDate = goalDate;
|
||||
}
|
||||
|
||||
public boolean isMale()
|
||||
@@ -66,40 +144,40 @@ public class ScaleUser {
|
||||
}
|
||||
|
||||
public void setInitialWeight(float weight) {
|
||||
this.initial_weight = weight;
|
||||
this.initialWeight = weight;
|
||||
|
||||
}
|
||||
|
||||
public void setConvertedInitialWeight(float weight) {
|
||||
switch (ScaleUser.UNIT_STRING[scale_unit]) {
|
||||
switch (ScaleUser.UNIT_STRING[scaleUnit]) {
|
||||
case "kg":
|
||||
this.initial_weight = weight;
|
||||
this.initialWeight = weight;
|
||||
break;
|
||||
case "lb":
|
||||
this.initial_weight = weight / KG_LB;
|
||||
this.initialWeight = weight / KG_LB;
|
||||
break;
|
||||
case "st":
|
||||
this.initial_weight = weight / KG_ST;
|
||||
this.initialWeight = weight / KG_ST;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public float getInitialWeight() {
|
||||
return initial_weight;
|
||||
return initialWeight;
|
||||
}
|
||||
|
||||
public float getConvertedInitialWeight() {
|
||||
float converted_weight = 0.0f;
|
||||
|
||||
switch (ScaleUser.UNIT_STRING[scale_unit]) {
|
||||
switch (ScaleUser.UNIT_STRING[scaleUnit]) {
|
||||
case "kg":
|
||||
converted_weight = initial_weight;
|
||||
converted_weight = initialWeight;
|
||||
break;
|
||||
case "lb":
|
||||
converted_weight = initial_weight * KG_LB;
|
||||
converted_weight = initialWeight * KG_LB;
|
||||
break;
|
||||
case "st":
|
||||
converted_weight = initial_weight * KG_ST;
|
||||
converted_weight = initialWeight * KG_ST;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -109,6 +187,6 @@ public class ScaleUser {
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "ID : " + id + " NAME: " + user_name + " BIRTHDAY: " + birthday.toString() + " BODY_HEIGHT: " + body_height + " SCALE_UNIT: " + UNIT_STRING[scale_unit] + " GENDER " + gender + " INITIAL WEIGHT " + initial_weight + " GOAL WEIGHT " + goal_weight + " GOAL DATE " + goal_date.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();
|
||||
}
|
||||
}
|
||||
|
@@ -166,7 +166,7 @@ public class EvaluationSheet {
|
||||
|
||||
|
||||
public EvaluationResult evaluateWeight(float weight) {
|
||||
float body_height_squared = (evalUser.body_height / 100.0f) * (evalUser.body_height / 100.0f);
|
||||
float body_height_squared = (evalUser.getBodyHeight() / 100.0f) * (evalUser.getBodyHeight() / 100.0f);
|
||||
float lowLimit = 0.0f;
|
||||
float highLimit = 0.0f;
|
||||
|
||||
|
@@ -0,0 +1,33 @@
|
||||
/* Copyright (C) 2018 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.utils;
|
||||
|
||||
import android.arch.persistence.room.TypeConverter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Converters {
|
||||
@TypeConverter
|
||||
public static Date fromTimestamp(Long value) {
|
||||
return value == null ? null : new Date(value);
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static Long dateToTimestamp(Date date) {
|
||||
return date == null ? null : date.getTime();
|
||||
}
|
||||
}
|
@@ -276,7 +276,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
|
||||
ScaleData scaleBtData = (ScaleData) msg.obj;
|
||||
|
||||
scaleBtData.setConvertedWeight(scaleBtData.getWeight(), OpenScale.getInstance(getApplicationContext()).getSelectedScaleUser().scale_unit);
|
||||
scaleBtData.setConvertedWeight(scaleBtData.getWeight(), OpenScale.getInstance(getApplicationContext()).getSelectedScaleUser().getScaleUnit());
|
||||
|
||||
OpenScale.getInstance(getApplicationContext()).addScaleData(scaleBtData);
|
||||
break;
|
||||
|
@@ -91,7 +91,7 @@ public class DataEntryActivity extends Activity {
|
||||
private FloatingActionButton switchEditMode;
|
||||
private FloatingActionButton expandButton;
|
||||
|
||||
private long id;
|
||||
private int id;
|
||||
|
||||
private Context context;
|
||||
|
||||
@@ -178,7 +178,7 @@ public class DataEntryActivity extends Activity {
|
||||
}
|
||||
|
||||
if (getIntent().hasExtra("id")) {
|
||||
id = getIntent().getExtras().getLong("id");
|
||||
id = getIntent().getExtras().getInt("id");
|
||||
}
|
||||
|
||||
ScaleData scaleData;
|
||||
@@ -302,13 +302,13 @@ public class DataEntryActivity extends Activity {
|
||||
|
||||
ScaleData scaleData = new ScaleData();
|
||||
|
||||
scaleData.setUserId(user.id);
|
||||
scaleData.setUserId(user.getId());
|
||||
scaleData.setDateTime(cal.getTime());
|
||||
scaleData.setConvertedWeight(weightMeasurement.getValue(), user.scale_unit);
|
||||
scaleData.setConvertedWeight(weightMeasurement.getValue(), user.getScaleUnit());
|
||||
scaleData.setFat(fatMeasurement.getValue());
|
||||
scaleData.setWater(waterMeasurement.getValue());
|
||||
scaleData.setMuscle(muscleMeasurement.getValue());
|
||||
scaleData.setLBW(lbwMeasurement.getValue());
|
||||
scaleData.setLbw(lbwMeasurement.getValue());
|
||||
scaleData.setWaist(waistMeasurement.getValue());
|
||||
scaleData.setHip(hipMeasurement.getValue());
|
||||
scaleData.setBone(boneMeasurementView.getValue());
|
||||
|
@@ -135,17 +135,17 @@ public class UserSettingsActivity extends Activity {
|
||||
|
||||
ScaleUser scaleUser = openScale.getScaleUser(id);
|
||||
|
||||
birthday = scaleUser.birthday;
|
||||
goal_date = scaleUser.goal_date;
|
||||
birthday = scaleUser.getBirthday();
|
||||
goal_date = scaleUser.getGoalDate();
|
||||
|
||||
txtUserName.setText(scaleUser.user_name);
|
||||
txtBodyHeight.setText(Integer.toString(scaleUser.body_height));
|
||||
txtUserName.setText(scaleUser.getUserName());
|
||||
txtBodyHeight.setText(Integer.toString(scaleUser.getBodyHeight()));
|
||||
txtBirthday.setText(dateFormat.format(birthday));
|
||||
txtGoalDate.setText(dateFormat.format(goal_date));
|
||||
txtInitialWeight.setText(Math.round(scaleUser.getConvertedInitialWeight()*100.0f)/100.0f + "");
|
||||
txtGoalWeight.setText(scaleUser.goal_weight+"");
|
||||
txtGoalWeight.setText(scaleUser.getGoalWeight() +"");
|
||||
|
||||
switch (scaleUser.scale_unit)
|
||||
switch (scaleUser.getScaleUnit())
|
||||
{
|
||||
case 0:
|
||||
radioScaleUnit.check(R.id.btnRadioKG);
|
||||
@@ -158,7 +158,7 @@ public class UserSettingsActivity extends Activity {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (scaleUser.gender)
|
||||
switch (scaleUser.getGender())
|
||||
{
|
||||
case 0:
|
||||
radioGender.check(R.id.btnRadioMale);
|
||||
@@ -236,7 +236,7 @@ public class UserSettingsActivity extends Activity {
|
||||
int lastUserId = -1;
|
||||
|
||||
if (!scaleUser.isEmpty()) {
|
||||
lastUserId = scaleUser.get(0).id;
|
||||
lastUserId = scaleUser.get(0).getId();
|
||||
}
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
@@ -308,7 +308,7 @@ public class UserSettingsActivity extends Activity {
|
||||
} else {
|
||||
openScale.addScaleUser(name, birthday, body_height, scale_unit, gender, initial_weight, goal_weight, goal_date);
|
||||
|
||||
id = openScale.getScaleUserList().get(openScale.getScaleUserList().size() - 1).id;
|
||||
id = openScale.getScaleUserList().get(openScale.getScaleUserList().size() - 1).getId();
|
||||
}
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
@@ -261,14 +261,14 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
for (ScaleData scaleEntry: scaleDataList) {
|
||||
calDB.setTime(scaleEntry.getDateTime());
|
||||
|
||||
if (addPointValue(valuesWeight, calDB.get(field), scaleEntry.getConvertedWeight(openScale.getSelectedScaleUser().scale_unit))) {
|
||||
if (addPointValue(valuesWeight, calDB.get(field), scaleEntry.getConvertedWeight(openScale.getSelectedScaleUser().getScaleUnit()))) {
|
||||
pointIndexScaleDataList.add(scaleEntry); // if new point was added, add this point to pointIndexScaleDataList to get the correct point index after selecting an point
|
||||
}
|
||||
|
||||
addPointValue(valuesFat, calDB.get(field), scaleEntry.getFat());
|
||||
addPointValue(valuesWater, calDB.get(field), scaleEntry.getWater());
|
||||
addPointValue(valuesMuscle, calDB.get(field), scaleEntry.getMuscle());
|
||||
addPointValue(valuesLBW, calDB.get(field), scaleEntry.getLBW());
|
||||
addPointValue(valuesLBW, calDB.get(field), scaleEntry.getLbw());
|
||||
addPointValue(valuesWaist, calDB.get(field), scaleEntry.getWaist());
|
||||
addPointValue(valuesHip, calDB.get(field), scaleEntry.getHip());
|
||||
addPointValue(valuesBone, calDB.get(field), scaleEntry.getBone());
|
||||
@@ -397,7 +397,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
if (prefs.getBoolean("goalLine", true)) {
|
||||
Stack<PointValue> valuesGoalLine = new Stack<PointValue>();
|
||||
|
||||
float goalWeight = openScale.getSelectedScaleUser().goal_weight;
|
||||
float goalWeight = openScale.getSelectedScaleUser().getGoalWeight();
|
||||
|
||||
valuesGoalLine.push(new PointValue(0, goalWeight));
|
||||
valuesGoalLine.push(new PointValue(maxDays, goalWeight));
|
||||
@@ -533,7 +533,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
||||
public void onValueSelected(int lineIndex, int pointIndex, PointValue pointValue) {
|
||||
ScaleData scaleData = pointIndexScaleDataList.get(pointIndex);
|
||||
|
||||
long id = scaleData.getId();
|
||||
int id = scaleData.getId();
|
||||
|
||||
Intent intent = new Intent(graphView.getContext(), DataEntryActivity.class);
|
||||
intent.putExtra("id", id);
|
||||
|
@@ -56,7 +56,6 @@ import com.health.openscale.gui.views.WeightMeasurementView;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter;
|
||||
@@ -221,9 +220,9 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
||||
int posUser = 0;
|
||||
|
||||
for (ScaleUser scaleUser : scaleUserList) {
|
||||
spinUserAdapter.add(scaleUser.user_name);
|
||||
spinUserAdapter.add(scaleUser.getUserName());
|
||||
|
||||
if (scaleUser.id == currentScaleUser.id) {
|
||||
if (scaleUser.getId() == currentScaleUser.getId()) {
|
||||
posUser = spinUserAdapter.getCount() - 1;
|
||||
}
|
||||
}
|
||||
@@ -267,15 +266,15 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
||||
|
||||
scaleDataLastDays.add(histData);
|
||||
|
||||
valuesWeight.add(new PointValue(i, histData.getConvertedWeight(currentScaleUser.scale_unit)));
|
||||
valuesWeight.add(new PointValue(i, histData.getConvertedWeight(currentScaleUser.getScaleUnit())));
|
||||
if (histData.getFat() != 0.0f)
|
||||
valuesFat.add(new PointValue(i, histData.getFat()));
|
||||
if (histData.getWater() != 0.0f)
|
||||
valuesWater.add(new PointValue(i, histData.getWater()));
|
||||
if (histData.getMuscle() != 0.0f)
|
||||
valuesMuscle.add(new PointValue(i, histData.getMuscle()));
|
||||
if (histData.getLBW() != 0.0f)
|
||||
valuesLBW.add(new PointValue(i, histData.getLBW()));
|
||||
if (histData.getLbw() != 0.0f)
|
||||
valuesLBW.add(new PointValue(i, histData.getLbw()));
|
||||
if (histData.getWaist() != 0.0f)
|
||||
valuesWaist.add(new PointValue(i, histData.getWaist()));
|
||||
if (histData.getHip() != 0.0f)
|
||||
@@ -408,7 +407,7 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
||||
PieChartData pieChartData = new PieChartData(arcValuesLast);
|
||||
pieChartData.setHasLabels(false);
|
||||
pieChartData.setHasCenterCircle(true);
|
||||
pieChartData.setCenterText1(String.format("%.2f %s", lastScaleData.getConvertedWeight(currentScaleUser.scale_unit), ScaleUser.UNIT_STRING[currentScaleUser.scale_unit]));
|
||||
pieChartData.setCenterText1(String.format("%.2f %s", lastScaleData.getConvertedWeight(currentScaleUser.getScaleUnit()), ScaleUser.UNIT_STRING[currentScaleUser.getScaleUnit()]));
|
||||
pieChartData.setCenterText2(DateFormat.getDateInstance(DateFormat.MEDIUM).format(lastScaleData.getDateTime()));
|
||||
|
||||
|
||||
@@ -486,7 +485,7 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
||||
ScaleUser scaleUser = scaleUserList.get(position);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
prefs.edit().putInt("selectedUserId", scaleUser.id).commit();
|
||||
prefs.edit().putInt("selectedUserId", scaleUser.getId()).commit();
|
||||
OpenScale.getInstance(getContext()).updateScaleData();
|
||||
}
|
||||
}
|
||||
|
@@ -35,7 +35,6 @@ import com.health.openscale.core.utils.DateTimeHelpers;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class StatisticsFragment extends Fragment implements FragmentUpdateListener {
|
||||
|
||||
@@ -108,23 +107,23 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
||||
|
||||
private void updateGoal(ArrayList<ScaleData> scaleDataList) {
|
||||
ScaleData goalScaleData = new ScaleData();
|
||||
goalScaleData.setConvertedWeight(currentScaleUser.goal_weight, currentScaleUser.scale_unit);
|
||||
goalScaleData.setConvertedWeight(currentScaleUser.getGoalWeight(), currentScaleUser.getScaleUnit());
|
||||
|
||||
txtGoalWeight.setText(goalScaleData.getConvertedWeight(currentScaleUser.scale_unit) + " " + ScaleUser.UNIT_STRING[currentScaleUser.scale_unit]);
|
||||
txtGoalWeight.setText(goalScaleData.getConvertedWeight(currentScaleUser.getScaleUnit()) + " " + ScaleUser.UNIT_STRING[currentScaleUser.getScaleUnit()]);
|
||||
|
||||
double weight_diff = goalScaleData.getConvertedWeight(currentScaleUser.scale_unit) - lastScaleData.getConvertedWeight(currentScaleUser.scale_unit);
|
||||
txtGoalDiff.setText(String.format("%.1f " + ScaleUser.UNIT_STRING[currentScaleUser.scale_unit], weight_diff));
|
||||
double weight_diff = goalScaleData.getConvertedWeight(currentScaleUser.getScaleUnit()) - lastScaleData.getConvertedWeight(currentScaleUser.getScaleUnit());
|
||||
txtGoalDiff.setText(String.format("%.1f " + ScaleUser.UNIT_STRING[currentScaleUser.getScaleUnit()], weight_diff));
|
||||
|
||||
Calendar goalCalendar = Calendar.getInstance();
|
||||
goalCalendar.setTime(currentScaleUser.goal_date);
|
||||
goalCalendar.setTime(currentScaleUser.getGoalDate());
|
||||
int days = Math.max(0, DateTimeHelpers.daysBetween(Calendar.getInstance(), goalCalendar));
|
||||
txtGoalDayLeft.setText(getResources().getQuantityString(R.plurals.label_days, days, days));
|
||||
|
||||
lastScaleData.setUserId(currentScaleUser.id);
|
||||
lastScaleData.setUserId(currentScaleUser.getId());
|
||||
|
||||
ScaleData goalData = new ScaleData();
|
||||
goalData.setConvertedWeight(currentScaleUser.goal_weight, currentScaleUser.scale_unit);
|
||||
goalData.setUserId(currentScaleUser.id);
|
||||
goalData.setConvertedWeight(currentScaleUser.getGoalWeight(), currentScaleUser.getScaleUnit());
|
||||
goalData.setUserId(currentScaleUser.getId());
|
||||
|
||||
txtLabelGoalWeight.setText(
|
||||
Html.fromHtml(
|
||||
@@ -132,7 +131,7 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
||||
" <br> <font color='grey'><small>" +
|
||||
getResources().getString(R.string.label_bmi) +
|
||||
": " +
|
||||
String.format("%.1f", goalData.getBMI(currentScaleUser.body_height)) +
|
||||
String.format("%.1f", goalData.getBMI(currentScaleUser.getBodyHeight())) +
|
||||
" </small></font>"
|
||||
)
|
||||
);
|
||||
@@ -142,7 +141,7 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
||||
" <br> <font color='grey'><small>" +
|
||||
getResources().getString(R.string.label_bmi) +
|
||||
": " +
|
||||
String.format("%.1f", lastScaleData.getBMI(currentScaleUser.body_height) - goalData.getBMI(currentScaleUser.body_height)) +
|
||||
String.format("%.1f", lastScaleData.getBMI(currentScaleUser.getBodyHeight()) - goalData.getBMI(currentScaleUser.getBodyHeight())) +
|
||||
" </small></font>"
|
||||
)
|
||||
);
|
||||
@@ -152,10 +151,10 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
||||
" <br> <font color='grey'><small>" +
|
||||
getResources().getString(R.string.label_goal_date_is) +
|
||||
" "
|
||||
+ DateFormat.getDateInstance(DateFormat.LONG).format(currentScaleUser.goal_date) +
|
||||
+ DateFormat.getDateInstance(DateFormat.LONG).format(currentScaleUser.getGoalDate()) +
|
||||
" </small></font>"
|
||||
)
|
||||
); // currentScaleUser.goal_date
|
||||
); // currentScaleUser.goalDate
|
||||
}
|
||||
|
||||
private void updateStatistics(ArrayList<ScaleData> scaleDataList) {
|
||||
@@ -202,32 +201,32 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
||||
if (weekPastDate.before(histDate)) {
|
||||
weekSize++;
|
||||
|
||||
weekAvgWeight += scaleData.getConvertedWeight(currentScaleUser.scale_unit);
|
||||
weekAvgBMI += scaleData.getBMI(currentScaleUser.body_height);
|
||||
weekAvgWeight += scaleData.getConvertedWeight(currentScaleUser.getScaleUnit());
|
||||
weekAvgBMI += scaleData.getBMI(currentScaleUser.getBodyHeight());
|
||||
weekAvgFat += scaleData.getFat();
|
||||
weekAvgWater += scaleData.getWater();
|
||||
weekAvgMuscle += scaleData.getMuscle();
|
||||
weekAvgLBW += scaleData.getLBW();
|
||||
weekAvgLBW += scaleData.getLbw();
|
||||
weekAvgBone += scaleData.getBone();
|
||||
weekAvgWaist += scaleData.getWaist();
|
||||
weekAvgHip += scaleData.getHip();
|
||||
weekAvgWHtR += scaleData.getWHtR(currentScaleUser.body_height);
|
||||
weekAvgWHtR += scaleData.getWHtR(currentScaleUser.getBodyHeight());
|
||||
weekAvgWHR += scaleData.getWHR();
|
||||
}
|
||||
|
||||
if (monthPastDate.before(histDate)) {
|
||||
monthSize++;
|
||||
|
||||
monthAvgWeight += scaleData.getConvertedWeight(currentScaleUser.scale_unit);
|
||||
monthAvgBMI += scaleData.getBMI(currentScaleUser.body_height);
|
||||
monthAvgWeight += scaleData.getConvertedWeight(currentScaleUser.getScaleUnit());
|
||||
monthAvgBMI += scaleData.getBMI(currentScaleUser.getBodyHeight());
|
||||
monthAvgFat += scaleData.getFat();
|
||||
monthAvgWater += scaleData.getWater();
|
||||
monthAvgMuscle += scaleData.getMuscle();
|
||||
monthAvgLBW += scaleData.getLBW();
|
||||
monthAvgLBW += scaleData.getLbw();
|
||||
monthAvgBone += scaleData.getBone();
|
||||
monthAvgWaist += scaleData.getWaist();
|
||||
monthAvgHip += scaleData.getHip();
|
||||
monthAvgWHtR += scaleData.getWHtR(currentScaleUser.body_height);
|
||||
monthAvgWHtR += scaleData.getWHtR(currentScaleUser.getBodyHeight());
|
||||
monthAvgWHR += scaleData.getWHR();
|
||||
} else {
|
||||
break;
|
||||
@@ -263,8 +262,8 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
||||
|
||||
int lines = 1;
|
||||
|
||||
info_week += String.format("Ø-"+getResources().getString(R.string.label_weight)+": %.1f" + ScaleUser.UNIT_STRING[currentScaleUser.scale_unit] + "<br>", weekAvgWeight);
|
||||
info_month += String.format("Ø-"+getResources().getString(R.string.label_weight)+": %.1f" + ScaleUser.UNIT_STRING[currentScaleUser.scale_unit] + "<br>", monthAvgWeight);
|
||||
info_week += String.format("Ø-"+getResources().getString(R.string.label_weight)+": %.1f" + ScaleUser.UNIT_STRING[currentScaleUser.getScaleUnit()] + "<br>", weekAvgWeight);
|
||||
info_month += String.format("Ø-"+getResources().getString(R.string.label_weight)+": %.1f" + ScaleUser.UNIT_STRING[currentScaleUser.getScaleUnit()] + "<br>", monthAvgWeight);
|
||||
lines++;
|
||||
|
||||
info_week += String.format("Ø-"+getResources().getString(R.string.label_bmi)+": %.1f <br>", weekAvgBMI);
|
||||
|
@@ -252,7 +252,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long click_id) {
|
||||
LinearLayout dataRow = (LinearLayout)view;
|
||||
TextView idTextView = (TextView) dataRow.getChildAt(0);
|
||||
long id = Long.parseLong(idTextView.getText().toString());
|
||||
int id = Integer.parseInt(idTextView.getText().toString());
|
||||
|
||||
Intent intent = new Intent(tableView.getContext(), DataEntryActivity.class);
|
||||
intent.putExtra("id", id);
|
||||
@@ -283,7 +283,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||
filenameDialog.setTitle(getResources().getString(R.string.info_set_filename) + " /sdcard ...");
|
||||
|
||||
final EditText txtFilename = new EditText(tableView.getContext());
|
||||
txtFilename.setText("/openScale_data_" + OpenScale.getInstance(getContext()).getSelectedScaleUser().user_name + ".csv");
|
||||
txtFilename.setText("/openScale_data_" + OpenScale.getInstance(getContext()).getSelectedScaleUser().getUserName() + ".csv");
|
||||
|
||||
filenameDialog.setView(txtFilename);
|
||||
|
||||
@@ -325,7 +325,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
||||
filenameDialog.setTitle(getResources().getString(R.string.info_set_filename) + " /sdcard ...");
|
||||
|
||||
final EditText txtFilename = new EditText(tableView.getContext());
|
||||
txtFilename.setText("/openScale_data_" + OpenScale.getInstance(getContext()).getSelectedScaleUser().user_name + ".csv");
|
||||
txtFilename.setText("/openScale_data_" + OpenScale.getInstance(getContext()).getSelectedScaleUser().getUserName() + ".csv");
|
||||
|
||||
filenameDialog.setView(txtFilename);
|
||||
|
||||
|
@@ -57,14 +57,14 @@ public class UsersPreferences extends PreferenceFragment {
|
||||
Preference prefUser = new Preference(getActivity().getBaseContext());
|
||||
prefUser.setOnPreferenceClickListener(new onClickListenerUserSelect());
|
||||
|
||||
if (scaleUser.id == selectedUserId) {
|
||||
prefUser.setTitle("> " + scaleUser.user_name);
|
||||
if (scaleUser.getId() == selectedUserId) {
|
||||
prefUser.setTitle("> " + scaleUser.getUserName());
|
||||
} else
|
||||
{
|
||||
prefUser.setTitle(scaleUser.user_name);
|
||||
prefUser.setTitle(scaleUser.getUserName());
|
||||
}
|
||||
|
||||
prefUser.setKey(Integer.toString(scaleUser.id));
|
||||
prefUser.setKey(Integer.toString(scaleUser.getId()));
|
||||
|
||||
getPreferenceScreen().addPreference(prefUser);
|
||||
}
|
||||
|
@@ -37,12 +37,12 @@ public class BMIMeasurementView extends MeasurementView {
|
||||
|
||||
@Override
|
||||
public void updateValue(ScaleData updateData) {
|
||||
setValueOnView(updateData.getDateTime(), updateData.getBMI(getScaleUser().body_height));
|
||||
setValueOnView(updateData.getDateTime(), updateData.getBMI(getScaleUser().getBodyHeight()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||
setDiffOnView(updateData.getBMI(getScaleUser().body_height), lastData.getBMI(getScaleUser().body_height));
|
||||
setDiffOnView(updateData.getBMI(getScaleUser().getBodyHeight()), lastData.getBMI(getScaleUser().getBodyHeight()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -45,13 +45,13 @@ public class LBWMeasurementView extends MeasurementView {
|
||||
if (estimateLBWEnable && getMeasurementMode() == MeasurementViewMode.ADD) {
|
||||
setValueOnView(updateData.getDateTime(), (getContext().getString(R.string.label_automatic)));
|
||||
} else {
|
||||
setValueOnView(updateData.getDateTime(), updateData.getLBW());
|
||||
setValueOnView(updateData.getDateTime(), updateData.getLbw());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||
setDiffOnView(updateData.getLBW(), lastData.getLBW());
|
||||
setDiffOnView(updateData.getLbw(), lastData.getLbw());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -37,12 +37,12 @@ public class WHtRMeasurementView extends MeasurementView {
|
||||
|
||||
@Override
|
||||
public void updateValue(ScaleData updateData) {
|
||||
setValueOnView(updateData.getDateTime(), updateData.getWHtR(getScaleUser().body_height));
|
||||
setValueOnView(updateData.getDateTime(), updateData.getWHtR(getScaleUser().getBodyHeight()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||
setDiffOnView(updateData.getWHtR(getScaleUser().body_height), lastData.getWHtR(getScaleUser().body_height));
|
||||
setDiffOnView(updateData.getWHtR(getScaleUser().getBodyHeight()), lastData.getWHtR(getScaleUser().getBodyHeight()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -33,17 +33,17 @@ public class WeightMeasurementView extends MeasurementView {
|
||||
|
||||
@Override
|
||||
public void updateValue(ScaleData updateData) {
|
||||
setValueOnView(updateData.getDateTime(), updateData.getConvertedWeight(getScaleUser().scale_unit));
|
||||
setValueOnView(updateData.getDateTime(), updateData.getConvertedWeight(getScaleUser().getScaleUnit()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDiff(ScaleData updateData, ScaleData lastData) {
|
||||
setDiffOnView(updateData.getConvertedWeight(getScaleUser().scale_unit), lastData.getConvertedWeight(getScaleUser().scale_unit));
|
||||
setDiffOnView(updateData.getConvertedWeight(getScaleUser().getScaleUnit()), lastData.getConvertedWeight(getScaleUser().getScaleUnit()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnit() {
|
||||
return ScaleUser.UNIT_STRING[getScaleUser().scale_unit];
|
||||
return ScaleUser.UNIT_STRING[getScaleUser().getScaleUnit()];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user