Move Stats settings to StatsSettingsActivity.

This commit is contained in:
Jimmy Shih
2012-05-07 13:38:17 -07:00
parent 77903ed2c9
commit 3461a50288
30 changed files with 320 additions and 368 deletions
+1
View File
@@ -212,6 +212,7 @@ limitations under the License.
<activity android:name="com.google.android.apps.mytracks.settings.SensorSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.SharingSettingsActivity" />
<activity android:name="com.google.android.apps.mytracks.settings.StatsSettingsActivity" />
<!-- Services -->
<service
android:exported="false"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

-56
View File
@@ -1,56 +0,0 @@
<?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.
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ScrollView" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:padding="8dp" >
<TextView
android:text="@string/stats_settings_time"
style="@style/TextLarge" />
<RadioGroup
android:id="@+id/stats_settings_time"
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<RadioButton
android:id="@+id/stats_settings_total_time"
android:text="@string/stats_total_time"
style="@style/TextMedium" />
<RadioButton
android:id="@+id/stats_settings_moving_time"
android:text="@string/stats_moving_time"
style="@style/TextMedium" />
</RadioGroup>
<TextView
android:text="@string/stats_settings_show"
style="@style/TextLarge" />
<CheckBox
android:id="@+id/stats_settings_elevation"
android:text="@string/stats_elevation"
style="@style/TextMedium" />
<CheckBox
android:id="@+id/stats_settings_grade"
android:text="@string/stats_settings_grade"
style="@style/TextMedium" />
<CheckBox
android:id="@+id/stats_settings_coordinate"
android:text="@string/stats_settings_coordinate"
style="@style/TextMedium" />
</LinearLayout>
</ScrollView>
-4
View File
@@ -88,10 +88,6 @@ limitations under the License.
android:icon="@drawable/menu_chart_settings"
android:id="@+id/track_detail_chart_settings"
android:title="@string/menu_chart_settings"/>
<item
android:icon="@drawable/menu_stats_settings"
android:id="@+id/track_detail_stats_settings"
android:title="@string/menu_stats_settings"/>
<item
android:icon="@drawable/menu_settings"
android:id="@+id/track_detail_settings"
+2 -1
View File
@@ -49,7 +49,7 @@ limitations under the License.
<string name="stats_show_coordinate_key">statsShowCoordinate</string>
<string name="stats_show_elevation_key">statsShowElevation</string>
<string name="stats_show_grade_key">statsShowGrade</string>
<string name="stats_show_total_time_key">statsShowTotalTime</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>
@@ -70,5 +70,6 @@ limitations under the License.
<string name="settings_sensor_bluetooth_pairing_key">settingsSensorBluetoothPairing</string>
<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>
+71 -79
View File
@@ -1141,10 +1141,6 @@ limitations under the License.
translation_description="In the menu, to show a marker on map.">
Show on map
</string>
<string name="menu_stats_settings"
translation_description="In the menu, to change the stats settings.">
Stats settings
</string>
<string name="menu_stop_recording"
translation_description="In the menu, to stop recording a track.">
Stop recording
@@ -1213,23 +1209,6 @@ limitations under the License.
write data to My Tracks and start/stop My Tracks recording
</string>
<!-- Preferred Units -->
<string name="preferred_units_imperial"
translation_description="In the dialog asking the user to choose a preferred units, the option
to choose the imperial units.">
Imperial (mi, ft)
</string>
<string name="preferred_units_metric"
translation_description="In the dialog asking the user to choose a preferred units, the option
to choose the metric units.">
Metric (km, m)
</string>
<string name="preferred_units_title"
translation_description="The title of the dialog asking the user to choose a preferred units,
metric or imperial.">
Preferred Units
</string>
<!-- Save All -->
<string name="save_all_error"
translation_description="When saving all the tracks to the SD card, a toast message indicating
@@ -1480,7 +1459,7 @@ limitations under the License.
Sending
</string>
<!-- Settings -->
<!-- Settings Backup -->
<string name="settings_backup"
translation_description="In the 'Settings' page, the option to change the data backup related
settings.
@@ -1541,6 +1520,8 @@ 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.
@@ -1548,41 +1529,6 @@ limitations under the License.
Character limit: ~26 (1 line)">
Display
</string>
<string name="settings_display_metric"
translation_description="In the 'Display' settings, the checkbox option to use the metric units.
Character limit: ~23 (1 line)">
Use metric
</string>
<string name="settings_display_metric_summary_off"
translation_description="In the 'Display' settings, the summary for the 'Use metric'
checkbox when it is unchecked explaining using the imperial units to display distances.">
Use imperial units to display distances.
</string>
<string name="settings_display_metric_summary_on"
translation_description="In the 'Display' settings, the summary for the 'Use metric'
checkbox when it is checked explaining using the metric units to display distances.">
Use metric units to display distances.
</string>
<string name="settings_display_speed"
translation_description="In the 'Display' settings, the checkbox option to display speed (e.g.,
5 miles per hour) instead of pace (e.g., 0.2 hours per mile).
Character limit: ~23 (1 line)">
Display speed
</string>
<string name="settings_display_speed_summary_off"
translation_description="In the 'Display' settings, the summary for the 'Display speed' checkbox
when it is unchecked explaining that pace (e.g., 0.2 hours per mile) will be used instead of
speed (e.g., 5 miles per hour).">
Display pace (e.g., hours/mile).
</string>
<string name="settings_display_speed_summary_on"
translation_description="In the 'Display' settings, the summary for the 'Display speed' checkbox
when it is checked explaining that speed (e.g., 5 miles per hour) will be used instead of pace
(e.g., 0.2 hours per mile).">
Display speed (e.g., miles/hour).
</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.
@@ -1670,6 +1616,8 @@ limitations under the License.
track recording.">
Not available while recording a track.
</string>
<!-- Settings Recording -->
<string name="settings_recording"
translation_description="In the 'Settings' page, the option to change the track recording
related settings.
@@ -1815,6 +1763,8 @@ limitations under the License.
announcements.">
Time/distance between two voice announcements.
</string>
<!-- Settings Reset -->
<string name="settings_reset"
translation_description="In the 'Settings' page, the option to reset everything to the defaults.
@@ -1838,6 +1788,8 @@ limitations under the License.
explaining reverting all the settings to the default values.">
Revert all your settings to the default values.
</string>
<!-- Settings Sensor -->
<string name="settings_sensor"
translation_description="In the 'Settings' page, the option to change the sensor related
settings.
@@ -1961,6 +1913,8 @@ limitations under the License.
Character limit: ~26 (1 line)">
Unpair SRM ANT+ bridge
</string>
<!-- Settings Sharing -->
<string name="settings_sharing"
translation_description="In the 'Settings' page, the option to change the track sharing related
settings.
@@ -2034,6 +1988,66 @@ limitations under the License.
Remove any descriptive text when sharing a URL with friends.
</string>
<!-- Settings Stats -->
<string name="settings_stats_coordinate"
translation_description="In the 'Stats settings, the option to show latitude and longitude.">
Latitude/Longitude
</string>
<string name="settings_stats_grade"
translation_description="In the 'Stats settings, the option to show grade. Grade is the amount
of inclination to the horizontal, also known as slope or incline.">
Grade
</string>
<string name="settings_stats_rate_pace_imperial"
translation_description="In the 'Stats' settings, the option to display pace, with example in
imperial units.">
Pace (hr/mi).
</string>
<string name="settings_stats_rate_pace_metric"
translation_description="In the 'Stats' settings, the option to display pace, with example in
metric units.">
Pace (hr/km).
</string>
<string name="settings_stats_rate_speed_imperial"
translation_description="In the 'Stats' settings, the option to display speed, with example in
imperial units.">
Speed (mi/hr)
</string>
<string name="settings_stats_rate_speed_metric"
translation_description="In the 'Stats' settings, the option to display speed, with example in
metric units.">
Speed (km/hr)
</string>
<string name="settings_stats_rate_title"
translation_description="In the 'Stats' settings, the option to change the preferred rate,
either speed (mi/hr) or pace (hr/mi).">
Preferred Rate
</string>
<string name="settings_stats_show"
translation_description="In the 'Stats' settings, the section label to show additional stats.">
Show
</string>
<string name="settings_stats_time_title"
translation_description="In the 'Stats' settings, the option to change the time measurement,
either total time or moving time.">
Time Measurement
</string>
<string name="settings_stats_units_imperial"
translation_description="In the 'Stats' setttings, the option to use imperial units, with
examples.">
Imperial (mi, ft)
</string>
<string name="settings_stats_units_metric"
translation_description="In the 'Stats' settings, the option to use metric units, with
examples.">
Metric (km, m)
</string>
<string name="settings_stats_units_title"
translation_description="In the 'Stats' settings page, the option to change the preferred units,
either metric (km) or imperial (mi).">
Preferred Units
</string>
<!-- Share Track -->
<string name="share_track_file_body_format"
translation_description="When sharing a track file with friends, the body of the message.">
@@ -2134,28 +2148,6 @@ limitations under the License.
Total time
</string>
<!-- Stats Settings -->
<string name="stats_settings_show"
translation_description="In the 'Stats settings' dialog, the section label to show additional
stats.">
Show
</string>
<string name="stats_settings_grade"
translation_description="In the 'Stats settings' dialog, the option to show grade. Grade is
the amount of inclination to the horizontal, also known as slope or incline.">
Grade
</string>
<string name="stats_settings_coordinate"
translation_description="In the 'Stats settings' dialog, the option to show latitude and
longitude.">
Latitude/Longitude
</string>
<string name="stats_settings_time"
translation_description="In the 'Stats settings' dialog, the section label to choose between
displaying total time or moving time.">
Time
</string>
<!-- Track -->
<string name="track_detail_chart_tab"
translation_description="In the track detail page, the title of the tab showing the chart.">
+4 -15
View File
@@ -19,20 +19,6 @@ limitations under the License.
<!-- Display settings -->
<PreferenceScreen android:title="@string/settings_display">
<CheckBoxPreference
android:key="@string/metric_units_key"
android:title="@string/settings_display_metric"
android:summaryOn="@string/settings_display_metric_summary_on"
android:summaryOff="@string/settings_display_metric_summary_off"
android:defaultValue="true" />
<CheckBoxPreference
android:key="@string/report_speed_key"
android:title="@string/settings_display_speed"
android:summaryOn="@string/settings_display_speed_summary_on"
android:summaryOff="@string/settings_display_speed_summary_off"
android:defaultValue="true" />
<ListPreference android:key="@string/track_color_mode_key"
android:title="@string/settings_display_track_color"
android:summary="@string/settings_display_track_color_summary"
@@ -85,7 +71,10 @@ limitations under the License.
</EditTextPreference>
</PreferenceCategory>
</PreferenceScreen>
<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"
+49
View File
@@ -0,0 +1,49 @@
<?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_stats_tab" >
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/metric_units_key"
android:summaryOff="@string/settings_stats_units_imperial"
android:summaryOn="@string/settings_stats_units_metric"
android:title="@string/settings_stats_units_title" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/report_speed_key"
android:title="@string/settings_stats_rate_title" />
<CheckBoxPreference
android:defaultValue="true"
android:key="@string/stats_use_total_time_key"
android:summaryOff="@string/stats_total_time"
android:summaryOn="@string/stats_moving_time"
android:title="@string/settings_stats_time_title" />
<PreferenceCategory android:title="@string/settings_stats_show" >
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/stats_show_elevation_key"
android:title="@string/stats_elevation" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/stats_show_grade_key"
android:title="@string/settings_stats_grade" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/stats_show_coordinate_key"
android:title="@string/settings_stats_coordinate" />
</PreferenceCategory>
</PreferenceScreen>
@@ -185,7 +185,8 @@ public class SearchListActivity extends AbstractMyTracksActivity {
@Override
protected void onResume() {
super.onResume();
metricUnits = PreferencesUtils.getBoolean(this, R.string.metric_units_key, true);
metricUnits = PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
}
@Override
@@ -27,8 +27,6 @@ import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment;
import com.google.android.apps.mytracks.fragments.MapFragment;
import com.google.android.apps.mytracks.fragments.MarkerAddDialogFragment;
import com.google.android.apps.mytracks.fragments.StatsFragment;
import com.google.android.apps.mytracks.fragments.StatsSettingsDialogFragment;
import com.google.android.apps.mytracks.fragments.StatsSettingsDialogFragment.OnStatsSettingsChangedListener;
import com.google.android.apps.mytracks.io.file.SaveActivity;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
@@ -66,8 +64,7 @@ import java.util.List;
* @author Leif Hendrik Wilden
* @author Rodrigo Damazio
*/
public class TrackDetailActivity extends AbstractMyTracksActivity
implements OnStatsSettingsChangedListener {
public class TrackDetailActivity extends AbstractMyTracksActivity {
public static final String EXTRA_TRACK_ID = "track_id";
public static final String EXTRA_MARKER_ID = "marker_id";
@@ -236,8 +233,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity
String currentTabTag = tabHost.getCurrentTabTag();
menu.findItem(R.id.track_detail_chart_settings).setVisible(
ChartFragment.CHART_FRAGMENT_TAG.equals(currentTabTag));
menu.findItem(R.id.track_detail_stats_settings).setVisible(
StatsFragment.STATS_FRAGMENT_TAG.equals(currentTabTag));
MenuItem satelliteMode = menu.findItem(R.id.track_detail_satellite_mode)
.setVisible(MapFragment.MAP_FRAGMENT_TAG.equals(currentTabTag));
@@ -356,10 +351,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity
new ChartSettingsDialogFragment().show(
getSupportFragmentManager(), ChartSettingsDialogFragment.CHART_SETTINGS_DIALOG_TAG);
return true;
case R.id.track_detail_stats_settings:
new StatsSettingsDialogFragment().show(
getSupportFragmentManager(), StatsSettingsDialogFragment.STATS_SETTINGS_DIALOG_TAG);
return true;
case R.id.track_detail_settings:
intent = IntentUtils.newIntent(this, SettingsActivity.class);
startActivity(intent);
@@ -392,13 +383,6 @@ public class TrackDetailActivity extends AbstractMyTracksActivity
return mapViewContainer;
}
@Override
public void onStatsSettingsChanged() {
StatsFragment statsFragment = (StatsFragment) getSupportFragmentManager()
.findFragmentByTag(StatsFragment.STATS_FRAGMENT_TAG);
statsFragment.updateUi();
}
/**
* Handles the data in the intent.
*/
@@ -120,12 +120,16 @@ public class TrackListActivity extends FragmentActivity {
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
boolean updateList = false;
// Note that key can be null
if (PreferencesUtils.getKey(TrackListActivity.this, R.string.metric_units_key).equals(key)) {
metricUnits = PreferencesUtils.getBoolean(TrackListActivity.this, R.string.metric_units_key, true);
if (PreferencesUtils.getKey(TrackListActivity.this, R.string.metric_units_key)
.equals(key)) {
metricUnits = PreferencesUtils.getBoolean(TrackListActivity.this,
R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
updateList = true;
}
if (PreferencesUtils.getKey(TrackListActivity.this, R.string.recording_track_id_key).equals(key)) {
recordingTrackId = PreferencesUtils.getLong(TrackListActivity.this, R.string.recording_track_id_key);
if (PreferencesUtils.getKey(TrackListActivity.this, R.string.recording_track_id_key)
.equals(key)) {
recordingTrackId = PreferencesUtils.getLong(
TrackListActivity.this, R.string.recording_track_id_key);
if (TrackRecordingServiceConnectionUtils.isRecording(
TrackListActivity.this, trackRecordingServiceConnection)) {
trackRecordingServiceConnection.startAndBind();
@@ -177,7 +181,8 @@ public class TrackListActivity extends FragmentActivity {
SharedPreferences sharedPreferences = getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
metricUnits = PreferencesUtils.getBoolean(this, R.string.metric_units_key, true);
metricUnits = PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);
ImageButton recordImageButton = (ImageButton) findViewById(R.id.track_list_record_button);
@@ -289,8 +289,10 @@ public class TrackDataHub {
private void loadSharedPreferences() {
selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
reportSpeed = PreferencesUtils.getBoolean(context, R.string.report_speed_key, true);
metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
minRequiredAccuracy = PreferencesUtils.getInt(context, R.string.min_required_accuracy_key,
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
}
@@ -607,10 +609,12 @@ public class TrackDataHub {
minRequiredAccuracy = PreferencesUtils.getInt(context, R.string.min_required_accuracy_key,
PreferencesUtils.MIN_REQUIRED_ACCURACY_DEFAULT);
} else if (PreferencesUtils.getKey(context, R.string.metric_units_key).equals(key)) {
metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
notifyUnitsChanged();
} else if (PreferencesUtils.getKey(context, R.string.report_speed_key).equals(key)) {
reportSpeed = PreferencesUtils.getBoolean(context, R.string.report_speed_key, true);
reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
notifySpeedReportingChanged();
} else if (PreferencesUtils.getKey(context, R.string.selected_track_id_key).equals(key)) {
loadTrack(PreferencesUtils.getLong(context, R.string.selected_track_id_key));
@@ -47,8 +47,8 @@ public class CheckUnitsDialogFragment extends DialogFragment {
Locale defaultLocale = Locale.getDefault();
boolean defaultMetric = !defaultLocale.equals(Locale.US) && !defaultLocale.equals(Locale.UK);
PreferencesUtils.setBoolean(getActivity(), R.string.metric_units_key, defaultMetric);
final String metric = getString(R.string.preferred_units_metric);
final String imperial = getString(R.string.preferred_units_imperial);
final String metric = getString(R.string.settings_stats_units_metric);
final String imperial = getString(R.string.settings_stats_units_imperial);
final CharSequence[] items = defaultMetric ? new CharSequence[] { metric, imperial }
: new CharSequence[] { imperial, metric };
return new AlertDialog.Builder(getActivity())
@@ -56,12 +56,13 @@ public class CheckUnitsDialogFragment extends DialogFragment {
@Override
public void onClick(DialogInterface dialog, int which) {
int position = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
PreferencesUtils.setBoolean(getActivity(), R.string.metric_units_key, items[position].equals(metric));
PreferencesUtils.setBoolean(
getActivity(), R.string.metric_units_key, items[position].equals(metric));
onDone();
}
})
.setSingleChoiceItems(items, 0, null)
.setTitle(R.string.preferred_units_title).create();
.setTitle(R.string.settings_stats_units_title).create();
}
/**
@@ -270,8 +270,11 @@ public class StatsFragment extends Fragment implements TrackDataListener {
private synchronized boolean isRecording() {
return trackDataHub != null && trackDataHub.isRecordingSelected();
}
public void updateUi() {
/**
* Updates the UI.
*/
private void updateUi() {
StatsUtils.setTripStatisticsValues(getActivity(), lastTripStatistics);
StatsUtils.setLocationValues(getActivity(), lastLocation, true);
}
@@ -1,96 +0,0 @@
/*
* 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.fragments;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioGroup;
/**
* A DialogFragment to show stats settings.
*
* @author Jimmy Shih
*/
public class StatsSettingsDialogFragment extends DialogFragment {
public static final String STATS_SETTINGS_DIALOG_TAG = "statsSettingsDialog";
public interface OnStatsSettingsChangedListener {
public void onStatsSettingsChanged();
}
private OnStatsSettingsChangedListener listener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
listener = (OnStatsSettingsChangedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnArticleSelectedListener");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.stats_settings, null);
final RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.stats_settings_time);
boolean totalTime = PreferencesUtils.getBoolean(
getActivity(), R.string.stats_show_total_time_key, true);
radioGroup.check(totalTime ? R.id.stats_settings_total_time : R.id.stats_settings_moving_time);
final CheckBox elevation = (CheckBox) view.findViewById(R.id.stats_settings_elevation);
final CheckBox grade = (CheckBox) view.findViewById(R.id.stats_settings_grade);
final CheckBox coordinate = (CheckBox) view.findViewById(R.id.stats_settings_coordinate);
elevation.setChecked(
PreferencesUtils.getBoolean(getActivity(), R.string.stats_show_elevation_key, false));
grade.setChecked(
PreferencesUtils.getBoolean(getActivity(), R.string.stats_show_grade_key, false));
coordinate.setChecked(
PreferencesUtils.getBoolean(getActivity(), R.string.stats_show_coordinate_key, false));
return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PreferencesUtils.setBoolean(getActivity(), R.string.stats_show_total_time_key,
radioGroup.getCheckedRadioButtonId() == R.id.stats_settings_total_time);
PreferencesUtils.setBoolean(
getActivity(), R.string.stats_show_elevation_key, elevation.isChecked());
PreferencesUtils.setBoolean(
getActivity(), R.string.stats_show_grade_key, grade.isChecked());
PreferencesUtils.setBoolean(
getActivity(), R.string.stats_show_coordinate_key, coordinate.isChecked());
listener.onStatsSettingsChanged();
}
})
.setTitle(R.string.menu_stats_settings)
.setView(view)
.create();
}
}
@@ -270,7 +270,8 @@ public class SendDocsUtils {
Track track, String spreadsheetId, String worksheetId, String authToken, Context context)
throws IOException {
String worksheetUri = String.format(GET_WORKSHEET_URI, spreadsheetId, worksheetId);
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
boolean metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
addRow(worksheetUri, getRowContent(track, metricUnits, context), authToken);
}
@@ -205,7 +205,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
private boolean uploadAllTrackPoints(Track track) {
Cursor locationsCursor = null;
try {
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
boolean metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false);
if (locationsCursor == null) {
@@ -255,7 +255,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
boolean uploadAllTrackPoints(Track track) {
Cursor locationsCursor = null;
try {
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
boolean metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false);
if (locationsCursor == null) {
@@ -68,7 +68,8 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
}
}
if (key == null || PreferencesUtils.getKey(service, R.string.metric_units_key).equals(key)) {
service.setMetricUnits(PreferencesUtils.getBoolean(service, R.string.metric_units_key, true));
service.setMetricUnits(PreferencesUtils.getBoolean(
service, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT));
}
if (key == null
|| PreferencesUtils.getKey(service, R.string.announcement_frequency_key).equals(key)) {
@@ -150,9 +150,11 @@ public class StatusAnnouncerTask implements PeriodicTask {
*/
// @VisibleForTesting
protected String getAnnouncement(TripStatistics stats) {
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
boolean reportSpeed = PreferencesUtils.getBoolean(context, R.string.report_speed_key, true);
double d = stats.getTotalDistance() * UnitConversions.M_TO_KM;
boolean metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
boolean reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
double d = stats.getTotalDistance() * UnitConversions.M_TO_KM;
double s = stats.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH;
if (d == 0) {
@@ -52,12 +52,24 @@ public class SettingsActivity extends AbstractSettingsActivity {
private static final int DIALOG_CONFIRM_RESET_ID = 0;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.preferences);
customizeTrackColorModePreferences();
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);
startActivity(intent);
return true;
}
});
Preference recordingPreference = findPreference(getString(R.string.settings_recording_key));
recordingPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@@ -215,7 +227,8 @@ public class SettingsActivity extends AbstractSettingsActivity {
* 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, true)) {
if (PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
return;
}
// Convert miles/h to km/h
@@ -236,7 +249,8 @@ public class SettingsActivity extends AbstractSettingsActivity {
*/
private void validateTrackColorModeSettings(String newValue, int id) {
String metricspeed;
if (PreferencesUtils.getBoolean(this, R.string.metric_units_key, true)) {
if (PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT)) {
metricspeed = newValue;
} else {
// Convert miles/h to km/h
@@ -0,0 +1,82 @@
/*
* 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.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.os.Bundle;
import android.preference.CheckBoxPreference;
/**
* An activity for accessing stats settings.
*
* @author Jimmy Shih
*/
public class StatsSettingsActivity extends AbstractSettingsActivity {
/*
* Note that sharedPreferenceChangeListenr cannot be an anonymous inner class.
* Anonymous inner class will get garbage collected.
*/
private final OnSharedPreferenceChangeListener
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
// Note that key can be null
if (PreferencesUtils.getKey(StatsSettingsActivity.this, R.string.metric_units_key)
.equals(key)) {
updateUi();
}
}
};
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
addPreferencesFromResource(R.xml.stats_settings);
SharedPreferences sharedPreferences = getSharedPreferences(
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
@Override
protected void onResume() {
super.onResume();
updateUi();
}
@SuppressWarnings("deprecation")
private void updateUi() {
CheckBoxPreference reportSpeedCheckBoxPreference = (CheckBoxPreference) findPreference(
getString(R.string.report_speed_key));
boolean metric = PreferencesUtils.getBoolean(
this, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
reportSpeedCheckBoxPreference.setSummaryOn(
metric ? getString(R.string.settings_stats_rate_speed_metric)
: getString(R.string.settings_stats_rate_speed_imperial));
reportSpeedCheckBoxPreference.setSummaryOff(
metric ? getString(R.string.settings_stats_rate_pace_metric)
: getString(R.string.settings_stats_rate_pace_imperial));
}
}
@@ -47,7 +47,8 @@ public class ChartURLGenerator {
*/
public static String getChartUrl(
Vector<Double> distances, Vector<Double> elevations, Track track, Context context) {
boolean metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
boolean metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
return getChartUrl(
distances, elevations, track, context.getString(R.string.stats_elevation), metricUnits);
}
@@ -57,11 +57,17 @@ public class PreferencesUtils {
public static final int MIN_REQUIRED_ACCURACY_POOR = 5000;
public static final int PERIODIC_TASK_OFF = 0;
public static final long RECORDING_TRACK_ID_DEFAULT = -1L;
public static final boolean REPORT_SPEED_DEFAULT = true;
public static final boolean SHARE_URL_ONLY_DEFAULT = false;
public static final int SPLIT_FREQUENCY_DEFAULT = 0;
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
public static final boolean STATS_SHOW_ELEVATION_DEFAULT = false;
public static final boolean STATS_SHOW_GRADE_DEFAULT = false;
public static final boolean STATS_USE_TOTAL_TIME_DEFAULT = true;
private PreferencesUtils() {}
/**
@@ -42,12 +42,14 @@ public class StatsUtils {
* elevation field
*/
public static void setLocationValues(Activity activity, Location location, boolean showAll) {
boolean metricUnits = PreferencesUtils.getBoolean(activity, R.string.metric_units_key, true);
boolean reportSpeed = PreferencesUtils.getBoolean(activity, R.string.report_speed_key, true);
boolean metricUnits = PreferencesUtils.getBoolean(
activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
boolean reportSpeed = PreferencesUtils.getBoolean(
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
// Set elevation
boolean showElevation = PreferencesUtils.getBoolean(
activity, R.string.stats_show_elevation_key, false);
activity, R.string.stats_show_elevation_key, PreferencesUtils.STATS_SHOW_ELEVATION_DEFAULT);
if (showElevation) {
double altitude = location == null ? Double.NaN : location.getAltitude();
setElevationValue(activity, R.id.stats_elevation_value, altitude, metricUnits);
@@ -64,8 +66,8 @@ public class StatsUtils {
setSpeedValue(activity, R.id.stats_speed_value, speed, metricUnits, reportSpeed);
// Set coordinate
boolean showCoordinate = PreferencesUtils.getBoolean(
activity, R.string.stats_show_coordinate_key, false);
boolean showCoordinate = PreferencesUtils.getBoolean(activity,
R.string.stats_show_coordinate_key, PreferencesUtils.STATS_SHOW_COORDINATE_DEFAULT);
View coordinateLabelTableRow = activity.findViewById(R.id.stats_coordinate_label_table_row);
View coordinateValueTableRow = activity.findViewById(R.id.stats_coordinate_value_table_row);
coordinateLabelTableRow.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
@@ -95,10 +97,12 @@ public class StatsUtils {
* @param tripStatistics the trip statistics
*/
public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) {
boolean metricUnits = PreferencesUtils.getBoolean(activity, R.string.metric_units_key, true);
boolean reportSpeed = PreferencesUtils.getBoolean(activity, R.string.report_speed_key, true);
boolean showTotalTime = PreferencesUtils.getBoolean(
activity, R.string.stats_show_total_time_key, true);
boolean metricUnits = PreferencesUtils.getBoolean(
activity, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
boolean reportSpeed = PreferencesUtils.getBoolean(
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
boolean useTotalTime = PreferencesUtils.getBoolean(
activity, R.string.stats_use_total_time_key, PreferencesUtils.STATS_USE_TOTAL_TIME_DEFAULT);
// Set total distance
double totalDistance = tripStatistics == null ? Double.NaN : tripStatistics.getTotalDistance();
@@ -106,17 +110,17 @@ public class StatsUtils {
// Set total time/moving time
setTimeLabel(activity, R.id.stats_total_time_label, R.string.stats_total_time,
R.string.stats_moving_time, showTotalTime);
R.string.stats_moving_time, useTotalTime);
long totalTime;
if (tripStatistics == null) {
totalTime = -1L;
} else {
totalTime = showTotalTime ? tripStatistics.getTotalTime() : tripStatistics.getMovingTime();
totalTime = useTotalTime ? tripStatistics.getTotalTime() : tripStatistics.getMovingTime();
}
setTimeValue(activity, R.id.stats_total_time_value, totalTime);
// Set average speed/moving average speed
if (showTotalTime) {
if (useTotalTime) {
setSpeedLabel(activity, R.id.stats_average_speed_label, R.string.stats_average_speed,
R.string.stats_average_pace, reportSpeed);
} else {
@@ -127,7 +131,7 @@ public class StatsUtils {
if (tripStatistics == null) {
averageSpeed = Double.NaN;
} else {
averageSpeed = showTotalTime ? tripStatistics.getAverageSpeed()
averageSpeed = useTotalTime ? tripStatistics.getAverageSpeed()
: tripStatistics.getAverageMovingSpeed();
}
setSpeedValue(activity, R.id.stats_average_speed_value, averageSpeed, metricUnits, reportSpeed);
@@ -140,7 +144,7 @@ public class StatsUtils {
// Set elevation
boolean showElevation = PreferencesUtils.getBoolean(
activity, R.string.stats_show_elevation_key, false);
activity, R.string.stats_show_elevation_key, PreferencesUtils.STATS_SHOW_ELEVATION_DEFAULT);
View elevationLabelTableRow1 = activity.findViewById(R.id.stats_elevation_label_table_row1);
View elevationValueTableRow1 = activity.findViewById(R.id.stats_elevation_value_table_row1);
View elevationLabelTableRow2 = activity.findViewById(R.id.stats_elevation_label_table_row2);
@@ -160,7 +164,8 @@ public class StatsUtils {
}
// Set grade
boolean showGrade = PreferencesUtils.getBoolean(activity, R.string.stats_show_grade_key, false);
boolean showGrade = PreferencesUtils.getBoolean(
activity, R.string.stats_show_grade_key, PreferencesUtils.STATS_SHOW_GRADE_DEFAULT);
View gradeLabelTableRow = activity.findViewById(R.id.stats_grade_label_table_row);
View gradeValueTableRow = activity.findViewById(R.id.stats_grade_value_table_row);
gradeLabelTableRow.setVisibility(showGrade ? View.VISIBLE : View.GONE);
@@ -230,15 +230,16 @@ public class TrackWidgetProvider
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.metric_units_key))) {
metricUnits = PreferencesUtils.getBoolean(context, R.string.metric_units_key, true);
if (key == null || PreferencesUtils.getKey(context, R.string.metric_units_key).equals(key)) {
metricUnits = PreferencesUtils.getBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
}
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.report_speed_key))) {
reportSpeed = PreferencesUtils.getBoolean(context, R.string.report_speed_key, true);
if (key == null || PreferencesUtils.getKey(context, R.string.report_speed_key).equals(key)) {
reportSpeed = PreferencesUtils.getBoolean(
context, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
}
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.selected_track_id_key))) {
if (key == null
|| PreferencesUtils.getKey(context, R.string.selected_track_id_key).equals(key)) {
selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
Log.d(TAG, "TrackWidgetProvider setting selecting track from preference: " + selectedTrackId);
}
@@ -798,13 +798,8 @@ public class TrackDataHubTest extends AndroidTestCase {
}
public void testDisplayPreferencesListen() throws Exception {
String metricUnitsKey = PreferencesUtils.getKey(context, R.string.metric_units_key);
String reportSpeedKey = PreferencesUtils.getKey(context, R.string.report_speed_key);
prefs.edit()
.putBoolean(metricUnitsKey, true)
.putBoolean(reportSpeedKey, true)
.apply();
PreferencesUtils.setBoolean(context, R.string.report_speed_key, true);
PreferencesUtils.setBoolean(context, R.string.metric_units_key, true);
Capture<OnSharedPreferenceChangeListener> listenerCapture =
new Capture<OnSharedPreferenceChangeListener>();
@@ -828,11 +823,10 @@ public class TrackDataHubTest extends AndroidTestCase {
replay();
prefs.edit()
.putBoolean(reportSpeedKey, false)
.apply();
PreferencesUtils.setBoolean(context, R.string.report_speed_key, false);
OnSharedPreferenceChangeListener listener = listenerCapture.getValue();
listener.onSharedPreferenceChanged(prefs, reportSpeedKey);
listener.onSharedPreferenceChanged(
prefs, PreferencesUtils.getKey(context, R.string.report_speed_key));
AndroidMock.verify(dataSources, providerUtils, listener1, listener2);
AndroidMock.reset(dataSources, providerUtils, listener1, listener2);
@@ -842,10 +836,9 @@ public class TrackDataHubTest extends AndroidTestCase {
replay();
prefs.edit()
.putBoolean(metricUnitsKey, false)
.apply();
listener.onSharedPreferenceChanged(prefs, metricUnitsKey);
PreferencesUtils.setBoolean(context, R.string.metric_units_key, false);
listener.onSharedPreferenceChanged(
prefs, PreferencesUtils.getKey(context, R.string.metric_units_key));
verifyAndReset();
}
@@ -34,7 +34,6 @@ import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.location.Location;
import android.net.Uri;
@@ -606,18 +605,16 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
}
@MediumTest
public void testWithProperties_noMetricUnits() throws Exception {
functionalTest(R.string.metric_units_key, (Object) null);
}
@MediumTest
public void testWithProperties_metricUnitsEnabled() throws Exception {
functionalTest(R.string.metric_units_key, true);
public void testWithProperties_metricUnitsDefault() throws Exception {
PreferencesUtils.setBoolean(
context, R.string.metric_units_key, PreferencesUtils.METRIC_UNITS_DEFAULT);
fullRecordingSession();
}
@MediumTest
public void testWithProperties_metricUnitsDisabled() throws Exception {
functionalTest(R.string.metric_units_key, false);
PreferencesUtils.setBoolean(context, R.string.metric_units_key, false);
fullRecordingSession();
}
@MediumTest
@@ -696,33 +693,6 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
PreferencesUtils.setLong(context, R.string.recording_track_id_key, isRecording ? track.getId() : -1L);
}
// TODO: We support multiple values for readability, however this test's
// base class doesn't properly shutdown the service, so it's not possible
// to pass more than 1 value at a time.
private void functionalTest(int resourceId, Object ...values)
throws Exception {
final String key = context.getString(resourceId);
for (Object value : values) {
// Remove all properties and set the property for the given key.
Editor editor = sharedPreferences.edit();
editor.clear();
if (value instanceof String) {
editor.putString(key, (String) value);
} else if (value instanceof Long) {
editor.putLong(key, (Long) value);
} else if (value instanceof Integer) {
editor.putInt(key, (Integer) value);
} else if (value instanceof Boolean) {
editor.putBoolean(key, (Boolean) value);
} else if (value == null) {
// Do nothing, as clear above has already removed this property.
}
editor.apply();
fullRecordingSession();
}
}
private void fullRecordingSession() throws Exception {
ITrackRecordingService service = bindAndGetService(createStartIntent());
assertFalse(service.isRecording());