Use stats_core.xml layout for

- AggregatedStatsActivity
- StatsFragment
- MarkerDetailActivity
Remove StatsUtilities. Use StatsUtils to set all stats labels and values.
This commit is contained in:
Jimmy Shih
2012-04-20 12:50:22 -07:00
parent 8f7c44d1e7
commit aaef92b139
20 changed files with 630 additions and 1211 deletions
@@ -16,9 +16,11 @@
package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
import android.location.Location;
import android.widget.TextView;
/**
@@ -30,6 +32,114 @@ public class StatsUtils {
private StatsUtils() {}
/**
* Sets the speed labels.
*
* @param activity the activity
* @param reportSpeed true to report speed
* @param includeLocationSpeed true to include the current location speed
*/
public static void setSpeedLabels(
Activity activity, boolean reportSpeed, boolean includeLocationSpeed) {
StatsUtils.setSpeedLabel(activity, R.id.stats_max_speed_label, R.string.stats_max_speed,
R.string.stats_fastest_pace, reportSpeed);
StatsUtils.setSpeedLabel(activity, R.id.stats_average_speed_label, R.string.stats_average_speed,
R.string.stats_average_pace, reportSpeed);
StatsUtils.setSpeedLabel(activity, R.id.stats_average_moving_speed_label,
R.string.stats_average_moving_speed, R.string.stats_average_moving_pace, reportSpeed);
if (includeLocationSpeed) {
StatsUtils.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
*/
public static void setTripStatisticsValues(
Activity activity, TripStatistics tripStatistics, boolean metricUnits, boolean reportSpeed) {
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();
StatsUtils.setDistanceValue(
activity, R.id.stats_total_distance_value, totalDistance, metricUnits);
StatsUtils.setSpeedValue(
activity, R.id.stats_max_speed_value, maxSpeed, metricUnits, reportSpeed);
StatsUtils.setTimeValue(activity, R.id.stats_total_time_value, totalTime);
StatsUtils.setSpeedValue(
activity, R.id.stats_average_speed_value, averageSpeed, metricUnits, reportSpeed);
StatsUtils.setTimeValue(activity, R.id.stats_moving_time_value, movingTime);
StatsUtils.setSpeedValue(activity, R.id.stats_average_moving_speed_value, averageMovingSpeed,
metricUnits, reportSpeed);
StatsUtils.setAltitudeValue(
activity, R.id.stats_elevation_gain_value, elevationGain, metricUnits);
StatsUtils.setAltitudeValue(
activity, R.id.stats_min_elevation_value, minElevation, metricUnits);
StatsUtils.setAltitudeValue(
activity, R.id.stats_max_elevation_value, maxElevation, metricUnits);
StatsUtils.setGradeValue(activity, R.id.stats_min_grade_value, minGrade);
StatsUtils.setGradeValue(activity, R.id.stats_max_grade_value, maxGrade);
}
/**
* 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
*/
public static void setLocationValues(
Activity activity, Location location, boolean metricUnits, boolean 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();
StatsUtils.setSpeedValue(activity, R.id.stats_speed_value, speed, metricUnits, reportSpeed);
StatsUtils.setAltitudeValue(activity, R.id.stats_elevation_value, altitude, metricUnits);
StatsUtils.setCoordinateValue(activity, R.id.stats_latitude_value, latitude);
StatsUtils.setCoordinateValue(activity, R.id.stats_longitude_value, longitude);
}
/**
* Sets the location elevation value.
*
* @param activity the activity
* @param elevation the elevation in meters
* @param metricUnits true to display in metric units
*/
public static void setLocationElevationValue(
Activity activity, double elevation, boolean metricUnits) {
StatsUtils.setAltitudeValue(activity, R.id.stats_elevation_value, elevation, metricUnits);
}
/**
* Sets the total time value.
*
* @param activity the activity
* @param totalTime the total time
*/
public static void setTotalTimeValue(Activity activity, long totalTime) {
StatsUtils.setTimeValue(activity, R.id.stats_total_time_value, totalTime);
}
/**
* Sets a speed label.
*
@@ -39,7 +149,7 @@ public class StatsUtils {
* @param paceId the pace string id
* @param reportSpeed true to report speed
*/
public static void setSpeedLabel(
private static void setSpeedLabel(
Activity activity, int id, int speedId, int paceId, boolean reportSpeed) {
TextView textView = (TextView) activity.findViewById(id);
textView.setText(reportSpeed ? speedId : paceId);
@@ -51,30 +161,34 @@ public class StatsUtils {
* @param activity the activity
* @param id the speed value resource id
* @param speed the speed in meters per second
* @param reportSpeed true to report speed
* @param metricUnits true to display in metric units
* @param reportSpeed true to report speed
*/
public static void setSpeedValue(
Activity activity, int id, double speed, boolean reportSpeed, boolean metricUnits) {
private static void setSpeedValue(
Activity activity, int id, double speed, boolean metricUnits, boolean reportSpeed) {
TextView textView = (TextView) activity.findViewById(id);
speed *= UnitConversions.MS_TO_KMH;
String value;
if (metricUnits) {
if (reportSpeed) {
value = activity.getString(R.string.value_float_kilometer_hour, speed);
} else {
// convert from hours to minutes
double pace = speed == 0 ? 0.0 : 60.0 / speed;
value = activity.getString(R.string.value_float_minute_kilometer, pace);
}
if (Double.isNaN(speed) || Double.isInfinite(speed)) {
value = activity.getString(R.string.value_unknown);
} else {
speed *= UnitConversions.KM_TO_MI;
if (reportSpeed) {
value = activity.getString(R.string.value_float_mile_hour, speed);
speed *= UnitConversions.MS_TO_KMH;
if (metricUnits) {
if (reportSpeed) {
value = activity.getString(R.string.value_float_kilometer_hour, speed);
} else {
// convert from hours to minutes
double pace = speed == 0 ? 0.0 : 60.0 / speed;
value = activity.getString(R.string.value_float_minute_kilometer, pace);
}
} else {
// convert from hours to minutes
double pace = speed == 0 ? 0.0 : 60.0 / speed;
value = activity.getString(R.string.value_float_minute_mile, pace);
speed *= UnitConversions.KM_TO_MI;
if (reportSpeed) {
value = activity.getString(R.string.value_float_mile_hour, speed);
} else {
// convert from hours to minutes
double pace = speed == 0 ? 0.0 : 60.0 / speed;
value = activity.getString(R.string.value_float_minute_mile, pace);
}
}
}
textView.setText(value);
@@ -88,16 +202,20 @@ public class StatsUtils {
* @param distance the distance in meters
* @param metricUnits true to display in metric units
*/
public static void setDistanceValue(
private static void setDistanceValue(
Activity activity, int id, double distance, boolean metricUnits) {
TextView textView = (TextView) activity.findViewById(id);
distance *= UnitConversions.M_TO_KM;
String value;
if (metricUnits) {
value = activity.getString(R.string.value_float_kilometer, distance);
if (Double.isNaN(distance) || Double.isInfinite(distance)) {
value = activity.getString(R.string.value_unknown);
} else {
distance *= UnitConversions.KM_TO_MI;
value = activity.getString(R.string.value_float_mile, distance);
distance *= UnitConversions.M_TO_KM;
if (metricUnits) {
value = activity.getString(R.string.value_float_kilometer, distance);
} else {
distance *= UnitConversions.KM_TO_MI;
value = activity.getString(R.string.value_float_mile, distance);
}
}
textView.setText(value);
}
@@ -109,9 +227,11 @@ public class StatsUtils {
* @param id the time value resource id
* @param time the time
*/
public static void setTimeValue(Activity activity, int id, long time) {
private static void setTimeValue(Activity activity, int id, long time) {
TextView textView = (TextView) activity.findViewById(id);
textView.setText(StringUtils.formatElapsedTime(time));
String value = time == -1L ? activity.getString(R.string.value_unknown)
: StringUtils.formatElapsedTime(time);
textView.setText(value);
}
/**
@@ -122,7 +242,7 @@ public class StatsUtils {
* @param altitude the altitude in meters
* @param metricUnits true to display in metric units
*/
public static void setAltitudeValue(
private static void setAltitudeValue(
Activity activity, int id, double altitude, boolean metricUnits) {
TextView textView = (TextView) activity.findViewById(id);
String value;
@@ -146,7 +266,7 @@ public class StatsUtils {
* @param id the grade value resource id
* @param grade the grade in fraction between 0 and 1
*/
public static void setGradeValue(Activity activity, int id, double grade) {
private static void setGradeValue(Activity activity, int id, double grade) {
TextView textView = (TextView) activity.findViewById(id);
String value;
if (Double.isNaN(grade) || Double.isInfinite(grade)) {
@@ -156,4 +276,23 @@ public class StatsUtils {
}
textView.setText(value);
}
/**
* Sets a coordinate value.
*
* @param activity the activity
* @param id the coordinate value resource id
* @param coordinate the coordinate in degrees
*/
private static void setCoordinateValue(Activity activity, int id, double coordinate) {
TextView textView = (TextView) activity.findViewById(id);
String value;
if (Double.isNaN(coordinate) || Double.isInfinite(coordinate)) {
value = activity.getString(R.string.value_unknown);
} else {
value = activity.getString(
R.string.value_coordinate_degree, Location.convert(coordinate, Location.FORMAT_DEGREES));
}
textView.setText(value);
}
}