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_none</item>
</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">
<item>@string/settings_stats_units_metric</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_location_value">LOCATION</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_metric">METRIC</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="recording_distance_interval_key">recordingDistanceInterval</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="share_track_invite_key">shareTrackInvite</string>
<string name="share_track_public_key">shareTrackPublic</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_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_percentage_key">trackColorModePercentage</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:key="@string/stats_units_key"
android:title="@string/settings_stats_units_title" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/report_speed_key"
<ListPreference
android:defaultValue="@string/stats_rate_speed"
android:key="@string/stats_rate_key"
android:title="@string/settings_stats_rate_title" />
<PreferenceCategory android:title="@string/settings_show" >
<CheckBoxPreference
@@ -282,9 +282,8 @@ public class TrackDataHub implements DataSourceListener {
}
}
if (key == null
|| key.equals(PreferencesUtils.getKey(context, R.string.report_speed_key))) {
reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|| key.equals(PreferencesUtils.getKey(context, R.string.stats_rate_key))) {
reportSpeed = PreferencesUtils.isReportSpeed(context);
if (key != null) {
for (TrackDataListener trackDataListener :
trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
@@ -65,7 +65,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
private long startTime;
private boolean metricUnits = true;
private boolean reportSpeed = PreferencesUtils.REPORT_SPEED_DEFAULT;
private boolean reportSpeed = true;
private int recordingDistanceInterval = PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT;
// Modes of operation
@@ -228,8 +228,7 @@ public class AnnouncementPeriodicTask implements PeriodicTask {
@VisibleForTesting
protected String getAnnouncement(TripStatistics tripStatistics) {
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
boolean reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
boolean reportSpeed = PreferencesUtils.isReportSpeed(context);
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
double speed = tripStatistics.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH;
@@ -46,8 +46,7 @@ public class ChartSettingsActivity extends AbstractSettingsActivity {
private void updateUi() {
CheckBoxPreference speedCheckBoxPreference = (CheckBoxPreference) findPreference(
getString(R.string.chart_show_speed_key));
boolean reportSpeed = PreferencesUtils.getBoolean(
this, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
boolean reportSpeed = PreferencesUtils.isReportSpeed(this);
speedCheckBoxPreference.setTitle(reportSpeed ? R.string.stats_speed
: R.string.stats_pace);
}
@@ -20,7 +20,6 @@ import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
@@ -32,21 +31,30 @@ import android.preference.Preference.OnPreferenceChangeListener;
*/
public class StatsSettingsActivity extends AbstractSettingsActivity {
private String statsUnits;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
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));
OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
statsUnits = (String) newValue;
updateUi();
configRateListPreference(PreferencesUtils.STATS_UNITS_DEFAULT.equals((String) newValue));
return true;
}
};
@@ -54,27 +62,23 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
String[] values = getResources().getStringArray(R.array.stats_units_values);
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() {
super.onResume();
statsUnits = PreferencesUtils.getString(
this, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
updateUi();
}
@SuppressWarnings("deprecation")
private void updateUi() {
CheckBoxPreference reportSpeedCheckBoxPreference = (CheckBoxPreference) findPreference(
getString(R.string.report_speed_key));
boolean metricUnits = PreferencesUtils.STATS_UNITS_DEFAULT.equals(statsUnits);
reportSpeedCheckBoxPreference.setSummaryOn(
metricUnits ? getString(R.string.description_speed_metric)
: getString(R.string.description_speed_imperial));
reportSpeedCheckBoxPreference.setSummaryOff(
metricUnits ? getString(R.string.description_pace_metric)
: getString(R.string.description_pace_imperial));
/**
* Configures the preferred rate list preference.
*
* @param metricUnits true if metric units
*/
private void configRateListPreference(boolean metricUnits) {
@SuppressWarnings("deprecation")
ListPreference listPreference = (ListPreference) findPreference(
getString(R.string.stats_rate_key));
String value = PreferencesUtils.getString(
this, R.string.stats_rate_key, PreferencesUtils.STATS_RATE_DEFAULT);
String[] values = getResources().getStringArray(R.array.stats_rate_values);
String[] options = getResources().getStringArray(
metricUnits ? R.array.stats_rate_metric_options : R.array.stats_rate_imperial_options);
configureListPreference(listPreference, options, options, values, value, null);
}
}
@@ -91,7 +91,6 @@ public class PreferencesUtils {
public static final long RECORDING_TRACK_ID_DEFAULT = -1L;
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 String SENSOR_TYPE_DEFAULT = "NONE";
@@ -102,6 +101,7 @@ public class PreferencesUtils {
public static final int SPLIT_FREQUENCY_DEFAULT = 0;
// Stats
public static final String STATS_RATE_DEFAULT = "SPEED";
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
public static final String STATS_UNITS_DEFAULT = "METRIC";
@@ -257,4 +257,14 @@ public class PreferencesUtils {
return PreferencesUtils.STATS_UNITS_DEFAULT.equals(
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) {
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
boolean reportSpeed = PreferencesUtils.getBoolean(
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
// Set speed/pace
double speed = isRecording && location != null && location.hasSpeed() ? location.getSpeed()
@@ -111,8 +110,7 @@ public class StatsUtils {
*/
public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) {
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
boolean reportSpeed = PreferencesUtils.getBoolean(
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
// Set total distance
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);
item4 = (Spinner) findViewById(R.id.track_widget_config_item4);
boolean reportSpeed = PreferencesUtils.getBoolean(
this, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
boolean reportSpeed = PreferencesUtils.isReportSpeed(this);
List<CharSequence> list = new ArrayList<CharSequence>();
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,
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
boolean metricUnits = PreferencesUtils.isMetricUnits(context);
boolean reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
boolean reportSpeed = PreferencesUtils.isReportSpeed(context);
int item1 = PreferencesUtils.getInt(
context, R.string.track_widget_item1, PreferencesUtils.TRACK_WIDGET_ITEM1_DEFAULT);
int item2 = PreferencesUtils.getInt(
@@ -526,7 +526,8 @@ public class TrackDataHubTest extends AndroidTestCase {
public void testPreferencesChange() throws Exception {
// 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(
context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
PreferencesUtils.setInt(context, R.string.recording_gps_accuracy_key,
@@ -563,10 +564,11 @@ public class TrackDataHubTest extends AndroidTestCase {
expect(trackDataListener2.onReportSpeedChanged(false)).andReturn(false);
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();
listener.onSharedPreferenceChanged(
sharedPreferences, PreferencesUtils.getKey(context, R.string.report_speed_key));
sharedPreferences, PreferencesUtils.getKey(context, R.string.stats_rate_key));
verifyAndReset();
// Change metric units to false
@@ -785,14 +787,16 @@ public class TrackDataHubTest extends AndroidTestCase {
* the key is R.string.metric_units_key.
*/
public void testNotifyPreferenceChanged_reportSpeedNoNotify() {
boolean value = false;
PreferencesUtils.setBoolean(context, R.string.report_speed_key, value);
String value = context.getString(R.string.stats_rate_pace);
PreferencesUtils.setString(context, R.string.stats_rate_key, value);
trackDataHub.notifyPreferenceChanged(PreferencesUtils
.getKey(context, R.string.report_speed_key));
assertEquals(value, trackDataHub.isReportSpeed());
PreferencesUtils.setBoolean(context, R.string.report_speed_key, !value);
.getKey(context, R.string.stats_rate_key));
assertEquals(false, trackDataHub.isReportSpeed());
value = context.getString(R.string.stats_rate_speed);
PreferencesUtils.setString(context, R.string.stats_rate_key, value);
trackDataHub.notifyPreferenceChanged(PreferencesUtils
.getKey(context, R.string.report_speed_key));
assertEquals(!value, trackDataHub.isReportSpeed());
.getKey(context, R.string.stats_rate_key));
assertEquals(true, trackDataHub.isReportSpeed());
}
}