Make sure the start marker is always shown during a recording.

This commit is contained in:
Jimmy Shih
2013-05-23 12:53:09 -07:00
parent 640f960bd0
commit 0d38d1b38d
2 changed files with 19 additions and 6 deletions
@@ -210,9 +210,11 @@ public class MapOverlay {
* @param googleMap the google map * @param googleMap the google map
* @param paths the paths * @param paths the paths
* @param reload true to reload all points * @param reload true to reload all points
* @return true if has the start marker
*/ */
public void update(GoogleMap googleMap, ArrayList<Polyline> paths, boolean reload) { public boolean update(GoogleMap googleMap, ArrayList<Polyline> paths, boolean reload) {
synchronized (locations) { synchronized (locations) {
boolean hasStartMarker = false;
// Merge pendingLocations with locations // Merge pendingLocations with locations
int newLocations = pendingLocations.drainTo(locations); int newLocations = pendingLocations.drainTo(locations);
// Call updateState first because we want to update its state each time // Call updateState first because we want to update its state each time
@@ -221,7 +223,7 @@ public class MapOverlay {
googleMap.clear(); googleMap.clear();
paths.clear(); paths.clear();
trackPath.updatePath(googleMap, paths, 0, locations); trackPath.updatePath(googleMap, paths, 0, locations);
updateStartAndEndMarkers(googleMap); hasStartMarker = updateStartAndEndMarkers(googleMap);
updateWaypoints(googleMap); updateWaypoints(googleMap);
} else { } else {
if (newLocations != 0) { if (newLocations != 0) {
@@ -229,6 +231,7 @@ public class MapOverlay {
trackPath.updatePath(googleMap, paths, numLocations - newLocations, locations); trackPath.updatePath(googleMap, paths, numLocations - newLocations, locations);
} }
} }
return hasStartMarker;
} }
} }
@@ -236,8 +239,9 @@ public class MapOverlay {
* Updates the start and end markers. * Updates the start and end markers.
* *
* @param googleMap the google map * @param googleMap the google map
* @return true if has the start marker
*/ */
private void updateStartAndEndMarkers(GoogleMap googleMap) { private boolean updateStartAndEndMarkers(GoogleMap googleMap) {
// Add the end marker // Add the end marker
if (showEndMarker) { if (showEndMarker) {
for (int i = locations.size() - 1; i >= 0; i--) { for (int i = locations.size() - 1; i >= 0; i--) {
@@ -253,6 +257,7 @@ public class MapOverlay {
} }
// Add the start marker // Add the start marker
boolean hasStartMarker = false;
for (int i = 0; i < locations.size(); i++) { for (int i = 0; i < locations.size(); i++) {
CachedLocation cachedLocation = locations.get(i); CachedLocation cachedLocation = locations.get(i);
if (cachedLocation.valid) { if (cachedLocation.valid) {
@@ -260,9 +265,11 @@ public class MapOverlay {
.anchor(MARKER_X_ANCHOR, MARKER_Y_ANCHOR).draggable(false).visible(true) .anchor(MARKER_X_ANCHOR, MARKER_Y_ANCHOR).draggable(false).visible(true)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.green_dot)); .icon(BitmapDescriptorFactory.fromResource(R.drawable.green_dot));
googleMap.addMarker(markerOptions); googleMap.addMarker(markerOptions);
hasStartMarker = true;
break; break;
} }
} }
return hasStartMarker;
} }
/** /**
@@ -455,9 +455,15 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
getActivity().runOnUiThread(new Runnable() { getActivity().runOnUiThread(new Runnable() {
public void run() { public void run() {
if (isResumed() && googleMap != null) { if (isResumed() && googleMap != null) {
mapOverlay.update(googleMap, paths, reloadPaths); boolean hasStartMarker = mapOverlay.update(googleMap, paths, reloadPaths);
reloadPaths = false;
/*
* If has the start marker, then don't need to reload the paths each
* time
*/
if (hasStartMarker) {
reloadPaths = false;
}
if (!isSelectedTrackRecording() || isSelectedTrackPaused()) { if (!isSelectedTrackRecording() || isSelectedTrackPaused()) {
lastTrackPoint = null; lastTrackPoint = null;
} }