From efaa7df2017367f1e9b61a897f1f37fbec30fbca Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Thu, 20 Dec 2012 13:55:01 -0800 Subject: [PATCH] Declare WaypointType as an enum. --- MyTracks/.settings/org.eclipse.jdt.core.prefs | 11 ------- .../android/apps/mytracks/ChartView.java | 3 +- .../android/apps/mytracks/MapOverlay.java | 3 +- .../apps/mytracks/MarkerDetailActivity.java | 3 +- .../apps/mytracks/MarkerEditActivity.java | 8 ++--- .../apps/mytracks/MarkerListActivity.java | 5 +-- .../apps/mytracks/SearchListActivity.java | 3 +- .../apps/mytracks/io/file/GpxImporter.java | 5 +-- .../apps/mytracks/io/file/KmlTrackWriter.java | 3 +- .../SendFusionTablesAsyncTask.java | 3 +- .../services/TrackRecordingService.java | 12 +++---- .../.settings/org.eclipse.jdt.core.prefs | 11 ------- .../content/MyTracksProviderUtils.java | 16 +++++---- .../content/MyTracksProviderUtilsImpl.java | 25 +++++++------- .../apps/mytracks/content/Waypoint.java | 17 +++++----- .../content/WaypointCreationRequest.java | 6 ++-- .../.settings/org.eclipse.jdt.core.prefs | 10 ------ .../MyTracksProviderUtilsImplTest.java | 33 ++++++++++--------- .../content/WaypointCreationRequestTest.java | 2 +- .../services/TrackRecordingServiceTest.java | 5 +-- .../.settings/org.eclipse.jdt.core.prefs | 10 ------ 21 files changed, 82 insertions(+), 112 deletions(-) diff --git a/MyTracks/.settings/org.eclipse.jdt.core.prefs b/MyTracks/.settings/org.eclipse.jdt.core.prefs index 8e0fed2d0..aca2544a7 100644 --- a/MyTracks/.settings/org.eclipse.jdt.core.prefs +++ b/MyTracks/.settings/org.eclipse.jdt.core.prefs @@ -1,14 +1,5 @@ -#Tue Jul 17 10:23:26 PDT 2012 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning org.eclipse.jdt.core.compiler.problem.deadCode=warning @@ -17,7 +8,6 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled org.eclipse.jdt.core.compiler.problem.fieldHiding=warning @@ -74,7 +64,6 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=1585 org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field.count_dependent=1585|-1|1585 diff --git a/MyTracks/src/com/google/android/apps/mytracks/ChartView.java b/MyTracks/src/com/google/android/apps/mytracks/ChartView.java index 165a20327..a4cd573db 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/ChartView.java +++ b/MyTracks/src/com/google/android/apps/mytracks/ChartView.java @@ -17,6 +17,7 @@ package com.google.android.apps.mytracks; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.stats.ExtremityMonitor; import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.StringUtils; @@ -565,7 +566,7 @@ public class ChartView extends View { x, topBorder + spacer + markerHeight / 2, x, topBorder + effectiveHeight, markerPaint); canvas.translate( x - (float) (markerWidth * MapOverlay.WAYPOINT_X_ANCHOR), topBorder + spacer); - if (waypoints.get(i).getType() == Waypoint.TYPE_STATISTICS) { + if (waypoints.get(i).getType() == WaypointType.STATISTICS) { statisticsMarker.draw(canvas); } else { waypointMarker.draw(canvas); diff --git a/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java b/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java index 07e0cc7f1..d90116a4d 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MapOverlay.java @@ -19,6 +19,7 @@ package com.google.android.apps.mytracks; import static com.google.android.apps.mytracks.Constants.TAG; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.maps.TrackPath; import com.google.android.apps.mytracks.maps.TrackPathFactory; import com.google.android.apps.mytracks.util.LocationUtils; @@ -274,7 +275,7 @@ public class MapOverlay { for (Waypoint waypoint : waypoints) { Location location = waypoint.getLocation(); LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); - int drawableId = waypoint.getType() == Waypoint.TYPE_STATISTICS ? R.drawable.yellow_pushpin + int drawableId = waypoint.getType() == WaypointType.STATISTICS ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin; MarkerOptions markerOptions = new MarkerOptions().position(latLng) .anchor(WAYPOINT_X_ANCHOR, WAYPOINT_Y_ANCHOR).draggable(false).visible(true) diff --git a/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java b/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java index f70e74444..71087803c 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MarkerDetailActivity.java @@ -18,6 +18,7 @@ package com.google.android.apps.mytracks; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment; import com.google.android.apps.mytracks.util.IntentUtils; import com.google.android.apps.mytracks.util.StatsUtils; @@ -78,7 +79,7 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity { return; } name.setText(getString(R.string.generic_name_line, waypoint.getName())); - if (waypoint.getType() == Waypoint.TYPE_WAYPOINT) { + if (waypoint.getType() == WaypointType.WAYPOINT) { waypointSection.setVisibility(View.VISIBLE); statisticsSection.setVisibility(View.GONE); diff --git a/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java index 803cd36a8..8c91add55 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java @@ -18,8 +18,8 @@ package com.google.android.apps.mytracks; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.WaypointCreationRequest; -import com.google.android.apps.mytracks.content.WaypointCreationRequest.WaypointType; import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection; import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils; import com.google.android.maps.mytracks.R; @@ -131,7 +131,7 @@ public class MarkerEditActivity extends AbstractMyTracksActivity { statisticsSection.setVisibility(View.GONE); waypointSection.setVisibility(View.VISIBLE); int nextWaypointNumber = trackId == -1L ? -1 - : MyTracksProviderUtils.Factory.get(this).getNextWaypointNumber(trackId, false); + : MyTracksProviderUtils.Factory.get(this).getNextWaypointNumber(trackId, WaypointType.WAYPOINT); if (nextWaypointNumber == -1) { nextWaypointNumber = 0; } @@ -146,7 +146,7 @@ public class MarkerEditActivity extends AbstractMyTracksActivity { finish(); return; } - boolean statistics = waypoint.getType() == Waypoint.TYPE_STATISTICS; + boolean statistics = waypoint.getType() == WaypointType.STATISTICS; statisticsSection.setVisibility(statistics ? View.VISIBLE : View.GONE); waypointSection.setVisibility(statistics ? View.GONE : View.VISIBLE); if (statistics) { @@ -178,7 +178,7 @@ public class MarkerEditActivity extends AbstractMyTracksActivity { * Saves a marker. */ private void saveMarker() { - boolean statistics = waypoint.getType() == Waypoint.TYPE_STATISTICS; + boolean statistics = waypoint.getType() == WaypointType.STATISTICS; if (statistics) { waypoint.setName(statisticsName.getText().toString()); } else { diff --git a/MyTracks/src/com/google/android/apps/mytracks/MarkerListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/MarkerListActivity.java index e7711f286..566cd76ab 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MarkerListActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MarkerListActivity.java @@ -17,7 +17,7 @@ package com.google.android.apps.mytracks; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; -import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.WaypointsColumns; import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment; import com.google.android.apps.mytracks.util.ApiAdapterFactory; @@ -149,7 +149,8 @@ public class MarkerListActivity extends AbstractMyTracksActivity { int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME); int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION); - boolean statistics = cursor.getInt(typeIndex) == Waypoint.TYPE_STATISTICS; + boolean statistics = WaypointType.values()[cursor.getInt(typeIndex)] + == WaypointType.STATISTICS; int iconId = statistics ? R.drawable.yellow_pushpin : R.drawable.blue_pushpin; String category = statistics ? null : cursor.getString(categoryIndex); String description = statistics ? null : cursor.getString(descriptionIndex); diff --git a/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java index 7a817176c..e50208242 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/SearchListActivity.java @@ -23,6 +23,7 @@ import com.google.android.apps.mytracks.content.SearchEngine.SearchQuery; import com.google.android.apps.mytracks.content.SearchEngineProvider; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment; import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment; import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller; @@ -432,7 +433,7 @@ public class SearchListActivity extends AbstractMyTracksActivity implements Dele } } - boolean statistics = waypoint.getType() == Waypoint.TYPE_STATISTICS; + boolean statistics = waypoint.getType() == WaypointType.STATISTICS; long time = waypoint.getLocation().getTime(); resultMap.put(IS_RECORDING_FIELD, false); diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java index 7a4e5ff6d..66278aa23 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/GpxImporter.java @@ -20,6 +20,7 @@ import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.services.TrackRecordingService; import com.google.android.apps.mytracks.stats.TripStatisticsUpdater; import com.google.android.apps.mytracks.util.LocationUtils; @@ -608,7 +609,7 @@ public class GpxImporter extends DefaultHandler { Location waypointLocation = new Location(""); waypointLocation.setLatitude(100); waypointLocation.setLongitude(180); - Waypoint waypoint = new Waypoint("", "", "", icon, track.getId(), Waypoint.TYPE_STATISTICS, 0, + Waypoint waypoint = new Waypoint("", "", "", icon, track.getId(), WaypointType.STATISTICS, 0, 0, -1L, -1L, waypointLocation, null); myTracksProviderUtils.insertWaypoint(waypoint); } @@ -665,7 +666,7 @@ public class GpxImporter extends DefaultHandler { waypoint.setLength(updater.getTripStatistics().getTotalDistance()); waypoint.setLocation(trackPoint); waypoint.setTrackId(track.getId()); - waypoint.setType(Waypoint.TYPE_WAYPOINT); + waypoint.setType(WaypointType.WAYPOINT); myTracksProviderUtils.insertWaypoint(waypoint); } waypoint = null; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/KmlTrackWriter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/KmlTrackWriter.java index 6a7aecb2a..cf18b7c4a 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/KmlTrackWriter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/KmlTrackWriter.java @@ -23,6 +23,7 @@ import com.google.android.apps.mytracks.content.Sensor.SensorData; import com.google.android.apps.mytracks.content.Sensor.SensorDataSet; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat; import com.google.android.apps.mytracks.util.StringUtils; import com.google.android.maps.mytracks.R; @@ -164,7 +165,7 @@ public class KmlTrackWriter implements TrackFormatWriter { @Override public void writeWaypoint(Waypoint waypoint) { if (printWriter != null) { - String styleName = waypoint.getType() == Waypoint.TYPE_STATISTICS ? STATISTICS_STYLE + String styleName = waypoint.getType() == WaypointType.STATISTICS ? STATISTICS_STYLE : WAYPOINT_STYLE; writePlacemark( waypoint.getName(), waypoint.getDescription(), styleName, waypoint.getLocation()); diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesAsyncTask.java index 114e5726d..e94eafb17 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/fusiontables/SendFusionTablesAsyncTask.java @@ -8,6 +8,7 @@ import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; 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; @@ -335,7 +336,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask { // track). while (cursor.moveToNext()) { Waypoint wpt = myTracksProviderUtils.createWaypoint(cursor); - String type = wpt.getType() == Waypoint.TYPE_STATISTICS ? MARKER_TYPE_STATISTICS + String type = wpt.getType() == WaypointType.STATISTICS ? MARKER_TYPE_STATISTICS : MARKER_TYPE_WAYPOINT; if (!createNewPoint(wpt.getName(), wpt.getDescription(), wpt.getLocation(), type)) { Log.d(TAG, "Upload waypoints failed"); 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 cea1615be..1e79d0056 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -28,8 +28,8 @@ import com.google.android.apps.mytracks.content.Sensor; import com.google.android.apps.mytracks.content.Sensor.SensorDataSet; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.WaypointCreationRequest; -import com.google.android.apps.mytracks.content.WaypointCreationRequest.WaypointType; import com.google.android.apps.mytracks.services.sensors.SensorManager; import com.google.android.apps.mytracks.services.sensors.SensorManagerFactory; import com.google.android.apps.mytracks.services.tasks.AnnouncementPeriodicTaskFactory; @@ -413,13 +413,14 @@ public class TrackRecordingService extends Service { return -1L; } - boolean isStatistics = waypointCreationRequest.getType() == WaypointType.STATISTICS; + WaypointType waypointType = waypointCreationRequest.getType(); + boolean isStatistics = waypointType == WaypointType.STATISTICS; String name; if (waypointCreationRequest.getName() != null) { name = waypointCreationRequest.getName(); } else { int nextWaypointNumber = myTracksProviderUtils.getNextWaypointNumber( - recordingTrackId, isStatistics); + recordingTrackId, waypointType); if (nextWaypointNumber == -1) { nextWaypointNumber = 0; } @@ -448,7 +449,6 @@ public class TrackRecordingService extends Service { : ""; String icon = getString( isStatistics ? R.string.marker_statistics_icon_url : R.string.marker_waypoint_icon_url); - int type = isStatistics ? Waypoint.TYPE_STATISTICS : Waypoint.TYPE_WAYPOINT; long duration; double length; Location location = getLastValidTrackPointInCurrentSegment(recordingTrackId); @@ -467,7 +467,7 @@ public class TrackRecordingService extends Service { length = 0; duration = 0; } - Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, type, + Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, waypointType, length, duration, -1L, -1L, location, tripStatistics); Uri uri = myTracksProviderUtils.insertWaypoint(waypoint); return Long.parseLong(uri.getLastPathSegment()); @@ -592,7 +592,7 @@ public class TrackRecordingService extends Service { trackTripStatisticsUpdater = new TripStatisticsUpdater(tripStatistics.getStartTime()); long markerStartTime; - Waypoint waypoint = myTracksProviderUtils.getLastStatisticsWaypoint(recordingTrackId); + Waypoint waypoint = myTracksProviderUtils.getLastWaypoint(recordingTrackId, WaypointType.STATISTICS); if (waypoint != null && waypoint.getTripStatistics() != null) { markerStartTime = waypoint.getTripStatistics().getStopTime(); } else { diff --git a/MyTracksLib/.settings/org.eclipse.jdt.core.prefs b/MyTracksLib/.settings/org.eclipse.jdt.core.prefs index a46bd1b8b..aca2544a7 100644 --- a/MyTracksLib/.settings/org.eclipse.jdt.core.prefs +++ b/MyTracksLib/.settings/org.eclipse.jdt.core.prefs @@ -1,14 +1,5 @@ -#Tue Jul 17 10:23:25 PDT 2012 eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning org.eclipse.jdt.core.compiler.problem.deadCode=warning @@ -17,7 +8,6 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled org.eclipse.jdt.core.compiler.problem.fieldHiding=warning @@ -74,7 +64,6 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=1585 org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field.count_dependent=1585|-1|1585 diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java index 9c101f386..db82735b7 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java @@ -16,6 +16,8 @@ package com.google.android.apps.mytracks.content; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; + import android.content.Context; import android.database.Cursor; import android.location.Location; @@ -126,28 +128,28 @@ public interface MyTracksProviderUtils { /** * Gets the first waypoint id for a track. The first waypoint is special as it - * contains the stats for the current segment. Returns -1L if it doesn't - * exist. + * contains the stats for the track. Returns -1L if it doesn't exist. * * @param trackId the track id */ public long getFirstWaypointId(long trackId); /** - * Gets the last statistics waypoint for a track. Returns null if it doesn't exist. + * Gets the last waypoint for a type. Returns null if it doesn't exist. * * @param trackId the track id + * @param waypointType the waypoint type */ - public Waypoint getLastStatisticsWaypoint(long trackId); + public Waypoint getLastWaypoint(long trackId, WaypointType waypointType); /** - * Gets the next waypoint number. Returns -1 if not able to get the next + * Gets the next waypoint number for a type. Returns -1 if not able to get the next * waypoint number. * * @param trackId the track id - * @param statistics true for statistics marker, false for waypoint marker + * @param waypointType the waypoint type */ - public int getNextWaypointNumber(long trackId, boolean statistics); + public int getNextWaypointNumber(long trackId, WaypointType waypointType); /** * Gets a waypoint from a waypoint id. Returns null if not found. diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java index 8eabdf7f6..ddebefaa8 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java @@ -17,6 +17,7 @@ package com.google.android.apps.mytracks.content; import com.google.android.apps.mytracks.content.Sensor.SensorDataSet; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.protobuf.InvalidProtocolBufferException; @@ -350,7 +351,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { waypoint.setTrackId(cursor.getLong(trackIdIndex)); } if (!cursor.isNull(typeIndex)) { - waypoint.setType(cursor.getInt(typeIndex)); + waypoint.setType(WaypointType.values()[cursor.getInt(typeIndex)]); } if (!cursor.isNull(lengthIndex)) { waypoint.setLength(cursor.getFloat(lengthIndex)); @@ -439,7 +440,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { @Override public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator) { final Waypoint waypoint = getWaypoint(waypointId); - if (waypoint != null && waypoint.getType() == Waypoint.TYPE_STATISTICS + if (waypoint != null && waypoint.getType() == WaypointType.STATISTICS && descriptionGenerator != null) { final Waypoint nextWaypoint = getNextStatisticsWaypointAfter(waypoint); if (nextWaypoint == null) { @@ -479,15 +480,15 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { } @Override - public Waypoint getLastStatisticsWaypoint(long trackId) { + public Waypoint getLastWaypoint(long trackId, WaypointType waypointType) { if (trackId < 0) { return null; } Cursor cursor = null; try { - String selection = WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns.TYPE + "=" - + Waypoint.TYPE_STATISTICS; - String[] selectionArgs = new String[] { Long.toString(trackId) }; + String selection = WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns.TYPE + "=?"; + String[] selectionArgs = new String[] { + Long.toString(trackId), Integer.toString(waypointType.ordinal()) }; cursor = getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID + " DESC", 1); if (cursor != null && cursor.moveToFirst()) { return createWaypoint(cursor); @@ -501,7 +502,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { } @Override - public int getNextWaypointNumber(long trackId, boolean statistics) { + public int getNextWaypointNumber(long trackId, WaypointType waypointType) { if (trackId < 0) { return -1; } @@ -509,8 +510,8 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { try { String[] projection = { WaypointsColumns._ID }; String selection = WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns.TYPE + "=?"; - int type = statistics ? Waypoint.TYPE_STATISTICS : Waypoint.TYPE_WAYPOINT; - String[] selectionArgs = new String[] { Long.toString(trackId), Integer.toString(type) }; + String[] selectionArgs = new String[] { + Long.toString(trackId), Integer.toString(waypointType.ordinal()) }; cursor = getWaypointCursor(projection, selection, selectionArgs, WaypointsColumns._ID, -1); if (cursor != null) { int count = cursor.getCount(); @@ -518,7 +519,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { * For statistics markers, the first marker is for the track statistics, * so return the count as the next user visible number. */ - return statistics ? count : count + 1; + return waypointType == WaypointType.STATISTICS ? count : count + 1; } } finally { if (cursor != null) { @@ -597,7 +598,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { values.put(WaypointsColumns.CATEGORY, waypoint.getCategory()); values.put(WaypointsColumns.ICON, waypoint.getIcon()); values.put(WaypointsColumns.TRACKID, waypoint.getTrackId()); - values.put(WaypointsColumns.TYPE, waypoint.getType()); + values.put(WaypointsColumns.TYPE, waypoint.getType().ordinal()); values.put(WaypointsColumns.LENGTH, waypoint.getLength()); values.put(WaypointsColumns.DURATION, waypoint.getDuration()); values.put(WaypointsColumns.STARTID, waypoint.getStartId()); @@ -644,7 +645,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { Cursor cursor = null; try { String selection = WaypointsColumns._ID + ">? AND " + WaypointsColumns.TRACKID + "=? AND " - + WaypointsColumns.TYPE + "=" + Waypoint.TYPE_STATISTICS; + + WaypointsColumns.TYPE + "=" + WaypointType.STATISTICS.ordinal(); String[] selectionArgs = new String[] { Long.toString(waypoint.getId()), Long.toString(waypoint.getTrackId()) }; cursor = getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID, 1); diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/Waypoint.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/Waypoint.java index 166905a6a..f9a97888f 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/Waypoint.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/Waypoint.java @@ -30,8 +30,9 @@ import android.os.Parcelable; */ public final class Waypoint implements Parcelable { - public static final int TYPE_WAYPOINT = 0; - public static final int TYPE_STATISTICS = 1; + public static enum WaypointType { + WAYPOINT, STATISTICS; + } private long id = -1L; private String name = ""; @@ -39,7 +40,7 @@ public final class Waypoint implements Parcelable { private String category = ""; private String icon = ""; private long trackId = -1L; - private int type = 0; + private WaypointType type = WaypointType.WAYPOINT; private double length = 0.0; private long duration = 0; private long startId = -1L; @@ -50,7 +51,7 @@ public final class Waypoint implements Parcelable { public Waypoint() {} public Waypoint(String name, String description, String category, String icon, long trackId, - int type, double length, long duration, long startId, long stopId, Location location, + WaypointType type, double length, long duration, long startId, long stopId, Location location, TripStatistics tripStatistics) { this.name = name; this.description = description; @@ -73,7 +74,7 @@ public final class Waypoint implements Parcelable { category = source.readString(); icon = source.readString(); trackId = source.readLong(); - type = source.readInt(); + type = WaypointType.values()[source.readInt()]; length = source.readDouble(); duration = source.readLong(); startId = source.readLong(); @@ -103,7 +104,7 @@ public final class Waypoint implements Parcelable { dest.writeString(category); dest.writeString(icon); dest.writeLong(trackId); - dest.writeInt(type); + dest.writeInt(type.ordinal()); dest.writeDouble(length); dest.writeLong(duration); dest.writeLong(startId); @@ -178,11 +179,11 @@ public final class Waypoint implements Parcelable { this.trackId = trackId; } - public int getType() { + public WaypointType getType() { return type; } - public void setType(int type) { + public void setType(WaypointType type) { this.type = type; } diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java index aabf08c97..82b238020 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/WaypointCreationRequest.java @@ -15,6 +15,8 @@ */ package com.google.android.apps.mytracks.content; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; + import android.os.Parcel; import android.os.Parcelable; @@ -25,10 +27,6 @@ import android.os.Parcelable; */ public class WaypointCreationRequest implements Parcelable { - public static enum WaypointType { - WAYPOINT, STATISTICS; - } - private WaypointType type; // true if this marker contains the track statistics private boolean isTrackStatistics; diff --git a/MyTracksTest/.settings/org.eclipse.jdt.core.prefs b/MyTracksTest/.settings/org.eclipse.jdt.core.prefs index 2c72e774c..85ecb6db7 100644 --- a/MyTracksTest/.settings/org.eclipse.jdt.core.prefs +++ b/MyTracksTest/.settings/org.eclipse.jdt.core.prefs @@ -1,13 +1,5 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning org.eclipse.jdt.core.compiler.problem.deadCode=warning @@ -16,7 +8,6 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled org.eclipse.jdt.core.compiler.problem.fieldHiding=warning @@ -74,7 +65,6 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.processAnnotations=enabled -org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=1585 org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field.count_dependent=1585|-1|1585 diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImplTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImplTest.java index ebb2721fc..afc4130aa 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImplTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImplTest.java @@ -17,6 +17,7 @@ package com.google.android.apps.mytracks.content; import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationFactory; import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.services.TrackRecordingServiceTest.MockContext; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.testing.mocking.AndroidMock; @@ -365,7 +366,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { // Insert at first. Waypoint waypoint = new Waypoint(); waypoint.setDescription(TEST_DESC); - waypoint.setType(Waypoint.TYPE_STATISTICS); + waypoint.setType(WaypointType.STATISTICS); waypoint.setTripStatistics(statistics); Location loc = new Location("test"); @@ -442,7 +443,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { Waypoint waypoint1 = new Waypoint(); waypoint1.setDescription(TEST_DESC); waypoint1.setTrackId(trackId); - waypoint1.setType(Waypoint.TYPE_STATISTICS); + waypoint1.setType(WaypointType.STATISTICS); providerUtils.insertWaypoint(waypoint1); // Delete @@ -491,13 +492,13 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { Waypoint waypoint1 = new Waypoint(); waypoint1.setDescription(Long.toString(trackId)); waypoint1.setTrackId(trackId); - waypoint1.setType(Waypoint.TYPE_STATISTICS); + waypoint1.setType(WaypointType.STATISTICS); waypoint1.setTripStatistics(statistics); providerUtils.insertWaypoint(waypoint1); Waypoint waypoint2 = new Waypoint(); waypoint2.setDescription(Long.toString(trackId)); waypoint2.setTrackId(trackId); - waypoint2.setType(Waypoint.TYPE_STATISTICS); + waypoint2.setType(WaypointType.STATISTICS); waypoint2.setTripStatistics(statistics); providerUtils.insertWaypoint(waypoint2); @@ -541,7 +542,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { } /** - * Tests the method {@link MyTracksProviderUtilsImpl#getNextWaypointNumber(long, boolean)}. + * Tests the method {@link MyTracksProviderUtilsImpl#getNextWaypointNumber(long, WaypointType)}. */ public void testGetNextWaypointNumber() { long trackId = System.currentTimeMillis(); @@ -549,29 +550,29 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { providerUtils.insertTrack(track); Waypoint waypoint1 = new Waypoint(); - waypoint1.setType(Waypoint.TYPE_STATISTICS); + waypoint1.setType(WaypointType.STATISTICS); waypoint1.setTrackId(trackId); Waypoint waypoint2 = new Waypoint(); - waypoint2.setType(Waypoint.TYPE_WAYPOINT); + waypoint2.setType(WaypointType.WAYPOINT); waypoint2.setTrackId(trackId); Waypoint waypoint3 = new Waypoint(); - waypoint3.setType(Waypoint.TYPE_STATISTICS); + waypoint3.setType(WaypointType.STATISTICS); waypoint3.setTrackId(trackId); Waypoint waypoint4 = new Waypoint(); - waypoint4.setType(Waypoint.TYPE_WAYPOINT); + waypoint4.setType(WaypointType.WAYPOINT); waypoint4.setTrackId(trackId); providerUtils.insertWaypoint(waypoint1); providerUtils.insertWaypoint(waypoint2); providerUtils.insertWaypoint(waypoint3); providerUtils.insertWaypoint(waypoint4); - assertEquals(2, providerUtils.getNextWaypointNumber(trackId, true)); - assertEquals(3, providerUtils.getNextWaypointNumber(trackId, false)); + assertEquals(2, providerUtils.getNextWaypointNumber(trackId, WaypointType.STATISTICS)); + assertEquals(3, providerUtils.getNextWaypointNumber(trackId, WaypointType.WAYPOINT)); } /** * Tests the method - * {@link MyTracksProviderUtils#getLastStatisticsWaypoint(long)}. + * {@link MyTracksProviderUtils#getLastWaypoint(long, WaypointType)}. */ public void testGetLastStatisticsWaypoint() { long trackId = System.currentTimeMillis(); @@ -580,21 +581,21 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { Waypoint waypoint1 = new Waypoint(); waypoint1.setTrackId(trackId); - waypoint1.setType(Waypoint.TYPE_STATISTICS); + waypoint1.setType(WaypointType.STATISTICS); waypoint1.setDescription("Desc1"); Waypoint waypoint2 = new Waypoint(); waypoint2.setTrackId(trackId); - waypoint2.setType(Waypoint.TYPE_STATISTICS); + waypoint2.setType(WaypointType.STATISTICS); waypoint2.setDescription("Desc2"); Waypoint waypoint3 = new Waypoint(); waypoint3.setTrackId(trackId); - waypoint3.setType(Waypoint.TYPE_WAYPOINT); + waypoint3.setType(WaypointType.WAYPOINT); waypoint3.setDescription("Desc3"); providerUtils.insertWaypoint(waypoint1); providerUtils.insertWaypoint(waypoint2); providerUtils.insertWaypoint(waypoint3); - assertEquals("Desc2", providerUtils.getLastStatisticsWaypoint(trackId).getDescription()); + assertEquals("Desc2", providerUtils.getLastWaypoint(trackId, WaypointType.STATISTICS).getDescription()); } /** diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/content/WaypointCreationRequestTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/content/WaypointCreationRequestTest.java index cfe308cf7..7d15be8ba 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/content/WaypointCreationRequestTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/content/WaypointCreationRequestTest.java @@ -15,7 +15,7 @@ */ package com.google.android.apps.mytracks.content; -import com.google.android.apps.mytracks.content.WaypointCreationRequest.WaypointType; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import android.os.Parcel; import android.test.AndroidTestCase; diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java index fb8c96071..0195fc5b0 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/services/TrackRecordingServiceTest.java @@ -22,6 +22,7 @@ import com.google.android.apps.mytracks.content.MyTracksProvider; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Waypoint; +import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.content.WaypointCreationRequest; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.util.ApiAdapterFactory; @@ -532,7 +533,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase