forked from upstream-mirrors/OpenTracks
Move Stats settings to StatsSettingsActivity.
This commit is contained in:
@@ -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));
|
||||
|
||||
+5
-4
@@ -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);
|
||||
}
|
||||
|
||||
-96
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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)) {
|
||||
|
||||
+5
-3
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user