diff --git a/MyTracks/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainter.java b/MyTracks/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainter.java index cd9ee85a7..8e3d099ff 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainter.java @@ -51,9 +51,9 @@ public class SingleColorTrackPathPainter implements TrackPathPainter { @Override public void updatePath(Projection projection, Rect viewRect, int startLocationIdx, Boolean alwaysVisible, List points) { - Path newPath = new Path(); - newPath.incReserve(points.size()); - path = updatePath(projection, viewRect, startLocationIdx, alwaysVisible, points, newPath); + path = new Path(); + path.incReserve(points.size()); + updatePath(projection, viewRect, startLocationIdx, alwaysVisible, points, path); } @@ -68,7 +68,7 @@ public class SingleColorTrackPathPainter implements TrackPathPainter { * @param newPath The path to be created. */ @VisibleForTesting - Path updatePath(Projection projection, Rect viewRect, int startLocationIdx, + void updatePath(Projection projection, Rect viewRect, int startLocationIdx, Boolean alwaysVisible, List points, Path newPath) { // Whether to start a new segment on new valid and visible point. boolean newSegment = startLocationIdx <= 0 || !points.get(startLocationIdx - 1).valid; @@ -103,7 +103,6 @@ public class SingleColorTrackPathPainter implements TrackPathPainter { newPath.lineTo(pt.x, pt.y); } } - return newPath; } @Override diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathPainterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathPainterTest.java index d6044e59f..fb75fe62a 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathPainterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/maps/DynamicSpeedTrackPathPainterTest.java @@ -34,13 +34,12 @@ public class DynamicSpeedTrackPathPainterTest extends TrackPathPainterTestCase { private DynamicSpeedTrackPathPainter dynamicSpeedTrackPathPainter; private TrackPathDescriptor trackPathDescriptor; - // This number must bigger than 10 to meets the requirement of test. + // This number must bigger than 10 to meet the requirement of test. private static final int NUMBER_OF_LOCATIONS = 100; - private static final int NUMBER_OF_SEGMENTS = 4; private static final int LOCATIONS_PER_SEGMENT = 25; - // The maximum speed which is considered slow. + // The maximum speed(KM/H) which is considered slow. private static final int SLOW_SPEED = 30; - // The maximum speed which is considered normal. + // The maximum speed(KM/H) which is considered normal. private static final int NORMAL_SPEED = 50; @Override @@ -94,18 +93,21 @@ public class DynamicSpeedTrackPathPainterTest extends TrackPathPainterTestCase { */ public void testUpdatePath_CheckColoredPath() { // Gets the slow speed. Divide SLOW_SPEED by 2 to make it smaller than - // SLOW_SPEED. + // SLOW_SPEED. Speed in MyTracksLocation use MS, but speed in CachedLocation + // use KMH. int slowSpeed = (int) (SLOW_SPEED / (2 * UnitConversions.MS_TO_KMH)); // Gets the normal speed. Makes it smaller than SLOW_SPEED and bigger than - // NORMAL_SPEED. + // NORMAL_SPEED. Speed in MyTracksLocation use MS, but speed in + // CachedLocation use KMH. int normalSpeed = (int) ((SLOW_SPEED + NORMAL_SPEED) / (2 * UnitConversions.MS_TO_KMH)); // Gets the fast speed. Multiply it by 2 to make it bigger than - // NORMAL_SPEED. + // NORMAL_SPEED. Speed in MyTracksLocation use MS, but speed in + // CachedLocation use KMH. int fastSpeed = (int) (NORMAL_SPEED * 2 / UnitConversions.MS_TO_KMH); // Get a number of startLocationIdx. And divide NUMBER_OF_LOCATIONS by 8 to // make sure it is less than numberOfFirstThreeSegments. - int startLocationIdx = NUMBER_OF_LOCATIONS / NUMBER_OF_SEGMENTS / 2; + int startLocationIdx = LOCATIONS_PER_SEGMENT / 2; List points = createCachedLocations(LOCATIONS_PER_SEGMENT, TrackStubUtils.INITIAL_LATITUDE, slowSpeed); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainterTest.java index 3654cf396..70694f836 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/maps/SingleColorTrackPathPainterTest.java @@ -59,7 +59,7 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase { // Gets a number as the start index of points. int startLocationIdx = NUMBER_OF_LOCATIONS / 2; - for (int i = 0; i < NUMBER_OF_LOCATIONS - startLocationIdx; i++) { + for (int i = startLocationIdx; i < NUMBER_OF_LOCATIONS; i++) { pathMock.lineTo(0, 0); } @@ -77,7 +77,7 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase { public void testUpdatePath_AllInvalidLocation() { List points = createCachedLocations(NUMBER_OF_LOCATIONS, INVALID_LATITUDE, -1); // Gets a random number from 1 to numberOfLocations. - int startLocationIdx = (int) (1 + (NUMBER_OF_LOCATIONS - 1) * Math.random()); + int startLocationIdx = NUMBER_OF_LOCATIONS / 2; AndroidMock.replay(pathMock); singleColorTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView), myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points, pathMock); @@ -100,7 +100,7 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase { // Third segment. points.addAll(createCachedLocations(NUMBER_OF_LOCATIONS, TrackStubUtils.INITIAL_LATITUDE, -1)); // Gets a random number from 1 to numberOfLocations. - int startLocationIdx = (int) (1 + (NUMBER_OF_LOCATIONS - 1) * Math.random()); + int startLocationIdx = NUMBER_OF_LOCATIONS / 2; for (int i = 0; i < NUMBER_OF_LOCATIONS - startLocationIdx; i++) { pathMock.lineTo(0, 0); } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathPainterTestCase.java b/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathPainterTestCase.java index 3069e7cf6..b53909b6e 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathPainterTestCase.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/maps/TrackPathPainterTestCase.java @@ -56,7 +56,7 @@ public class TrackPathPainterTestCase extends AndroidTestCase { * * @param number the number of locations * @param latitude the latitude value of locations. - * @param speed the speed of locations, and will give a default valid value if + * @param speed the speed(meter per second) of locations, and will give a default valid value if * less than zero * @return the simulated locations */