forked from upstream-mirrors/OpenTracks
Fix bug with slow speed preference and unit conversion
This commit is contained in:
+6
-6
@@ -47,8 +47,8 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor {
|
||||
|
||||
private final Context context;
|
||||
private int speedMargin;
|
||||
private int slowSpeed;
|
||||
private int normalSpeed;
|
||||
private double slowSpeed;
|
||||
private double normalSpeed;
|
||||
private double averageMovingSpeed;
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -62,14 +62,14 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlowSpeed() {
|
||||
slowSpeed = (int) (averageMovingSpeed - (averageMovingSpeed * speedMargin / 100.0));
|
||||
public double getSlowSpeed() {
|
||||
slowSpeed = averageMovingSpeed - (averageMovingSpeed * speedMargin / 100.0);
|
||||
return slowSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNormalSpeed() {
|
||||
normalSpeed = (int) (averageMovingSpeed + (averageMovingSpeed * speedMargin / 100.0));
|
||||
public double getNormalSpeed() {
|
||||
normalSpeed = averageMovingSpeed + (averageMovingSpeed * speedMargin / 100.0);
|
||||
return normalSpeed;
|
||||
}
|
||||
|
||||
|
||||
+11
-4
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.maps;
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -40,18 +41,24 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor {
|
||||
|| key.equals(PreferencesUtils.getKey(context, R.string.track_color_mode_slow_key))) {
|
||||
slowSpeed = PreferencesUtils.getInt(context, R.string.track_color_mode_slow_key,
|
||||
PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT);
|
||||
if (!PreferencesUtils.isMetricUnits(context)) {
|
||||
slowSpeed = slowSpeed * UnitConversions.MI_TO_KM;
|
||||
}
|
||||
}
|
||||
if (key == null || key.equals(
|
||||
PreferencesUtils.getKey(context, R.string.track_color_mode_medium_key))) {
|
||||
normalSpeed = PreferencesUtils.getInt(context, R.string.track_color_mode_medium_key,
|
||||
PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT);
|
||||
if (!PreferencesUtils.isMetricUnits(context)) {
|
||||
normalSpeed = normalSpeed * UnitConversions.MI_TO_KM;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final Context context;
|
||||
private int slowSpeed;
|
||||
private int normalSpeed;
|
||||
private double slowSpeed;
|
||||
private double normalSpeed;
|
||||
|
||||
public FixedSpeedTrackPathDescriptor(Context context) {
|
||||
this.context = context;
|
||||
@@ -62,12 +69,12 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlowSpeed() {
|
||||
public double getSlowSpeed() {
|
||||
return slowSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNormalSpeed() {
|
||||
public double getNormalSpeed() {
|
||||
return normalSpeed;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public class MultiColorTrackPath implements TrackPath {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getColor(int speed) {
|
||||
protected int getColor(double speed) {
|
||||
if (speed <= trackPathDescriptor.getSlowSpeed()) {
|
||||
return slowColor;
|
||||
} else if (speed <= trackPathDescriptor.getNormalSpeed()) {
|
||||
|
||||
@@ -28,12 +28,12 @@ public interface TrackPathDescriptor {
|
||||
/**
|
||||
* Gets the maximum speed which is considered slow.
|
||||
*/
|
||||
public int getSlowSpeed();
|
||||
public double getSlowSpeed();
|
||||
|
||||
/**
|
||||
* Gets the maximum speed which is considered normal.
|
||||
*/
|
||||
public int getNormalSpeed();
|
||||
public double getNormalSpeed();
|
||||
|
||||
/**
|
||||
* Updates state.
|
||||
|
||||
Reference in New Issue
Block a user