From 2be9f58545d5dc4a64b37279669c892137513ca7 Mon Sep 17 00:00:00 2001 From: youtaol Date: Thu, 31 Oct 2013 11:11:35 +0800 Subject: [PATCH] Change code style. --- .../apps/mytracks/TrackEditActivity.java | 2 +- .../apps/mytracks/fragments/ChartFragment.java | 18 +++++++----------- .../importer/AbstractFileTrackImporter.java | 16 ++++------------ .../mytracks/io/maps/SendMapsAsyncTask.java | 9 +++------ .../services/TrackRecordingService.java | 17 +++++------------ .../apps/mytracks/util/CalorieUtils.java | 7 +++---- .../mytracks/fragments/ChartFragmentTest.java | 2 +- 7 files changed, 24 insertions(+), 47 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java index 821c4c152..d6a23d063 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java @@ -200,7 +200,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity myTracksProviderUtils.updateTrack(track); TrackRecordingServiceConnectionUtils.updateCalorie(trackRecordingServiceConnection); } else { - CalorieUtils.updateCalorie(getApplicationContext(), -1, track); + CalorieUtils.updateCalorie(getApplicationContext(), -1L, track); // Update data with new calorie. myTracksProviderUtils.updateTrack(track); diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java index 150ccb530..28bc30397 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java @@ -28,14 +28,13 @@ import com.google.android.apps.mytracks.content.TrackDataType; import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatisticsUpdater; -import com.google.android.apps.mytracks.util.CalorieUtils; +import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.UnitConversions; import com.google.android.maps.mytracks.R; import com.google.common.annotations.VisibleForTesting; -import android.content.Context; import android.location.Location; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -190,7 +189,7 @@ public class ChartFragment extends Fragment implements TrackDataListener { public void onSampledInTrackPoint(Location location) { if (isResumed()) { double[] data = new double[ChartView.NUM_SERIES + 1]; - fillDataPoint(location, data, getActivity()); + fillDataPoint(location, data); pendingPoints.add(data); } } @@ -198,14 +197,14 @@ public class ChartFragment extends Fragment implements TrackDataListener { @Override public void onSampledOutTrackPoint(Location location) { if (isResumed()) { - fillDataPoint(location, null, getActivity()); + fillDataPoint(location, null); } } @Override public void onSegmentSplit(Location location) { if (isResumed()) { - fillDataPoint(location, null, getActivity()); + fillDataPoint(location, null); } } @@ -441,10 +440,9 @@ public class ChartFragment extends Fragment implements TrackDataListener { * * @param location the location * @param data the data point to fill in, can be null - * @param context the context */ @VisibleForTesting - void fillDataPoint(Location location, double data[], Context context) { + void fillDataPoint(Location location, double data[]) { double timeOrDistance = Double.NaN; double elevation = Double.NaN; double speed = Double.NaN; @@ -454,10 +452,8 @@ public class ChartFragment extends Fragment implements TrackDataListener { double power = Double.NaN; if (tripStatisticsUpdater != null) { - tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, CalorieUtils - .getActivityType(context, - PreferencesUtils.getLong(context, R.string.recording_track_id_key)), PreferencesUtils - .getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT)); + tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, + ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT); TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics(); if (chartByDistance) { double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java index 7735a7e03..ba8efc2d3 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java @@ -24,7 +24,7 @@ import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.services.TrackRecordingService; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatisticsUpdater; -import com.google.android.apps.mytracks.util.CalorieUtils; +import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType; import com.google.android.apps.mytracks.util.FileUtils; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; @@ -243,15 +243,9 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track return; } trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval, false, - CalorieUtils.getActivityType(context, - PreferencesUtils.getLong(context, R.string.recording_track_id_key)), - PreferencesUtils.getInt(context, R.string.stats_weight_key, - PreferencesUtils.STATS_WEIGHT_DEFAULT)); + ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT); markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval, false, - CalorieUtils.getActivityType(context, - PreferencesUtils.getLong(context, R.string.recording_track_id_key)), - PreferencesUtils.getInt(context, R.string.stats_weight_key, - PreferencesUtils.STATS_WEIGHT_DEFAULT)); + ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT); } if (waypoint.getLocation().getTime() > trackPoint.getTime()) { trackPoint = null; @@ -555,9 +549,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track location.getTime() != -1L ? location.getTime() : trackData.importTime); } trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, - CalorieUtils.getActivityType(context, - PreferencesUtils.getLong(context, R.string.recording_track_id_key)), PreferencesUtils - .getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT)); + ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT); trackData.bufferedLocations[trackData.numBufferedLocations] = location; trackData.numBufferedLocations++; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java index 3776779f1..5a0eb700e 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java @@ -29,7 +29,7 @@ import com.google.android.apps.mytracks.io.gdata.maps.XmlMapsGDataParserFactory; import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask; import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils; import com.google.android.apps.mytracks.stats.TripStatisticsUpdater; -import com.google.android.apps.mytracks.util.CalorieUtils; +import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.common.gdata.AndroidXmlParserFactory; @@ -278,11 +278,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask { sentStartMarker = true; } - tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, CalorieUtils - .getActivityType(context, - PreferencesUtils.getLong(context, R.string.recording_track_id_key)), - PreferencesUtils.getInt(context, R.string.stats_weight_key, - PreferencesUtils.STATS_WEIGHT_DEFAULT)); + tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, + ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT); if (i % elevationSamplingFrequency == 0) { distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance()); elevations.add(tripStatisticsUpdater.getSmoothedElevation()); diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java index 20daec67a..644c1e65c 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -37,6 +37,7 @@ import com.google.android.apps.mytracks.services.tasks.SplitPeriodicTaskFactory; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatisticsUpdater; import com.google.android.apps.mytracks.util.CalorieUtils; +import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType; import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; @@ -661,16 +662,10 @@ public class TrackRecordingService extends Service { do { Location location = myTracksProviderUtils.createTrackPoint(cursor); trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, - CalorieUtils.getActivityType(context, - PreferencesUtils.getLong(context, R.string.recording_track_id_key)), - PreferencesUtils.getInt(context, R.string.stats_weight_key, - PreferencesUtils.STATS_WEIGHT_DEFAULT)); + ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT); if (location.getTime() > markerStartTime) { markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, - CalorieUtils.getActivityType(context, - PreferencesUtils.getLong(context, R.string.recording_track_id_key)), - PreferencesUtils.getInt(context, R.string.stats_weight_key, - PreferencesUtils.STATS_WEIGHT_DEFAULT)); + ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT); } } while (cursor.moveToPrevious()); } @@ -1014,9 +1009,7 @@ public class TrackRecordingService extends Service { CalorieUtils.getActivityType(context, track.getId()), PreferencesUtils.getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT)); markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, - CalorieUtils.getActivityType(context, - PreferencesUtils.getLong(context, R.string.recording_track_id_key)), PreferencesUtils - .getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT)); + ActivityType.INVALID, PreferencesUtils.STATS_WEIGHT_DEFAULT); updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location)); } catch (SQLiteException e) { /* @@ -1378,7 +1371,7 @@ public class TrackRecordingService extends Service { if (currentTrack == null) { return; } - double newCalorie = CalorieUtils.updateCalorie(getApplicationContext(), -1, currentTrack); + double newCalorie = CalorieUtils.updateCalorie(getApplicationContext(), -1L, currentTrack); trackTripStatisticsUpdater.updateCalorie(newCalorie); // Update to database. diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java index bdbd90777..f51748611 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java @@ -277,8 +277,8 @@ public class CalorieUtils { * * @param context the context * @param track the track to calculate - * @param startTrackPointId the starting track point id. Make this value less - * than 1 to calculate the entire track + * @param startTrackPointId the starting track point id. Make this value 1L to + * calculate the entire track * @return the calorie value of track */ public static double updateCalorie(Context context, @@ -297,8 +297,7 @@ public class CalorieUtils { tripStatisticsUpdater.addLocation(points.next(), PreferencesUtils.getInt(context, R.string.recording_distance_interval_key, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT), false, activityType, - PreferencesUtils.getInt(context, R.string.stats_weight_key, - PreferencesUtils.STATS_WEIGHT_DEFAULT)); + PreferencesUtils.STATS_WEIGHT_DEFAULT); } else { tripStatisticsUpdater.addLocation(points.next(), PreferencesUtils.getInt(context, R.string.recording_distance_interval_key, diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/fragments/ChartFragmentTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/fragments/ChartFragmentTest.java index 69790b014..043b0e892 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/fragments/ChartFragmentTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/fragments/ChartFragmentTest.java @@ -345,7 +345,7 @@ public class ChartFragmentTest extends AndroidTestCase { */ private double[] fillDataPointTestHelper(Location location) { double[] point = new double[ChartView.NUM_SERIES + 1]; - chartFragment.fillDataPoint(location, point, getContext()); + chartFragment.fillDataPoint(location, point); return point; }