forked from upstream-mirrors/OpenTracks
Merge heads
This commit is contained in:
+42
-59
@@ -50,83 +50,66 @@ public class SendToGoogleUtils {
|
|||||||
ArrayList<Track> splitTracks = new ArrayList<Track>();
|
ArrayList<Track> splitTracks = new ArrayList<Track>();
|
||||||
|
|
||||||
// Create a new segment
|
// Create a new segment
|
||||||
|
Track segment = createNewSegment(
|
||||||
|
track, locations.size() > 0 ? locations.get(0).getTime() : -1L);
|
||||||
|
|
||||||
|
for (Location location : locations) {
|
||||||
|
/*
|
||||||
|
* Latitude is greater than 90 if the location is a pause/resume
|
||||||
|
* separator.
|
||||||
|
*/
|
||||||
|
if (location.getLatitude() > 90) {
|
||||||
|
endSegment(segment, location.getTime(), splitTracks);
|
||||||
|
segment = createNewSegment(track, location.getTime());
|
||||||
|
} else {
|
||||||
|
segment.addLocation(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endSegment(segment, locations.size() > 0 ? locations.get(locations.size() - 1).getTime() : -1L,
|
||||||
|
splitTracks);
|
||||||
|
return splitTracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new segment for a track.
|
||||||
|
*
|
||||||
|
* @param track the track
|
||||||
|
* @param startTime the segment start time
|
||||||
|
*/
|
||||||
|
private static Track createNewSegment(Track track, long startTime) {
|
||||||
Track segment = new Track();
|
Track segment = new Track();
|
||||||
segment.setId(track.getId());
|
segment.setId(track.getId());
|
||||||
segment.setName(track.getName());
|
segment.setName(track.getName());
|
||||||
segment.setDescription("");
|
segment.setDescription("");
|
||||||
segment.setCategory(track.getCategory());
|
segment.setCategory(track.getCategory());
|
||||||
|
TripStatistics segmentTripStatistics = segment.getTripStatistics();
|
||||||
TripStatistics segmentStats = segment.getTripStatistics();
|
segmentTripStatistics.setStartTime(startTime);
|
||||||
TripStatistics trackStats = track.getTripStatistics();
|
return segment;
|
||||||
segmentStats.setStartTime(trackStats.getStartTime());
|
|
||||||
segmentStats.setStopTime(trackStats.getStopTime());
|
|
||||||
boolean startNewTrackSegment = false;
|
|
||||||
for (Location loc : locations) {
|
|
||||||
// Latitude is greater than 90 if the location is invalid. Do not add to
|
|
||||||
// the segment.
|
|
||||||
if (loc.getLatitude() > 90) {
|
|
||||||
startNewTrackSegment = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (startNewTrackSegment) {
|
|
||||||
// Close the last segment
|
|
||||||
prepareTrackSegment(segment, splitTracks);
|
|
||||||
|
|
||||||
startNewTrackSegment = false;
|
|
||||||
segment = new Track();
|
|
||||||
segment.setId(track.getId());
|
|
||||||
segment.setName(track.getName());
|
|
||||||
segment.setDescription("");
|
|
||||||
segment.setCategory(track.getCategory());
|
|
||||||
segmentStats = segment.getTripStatistics();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (loc.getLatitude() <= 90) {
|
|
||||||
segment.addLocation(loc);
|
|
||||||
|
|
||||||
// For a new segment, sets its start time using the first available
|
|
||||||
// location time.
|
|
||||||
if (segmentStats.getStartTime() < 0) {
|
|
||||||
segmentStats.setStartTime(loc.getTime());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
prepareTrackSegment(segment, splitTracks);
|
|
||||||
|
|
||||||
return splitTracks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares a track segment for sending to Google Maps or Google Fusion
|
* Ends a segment. Adds to the array of track segments if the segment is
|
||||||
* Tables. The main steps are:
|
* valid.
|
||||||
* <ul>
|
|
||||||
* <li>make sure the segment has at least 2 points</li>
|
|
||||||
* <li>set the segment stop time if necessary</li>
|
|
||||||
* <li>decimate locations precision</li>
|
|
||||||
* </ul>
|
|
||||||
* The prepared track will be added to the splitTracks.
|
|
||||||
*
|
*
|
||||||
* @param segment the track segment
|
* @param segment the segment
|
||||||
* @param splitTracks an array of track segments
|
* @param stopTime the stop time
|
||||||
|
* @param splitTracks the array of track segments
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static boolean prepareTrackSegment(Track segment, ArrayList<Track> splitTracks) {
|
static boolean endSegment(Track segment, long stopTime, ArrayList<Track> splitTracks) {
|
||||||
// Make sure the segment has at least 2 points
|
// Make sure the segment has at least 2 points
|
||||||
if (segment.getLocations().size() < 2) {
|
if (segment.getLocations().size() < 2) {
|
||||||
Log.d(TAG, "segment has less than 2 points");
|
Log.d(TAG, "segment has less than 2 points");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For a new segment, sets it stop time
|
// Set its stop time
|
||||||
TripStatistics segmentStats = segment.getTripStatistics();
|
segment.getTripStatistics().setStopTime(stopTime);
|
||||||
if (segmentStats.getStopTime() < 0) {
|
|
||||||
Location lastLocation = segment.getLocations().get(segment.getLocations().size() - 1);
|
|
||||||
segmentStats.setStopTime(lastLocation.getTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decimate to 2 meter precision. Google Maps and Google Fusion Tables do
|
/*
|
||||||
// not like the locations to be too precise.
|
* Decimate to 2 meter precision. Google Maps and Google Fusion Tables do
|
||||||
|
* not like the locations to be too precise.
|
||||||
|
*/
|
||||||
LocationUtils.decimate(segment, 2.0);
|
LocationUtils.decimate(segment, 2.0);
|
||||||
|
|
||||||
splitTracks.add(segment);
|
splitTracks.add(segment);
|
||||||
|
|||||||
@@ -72,11 +72,7 @@ public class TimerTaskExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long next = System.currentTimeMillis() + interval - (tripStatistics.getTotalTime() % interval);
|
||||||
long next = tripStatistics.getStartTime();
|
|
||||||
if (next < now) {
|
|
||||||
next = now + interval - ((now - next) % interval);
|
|
||||||
}
|
|
||||||
timer.scheduleAtFixedRate(new PeriodicTimerTask(), new Date(next), interval);
|
timer.scheduleAtFixedRate(new PeriodicTimerTask(), new Date(next), interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -607,7 +607,7 @@ public class EndToEndTestUtils {
|
|||||||
return findResult;
|
return findResult;
|
||||||
}
|
}
|
||||||
showMenuItem();
|
showMenuItem();
|
||||||
findResult = SOLO.getText(menuName) != null;
|
findResult = SOLO.searchText(menuName);
|
||||||
} else {
|
} else {
|
||||||
// Non-ICS phone.
|
// Non-ICS phone.
|
||||||
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
SOLO.sendKey(KeyEvent.KEYCODE_MENU);
|
||||||
@@ -615,7 +615,7 @@ public class EndToEndTestUtils {
|
|||||||
findResult = true;
|
findResult = true;
|
||||||
} else if (SOLO.searchText(MENU_MORE)) {
|
} else if (SOLO.searchText(MENU_MORE)) {
|
||||||
SOLO.clickOnText(MENU_MORE);
|
SOLO.clickOnText(MENU_MORE);
|
||||||
findResult = SOLO.getText(menuName) != null;
|
findResult = SOLO.searchText(menuName);
|
||||||
isMoreMenuOpened = true;
|
isMoreMenuOpened = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-27
@@ -41,47 +41,30 @@ public class SendToGoogleUtilsTest extends TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link SendToGoogleUtils#prepareTrackSegment(Track, java.util.ArrayList)}
|
* {@link SendToGoogleUtils#endSegment(Track, long, ArrayList)}
|
||||||
* when there is only one location in a segment.
|
* when there is only one location in a segment.
|
||||||
*/
|
*/
|
||||||
public void testPrepareTrackSegment_onlyOneLocation() {
|
public void testPrepareTrackSegment_onlyOneLocation() {
|
||||||
Track trackStub = TrackStubUtils.createTrack(1);
|
Track segment = TrackStubUtils.createTrack(1);
|
||||||
assertFalse(SendToGoogleUtils.prepareTrackSegment(trackStub, null));
|
assertFalse(SendToGoogleUtils.endSegment(segment, -1L, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link SendToGoogleUtils#prepareTrackSegment(Track, ArrayList)} when there
|
* {@link SendToGoogleUtils#endSegment(Track, long, ArrayList)} when there
|
||||||
* is no stop time.
|
* is no stop time.
|
||||||
*/
|
*/
|
||||||
public void testPrepareTrackSegment_noStopTime() {
|
public void testPrepareTrackSegment_noStopTime() {
|
||||||
Track trackStub = TrackStubUtils.createTrack(2);
|
Track segment = TrackStubUtils.createTrack(2);
|
||||||
assertEquals(-1L, trackStub.getTripStatistics().getStopTime());
|
assertEquals(-1L, segment.getTripStatistics().getStopTime());
|
||||||
|
|
||||||
ArrayList<Track> tracksArray = new ArrayList<Track>();
|
ArrayList<Track> tracksArray = new ArrayList<Track>();
|
||||||
assertTrue(SendToGoogleUtils.prepareTrackSegment(trackStub, tracksArray));
|
assertTrue(SendToGoogleUtils.endSegment(
|
||||||
assertEquals(trackStub, tracksArray.get(0));
|
segment, segment.getLocations().get(1).getTime(), tracksArray));
|
||||||
|
assertEquals(segment, tracksArray.get(0));
|
||||||
// The stop time should be the time of last location
|
// The stop time should be the time of last location
|
||||||
assertEquals(
|
assertEquals(
|
||||||
trackStub.getLocations().get(1).getTime(), trackStub.getTripStatistics().getStopTime());
|
segment.getLocations().get(1).getTime(), segment.getTripStatistics().getStopTime());
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the method
|
|
||||||
* {@link SendToGoogleUtils#prepareTrackSegment(Track, java.util.ArrayList)}
|
|
||||||
* when there is stop time.
|
|
||||||
*/
|
|
||||||
public void testPrepareTrackSegment_hasStopTime() {
|
|
||||||
Track trackStub = TrackStubUtils.createTrack(2);
|
|
||||||
// Gives a margin to make sure the this time will be not same with the last
|
|
||||||
// location in the track.
|
|
||||||
long stopTime = System.currentTimeMillis() + 1000;
|
|
||||||
trackStub.getTripStatistics().setStopTime(stopTime);
|
|
||||||
|
|
||||||
ArrayList<Track> tracksArray = new ArrayList<Track>();
|
|
||||||
SendToGoogleUtils.prepareTrackSegment(trackStub, tracksArray);
|
|
||||||
assertEquals(trackStub, tracksArray.get(0));
|
|
||||||
assertEquals(stopTime, trackStub.getTripStatistics().getStopTime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user