forked from upstream-mirrors/OpenTracks
When in imperial unit, use 150 lb as the default
This commit is contained in:
@@ -452,8 +452,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
double power = Double.NaN;
|
double power = Double.NaN;
|
||||||
|
|
||||||
if (tripStatisticsUpdater != null) {
|
if (tripStatisticsUpdater != null) {
|
||||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
tripStatisticsUpdater.addLocation(
|
||||||
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
location, recordingDistanceInterval, false, ActivityType.INVALID, 0.0);
|
||||||
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
if (chartByDistance) {
|
if (chartByDistance) {
|
||||||
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
||||||
|
|||||||
+3
-3
@@ -147,7 +147,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
R.string.recording_distance_interval_key,
|
R.string.recording_distance_interval_key,
|
||||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||||
this.weight = PreferencesUtils.getFloat(
|
this.weight = PreferencesUtils.getFloat(
|
||||||
context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT);
|
context, R.string.weight_key, PreferencesUtils.getDefaultWeight(context));
|
||||||
trackIds = new ArrayList<Long>();
|
trackIds = new ArrayList<Long>();
|
||||||
waypoints = new ArrayList<Waypoint>();
|
waypoints = new ArrayList<Waypoint>();
|
||||||
}
|
}
|
||||||
@@ -245,8 +245,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
location = locationIterator.next();
|
location = locationIterator.next();
|
||||||
trackTripStatisticstrackUpdater.addLocation(location, recordingDistanceInterval, false,
|
trackTripStatisticstrackUpdater.addLocation(
|
||||||
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
location, recordingDistanceInterval, false, ActivityType.INVALID, 0.0);
|
||||||
markerTripStatisticsUpdater.addLocation(
|
markerTripStatisticsUpdater.addLocation(
|
||||||
location, recordingDistanceInterval, true, activityType, weight);
|
location, recordingDistanceInterval, true, activityType, weight);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,8 +275,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
sentStartMarker = true;
|
sentStartMarker = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
tripStatisticsUpdater.addLocation(
|
||||||
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
location, recordingDistanceInterval, false, ActivityType.INVALID, 0.0);
|
||||||
if (readCount % elevationSamplingFrequency == 0) {
|
if (readCount % elevationSamplingFrequency == 0) {
|
||||||
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
||||||
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ public class TrackRecordingService extends Service {
|
|||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.weight_key))) {
|
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.weight_key))) {
|
||||||
weight = PreferencesUtils.getFloat(
|
weight = PreferencesUtils.getFloat(
|
||||||
context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT);
|
context, R.string.weight_key, PreferencesUtils.getDefaultWeight(context));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class CalorieUtils {
|
|||||||
R.string.recording_distance_interval_key,
|
R.string.recording_distance_interval_key,
|
||||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||||
double weight = PreferencesUtils.getFloat(
|
double weight = PreferencesUtils.getFloat(
|
||||||
context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT);
|
context, R.string.weight_key, PreferencesUtils.getDefaultWeight(context));
|
||||||
LocationIterator locationIterator = null;
|
LocationIterator locationIterator = null;
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
|
|
||||||
|
|||||||
@@ -123,8 +123,6 @@ public class PreferencesUtils {
|
|||||||
public static final int TRACK_WIDGET_ITEM4_DEFAULT = 2; // average speed
|
public static final int TRACK_WIDGET_ITEM4_DEFAULT = 2; // average speed
|
||||||
public static final int VOICE_FREQUENCY_DEFAULT = 0;
|
public static final int VOICE_FREQUENCY_DEFAULT = 0;
|
||||||
|
|
||||||
public static final float WEIGHT_DEFAULT = 65.0f; // in kilogram
|
|
||||||
|
|
||||||
private static final String TAG = PreferencesUtils.class.getSimpleName();
|
private static final String TAG = PreferencesUtils.class.getSimpleName();
|
||||||
|
|
||||||
private PreferencesUtils() {}
|
private PreferencesUtils() {}
|
||||||
@@ -289,8 +287,8 @@ public class PreferencesUtils {
|
|||||||
* @param context the context
|
* @param context the context
|
||||||
*/
|
*/
|
||||||
public static boolean isMetricUnits(Context context) {
|
public static boolean isMetricUnits(Context context) {
|
||||||
return PreferencesUtils.STATS_UNITS_DEFAULT.equals(
|
return STATS_UNITS_DEFAULT.equals(
|
||||||
getString(context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT));
|
getString(context, R.string.stats_units_key, STATS_UNITS_DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -300,8 +298,8 @@ public class PreferencesUtils {
|
|||||||
* @param context the context
|
* @param context the context
|
||||||
*/
|
*/
|
||||||
public static boolean isReportSpeed(Context context) {
|
public static boolean isReportSpeed(Context context) {
|
||||||
return PreferencesUtils.STATS_RATE_DEFAULT.equals(
|
return STATS_RATE_DEFAULT.equals(
|
||||||
getString(context, R.string.stats_rate_key, PreferencesUtils.STATS_RATE_DEFAULT));
|
getString(context, R.string.stats_rate_key, STATS_RATE_DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -310,8 +308,8 @@ public class PreferencesUtils {
|
|||||||
* @param context the context
|
* @param context the context
|
||||||
*/
|
*/
|
||||||
public static boolean isChartByDistance(Context context) {
|
public static boolean isChartByDistance(Context context) {
|
||||||
return PreferencesUtils.CHART_X_AXIS_DEFAULT.equals(
|
return CHART_X_AXIS_DEFAULT.equals(
|
||||||
getString(context, R.string.chart_x_axis_key, PreferencesUtils.CHART_X_AXIS_DEFAULT));
|
getString(context, R.string.chart_x_axis_key, CHART_X_AXIS_DEFAULT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -337,6 +335,18 @@ public class PreferencesUtils {
|
|||||||
setString(context, keyId, list + ";" + value);
|
setString(context, keyId, list + ";" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default weight.
|
||||||
|
*
|
||||||
|
* @param context the context
|
||||||
|
*/
|
||||||
|
public static float getDefaultWeight(Context context) {
|
||||||
|
if (isMetricUnits(context)) {
|
||||||
|
return 65.0f; // in kg
|
||||||
|
} else {
|
||||||
|
return 68.0389f; // 150 lb in kg
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Stores the weight value, always in metric units.
|
* Stores the weight value, always in metric units.
|
||||||
*
|
*
|
||||||
@@ -346,14 +356,14 @@ public class PreferencesUtils {
|
|||||||
double value;
|
double value;
|
||||||
try {
|
try {
|
||||||
value = Double.parseDouble(displayValue);
|
value = Double.parseDouble(displayValue);
|
||||||
if (!PreferencesUtils.isMetricUnits(context)) {
|
if (!isMetricUnits(context)) {
|
||||||
value = value * UnitConversions.LB_TO_KG;
|
value = value * UnitConversions.LB_TO_KG;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.e(TAG, "invalid value " + displayValue);
|
Log.e(TAG, "invalid value " + displayValue);
|
||||||
value = PreferencesUtils.WEIGHT_DEFAULT;
|
value = getDefaultWeight(context);
|
||||||
}
|
}
|
||||||
PreferencesUtils.setFloat(context, R.string.weight_key, (float) value);
|
setFloat(context, R.string.weight_key, (float) value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -362,9 +372,8 @@ public class PreferencesUtils {
|
|||||||
* @param context the context
|
* @param context the context
|
||||||
*/
|
*/
|
||||||
public static double getWeightDisplayValue(Context context) {
|
public static double getWeightDisplayValue(Context context) {
|
||||||
double value = PreferencesUtils.getFloat(
|
double value = getFloat(context, R.string.weight_key, getDefaultWeight(context));
|
||||||
context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT);
|
if (!isMetricUnits(context)) {
|
||||||
if (!PreferencesUtils.isMetricUnits(context)) {
|
|
||||||
value = value * UnitConversions.KG_TO_LB;
|
value = value * UnitConversions.KG_TO_LB;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
+4
-3
@@ -19,6 +19,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
private static final long ONE_SECOND = 1000;
|
private static final long ONE_SECOND = 1000;
|
||||||
private static final long TEN_SECONDS = 10 * ONE_SECOND;
|
private static final long TEN_SECONDS = 10 * ONE_SECOND;
|
||||||
private static final float MOVING_SPEED = 11.1f;
|
private static final float MOVING_SPEED = 11.1f;
|
||||||
|
private static final double DEFAULT_WEIGHT = 65.0;
|
||||||
|
|
||||||
private TripStatisticsUpdater tripStatisticsUpdater = null;
|
private TripStatisticsUpdater tripStatisticsUpdater = null;
|
||||||
|
|
||||||
@@ -215,7 +216,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
startTime + (timeOffset + i) * TEN_SECONDS);
|
startTime + (timeOffset + i) * TEN_SECONDS);
|
||||||
tripStatisticsUpdater.addLocation(location,
|
tripStatisticsUpdater.addLocation(location,
|
||||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.WALKING,
|
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.WALKING,
|
||||||
PreferencesUtils.WEIGHT_DEFAULT);
|
DEFAULT_WEIGHT);
|
||||||
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
|
|
||||||
assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime());
|
assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime());
|
||||||
@@ -263,7 +264,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
locationOffset, locationOffset * .001, 0, startTime + (i + timeOffset) * TEN_SECONDS);
|
locationOffset, locationOffset * .001, 0, startTime + (i + timeOffset) * TEN_SECONDS);
|
||||||
tripStatisticsUpdater.addLocation(location,
|
tripStatisticsUpdater.addLocation(location,
|
||||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, false, ActivityType.WALKING,
|
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, false, ActivityType.WALKING,
|
||||||
PreferencesUtils.WEIGHT_DEFAULT);
|
DEFAULT_WEIGHT);
|
||||||
|
|
||||||
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime());
|
assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime());
|
||||||
@@ -299,7 +300,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
|||||||
startTime + (timeOffset + i) * TEN_SECONDS);
|
startTime + (timeOffset + i) * TEN_SECONDS);
|
||||||
tripStatisticsUpdater.addLocation(location,
|
tripStatisticsUpdater.addLocation(location,
|
||||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.WALKING,
|
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.WALKING,
|
||||||
PreferencesUtils.WEIGHT_DEFAULT);
|
DEFAULT_WEIGHT);
|
||||||
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
|
|
||||||
assertTrue(tripStatistics.getMovingTime() <= tripStatistics.getTotalTime());
|
assertTrue(tripStatistics.getMovingTime() <= tripStatistics.getTotalTime());
|
||||||
|
|||||||
Reference in New Issue
Block a user