diff --git a/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java index f4ded6ad9..1026c1660 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MarkerEditActivity.java @@ -114,12 +114,12 @@ public class MarkerEditActivity extends AbstractMyTracksActivity { if (newMarker) { statisticsSection.setVisibility(View.GONE); waypointSection.setVisibility(View.VISIBLE); - int nextMarkerNumber = trackId == -1L ? -1 - : MyTracksProviderUtils.Factory.get(this).getNextMarkerNumber(trackId, false); - if (nextMarkerNumber == -1) { - nextMarkerNumber = 0; + int nextWaypointNumber = trackId == -1L ? -1 + : MyTracksProviderUtils.Factory.get(this).getNextWaypointNumber(trackId, false); + if (nextWaypointNumber == -1) { + nextWaypointNumber = 0; } - waypointName.setText(getString(R.string.marker_name_format, nextMarkerNumber)); + waypointName.setText(getString(R.string.marker_name_format, nextWaypointNumber)); waypointName.selectAll(); waypointMarkerType.setText(""); waypointDescription.setText(""); diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java index abefb3733..1dc6fafcb 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java @@ -125,7 +125,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity { Button cancel = (Button) findViewById(R.id.track_edit_cancel); if (getIntent().getBooleanExtra(EXTRA_NEW_TRACK, false)) { String trackName = TrackNameUtils.getTrackName( - this, -1L, -1L, myTracksProviderUtils.getLastValidTrackLocation(trackId)); + this, -1L, -1L, myTracksProviderUtils.getLastValidTrackPoint(trackId)); if (trackName != null) { name.setText(trackName); } diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/SearchEngine.java b/MyTracks/src/com/google/android/apps/mytracks/content/SearchEngine.java index 46fd69172..b1ec32f49 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/content/SearchEngine.java +++ b/MyTracks/src/com/google/android/apps/mytracks/content/SearchEngine.java @@ -186,7 +186,7 @@ public class SearchEngine { queryLikeSelection, queryLikeSelection }; - Cursor tracksCursor = providerUtils.getTracksCursor( + Cursor tracksCursor = providerUtils.getTrackCursor( TRACK_SELECTION_QUERY, trackSelectionArgs, TRACK_SELECTION_ORDER); if (tracksCursor != null) { try { @@ -213,21 +213,21 @@ public class SearchEngine { queryLikeSelection2, queryLikeSelection2, queryLikeSelection2 }; - Cursor waypointsCursor = providerUtils.getWaypointsCursor( + Cursor waypointCursor = providerUtils.getWaypointCursor( WAYPOINT_SELECTION_QUERY, waypointSelectionArgs, WAYPOINT_SELECTION_ORDER, MAX_SCORED_WAYPOINTS); - if (waypointsCursor != null) { + if (waypointCursor != null) { try { - waypoints.ensureCapacity(waypointsCursor.getCount()); + waypoints.ensureCapacity(waypointCursor.getCount()); - while (waypointsCursor.moveToNext()) { - Waypoint waypoint = providerUtils.createWaypoint(waypointsCursor); + while (waypointCursor.moveToNext()) { + Waypoint waypoint = providerUtils.createWaypoint(waypointCursor); if (LocationUtils.isValidLocation(waypoint.getLocation())) { waypoints.add(waypoint); } } } finally { - waypointsCursor.close(); + waypointCursor.close(); } } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java b/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java index 5bf6be832..6e68a31d5 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java +++ b/MyTracks/src/com/google/android/apps/mytracks/content/TrackDataHub.java @@ -563,7 +563,7 @@ public class TrackDataHub implements DataSourceListener { Cursor cursor = null; try { - cursor = myTracksProviderUtils.getWaypointsCursor( + cursor = myTracksProviderUtils.getWaypointCursor( selectedTrackId, 0L, MAX_DISPLAYED_WAYPOINTS_POINTS); if (cursor != null && cursor.moveToFirst()) { do { @@ -614,9 +614,9 @@ public class TrackDataHub implements DataSourceListener { long localLastSeenLocationId = updateSamplingState ? lastSeenLocationId : -1L; long maxPointId = updateSamplingState ? -1L : lastSeenLocationId; - long lastLocationId = myTracksProviderUtils.getLastTrackLocationId(selectedTrackId); + long lastTrackPointId = myTracksProviderUtils.getLastTrackPointId(selectedTrackId); int samplingFrequency = -1; - LocationIterator iterator = myTracksProviderUtils.getLocationIterator( + LocationIterator iterator = myTracksProviderUtils.getTrackPointLocationIterator( selectedTrackId, localLastSeenLocationId + 1, false, locationFactory); boolean includeNextPoint = false; while (iterator.hasNext()) { @@ -633,7 +633,7 @@ public class TrackDataHub implements DataSourceListener { } if (samplingFrequency == -1) { - long numTotalPoints = Math.max(0L, lastLocationId - localFirstSeenLocationId); + long numTotalPoints = Math.max(0L, lastTrackPointId - localFirstSeenLocationId); samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints); } @@ -646,7 +646,7 @@ public class TrackDataHub implements DataSourceListener { } else { // Also include the last point if the selected track is not recording. if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0) - || (locationId == lastLocationId && !isSelectedTrackRecording())) { + || (locationId == lastTrackPointId && !isSelectedTrackRecording())) { includeNextPoint = false; for (TrackDataListener trackDataListener : sampledInListeners) { trackDataListener.onSampledInTrackPoint(location); 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 8059b1057..7eb074127 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 @@ -506,7 +506,7 @@ public class GpxImporter extends DefaultHandler { if (numBufferedPointInserts <= 0) { return; } - myTracksProviderUtils.bulkInsertTrackPoints( + myTracksProviderUtils.bulkInsertTrackPoint( bufferedPointInserts, numBufferedPointInserts, track.getId()); numBufferedPointInserts = 0; } @@ -528,7 +528,7 @@ public class GpxImporter extends DefaultHandler { */ private long getLastPointId() { flushPoints(); - return myTracksProviderUtils.getLastTrackLocationId(track.getId()); + return myTracksProviderUtils.getLastTrackPointId(track.getId()); } /** diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveAsyncTask.java index 622594f94..9be2add93 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/SaveAsyncTask.java @@ -168,7 +168,7 @@ public class SaveAsyncTask extends AsyncTask { private Boolean saveAllTracks() { Cursor cursor = null; try { - cursor = myTracksProviderUtils.getTracksCursor(null, null, TracksColumns._ID); + cursor = myTracksProviderUtils.getTrackCursor(null, null, TracksColumns._ID); if (cursor == null) { messageId = R.string.sd_card_save_error_no_track; return false; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriterImpl.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriterImpl.java index e7fe59768..0a1dadbc4 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriterImpl.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/TrackWriterImpl.java @@ -245,7 +245,7 @@ class TrackWriterImpl implements TrackWriter { // problem because we don't try to load them into objects all at the // same time. Cursor cursor = null; - cursor = providerUtils.getWaypointsCursor(trackId, 0, + cursor = providerUtils.getWaypointCursor(trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS); boolean hasWaypoints = false; if (cursor != null) { @@ -314,7 +314,7 @@ class TrackWriterImpl implements TrackWriter { }; TrackWriterLocationFactory locationFactory = new TrackWriterLocationFactory(); - LocationIterator it = providerUtils.getLocationIterator(track.getId(), 0, false, + LocationIterator it = providerUtils.getTrackPointLocationIterator(track.getId(), 0, false, locationFactory); try { if (!it.hasNext()) { 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 0afa56da0..508e9cf69 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 @@ -208,20 +208,20 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask { * @return true if success. */ private boolean uploadAllTrackPoints(Track track) { - Cursor locationsCursor = null; + Cursor cursor = null; try { - locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false); - if (locationsCursor == null) { + cursor = myTracksProviderUtils.getTrackPointCursor(trackId, 0, -1, false); + if (cursor == null) { Log.d(TAG, "Location cursor is null"); return false; } - int locationsCount = locationsCursor.getCount(); + int count = cursor.getCount(); List locations = new ArrayList(MAX_POINTS_PER_UPLOAD); Location lastLocation = null; // For chart server, limit the number of elevation readings to 250. - int elevationSamplingFrequency = Math.max(1, (int) (locationsCount / 250.0)); + int elevationSamplingFrequency = Math.max(1, (int) (count / 250.0)); Vector distances = new Vector(); Vector elevations = new Vector(); TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder( @@ -229,10 +229,10 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask { int minRecordingDistance = PreferencesUtils.getInt(context, R.string.min_recording_distance_key, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT); - for (int i = 0; i < locationsCount; i++) { - locationsCursor.moveToPosition(i); + for (int i = 0; i < count; i++) { + cursor.moveToPosition(i); - Location location = myTracksProviderUtils.createLocation(locationsCursor); + Location location = myTracksProviderUtils.createTrackPoint(cursor); locations.add(location); if (i == 0) { @@ -260,7 +260,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask { Log.d(TAG, "Unable to upload points"); return false; } - updateProgress(readCount, locationsCount); + updateProgress(readCount, count); locations.clear(); } } @@ -287,8 +287,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask { return true; } finally { - if (locationsCursor != null) { - locationsCursor.close(); + if (cursor != null) { + cursor.close(); } } } @@ -328,7 +328,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask { private boolean uploadWaypoints() { Cursor cursor = null; try { - cursor = myTracksProviderUtils.getWaypointsCursor( + cursor = myTracksProviderUtils.getWaypointCursor( trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS); if (cursor != null && cursor.moveToFirst()) { // This will skip the first waypoint (it carries the stats for the 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 5e00b08f0..590cd54fc 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 @@ -251,20 +251,20 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask { */ @VisibleForTesting boolean uploadAllTrackPoints(Track track) { - Cursor locationsCursor = null; + Cursor cursor = null; try { - locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false); - if (locationsCursor == null) { + cursor = myTracksProviderUtils.getTrackPointCursor(trackId, 0, -1, false); + if (cursor == null) { Log.d(TAG, "Location cursor is null"); return false; } - int locationsCount = locationsCursor.getCount(); + int count = cursor.getCount(); List locations = new ArrayList(MAX_POINTS_PER_UPLOAD); Location lastLocation = null; // For chart server, limit the number of elevation readings to 250. - int elevationSamplingFrequency = Math.max(1, (int) (locationsCount / 250.0)); + int elevationSamplingFrequency = Math.max(1, (int) (count / 250.0)); Vector distances = new Vector(); Vector elevations = new Vector(); TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder( @@ -272,10 +272,10 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask { int minRecordingDistance = PreferencesUtils.getInt(context, R.string.min_recording_distance_key, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT); - for (int i = 0; i < locationsCount; i++) { - locationsCursor.moveToPosition(i); + for (int i = 0; i < count; i++) { + cursor.moveToPosition(i); - Location location = myTracksProviderUtils.createLocation(locationsCursor); + Location location = myTracksProviderUtils.createTrackPoint(cursor); locations.add(location); if (i == 0) { @@ -303,7 +303,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask { Log.d(TAG, "Unable to upload points"); return false; } - updateProgress(readCount, locationsCount); + updateProgress(readCount, count); locations.clear(); } } @@ -329,8 +329,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask { } return true; } finally { - if (locationsCursor != null) { - locationsCursor.close(); + if (cursor != null) { + cursor.close(); } } } @@ -436,7 +436,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask { boolean uploadWaypoints() { Cursor cursor = null; try { - cursor = myTracksProviderUtils.getWaypointsCursor( + cursor = myTracksProviderUtils.getWaypointCursor( trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS); if (cursor != null && cursor.moveToFirst()) { // This will skip the first waypoint (it carries the stats for the 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 c842ad76e..740121ca1 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -419,14 +419,14 @@ public class TrackRecordingService extends Service { if (waypointCreationRequest.getName() != null) { name = waypointCreationRequest.getName(); } else { - int nextMarkerNumber = myTracksProviderUtils.getNextMarkerNumber( + int nextWaypointNumber = myTracksProviderUtils.getNextWaypointNumber( recordingTrackId, isStatistics); - if (nextMarkerNumber == -1) { - nextMarkerNumber = 0; + if (nextWaypointNumber == -1) { + nextWaypointNumber = 0; } name = getString( isStatistics ? R.string.marker_split_name_format : R.string.marker_name_format, - nextMarkerNumber); + nextWaypointNumber); } TripStatistics tripStatistics; @@ -452,8 +452,8 @@ public class TrackRecordingService extends Service { int type = isStatistics ? Waypoint.TYPE_STATISTICS : Waypoint.TYPE_WAYPOINT; long duration; double length; - Location lastTrackLocation = myTracksProviderUtils.getLastTrackLocation(recordingTrackId); - if (currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackLocation) + Location lastTrackPoint = myTracksProviderUtils.getLastTrackPoint(recordingTrackId); + if (currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackPoint) && trackTripStatisticsBuilder != null) { TripStatistics stats = trackTripStatisticsBuilder.getTripStatistics(); length = stats.getTotalDistance(); @@ -463,14 +463,14 @@ public class TrackRecordingService extends Service { return -1L; } // For track statistics, make it an impossible location - lastTrackLocation = new Location(""); - lastTrackLocation.setLatitude(100); - lastTrackLocation.setLongitude(180); + lastTrackPoint = new Location(""); + lastTrackPoint.setLatitude(100); + lastTrackPoint.setLongitude(180); length = 0; duration = 0; } Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, type, - length, duration, -1L, -1L, lastTrackLocation, tripStatistics); + length, duration, -1L, -1L, lastTrackPoint, tripStatistics); Uri uri = myTracksProviderUtils.insertWaypoint(waypoint); return Long.parseLong(uri.getLastPathSegment()); } @@ -605,14 +605,14 @@ public class TrackRecordingService extends Service { Cursor cursor = null; try { // TODO: how to handle very long track. - cursor = myTracksProviderUtils.getLocationsCursor( + cursor = myTracksProviderUtils.getTrackPointCursor( recordingTrackId, -1, Constants.MAX_LOADED_TRACK_POINTS, true); if (cursor == null) { Log.e(TAG, "Cursor is null."); } else { if (cursor.moveToLast()) { do { - Location location = myTracksProviderUtils.createLocation(cursor); + Location location = myTracksProviderUtils.createTrackPoint(cursor); trackTripStatisticsBuilder.addLocation(location, minRecordingDistance); if (location.getTime() > markerStartTime) { markerTripStatisticsBuilder.addLocation(location, minRecordingDistance); @@ -701,8 +701,8 @@ public class TrackRecordingService extends Service { // Update database Track track = myTracksProviderUtils.getTrack(trackId); if (track != null) { - insertLocation(track, lastLocation, myTracksProviderUtils.getLastTrackLocation(trackId)); - updateRecordingTrack(track, myTracksProviderUtils.getLastTrackLocationId(trackId), false); + insertLocation(track, lastLocation, myTracksProviderUtils.getLastTrackPoint(trackId)); + updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false); } endRecording(true, trackId); @@ -726,7 +726,7 @@ public class TrackRecordingService extends Service { Track track = myTracksProviderUtils.getTrack(recordingTrackId); if (track != null) { insertLocation( - track, lastLocation, myTracksProviderUtils.getLastTrackLocation(track.getId())); + track, lastLocation, myTracksProviderUtils.getLastTrackPoint(track.getId())); Location pause = new Location(LocationManager.GPS_PROVIDER); pause.setLongitude(0); @@ -809,9 +809,9 @@ public class TrackRecordingService extends Service { return; } - Location lastTrackLocation = myTracksProviderUtils.getLastTrackLocation(track.getId()); - long idleTime = currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackLocation) ? - location.getTime() - lastTrackLocation.getTime() + Location lastTrackPoint = myTracksProviderUtils.getLastTrackPoint(track.getId()); + long idleTime = currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackPoint) ? + location.getTime() - lastTrackPoint.getTime() : 0L; locationListenerPolicy.updateIdleTime(idleTime); if (currentRecordingInterval != locationListenerPolicy.getDesiredPollingInterval()) { @@ -825,41 +825,41 @@ public class TrackRecordingService extends Service { // Always insert the first segment location if (!currentSegmentHasLocation) { - insertLocation(track, location, lastTrackLocation); + insertLocation(track, location, lastTrackPoint); currentSegmentHasLocation = true; lastLocation = location; return; } - if (!LocationUtils.isValidLocation(lastTrackLocation)) { + if (!LocationUtils.isValidLocation(lastTrackPoint)) { /* * Should not happen. The current segment should have a location. Just * insert the current location. */ - insertLocation(track, location, lastTrackLocation); + insertLocation(track, location, lastTrackPoint); lastLocation = location; return; } - double distanceToLastTrackLocation = location.distanceTo(lastTrackLocation); + double distanceToLastTrackLocation = location.distanceTo(lastTrackPoint); if (distanceToLastTrackLocation < minRecordingDistance && sensorDataSet == null) { Log.d(TAG, "Not recording location due to min recording distance."); } else if (distanceToLastTrackLocation > maxRecordingDistance) { - insertLocation(track, lastLocation, lastTrackLocation); + insertLocation(track, lastLocation, lastTrackPoint); Location pause = new Location(LocationManager.GPS_PROVIDER); pause.setLongitude(0); pause.setLatitude(PAUSE_LATITUDE); pause.setTime(lastLocation.getTime()); insertLocation(track, pause, null); - insertLocation(track, location, lastTrackLocation); + insertLocation(track, location, lastTrackPoint); } else { /* * (distanceToLastTrackLocation >= minRecordingDistance || * hasSensorData) && distanceToLastTrackLocation <= maxRecordingDistance */ - insertLocation(track, lastLocation, lastTrackLocation); - insertLocation(track, location, lastTrackLocation); + insertLocation(track, lastLocation, lastTrackPoint); + insertLocation(track, location, lastTrackPoint); } lastLocation = location; } catch (Error e) { 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 a17c7bec2..b3604bef9 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtils.java @@ -39,14 +39,23 @@ public interface MyTracksProviderUtils { public static final String AUTHORITY = "com.google.android.maps.mytracks"; /** - * Gets a track cursor. The caller owns the returned cursor and is responsible - * for closing it. + * Creates a {@link Track} from a cursor. * - * @param selection the selection - * @param selectionArgs the selection arguments - * @param sortOrder the sort order + * @param cursor the cursor pointing to the track */ - public Cursor getTracksCursor(String selection, String[] selectionArgs, String sortOrder); + public Track createTrack(Cursor cursor); + + /** + * Deletes all tracks (including waypoints and track points). + */ + public void deleteAllTracks(); + + /** + * Deletes a track. + * + * @param trackId the track id + */ + public void deleteTrack(long trackId); /** * Gets all the tracks. If no track exists, an empty list is returned. @@ -55,6 +64,11 @@ public interface MyTracksProviderUtils { */ public List getAllTracks(); + /** + * Gets the last track. Returns null if doesn't exist. + */ + public Track getLastTrack(); + /** * Gets a track by a track id. Returns null if not found. *

@@ -65,9 +79,14 @@ public interface MyTracksProviderUtils { public Track getTrack(long trackId); /** - * Gets the last track. Returns null if doesn't exist. + * Gets a track cursor. The caller owns the returned cursor and is responsible + * for closing it. + * + * @param selection the selection + * @param selectionArgs the selection arguments + * @param sortOrder the sort order */ - public Track getLastTrack(); + public Cursor getTrackCursor(String selection, String[] selectionArgs, String sortOrder); /** * Inserts a track. @@ -89,45 +108,21 @@ public interface MyTracksProviderUtils { public void updateTrack(Track track); /** - * Deletes all tracks (including waypoints and track points). + * Creates a waypoint from a cursor. + * + * @param cursor the cursor pointing to the waypoint */ - public void deleteAllTracks(); + public Waypoint createWaypoint(Cursor cursor); /** - * Deletes a track. + * Deletes a waypoint. If deleting a statistics waypoint, this will also + * correct the next statistics waypoint after the deleted one to reflect the + * deletion. The generator is used to update the next statistics waypoint. * - * @param trackId the track id + * @param waypointId the waypoint id + * @param descriptionGenerator the description generator */ - public void deleteTrack(long trackId); - - /** - * Creates a {@link Track} from a cursor. - * - * @param cursor the cursor pointing to the track - */ - public Track createTrack(Cursor cursor); - - /** - * Gets a waypoint cursor. The caller owns the returned cursor and is - * responsible for closing it. - * - * @param selection the selection - * @param selectionArgs the selection arguments - * @param sortOrder the sort order - * @param maxWaypoints the maximum number of waypoints to return - */ - public Cursor getWaypointsCursor( - String selection, String[] selectionArgs, String sortOrder, int maxWaypoints); - - /** - * Gets a waypoint cursor for a track. The caller owns the returned cursor and - * is responsible for closing it. - * - * @param trackId the track id - * @param minWaypointId the minimum waypoint id - * @param maxWaypoints the maximum number of waypoints to return - */ - public Cursor getWaypointsCursor(long trackId, long minWaypointId, int maxWaypoints); + public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator); /** * Gets the first waypoint id for a track. The first waypoint is special as it @@ -144,15 +139,15 @@ public interface MyTracksProviderUtils { * @param trackId the track id */ public Waypoint getLastStatisticsWaypoint(long trackId); - + /** - * Gets the next marker number. Returns -1 if not able to get the next marker - * number. + * Gets the next waypoint number. 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 */ - public int getNextMarkerNumber(long trackId, boolean statistics); + public int getNextWaypointNumber(long trackId, boolean statistics); /** * Gets a waypoint from a waypoint id. Returns null if not found. @@ -161,6 +156,28 @@ public interface MyTracksProviderUtils { */ public Waypoint getWaypoint(long waypointId); + /** + * Gets a waypoint cursor. The caller owns the returned cursor and is + * responsible for closing it. + * + * @param selection the selection + * @param selectionArgs the selection arguments + * @param sortOrder the sort order + * @param maxWaypoints the maximum number of waypoints to return + */ + public Cursor getWaypointCursor( + String selection, String[] selectionArgs, String sortOrder, int maxWaypoints); + + /** + * Gets a waypoint cursor for a track. The caller owns the returned cursor and + * is responsible for closing it. + * + * @param trackId the track id + * @param minWaypointId the minimum waypoint id + * @param maxWaypoints the maximum number of waypoints to return + */ + public Cursor getWaypointCursor(long trackId, long minWaypointId, int maxWaypoints); + /** * Inserts a waypoint. * @@ -177,21 +194,43 @@ public interface MyTracksProviderUtils { public boolean updateWaypoint(Waypoint waypoint); /** - * Deletes a waypoint. If deleting a statistics waypoint, this will also - * correct the next statistics waypoint after the deleted one to reflect the - * deletion. The generator is used to update the next statistics waypoint. + * Inserts multiple track points. * - * @param waypointId the waypoint id - * @param descriptionGenerator the description generator + * @param locations an array of locations + * @param length the number of locations (from the beginning of the array) to + * insert, or -1 for all of them + * @param trackId the track id + * @return the number of points inserted */ - public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator); + public int bulkInsertTrackPoint(Location[] locations, int length, long trackId); /** - * Creates a waypoint from a cursor. + * Creates a location object from a cursor. * - * @param cursor the cursor pointing to the waypoint + * @param cursor the cursor pointing to the location */ - public Waypoint createWaypoint(Cursor cursor); + public Location createTrackPoint(Cursor cursor); + + /** + * Gets the last location for a track. Returns null if it doesn't exist. + * + * @param trackId the track id + */ + public Location getLastTrackPoint(long trackId); + + /** + * Gets the last location id for a track. Returns -1L if it doesn't exist. + * + * @param trackId the track id + */ + public long getLastTrackPointId(long trackId); + + /** + * Gets the last valid location for a track. Returns null if it doesn't exist. + * + * @param trackId the track id + */ + public Location getLastValidTrackPoint(long trackId); /** * Creates a location cursor. The caller owns the returned cursor and is @@ -203,7 +242,7 @@ public interface MyTracksProviderUtils { * @param descending true to sort the result in descending order (latest * location first) */ - public Cursor getLocationsCursor( + public Cursor getTrackPointCursor( long trackId, long startTrackPointId, int maxLocations, boolean descending); /** @@ -224,30 +263,9 @@ public interface MyTracksProviderUtils { * location first) * @param locationFactory the location factory */ - public LocationIterator getLocationIterator( + public LocationIterator getTrackPointLocationIterator( long trackId, long startTrackPointId, boolean descending, LocationFactory locationFactory); - /** - * Gets the last location id for a track. Returns -1L if it doesn't exist. - * - * @param trackId the track id - */ - public long getLastTrackLocationId(long trackId); - - /** - * Gets the last location for a track. Returns null if it doesn't exist. - * - * @param trackId the track id - */ - public Location getLastTrackLocation(long trackId); - - /** - * Gets the last valid location for a track. Returns null if it doesn't exist. - * - * @param trackId the track id - */ - public Location getLastValidTrackLocation(long trackId); - /** * Inserts a track point. * @@ -257,24 +275,6 @@ public interface MyTracksProviderUtils { */ public Uri insertTrackPoint(Location location, long trackId); - /** - * Inserts multiple track points. - * - * @param locations an array of locations - * @param length the number of locations (from the beginning of the array) to - * insert, or -1 for all of them - * @param trackId the track id - * @return the number of points inserted - */ - public int bulkInsertTrackPoints(Location[] locations, int length, long trackId); - - /** - * Creates a location object from a cursor. - * - * @param cursor the cursor pointing to the location - */ - public Location createLocation(Cursor cursor); - /** * A lightweight wrapper around the original {@link Cursor} with a method to * clean up. 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 232de80a8..5fca8d080 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java @@ -47,114 +47,6 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { this.contentResolver = contentResolver; } - /** - * Gets a track cursor. - * - * @param projection the projection - * @param selection the selection - * @param selectionArgs the selection arguments - * @param sortOrder the sort oder - */ - private Cursor getTracksCursor( - String[] projection, String selection, String[] selectionArgs, String sortOrder) { - return contentResolver.query( - TracksColumns.CONTENT_URI, projection, selection, selectionArgs, sortOrder); - } - - @Override - public Cursor getTracksCursor(String selection, String[] selectionArgs, String sortOrder) { - return getTracksCursor(null, selection, selectionArgs, sortOrder); - } - - @Override - public List getAllTracks() { - Cursor cursor = getTracksCursor(null, null, null, TracksColumns._ID); - ArrayList tracks = new ArrayList(); - if (cursor != null) { - tracks.ensureCapacity(cursor.getCount()); - if (cursor.moveToFirst()) { - do { - tracks.add(createTrack(cursor)); - } while (cursor.moveToNext()); - } - cursor.close(); - } - return tracks; - } - - @Override - public Track getTrack(long trackId) { - if (trackId < 0) { - return null; - } - Cursor cursor = null; - try { - cursor = getTracksCursor(null, TracksColumns._ID + "=?", - new String[] { Long.toString(trackId) }, TracksColumns._ID); - if (cursor != null && cursor.moveToNext()) { - return createTrack(cursor); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return null; - } - - @Override - public Track getLastTrack() { - Cursor cursor = null; - try { - String selection = TracksColumns._ID + "=(select max(" + TracksColumns._ID + ") from " - + TracksColumns.TABLE_NAME + ")"; - cursor = getTracksCursor(null, selection, null, TracksColumns._ID); - if (cursor != null && cursor.moveToNext()) { - return createTrack(cursor); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return null; - } - - @Override - public Uri insertTrack(Track track) { - return contentResolver.insert(TracksColumns.CONTENT_URI, createContentValues(track)); - } - - @Override - public void updateTrack(Track track) { - contentResolver.update(TracksColumns.CONTENT_URI, createContentValues(track), - TracksColumns._ID + "=?", new String[] { Long.toString(track.getId()) }); - } - - @Override - public void deleteAllTracks() { - contentResolver.delete(TrackPointsColumns.CONTENT_URI, null, null); - contentResolver.delete(WaypointsColumns.CONTENT_URI, null, null); - // Delete tracks last since it triggers a database vaccum call - contentResolver.delete(TracksColumns.CONTENT_URI, null, null); - } - - @Override - public void deleteTrack(long trackId) { - Track track = getTrack(trackId); - if (track != null) { - String where = TrackPointsColumns._ID + ">=? AND " + TrackPointsColumns._ID + "<=?"; - String[] selectionArgs = new String[] { Long.toString(track.getStartId()), Long.toString( - track.getStopId()) }; - contentResolver.delete(TrackPointsColumns.CONTENT_URI, where, selectionArgs); - } - contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns.TRACKID + "=?", - new String[] { Long.toString(trackId) }); - // Delete tracks last since it triggers a database vaccum call - contentResolver.delete(TracksColumns.CONTENT_URI, TracksColumns._ID + "=?", new String[] { - Long.toString(trackId) }); - } - @Override public Track createTrack(Cursor cursor) { int idIndex = cursor.getColumnIndexOrThrow(TracksColumns._ID); @@ -182,7 +74,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { int mapIdIndex = cursor.getColumnIndexOrThrow(TracksColumns.MAPID); int tableIdIndex = cursor.getColumnIndexOrThrow(TracksColumns.TABLEID); int iconIndex = cursor.getColumnIndexOrThrow(TracksColumns.ICON); - + Track track = new Track(); TripStatistics tripStatistics = track.getTripStatistics(); if (!cursor.isNull(idIndex)) { @@ -259,6 +151,100 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { return track; } + @Override + public void deleteAllTracks() { + contentResolver.delete(TrackPointsColumns.CONTENT_URI, null, null); + contentResolver.delete(WaypointsColumns.CONTENT_URI, null, null); + // Delete tracks last since it triggers a database vaccum call + contentResolver.delete(TracksColumns.CONTENT_URI, null, null); + } + + @Override + public void deleteTrack(long trackId) { + Track track = getTrack(trackId); + if (track != null) { + String where = TrackPointsColumns._ID + ">=? AND " + TrackPointsColumns._ID + "<=?"; + String[] selectionArgs = new String[] { Long.toString(track.getStartId()), Long.toString( + track.getStopId()) }; + contentResolver.delete(TrackPointsColumns.CONTENT_URI, where, selectionArgs); + } + contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns.TRACKID + "=?", + new String[] { Long.toString(trackId) }); + // Delete tracks last since it triggers a database vaccum call + contentResolver.delete(TracksColumns.CONTENT_URI, TracksColumns._ID + "=?", new String[] { + Long.toString(trackId) }); + } + + @Override + public List getAllTracks() { + Cursor cursor = getTrackCursor(null, null, null, TracksColumns._ID); + ArrayList tracks = new ArrayList(); + if (cursor != null) { + tracks.ensureCapacity(cursor.getCount()); + if (cursor.moveToFirst()) { + do { + tracks.add(createTrack(cursor)); + } while (cursor.moveToNext()); + } + cursor.close(); + } + return tracks; + } + + @Override + public Track getLastTrack() { + Cursor cursor = null; + try { + String selection = TracksColumns._ID + "=(select max(" + TracksColumns._ID + ") from " + + TracksColumns.TABLE_NAME + ")"; + cursor = getTrackCursor(null, selection, null, TracksColumns._ID); + if (cursor != null && cursor.moveToNext()) { + return createTrack(cursor); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return null; + } + + @Override + public Track getTrack(long trackId) { + if (trackId < 0) { + return null; + } + Cursor cursor = null; + try { + cursor = getTrackCursor(null, TracksColumns._ID + "=?", + new String[] { Long.toString(trackId) }, TracksColumns._ID); + if (cursor != null && cursor.moveToNext()) { + return createTrack(cursor); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return null; + } + + @Override + public Cursor getTrackCursor(String selection, String[] selectionArgs, String sortOrder) { + return getTrackCursor(null, selection, selectionArgs, sortOrder); + } + + @Override + public Uri insertTrack(Track track) { + return contentResolver.insert(TracksColumns.CONTENT_URI, createContentValues(track)); + } + + @Override + public void updateTrack(Track track) { + contentResolver.update(TracksColumns.CONTENT_URI, createContentValues(track), + TracksColumns._ID + "=?", new String[] { Long.toString(track.getId()) }); + } + private ContentValues createContentValues(Track track) { ContentValues values = new ContentValues(); TripStatistics tripStatistics = track.getTripStatistics(); @@ -297,192 +283,17 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { } /** - * Gets a waypoints cursor. + * Gets a track cursor. * * @param projection the projection * @param selection the selection - * @param selectionArgs the selection args - * @param sortOrder the sort order - * @param maxWaypoints the maximum number of waypoints + * @param selectionArgs the selection arguments + * @param sortOrder the sort oder */ - private Cursor getWaypointsCursor(String[] projection, String selection, String[] selectionArgs, - String sortOrder, int maxWaypoints) { - if (sortOrder == null) { - sortOrder = WaypointsColumns._ID; - } - if (maxWaypoints > 0) { - sortOrder += " LIMIT " + maxWaypoints; - } + private Cursor getTrackCursor( + String[] projection, String selection, String[] selectionArgs, String sortOrder) { return contentResolver.query( - WaypointsColumns.CONTENT_URI, projection, selection, selectionArgs, sortOrder); - } - - @Override - public Cursor getWaypointsCursor( - String selection, String[] selectionArgs, String sortOrder, int maxWaypoints) { - return getWaypointsCursor(null, selection, selectionArgs, sortOrder, maxWaypoints); - } - - @Override - public Cursor getWaypointsCursor(long trackId, long minWaypointId, int maxWaypoints) { - if (trackId < 0) { - return null; - } - - String selection; - String[] selectionArgs; - if (minWaypointId >= 0) { - selection = WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + ">=?"; - selectionArgs = new String[] { Long.toString(trackId), Long.toString(minWaypointId) }; - } else { - selection = WaypointsColumns.TRACKID + "=?"; - selectionArgs = new String[] { Long.toString(trackId) }; - } - return getWaypointsCursor(null, selection, selectionArgs, WaypointsColumns._ID, maxWaypoints); - } - - @Override - public long getFirstWaypointId(long trackId) { - if (trackId < 0) { - return -1L; - } - Cursor cursor = null; - try { - cursor = getWaypointsCursor(new String[] { WaypointsColumns._ID }, - WaypointsColumns.TRACKID + "=?", new String[] { Long.toString(trackId) }, - WaypointsColumns._ID, 1); - if (cursor != null && cursor.moveToFirst()) { - return cursor.getLong(cursor.getColumnIndexOrThrow(WaypointsColumns._ID)); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return -1L; - } - - @Override - public Waypoint getLastStatisticsWaypoint(long trackId) { - 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) }; - cursor = getWaypointsCursor( - null, selection, selectionArgs, WaypointsColumns._ID + " DESC", 1); - if (cursor != null && cursor.moveToFirst()) { - return createWaypoint(cursor); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return null; - } - - @Override - public int getNextMarkerNumber(long trackId, boolean statistics) { - if (trackId < 0) { - return -1; - } - Cursor cursor = null; - 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) }; - cursor = getWaypointsCursor(projection, selection, selectionArgs, WaypointsColumns._ID, 0); - if (cursor != null) { - int count = cursor.getCount(); - /* - * 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; - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return -1; - } - - private Waypoint getNextStatisticsWaypointAfter(Waypoint waypoint) { - Cursor cursor = null; - try { - String selection = WaypointsColumns._ID + ">? AND " + WaypointsColumns.TRACKID + "=? AND " - + WaypointsColumns.TYPE + "=" + Waypoint.TYPE_STATISTICS; - String[] selectionArgs = new String[] { - Long.toString(waypoint.getId()), Long.toString(waypoint.getTrackId()) }; - cursor = getWaypointsCursor(null, selection, selectionArgs, WaypointsColumns._ID, 1); - if (cursor != null && cursor.moveToFirst()) { - return createWaypoint(cursor); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return null; - } - - @Override - public Waypoint getWaypoint(long waypointId) { - if (waypointId < 0) { - return null; - } - Cursor cursor = null; - try { - cursor = getWaypointsCursor(null, WaypointsColumns._ID + "=?", - new String[] { Long.toString(waypointId) }, WaypointsColumns._ID, 0); - if (cursor != null && cursor.moveToFirst()) { - return createWaypoint(cursor); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return null; - } - - @Override - public Uri insertWaypoint(Waypoint waypoint) { - waypoint.setId(-1L); - return contentResolver.insert(WaypointsColumns.CONTENT_URI, createContentValues(waypoint)); - } - - @Override - public boolean updateWaypoint(Waypoint waypoint) { - int rows = contentResolver.update(WaypointsColumns.CONTENT_URI, createContentValues(waypoint), - WaypointsColumns._ID + "=?", new String[] { Long.toString(waypoint.getId()) }); - return rows == 1; - } - - @Override - public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator) { - final Waypoint waypoint = getWaypoint(waypointId); - if (waypoint != null && waypoint.getType() == Waypoint.TYPE_STATISTICS) { - final Waypoint nextWaypoint = getNextStatisticsWaypointAfter(waypoint); - if (nextWaypoint == null) { - Log.d(TAG, "Unable to find the next statistics marker after deleting one."); - } else { - nextWaypoint.getTripStatistics().merge(waypoint.getTripStatistics()); - nextWaypoint.setDescription( - descriptionGenerator.generateWaypointDescription(nextWaypoint.getTripStatistics())); - if (!updateWaypoint(nextWaypoint)) { - Log.e(TAG, "Unable to update the next statistics marker after deleting one."); - } - } - } - contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns._ID + "=?", - new String[] { Long.toString(waypointId) }); + TracksColumns.CONTENT_URI, projection, selection, selectionArgs, sortOrder); } @Override @@ -515,9 +326,9 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { int elevationGainIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.ELEVATIONGAIN); int minGradeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.MINGRADE); int maxGradeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.MAXGRADE); - + Waypoint waypoint = new Waypoint(); - + if (!cursor.isNull(idIndex)) { waypoint.setId(cursor.getLong(idIndex)); } @@ -551,7 +362,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { if (!cursor.isNull(stopIdIndex)) { waypoint.setStopId(cursor.getLong(stopIdIndex)); } - + Location location = new Location(""); if (!cursor.isNull(longitudeIndex) && !cursor.isNull(latitudeIndex)) { location.setLongitude(((double) cursor.getInt(longitudeIndex)) / 1E6); @@ -573,7 +384,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { location.setBearing(cursor.getFloat(bearingIndex)); } waypoint.setLocation(location); - + TripStatistics tripStatistics = new TripStatistics(); boolean hasTripStatistics = false; if (!cursor.isNull(startTimeIndex)) { @@ -616,16 +427,165 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { tripStatistics.setMaxGrade(cursor.getFloat(maxGradeIndex)); hasTripStatistics = true; } - + if (hasTripStatistics) { waypoint.setTripStatistics(tripStatistics); } return waypoint; } + @Override + public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator) { + final Waypoint waypoint = getWaypoint(waypointId); + if (waypoint != null && waypoint.getType() == Waypoint.TYPE_STATISTICS) { + final Waypoint nextWaypoint = getNextStatisticsWaypointAfter(waypoint); + if (nextWaypoint == null) { + Log.d(TAG, "Unable to find the next statistics marker after deleting one."); + } else { + nextWaypoint.getTripStatistics().merge(waypoint.getTripStatistics()); + nextWaypoint.setDescription( + descriptionGenerator.generateWaypointDescription(nextWaypoint.getTripStatistics())); + if (!updateWaypoint(nextWaypoint)) { + Log.e(TAG, "Unable to update the next statistics marker after deleting one."); + } + } + } + contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns._ID + "=?", + new String[] { Long.toString(waypointId) }); + } + + @Override + public long getFirstWaypointId(long trackId) { + if (trackId < 0) { + return -1L; + } + Cursor cursor = null; + try { + cursor = getWaypointCursor(new String[] { WaypointsColumns._ID }, + WaypointsColumns.TRACKID + "=?", new String[] { Long.toString(trackId) }, + WaypointsColumns._ID, 1); + if (cursor != null && cursor.moveToFirst()) { + return cursor.getLong(cursor.getColumnIndexOrThrow(WaypointsColumns._ID)); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return -1L; + } + + @Override + public Waypoint getLastStatisticsWaypoint(long trackId) { + 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) }; + cursor = getWaypointCursor( + null, selection, selectionArgs, WaypointsColumns._ID + " DESC", 1); + if (cursor != null && cursor.moveToFirst()) { + return createWaypoint(cursor); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return null; + } + + @Override + public int getNextWaypointNumber(long trackId, boolean statistics) { + if (trackId < 0) { + return -1; + } + Cursor cursor = null; + 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) }; + cursor = getWaypointCursor(projection, selection, selectionArgs, WaypointsColumns._ID, 0); + if (cursor != null) { + int count = cursor.getCount(); + /* + * 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; + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return -1; + } + + @Override + public Waypoint getWaypoint(long waypointId) { + if (waypointId < 0) { + return null; + } + Cursor cursor = null; + try { + cursor = getWaypointCursor(null, WaypointsColumns._ID + "=?", + new String[] { Long.toString(waypointId) }, WaypointsColumns._ID, 0); + if (cursor != null && cursor.moveToFirst()) { + return createWaypoint(cursor); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return null; + } + + @Override + public Cursor getWaypointCursor( + String selection, String[] selectionArgs, String sortOrder, int maxWaypoints) { + return getWaypointCursor(null, selection, selectionArgs, sortOrder, maxWaypoints); + } + + @Override + public Cursor getWaypointCursor(long trackId, long minWaypointId, int maxWaypoints) { + if (trackId < 0) { + return null; + } + + String selection; + String[] selectionArgs; + if (minWaypointId >= 0) { + selection = WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + ">=?"; + selectionArgs = new String[] { Long.toString(trackId), Long.toString(minWaypointId) }; + } else { + selection = WaypointsColumns.TRACKID + "=?"; + selectionArgs = new String[] { Long.toString(trackId) }; + } + return getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID, maxWaypoints); + } + + @Override + public Uri insertWaypoint(Waypoint waypoint) { + waypoint.setId(-1L); + return contentResolver.insert(WaypointsColumns.CONTENT_URI, createContentValues(waypoint)); + } + + @Override + public boolean updateWaypoint(Waypoint waypoint) { + int rows = contentResolver.update(WaypointsColumns.CONTENT_URI, createContentValues(waypoint), + WaypointsColumns._ID + "=?", new String[] { Long.toString(waypoint.getId()) }); + return rows == 1; + } + ContentValues createContentValues(Waypoint waypoint) { ContentValues values = new ContentValues(); - + // Value < 0 indicates no id is available if (waypoint.getId() >= 0) { values.put(WaypointsColumns._ID, waypoint.getId()); @@ -640,7 +600,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { values.put(WaypointsColumns.DURATION, waypoint.getDuration()); values.put(WaypointsColumns.STARTID, waypoint.getStartId()); values.put(WaypointsColumns.STOPID, waypoint.getStopId()); - + Location location = waypoint.getLocation(); if (location != null) { values.put(WaypointsColumns.LONGITUDE, (int) (location.getLongitude() * 1E6)); @@ -659,7 +619,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { values.put(WaypointsColumns.BEARING, location.getBearing()); } } - + TripStatistics tripStatistics = waypoint.getTripStatistics(); if (tripStatistics != null) { values.put(WaypointsColumns.STARTTIME, tripStatistics.getStartTime()); @@ -678,26 +638,16 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { return values; } - /** - * Gets a track points cursor. - * - * @param projection the projection - * @param selection the selection - * @param selectionArgs the selection arguments - * @param sortOrder the sort order - */ - private Cursor getTrackPointsCursor( - String[] projection, String selection, String[] selectionArgs, String sortOrder) { - return contentResolver.query( - TrackPointsColumns.CONTENT_URI, projection, selection, selectionArgs, sortOrder); - } - - private Location findLocationBy(String selection, String[] selectionArgs) { + private Waypoint getNextStatisticsWaypointAfter(Waypoint waypoint) { Cursor cursor = null; try { - cursor = getTrackPointsCursor(null, selection, selectionArgs, TrackPointsColumns._ID); - if (cursor != null && cursor.moveToNext()) { - return createLocation(cursor); + String selection = WaypointsColumns._ID + ">? AND " + WaypointsColumns.TRACKID + "=? AND " + + WaypointsColumns.TYPE + "=" + Waypoint.TYPE_STATISTICS; + String[] selectionArgs = new String[] { + Long.toString(waypoint.getId()), Long.toString(waypoint.getTrackId()) }; + cursor = getWaypointCursor(null, selection, selectionArgs, WaypointsColumns._ID, 1); + if (cursor != null && cursor.moveToFirst()) { + return createWaypoint(cursor); } } finally { if (cursor != null) { @@ -707,13 +657,100 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { return null; } + /** + * Gets a waypoint cursor. + * + * @param projection the projection + * @param selection the selection + * @param selectionArgs the selection args + * @param sortOrder the sort order + * @param maxWaypoints the maximum number of waypoints + */ + private Cursor getWaypointCursor(String[] projection, String selection, String[] selectionArgs, + String sortOrder, int maxWaypoints) { + if (sortOrder == null) { + sortOrder = WaypointsColumns._ID; + } + if (maxWaypoints > 0) { + sortOrder += " LIMIT " + maxWaypoints; + } + return contentResolver.query( + WaypointsColumns.CONTENT_URI, projection, selection, selectionArgs, sortOrder); + } + @Override - public Cursor getLocationsCursor( + public int bulkInsertTrackPoint(Location[] locations, int length, long trackId) { + if (length == -1) { + length = locations.length; + } + ContentValues[] values = new ContentValues[length]; + for (int i = 0; i < length; i++) { + values[i] = createContentValues(locations[i], trackId); + } + return contentResolver.bulkInsert(TrackPointsColumns.CONTENT_URI, values); + } + + @Override + public Location createTrackPoint(Cursor cursor) { + Location location = new MyTracksLocation(""); + fillTrackPoint(cursor, new CachedTrackPointsIndexes(cursor), location); + return location; + } + + @Override + public Location getLastTrackPoint(long trackId) { + if (trackId < 0) { + return null; + } + String selection = TrackPointsColumns._ID + "=(select max(" + TrackPointsColumns._ID + ") from " + + TrackPointsColumns.TABLE_NAME + " WHERE " + TrackPointsColumns.TRACKID + "=?)"; + String[] selectionArgs = new String[] { Long.toString(trackId) }; + return findTrackPointBy(selection, selectionArgs); + } + + @Override + public long getLastTrackPointId(long trackId) { + if (trackId < 0) { + return -1L; + } + Cursor cursor = null; + try { + String selection = TrackPointsColumns._ID + "=(select max(" + TrackPointsColumns._ID + + ") from " + TrackPointsColumns.TABLE_NAME + " WHERE " + TrackPointsColumns.TRACKID + + "=?)"; + String[] selectionArgs = new String[] { Long.toString(trackId) }; + cursor = getTrackPointCursor(new String[] { TrackPointsColumns._ID }, selection, + selectionArgs, TrackPointsColumns._ID); + if (cursor != null && cursor.moveToFirst()) { + return cursor.getLong(cursor.getColumnIndexOrThrow(TrackPointsColumns._ID)); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return -1L; + } + + @Override + public Location getLastValidTrackPoint(long trackId) { + if (trackId < 0) { + return null; + } + String selection = TrackPointsColumns._ID + "=(select max(" + TrackPointsColumns._ID + ") from " + + TrackPointsColumns.TABLE_NAME + " WHERE " + TrackPointsColumns.TRACKID + "=? AND " + + TrackPointsColumns.LATITUDE + "<=90000000)"; + String[] selectionArgs = new String[] { Long.toString(trackId) }; + return findTrackPointBy(selection, selectionArgs); + } + + @Override + public Cursor getTrackPointCursor( long trackId, long startTrackPointId, int maxLocations, boolean descending) { if (trackId < 0) { return null; } - + String selection; String[] selectionArgs; if (startTrackPointId >= 0) { @@ -725,7 +762,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { selection = TrackPointsColumns.TRACKID + "=?"; selectionArgs = new String[] { Long.toString(trackId) }; } - + String sortOrder = TrackPointsColumns._ID; if (descending) { sortOrder += " DESC"; @@ -733,11 +770,11 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { if (maxLocations > 0) { sortOrder += " LIMIT " + maxLocations; } - return getTrackPointsCursor(null, selection, selectionArgs, sortOrder); + return getTrackPointCursor(null, selection, selectionArgs, sortOrder); } @Override - public LocationIterator getLocationIterator(final long trackId, final long startTrackPointId, + public LocationIterator getTrackPointLocationIterator(final long trackId, final long startTrackPointId, final boolean descending, final LocationFactory locationFactory) { if (locationFactory == null) { throw new IllegalArgumentException("locationFactory is null"); @@ -748,16 +785,16 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { private final CachedTrackPointsIndexes indexes = cursor != null ? new CachedTrackPointsIndexes(cursor) : null; - + /** * Gets the track point cursor. * * @param trackPointId the starting track point id */ private Cursor getCursor(long trackPointId) { - return getLocationsCursor(trackId, trackPointId, defaultCursorBatchSize, descending); + return getTrackPointCursor(trackId, trackPointId, defaultCursorBatchSize, descending); } - + /** * Advances the cursor to the next batch. Returns true if successful. */ @@ -769,12 +806,12 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { cursor = getCursor(trackPointId); return cursor != null; } - + @Override public long getLocationId() { return lastTrackPointId; } - + @Override public boolean hasNext() { if (cursor == null) { @@ -791,7 +828,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { } return true; } - + @Override public Location next() { if (cursor == null) { @@ -804,10 +841,10 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { } lastTrackPointId = cursor.getLong(indexes.idIndex); Location location = locationFactory.createLocation(); - fillLocation(cursor, indexes, location); + fillTrackPoint(cursor, indexes, location); return location; } - + @Override public void close() { if (cursor != null) { @@ -815,7 +852,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { cursor = null; } } - + @Override public void remove() { throw new UnsupportedOperationException(); @@ -823,81 +860,62 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { }; } - @Override - public long getLastTrackLocationId(long trackId) { - if (trackId < 0) { - return -1L; - } - Cursor cursor = null; - try { - String selection = TrackPointsColumns._ID + "=(select max(" + TrackPointsColumns._ID - + ") from " + TrackPointsColumns.TABLE_NAME + " WHERE " + TrackPointsColumns.TRACKID - + "=?)"; - String[] selectionArgs = new String[] { Long.toString(trackId) }; - cursor = getTrackPointsCursor(new String[] { TrackPointsColumns._ID }, selection, - selectionArgs, TrackPointsColumns._ID); - if (cursor != null && cursor.moveToFirst()) { - return cursor.getLong(cursor.getColumnIndexOrThrow(TrackPointsColumns._ID)); - } - } finally { - if (cursor != null) { - cursor.close(); - } - } - return -1L; - } - - @Override - public Location getLastTrackLocation(long trackId) { - if (trackId < 0) { - return null; - } - String selection = TrackPointsColumns._ID + "=(select max(" + TrackPointsColumns._ID + ") from " - + TrackPointsColumns.TABLE_NAME + " WHERE " + TrackPointsColumns.TRACKID + "=?)"; - String[] selectionArgs = new String[] { Long.toString(trackId) }; - return findLocationBy(selection, selectionArgs); - } - - @Override - public Location getLastValidTrackLocation(long trackId) { - if (trackId < 0) { - return null; - } - String selection = TrackPointsColumns._ID + "=(select max(" + TrackPointsColumns._ID + ") from " - + TrackPointsColumns.TABLE_NAME + " WHERE " + TrackPointsColumns.TRACKID + "=? AND " - + TrackPointsColumns.LATITUDE + "<=90000000)"; - String[] selectionArgs = new String[] { Long.toString(trackId) }; - return findLocationBy(selection, selectionArgs); - } - @Override public Uri insertTrackPoint(Location location, long trackId) { return contentResolver.insert( TrackPointsColumns.CONTENT_URI, createContentValues(location, trackId)); } - @Override - public int bulkInsertTrackPoints(Location[] locations, int length, long trackId) { - if (length == -1) { - length = locations.length; + /** + * Creates the {@link ContentValues} for a {@link Location}. + * + * @param location the location + * @param trackId the track id + */ + private ContentValues createContentValues(Location location, long trackId) { + ContentValues values = new ContentValues(); + values.put(TrackPointsColumns.TRACKID, trackId); + values.put(TrackPointsColumns.LONGITUDE, (int) (location.getLongitude() * 1E6)); + values.put(TrackPointsColumns.LATITUDE, (int) (location.getLatitude() * 1E6)); + + // Hack for Samsung phones that don't properly populate the time field + long time = location.getTime(); + if (time == 0) { + time = System.currentTimeMillis(); } - ContentValues[] values = new ContentValues[length]; - for (int i = 0; i < length; i++) { - values[i] = createContentValues(locations[i], trackId); + values.put(TrackPointsColumns.TIME, time); + if (location.hasAltitude()) { + values.put(TrackPointsColumns.ALTITUDE, location.getAltitude()); } - return contentResolver.bulkInsert(TrackPointsColumns.CONTENT_URI, values); + if (location.hasAccuracy()) { + values.put(TrackPointsColumns.ACCURACY, location.getAccuracy()); + } + if (location.hasSpeed()) { + values.put(TrackPointsColumns.SPEED, location.getSpeed()); + } + if (location.hasBearing()) { + values.put(TrackPointsColumns.BEARING, location.getBearing()); + } + + if (location instanceof MyTracksLocation) { + MyTracksLocation myTracksLocation = (MyTracksLocation) location; + if (myTracksLocation.getSensorDataSet() != null) { + values.put(TrackPointsColumns.SENSOR, myTracksLocation.getSensorDataSet().toByteArray()); + } + } + return values; } /** - * Fills a location from a cursor. + * Fills a track point from a cursor. * * @param cursor the cursor pointing to a location. * @param indexes the cached track points indexes - * @param location the location + * @param location the track point */ - private void fillLocation(Cursor cursor, CachedTrackPointsIndexes indexes, Location location) { + private void fillTrackPoint(Cursor cursor, CachedTrackPointsIndexes indexes, Location location) { location.reset(); - + if (!cursor.isNull(indexes.longitudeIndex)) { location.setLongitude(((double) cursor.getInt(indexes.longitudeIndex)) / 1E6); } @@ -930,51 +948,33 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { } } - @Override - public Location createLocation(Cursor cursor) { - Location location = new MyTracksLocation(""); - fillLocation(cursor, new CachedTrackPointsIndexes(cursor), location); - return location; + private Location findTrackPointBy(String selection, String[] selectionArgs) { + Cursor cursor = null; + try { + cursor = getTrackPointCursor(null, selection, selectionArgs, TrackPointsColumns._ID); + if (cursor != null && cursor.moveToNext()) { + return createTrackPoint(cursor); + } + } finally { + if (cursor != null) { + cursor.close(); + } + } + return null; } /** - * Creates the {@link ContentValues} for a {@link Location}. + * Gets a track point cursor. * - * @param location the location - * @param trackId the track id + * @param projection the projection + * @param selection the selection + * @param selectionArgs the selection arguments + * @param sortOrder the sort order */ - private ContentValues createContentValues(Location location, long trackId) { - ContentValues values = new ContentValues(); - values.put(TrackPointsColumns.TRACKID, trackId); - values.put(TrackPointsColumns.LONGITUDE, (int) (location.getLongitude() * 1E6)); - values.put(TrackPointsColumns.LATITUDE, (int) (location.getLatitude() * 1E6)); - - // Hack for Samsung phones that don't properly populate the time field - long time = location.getTime(); - if (time == 0) { - time = System.currentTimeMillis(); - } - values.put(TrackPointsColumns.TIME, time); - if (location.hasAltitude()) { - values.put(TrackPointsColumns.ALTITUDE, location.getAltitude()); - } - if (location.hasAccuracy()) { - values.put(TrackPointsColumns.ACCURACY, location.getAccuracy()); - } - if (location.hasSpeed()) { - values.put(TrackPointsColumns.SPEED, location.getSpeed()); - } - if (location.hasBearing()) { - values.put(TrackPointsColumns.BEARING, location.getBearing()); - } - - if (location instanceof MyTracksLocation) { - MyTracksLocation myTracksLocation = (MyTracksLocation) location; - if (myTracksLocation.getSensorDataSet() != null) { - values.put(TrackPointsColumns.SENSOR, myTracksLocation.getSensorDataSet().toByteArray()); - } - } - return values; + private Cursor getTrackPointCursor( + String[] projection, String selection, String[] selectionArgs, String sortOrder) { + return contentResolver.query( + TrackPointsColumns.CONTENT_URI, projection, selection, selectionArgs, sortOrder); } /** 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 b6c070717..969c88483 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImplTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImplTest.java @@ -127,7 +127,8 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { long lastPointId = initializeTrack(trackId, numPoints); ((MyTracksProviderUtilsImpl) providerUtils).setDefaultCursorBatchSize(batchSize); List locations = new ArrayList(numPoints); - LocationIterator it = providerUtils.getLocationIterator(trackId, -1, descending, locationFactory); + LocationIterator it = providerUtils.getTrackPointLocationIterator( + trackId, -1, descending, locationFactory); try { while (it.hasNext()) { Location loc = it.next(); @@ -162,12 +163,12 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { loc.setAltitude(i * 2.5); locations[i] = loc; } - providerUtils.bulkInsertTrackPoints(locations, numPoints, id); + providerUtils.bulkInsertTrackPoint(locations, numPoints, id); // Load all inserted locations. long lastPointId = -1; int counter = 0; - LocationIterator it = providerUtils.getLocationIterator(id, -1, false, + LocationIterator it = providerUtils.getTrackPointLocationIterator(id, -1, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); try { while (it.hasNext()) { @@ -187,51 +188,36 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { } /** - * Tests the method {@link MyTracksProviderUtilsImpl#getAllTracks()} + * Tests the method {@link MyTracksProviderUtilsImpl#createTrack(Cursor)}. */ - public void testGetAllTracks() { - int initialTrackNumber = providerUtils.getAllTracks().size(); + @UsesMocks(Cursor.class) + public void testCreateTrack() { + Cursor cursorMock = AndroidMock.createNiceMock(Cursor.class); + int startColumnIndex = 1; + int columnIndex = startColumnIndex; + AndroidMock.expect(cursorMock.getColumnIndexOrThrow(TracksColumns._ID)) + .andReturn(columnIndex++); + AndroidMock.expect(cursorMock.getColumnIndexOrThrow(TracksColumns.NAME)).andReturn( + columnIndex++); + columnIndex = startColumnIndex; + // Id + AndroidMock.expect(cursorMock.isNull(columnIndex++)).andReturn(false); + // Name + AndroidMock.expect(cursorMock.isNull(columnIndex++)).andReturn(false); long trackId = System.currentTimeMillis(); - providerUtils.insertTrack(getTrack(trackId, 0)); - List allTracks = providerUtils.getAllTracks(); - assertEquals(initialTrackNumber + 1, allTracks.size()); - assertEquals(trackId, allTracks.get(allTracks.size() - 1).getId()); - } - - /** - * Tests the method {@link MyTracksProviderUtilsImpl#getTrack(long)} - */ - public void testGetTrack() { - long trackId = System.currentTimeMillis(); - providerUtils.insertTrack(getTrack(trackId, 0)); - assertNotNull(providerUtils.getTrack(trackId)); - } - - /** - * Tests the method {@link MyTracksProviderUtilsImpl#getLastTrack()} - */ - public void testGetLastTrack() { - long trackId = System.currentTimeMillis(); - providerUtils.insertTrack(getTrack(trackId, 0)); - assertEquals(trackId, providerUtils.getLastTrack().getId()); + columnIndex = startColumnIndex; + // Id + AndroidMock.expect(cursorMock.getLong(columnIndex++)).andReturn(trackId); + // Name + String name = NAME_PREFIX + Long.toString(trackId); + AndroidMock.expect(cursorMock.getString(columnIndex++)).andReturn(name); + AndroidMock.replay(cursorMock); + Track track = providerUtils.createTrack(cursorMock); + assertEquals(trackId, track.getId()); + assertEquals(name, track.getName()); + AndroidMock.verify(cursorMock); } - /** - * Tests the method {@link MyTracksProviderUtilsImpl#updateTrack(Track)} - */ - public void testUpdateTrack() { - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 0); - String nameOld = "name1"; - String nameNew = "name2"; - track.setName(nameOld); - providerUtils.insertTrack(track); - assertEquals(nameOld, providerUtils.getTrack(trackId).getName()); - track.setName(nameNew); - providerUtils.updateTrack(track); - assertEquals(nameNew, providerUtils.getTrack(trackId).getName()); - } - /** * Tests the method {@link MyTracksProviderUtilsImpl#deleteAllTracks()} */ @@ -265,7 +251,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { null, WaypointsColumns._ID); assertEquals(0, waypointCursor.getCount()); } - + /** * Tests the method {@link MyTracksProviderUtilsImpl#deleteTrack(long)}. */ @@ -305,38 +291,238 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { null, WaypointsColumns._ID); assertEquals(0, waypointCursor.getCount()); } + + /** + * Tests the method {@link MyTracksProviderUtilsImpl#getAllTracks()} + */ + public void testGetAllTracks() { + int initialTrackNumber = providerUtils.getAllTracks().size(); + long trackId = System.currentTimeMillis(); + providerUtils.insertTrack(getTrack(trackId, 0)); + List allTracks = providerUtils.getAllTracks(); + assertEquals(initialTrackNumber + 1, allTracks.size()); + assertEquals(trackId, allTracks.get(allTracks.size() - 1).getId()); + } /** - * Tests the method {@link MyTracksProviderUtilsImpl#createTrack(Cursor)}. + * Tests the method {@link MyTracksProviderUtilsImpl#getLastTrack()} + */ + public void testGetLastTrack() { + long trackId = System.currentTimeMillis(); + providerUtils.insertTrack(getTrack(trackId, 0)); + assertEquals(trackId, providerUtils.getLastTrack().getId()); + } + + /** + * Tests the method {@link MyTracksProviderUtilsImpl#getTrack(long)} + */ + public void testGetTrack() { + long trackId = System.currentTimeMillis(); + providerUtils.insertTrack(getTrack(trackId, 0)); + assertNotNull(providerUtils.getTrack(trackId)); + } + + /** + * Tests the method {@link MyTracksProviderUtilsImpl#updateTrack(Track)} + */ + public void testUpdateTrack() { + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 0); + String nameOld = "name1"; + String nameNew = "name2"; + track.setName(nameOld); + providerUtils.insertTrack(track); + assertEquals(nameOld, providerUtils.getTrack(trackId).getName()); + track.setName(nameNew); + providerUtils.updateTrack(track); + assertEquals(nameNew, providerUtils.getTrack(trackId).getName()); + } + + /** + * Tests the method {@link MyTracksProviderUtilsImpl#createContentValues(Waypoint)}. + */ + public void testCreateContentValues_waypoint() { + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + providerUtils.insertTrack(track); + // Bottom + long startTime = 1000L; + // AverageSpeed + double minGrade = -20.11; + TripStatistics statistics = new TripStatistics(); + statistics.setStartTime(startTime); + statistics.setStopTime(2500L); + statistics.setTotalTime(1500L); + statistics.setMovingTime(700L); + statistics.setTotalDistance(750.0); + statistics.setTotalElevationGain(50.0); + statistics.setMaxSpeed(60.0); + statistics.setMaxElevation(1250.0); + statistics.setMinElevation(1200.0); + statistics.setMaxGrade(15.0); + statistics.setMinGrade(minGrade); + statistics.setBounds(-10000, 20000, 30000, -40000); + // Insert at first. + Waypoint waypoint = new Waypoint(); + waypoint.setDescription(TEST_DESC); + waypoint.setType(Waypoint.TYPE_STATISTICS); + waypoint.setTripStatistics(statistics); + + Location loc = new Location("test"); + loc.setLatitude(22); + loc.setLongitude(22); + loc.setAccuracy((float) 1 / 100.0f); + loc.setAltitude(2.5); + waypoint.setLocation(loc); + providerUtils.insertWaypoint(waypoint); + + MyTracksProviderUtilsImpl myTracksProviderUtilsImpl = new MyTracksProviderUtilsImpl( + new MockContentResolver()); + + long waypointId = System.currentTimeMillis(); + waypoint.setId(waypointId); + ContentValues contentValues = myTracksProviderUtilsImpl.createContentValues(waypoint); + assertEquals(waypointId, contentValues.get(WaypointsColumns._ID)); + assertEquals(22 * 1000000, contentValues.get(WaypointsColumns.LONGITUDE)); + assertEquals(TEST_DESC, contentValues.get(WaypointsColumns.DESCRIPTION)); + assertEquals(startTime, contentValues.get(WaypointsColumns.STARTTIME)); + assertEquals(minGrade, contentValues.get(WaypointsColumns.MINGRADE)); + } + + /** + * Tests the method {@link MyTracksProviderUtilsImpl#createWaypoint(Cursor)}. */ @UsesMocks(Cursor.class) - public void testCreateTrack() { + public void testCreateWaypoint() { Cursor cursorMock = AndroidMock.createNiceMock(Cursor.class); int startColumnIndex = 1; int columnIndex = startColumnIndex; - AndroidMock.expect(cursorMock.getColumnIndexOrThrow(TracksColumns._ID)) + AndroidMock.expect(cursorMock.getColumnIndexOrThrow(WaypointsColumns._ID)) .andReturn(columnIndex++); - AndroidMock.expect(cursorMock.getColumnIndexOrThrow(TracksColumns.NAME)).andReturn( + AndroidMock.expect(cursorMock.getColumnIndexOrThrow(WaypointsColumns.NAME)).andReturn( + columnIndex++); + AndroidMock.expect(cursorMock.getColumnIndexOrThrow(WaypointsColumns.TRACKID)).andReturn( columnIndex++); columnIndex = startColumnIndex; // Id AndroidMock.expect(cursorMock.isNull(columnIndex++)).andReturn(false); // Name AndroidMock.expect(cursorMock.isNull(columnIndex++)).andReturn(false); - long trackId = System.currentTimeMillis(); + // trackIdIndex + AndroidMock.expect(cursorMock.isNull(columnIndex++)).andReturn(false); + long id = System.currentTimeMillis(); columnIndex = startColumnIndex; // Id - AndroidMock.expect(cursorMock.getLong(columnIndex++)).andReturn(trackId); + AndroidMock.expect(cursorMock.getLong(columnIndex++)).andReturn(id); // Name - String name = NAME_PREFIX + Long.toString(trackId); + String name = NAME_PREFIX + Long.toString(id); AndroidMock.expect(cursorMock.getString(columnIndex++)).andReturn(name); + // trackIdIndex + long trackId = 11L; + AndroidMock.expect(cursorMock.getLong(columnIndex++)).andReturn(trackId); AndroidMock.replay(cursorMock); - Track track = providerUtils.createTrack(cursorMock); - assertEquals(trackId, track.getId()); - assertEquals(name, track.getName()); + Waypoint waypoint = providerUtils.createWaypoint(cursorMock); + assertEquals(id, waypoint.getId()); + assertEquals(name, waypoint.getName()); + assertEquals(trackId, waypoint.getTrackId()); AndroidMock.verify(cursorMock); } + /** + * Tests the method + * {@link MyTracksProviderUtilsImpl#deleteWaypoint(long, DescriptionGenerator)} + * when there is only one waypoint in the track. + */ + public void testDeleteWaypoint_onlyOneWayPoint() { + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + providerUtils.insertTrack(track); + + // Insert at first. + Waypoint waypoint1 = new Waypoint(); + waypoint1.setDescription(TEST_DESC); + waypoint1.setTrackId(trackId); + waypoint1.setType(Waypoint.TYPE_STATISTICS); + providerUtils.insertWaypoint(waypoint1); + + // Delete + DescriptionGenerator descriptionGenerator = new DescriptionGenerator() { + + @Override + public String generateWaypointDescription(TripStatistics tripStatistics) { + return MyTracksProviderUtilsImplTest.MOCK_DESC; + } + + @SuppressWarnings("hiding") + @Override + public String generateTrackDescription(Track track, Vector distances, + Vector elevations, boolean html) { + return null; + } + }; + providerUtils.deleteWaypoint(1, descriptionGenerator); + + assertNull(providerUtils.getWaypoint(1)); + } + + /** + * Tests the method + * {@link MyTracksProviderUtilsImpl#deleteWaypoint(long, DescriptionGenerator)} + * when there is more than one waypoint in the track. + */ + public void testDeleteWaypoint_hasNextWayPoint() { + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + providerUtils.insertTrack(track); + + TripStatistics statistics = new TripStatistics(); + statistics.setStartTime(1000L); + statistics.setStopTime(2500L); + statistics.setTotalTime(1500L); + statistics.setMovingTime(700L); + statistics.setTotalDistance(750.0); + statistics.setTotalElevationGain(50.0); + statistics.setMaxSpeed(60.0); + statistics.setMaxElevation(1250.0); + statistics.setMinElevation(1200.0); + statistics.setMaxGrade(15.0); + statistics.setMinGrade(-25.0); + statistics.setBounds(-10000, 20000, 30000, -40000); + // Insert at first. + Waypoint waypoint1 = new Waypoint(); + waypoint1.setDescription(Long.toString(trackId)); + waypoint1.setTrackId(trackId); + waypoint1.setType(Waypoint.TYPE_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.setTripStatistics(statistics); + providerUtils.insertWaypoint(waypoint2); + + // Delete + DescriptionGenerator descriptionGenerator = new DescriptionGenerator() { + @Override + public String generateWaypointDescription(TripStatistics tripStatistics) { + return MyTracksProviderUtilsImplTest.MOCK_DESC; + } + + @SuppressWarnings("hiding") + @Override + public String generateTrackDescription(Track track, Vector distances, + Vector elevations, boolean html) { + return null; + } + }; + providerUtils.deleteWaypoint(1, descriptionGenerator); + + assertNull(providerUtils.getWaypoint(1)); + assertEquals(MyTracksProviderUtilsImplTest.MOCK_DESC, providerUtils.getWaypoint(2) + .getDescription()); + } + /** * Tests the method {@link MyTracksProviderUtilsImpl#getFirstWaypointId(long)}. */ @@ -356,6 +542,35 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { assertEquals(1L, providerUtils.getFirstWaypointId(trackId)); } + /** + * Tests the method {@link MyTracksProviderUtilsImpl#getNextWaypointNumber(long, boolean)}. + */ + public void testGetNextWaypointNumber() { + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + providerUtils.insertTrack(track); + + Waypoint waypoint1 = new Waypoint(); + waypoint1.setType(Waypoint.TYPE_STATISTICS); + waypoint1.setTrackId(trackId); + Waypoint waypoint2 = new Waypoint(); + waypoint2.setType(Waypoint.TYPE_WAYPOINT); + waypoint2.setTrackId(trackId); + Waypoint waypoint3 = new Waypoint(); + waypoint3.setType(Waypoint.TYPE_STATISTICS); + waypoint3.setTrackId(trackId); + Waypoint waypoint4 = new Waypoint(); + waypoint4.setType(Waypoint.TYPE_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)); + } + /** * Tests the method * {@link MyTracksProviderUtils#getLastStatisticsWaypoint(long)}. @@ -384,35 +599,6 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { assertEquals("Desc2", providerUtils.getLastStatisticsWaypoint(trackId).getDescription()); } - /** - * Tests the method {@link MyTracksProviderUtilsImpl#getNextMarkerNumber(long, boolean)}. - */ - public void testGetNextMarkerNumber() { - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - providerUtils.insertTrack(track); - - Waypoint waypoint1 = new Waypoint(); - waypoint1.setType(Waypoint.TYPE_STATISTICS); - waypoint1.setTrackId(trackId); - Waypoint waypoint2 = new Waypoint(); - waypoint2.setType(Waypoint.TYPE_WAYPOINT); - waypoint2.setTrackId(trackId); - Waypoint waypoint3 = new Waypoint(); - waypoint3.setType(Waypoint.TYPE_STATISTICS); - waypoint3.setTrackId(trackId); - Waypoint waypoint4 = new Waypoint(); - waypoint4.setType(Waypoint.TYPE_WAYPOINT); - waypoint4.setTrackId(trackId); - providerUtils.insertWaypoint(waypoint1); - providerUtils.insertWaypoint(waypoint2); - providerUtils.insertWaypoint(waypoint3); - providerUtils.insertWaypoint(waypoint4); - - assertEquals(2, providerUtils.getNextMarkerNumber(trackId, true)); - assertEquals(3, providerUtils.getNextMarkerNumber(trackId, false)); - } - /** * Tests the method {@link MyTracksProviderUtilsImpl#insertWaypoint(Waypoint)} and * {@link MyTracksProviderUtilsImpl#getWaypoint(long)}. @@ -452,339 +638,22 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { /** * Tests the method - * {@link MyTracksProviderUtilsImpl#deleteWaypoint(long, DescriptionGenerator)} - * when there is only one waypoint in the track. - */ - public void testDeleteWaypoint_onlyOneWayPoint() { - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - providerUtils.insertTrack(track); - - // Insert at first. - Waypoint waypoint1 = new Waypoint(); - waypoint1.setDescription(TEST_DESC); - waypoint1.setTrackId(trackId); - waypoint1.setType(Waypoint.TYPE_STATISTICS); - providerUtils.insertWaypoint(waypoint1); - - // Delete - DescriptionGenerator descriptionGenerator = new DescriptionGenerator() { - - @Override - public String generateWaypointDescription(TripStatistics tripStatistics) { - return MyTracksProviderUtilsImplTest.MOCK_DESC; - } - - @SuppressWarnings("hiding") - @Override - public String generateTrackDescription(Track track, Vector distances, - Vector elevations, boolean html) { - return null; - } - }; - providerUtils.deleteWaypoint(1, descriptionGenerator); - - assertNull(providerUtils.getWaypoint(1)); - } - - /** - * Tests the method - * {@link MyTracksProviderUtilsImpl#deleteWaypoint(long, DescriptionGenerator)} - * when there is more than one waypoint in the track. - */ - public void testDeleteWaypoint_hasNextWayPoint() { - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - providerUtils.insertTrack(track); - - TripStatistics statistics = new TripStatistics(); - statistics.setStartTime(1000L); - statistics.setStopTime(2500L); - statistics.setTotalTime(1500L); - statistics.setMovingTime(700L); - statistics.setTotalDistance(750.0); - statistics.setTotalElevationGain(50.0); - statistics.setMaxSpeed(60.0); - statistics.setMaxElevation(1250.0); - statistics.setMinElevation(1200.0); - statistics.setMaxGrade(15.0); - statistics.setMinGrade(-25.0); - statistics.setBounds(-10000, 20000, 30000, -40000); - // Insert at first. - Waypoint waypoint1 = new Waypoint(); - waypoint1.setDescription(Long.toString(trackId)); - waypoint1.setTrackId(trackId); - waypoint1.setType(Waypoint.TYPE_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.setTripStatistics(statistics); - providerUtils.insertWaypoint(waypoint2); - - // Delete - DescriptionGenerator descriptionGenerator = new DescriptionGenerator() { - @Override - public String generateWaypointDescription(TripStatistics tripStatistics) { - return MyTracksProviderUtilsImplTest.MOCK_DESC; - } - - @SuppressWarnings("hiding") - @Override - public String generateTrackDescription(Track track, Vector distances, - Vector elevations, boolean html) { - return null; - } - }; - providerUtils.deleteWaypoint(1, descriptionGenerator); - - assertNull(providerUtils.getWaypoint(1)); - assertEquals(MyTracksProviderUtilsImplTest.MOCK_DESC, providerUtils.getWaypoint(2) - .getDescription()); - } - - /** - * Tests the method {@link MyTracksProviderUtilsImpl#createWaypoint(Cursor)}. - */ - @UsesMocks(Cursor.class) - public void testCreateWaypoint() { - Cursor cursorMock = AndroidMock.createNiceMock(Cursor.class); - int startColumnIndex = 1; - int columnIndex = startColumnIndex; - AndroidMock.expect(cursorMock.getColumnIndexOrThrow(WaypointsColumns._ID)) - .andReturn(columnIndex++); - AndroidMock.expect(cursorMock.getColumnIndexOrThrow(WaypointsColumns.NAME)).andReturn( - columnIndex++); - AndroidMock.expect(cursorMock.getColumnIndexOrThrow(WaypointsColumns.TRACKID)).andReturn( - columnIndex++); - columnIndex = startColumnIndex; - // Id - AndroidMock.expect(cursorMock.isNull(columnIndex++)).andReturn(false); - // Name - AndroidMock.expect(cursorMock.isNull(columnIndex++)).andReturn(false); - // trackIdIndex - AndroidMock.expect(cursorMock.isNull(columnIndex++)).andReturn(false); - long id = System.currentTimeMillis(); - columnIndex = startColumnIndex; - // Id - AndroidMock.expect(cursorMock.getLong(columnIndex++)).andReturn(id); - // Name - String name = NAME_PREFIX + Long.toString(id); - AndroidMock.expect(cursorMock.getString(columnIndex++)).andReturn(name); - // trackIdIndex - long trackId = 11L; - AndroidMock.expect(cursorMock.getLong(columnIndex++)).andReturn(trackId); - AndroidMock.replay(cursorMock); - Waypoint waypoint = providerUtils.createWaypoint(cursorMock); - assertEquals(id, waypoint.getId()); - assertEquals(name, waypoint.getName()); - assertEquals(trackId, waypoint.getTrackId()); - AndroidMock.verify(cursorMock); - } - - /** - * Tests the method {@link MyTracksProviderUtilsImpl#createContentValues(Waypoint)}. - */ - public void testCreateContentValues_waypoint() { - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - providerUtils.insertTrack(track); - // Bottom - long startTime = 1000L; - // AverageSpeed - double minGrade = -20.11; - TripStatistics statistics = new TripStatistics(); - statistics.setStartTime(startTime); - statistics.setStopTime(2500L); - statistics.setTotalTime(1500L); - statistics.setMovingTime(700L); - statistics.setTotalDistance(750.0); - statistics.setTotalElevationGain(50.0); - statistics.setMaxSpeed(60.0); - statistics.setMaxElevation(1250.0); - statistics.setMinElevation(1200.0); - statistics.setMaxGrade(15.0); - statistics.setMinGrade(minGrade); - statistics.setBounds(-10000, 20000, 30000, -40000); - // Insert at first. - Waypoint waypoint = new Waypoint(); - waypoint.setDescription(TEST_DESC); - waypoint.setType(Waypoint.TYPE_STATISTICS); - waypoint.setTripStatistics(statistics); - - Location loc = new Location("test"); - loc.setLatitude(22); - loc.setLongitude(22); - loc.setAccuracy((float) 1 / 100.0f); - loc.setAltitude(2.5); - waypoint.setLocation(loc); - providerUtils.insertWaypoint(waypoint); - - MyTracksProviderUtilsImpl myTracksProviderUtilsImpl = new MyTracksProviderUtilsImpl( - new MockContentResolver()); - - long waypointId = System.currentTimeMillis(); - waypoint.setId(waypointId); - ContentValues contentValues = myTracksProviderUtilsImpl.createContentValues(waypoint); - assertEquals(waypointId, contentValues.get(WaypointsColumns._ID)); - assertEquals(22 * 1000000, contentValues.get(WaypointsColumns.LONGITUDE)); - assertEquals(TEST_DESC, contentValues.get(WaypointsColumns.DESCRIPTION)); - assertEquals(startTime, contentValues.get(WaypointsColumns.STARTTIME)); - assertEquals(minGrade, contentValues.get(WaypointsColumns.MINGRADE)); - } - - /** - * Tests the method {@link MyTracksProviderUtilsImpl#getLastValidTrackLocation(long)}. - */ - public void testGetLastValidTrackLocation() { - // Insert track, points at first. - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - insertTrackWithLocations(track); - - Location lastLocation = providerUtils.getLastValidTrackLocation(trackId); - checkLocation(9, lastLocation); - } - - /** - * Tests the method - * {@link MyTracksProviderUtilsImpl#getLocationsCursor(long, long, int, boolean)} - * in descending. - */ - public void testGetLocationCursor_desc() { - // Insert track, points at first. - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - insertTrackWithLocations(track); - - Cursor cursor = providerUtils.getLocationsCursor(trackId, 2L, 5, true); - assertEquals(2, cursor.getCount()); - } - - /** - * Tests the method - * {@link MyTracksProviderUtilsImpl#getLocationsCursor(long, long, int, boolean)} - * in ascending. - */ - public void testGetLocationCursor_asc() { - // Insert track, points at first. - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - insertTrackWithLocations(track); - - Cursor cursor = providerUtils.getLocationsCursor(trackId, 2L, 5, false); - assertEquals(5, cursor.getCount()); - } - - /** - * Tests the method - * {@link MyTracksProviderUtilsImpl#getLocationIterator(long, long, boolean, LocationFactory)} - * in descending. - */ - public void testGeLocationIterator_desc() { - // Insert track, points at first. - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - insertTrackWithLocations(track); - - long startTrackPointId = 2L; - - LocationIterator locationIterator = providerUtils.getLocationIterator(trackId, - startTrackPointId, true, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); - for (int i = 1; i >= 0; i--) { - assertTrue(locationIterator.hasNext()); - Location location = locationIterator.next(); - assertEquals(2 + (i - 1), locationIterator.getLocationId()); - checkLocation(i, location); - } - assertFalse(locationIterator.hasNext()); - } - - /** - * Tests the method - * {@link MyTracksProviderUtilsImpl#getLocationIterator(long, long, boolean, LocationFactory)} - * in ascending. - */ - public void testGeLocationIterator_asc() { - // Insert track, point at first. - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - insertTrackWithLocations(track); - - long startTrackPointId = 2L; - - LocationIterator locationIterator = providerUtils.getLocationIterator(trackId, - startTrackPointId, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); - - for (int i = 1; i < 10; i++) { - assertTrue(locationIterator.hasNext()); - Location location = locationIterator.next(); - assertEquals(2 + (i - 1), locationIterator.getLocationId()); - checkLocation(i, location); - } - assertFalse(locationIterator.hasNext()); - } - - /** - * Tests the method {@link MyTracksProviderUtilsImpl#getLastTrackLocationId(long)}. - */ - public void testGetLastTrackLocationId() { - // Insert track, point at first. - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - insertTrackWithLocations(track); - - assertEquals(10, providerUtils.getLastTrackLocationId(trackId)); - } - - /** - * Tests the method {@link MyTracksProviderUtilsImpl#getLastTrackLocation(long)}. - */ - public void testGetLastTrackLocation() { - // Insert track, point at first. - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - insertTrackWithLocations(track); - checkLocation(9, providerUtils.getLastTrackLocation(trackId)); - } - - /** - * Tests the method - * {@link MyTracksProviderUtilsImpl#insertTrackPoint(Location, long)}. This - * test also covers the method - * {@link MyTracksProviderUtilsImpl#createContentValues(Location, long)}. - */ - @SuppressWarnings("javadoc") - public void testInsertTrackPoint() { - // Insert track, point at first. - long trackId = System.currentTimeMillis(); - Track track = getTrack(trackId, 10); - insertTrackWithLocations(track); - - providerUtils.insertTrackPoint(createLocation(22), trackId); - assertEquals(11, providerUtils.getLocationsCursor(trackId, 0, 1000, false).getCount()); - } - - /** - * Tests the method - * {@link MyTracksProviderUtilsImpl#bulkInsertTrackPoints(Location[], int, long)} + * {@link MyTracksProviderUtilsImpl#bulkInsertTrackPoint(Location[], int, long)} * . This test also covers the method * {@link MyTracksProviderUtilsImpl#createContentValues(Location, long)} and * the inner class {@link MyTracksProviderUtilsImpl.CachedTrackPointsIndexes}. */ @SuppressWarnings("javadoc") - public void testBulkInsertTrackPoints() { + public void testBulkInsertTrackPoint() { // Insert track, point at first. long trackId = System.currentTimeMillis(); Track track = getTrack(trackId, 10); insertTrackWithLocations(track); - - providerUtils.bulkInsertTrackPoints(track.getLocations().toArray(new Location[0]), -1, trackId); - assertEquals(20, providerUtils.getLocationsCursor(trackId, 0, 1000, false).getCount()); - providerUtils.bulkInsertTrackPoints(track.getLocations().toArray(new Location[0]), 8, trackId); - assertEquals(28, providerUtils.getLocationsCursor(trackId, 0, 1000, false).getCount()); + + providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), -1, trackId); + assertEquals(20, providerUtils.getTrackPointCursor(trackId, 0, 1000, false).getCount()); + providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), 8, trackId); + assertEquals(28, providerUtils.getTrackPointCursor(trackId, 0, 1000, false).getCount()); } /** @@ -797,9 +666,9 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { */ @SuppressWarnings("javadoc") @UsesMocks(Cursor.class) - public void testCreateLocation() { + public void testCreateTrackPoint() { Cursor cursorMock = AndroidMock.createNiceMock(Cursor.class); - + // Set index. int index = 1; // Id @@ -819,7 +688,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { // Sensor AndroidMock.expect(cursorMock.getColumnIndexOrThrow(TrackPointsColumns.SENSOR)).andReturn( index++); - + // Set return value of isNull(). index = 2; // Longitude @@ -832,7 +701,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { AndroidMock.expect(cursorMock.isNull(index++)).andReturn(false); // Sensor AndroidMock.expect(cursorMock.isNull(index++)).andReturn(false); - + // Set return value of isNull(). index = 2; // Longitude @@ -850,9 +719,9 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { // Sensor byte[] sensor = "Sensor state".getBytes(); AndroidMock.expect(cursorMock.getBlob(index++)).andReturn(sensor); - + AndroidMock.replay(cursorMock); - Location location = providerUtils.createLocation(cursorMock); + Location location = providerUtils.createTrackPoint(cursorMock); assertEquals((double) longitude, location.getLongitude()); assertEquals((double) latitude, location.getLatitude()); assertEquals(time, location.getTime()); @@ -860,6 +729,138 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { AndroidMock.verify(cursorMock); } + /** + * Tests the method + * {@link MyTracksProviderUtilsImpl#insertTrackPoint(Location, long)}. This + * test also covers the method + * {@link MyTracksProviderUtilsImpl#createContentValues(Location, long)}. + */ + @SuppressWarnings("javadoc") + public void testInsertTrackPoint() { + // Insert track, point at first. + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + insertTrackWithLocations(track); + + providerUtils.insertTrackPoint(createLocation(22), trackId); + assertEquals(11, providerUtils.getTrackPointCursor(trackId, 0, 1000, false).getCount()); + } + + /** + * Tests the method {@link MyTracksProviderUtilsImpl#getLastTrackPoint(long)}. + */ + public void testGetLastTrackPoint() { + // Insert track, point at first. + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + insertTrackWithLocations(track); + checkLocation(9, providerUtils.getLastTrackPoint(trackId)); + } + + /** + * Tests the method {@link MyTracksProviderUtilsImpl#getLastTrackPointId(long)}. + */ + public void testGetLastTrackPointId() { + // Insert track, point at first. + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + insertTrackWithLocations(track); + + assertEquals(10, providerUtils.getLastTrackPointId(trackId)); + } + + /** + * Tests the method {@link MyTracksProviderUtilsImpl#getLastValidTrackPoint(long)}. + */ + public void testGetLastValidTrackPoint() { + // Insert track, points at first. + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + insertTrackWithLocations(track); + + Location lastLocation = providerUtils.getLastValidTrackPoint(trackId); + checkLocation(9, lastLocation); + } + + /** + * Tests the method + * {@link MyTracksProviderUtilsImpl#getTrackPointCursor(long, long, int, boolean)} + * in descending. + */ + public void testGetTrackPointCursor_desc() { + // Insert track, points at first. + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + insertTrackWithLocations(track); + + Cursor cursor = providerUtils.getTrackPointCursor(trackId, 2L, 5, true); + assertEquals(2, cursor.getCount()); + } + + /** + * Tests the method + * {@link MyTracksProviderUtilsImpl#getTrackPointCursor(long, long, int, boolean)} + * in ascending. + */ + public void testGetTrackPointCursor_asc() { + // Insert track, points at first. + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + insertTrackWithLocations(track); + + Cursor cursor = providerUtils.getTrackPointCursor(trackId, 2L, 5, false); + assertEquals(5, cursor.getCount()); + } + + /** + * Tests the method + * {@link MyTracksProviderUtilsImpl#getTrackPointLocationIterator(long, long, boolean, LocationFactory)} + * in descending. + */ + public void testGetTrackPointLocationIterator_desc() { + // Insert track, points at first. + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + insertTrackWithLocations(track); + + long startTrackPointId = 2L; + + LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, + startTrackPointId, true, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); + for (int i = 1; i >= 0; i--) { + assertTrue(locationIterator.hasNext()); + Location location = locationIterator.next(); + assertEquals(2 + (i - 1), locationIterator.getLocationId()); + checkLocation(i, location); + } + assertFalse(locationIterator.hasNext()); + } + + /** + * Tests the method + * {@link MyTracksProviderUtilsImpl#getTrackPointLocationIterator(long, long, boolean, LocationFactory)} + * in ascending. + */ + public void testGetTrackPointLocationIterator_asc() { + // Insert track, point at first. + long trackId = System.currentTimeMillis(); + Track track = getTrack(trackId, 10); + insertTrackWithLocations(track); + + long startTrackPointId = 2L; + + LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, + startTrackPointId, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); + + for (int i = 1; i < 10; i++) { + assertTrue(locationIterator.hasNext()); + Location location = locationIterator.next(); + assertEquals(2 + (i - 1), locationIterator.getLocationId()); + checkLocation(i, location); + } + assertFalse(locationIterator.hasNext()); + } + /** * Simulates a track which is used for testing. * @@ -914,7 +915,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase { */ private void insertTrackWithLocations(Track track) { providerUtils.insertTrack(track); - providerUtils.bulkInsertTrackPoints(track.getLocations().toArray(new Location[0]), track + providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), track .getLocations().size(), track.getId()); } } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/content/TrackDataHubTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/content/TrackDataHubTest.java index 02c22558d..14da06dde 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/content/TrackDataHubTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/content/TrackDataHubTest.java @@ -203,7 +203,7 @@ public class TrackDataHubTest extends AndroidTestCase { // Register two listeners Capture contentObserverCapture = new Capture(); - expect(myTracksProviderUtils.getWaypointsCursor( + expect(myTracksProviderUtils.getWaypointCursor( eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS))) .andStubAnswer(new FixedSizeCursorAnswer(2)); expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class))) @@ -230,7 +230,7 @@ public class TrackDataHubTest extends AndroidTestCase { // Cause waypoints table update ContentObserver contentObserver = contentObserverCapture.getValue(); - expect(myTracksProviderUtils.getWaypointsCursor( + expect(myTracksProviderUtils.getWaypointCursor( eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS))) .andStubAnswer(new FixedSizeCursorAnswer(3)); expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class))) @@ -251,7 +251,7 @@ public class TrackDataHubTest extends AndroidTestCase { verifyAndReset(); // Unregister one listener - expect(myTracksProviderUtils.getWaypointsCursor( + expect(myTracksProviderUtils.getWaypointCursor( eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS))) .andStubAnswer(new FixedSizeCursorAnswer(4)); expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class))) @@ -288,9 +288,9 @@ public class TrackDataHubTest extends AndroidTestCase { eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture)); FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); trackDataListener1.clearTrackPoints(); locationIterator.expectLocationsDelivered(trackDataListener1); trackDataListener1.onNewTrackPointsDone(); @@ -303,9 +303,9 @@ public class TrackDataHubTest extends AndroidTestCase { // Register a second listener locationIterator = new FixedSizeLocationIterator(1, 10, 5); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); trackDataListener2.clearTrackPoints(); locationIterator.expectLocationsDelivered(trackDataListener2); trackDataListener2.onNewTrackPointsDone(); @@ -318,9 +318,9 @@ public class TrackDataHubTest extends AndroidTestCase { // Deliver more points - should go to both listeners without clearing ContentObserver contentObserver = contentObserverCapture.getValue(); locationIterator = new FixedSizeLocationIterator(11, 10, 1); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(11L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(20L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(20L); locationIterator.expectLocationsDelivered(trackDataListener1); locationIterator.expectLocationsDelivered(trackDataListener2); trackDataListener1.onNewTrackPointsDone(); @@ -332,10 +332,10 @@ public class TrackDataHubTest extends AndroidTestCase { // Unregister one listener and change track locationIterator = new FixedSizeLocationIterator(101, 10); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class))) .andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID + 1)).andReturn(110L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID + 1)).andReturn(110L); trackDataListener2.clearTrackPoints(); locationIterator.expectLocationsDelivered(trackDataListener2); trackDataListener2.onNewTrackPointsDone(); @@ -358,9 +358,9 @@ public class TrackDataHubTest extends AndroidTestCase { eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture)); FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); trackDataListener1.clearTrackPoints(); locationIterator.expectLocationsDelivered(trackDataListener1); @@ -384,9 +384,9 @@ public class TrackDataHubTest extends AndroidTestCase { dataSource.registerContentObserver( eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture)); locationIterator = new FixedSizeLocationIterator(1, 10, 5); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); trackDataListener1.clearTrackPoints(); locationIterator.expectLocationsDelivered(trackDataListener1); trackDataListener1.onNewTrackPointsDone(); @@ -409,9 +409,9 @@ public class TrackDataHubTest extends AndroidTestCase { eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture)); FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L); trackDataListener1.clearTrackPoints(); locationIterator.expectLocationsDelivered(trackDataListener1); trackDataListener1.onNewTrackPointsDone(); @@ -434,10 +434,10 @@ public class TrackDataHubTest extends AndroidTestCase { dataSource.registerContentObserver( eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture)); locationIterator = new FixedSizeLocationIterator(1, 10); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class))) .andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID + 1)).andReturn(10L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID + 1)).andReturn(10L); trackDataListener1.clearTrackPoints(); locationIterator.expectLocationsDelivered(trackDataListener1); trackDataListener1.onNewTrackPointsDone(); @@ -458,15 +458,15 @@ public class TrackDataHubTest extends AndroidTestCase { dataSource.registerContentObserver( eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture)); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(200L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(200L); AndroidMock.expectLastCall().anyTimes(); FixedSizeLocationIterator locationIterator1 = new FixedSizeLocationIterator( 1, 200, 4, 25, 71, 120); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator1); FixedSizeLocationIterator locationIterator2 = new FixedSizeLocationIterator( 1, 200, 4, 25, 71, 120); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator2); trackDataListener1.clearTrackPoints(); @@ -496,9 +496,9 @@ public class TrackDataHubTest extends AndroidTestCase { // Deliver 30 points (no sampling happens) FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 30, 5); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(30L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(30L); trackDataListener1.clearTrackPoints(); locationIterator.expectLocationsDelivered(trackDataListener1); @@ -513,9 +513,9 @@ public class TrackDataHubTest extends AndroidTestCase { // Now deliver 30 more (incrementally sampled) ContentObserver observer = observerCapture.getValue(); locationIterator = new FixedSizeLocationIterator(31, 30); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(31L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(60L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(60L); locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false); trackDataListener1.onNewTrackPointsDone(); replay(); @@ -525,9 +525,9 @@ public class TrackDataHubTest extends AndroidTestCase { // Now another 30 (triggers resampling) locationIterator = new FixedSizeLocationIterator(1, 90); - expect(myTracksProviderUtils.getLocationIterator( + expect(myTracksProviderUtils.getTrackPointLocationIterator( eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator); - expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(90L); + expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(90L); trackDataListener1.clearTrackPoints(); locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false); trackDataListener1.onNewTrackPointsDone(); @@ -840,7 +840,7 @@ public class TrackDataHubTest extends AndroidTestCase { dataSource.registerOnSharedPreferenceChangeListener(capture(preferenceChangeListenerCapture)); Capture observerCapture = new Capture(); dataSource.registerContentObserver(eq(WaypointsColumns.CONTENT_URI), capture(observerCapture)); - expect(myTracksProviderUtils.getWaypointsCursor(capture(new Capture()), capture(new Capture()), + expect(myTracksProviderUtils.getWaypointCursor(capture(new Capture()), capture(new Capture()), capture(new Capture()))).andReturn(null); trackDataListener1.clearWaypoints(); trackDataListener1.onNewWaypointsDone(); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java index 6bcd5b27d..6f21364bf 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/GpxImporterTest.java @@ -148,13 +148,13 @@ public class GpxImporterTest extends AndroidTestCase { expect(providerUtils.insertTrack(AndroidMock.capture(trackParam))) .andReturn(TRACK_ID_URI); - expect(providerUtils.getLastTrackLocationId(TRACK_ID)).andReturn(TRACK_POINT_ID_1).andReturn(TRACK_POINT_ID_2); + expect(providerUtils.getLastTrackPointId(TRACK_ID)).andReturn(TRACK_POINT_ID_1).andReturn(TRACK_POINT_ID_2); // A flush happens after the first insertion to get the starting point ID, // which is why we get two calls - expect(providerUtils.bulkInsertTrackPoints(LocationsMatcher.eqLoc(loc1), + expect(providerUtils.bulkInsertTrackPoint(LocationsMatcher.eqLoc(loc1), eq(1), eq(TRACK_ID))).andReturn(1); - expect(providerUtils.bulkInsertTrackPoints(LocationsMatcher.eqLoc(loc2), + expect(providerUtils.bulkInsertTrackPoint(LocationsMatcher.eqLoc(loc2), eq(1), eq(TRACK_ID))).andReturn(1); providerUtils.updateTrack(AndroidMock.capture(trackParam)); @@ -223,9 +223,9 @@ public class GpxImporterTest extends AndroidTestCase { expect(providerUtils.insertTrack((Track) AndroidMock.anyObject())) .andReturn(TRACK_ID_URI); - expect(providerUtils.bulkInsertTrackPoints((Location[]) AndroidMock.anyObject(), + expect(providerUtils.bulkInsertTrackPoint((Location[]) AndroidMock.anyObject(), AndroidMock.anyInt(), AndroidMock.anyLong())).andStubReturn(1); - expect(providerUtils.getLastTrackLocationId(TRACK_ID)).andStubReturn(TRACK_POINT_ID_1); + expect(providerUtils.getLastTrackPointId(TRACK_ID)).andStubReturn(TRACK_POINT_ID_1); providerUtils.deleteTrack(TRACK_ID); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/TrackWriterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/TrackWriterTest.java index 467221475..c855c6b35 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/file/TrackWriterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/file/TrackWriterTest.java @@ -256,7 +256,7 @@ public class TrackWriterTest extends AndroidTestCase { // Make location 3 invalid locs[2].setLatitude(100); - assertEquals(locs.length, providerUtils.bulkInsertTrackPoints(locs, locs.length, TRACK_ID)); + assertEquals(locs.length, providerUtils.bulkInsertTrackPoint(locs, locs.length, TRACK_ID)); for (int i = 0; i < wps.length; ++i) { Waypoint wpt = wps[i]; wpt.setTrackId(TRACK_ID); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTaskTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTaskTest.java index 904114791..61f35e6f3 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTaskTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTaskTest.java @@ -144,7 +144,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase { */ public void testUploadAllTrackPoints_nullCursor() { Track track = TrackStubUtils.createTrack(1); - AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false)) + AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false)) .andReturn(null); AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock); SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock, @@ -164,9 +164,9 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase { AndroidMock.expect(cursorMock.getCount()).andReturn(2); AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true); cursorMock.close(); - AndroidMock.expect(myTracksProviderUtilsMock.createLocation(cursorMock)).andReturn( + AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock)).andReturn( new Location("1")); - AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false)) + AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false)) .andReturn(cursorMock); AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock); @@ -191,9 +191,9 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase { AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true); AndroidMock.expect(cursorMock.moveToPosition(1)).andReturn(true); cursorMock.close(); - AndroidMock.expect(myTracksProviderUtilsMock.createLocation(cursorMock)) + AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock)) .andReturn(new Location("1")).times(2); - AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false)) + AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false)) .andReturn(cursorMock); AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock); @@ -221,9 +221,9 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase { AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true); AndroidMock.expect(cursorMock.moveToPosition(1)).andReturn(true); cursorMock.close(); - AndroidMock.expect(myTracksProviderUtilsMock.createLocation(cursorMock)) + AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock)) .andReturn(new Location("1")).times(2); - AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false)) + AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false)) .andReturn(cursorMock); AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock); @@ -250,9 +250,9 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase { AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true); AndroidMock.expect(cursorMock.moveToPosition(1)).andReturn(true); cursorMock.close(); - AndroidMock.expect(myTracksProviderUtilsMock.createLocation(cursorMock)) + AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock)) .andReturn(new Location("1")).times(2); - AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false)) + AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false)) .andReturn(cursorMock); AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock); @@ -274,7 +274,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase { @UsesMocks(Cursor.class) public void testUploadWaypoints_nullCursor() { AndroidMock.expect( - myTracksProviderUtilsMock.getWaypointsCursor(TRACK_ID, 0, + myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(null); AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock); SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock, @@ -296,7 +296,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase { cursorMock.close(); AndroidMock.expect( - myTracksProviderUtilsMock.getWaypointsCursor(TRACK_ID, 0, + myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(cursorMock); AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock); @@ -323,7 +323,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase { cursorMock.close(); AndroidMock.expect( - myTracksProviderUtilsMock.getWaypointsCursor(TRACK_ID, 0, + myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(cursorMock); Waypoint waypoint = new Waypoint(); waypoint.setLocation(TrackStubUtils.createMyTracksLocation());