forked from upstream-mirrors/OpenTracks
Fix crash in issue 680.
This commit is contained in:
+19
-11
@@ -36,6 +36,9 @@ import android.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class DynamicSpeedTrackPathDescriptor
|
public class DynamicSpeedTrackPathDescriptor
|
||||||
implements TrackPathDescriptor, OnSharedPreferenceChangeListener {
|
implements TrackPathDescriptor, OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
private static int DEFAULT_SPEED_MARGIN = 25;
|
||||||
|
|
||||||
private int slowSpeed;
|
private int slowSpeed;
|
||||||
private int normalSpeed;
|
private int normalSpeed;
|
||||||
private int speedMargin;
|
private int speedMargin;
|
||||||
@@ -48,15 +51,23 @@ public class DynamicSpeedTrackPathDescriptor
|
|||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||||
|
|
||||||
if (prefs == null) {
|
if (prefs == null) {
|
||||||
speedMargin = 25;
|
speedMargin = DEFAULT_SPEED_MARGIN;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
speedMargin = Integer.parseInt(prefs.getString(
|
speedMargin = getSpeedMargin(prefs);
|
||||||
context.getString(R.string.track_color_mode_dynamic_speed_variation_key), "25"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getSpeedMargin(SharedPreferences sharedPreferences) {
|
||||||
|
String key = context.getString(R.string.track_color_mode_dynamic_speed_variation_key);
|
||||||
|
String percentage = sharedPreferences.getString(key, DEFAULT_SPEED_MARGIN + "");
|
||||||
|
if (percentage.isEmpty()) {
|
||||||
|
return DEFAULT_SPEED_MARGIN;
|
||||||
|
}
|
||||||
|
return Integer.parseInt(percentage);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the slow speed calculated based on the % below the average speed.
|
* Get the slow speed calculated based on the % below the average speed.
|
||||||
* @return The speed limit considered as slow.
|
* @return The speed limit considered as slow.
|
||||||
@@ -88,15 +99,12 @@ public class DynamicSpeedTrackPathDescriptor
|
|||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||||
|
|
||||||
if (prefs == null) {
|
if (prefs == null) {
|
||||||
speedMargin = 25;
|
speedMargin = DEFAULT_SPEED_MARGIN;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
speedMargin =
|
speedMargin = getSpeedMargin(prefs);
|
||||||
Integer.parseInt(
|
}
|
||||||
prefs.getString(
|
|
||||||
context.getString(R.string.track_color_mode_dynamic_speed_variation_key), "25"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean needsRedraw() {
|
public boolean needsRedraw() {
|
||||||
|
|||||||
Reference in New Issue
Block a user