From 352137c44097fc3ff6b436b0b5c3ac93ef38bfe7 Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Thu, 19 Apr 2012 10:40:10 -0700 Subject: [PATCH] fix comment for 3e985a497047 --- .../apps/mytracks/MarkerDetailActivity.java | 164 ++++-------------- .../apps/mytracks/MarkerEditActivity.java | 15 +- .../android/apps/mytracks/StatsUtilities.java | 3 + .../apps/mytracks/util/StatsUtils.java | 159 +++++++++++++++++ 4 files changed, 197 insertions(+), 144 deletions(-) create mode 100644 MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java diff --git a/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java b/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java index 2032597ee..32247dddf 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java @@ -21,8 +21,7 @@ import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.util.ApiAdapterFactory; -import com.google.android.apps.mytracks.util.StringUtils; -import com.google.android.apps.mytracks.util.UnitConversions; +import com.google.android.apps.mytracks.util.StatsUtils; import com.google.android.maps.mytracks.R; import android.content.Context; @@ -93,43 +92,44 @@ public class MarkerDetailActivity extends FragmentActivity { boolean metricUnits = preferences.getBoolean(getString(R.string.metric_units_key), true); boolean reportSpeed = preferences.getBoolean(getString(R.string.report_speed_key), true); - TextView maxSpeedLabel = (TextView) findViewById(R.id.marker_detail_max_speed_label); - maxSpeedLabel.setText(reportSpeed ? R.string.stat_max_speed : R.string.stat_fastest_pace); - TextView averageSpeedLabel = (TextView) findViewById(R.id.marker_detail_average_speed_label); - averageSpeedLabel.setText(reportSpeed ? R.string.stat_average_speed - : R.string.stat_average_pace); - TextView averageMovingSpeedLabel = (TextView) findViewById( - R.id.marker_detail_average_moving_speed_label); - averageMovingSpeedLabel.setText(reportSpeed ? R.string.stat_average_moving_speed - : R.string.stat_average_moving_pace); + StatsUtils.setSpeedLabel(this, R.id.marker_detail_max_speed_label, R.string.stat_max_speed, + R.string.stat_fastest_pace, reportSpeed); + StatsUtils.setSpeedLabel(this, R.id.marker_detail_average_speed_label, + R.string.stat_average_speed, R.string.stat_average_pace, reportSpeed); + StatsUtils.setSpeedLabel(this, R.id.marker_detail_average_moving_speed_label, + R.string.stat_average_moving_speed, R.string.stat_average_moving_pace, reportSpeed); TripStatistics tripStatistics = waypoint.getStatistics(); - setDistance( - R.id.marker_detail_total_distance_value, tripStatistics.getTotalDistance(), metricUnits); - setSpeed(R.id.marker_detail_max_speed_value, tripStatistics.getMaxSpeed(), reportSpeed, - metricUnits); + StatsUtils.setDistanceValue(this, R.id.marker_detail_total_distance_value, + tripStatistics.getTotalDistance(), metricUnits); + StatsUtils.setSpeedValue(this, R.id.marker_detail_max_speed_value, + tripStatistics.getMaxSpeed(), reportSpeed, metricUnits); - setTime(R.id.marker_detail_total_time_value, tripStatistics.getTotalTime()); - setSpeed(R.id.marker_detail_average_speed_value, tripStatistics.getAverageSpeed(), - reportSpeed, metricUnits); + StatsUtils.setTimeValue( + this, R.id.marker_detail_total_time_value, tripStatistics.getTotalTime()); + StatsUtils.setSpeedValue(this, R.id.marker_detail_average_speed_value, + tripStatistics.getAverageSpeed(), reportSpeed, metricUnits); - setTime(R.id.marker_detail_moving_time_value, tripStatistics.getMovingTime()); - setSpeed(R.id.marker_detail_average_moving_speed_value, + StatsUtils.setTimeValue( + this, R.id.marker_detail_moving_time_value, tripStatistics.getMovingTime()); + StatsUtils.setSpeedValue(this, R.id.marker_detail_average_moving_speed_value, tripStatistics.getAverageMovingSpeed(), reportSpeed, metricUnits); - setAltitude( - R.id.marker_detail_elevation_value, waypoint.getLocation().getAltitude(), metricUnits); - setAltitude(R.id.marker_detail_elevation_gain_value, tripStatistics.getTotalElevationGain(), - metricUnits); + StatsUtils.setAltitudeValue(this, R.id.marker_detail_elevation_value, + waypoint.getLocation().getAltitude(), metricUnits); + StatsUtils.setAltitudeValue(this, R.id.marker_detail_elevation_gain_value, + tripStatistics.getTotalElevationGain(), metricUnits); - setAltitude( - R.id.marker_detail_min_elevation_value, tripStatistics.getMinElevation(), metricUnits); - setAltitude( - R.id.marker_detail_max_elevation_value, tripStatistics.getMaxElevation(), metricUnits); + StatsUtils.setAltitudeValue(this, R.id.marker_detail_min_elevation_value, + tripStatistics.getMinElevation(), metricUnits); + StatsUtils.setAltitudeValue(this, R.id.marker_detail_max_elevation_value, + tripStatistics.getMaxElevation(), metricUnits); - setGrade(R.id.marker_detail_min_grade_value, tripStatistics.getMinGrade()); - setGrade(R.id.marker_detail_max_grade_value, tripStatistics.getMaxGrade()); + StatsUtils.setGradeValue( + this, R.id.marker_detail_min_grade_value, tripStatistics.getMinGrade()); + StatsUtils.setGradeValue( + this, R.id.marker_detail_max_grade_value, tripStatistics.getMaxGrade()); } } @@ -163,108 +163,4 @@ public class MarkerDetailActivity extends FragmentActivity { return super.onOptionsItemSelected(item); } } - - /** - * Sets distance. - * - * @param id resource id - * @param distance distance in meters - * @param metricUnits true to display in metric units - */ - private void setDistance(int id, double distance, boolean metricUnits) { - TextView textView = (TextView) findViewById(id); - distance *= UnitConversions.M_TO_KM; - String value; - if (metricUnits) { - value = getString(R.string.value_float_kilometer, distance); - } else { - distance *= UnitConversions.KM_TO_MI; - value = getString(R.string.value_float_mile, distance); - } - textView.setText(value); - } - - /** - * Sets time. - * - * @param id resource id - * @param time time - */ - private void setTime(int id, long time) { - TextView textView = (TextView) findViewById(id); - textView.setText(StringUtils.formatElapsedTime(time)); - } - - /** - * Sets speed. - * - * @param id resource id - * @param speed speed in meters per second - * @param reportSpeed true to report speed - * @param metricUnits true to display in metric units - */ - private void setSpeed(int id, double speed, boolean reportSpeed, boolean metricUnits) { - TextView textView = (TextView) findViewById(id); - speed *= UnitConversions.MS_TO_KMH; - String value; - if (metricUnits) { - if (reportSpeed) { - value = getString(R.string.value_float_kilometer_hour, speed); - } else { - double pace = speed == 0 ? 0.0 : 60.0 / speed; // convert from hours to - // minutes - value = getString(R.string.value_float_minute_kilometer, pace); - } - } else { - speed *= UnitConversions.KM_TO_MI; - if (reportSpeed) { - value = getString(R.string.value_float_mile_hour, speed); - } else { - double pace = speed == 0 ? 0.0 : 60.0 / speed; // convert from hours to - // minutes - value = getString(R.string.value_float_minute_mile, pace); - } - } - textView.setText(value); - } - - /** - * Sets the altitude. - * - * @param id resource id - * @param altitude altitude in meters - * @param metricUnits true to display in metric units - */ - private void setAltitude(int id, double altitude, boolean metricUnits) { - TextView textView = (TextView) findViewById(id); - String value; - if (Double.isNaN(altitude) || Double.isInfinite(altitude)) { - value = getString(R.string.value_unknown); - } else { - if (metricUnits) { - value = getString(R.string.value_float_meter, altitude); - } else { - altitude *= UnitConversions.M_TO_FT; - value = getString(R.string.value_float_feet, altitude); - } - } - textView.setText(value); - } - - /** - * Sets the grade. - * - * @param id resource id - * @param grade grade in fraction between 0 and 1 - */ - private void setGrade(int id, double grade) { - TextView textView = (TextView) findViewById(id); - String value; - if (Double.isNaN(grade) || Double.isInfinite(grade)) { - value = getString(R.string.value_unknown); - } else { - value = getString(R.string.value_integer_percent, Math.round(grade * 100)); - } - textView.setText(value); - } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java index 6f3ff54fd..5982824ce 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java @@ -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.content.WaypointCreationRequest; import com.google.android.apps.mytracks.content.WaypointCreationRequest.WaypointType; -import com.google.android.apps.mytracks.content.WaypointsColumns; import com.google.android.apps.mytracks.services.ITrackRecordingService; import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection; import com.google.android.apps.mytracks.util.ApiAdapterFactory; @@ -28,7 +27,6 @@ import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtil import com.google.android.maps.mytracks.R; import android.app.Activity; -import android.content.ContentValues; import android.os.Bundle; import android.os.RemoteException; import android.speech.tts.TextToSpeech; @@ -218,14 +216,11 @@ public class MarkerEditActivity extends Activity { * Saves a marker. */ private void saveMarker() { - ContentValues values = new ContentValues(); - values.put(WaypointsColumns.NAME, name.getText().toString()); - if (waypoint != null && waypoint.getType() == Waypoint.TYPE_WAYPOINT) { - values.put(WaypointsColumns.CATEGORY, markerType.getText().toString()); - values.put(WaypointsColumns.DESCRIPTION, description.getText().toString()); + waypoint.setName(name.getText().toString()); + if (waypoint.getType() == Waypoint.TYPE_WAYPOINT) { + waypoint.setCategory(markerType.getText().toString()); + waypoint.setDescription(description.getText().toString()); } - getContentResolver().update(WaypointsColumns.CONTENT_URI, values, "_id=?", - new String[] { String.valueOf(markerId) }); - + MyTracksProviderUtils.Factory.get(this).updateWaypoint(waypoint); } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/StatsUtilities.java b/MyTracks/src/com/google/android/apps/mytracks/StatsUtilities.java index b8a6fef65..d851ffff0 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/StatsUtilities.java +++ b/MyTracks/src/com/google/android/apps/mytracks/StatsUtilities.java @@ -16,6 +16,7 @@ package com.google.android.apps.mytracks; import com.google.android.apps.mytracks.stats.TripStatistics; +import com.google.android.apps.mytracks.util.StatsUtils; import com.google.android.apps.mytracks.util.StringUtils; import com.google.android.apps.mytracks.util.UnitConversions; import com.google.android.maps.mytracks.R; @@ -29,6 +30,8 @@ import java.text.NumberFormat; /** * Various utility functions for views that display statistics information. * + * @deprecated use {@link StatsUtils}. + * * @author Sandor Dornbush */ public class StatsUtilities { diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java new file mode 100644 index 000000000..1a31c4583 --- /dev/null +++ b/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java @@ -0,0 +1,159 @@ +/* + * 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.util; + +import com.google.android.maps.mytracks.R; + +import android.app.Activity; +import android.widget.TextView; + +/** + * Utilities for updating the statistics UI labels and values. + * + * @author Jimmy Shih + */ +public class StatsUtils { + + private StatsUtils() {} + + /** + * Sets a speed label. + * + * @param activity the activity + * @param id the speed label resource id + * @param speedId the speed string id + * @param paceId the pace string id + * @param reportSpeed true to report speed + */ + public static void setSpeedLabel( + Activity activity, int id, int speedId, int paceId, boolean reportSpeed) { + TextView textView = (TextView) activity.findViewById(id); + textView.setText(reportSpeed ? speedId : paceId); + } + + /** + * Sets a speed value. + * + * @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 + */ + public static void setSpeedValue( + Activity activity, int id, double speed, boolean reportSpeed, boolean metricUnits) { + 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); + } + } else { + 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); + } + + /** + * Sets a distance value. + * + * @param activity the activity + * @param id the distance value resource id + * @param distance the distance in meters + * @param metricUnits true to display in metric units + */ + public 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); + } else { + distance *= UnitConversions.KM_TO_MI; + value = activity.getString(R.string.value_float_mile, distance); + } + textView.setText(value); + } + + /** + * Sets a time value. + * + * @param activity the activity + * @param id the time value resource id + * @param time the time + */ + public static void setTimeValue(Activity activity, int id, long time) { + TextView textView = (TextView) activity.findViewById(id); + textView.setText(StringUtils.formatElapsedTime(time)); + } + + /** + * Sets an altitude value. + * + * @param activity the activity + * @param id the altitude value resource id + * @param altitude the altitude in meters + * @param metricUnits true to display in metric units + */ + public static void setAltitudeValue( + Activity activity, int id, double altitude, boolean metricUnits) { + TextView textView = (TextView) activity.findViewById(id); + String value; + if (Double.isNaN(altitude) || Double.isInfinite(altitude)) { + value = activity.getString(R.string.value_unknown); + } else { + if (metricUnits) { + value = activity.getString(R.string.value_float_meter, altitude); + } else { + altitude *= UnitConversions.M_TO_FT; + value = activity.getString(R.string.value_float_feet, altitude); + } + } + textView.setText(value); + } + + /** + * Sets a grade value. + * + * @param activity the activity + * @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) { + TextView textView = (TextView) activity.findViewById(id); + String value; + if (Double.isNaN(grade) || Double.isInfinite(grade)) { + value = activity.getString(R.string.value_unknown); + } else { + value = activity.getString(R.string.value_integer_percent, Math.round(grade * 100)); + } + textView.setText(value); + } +}