diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java index 8554a72b1..4db35d3d0 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java @@ -452,8 +452,8 @@ public class ChartFragment extends Fragment implements TrackDataListener { double power = Double.NaN; if (tripStatisticsUpdater != null) { - tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, - ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT); + tripStatisticsUpdater.addLocation( + location, recordingDistanceInterval, false, ActivityType.INVALID, 0.0); TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics(); if (chartByDistance) { double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java index c5e553388..4d01eb1f1 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java @@ -147,7 +147,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track R.string.recording_distance_interval_key, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT); this.weight = PreferencesUtils.getFloat( - context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT); + context, R.string.weight_key, PreferencesUtils.getDefaultWeight(context)); trackIds = new ArrayList(); waypoints = new ArrayList(); } @@ -245,8 +245,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track return; } location = locationIterator.next(); - trackTripStatisticstrackUpdater.addLocation(location, recordingDistanceInterval, false, - ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT); + trackTripStatisticstrackUpdater.addLocation( + location, recordingDistanceInterval, false, ActivityType.INVALID, 0.0); markerTripStatisticsUpdater.addLocation( location, recordingDistanceInterval, true, activityType, weight); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java index 663fea54a..c1f22740d 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java @@ -275,8 +275,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask { sentStartMarker = true; } - tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, - ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT); + tripStatisticsUpdater.addLocation( + location, recordingDistanceInterval, false, ActivityType.INVALID, 0.0); if (readCount % elevationSamplingFrequency == 0) { distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance()); elevations.add(tripStatisticsUpdater.getSmoothedElevation()); diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java index 66f3321c3..b1e64650e 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -233,7 +233,7 @@ public class TrackRecordingService extends Service { } if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.weight_key))) { weight = PreferencesUtils.getFloat( - context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT); + context, R.string.weight_key, PreferencesUtils.getDefaultWeight(context)); } } }; diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java index 1990845eb..7670b3468 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java @@ -109,7 +109,7 @@ public class CalorieUtils { R.string.recording_distance_interval_key, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT); double weight = PreferencesUtils.getFloat( - context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT); + context, R.string.weight_key, PreferencesUtils.getDefaultWeight(context)); LocationIterator locationIterator = null; Cursor cursor = null; diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java index 975b13613..251128b3d 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/PreferencesUtils.java @@ -122,8 +122,6 @@ public class PreferencesUtils { public static final int TRACK_WIDGET_ITEM3_DEFAULT = 1; // total time public static final int TRACK_WIDGET_ITEM4_DEFAULT = 2; // average speed 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(); @@ -289,8 +287,8 @@ public class PreferencesUtils { * @param context the context */ public static boolean isMetricUnits(Context context) { - return PreferencesUtils.STATS_UNITS_DEFAULT.equals( - getString(context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT)); + return STATS_UNITS_DEFAULT.equals( + getString(context, R.string.stats_units_key, STATS_UNITS_DEFAULT)); } /** @@ -300,8 +298,8 @@ public class PreferencesUtils { * @param context the context */ public static boolean isReportSpeed(Context context) { - return PreferencesUtils.STATS_RATE_DEFAULT.equals( - getString(context, R.string.stats_rate_key, PreferencesUtils.STATS_RATE_DEFAULT)); + return STATS_RATE_DEFAULT.equals( + getString(context, R.string.stats_rate_key, STATS_RATE_DEFAULT)); } /** @@ -310,8 +308,8 @@ public class PreferencesUtils { * @param context the context */ public static boolean isChartByDistance(Context context) { - return PreferencesUtils.CHART_X_AXIS_DEFAULT.equals( - getString(context, R.string.chart_x_axis_key, PreferencesUtils.CHART_X_AXIS_DEFAULT)); + return CHART_X_AXIS_DEFAULT.equals( + getString(context, R.string.chart_x_axis_key, CHART_X_AXIS_DEFAULT)); } /** @@ -337,6 +335,18 @@ public class PreferencesUtils { 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. * @@ -346,14 +356,14 @@ public class PreferencesUtils { double value; try { value = Double.parseDouble(displayValue); - if (!PreferencesUtils.isMetricUnits(context)) { + if (!isMetricUnits(context)) { value = value * UnitConversions.LB_TO_KG; } } catch (NumberFormatException e) { 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,11 +372,10 @@ public class PreferencesUtils { * @param context the context */ public static double getWeightDisplayValue(Context context) { - double value = PreferencesUtils.getFloat( - context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT); - if (!PreferencesUtils.isMetricUnits(context)) { + double value = getFloat(context, R.string.weight_key, getDefaultWeight(context)); + if (!isMetricUnits(context)) { value = value * UnitConversions.KG_TO_LB; } return value; - } + } } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java index a380b9161..8d43dfd75 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java @@ -19,7 +19,8 @@ public class TripStatisticsUpdaterTest extends TestCase { private static final long ONE_SECOND = 1000; private static final long TEN_SECONDS = 10 * ONE_SECOND; private static final float MOVING_SPEED = 11.1f; - + private static final double DEFAULT_WEIGHT = 65.0; + private TripStatisticsUpdater tripStatisticsUpdater = null; @Override @@ -215,7 +216,7 @@ public class TripStatisticsUpdaterTest extends TestCase { startTime + (timeOffset + i) * TEN_SECONDS); tripStatisticsUpdater.addLocation(location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.WALKING, - PreferencesUtils.WEIGHT_DEFAULT); + DEFAULT_WEIGHT); tripStatistics = tripStatisticsUpdater.getTripStatistics(); 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); tripStatisticsUpdater.addLocation(location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, false, ActivityType.WALKING, - PreferencesUtils.WEIGHT_DEFAULT); + DEFAULT_WEIGHT); tripStatistics = tripStatisticsUpdater.getTripStatistics(); assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime()); @@ -299,7 +300,7 @@ public class TripStatisticsUpdaterTest extends TestCase { startTime + (timeOffset + i) * TEN_SECONDS); tripStatisticsUpdater.addLocation(location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, true, ActivityType.WALKING, - PreferencesUtils.WEIGHT_DEFAULT); + DEFAULT_WEIGHT); tripStatistics = tripStatisticsUpdater.getTripStatistics(); assertTrue(tripStatistics.getMovingTime() <= tripStatistics.getTotalTime());