Update gallery when photo markers are deleted

This commit is contained in:
Jimmy Shih
2013-12-02 15:50:08 -08:00
parent 4043bd8696
commit 9c4ccb2da9
14 changed files with 69 additions and 78 deletions
@@ -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();
}
@@ -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());
@@ -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
@@ -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);