forked from upstream-mirrors/OpenTracks
Cleanup calorie settings
This commit is contained in:
@@ -120,11 +120,11 @@ public class CalorieUtils {
|
||||
int recordingDistanceInterval = PreferencesUtils.getInt(context,
|
||||
R.string.recording_distance_interval_key,
|
||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||
int statsWeight = PreferencesUtils.getInt(
|
||||
double weight = PreferencesUtils.getFloat(
|
||||
context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
||||
while (iterator.hasNext()) {
|
||||
tripStatisticsUpdater.addLocation(
|
||||
iterator.next(), recordingDistanceInterval, true, activityType, statsWeight);
|
||||
iterator.next(), recordingDistanceInterval, true, activityType, weight);
|
||||
}
|
||||
return tripStatisticsUpdater.getTripStatistics().getCalorie();
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class CalorieUtils {
|
||||
* @param activityType the activity type
|
||||
*/
|
||||
public static double getCalorie(
|
||||
Location start, Location stop, double grade, int weight, ActivityType activityType) {
|
||||
Location start, Location stop, double grade, double weight, ActivityType activityType) {
|
||||
if (activityType == ActivityType.INVALID) {
|
||||
return 0.0;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public class CalorieUtils {
|
||||
* @param weight the weight in kilogram of the rider plus bike
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static double getCyclingCalorie(Location start, Location stop, double grade, int weight) {
|
||||
static double getCyclingCalorie(Location start, Location stop, double grade, double weight) {
|
||||
// Gets duration in seconds
|
||||
double duration = (double) (stop.getTime() - start.getTime()) * UnitConversions.MS_TO_S;
|
||||
// Get speed in meters per second
|
||||
@@ -191,7 +191,7 @@ public class CalorieUtils {
|
||||
* @param duration the duration in seconds
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static double getCyclingCalorie(double speed, double grade, int weight, double duration) {
|
||||
static double getCyclingCalorie(double speed, double grade, double weight, double duration) {
|
||||
// Get the power in watt (Joule/second)
|
||||
double power = EARTH_GRAVITY * weight * speed * (K1 + grade) + K2 * (speed * speed * speed);
|
||||
|
||||
@@ -208,7 +208,7 @@ public class CalorieUtils {
|
||||
* @param weight the weight of the user in kilogram
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static double getFootCalorie(Location start, Location stop, double grade, int weight) {
|
||||
static double getFootCalorie(Location start, Location stop, double grade, double weight) {
|
||||
// Get speed in meters per second
|
||||
double averageSpeed = (start.getSpeed() + stop.getSpeed()) / 2.0;
|
||||
// Get VO2 in mL/kg/min
|
||||
|
||||
@@ -106,8 +106,7 @@ public class PreferencesUtils {
|
||||
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
|
||||
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
|
||||
public static final String STATS_UNITS_DEFAULT = "METRIC";
|
||||
public static final boolean STATS_SHOW_CALORIE_DEFAULT = false;
|
||||
public static final int STATS_WEIGHT_DEFAULT = 65; // in kilogram
|
||||
public static final float STATS_WEIGHT_DEFAULT = 65.0f; // in kilogram
|
||||
|
||||
// Track color
|
||||
public static final String TRACK_COLOR_MODE_DEFAULT = "SINGLE";
|
||||
@@ -194,6 +193,35 @@ public class PreferencesUtils {
|
||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a float preference value.
|
||||
*
|
||||
* @param context the context
|
||||
* @param keyId the key id
|
||||
* @param defaultValue the default value
|
||||
*/
|
||||
public static float getFloat(Context context, int keyId, float defaultValue) {
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
return sharedPreferences.getFloat(getKey(context, keyId), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a float preference value.
|
||||
*
|
||||
* @param context the context
|
||||
* @param keyId the key id
|
||||
* @param value the value
|
||||
*/
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
public static void setFloat(Context context, int keyId, float value) {
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
Editor editor = sharedPreferences.edit();
|
||||
editor.putFloat(getKey(context, keyId), value);
|
||||
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a long preference value.
|
||||
*
|
||||
|
||||
@@ -148,10 +148,18 @@ public class StringUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatWeight(double value) {
|
||||
return formatDecimal(value, 1);
|
||||
}
|
||||
|
||||
public static String formatDecimal(double value) {
|
||||
String result = String.format(Locale.getDefault(), "%1$,.2f", value);
|
||||
return result.endsWith(".00") ? result.substring(0, result.lastIndexOf('.')) : result;
|
||||
return formatDecimal(value, 2);
|
||||
}
|
||||
|
||||
private static String formatDecimal(double value, int precision) {
|
||||
String result = String.format(Locale.getDefault(), "%1$,." + precision + "f", value);
|
||||
return value % 1 == 0 ? result.substring(0, result.lastIndexOf('.')) : result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user