mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Add stats settings to configure the stats page.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -34,8 +34,7 @@ limitations under the License.
|
||||
style="@style/StatsValue" />
|
||||
</TableRow>
|
||||
<include layout="@layout/stats_core" />
|
||||
<!-- Latitude and longitude -->
|
||||
<TableRow>
|
||||
<TableRow android:id="@+id/stats_coordinate_label_table_row" >
|
||||
<TextView
|
||||
android:text="@string/stats_latitude"
|
||||
style="@style/StatsLabel" />
|
||||
@@ -44,7 +43,7 @@ limitations under the License.
|
||||
android:text="@string/stats_longitude"
|
||||
style="@style/StatsLabel" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TableRow android:id="@+id/stats_coordinate_value_table_row" >
|
||||
<TextView
|
||||
android:id="@+id/stats_latitude_value"
|
||||
style="@style/StatsValue" />
|
||||
|
||||
@@ -15,11 +15,33 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<!-- Total distance and max speed (fastest pace) -->
|
||||
<!-- Total distance -->
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:text="@string/stats_total_distance"
|
||||
style="@style/StatsLabel" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:id="@+id/stats_total_distance_value"
|
||||
style="@style/StatsValue" />
|
||||
</TableRow>
|
||||
<!-- Total time/moving time -->
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:id="@+id/stats_total_time_label"
|
||||
style="@style/StatsLabel" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:id="@+id/stats_total_time_value"
|
||||
style="@style/StatsValue" />
|
||||
</TableRow>
|
||||
<!-- Average speed/average moving speed and max speed (average pace/average moving pace and fastest pace) -->
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:id="@+id/stats_average_speed_label"
|
||||
style="@style/StatsLabel" />
|
||||
<TextView
|
||||
android:id="@+id/stats_max_speed_label"
|
||||
android:layout_column="2"
|
||||
@@ -27,53 +49,15 @@ limitations under the License.
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:id="@+id/stats_total_distance_value"
|
||||
android:id="@+id/stats_average_speed_value"
|
||||
style="@style/StatsValue" />
|
||||
<TextView style="@style/StatsSpacer" />
|
||||
<TextView
|
||||
android:id="@+id/stats_max_speed_value"
|
||||
style="@style/StatsValue" />
|
||||
</TableRow>
|
||||
<!-- Total time and average speed (average pace) -->
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:text="@string/stats_total_time"
|
||||
style="@style/StatsLabel" />
|
||||
<TextView
|
||||
android:id="@+id/stats_average_speed_label"
|
||||
android:layout_column="2"
|
||||
style="@style/StatsLabel" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:id="@+id/stats_total_time_value"
|
||||
style="@style/StatsValue" />
|
||||
<TextView style="@style/StatsSpacer" />
|
||||
<TextView
|
||||
android:id="@+id/stats_average_speed_value"
|
||||
style="@style/StatsValue" />
|
||||
</TableRow>
|
||||
<!-- Moving time and average moving speed (average moving pace) -->
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:text="@string/stats_moving_time"
|
||||
style="@style/StatsLabel" />
|
||||
<TextView
|
||||
android:id="@+id/stats_average_moving_speed_label"
|
||||
android:layout_column="2"
|
||||
style="@style/StatsLabel" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:id="@+id/stats_moving_time_value"
|
||||
style="@style/StatsValue" />
|
||||
<TextView style="@style/StatsSpacer" />
|
||||
<TextView
|
||||
android:id="@+id/stats_average_moving_speed_value"
|
||||
style="@style/StatsValue" />
|
||||
</TableRow>
|
||||
<!-- Elevation and elevation gain -->
|
||||
<TableRow>
|
||||
<TableRow android:id="@+id/stats_elevation_label_table_row1" >
|
||||
<TextView
|
||||
android:text="@string/stats_elevation"
|
||||
style="@style/StatsLabel" />
|
||||
@@ -82,7 +66,7 @@ limitations under the License.
|
||||
android:text="@string/stats_elevation_gain"
|
||||
style="@style/StatsLabel" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TableRow android:id="@+id/stats_elevation_value_table_row1" >
|
||||
<TextView
|
||||
android:id="@+id/stats_elevation_value"
|
||||
style="@style/StatsValue" />
|
||||
@@ -92,7 +76,7 @@ limitations under the License.
|
||||
style="@style/StatsValue" />
|
||||
</TableRow>
|
||||
<!-- Min and max elevation -->
|
||||
<TableRow>
|
||||
<TableRow android:id="@+id/stats_elevation_label_table_row2" >
|
||||
<TextView
|
||||
android:text="@string/stats_min_elevation"
|
||||
style="@style/StatsLabel" />
|
||||
@@ -101,7 +85,7 @@ limitations under the License.
|
||||
android:text="@string/stats_max_elevation"
|
||||
style="@style/StatsLabel" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TableRow android:id="@+id/stats_elevation_value_table_row2" >
|
||||
<TextView
|
||||
android:id="@+id/stats_min_elevation_value"
|
||||
style="@style/StatsValue" />
|
||||
@@ -111,7 +95,7 @@ limitations under the License.
|
||||
style="@style/StatsValue" />
|
||||
</TableRow>
|
||||
<!-- Min and max grade -->
|
||||
<TableRow>
|
||||
<TableRow android:id="@+id/stats_grade_label_table_row" >
|
||||
<TextView
|
||||
android:text="@string/stats_min_grade"
|
||||
style="@style/StatsLabel" />
|
||||
@@ -120,7 +104,7 @@ limitations under the License.
|
||||
android:text="@string/stats_max_grade"
|
||||
style="@style/StatsLabel" />
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
<TableRow android:id="@+id/stats_grade_value_table_row" >
|
||||
<TextView
|
||||
android:id="@+id/stats_min_grade_value"
|
||||
style="@style/StatsValue" />
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?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>
|
||||
@@ -92,6 +92,10 @@ 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"
|
||||
|
||||
@@ -48,6 +48,10 @@ limitations under the License.
|
||||
<string name="show_check_units_dialog_key">showCheckUnitsDialog</string>
|
||||
<string name="show_welcome_dialog_key">showWelcomeDialog</string>
|
||||
<string name="split_frequency_key">splitFrequency</string>
|
||||
<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="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>
|
||||
|
||||
@@ -1144,6 +1144,10 @@ limitations under the License.
|
||||
<string name="menu_show_on_map"
|
||||
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.">
|
||||
@@ -2140,6 +2144,28 @@ 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.">
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.google.android.apps.mytracks;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.StatsUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -38,17 +37,8 @@ public class AggregatedStatsActivity extends AbstractMyTracksActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.aggregated_stats);
|
||||
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(this);
|
||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(this);
|
||||
|
||||
StatsUtils.setStats(this,
|
||||
getTripStatistics(),
|
||||
null,
|
||||
Double.NaN,
|
||||
metricUnits,
|
||||
reportSpeed,
|
||||
false);
|
||||
StatsUtils.setTripStatisticsValues(this, getTripStatistics());
|
||||
StatsUtils.setLocationValues(this, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.StatsUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -82,17 +81,8 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity {
|
||||
} else {
|
||||
waypointSection.setVisibility(View.GONE);
|
||||
statisticsSection.setVisibility(View.VISIBLE);
|
||||
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(this);
|
||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(this);
|
||||
|
||||
StatsUtils.setStats(this,
|
||||
waypoint.getStatistics(),
|
||||
null,
|
||||
waypoint.getLocation().getAltitude(),
|
||||
metricUnits,
|
||||
reportSpeed,
|
||||
false);
|
||||
StatsUtils.setTripStatisticsValues(this, waypoint.getStatistics());
|
||||
StatsUtils.setLocationValues(this, waypoint.getLocation(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ 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;
|
||||
@@ -63,7 +65,8 @@ import java.util.List;
|
||||
* @author Leif Hendrik Wilden
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class TrackDetailActivity extends AbstractMyTracksActivity {
|
||||
public class TrackDetailActivity extends AbstractMyTracksActivity
|
||||
implements OnStatsSettingsChangedListener {
|
||||
|
||||
public static final String EXTRA_TRACK_ID = "track_id";
|
||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||
@@ -233,6 +236,8 @@ 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));
|
||||
menu.findItem(R.id.track_detail_my_location)
|
||||
.setVisible(MapFragment.MAP_FRAGMENT_TAG.equals(currentTabTag));
|
||||
MenuItem satelliteMode = menu.findItem(R.id.track_detail_satellite_mode)
|
||||
@@ -352,13 +357,17 @@ public class TrackDetailActivity extends AbstractMyTracksActivity {
|
||||
mapFragment.setSatelliteView(!mapFragment.isSatelliteView());
|
||||
}
|
||||
return true;
|
||||
case R.id.track_detail_sensor_state:
|
||||
intent = IntentUtils.newIntent(this, SensorStateActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.track_detail_chart_settings:
|
||||
new ChartSettingsDialogFragment().show(
|
||||
getSupportFragmentManager(), ChartSettingsDialogFragment.CHART_SETTINGS_DIALOG_TAG);
|
||||
return true;
|
||||
case R.id.track_detail_sensor_state:
|
||||
intent = IntentUtils.newIntent(this, SensorStateActivity.class);
|
||||
startActivity(intent);
|
||||
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);
|
||||
@@ -392,6 +401,13 @@ 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.
|
||||
*/
|
||||
|
||||
@@ -55,8 +55,6 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
// The start time of the current track.
|
||||
private long startTime = -1L;
|
||||
|
||||
private boolean metricUnits = true;
|
||||
private boolean reportSpeed = true;
|
||||
private Location lastLocation = null;
|
||||
private TripStatistics lastTripStatistics = null;
|
||||
|
||||
@@ -98,8 +96,6 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
metricUnits = PreferencesUtils.isMetricUnits(getActivity());
|
||||
reportSpeed = PreferencesUtils.isReportSpeed(getActivity());
|
||||
updateUi();
|
||||
}
|
||||
|
||||
@@ -126,7 +122,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
@Override
|
||||
public void run() {
|
||||
lastLocation = null;
|
||||
StatsUtils.setLocationValues(getActivity(), lastLocation, metricUnits, reportSpeed);
|
||||
StatsUtils.setLocationValues(getActivity(), lastLocation, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -139,7 +135,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
@Override
|
||||
public void run() {
|
||||
lastLocation = location;
|
||||
StatsUtils.setLocationValues(getActivity(), lastLocation, metricUnits, reportSpeed);
|
||||
StatsUtils.setLocationValues(getActivity(), lastLocation, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -228,7 +224,6 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
metricUnits = metric;
|
||||
updateUi();
|
||||
}
|
||||
});
|
||||
@@ -240,7 +235,6 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
reportSpeed = speed;
|
||||
updateUi();
|
||||
}
|
||||
});
|
||||
@@ -277,13 +271,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
return trackDataHub != null && trackDataHub.isRecordingSelected();
|
||||
}
|
||||
|
||||
private void updateUi() {
|
||||
StatsUtils.setStats(getActivity(),
|
||||
lastTripStatistics,
|
||||
lastLocation,
|
||||
Double.NaN,
|
||||
metricUnits,
|
||||
reportSpeed,
|
||||
true);
|
||||
public void updateUi() {
|
||||
StatsUtils.setTripStatisticsValues(getActivity(), lastTripStatistics);
|
||||
StatsUtils.setLocationValues(getActivity(), lastLocation, true);
|
||||
}
|
||||
}
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.location.Location;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
@@ -32,51 +33,49 @@ public class StatsUtils {
|
||||
|
||||
private StatsUtils() {}
|
||||
|
||||
/**
|
||||
* Sets stats.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param tripStatistics the trip statistics
|
||||
* @param location the location, needed when showAll is true
|
||||
* @param elevation the elevation, needed when showAll is false
|
||||
* @param metricUnits true to display in metric units
|
||||
* @param reportSpeed true to report speed
|
||||
* @param showAll true to display all fields
|
||||
*/
|
||||
public static void setStats(Activity activity,
|
||||
TripStatistics tripStatistics,
|
||||
Location location,
|
||||
double elevation,
|
||||
boolean metricUnits,
|
||||
boolean reportSpeed,
|
||||
boolean showAll) {
|
||||
setSpeedLabels(activity, reportSpeed, showAll);
|
||||
setTripStatisticsValues(activity, tripStatistics, metricUnits, reportSpeed);
|
||||
if (showAll) {
|
||||
setLocationValues(activity, location, metricUnits, reportSpeed);
|
||||
} else {
|
||||
setAltitudeValue(activity, R.id.stats_elevation_value, elevation, metricUnits);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sets the location values.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param location the location
|
||||
* @param metricUnits true to display in metric units
|
||||
* @param reportSpeed true to report speed
|
||||
* @param showAll true to show all the fields, false to show only the
|
||||
* elevation field
|
||||
*/
|
||||
public static void setLocationValues(
|
||||
Activity activity, Location location, boolean metricUnits, boolean reportSpeed) {
|
||||
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);
|
||||
|
||||
// Set elevation
|
||||
boolean showElevation = PreferencesUtils.getBoolean(
|
||||
activity, R.string.stats_show_elevation_key, false);
|
||||
if (showElevation) {
|
||||
double altitude = location == null ? Double.NaN : location.getAltitude();
|
||||
setElevationValue(activity, R.id.stats_elevation_value, altitude, metricUnits);
|
||||
}
|
||||
|
||||
if (!showAll) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set speed/pace
|
||||
setSpeedLabel(
|
||||
activity, R.id.stats_speed_label, R.string.stats_speed, R.string.stats_pace, reportSpeed);
|
||||
double speed = location == null ? Double.NaN : location.getSpeed();
|
||||
double altitude = location == null ? Double.NaN : location.getAltitude();
|
||||
double latitude = location == null ? Double.NaN : location.getLatitude();
|
||||
double longitude = location == null ? Double.NaN : location.getLongitude();
|
||||
|
||||
setSpeedValue(activity, R.id.stats_speed_value, speed, metricUnits, reportSpeed);
|
||||
setAltitudeValue(activity, R.id.stats_elevation_value, altitude, metricUnits);
|
||||
setCoordinateValue(activity, R.id.stats_latitude_value, latitude);
|
||||
setCoordinateValue(activity, R.id.stats_longitude_value, longitude);
|
||||
|
||||
// Set coordinate
|
||||
boolean showCoordinate = PreferencesUtils.getBoolean(
|
||||
activity, R.string.stats_show_coordinate_key, false);
|
||||
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);
|
||||
coordinateValueTableRow.setVisibility(showCoordinate ? View.VISIBLE : View.GONE);
|
||||
if (showCoordinate) {
|
||||
double latitude = location == null ? Double.NaN : location.getLatitude();
|
||||
double longitude = location == null ? Double.NaN : location.getLongitude();
|
||||
setCoordinateValue(activity, R.id.stats_latitude_value, latitude);
|
||||
setCoordinateValue(activity, R.id.stats_longitude_value, longitude);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,63 +88,104 @@ public class StatsUtils {
|
||||
setTimeValue(activity, R.id.stats_total_time_value, totalTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the speed labels.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param reportSpeed true to report speed
|
||||
* @param includeLocationSpeed true to include the current location speed
|
||||
*/
|
||||
private static void setSpeedLabels(
|
||||
Activity activity, boolean reportSpeed, boolean includeLocationSpeed) {
|
||||
setSpeedLabel(activity, R.id.stats_max_speed_label, R.string.stats_max_speed,
|
||||
R.string.stats_fastest_pace, reportSpeed);
|
||||
setSpeedLabel(activity, R.id.stats_average_speed_label, R.string.stats_average_speed,
|
||||
R.string.stats_average_pace, reportSpeed);
|
||||
setSpeedLabel(activity, R.id.stats_average_moving_speed_label,
|
||||
R.string.stats_average_moving_speed, R.string.stats_average_moving_pace, reportSpeed);
|
||||
if (includeLocationSpeed) {
|
||||
setSpeedLabel(
|
||||
activity, R.id.stats_speed_label, R.string.stats_speed, R.string.stats_pace, reportSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the trip statistics values.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param tripStatistics the trip statistics
|
||||
* @param metricUnits true to display in metric units
|
||||
* @param reportSpeed true to report speed
|
||||
*/
|
||||
private static void setTripStatisticsValues(
|
||||
Activity activity, TripStatistics tripStatistics, boolean metricUnits, boolean reportSpeed) {
|
||||
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);
|
||||
|
||||
// Set total distance
|
||||
double totalDistance = tripStatistics == null ? Double.NaN : tripStatistics.getTotalDistance();
|
||||
double maxSpeed = tripStatistics == null ? Double.NaN : tripStatistics.getMaxSpeed();
|
||||
long totalTime = tripStatistics == null ? -1L : tripStatistics.getTotalTime();
|
||||
double averageSpeed = tripStatistics == null ? Double.NaN : tripStatistics.getAverageSpeed();
|
||||
long movingTime = tripStatistics == null ? -1L : tripStatistics.getMovingTime();
|
||||
double averageMovingSpeed = tripStatistics == null ? Double.NaN
|
||||
: tripStatistics.getAverageMovingSpeed();
|
||||
double elevationGain = tripStatistics == null ? Double.NaN
|
||||
: tripStatistics.getTotalElevationGain();
|
||||
double minElevation = tripStatistics == null ? Double.NaN : tripStatistics.getMinElevation();
|
||||
double maxElevation = tripStatistics == null ? Double.NaN : tripStatistics.getMaxElevation();
|
||||
double minGrade = tripStatistics == null ? Double.NaN : tripStatistics.getMinGrade();
|
||||
double maxGrade = tripStatistics == null ? Double.NaN : tripStatistics.getMaxGrade();
|
||||
|
||||
setDistanceValue(activity, R.id.stats_total_distance_value, totalDistance, metricUnits);
|
||||
setSpeedValue(activity, R.id.stats_max_speed_value, maxSpeed, metricUnits, reportSpeed);
|
||||
|
||||
// Set total time/moving time
|
||||
setTimeLabel(activity, R.id.stats_total_time_label, R.string.stats_total_time,
|
||||
R.string.stats_moving_time, showTotalTime);
|
||||
long totalTime;
|
||||
if (tripStatistics == null) {
|
||||
totalTime = -1L;
|
||||
} else {
|
||||
totalTime = showTotalTime ? tripStatistics.getTotalTime() : tripStatistics.getMovingTime();
|
||||
}
|
||||
setTimeValue(activity, R.id.stats_total_time_value, totalTime);
|
||||
|
||||
// Set average speed/moving average speed
|
||||
if (showTotalTime) {
|
||||
setSpeedLabel(activity, R.id.stats_average_speed_label, R.string.stats_average_speed,
|
||||
R.string.stats_average_pace, reportSpeed);
|
||||
} else {
|
||||
setSpeedLabel(activity, R.id.stats_average_speed_label, R.string.stats_average_moving_speed,
|
||||
R.string.stats_average_moving_pace, reportSpeed);
|
||||
}
|
||||
double averageSpeed;
|
||||
if (tripStatistics == null) {
|
||||
averageSpeed = Double.NaN;
|
||||
} else {
|
||||
averageSpeed = showTotalTime ? tripStatistics.getAverageSpeed()
|
||||
: tripStatistics.getAverageMovingSpeed();
|
||||
}
|
||||
setSpeedValue(activity, R.id.stats_average_speed_value, averageSpeed, metricUnits, reportSpeed);
|
||||
setTimeValue(activity, R.id.stats_moving_time_value, movingTime);
|
||||
setSpeedValue(activity, R.id.stats_average_moving_speed_value, averageMovingSpeed, metricUnits,
|
||||
reportSpeed);
|
||||
setAltitudeValue(activity, R.id.stats_elevation_gain_value, elevationGain, metricUnits);
|
||||
setAltitudeValue(activity, R.id.stats_min_elevation_value, minElevation, metricUnits);
|
||||
setAltitudeValue(activity, R.id.stats_max_elevation_value, maxElevation, metricUnits);
|
||||
setGradeValue(activity, R.id.stats_min_grade_value, minGrade);
|
||||
setGradeValue(activity, R.id.stats_max_grade_value, maxGrade);
|
||||
|
||||
// Set max speed
|
||||
setSpeedLabel(activity, R.id.stats_max_speed_label, R.string.stats_max_speed,
|
||||
R.string.stats_fastest_pace, reportSpeed);
|
||||
double maxSpeed = tripStatistics == null ? Double.NaN : tripStatistics.getMaxSpeed();
|
||||
setSpeedValue(activity, R.id.stats_max_speed_value, maxSpeed, metricUnits, reportSpeed);
|
||||
|
||||
// Set elevation
|
||||
boolean showElevation = PreferencesUtils.getBoolean(
|
||||
activity, R.string.stats_show_elevation_key, false);
|
||||
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);
|
||||
View elevationValueTableRow2 = activity.findViewById(R.id.stats_elevation_value_table_row2);
|
||||
elevationLabelTableRow1.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
||||
elevationValueTableRow1.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
||||
elevationLabelTableRow2.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
||||
elevationValueTableRow2.setVisibility(showElevation ? View.VISIBLE : View.GONE);
|
||||
if (showElevation) {
|
||||
double elevationGain = tripStatistics == null ? Double.NaN
|
||||
: tripStatistics.getTotalElevationGain();
|
||||
double minElevation = tripStatistics == null ? Double.NaN : tripStatistics.getMinElevation();
|
||||
double maxElevation = tripStatistics == null ? Double.NaN : tripStatistics.getMaxElevation();
|
||||
setElevationValue(activity, R.id.stats_elevation_gain_value, elevationGain, metricUnits);
|
||||
setElevationValue(activity, R.id.stats_min_elevation_value, minElevation, metricUnits);
|
||||
setElevationValue(activity, R.id.stats_max_elevation_value, maxElevation, metricUnits);
|
||||
}
|
||||
|
||||
// Set grade
|
||||
boolean showGrade = PreferencesUtils.getBoolean(activity, R.string.stats_show_grade_key, false);
|
||||
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);
|
||||
gradeValueTableRow.setVisibility(showGrade ? View.VISIBLE : View.GONE);
|
||||
if (showGrade) {
|
||||
double minGrade = tripStatistics == null ? Double.NaN : tripStatistics.getMinGrade();
|
||||
double maxGrade = tripStatistics == null ? Double.NaN : tripStatistics.getMaxGrade();
|
||||
setGradeValue(activity, R.id.stats_min_grade_value, minGrade);
|
||||
setGradeValue(activity, R.id.stats_max_grade_value, maxGrade);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a time label.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param id the time label resource id
|
||||
* @param totalTimeId the total time string id
|
||||
* @param movingTimeId the moving time string id
|
||||
* @param totalTime true to use total time
|
||||
*/
|
||||
private static void setTimeLabel(Activity activity, int id, int totalTimeId, int movingTimeId,
|
||||
boolean totalTime) {
|
||||
TextView textView = (TextView) activity.findViewById(id);
|
||||
textView.setText(totalTime ? totalTimeId : movingTimeId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,25 +283,25 @@ public class StatsUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an altitude value.
|
||||
* Sets an elevation value.
|
||||
*
|
||||
* @param activity the activity
|
||||
* @param id the altitude value resource id
|
||||
* @param altitude the altitude in meters
|
||||
* @param id the elevation value resource id
|
||||
* @param elevation the elevation in meters
|
||||
* @param metricUnits true to display in metric units
|
||||
*/
|
||||
private static void setAltitudeValue(
|
||||
Activity activity, int id, double altitude, boolean metricUnits) {
|
||||
private static void setElevationValue(
|
||||
Activity activity, int id, double elevation, boolean metricUnits) {
|
||||
TextView textView = (TextView) activity.findViewById(id);
|
||||
String value;
|
||||
if (Double.isNaN(altitude) || Double.isInfinite(altitude)) {
|
||||
if (Double.isNaN(elevation) || Double.isInfinite(elevation)) {
|
||||
value = activity.getString(R.string.value_unknown);
|
||||
} else {
|
||||
if (metricUnits) {
|
||||
value = activity.getString(R.string.value_float_meter, altitude);
|
||||
value = activity.getString(R.string.value_float_meter, elevation);
|
||||
} else {
|
||||
altitude *= UnitConversions.M_TO_FT;
|
||||
value = activity.getString(R.string.value_float_feet, altitude);
|
||||
elevation *= UnitConversions.M_TO_FT;
|
||||
value = activity.getString(R.string.value_float_feet, elevation);
|
||||
}
|
||||
}
|
||||
textView.setText(value);
|
||||
|
||||
Reference in New Issue
Block a user