forked from upstream-mirrors/OpenTracks
Update gallery when photo markers are deleted
This commit is contained in:
@@ -95,7 +95,7 @@ public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
context, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
|
||||
SyncUtils.disableSync(context);
|
||||
SyncUtils.clearSyncState(context);
|
||||
myTracksProviderUtils.deleteAllTracks();
|
||||
myTracksProviderUtils.deleteAllTracks(context);
|
||||
return true;
|
||||
} else {
|
||||
for (long id : trackIds) {
|
||||
@@ -103,7 +103,7 @@ public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
return false;
|
||||
}
|
||||
Track track = myTracksProviderUtils.getTrack(id);
|
||||
myTracksProviderUtils.deleteTrack(id);
|
||||
myTracksProviderUtils.deleteTrack(context, id);
|
||||
if (track != null) {
|
||||
String driveId = track.getDriveId();
|
||||
if (driveId != null && !driveId.equals("")) {
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ public class DeleteMarkerDialogFragment extends AbstractMyTracksDialogFragment {
|
||||
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(
|
||||
fragmentActivity);
|
||||
for (long markerId : markerIds) {
|
||||
myTracksProviderUtils.deleteWaypoint(
|
||||
myTracksProviderUtils.deleteWaypoint(fragmentActivity,
|
||||
markerId, new DescriptionGeneratorImpl(fragmentActivity));
|
||||
}
|
||||
caller.onDeleteMarkerDone();
|
||||
|
||||
+2
-2
@@ -310,7 +310,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
||||
"Cannot import more than one track to an existing track " + importTrackId));
|
||||
}
|
||||
trackId = importTrackId;
|
||||
myTracksProviderUtils.clearTrack(trackId);
|
||||
myTracksProviderUtils.clearTrack(context, trackId);
|
||||
}
|
||||
trackIds.add(trackId);
|
||||
trackData.track.setId(trackId);
|
||||
@@ -614,7 +614,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
||||
*/
|
||||
private void cleanImport() {
|
||||
for (long trackId : trackIds) {
|
||||
myTracksProviderUtils.deleteTrack(trackId);
|
||||
myTracksProviderUtils.deleteTrack(context, trackId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,13 +171,13 @@ public class ImportActivity extends Activity {
|
||||
final Dialog dialog = new AlertDialog.Builder(this).setCancelable(true).setIcon(iconId)
|
||||
.setMessage(message).setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
dialog.dismiss();
|
||||
public void onCancel(DialogInterface dialogInterface) {
|
||||
dialogInterface.dismiss();
|
||||
finish();
|
||||
}
|
||||
}).setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
public void onClick(DialogInterface dialogInterface, int which) {
|
||||
if (successCount == totalCount && !importAll && trackId != -1L) {
|
||||
Intent intent = IntentUtils.newIntent(
|
||||
ImportActivity.this, TrackDetailActivity.class)
|
||||
@@ -186,7 +186,7 @@ public class ImportActivity extends Activity {
|
||||
.addParentStack(TrackDetailActivity.class).addNextIntent(intent)
|
||||
.startActivities();
|
||||
}
|
||||
dialog.dismiss();
|
||||
dialogInterface.dismiss();
|
||||
finish();
|
||||
}
|
||||
}).setTitle(titleId).create();
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ public class KmzTrackImporter implements TrackImporter {
|
||||
private void cleanImport(long trackId) {
|
||||
if (trackId != -1L) {
|
||||
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||
myTracksProviderUtils.deleteTrack(trackId);
|
||||
myTracksProviderUtils.deleteTrack(context, trackId);
|
||||
}
|
||||
|
||||
if (importTrackId != -1L) {
|
||||
|
||||
@@ -197,7 +197,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
do {
|
||||
Track track = myTracksProviderUtils.createTrack(cursor);
|
||||
if (!syncedDriveIds.contains(track.getDriveId())) {
|
||||
myTracksProviderUtils.deleteTrack(track.getId());
|
||||
myTracksProviderUtils.deleteTrack(context, track.getId());
|
||||
}
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
@@ -314,7 +314,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
File driveFile = changes.get(driveId);
|
||||
if (driveFile == null) {
|
||||
Log.d(TAG, "Delete local track " + track.getName());
|
||||
myTracksProviderUtils.deleteTrack(track.getId());
|
||||
myTracksProviderUtils.deleteTrack(context, track.getId());
|
||||
} else {
|
||||
if (SyncUtils.isInMyTracksAndValid(driveFile, getFolderId())
|
||||
|| SyncUtils.isInSharedWithMe(driveFile)) {
|
||||
@@ -532,7 +532,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
if (!success) {
|
||||
// if the track is new, delete it
|
||||
if (trackId == -1L && track != null) {
|
||||
myTracksProviderUtils.deleteTrack(track.getId());
|
||||
myTracksProviderUtils.deleteTrack(context, track.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public class SyncUtils {
|
||||
do {
|
||||
Track track = myTracksProviderUtils.createTrack(cursor);
|
||||
if (track.isSharedWithMe()) {
|
||||
myTracksProviderUtils.deleteTrack(track.getId());
|
||||
myTracksProviderUtils.deleteTrack(context, track.getId());
|
||||
} else {
|
||||
SyncUtils.updateTrack(myTracksProviderUtils, track, null);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public interface MyTracksProviderUtils {
|
||||
*
|
||||
* @param trackId the track id
|
||||
*/
|
||||
public void clearTrack(long trackId);
|
||||
public void clearTrack(Context context, long trackId);
|
||||
|
||||
/**
|
||||
* Creates a {@link Track} from a cursor.
|
||||
@@ -57,14 +57,14 @@ public interface MyTracksProviderUtils {
|
||||
/**
|
||||
* Deletes all tracks (including waypoints and track points).
|
||||
*/
|
||||
public void deleteAllTracks();
|
||||
public void deleteAllTracks(Context context);
|
||||
|
||||
/**
|
||||
* Deletes a track.
|
||||
*
|
||||
* @param trackId the track id
|
||||
*/
|
||||
public void deleteTrack(long trackId);
|
||||
public void deleteTrack(Context context, long trackId);
|
||||
|
||||
/**
|
||||
* Gets all the tracks. If no track exists, an empty list is returned.
|
||||
@@ -132,7 +132,7 @@ public interface MyTracksProviderUtils {
|
||||
* @param descriptionGenerator the description generator. Can be null for
|
||||
* waypoint marker
|
||||
*/
|
||||
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator);
|
||||
public void deleteWaypoint(Context context, long waypointId, DescriptionGenerator descriptionGenerator);
|
||||
|
||||
/**
|
||||
* Gets the first waypoint id for a track. The first waypoint is special as it
|
||||
|
||||
+14
-11
@@ -24,6 +24,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.location.Location;
|
||||
import android.net.Uri;
|
||||
@@ -53,8 +54,8 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearTrack(long trackId) {
|
||||
deleteTrackPointsAndWaypoints(trackId);
|
||||
public void clearTrack(Context context, long trackId) {
|
||||
deleteTrackPointsAndWaypoints(context, trackId);
|
||||
Track track = new Track();
|
||||
track.setId(trackId);
|
||||
updateTrack(track);
|
||||
@@ -177,19 +178,19 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllTracks() {
|
||||
public void deleteAllTracks(Context context) {
|
||||
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);
|
||||
|
||||
File dir = FileUtils.getPhotoDir();
|
||||
deleteDirectoryRecurse(dir);
|
||||
deleteDirectoryRecurse(context, dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTrack(long trackId) {
|
||||
deleteTrackPointsAndWaypoints(trackId);
|
||||
public void deleteTrack(Context context, long trackId) {
|
||||
deleteTrackPointsAndWaypoints(context, trackId);
|
||||
|
||||
// Delete track last since it triggers a database vaccum call
|
||||
contentResolver.delete(TracksColumns.CONTENT_URI, TracksColumns._ID + "=?",
|
||||
@@ -203,7 +204,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
*
|
||||
* @param trackId the track id
|
||||
*/
|
||||
private void deleteTrackPointsAndWaypoints(long trackId) {
|
||||
private void deleteTrackPointsAndWaypoints(Context context, long trackId) {
|
||||
Track track = getTrack(trackId);
|
||||
if (track != null) {
|
||||
String where = TrackPointsColumns._ID + ">=? AND " + TrackPointsColumns._ID + "<=?";
|
||||
@@ -213,7 +214,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
}
|
||||
contentResolver.delete(WaypointsColumns.CONTENT_URI, WaypointsColumns.TRACKID + "=?",
|
||||
new String[] { Long.toString(trackId) });
|
||||
deleteDirectoryRecurse(FileUtils.getPhotoDir(trackId));
|
||||
deleteDirectoryRecurse(context, FileUtils.getPhotoDir(trackId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -221,14 +222,15 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
*
|
||||
* @param dir the directory
|
||||
*/
|
||||
private void deleteDirectoryRecurse(File dir) {
|
||||
private void deleteDirectoryRecurse(Context context, File dir) {
|
||||
if (FileUtils.isDirectory(dir)) {
|
||||
for (File child : dir.listFiles()) {
|
||||
deleteDirectoryRecurse(child);
|
||||
deleteDirectoryRecurse(context, child);
|
||||
}
|
||||
}
|
||||
if (dir.exists()) {
|
||||
dir.delete();
|
||||
FileUtils.updateMediaScanner(context, Uri.fromFile(dir));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,7 +511,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator) {
|
||||
public void deleteWaypoint(Context context, long waypointId, DescriptionGenerator descriptionGenerator) {
|
||||
final Waypoint waypoint = getWaypoint(waypointId);
|
||||
if (waypoint != null && waypoint.getType() == WaypointType.STATISTICS
|
||||
&& descriptionGenerator != null) {
|
||||
@@ -533,6 +535,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
if (file.exists()) {
|
||||
File parent = file.getParentFile();
|
||||
file.delete();
|
||||
FileUtils.updateMediaScanner(context, uri);
|
||||
if (parent.listFiles().length == 0) {
|
||||
parent.delete();
|
||||
}
|
||||
|
||||
+9
-9
@@ -69,7 +69,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
||||
setContext(context);
|
||||
|
||||
providerUtils = MyTracksProviderUtils.Factory.get(context);
|
||||
providerUtils.deleteAllTracks();
|
||||
providerUtils.deleteAllTracks(context);
|
||||
}
|
||||
|
||||
public void testLocationIterator_noPoints() {
|
||||
@@ -220,7 +220,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link MyTracksProviderUtilsImpl#deleteAllTracks()}
|
||||
* Tests the method {@link MyTracksProviderUtilsImpl#deleteAllTracks(Context)}
|
||||
*/
|
||||
public void testDeleteAllTracks() {
|
||||
// Insert track, points and waypoint at first.
|
||||
@@ -240,7 +240,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
||||
null, WaypointsColumns._ID);
|
||||
assertEquals(1, waypointCursor.getCount());
|
||||
// Delete all.
|
||||
providerUtils.deleteAllTracks();
|
||||
providerUtils.deleteAllTracks(context);
|
||||
// Check whether all have been deleted.
|
||||
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null,
|
||||
TracksColumns._ID);
|
||||
@@ -254,7 +254,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method {@link MyTracksProviderUtilsImpl#deleteTrack(long)}.
|
||||
* Tests the method {@link MyTracksProviderUtilsImpl#deleteTrack(Context, long)}.
|
||||
*/
|
||||
public void testDeleteTrack() {
|
||||
// Insert three tracks, points of two tracks and way point of one track.
|
||||
@@ -280,7 +280,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
||||
null, WaypointsColumns._ID);
|
||||
assertEquals(1, waypointCursor.getCount());
|
||||
// Delete one track.
|
||||
providerUtils.deleteTrack(trackId);
|
||||
providerUtils.deleteTrack(context, trackId);
|
||||
// Check whether all data of a track has been deleted.
|
||||
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null,
|
||||
TracksColumns._ID);
|
||||
@@ -431,7 +431,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(long, DescriptionGenerator)}
|
||||
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)}
|
||||
* when there is only one waypoint in the track.
|
||||
*/
|
||||
public void testDeleteWaypoint_onlyOneWayPoint() {
|
||||
@@ -460,14 +460,14 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
providerUtils.deleteWaypoint(1, descriptionGenerator);
|
||||
providerUtils.deleteWaypoint(context, 1, descriptionGenerator);
|
||||
|
||||
assertNull(providerUtils.getWaypoint(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the method
|
||||
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(long, DescriptionGenerator)}
|
||||
* {@link MyTracksProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)}
|
||||
* when there is more than one waypoint in the track.
|
||||
*/
|
||||
public void testDeleteWaypoint_hasNextWayPoint() {
|
||||
@@ -515,7 +515,7 @@ public class MyTracksProviderUtilsImplTest extends AndroidTestCase {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
providerUtils.deleteWaypoint(1, descriptionGenerator);
|
||||
providerUtils.deleteWaypoint(context, 1, descriptionGenerator);
|
||||
|
||||
assertNull(providerUtils.getWaypoint(1));
|
||||
assertEquals(MyTracksProviderUtilsImplTest.MOCK_DESC, providerUtils.getWaypoint(2)
|
||||
|
||||
@@ -66,7 +66,7 @@ public class SearchEngineTest extends AndroidTestCase {
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
providerUtils.deleteAllTracks();
|
||||
providerUtils.deleteAllTracks(getContext());
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
+1
-1
@@ -244,7 +244,7 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
||||
expect(
|
||||
myTracksProviderUtils.getTrack(PreferencesUtils.getLong(getContext(),
|
||||
R.string.recording_track_id_key))).andStubReturn(null);
|
||||
myTracksProviderUtils.deleteTrack(TRACK_ID_0);
|
||||
myTracksProviderUtils.deleteTrack(getContext(), TRACK_ID_0);
|
||||
AndroidMock.replay(myTracksProviderUtils);
|
||||
|
||||
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
||||
|
||||
myTracksProviderUtils.clearTrack(TRACK_ID_0);
|
||||
myTracksProviderUtils.clearTrack(getContext(), TRACK_ID_0);
|
||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||
|
||||
// A flush happens at the end
|
||||
@@ -108,7 +108,7 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
||||
|
||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||
|
||||
myTracksProviderUtils.clearTrack(TRACK_ID_0);
|
||||
myTracksProviderUtils.clearTrack(getContext(), TRACK_ID_0);
|
||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||
|
||||
// A flush happens at the end
|
||||
|
||||
+24
-36
@@ -88,18 +88,16 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
tripStatisticsUpdater.updateElevation(elevation);
|
||||
assertEquals(elevation, tripStatisticsUpdater.getSmoothedElevation());
|
||||
|
||||
if (i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||
assertEquals(elevation, tripStatistics.getMinElevation());
|
||||
assertEquals(elevation, tripStatistics.getMaxElevation());
|
||||
assertEquals(0.0, tripStatistics.getTotalElevationGain());
|
||||
}
|
||||
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||
assertEquals(elevation, tripStatistics.getMinElevation());
|
||||
assertEquals(elevation, tripStatistics.getMaxElevation());
|
||||
assertEquals(elevation, tripStatistics.getTotalElevationGain());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, Double)} with
|
||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with
|
||||
* elevation gain.
|
||||
*/
|
||||
public void testElevationGain() throws Exception {
|
||||
@@ -108,34 +106,27 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(),
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
|
||||
if (i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||
TripStatistics data = tripStatisticsUpdater.getTripStatistics();
|
||||
assertEquals(12.0, data.getMinElevation());
|
||||
assertEquals(
|
||||
i, data.getMaxElevation(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(
|
||||
i, data.getTotalElevationGain(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||
}
|
||||
TripStatistics data = tripStatisticsUpdater.getTripStatistics();
|
||||
assertEquals(0.0, data.getMinElevation());
|
||||
assertEquals(i, data.getMaxElevation(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(
|
||||
i, data.getTotalElevationGain(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, Double)} with grade
|
||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with grade
|
||||
* of 1 and -1.
|
||||
*/
|
||||
public void testGradeSimple() throws Exception {
|
||||
for (double i = 0; i < 1000; i++) {
|
||||
tripStatisticsUpdater.updateGrade(100, Double.valueOf(100));
|
||||
if (i >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR
|
||||
+ TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR) {
|
||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||
}
|
||||
tripStatisticsUpdater.updateGrade(100.0, 100.0);
|
||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||
}
|
||||
for (double i = 0; i < 1000; i++) {
|
||||
tripStatisticsUpdater.updateGrade(100, Double.valueOf(-100));
|
||||
if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR
|
||||
&& i >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR) {
|
||||
tripStatisticsUpdater.updateGrade(100.0, -100.0);
|
||||
if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR) {
|
||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||
// add 0.1 delta since changing min grade from 1 to -1
|
||||
assertEquals(-1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade(), 0.1);
|
||||
@@ -144,7 +135,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, Double)} with
|
||||
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with
|
||||
* distance of 1. The grade should get ignored.
|
||||
*/
|
||||
public void testGradeIgnoreShort() throws Exception {
|
||||
@@ -154,7 +145,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
* elevation buffer.
|
||||
*/
|
||||
tripStatisticsUpdater.updateElevation(i);
|
||||
tripStatisticsUpdater.updateGrade(1, Double.valueOf(100));
|
||||
tripStatisticsUpdater.updateGrade(1.0, 100.0);
|
||||
assertEquals(
|
||||
Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||
assertEquals(
|
||||
@@ -201,9 +192,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
double speed = 4.0;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
tripStatisticsUpdater.updateSpeed(i + ONE_SECOND, speed, i, speed);
|
||||
if (i >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
|
||||
assertEquals(speed, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
|
||||
}
|
||||
assertEquals(speed, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,7 +223,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
assertEquals(i + locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
if (i + locationOffset >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||
assertEquals(12.0, tripStatistics.getMinElevation());
|
||||
assertEquals(0.0, tripStatistics.getMinElevation());
|
||||
assertEquals(i + locationOffset, tripStatistics.getMaxElevation(),
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(i + locationOffset, tripStatistics.getTotalElevationGain(),
|
||||
@@ -248,8 +237,9 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
// If there are only moving locations in the track.
|
||||
if (locationOffset == 0 && (i + locationOffset) >= TripStatisticsUpdater.RUN_SMOOTHING_FACTOR
|
||||
+ TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR) {
|
||||
// 0.5 m / 111 m = .0045
|
||||
assertEquals(0.0045, tripStatistics.getMinGrade(), 0.0001);
|
||||
// 1 m / 111 m = .009
|
||||
assertEquals(0.009, tripStatistics.getMinGrade(), 0.0001);
|
||||
assertEquals(0.009, tripStatistics.getMaxGrade(), 0.0001);
|
||||
}
|
||||
assertEquals((i + locationOffset) * 111.0, tripStatistics.getTotalDistance(),
|
||||
@@ -280,14 +270,12 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
assertEquals((locationOffset) * TEN_SECONDS, tripStatistics.getMovingTime());
|
||||
assertEquals(locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(12.0, tripStatistics.getMinElevation());
|
||||
assertEquals(0.0, tripStatistics.getMinElevation());
|
||||
assertEquals(locationOffset, tripStatistics.getMaxElevation(),
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(locationOffset, tripStatistics.getTotalElevationGain(),
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||
if (locationOffset >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
|
||||
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
||||
}
|
||||
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
||||
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
||||
assertEquals(
|
||||
locationOffset * 111.0, tripStatistics.getTotalDistance(), locationOffset * 111.0 * 0.01);
|
||||
|
||||
Reference in New Issue
Block a user