forked from upstream-mirrors/OpenTracks
Update all TrackPathPainter and TrackPathDescriptor.
Fix issues of incrementally updating a path.
This commit is contained in:
@@ -71,21 +71,22 @@ public class MapOverlayTest extends AndroidTestCase {
|
||||
mockMyTracksOverlay.addLocation(location);
|
||||
assertEquals(2, mockMyTracksOverlay.getNumLocations());
|
||||
assertEquals(0, mockMyTracksOverlay.getNumWaypoints());
|
||||
assertNull(mockMyTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertFalse(mockMyTracksOverlay.getTrackPathPainter().hasPath());
|
||||
|
||||
// Draw and make sure that we don't lose any point.
|
||||
mockMyTracksOverlay.draw(canvas, mapView, false);
|
||||
assertEquals(2, mockMyTracksOverlay.getNumLocations());
|
||||
assertEquals(0, mockMyTracksOverlay.getNumWaypoints());
|
||||
assertNotNull(mockMyTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertTrue(mockMyTracksOverlay.getTrackPathPainter().getLastPath() instanceof MockPath);
|
||||
MockPath path = (MockPath) mockMyTracksOverlay.getTrackPathPainter().getLastPath();
|
||||
assertTrue(mockMyTracksOverlay.getTrackPathPainter().hasPath());
|
||||
SingleColorTrackPathPainter trackPathPainter = (SingleColorTrackPathPainter) mockMyTracksOverlay
|
||||
.getTrackPathPainter();
|
||||
MockPath path = (MockPath) trackPathPainter.getPath();
|
||||
assertEquals(2, path.getTotalPoints());
|
||||
|
||||
mockMyTracksOverlay.draw(canvas, mapView, true);
|
||||
assertEquals(2, mockMyTracksOverlay.getNumLocations());
|
||||
assertEquals(0, mockMyTracksOverlay.getNumWaypoints());
|
||||
assertNotNull(mockMyTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertTrue(mockMyTracksOverlay.getTrackPathPainter().hasPath());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +125,7 @@ public class MapOverlayTest extends AndroidTestCase {
|
||||
mockMyTracksOverlay.addWaypoint(waypoint);
|
||||
assertEquals(1, mockMyTracksOverlay.getNumWaypoints());
|
||||
assertEquals(0, mockMyTracksOverlay.getNumLocations());
|
||||
assertNull(mockMyTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertFalse(mockMyTracksOverlay.getTrackPathPainter().hasPath());
|
||||
|
||||
final int waypoints = 10;
|
||||
for (int i = 0; i < waypoints; ++i) {
|
||||
@@ -134,7 +135,7 @@ public class MapOverlayTest extends AndroidTestCase {
|
||||
}
|
||||
assertEquals(1 + waypoints, mockMyTracksOverlay.getNumWaypoints());
|
||||
assertEquals(0, mockMyTracksOverlay.getNumLocations());
|
||||
assertNull(mockMyTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertFalse(mockMyTracksOverlay.getTrackPathPainter().hasPath());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,15 +175,16 @@ public class MapOverlayTest extends AndroidTestCase {
|
||||
// Shadow.
|
||||
mockMyTracksOverlay.draw(canvas, mapView, true);
|
||||
// We don't expect to do anything if
|
||||
assertNull(mockMyTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertFalse(mockMyTracksOverlay.getTrackPathPainter().hasPath());
|
||||
assertEquals(40, mockMyTracksOverlay.getNumWaypoints());
|
||||
assertEquals(100, mockMyTracksOverlay.getNumLocations());
|
||||
|
||||
// No shadow.
|
||||
mockMyTracksOverlay.draw(canvas, mapView, false);
|
||||
assertNotNull(mockMyTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertTrue(mockMyTracksOverlay.getTrackPathPainter().getLastPath() instanceof MockPath);
|
||||
MockPath path = (MockPath) mockMyTracksOverlay.getTrackPathPainter().getLastPath();
|
||||
assertTrue(mockMyTracksOverlay.getTrackPathPainter().hasPath());
|
||||
SingleColorTrackPathPainter trackPathPainter = (SingleColorTrackPathPainter) mockMyTracksOverlay
|
||||
.getTrackPathPainter();
|
||||
MockPath path = (MockPath) trackPathPainter.getPath();
|
||||
assertEquals(40, mockMyTracksOverlay.getNumWaypoints());
|
||||
assertEquals(100, mockMyTracksOverlay.getNumLocations());
|
||||
assertEquals(100, path.getTotalPoints());
|
||||
|
||||
@@ -44,6 +44,6 @@ public class MockMyTracksOverlay extends MapOverlay {
|
||||
|
||||
@Override
|
||||
public Rect getMapViewRect(MapView mapView) {
|
||||
return new Rect(0, 0, 100, 100);
|
||||
return new Rect(0, 0, (int) (100 * 1E6), (int) (100 * 1E6));
|
||||
}
|
||||
}
|
||||
+4
-34
@@ -57,35 +57,6 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is null.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_nullKey() {
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
int speedMargin = dynamicSpeedTrackPathDescriptor.getSpeedMargin();
|
||||
// Change value in shared preferences.
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_percentage_key, speedMargin + 2);
|
||||
|
||||
dynamicSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences, null);
|
||||
assertEquals(speedMargin, dynamicSpeedTrackPathDescriptor.getSpeedMargin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is not null, and not trackColorModeDynamicVariation.
|
||||
*/
|
||||
public void testOnSharedPreferenceChanged_otherKey() {
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
int speedMargin = dynamicSpeedTrackPathDescriptor.getSpeedMargin();
|
||||
// Change value in shared preferences.
|
||||
PreferencesUtils.setInt(context, R.string.track_color_mode_percentage_key, speedMargin + 2);
|
||||
dynamicSpeedTrackPathDescriptor.onSharedPreferenceChanged(sharedPreferences, "anyKey");
|
||||
assertEquals(speedMargin, dynamicSpeedTrackPathDescriptor.getSpeedMargin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#onSharedPreferenceChanged(SharedPreferences,
|
||||
* String)} when the key is trackColorModeDynamicVariation.
|
||||
@@ -120,7 +91,7 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#needsRedraw()} by wrong track
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#updateState()} by wrong track
|
||||
* id.
|
||||
*/
|
||||
public void testNeedsRedraw_WrongTrackId() {
|
||||
@@ -128,11 +99,11 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
context, R.string.selected_track_id_key, PreferencesUtils.SELECTED_TRACK_ID_DEFAULT);
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
assertEquals(false, dynamicSpeedTrackPathDescriptor.needsRedraw());
|
||||
assertEquals(false, dynamicSpeedTrackPathDescriptor.updateState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#needsRedraw()} by different
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#updateState()} by different
|
||||
* averageMovingSpeed.
|
||||
*/
|
||||
public void testIsDiffereceSignificant() {
|
||||
@@ -145,8 +116,7 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
// Difference is more than CRITICAL_DIFFERENCE_PERCENTAGE
|
||||
30 * (1 + (DynamicSpeedTrackPathDescriptor.CRITICAL_DIFFERENCE_PERCENTAGE / 100.00) * 2) };
|
||||
boolean[] expectedValues = { true, false, false, true };
|
||||
double[] expectedAverageMovingSpeed = { 20, 30, 30,
|
||||
30 * (1 + (DynamicSpeedTrackPathDescriptor.CRITICAL_DIFFERENCE_PERCENTAGE / 100.00) * 2) };
|
||||
double[] expectedAverageMovingSpeed = { 0, 30, 30, 30 };
|
||||
// Test
|
||||
for (int i = 0; i < newAverageMovingSpeed.length; i++) {
|
||||
dynamicSpeedTrackPathDescriptor.setAverageMovingSpeed(averageMovingSpeeds[i]);
|
||||
|
||||
+3
-3
@@ -62,7 +62,7 @@ public class DynamicSpeedTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
public void testUpdatePath_AllInvalidLocation() {
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS, INVALID_LATITUDE, -1);
|
||||
dynamicSpeedTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), 1, true, points);
|
||||
myTracksOverlay.getMapViewRect(mockView), 1, points);
|
||||
AndroidMock.verify(trackPathDescriptor);
|
||||
// Should be zero for there is no valid locations.
|
||||
assertEquals(0, dynamicSpeedTrackPathPainter.getColoredPaths().size());
|
||||
@@ -80,7 +80,7 @@ public class DynamicSpeedTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
// Gets a number as the start index of points.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
dynamicSpeedTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points);
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, points);
|
||||
|
||||
AndroidMock.verify(trackPathDescriptor);
|
||||
assertEquals(NUMBER_OF_LOCATIONS - startLocationIdx, dynamicSpeedTrackPathPainter
|
||||
@@ -123,7 +123,7 @@ public class DynamicSpeedTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
slowSpeed));
|
||||
|
||||
dynamicSpeedTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points);
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, points);
|
||||
|
||||
AndroidMock.verify(trackPathDescriptor);
|
||||
List<ColoredPath> coloredPath = dynamicSpeedTrackPathPainter.getColoredPaths();
|
||||
|
||||
+16
-14
@@ -31,9 +31,10 @@ import java.util.List;
|
||||
*/
|
||||
public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
|
||||
private static final int NUMBER_OF_LOCATIONS = 10;
|
||||
private SingleColorTrackPathPainter singleColorTrackPathPainter;
|
||||
private Path pathMock;
|
||||
private static final int NUMBER_OF_LOCATIONS = 100;
|
||||
|
||||
|
||||
/**
|
||||
* Initials a mocked TrackPathDescriptor object and
|
||||
@@ -44,8 +45,8 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
pathMock = AndroidMock.createStrictMock(Path.class);
|
||||
singleColorTrackPathPainter = new SingleColorTrackPathPainter(getContext());
|
||||
pathMock = AndroidMock.createStrictMock(Path.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,11 +55,12 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
* method when all locations are valid.
|
||||
*/
|
||||
public void testUpdatePath_AllValidLocation() {
|
||||
pathMock.incReserve(NUMBER_OF_LOCATIONS);
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS,
|
||||
TrackStubUtils.INITIAL_LATITUDE, -1);
|
||||
// Gets a number as the start index of points.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
|
||||
pathMock.incReserve(NUMBER_OF_LOCATIONS - startLocationIdx);
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS,
|
||||
TrackStubUtils.INITIAL_LATITUDE, -1);
|
||||
|
||||
for (int i = startLocationIdx; i < NUMBER_OF_LOCATIONS; i++) {
|
||||
pathMock.lineTo(0, 0);
|
||||
@@ -66,7 +68,7 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
|
||||
AndroidMock.replay(pathMock);
|
||||
singleColorTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points, pathMock);
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, points, pathMock);
|
||||
AndroidMock.verify(pathMock);
|
||||
}
|
||||
|
||||
@@ -76,20 +78,20 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
* method when all locations are invalid.
|
||||
*/
|
||||
public void testUpdatePath_AllInvalidLocation() {
|
||||
pathMock.incReserve(NUMBER_OF_LOCATIONS);
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
pathMock.incReserve(NUMBER_OF_LOCATIONS - startLocationIdx);
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS, INVALID_LATITUDE, -1);
|
||||
// Gets a random number from 1 to numberOfLocations.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
AndroidMock.replay(pathMock);
|
||||
singleColorTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points, pathMock);
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, points, pathMock);
|
||||
AndroidMock.verify(pathMock);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the
|
||||
* {@link SingleColorTrackPathPainter#updatePath(com.google.android.maps.Projection, android.graphics.Rect, int, Boolean, List, Path)}
|
||||
* method when there are three segments.
|
||||
* Tests the {@link SingleColorTrackPathPainter#updatePath(com.google.android.maps.Projection,
|
||||
* android.graphics.Rect, int, Boolean, List, Path)} method when there are
|
||||
* three segments.
|
||||
*/
|
||||
public void testUpdatePath_ThreeSegments() {
|
||||
// First segment.
|
||||
@@ -103,7 +105,7 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
points.addAll(createCachedLocations(NUMBER_OF_LOCATIONS, TrackStubUtils.INITIAL_LATITUDE, -1));
|
||||
// Gets a random number from 1 to numberOfLocations.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
pathMock.incReserve(NUMBER_OF_LOCATIONS *3 + 1 +1);
|
||||
pathMock.incReserve(NUMBER_OF_LOCATIONS *3 + 1 +1 - startLocationIdx);
|
||||
for (int i = 0; i < NUMBER_OF_LOCATIONS - startLocationIdx; i++) {
|
||||
pathMock.lineTo(0, 0);
|
||||
}
|
||||
@@ -118,7 +120,7 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
|
||||
AndroidMock.replay(pathMock);
|
||||
singleColorTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points, pathMock);
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, points, pathMock);
|
||||
AndroidMock.verify(pathMock);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -40,13 +40,12 @@ public class TrackPathDescriptorDynamicSpeedTest extends TrackPathPainterTestCas
|
||||
myTracksOverlay.setTrackPathPainter(painter);
|
||||
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
|
||||
assertNotNull(painter);
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx,
|
||||
myTracksOverlay.getPoints());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
painter.drawTrack(canvas);
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().hasPath());
|
||||
painter.drawPath(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-6
@@ -40,13 +40,11 @@ public class TrackPathDescriptorFixedSpeedTest extends TrackPathPainterTestCase
|
||||
myTracksOverlay.setTrackPathPainter(painter);
|
||||
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
|
||||
assertNotNull(painter);
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getPoints());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
painter.drawTrack(canvas);
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, myTracksOverlay.getPoints());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().hasPath());
|
||||
painter.drawPath(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -55,8 +55,7 @@ public class TrackPathPainterFactoryTest extends TrackPathPainterTestCase {
|
||||
context, R.string.track_color_mode_key, context.getString(track_color_mode));
|
||||
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
|
||||
TrackPathPainter painter = TrackPathPainterFactory.getTrackPathPainter(context);
|
||||
myTracksOverlay.setTrackPathPainter(painter);
|
||||
|
||||
@@ -64,9 +63,9 @@ public class TrackPathPainterFactoryTest extends TrackPathPainterTestCase {
|
||||
assertTrue(c.isInstance(painter));
|
||||
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx,
|
||||
myTracksOverlay.getPoints());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
painter.drawTrack(canvas);
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().hasPath());
|
||||
painter.drawPath(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -39,13 +39,12 @@ public class TrackPathPainterSingleColorTest extends TrackPathPainterTestCase {
|
||||
myTracksOverlay.setTrackPathPainter(painter);
|
||||
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
assertNotNull(painter);
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx,
|
||||
myTracksOverlay.getPoints());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
painter.drawTrack(canvas);
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().hasPath());
|
||||
painter.drawPath(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user