Use a list preference for the preferred rate setting

This commit is contained in:
Jimmy Shih
2013-08-20 14:43:25 -07:00
parent 7a8a95853e
commit 594f156a1f
14 changed files with 83 additions and 58 deletions
@@ -176,6 +176,18 @@ limitations under the License.
<item>@string/sensor_type_value_zephyr</item> <item>@string/sensor_type_value_zephyr</item>
<item>@string/sensor_type_value_none</item> <item>@string/sensor_type_value_none</item>
</string-array> </string-array>
<string-array name="stats_rate_imperial_options">
<item>@string/description_speed_imperial</item>
<item>@string/description_pace_imperial</item>
</string-array>
<string-array name="stats_rate_metric_options">
<item>@string/description_speed_metric</item>
<item>@string/description_pace_metric</item>
</string-array>
<string-array name="stats_rate_values">
<item>@string/stats_rate_speed</item>
<item>@string/stats_rate_pace</item>
</string-array>
<string-array name="stats_units_options"> <string-array name="stats_units_options">
<item>@string/settings_stats_units_metric</item> <item>@string/settings_stats_units_metric</item>
<item>@string/settings_stats_units_imperial</item> <item>@string/settings_stats_units_imperial</item>
+2
View File
@@ -93,6 +93,8 @@ Google은 이용자에 대한 위치정보의 이용∙제공사실을 위치정
<string name="settings_recording_track_name_date_local_value">DATE_LOCAL</string> <string name="settings_recording_track_name_date_local_value">DATE_LOCAL</string>
<string name="settings_recording_track_name_location_value">LOCATION</string> <string name="settings_recording_track_name_location_value">LOCATION</string>
<string name="settings_recording_track_name_number_value">NUMBER</string> <string name="settings_recording_track_name_number_value">NUMBER</string>
<string name="stats_rate_pace">PACE</string>
<string name="stats_rate_speed">SPEED</string>
<string name="stats_units_imperial">IMPERIAL</string> <string name="stats_units_imperial">IMPERIAL</string>
<string name="stats_units_metric">METRIC</string> <string name="stats_units_metric">METRIC</string>
<string name="track_action_end">com.google.android.apps.mytracks.END_CURRENT_TRACK</string> <string name="track_action_end">com.google.android.apps.mytracks.END_CURRENT_TRACK</string>
+2 -2
View File
@@ -34,14 +34,14 @@ limitations under the License.
<string name="min_recording_interval_key">minRecordingInterval</string> <string name="min_recording_interval_key">minRecordingInterval</string>
<string name="recording_distance_interval_key">recordingDistanceInterval</string> <string name="recording_distance_interval_key">recordingDistanceInterval</string>
<string name="recording_gps_accuracy_key">recordingGpsAccuracy</string> <string name="recording_gps_accuracy_key">recordingGpsAccuracy</string>
<string name="report_speed_key">reportSpeed</string>
<string name="sensor_type_key">sensorType</string> <string name="sensor_type_key">sensorType</string>
<string name="share_track_invite_key">shareTrackInvite</string> <string name="share_track_invite_key">shareTrackInvite</string>
<string name="share_track_public_key">shareTrackPublic</string> <string name="share_track_public_key">shareTrackPublic</string>
<string name="split_frequency_key">splitFrequency</string> <string name="split_frequency_key">splitFrequency</string>
<string name="stats_rate_key">statsRate</string>
<string name="stats_show_coordinate_key">statsShowCoordinate</string> <string name="stats_show_coordinate_key">statsShowCoordinate</string>
<string name="stats_show_grade_elevation_key">statsShowGradeElevation</string> <string name="stats_show_grade_elevation_key">statsShowGradeElevation</string>
<string name="stats_units_key">statsdUnits</string> <string name="stats_units_key">statsUnits</string>
<string name="track_color_mode_medium_key">trackColorModeMedium</string> <string name="track_color_mode_medium_key">trackColorModeMedium</string>
<string name="track_color_mode_percentage_key">trackColorModePercentage</string> <string name="track_color_mode_percentage_key">trackColorModePercentage</string>
<string name="track_color_mode_slow_key">trackColorModeSlow</string> <string name="track_color_mode_slow_key">trackColorModeSlow</string>
+3 -3
View File
@@ -20,9 +20,9 @@ limitations under the License.
android:defaultValue="@string/stats_units_metric" android:defaultValue="@string/stats_units_metric"
android:key="@string/stats_units_key" android:key="@string/stats_units_key"
android:title="@string/settings_stats_units_title" /> android:title="@string/settings_stats_units_title" />
<CheckBoxPreference <ListPreference
android:defaultValue="true" android:defaultValue="@string/stats_rate_speed"
android:key="@string/report_speed_key" android:key="@string/stats_rate_key"
android:title="@string/settings_stats_rate_title" /> android:title="@string/settings_stats_rate_title" />
<PreferenceCategory android:title="@string/settings_show" > <PreferenceCategory android:title="@string/settings_show" >
<CheckBoxPreference <CheckBoxPreference
@@ -282,9 +282,8 @@ public class TrackDataHub implements DataSourceListener {
} }
} }
if (key == null if (key == null
|| key.equals(PreferencesUtils.getKey(context, R.string.report_speed_key))) { || key.equals(PreferencesUtils.getKey(context, R.string.stats_rate_key))) {
reportSpeed = PreferencesUtils.getBoolean( reportSpeed = PreferencesUtils.isReportSpeed(context);
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
if (key != null) { if (key != null) {
for (TrackDataListener trackDataListener : for (TrackDataListener trackDataListener :
trackDataManager.getListeners(TrackDataType.PREFERENCE)) { trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
@@ -65,7 +65,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
private long startTime; private long startTime;
private boolean metricUnits = true; private boolean metricUnits = true;
private boolean reportSpeed = PreferencesUtils.REPORT_SPEED_DEFAULT; private boolean reportSpeed = true;
private int recordingDistanceInterval = PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT; private int recordingDistanceInterval = PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT;
// Modes of operation // Modes of operation
@@ -228,8 +228,7 @@ public class AnnouncementPeriodicTask implements PeriodicTask {
@VisibleForTesting @VisibleForTesting
protected String getAnnouncement(TripStatistics tripStatistics) { protected String getAnnouncement(TripStatistics tripStatistics) {
boolean metricUnits = PreferencesUtils.isMetricUnits(context); boolean metricUnits = PreferencesUtils.isMetricUnits(context);
boolean reportSpeed = PreferencesUtils.getBoolean( boolean reportSpeed = PreferencesUtils.isReportSpeed(context);
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM; double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
double speed = tripStatistics.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH; double speed = tripStatistics.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH;
@@ -46,8 +46,7 @@ public class ChartSettingsActivity extends AbstractSettingsActivity {
private void updateUi() { private void updateUi() {
CheckBoxPreference speedCheckBoxPreference = (CheckBoxPreference) findPreference( CheckBoxPreference speedCheckBoxPreference = (CheckBoxPreference) findPreference(
getString(R.string.chart_show_speed_key)); getString(R.string.chart_show_speed_key));
boolean reportSpeed = PreferencesUtils.getBoolean( boolean reportSpeed = PreferencesUtils.isReportSpeed(this);
this, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
speedCheckBoxPreference.setTitle(reportSpeed ? R.string.stats_speed speedCheckBoxPreference.setTitle(reportSpeed ? R.string.stats_speed
: R.string.stats_pace); : R.string.stats_pace);
} }
@@ -20,7 +20,6 @@ import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceChangeListener;
@@ -32,21 +31,30 @@ import android.preference.Preference.OnPreferenceChangeListener;
*/ */
public class StatsSettingsActivity extends AbstractSettingsActivity { public class StatsSettingsActivity extends AbstractSettingsActivity {
private String statsUnits;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
protected void onCreate(Bundle bundle) { protected void onCreate(Bundle bundle) {
super.onCreate(bundle); super.onCreate(bundle);
addPreferencesFromResource(R.xml.stats_settings); addPreferencesFromResource(R.xml.stats_settings);
ListPreference preference = (ListPreference) findPreference( /*
* Note configureUnitsListPreference will trigger
* configureRateListPreference
*/
configUnitsListPreference();
}
/**
* Configures the preferred units list preference.
*/
private void configUnitsListPreference() {
@SuppressWarnings("deprecation")
ListPreference listPreference = (ListPreference) findPreference(
getString(R.string.stats_units_key)); getString(R.string.stats_units_key));
OnPreferenceChangeListener listener = new OnPreferenceChangeListener() { OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference pref, Object newValue) { public boolean onPreferenceChange(Preference pref, Object newValue) {
statsUnits = (String) newValue; configRateListPreference(PreferencesUtils.STATS_UNITS_DEFAULT.equals((String) newValue));
updateUi();
return true; return true;
} }
}; };
@@ -54,27 +62,23 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT); this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
String[] values = getResources().getStringArray(R.array.stats_units_values); String[] values = getResources().getStringArray(R.array.stats_units_values);
String[] options = getResources().getStringArray(R.array.stats_units_options); String[] options = getResources().getStringArray(R.array.stats_units_options);
configureListPreference(preference, options, options, values, value, listener); configureListPreference(listPreference, options, options, values, value, listener);
} }
@Override /**
protected void onResume() { * Configures the preferred rate list preference.
super.onResume(); *
statsUnits = PreferencesUtils.getString( * @param metricUnits true if metric units
this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT); */
updateUi(); private void configRateListPreference(boolean metricUnits) {
} @SuppressWarnings("deprecation")
ListPreference listPreference = (ListPreference) findPreference(
@SuppressWarnings("deprecation") getString(R.string.stats_rate_key));
private void updateUi() { String value = PreferencesUtils.getString(
CheckBoxPreference reportSpeedCheckBoxPreference = (CheckBoxPreference) findPreference( this, R.string.stats_rate_key, PreferencesUtils.STATS_RATE_DEFAULT);
getString(R.string.report_speed_key)); String[] values = getResources().getStringArray(R.array.stats_rate_values);
boolean metricUnits = PreferencesUtils.STATS_UNITS_DEFAULT.equals(statsUnits); String[] options = getResources().getStringArray(
reportSpeedCheckBoxPreference.setSummaryOn( metricUnits ? R.array.stats_rate_metric_options : R.array.stats_rate_imperial_options);
metricUnits ? getString(R.string.description_speed_metric) configureListPreference(listPreference, options, options, values, value, null);
: getString(R.string.description_speed_imperial));
reportSpeedCheckBoxPreference.setSummaryOff(
metricUnits ? getString(R.string.description_pace_metric)
: getString(R.string.description_pace_imperial));
} }
} }
@@ -91,7 +91,6 @@ public class PreferencesUtils {
public static final long RECORDING_TRACK_ID_DEFAULT = -1L; public static final long RECORDING_TRACK_ID_DEFAULT = -1L;
public static final boolean RECORDING_TRACK_PAUSED_DEFAULT = true; public static final boolean RECORDING_TRACK_PAUSED_DEFAULT = true;
public static final boolean REPORT_SPEED_DEFAULT = true;
public static final long SELECTED_TRACK_ID_DEFAULT = -1L; public static final long SELECTED_TRACK_ID_DEFAULT = -1L;
public static final String SENSOR_TYPE_DEFAULT = "NONE"; public static final String SENSOR_TYPE_DEFAULT = "NONE";
@@ -102,6 +101,7 @@ public class PreferencesUtils {
public static final int SPLIT_FREQUENCY_DEFAULT = 0; public static final int SPLIT_FREQUENCY_DEFAULT = 0;
// Stats // Stats
public static final String STATS_RATE_DEFAULT = "SPEED";
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false; public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false; public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
public static final String STATS_UNITS_DEFAULT = "METRIC"; public static final String STATS_UNITS_DEFAULT = "METRIC";
@@ -257,4 +257,14 @@ public class PreferencesUtils {
return PreferencesUtils.STATS_UNITS_DEFAULT.equals( return PreferencesUtils.STATS_UNITS_DEFAULT.equals(
getString(context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT)); getString(context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT));
} }
/**
* Returns true if the preferred rate is speed, false if the preferred rate is pace.
*
* @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));
}
} }
@@ -50,8 +50,7 @@ public class StatsUtils {
*/ */
public static void setLocationValues(Activity activity, Location location, boolean isRecording) { public static void setLocationValues(Activity activity, Location location, boolean isRecording) {
boolean metricUnits = PreferencesUtils.isMetricUnits(activity); boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
boolean reportSpeed = PreferencesUtils.getBoolean( boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
// Set speed/pace // Set speed/pace
double speed = isRecording && location != null && location.hasSpeed() ? location.getSpeed() double speed = isRecording && location != null && location.hasSpeed() ? location.getSpeed()
@@ -111,8 +110,7 @@ public class StatsUtils {
*/ */
public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) { public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) {
boolean metricUnits = PreferencesUtils.isMetricUnits(activity); boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
boolean reportSpeed = PreferencesUtils.getBoolean( boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
// Set total distance // Set total distance
double totalDistance = tripStatistics == null ? Double.NaN : tripStatistics.getTotalDistance(); double totalDistance = tripStatistics == null ? Double.NaN : tripStatistics.getTotalDistance();
@@ -60,8 +60,7 @@ public class TrackWidgetConfigActivity extends Activity {
item3 = (Spinner) findViewById(R.id.track_widget_config_item3); item3 = (Spinner) findViewById(R.id.track_widget_config_item3);
item4 = (Spinner) findViewById(R.id.track_widget_config_item4); item4 = (Spinner) findViewById(R.id.track_widget_config_item4);
boolean reportSpeed = PreferencesUtils.getBoolean( boolean reportSpeed = PreferencesUtils.isReportSpeed(this);
this, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
List<CharSequence> list = new ArrayList<CharSequence>(); List<CharSequence> list = new ArrayList<CharSequence>();
addItem(list, R.string.stats_distance); addItem(list, R.string.stats_distance);
@@ -196,8 +196,7 @@ public class TrackWidgetProvider extends AppWidgetProvider {
boolean isPaused = PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key, boolean isPaused = PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key,
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT); PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
boolean metricUnits = PreferencesUtils.isMetricUnits(context); boolean metricUnits = PreferencesUtils.isMetricUnits(context);
boolean reportSpeed = PreferencesUtils.getBoolean( boolean reportSpeed = PreferencesUtils.isReportSpeed(context);
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
int item1 = PreferencesUtils.getInt( int item1 = PreferencesUtils.getInt(
context, R.string.track_widget_item1, PreferencesUtils.TRACK_WIDGET_ITEM1_DEFAULT); context, R.string.track_widget_item1, PreferencesUtils.TRACK_WIDGET_ITEM1_DEFAULT);
int item2 = PreferencesUtils.getInt( int item2 = PreferencesUtils.getInt(
@@ -526,7 +526,8 @@ public class TrackDataHubTest extends AndroidTestCase {
public void testPreferencesChange() throws Exception { public void testPreferencesChange() throws Exception {
// Register two listeners // Register two listeners
PreferencesUtils.setBoolean(context, R.string.report_speed_key, true); PreferencesUtils.setString(
context, R.string.stats_rate_key, PreferencesUtils.STATS_RATE_DEFAULT);
PreferencesUtils.setString( PreferencesUtils.setString(
context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT); context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
PreferencesUtils.setInt(context, R.string.recording_gps_accuracy_key, PreferencesUtils.setInt(context, R.string.recording_gps_accuracy_key,
@@ -563,10 +564,11 @@ public class TrackDataHubTest extends AndroidTestCase {
expect(trackDataListener2.onReportSpeedChanged(false)).andReturn(false); expect(trackDataListener2.onReportSpeedChanged(false)).andReturn(false);
replay(); replay();
PreferencesUtils.setBoolean(context, R.string.report_speed_key, false); PreferencesUtils.setString(
context, R.string.stats_rate_key, context.getString(R.string.stats_rate_pace));
OnSharedPreferenceChangeListener listener = preferenceChangeListenerCapture.getValue(); OnSharedPreferenceChangeListener listener = preferenceChangeListenerCapture.getValue();
listener.onSharedPreferenceChanged( listener.onSharedPreferenceChanged(
sharedPreferences, PreferencesUtils.getKey(context, R.string.report_speed_key)); sharedPreferences, PreferencesUtils.getKey(context, R.string.stats_rate_key));
verifyAndReset(); verifyAndReset();
// Change metric units to false // Change metric units to false
@@ -785,14 +787,16 @@ public class TrackDataHubTest extends AndroidTestCase {
* the key is R.string.metric_units_key. * the key is R.string.metric_units_key.
*/ */
public void testNotifyPreferenceChanged_reportSpeedNoNotify() { public void testNotifyPreferenceChanged_reportSpeedNoNotify() {
boolean value = false; String value = context.getString(R.string.stats_rate_pace);
PreferencesUtils.setBoolean(context, R.string.report_speed_key, value); PreferencesUtils.setString(context, R.string.stats_rate_key, value);
trackDataHub.notifyPreferenceChanged(PreferencesUtils trackDataHub.notifyPreferenceChanged(PreferencesUtils
.getKey(context, R.string.report_speed_key)); .getKey(context, R.string.stats_rate_key));
assertEquals(value, trackDataHub.isReportSpeed()); assertEquals(false, trackDataHub.isReportSpeed());
PreferencesUtils.setBoolean(context, R.string.report_speed_key, !value);
value = context.getString(R.string.stats_rate_speed);
PreferencesUtils.setString(context, R.string.stats_rate_key, value);
trackDataHub.notifyPreferenceChanged(PreferencesUtils trackDataHub.notifyPreferenceChanged(PreferencesUtils
.getKey(context, R.string.report_speed_key)); .getKey(context, R.string.stats_rate_key));
assertEquals(!value, trackDataHub.isReportSpeed()); assertEquals(true, trackDataHub.isReportSpeed());
} }
} }