Place map settings in MapSettingsActivity.

This commit is contained in:
Jimmy Shih
2012-05-08 09:11:08 -07:00
parent 3461a50288
commit 26a44dfd9a
17 changed files with 566 additions and 584 deletions
+1
View File
@@ -208,6 +208,7 @@ limitations under the License.
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity" />
<activity android:name="com.google.android.apps.mytracks.io.sendtogoogle.UploadServiceChooserActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.BackupSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.MapSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.RecordingSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SensorSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SettingsActivity" />
+10 -10
View File
@@ -90,16 +90,6 @@ limitations under the License.
<item>15</item>
<item>-1</item>
</string-array>
<string-array name="display_track_color_options">
<item>@string/settings_display_track_color_single</item>
<item>@string/settings_display_track_color_fixed</item>
<item>@string/settings_display_track_color_dynamic</item>
</string-array>
<string-array name="display_track_color_values">
<item>@string/display_track_color_value_none</item>
<item>@string/display_track_color_value_fixed</item>
<item>@string/display_track_color_value_dynamic</item>
</string-array>
<string-array name="file_types">
<item>GPX</item>
<item>KML</item>
@@ -192,6 +182,16 @@ limitations under the License.
<item>@string/sensor_type_value_polar</item>
<item>@string/sensor_type_value_zephyr</item>
</string-array>
<string-array name="track_color_mode_options">
<item>@string/settings_map_track_color_mode_single</item>
<item>@string/settings_map_track_color_mode_fixed</item>
<item>@string/settings_map_track_color_mode_dynamic</item>
</string-array>
<string-array name="track_color_mode_values">
<item>@string/settings_map_track_color_mode_single_value</item>
<item>@string/settings_map_track_color_mode_fixed_value</item>
<item>@string/settings_map_track_color_mode_dynamic_value</item>
</string-array>
<string-array name="track_name_options">
<item>@string/settings_recording_track_name_date_local_option</item>
<item>@string/settings_recording_track_name_date_iso_8601_option</item>
+10 -21
View File
@@ -16,36 +16,25 @@ limitations under the License.
-->
<resources>
<!-- DO NOT TRANSLATE ANY STRINGS IN THIS FILE. -->
<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_fixed">FIXED</string>
<string name="display_track_color_value_none">NONE</string>
<string name="marker_statistics_icon_url">
http://maps.google.com/mapfiles/ms/micons/ylw-pushpin.png
</string>
<string name="marker_waypoint_icon_url">
http://maps.google.com/mapfiles/ms/micons/blue-pushpin.png
</string>
<string name="my_tracks_analytics_id">UA-7222692-2</string>
<string name="marker_statistics_icon_url">http://maps.google.com/mapfiles/ms/micons/ylw-pushpin.png</string>
<string name="marker_waypoint_icon_url">http://maps.google.com/mapfiles/ms/micons/blue-pushpin.png</string>
<string name="my_tracks_analytics_id">UA-7222692-2</string>
<string name="my_tracks_privacy_url">www.google.com/policies/privacy/</string>
<string name="my_tracks_recording_service_name">My Tracks Recording Service</string>
<string name="my_tracks_support_url">
groups.google.com/a/googleproductforums.com/forum/#!categories/maps/mytracks
</string>
<string name="my_tracks_support_url">groups.google.com/a/googleproductforums.com/forum/#!categories/maps/mytracks</string>
<string name="my_tracks_web_url">www.google.com/mobile/mytracks</string>
<string name="permission_notification_value">
com.google.android.apps.mytracks.MYTRACKS_NOTIFICATIONS
</string>
<string name="permission_notification_value">com.google.android.apps.mytracks.MYTRACKS_NOTIFICATIONS</string>
<string name="send_google_docs_url">docs.google.com</string>
<string name="send_google_fusion_tables_url">google.com/fusiontables</string>
<string name="send_google_maps_url">maps.google.com</string>
<string name="sensor_type_value_ant">ANT</string>
<string name="sensor_type_value_ant">ANT</string>
<string name="sensor_type_value_none">NONE</string>
<string name="sensor_type_value_polar">POLAR</string>
<string name="sensor_type_value_srm_ant_bridge">SRM_ANT_BRIDGE</string>
<string name="sensor_type_value_zephyr">ZEPHYR</string>
<string name="settings_map_track_color_mode_dynamic_value">DYNAMIC</string>
<string name="settings_map_track_color_mode_fixed_value">FIXED</string>
<string name="settings_map_track_color_mode_single_value">SINGLE</string>
<string name="settings_recording_track_name_date_iso_8601_value">DATE_ISO_8601</string>
<string name="settings_recording_track_name_date_local_value">DATE_LOCAL</string>
<string name="settings_recording_track_name_number_value">NUMBER</string>
@@ -53,4 +42,4 @@ limitations under the License.
<string name="track_action_save">android.intent.action.SAVE</string>
<string name="track_action_start">com.google.android.apps.mytracks.START_NEW_TRACK</string>
<string name="value_unknown">-</string>
</resources>
</resources>
+7 -6
View File
@@ -50,11 +50,9 @@ limitations under the License.
<string name="stats_show_elevation_key">statsShowElevation</string>
<string name="stats_show_grade_key">statsShowGrade</string>
<string name="stats_use_total_time_key">statsUseTotalTime</string>
<string name="track_color_mode_dynamic_speed_variation_key">trackColorModeDynamicVariation</string>
<string name="track_color_mode_fixed_speed_medium_display_key">trackColorModeFixedMediumDisplay</string>
<string name="track_color_mode_fixed_speed_medium_key">trackColorModeFixedMedium</string>
<string name="track_color_mode_fixed_speed_slow_display_key">trackColorModeFixedSlowDisplay</string>
<string name="track_color_mode_fixed_speed_slow_key">trackColorModeFixedSlow</string>
<string name="track_color_mode_medium_key">trackColorModeMedium</string>
<string name="track_color_mode_percentage_key">trackColorModePercentage</string>
<string name="track_color_mode_slow_key">trackColorModeSlow</string>
<string name="track_color_mode_key">trackColorMode</string>
<string name="track_name_key">trackName</string>
@@ -63,6 +61,10 @@ limitations under the License.
<string name="reset_key">resetToDefaults</string>
<string name="restore_from_sd_key">restoreFromSd</string>
<string name="settings_backup_key">settingsBackup</string>
<string name="settings_map_key">settingsMap</string>
<string name="settings_map_medium_display_key">settingsMapMediumDisplay</string>
<string name="settings_map_percentage_display_key">settingsMapPercentageDisplay</string>
<string name="settings_map_slow_display_key">settingsMapSlowDisplay</string>
<string name="settings_recording_key">settingsRecording</string>
<string name="settings_sensor_key">settingsSensor</string>
<string name="settings_sensor_ant_key">settingsSensorAnt</string>
@@ -71,5 +73,4 @@ limitations under the License.
<string name="settings_sensor_root_key">settingsSensorRoot</string>
<string name="settings_sharing_key">settingsSharing</string>
<string name="settings_stats_key">settingsStats</string>
<string name="track_color_mode_fixed_speed_options_key">trackColorModeFixedOptions</string>
</resources>
+55 -80
View File
@@ -1520,97 +1520,60 @@ limitations under the License.
the SD card.">
Restore all tracks and settings from the SD card.
</string>
<!-- Settings Display -->
<string name="settings_display"
translation_description="In the 'Settings' page, the option to change the display related
settings.
Character limit: ~26 (1 line)">
Display
<!-- Settings Map -->
<string name="settings_map_medium"
translation_description="In the 'Map' settings, under the 'Fixed thresholds' configurations, the
option for configuring the top medium speed.">
Top medium speed
</string>
<string name="settings_display_track_color"
translation_description="In the 'Display' settings, the dropdown option to choose a track color
mode for how to use different colors to color a track based on slow, medium, and fast speed.
Character limit: ~23 (1 line)">
Color mode
<string name="settings_map_percentage"
translation_description="In the 'Map' settings, under the 'Dynamic thresholds' configurations,
the option for configuring the percentage from the average speed for the medium speed range.">
Percentage from average
</string>
<string name="settings_display_track_color_dynamic"
translation_description="In the 'Display' settings, for the 'Color mode' dropdown, the
option to use different colors to color a track based on dynamically determined speed
thresholds. E.g., use one color when the speed is below the slow speed threshold.
Character limit: ~21 (1 line)">
Dynamic thresholds
</string>
<string name="settings_display_track_color_dynamic_medium"
translation_description="In the 'Display' settings, under the 'Dynamic thresholds'
configurations, the option for configuring the percentage from the average speed for the
medium speed range. The color mode will use different colors to color a track depending
on whether the speed is above, in, or below the medium speed range.
Character limit: ~23 (1 line)">
Percentage
</string>
<string name="settings_display_track_color_dynamic_medium_summary"
translation_description="In the 'Display' settings, under the 'Dynamic thresholds'
configurations, the summary for the 'Percentage' option explaining that it sets
the percentage from the average speed for the medium speed range. The color mode will
use different colors to color a track depending on whether the speed is above, in, or below
<string name="settings_map_percentage_summary"
translation_description="In the 'Map' settings, under the 'Dynamic thresholds' configurations,
the summary for the 'Percentage from average' option explaining that it sets the percentage
from the average speed for the medium speed range. The 'Dynamic thresholds' track color mode
uses different colors to color a track depending on whether the speed is above, in, or below
the medium speed range.">
Percentage from the average speed for the medium speed range.
</string>
<string name="settings_display_track_color_fixed"
translation_description="In the 'Display' settings, for the 'Color mode' dropdown, the
option to use different colors to color a track based on fixed speed thresholds. E.g., use
one color when the speed is below the slow speed threshold.
Character limit: ~21 (1 line)">
<string name="settings_map_slow"
translation_description="In the 'Map' settings, under the 'Fixed thresholds' configurations,
the option for configuring the top slow speed.">
Top slow speed
</string>
<string name="settings_map_track_color_mode"
translation_description="In the 'Map' settings, the option to select a track color mode for how
to use different colors to color a track based on slow, medium, and fast speed.">
Track color mode
</string>
<string name="settings_map_track_color_mode_dynamic"
translation_description="In the 'Map' settings, for the 'Track color mode' dropdown, the
option to use different colors to color a track based on dynamically determined speed
thresholds.">
Dynamic thresholds
</string>
<string name="settings_map_track_color_mode_fixed"
translation_description="In the 'Map' settings, for the 'Track color mode' dropdown, the
option to use different colors to color a track based on fixed speed thresholds.">
Fixed thresholds
</string>
<string name="settings_display_track_color_fixed_medium"
translation_description="In the 'Display' settings, under the 'Fixed thresholds' configurations,
the option for configuring the medium speed threshold. Thus any speed lower than the
threshold but greater than the slow speed threshold will be colored by the medium speed
color.
Character limit: ~23 (1 line)">
Medium speed
</string>
<string name="settings_display_track_color_fixed_medium_summary"
translation_description="In the 'Display' settings, under the 'Fixed thresholds' configurations,
the summary for the 'Medium speed' option explaining that it sets a cutoff speed
for the medium speed color.">
Medium speed top value.
</string>
<string name="settings_display_track_color_fixed_slow"
translation_description="In the 'Display' settings, under the 'Fixed thresholds' configurations,
the option for configuring the slow speed threshold. Thus any speed lower than the threshold
will be colored by the slow speed color.
Character limit: ~23 (1 line)">
Slow speed
</string>
<string name="settings_display_track_color_fixed_slow_summary"
translation_description="In the 'Display' settings, under the 'Fixed thresholds' configurations,
the summary for the 'Slow speed' option explaining that it sets a cutoff speed for
the slow speed color.">
Slow speed top value.
</string>
<string name="settings_display_track_color_single"
translation_description="In the 'Display' settings, for the 'Color mode' dropdown, the
option to use a single color for all speeds.
Character limit: ~21 (1 line)">
<string name="settings_map_track_color_mode_single"
translation_description="In the 'Map' settings, for the 'Track color mode' dropdown, the
option to use a single color for all speeds.">
Single color
</string>
<string name="settings_display_track_color_summary"
translation_description="In the 'Display' settings, the summary for the 'Color mode'
dropdown explaining that it configures how colors are used to color a track based on
slow, medium, and fast speed.">
<string name="settings_map_track_color_mode_summary"
translation_description="In the 'Map' settings, the summary for the 'Track color mode' option
explaining that it configures how colors are used to color a track based on slow, medium, and
fast speed.">
The way to color a track based on slow, medium, and fast speed.
</string>
<!-- Settings Others -->
<string name="settings_not_while_recording"
translation_description="In settings, the summary for an option that is not available during a
track recording.">
@@ -2281,7 +2244,7 @@ limitations under the License.
%1$.2f: a float number. E.g., '2.22'">
%1$.2f km
</string>
<string name="value_float_kilometer_hour"
<string name="value_float_kilometer_hour"
translation_description="Display a float value in kilometers per hour (km/h).
%1$.2f: a float number. E.g., '2.22'">
@@ -2352,6 +2315,12 @@ limitations under the License.
%1$d: an integer value. E.g., '2'">
%1$d km
</string>
<string name="value_integer_kilometer_hour"
translation_description="Display an integer value in kilometers per hour (km/h).
%1$d: an integer value. E.g., '2'">
%1$d km/h
</string>
<string name="value_integer_meter"
translation_description="In a setting picker, the string format to display an integer value in
meters (m).
@@ -2387,6 +2356,12 @@ limitations under the License.
%1$d: an integer value. E.g., '2'">
%1$d mi
</string>
<string name="value_integer_mile_hour"
translation_description="Display an integer value in miles per hour (mi/h).
%1$d: an integer value. E.g., '2'">
%1$d mi/h
</string>
<string name="value_integer_minute"
translation_description="In a setting picker, the string format to display an integer value in
minutes (min).
+51
View File
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2012 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/track_detail_map_tab" >
<ListPreference
android:defaultValue="@string/settings_map_track_color_mode_single_value"
android:entries="@array/track_color_mode_options"
android:entryValues="@array/track_color_mode_values"
android:key="@string/track_color_mode_key"
android:summary="@string/settings_map_track_color_mode_summary"
android:title="@string/settings_map_track_color_mode" />
<PreferenceCategory android:title="@string/settings_map_track_color_mode_fixed" >
<EditTextPreference
android:imeOptions="actionDone"
android:inputType="number"
android:key="@string/settings_map_slow_display_key"
android:persistent="false"
android:title="@string/settings_map_slow" >
</EditTextPreference>
<EditTextPreference
android:imeOptions="actionDone"
android:inputType="number"
android:key="@string/settings_map_medium_display_key"
android:persistent="false"
android:title="@string/settings_map_medium" >
</EditTextPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/settings_map_track_color_mode_dynamic" >
<EditTextPreference
android:imeOptions="actionDone"
android:inputType="number"
android:key="@string/settings_map_percentage_display_key"
android:persistent="false"
android:title="@string/settings_map_percentage" >
</EditTextPreference>
</PreferenceCategory>
</PreferenceScreen>
+23 -75
View File
@@ -15,87 +15,35 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/menu_settings">
<!-- Display settings -->
<PreferenceScreen android:title="@string/settings_display">
<ListPreference android:key="@string/track_color_mode_key"
android:title="@string/settings_display_track_color"
android:summary="@string/settings_display_track_color_summary"
android:entries="@array/display_track_color_options"
android:entryValues="@array/display_track_color_values"
android:defaultValue="@string/display_track_color_value_none"/>
<PreferenceCategory android:title="@string/settings_display_track_color_fixed"
android:key="@string/track_color_mode_fixed_speed_options_key">
<EditTextPreference android:key="@string/track_color_mode_fixed_speed_slow_key"
android:title="@string/settings_display_track_color_fixed_slow"
android:summary="@string/settings_display_track_color_fixed_slow_summary"
android:defaultValue="@string/color_mode_fixed_slow_default"
android:inputType="number"
android:maxLength="3">
</EditTextPreference>
<EditTextPreference android:key="@string/track_color_mode_fixed_speed_slow_display_key"
android:title="@string/settings_display_track_color_fixed_slow"
android:summary="@string/settings_display_track_color_fixed_slow_summary"
android:defaultValue="@string/color_mode_fixed_slow_default"
android:inputType="number"
android:maxLength="3">
</EditTextPreference>
<EditTextPreference android:key="@string/track_color_mode_fixed_speed_medium_key"
android:title="@string/settings_display_track_color_fixed_medium"
android:summary="@string/settings_display_track_color_fixed_medium_summary"
android:defaultValue="@string/color_mode_fixed_medium_default"
android:inputType="number"
android:maxLength="3">
</EditTextPreference>
<EditTextPreference android:key="@string/track_color_mode_fixed_speed_medium_display_key"
android:title="@string/settings_display_track_color_fixed_medium"
android:summary="@string/settings_display_track_color_fixed_medium_summary"
android:defaultValue="@string/color_mode_fixed_medium_default"
android:inputType="number"
android:maxLength="3">
</EditTextPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/settings_display_track_color_dynamic">
<EditTextPreference android:key="@string/track_color_mode_dynamic_speed_variation_key"
android:title="@string/settings_display_track_color_dynamic_medium"
android:summary="@string/settings_display_track_color_dynamic_medium_summary"
android:defaultValue="@string/color_mode_dynamic_percentage_default"
android:inputType="number"
android:maxLength="2">
</EditTextPreference>
</PreferenceCategory>
</PreferenceScreen>
android:title="@string/menu_settings" >
<Preference
android:key="@string/settings_map_key"
android:persistent="false"
android:title="@string/track_detail_map_tab" />
<Preference
android:key="@string/settings_stats_key"
android:persistent="false"
android:title="@string/track_detail_stats_tab" />
<Preference
android:title="@string/settings_recording"
android:key="@string/settings_recording_key"
android:persistent="false" />
android:key="@string/settings_recording_key"
android:persistent="false"
android:title="@string/settings_recording" />
<Preference
android:title="@string/settings_sharing"
android:key="@string/settings_sharing_key"
android:persistent="false" />
<Preference
android:title="@string/settings_sensor"
android:key="@string/settings_sensor_key"
android:persistent="false" />
android:key="@string/settings_sharing_key"
android:persistent="false"
android:title="@string/settings_sharing" />
<Preference
android:title="@string/settings_backup"
android:key="@string/settings_backup_key"
android:persistent="false" />
android:key="@string/settings_sensor_key"
android:persistent="false"
android:title="@string/settings_sensor" />
<Preference
android:key="@string/settings_backup_key"
android:persistent="false"
android:title="@string/settings_backup" />
<!-- Reset to defaults -->
<Preference
android:title="@string/settings_reset"
android:key="@string/reset_key"
android:summary="@string/settings_reset_summary"
android:persistent="false" />
</PreferenceScreen>
android:key="@string/reset_key"
android:persistent="false"
android:summary="@string/settings_reset_summary"
android:title="@string/settings_reset" />
</PreferenceScreen>
@@ -23,6 +23,7 @@ import com.google.android.apps.mytracks.maps.TrackPathPainterFactory;
import com.google.android.apps.mytracks.maps.TrackPathUtilities;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.UnitConversions;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
@@ -462,10 +463,8 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.d(TAG, "MapOverlay: onSharedPreferences changed " + key);
if (key != null) {
if (key.equals(context.getString(R.string.track_color_mode_key))) {
trackPathPainter = TrackPathPainterFactory.getTrackPathPainter(context);
}
if (PreferencesUtils.getKey(context, R.string.track_color_mode_key).equals(key)) {
trackPathPainter = TrackPathPainterFactory.getTrackPathPainter(context);
}
}
}
@@ -42,7 +42,6 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor,
private int slowSpeed;
private int normalSpeed;
private int speedMargin;
private final int speedMarginDefault;
private double averageMovingSpeed;
private final Context context;
@VisibleForTesting
@@ -50,29 +49,12 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor,
public DynamicSpeedTrackPathDescriptor(Context context) {
this.context = context;
speedMarginDefault = Integer.parseInt(context
.getString(R.string.color_mode_dynamic_percentage_default));
SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME,
Context.MODE_PRIVATE);
if (prefs == null) {
speedMargin = speedMarginDefault;
return;
}
prefs.registerOnSharedPreferenceChangeListener(this);
speedMargin = getSpeedMargin(prefs);
}
@VisibleForTesting
int getSpeedMargin(SharedPreferences sharedPreferences) {
try {
return Integer.parseInt(sharedPreferences.getString(
context.getString(R.string.track_color_mode_dynamic_speed_variation_key),
Integer.toString(speedMarginDefault)));
} catch (NumberFormatException e) {
return speedMarginDefault;
}
speedMargin = PreferencesUtils.getInt(context, R.string.track_color_mode_percentage_key,
PreferencesUtils.TRACK_COLOR_MODE_PERCENTAGE_DEFAULT);
}
/**
@@ -98,17 +80,10 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor,
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.d(TAG, "DynamicSpeedTrackPathDescriptor: onSharedPreferences changed " + key);
if (key == null
|| !key.equals(context.getString(R.string.track_color_mode_dynamic_speed_variation_key))) { return; }
SharedPreferences prefs = context.getSharedPreferences(Constants.SETTINGS_NAME,
Context.MODE_PRIVATE);
if (prefs == null) {
speedMargin = speedMarginDefault;
return;
if (PreferencesUtils.getKey(context, R.string.track_color_mode_percentage_key).equals(key)) {
speedMargin = PreferencesUtils.getInt(context, R.string.track_color_mode_percentage_key,
PreferencesUtils.TRACK_COLOR_MODE_PERCENTAGE_DEFAULT);
}
speedMargin = getSpeedMargin(prefs);
}
@Override
@@ -13,104 +13,67 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.maps;
import static com.google.android.apps.mytracks.Constants.TAG;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.util.Log;
/**
* A fixed speed path descriptor.
*
*
* @author Vangelis S.
*/
public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor, OnSharedPreferenceChangeListener {
public class FixedSpeedTrackPathDescriptor
implements TrackPathDescriptor, OnSharedPreferenceChangeListener {
private int slowSpeed;
private int normalSpeed;
private final int slowDefault;
private final int normalDefault;
private final Context context;
public FixedSpeedTrackPathDescriptor(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 sharedPreferences = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (prefs == null) {
slowSpeed = slowDefault;
normalSpeed = normalDefault;
return;
}
prefs.registerOnSharedPreferenceChangeListener(this);
try {
slowSpeed = Integer.parseInt(prefs.getString(context.getString(
R.string.track_color_mode_fixed_speed_slow_key), Integer.toString(slowDefault)));
} catch (NumberFormatException e) {
slowSpeed = slowDefault;
}
try {
normalSpeed = Integer.parseInt(prefs.getString(context.getString(
R.string.track_color_mode_fixed_speed_medium_key), Integer.toString(normalDefault)));
} catch (NumberFormatException e) {
normalSpeed = normalDefault;
}
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
slowSpeed = PreferencesUtils.getInt(context, R.string.track_color_mode_slow_key,
PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT);
normalSpeed = PreferencesUtils.getInt(context, R.string.track_color_mode_medium_key,
PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT);
}
/**
* Gets the slow speed for reference.
*
* @return The speed limit considered as slow.
*/
public int getSlowSpeed() {
return slowSpeed;
}
/**
* Gets the normal speed for reference.
*
* @return The speed limit considered as normal.
*/
public int getNormalSpeed() {
return normalSpeed;
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Log.d(TAG, "FixedSpeedTrackPathDescriptor: onSharedPreferences changed " + key);
if (key == null
|| (!key.equals(context.getString(R.string.track_color_mode_fixed_speed_slow_key))
&& !key.equals(context.getString(R.string.track_color_mode_fixed_speed_medium_key)))) {
return;
}
SharedPreferences prefs = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (prefs == null) {
slowSpeed = slowDefault;
normalSpeed = normalDefault;
return;
}
try {
slowSpeed = Integer.parseInt(prefs.getString(context.getString(
R.string.track_color_mode_fixed_speed_slow_key), Integer.toString(slowDefault)));
} catch (NumberFormatException e) {
slowSpeed = slowDefault;
}
try {
normalSpeed = Integer.parseInt(prefs.getString(context.getString(
R.string.track_color_mode_fixed_speed_medium_key), Integer.toString(normalDefault)));
} catch (NumberFormatException e) {
normalSpeed = normalDefault;
if (PreferencesUtils.getKey(context, R.string.track_color_mode_slow_key).equals(key)) {
slowSpeed = PreferencesUtils.getInt(context, R.string.track_color_mode_slow_key,
PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT);
} else if (PreferencesUtils.getKey(context, R.string.track_color_mode_medium_key).equals(key)) {
normalSpeed = PreferencesUtils.getInt(context, R.string.track_color_mode_medium_key,
PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT);
}
}
@@ -17,11 +17,10 @@ package com.google.android.apps.mytracks.maps;
import static com.google.android.apps.mytracks.Constants.TAG;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
/**
@@ -40,26 +39,18 @@ public class TrackPathPainterFactory {
* @return The TrackPathPainter that corresponds to the track color mode setting.
*/
public static TrackPathPainter getTrackPathPainter(Context context) {
SharedPreferences prefs = context.getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
if (prefs == null) {
return new SingleColorTrackPathPainter(context);
}
String colorMode = prefs.getString(context.getString(R.string.track_color_mode_key), null);
Log.i(TAG, "Creating track path painter of type: " + colorMode);
String trackColorMode = PreferencesUtils.getString(context, R.string.track_color_mode_key,
context.getString(R.string.settings_map_track_color_mode_single_value));
Log.i(TAG, "Creating track path painter of type: " + trackColorMode);
if (colorMode == null
|| colorMode.equals(context.getString(R.string.display_track_color_value_none))) {
return new SingleColorTrackPathPainter(context);
} else if (colorMode.equals(context.getString(R.string.display_track_color_value_fixed))) {
return new DynamicSpeedTrackPathPainter(context,
new FixedSpeedTrackPathDescriptor(context));
} else if (colorMode.equals(context.getString(R.string.display_track_color_value_dynamic))) {
return new DynamicSpeedTrackPathPainter(context,
new DynamicSpeedTrackPathDescriptor(context));
if (context.getString(R.string.settings_map_track_color_mode_fixed_value)
.equals(trackColorMode)) {
return new DynamicSpeedTrackPathPainter(context, new FixedSpeedTrackPathDescriptor(context));
} else if (context.getString(R.string.settings_map_track_color_mode_dynamic_value)
.equals(trackColorMode)) {
return new DynamicSpeedTrackPathPainter(context, new DynamicSpeedTrackPathDescriptor(
context));
} else {
Log.w(TAG, "Using default track path painter. Unrecognized painter: " + colorMode);
return new SingleColorTrackPathPainter(context);
}
}
@@ -0,0 +1,274 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.settings;
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.app.Dialog;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
/**
* An activity for accessing map settings.
*
* @author Jimmy Shih
*/
public class MapSettingsActivity extends AbstractSettingsActivity {
private static final String TAG = MapSettingsActivity.class.getSimpleName();
private EditTextPreference slowEditTextPreference;
private EditTextPreference mediumEditTextPreference;
private EditTextPreference percentageEditTextPreference;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.map_settings);
ListPreference trackColorModeListPreference = (ListPreference) findPreference(
getString(R.string.track_color_mode_key));
trackColorModeListPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
updateUiByTrackColorMode((String) newValue);
return true;
}
});
updateUiByTrackColorMode(trackColorModeListPreference.getValue());
slowEditTextPreference = (EditTextPreference) findPreference(
getString(R.string.settings_map_slow_display_key));
configureSpeedEditTextPreference(R.string.track_color_mode_slow_key);
mediumEditTextPreference = (EditTextPreference) findPreference(
getString(R.string.settings_map_medium_display_key));
configureSpeedEditTextPreference(R.string.track_color_mode_medium_key);
percentageEditTextPreference = (EditTextPreference) findPreference(
getString(R.string.settings_map_percentage_display_key));
configurePercentageEditTextPreference();
updatePercentageSummary();
configureImeActionDone(slowEditTextPreference);
configureImeActionDone(mediumEditTextPreference);
configureImeActionDone(percentageEditTextPreference);
}
/**
* Configures the speed edit text preference.
*
* @param keyId the key id
*/
private void configureSpeedEditTextPreference(final int keyId) {
final EditTextPreference editTextPreference = keyId == R.string.track_color_mode_slow_key ? slowEditTextPreference
: mediumEditTextPreference;
editTextPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
storeSpeedValue(keyId, (String) newValue);
updateSpeedSummary(keyId);
return true;
}
});
editTextPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
int value = getSpeedDisplayValue(keyId);
((EditTextPreference) preference).getEditText().setText(String.valueOf(value));
return true;
}
});
}
/**
* Configures the percentage edit text preference.
*/
private void configurePercentageEditTextPreference() {
percentageEditTextPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String displayValue = (String) newValue;
int value;
try {
value = Integer.parseInt(displayValue);
} catch (NumberFormatException e) {
Log.e(TAG, "invalid value " + displayValue);
value = PreferencesUtils.TRACK_COLOR_MODE_PERCENTAGE_DEFAULT;
}
if (value < 0) {
value = PreferencesUtils.TRACK_COLOR_MODE_PERCENTAGE_DEFAULT;
}
PreferencesUtils.setInt(
MapSettingsActivity.this, R.string.track_color_mode_percentage_key, value);
updatePercentageSummary();
return true;
}
});
percentageEditTextPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
int value = PreferencesUtils.getInt(
MapSettingsActivity.this, R.string.track_color_mode_percentage_key,
PreferencesUtils.TRACK_COLOR_MODE_PERCENTAGE_DEFAULT);
((EditTextPreference) preference).getEditText().setText(String.valueOf(value));
return true;
}
});
}
/**
* Configures the IME action done.
*
* @param editTextPreference the edit text preference
*/
private void configureImeActionDone(final EditTextPreference editTextPreference) {
editTextPreference.getEditText()
.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Dialog dialog = editTextPreference.getDialog();
editTextPreference.onClick(dialog, Dialog.BUTTON_POSITIVE);
dialog.dismiss();
return true;
}
return false;
}
});
}
@Override
protected void onResume() {
super.onResume();
updateSpeedSummary(R.string.track_color_mode_slow_key);
updateSpeedSummary(R.string.track_color_mode_medium_key);
}
/**
* Updates the UI by the track color mode.
*
* @param trackColorMode the track color mode
*/
@SuppressWarnings("deprecation")
private void updateUiByTrackColorMode(String trackColorMode) {
boolean isFixedValue = trackColorMode.equals(
getString(R.string.settings_map_track_color_mode_fixed_value));
boolean isDynamicValue = trackColorMode.equals(
getString(R.string.settings_map_track_color_mode_dynamic_value));
findPreference(getString(R.string.settings_map_slow_display_key)).setEnabled(isFixedValue);
findPreference(getString(R.string.settings_map_medium_display_key)).setEnabled(isFixedValue);
findPreference(getString(R.string.settings_map_percentage_display_key))
.setEnabled(isDynamicValue);
}
/**
* Stores the speed value, always in metric units.
*
* @param keyId the key id
* @param displayValue the display value
*/
private void storeSpeedValue(int keyId, String displayValue) {
int maxValue;
int minValue;
int defaultValue;
if (keyId == R.string.track_color_mode_slow_key) {
minValue = 0;
maxValue = PreferencesUtils.getInt(this, R.string.track_color_mode_medium_key,
PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT);
defaultValue = PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT;
} else {
minValue = PreferencesUtils.getInt(
this, R.string.track_color_mode_slow_key, PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT);
maxValue = Integer.MAX_VALUE;
defaultValue = PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT;
}
int value;
try {
value = Integer.parseInt(displayValue);
if (!PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
value = (int) (value * UnitConversions.MI_TO_KM);
}
} catch (NumberFormatException e) {
Log.e(TAG, "invalid value " + displayValue);
value = defaultValue;
}
if (value > maxValue) {
value = maxValue;
}
if (value < minValue) {
value = minValue;
}
PreferencesUtils.setInt(this, keyId, value);
}
/**
* Gets the speed display value, in metric or imperial depending on the preferred
* units.
*
* @param keyId the key id
*/
private int getSpeedDisplayValue(int keyId) {
int defaultValue = keyId == R.string.track_color_mode_slow_key ? PreferencesUtils.TRACK_COLOR_MODE_SLOW_DEFAULT
: PreferencesUtils.TRACK_COLOR_MODE_MEDIUM_DEFAULT;
int value = PreferencesUtils.getInt(this, keyId, defaultValue);
if (!PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
value = (int) (value * UnitConversions.KM_TO_MI);
}
return value;
}
/**
* Updates the speed summary.
*
* @param keyId the key id
*/
private void updateSpeedSummary(int keyId) {
EditTextPreference editTextPreference = keyId == R.string.track_color_mode_slow_key ? slowEditTextPreference
: mediumEditTextPreference;
boolean metric = PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
int displayValue = getSpeedDisplayValue(keyId);
editTextPreference.setSummary(getString(metric ? R.string.value_integer_kilometer_hour
: R.string.value_integer_mile_hour, displayValue));
}
/**
* Updates the percentage summary.
*/
private void updatePercentageSummary() {
int value = PreferencesUtils.getInt(
MapSettingsActivity.this, R.string.track_color_mode_percentage_key,
PreferencesUtils.TRACK_COLOR_MODE_PERCENTAGE_DEFAULT);
percentageEditTextPreference.setSummary(getString(R.string.settings_map_percentage_summary) + "\n"
+ getString(R.string.value_integer_percent, value));
}
}
@@ -19,11 +19,9 @@ package com.google.android.apps.mytracks.settings;
import static com.google.android.apps.mytracks.Constants.TAG;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
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.app.Dialog;
@@ -31,14 +29,9 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.util.Log;
import android.widget.Toast;
@@ -58,19 +51,26 @@ public class SettingsActivity extends AbstractSettingsActivity {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.preferences);
customizeTrackColorModePreferences();
Preference mapPreference = findPreference(getString(R.string.settings_map_key));
mapPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(SettingsActivity.this, MapSettingsActivity.class);
startActivity(intent);
return true;
}
});
Preference statsPreference = findPreference(getString(R.string.settings_stats_key));
statsPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = IntentUtils.newIntent(
SettingsActivity.this, StatsSettingsActivity.class);
Intent intent = IntentUtils.newIntent(SettingsActivity.this, StatsSettingsActivity.class);
startActivity(intent);
return true;
}
});
Preference recordingPreference = findPreference(getString(R.string.settings_recording_key));
recordingPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
@@ -139,31 +139,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
}
}
private void customizeTrackColorModePreferences() {
ListPreference trackColorModePreference =
(ListPreference) findPreference(getString(R.string.track_color_mode_key));
trackColorModePreference.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
updateTrackColorModeSettings((String) newValue);
return true;
}
});
updateTrackColorModeSettings(trackColorModePreference.getValue());
setTrackColorModePreferenceListeners();
PreferenceCategory speedOptionsCategory = (PreferenceCategory) findPreference(
getString(R.string.track_color_mode_fixed_speed_options_key));
speedOptionsCategory.removePreference(
findPreference(getString(R.string.track_color_mode_fixed_speed_slow_key)));
speedOptionsCategory.removePreference(
findPreference(getString(R.string.track_color_mode_fixed_speed_medium_key)));
}
@Override
protected void onResume() {
super.onResume();
@@ -175,20 +150,6 @@ public class SettingsActivity extends AbstractSettingsActivity {
: R.string.settings_reset_summary);
}
private void updateTrackColorModeSettings(String trackColorMode) {
boolean usesFixedSpeed =
trackColorMode.equals(getString(R.string.display_track_color_value_fixed));
boolean usesDynamicSpeed =
trackColorMode.equals(getString(R.string.display_track_color_value_dynamic));
findPreference(getString(R.string.track_color_mode_fixed_speed_slow_display_key))
.setEnabled(usesFixedSpeed);
findPreference(getString(R.string.track_color_mode_fixed_speed_medium_display_key))
.setEnabled(usesFixedSpeed);
findPreference(getString(R.string.track_color_mode_dynamic_speed_variation_key))
.setEnabled(usesDynamicSpeed);
}
/** Callback for when user confirms resetting all settings. */
private void onResetPreferencesConfirmed() {
// Change preferences in a separate thread.
@@ -221,84 +182,4 @@ public class SettingsActivity extends AbstractSettingsActivity {
}
}.start();
}
/**
* Set the given edit text preference text.
* If the units are not metric convert the value before displaying.
*/
private void viewTrackColorModeSettings(EditTextPreference preference, int id) {
if (PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
return;
}
// Convert miles/h to km/h
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
String metricspeed = prefs.getString(getString(id), null);
int englishspeed;
try {
englishspeed = (int) (Double.parseDouble(metricspeed) * UnitConversions.KM_TO_MI);
} catch (NumberFormatException e) {
englishspeed = 0;
}
preference.getEditText().setText(String.valueOf(englishspeed));
}
/**
* Saves the given edit text preference value.
* If the units are not metric convert the value before saving.
*/
private void validateTrackColorModeSettings(String newValue, int id) {
String metricspeed;
if (PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
metricspeed = newValue;
} else {
// Convert miles/h to km/h
try {
metricspeed = String.valueOf(
(int) (Double.parseDouble(newValue) * UnitConversions.MI_TO_KM));
} catch (NumberFormatException e) {
metricspeed = "0";
}
}
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
Editor editor = prefs.edit();
editor.putString(getString(id), metricspeed);
ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
}
/**
* Sets the TrackColorMode preference listeners.
*/
private void setTrackColorModePreferenceListeners() {
setTrackColorModePreferenceListener(R.string.track_color_mode_fixed_speed_slow_display_key,
R.string.track_color_mode_fixed_speed_slow_key);
setTrackColorModePreferenceListener(R.string.track_color_mode_fixed_speed_medium_display_key,
R.string.track_color_mode_fixed_speed_medium_key);
}
/**
* Sets a TrackColorMode preference listener.
*/
private void setTrackColorModePreferenceListener(int displayKey, final int metricKey) {
EditTextPreference trackColorModePreference =
(EditTextPreference) findPreference(getString(displayKey));
trackColorModePreference.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
validateTrackColorModeSettings((String) newValue, metricKey);
return true;
}
});
trackColorModePreference.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
viewTrackColorModeSettings((EditTextPreference) preference, metricKey);
return true;
}
});
}
}
@@ -68,6 +68,10 @@ public class PreferencesUtils {
public static final boolean STATS_SHOW_GRADE_DEFAULT = false;
public static final boolean STATS_USE_TOTAL_TIME_DEFAULT = true;
public static final int TRACK_COLOR_MODE_MEDIUM_DEFAULT = 15;
public static final int TRACK_COLOR_MODE_PERCENTAGE_DEFAULT = 25;
public static final int TRACK_COLOR_MODE_SLOW_DEFAULT = 9;
private PreferencesUtils() {}
/**