Fix comment on 9399fc25c7ce.

Also define the default values in "do_not_translate.xml" so that can be
consistent between the preferences.xml and the java files.
This commit is contained in:
Jimmy Shih
2011-12-22 11:20:16 -08:00
parent 22dafff7b7
commit 6028137c46
4 changed files with 57 additions and 47 deletions
+3
View File
@@ -22,6 +22,9 @@ limitations under the License.
<string name="about_leif">Leif Wilden</string> <string name="about_leif">Leif Wilden</string>
<string name="about_rodrigo">Rodrigo Damazio</string> <string name="about_rodrigo">Rodrigo Damazio</string>
<string name="about_sandor">Sandor Dornbush</string> <string name="about_sandor">Sandor Dornbush</string>
<string name="color_mode_dynamic_percentage_default">25</string>
<string name="color_mode_fixed_medium_default">15</string>
<string name="color_mode_fixed_slow_default">9</string>
<string name="display_track_color_value_dynamic">DYNAMIC</string> <string name="display_track_color_value_dynamic">DYNAMIC</string>
<string name="display_track_color_value_fixed">FIXED</string> <string name="display_track_color_value_fixed">FIXED</string>
<string name="display_track_color_value_none">NONE</string> <string name="display_track_color_value_none">NONE</string>
+5 -5
View File
@@ -45,7 +45,7 @@ limitations under the License.
<EditTextPreference android:key="@string/track_color_mode_fixed_speed_slow_key" <EditTextPreference android:key="@string/track_color_mode_fixed_speed_slow_key"
android:title="@string/settings_display_track_color_fixed_slow" android:title="@string/settings_display_track_color_fixed_slow"
android:summary="@string/settings_display_track_color_fixed_slow_summary" android:summary="@string/settings_display_track_color_fixed_slow_summary"
android:defaultValue="9" android:defaultValue="@string/color_mode_fixed_slow_default"
android:inputType="number" android:inputType="number"
android:maxLength="3"> android:maxLength="3">
</EditTextPreference> </EditTextPreference>
@@ -53,7 +53,7 @@ limitations under the License.
<EditTextPreference android:key="@string/track_color_mode_fixed_speed_slow_display_key" <EditTextPreference android:key="@string/track_color_mode_fixed_speed_slow_display_key"
android:title="@string/settings_display_track_color_fixed_slow" android:title="@string/settings_display_track_color_fixed_slow"
android:summary="@string/settings_display_track_color_fixed_slow_summary" android:summary="@string/settings_display_track_color_fixed_slow_summary"
android:defaultValue="9" android:defaultValue="@string/color_mode_fixed_slow_default"
android:inputType="number" android:inputType="number"
android:maxLength="3"> android:maxLength="3">
</EditTextPreference> </EditTextPreference>
@@ -61,7 +61,7 @@ limitations under the License.
<EditTextPreference android:key="@string/track_color_mode_fixed_speed_medium_key" <EditTextPreference android:key="@string/track_color_mode_fixed_speed_medium_key"
android:title="@string/settings_display_track_color_fixed_medium" android:title="@string/settings_display_track_color_fixed_medium"
android:summary="@string/settings_display_track_color_fixed_medium_summary" android:summary="@string/settings_display_track_color_fixed_medium_summary"
android:defaultValue="15" android:defaultValue="@string/color_mode_fixed_medium_default"
android:inputType="number" android:inputType="number"
android:maxLength="3"> android:maxLength="3">
</EditTextPreference> </EditTextPreference>
@@ -69,7 +69,7 @@ limitations under the License.
<EditTextPreference android:key="@string/track_color_mode_fixed_speed_medium_display_key" <EditTextPreference android:key="@string/track_color_mode_fixed_speed_medium_display_key"
android:title="@string/settings_display_track_color_fixed_medium" android:title="@string/settings_display_track_color_fixed_medium"
android:summary="@string/settings_display_track_color_fixed_medium_summary" android:summary="@string/settings_display_track_color_fixed_medium_summary"
android:defaultValue="15" android:defaultValue="@string/color_mode_fixed_medium_default"
android:inputType="number" android:inputType="number"
android:maxLength="3"> android:maxLength="3">
</EditTextPreference> </EditTextPreference>
@@ -79,7 +79,7 @@ limitations under the License.
<EditTextPreference android:key="@string/track_color_mode_dynamic_speed_variation_key" <EditTextPreference android:key="@string/track_color_mode_dynamic_speed_variation_key"
android:title="@string/settings_display_track_color_dynamic_medium" android:title="@string/settings_display_track_color_dynamic_medium"
android:summary="@string/settings_display_track_color_dynamic_medium_summary" android:summary="@string/settings_display_track_color_dynamic_medium_summary"
android:defaultValue="25" android:defaultValue="@string/color_mode_dynamic_percentage_default"
android:inputType="number" android:inputType="number"
android:maxLength="2"> android:maxLength="2">
</EditTextPreference> </EditTextPreference>
@@ -37,21 +37,22 @@ 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;
private final int speedMarginDefault;
private double averageMovingSpeed; private double averageMovingSpeed;
private final Context context; private final Context context;
public DynamicSpeedTrackPathDescriptor(Context context){ public DynamicSpeedTrackPathDescriptor(Context context){
this.context = context; this.context = context;
speedMarginDefault = Integer.parseInt(
context.getString(R.string.color_mode_dynamic_percentage_default));
SharedPreferences prefs = context.getSharedPreferences( SharedPreferences prefs = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (prefs == null) { if (prefs == null) {
speedMargin = DEFAULT_SPEED_MARGIN; speedMargin = speedMarginDefault;
return; return;
} }
prefs.registerOnSharedPreferenceChangeListener(this); prefs.registerOnSharedPreferenceChangeListener(this);
@@ -60,12 +61,13 @@ public class DynamicSpeedTrackPathDescriptor
} }
private int getSpeedMargin(SharedPreferences sharedPreferences) { private int getSpeedMargin(SharedPreferences sharedPreferences) {
String key = context.getString(R.string.track_color_mode_dynamic_speed_variation_key); try {
String percentage = sharedPreferences.getString(key, DEFAULT_SPEED_MARGIN + ""); return Integer.parseInt(sharedPreferences.getString(
if (percentage.isEmpty()) { context.getString(R.string.track_color_mode_dynamic_speed_variation_key),
return DEFAULT_SPEED_MARGIN; speedMarginDefault + ""));
} catch (NumberFormatException e) {
return speedMarginDefault;
} }
return Integer.parseInt(percentage);
} }
/** /**
@@ -99,7 +101,7 @@ public class DynamicSpeedTrackPathDescriptor
Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (prefs == null) { if (prefs == null) {
speedMargin = DEFAULT_SPEED_MARGIN; speedMargin = speedMarginDefault;
return; return;
} }
@@ -34,32 +34,37 @@ import android.util.Log;
public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSharedPreferenceChangeListener { public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSharedPreferenceChangeListener {
private int slowSpeed; private int slowSpeed;
private int normalSpeed; private int normalSpeed;
private final int slowDefault;
private final int normalDefault;
private final Context context; private final Context context;
public FixedSpeedTrackPathDescriptor(Context context) { public FixedSpeedTrackPathDescriptor(Context context) {
this.context = context; this.context = context;
slowDefault = Integer.parseInt(context.getString(R.string.color_mode_fixed_slow_default));
normalDefault = Integer.parseInt(context.getString(R.string.color_mode_fixed_medium_default));
SharedPreferences prefs = context.getSharedPreferences( SharedPreferences prefs = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (prefs == null) { if (prefs == null) {
slowSpeed = 9; slowSpeed = slowDefault;
normalSpeed = 17; normalSpeed = normalDefault;
return; return;
} }
prefs.registerOnSharedPreferenceChangeListener(this); prefs.registerOnSharedPreferenceChangeListener(this);
try { try {
slowSpeed = Integer.parseInt(prefs.getString(context.getString( slowSpeed = Integer.parseInt(prefs.getString(context.getString(
R.string.track_color_mode_fixed_speed_slow_key), "9")); R.string.track_color_mode_fixed_speed_slow_key), slowDefault + ""));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
slowSpeed = 9; slowSpeed = slowDefault;
} }
try { try {
normalSpeed = Integer.parseInt(prefs.getString(context.getString( normalSpeed = Integer.parseInt(prefs.getString(context.getString(
R.string.track_color_mode_fixed_speed_medium_key), "17")); R.string.track_color_mode_fixed_speed_medium_key), normalDefault + ""));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
normalSpeed = 17; normalSpeed = normalDefault;
} }
} }
@@ -90,22 +95,22 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSha
SharedPreferences prefs = context.getSharedPreferences( SharedPreferences prefs = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE); Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (prefs == null) { if (prefs == null) {
slowSpeed = 9; slowSpeed = slowDefault;
normalSpeed = 17; normalSpeed = normalDefault;
return; return;
} }
try { try {
slowSpeed = Integer.parseInt(prefs.getString(context.getString( slowSpeed = Integer.parseInt(prefs.getString(context.getString(
R.string.track_color_mode_fixed_speed_slow_key), "9")); R.string.track_color_mode_fixed_speed_slow_key), slowDefault + ""));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
slowSpeed = 9; slowSpeed = slowDefault;
} }
try { try {
normalSpeed = Integer.parseInt(prefs.getString(context.getString( normalSpeed = Integer.parseInt(prefs.getString(context.getString(
R.string.track_color_mode_fixed_speed_medium_key), "17")); R.string.track_color_mode_fixed_speed_medium_key), normalDefault + ""));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
normalSpeed = 17; normalSpeed = normalDefault;
} }
} }