forked from upstream-mirrors/OpenTracks
Code refactor. Remove DynamicSpeedTrackPathDescriptor's dependency on selected_track_id_key.
This commit is contained in:
@@ -22,6 +22,7 @@ import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
||||
import com.google.android.apps.mytracks.maps.TrackPath;
|
||||
import com.google.android.apps.mytracks.maps.TrackPathFactory;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
@@ -209,17 +210,19 @@ public class MapOverlay {
|
||||
*
|
||||
* @param googleMap the google map
|
||||
* @param paths the paths
|
||||
* @param tripStatistics the trip statistics
|
||||
* @param reload true to reload all points
|
||||
* @return true if has the start marker
|
||||
*/
|
||||
public boolean update(GoogleMap googleMap, ArrayList<Polyline> paths, boolean reload) {
|
||||
public boolean update(GoogleMap googleMap, ArrayList<Polyline> paths,
|
||||
TripStatistics tripStatistics, boolean reload) {
|
||||
synchronized (locations) {
|
||||
boolean hasStartMarker = false;
|
||||
// Merge pendingLocations with locations
|
||||
int newLocations = pendingLocations.drainTo(locations);
|
||||
// Call updateState first because we want to update its state each time
|
||||
// (for dynamic coloring)
|
||||
if (trackPath.updateState() || reload) {
|
||||
if (trackPath.updateState(tripStatistics) || reload) {
|
||||
googleMap.clear();
|
||||
paths.clear();
|
||||
trackPath.updatePath(googleMap, paths, 0, locations);
|
||||
|
||||
@@ -426,9 +426,10 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
||||
if (isResumed()) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (isResumed() && googleMap != null) {
|
||||
boolean hasStartMarker = mapOverlay.update(googleMap, paths, reloadPaths);
|
||||
|
||||
if (isResumed() && googleMap != null && currentTrack != null) {
|
||||
boolean hasStartMarker = mapOverlay.update(
|
||||
googleMap, paths, currentTrack.getTripStatistics(), reloadPaths);
|
||||
|
||||
/*
|
||||
* If has the start marker, then don't need to reload the paths each
|
||||
* time
|
||||
@@ -436,11 +437,11 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
||||
if (hasStartMarker) {
|
||||
reloadPaths = false;
|
||||
}
|
||||
|
||||
|
||||
if (lastTrackPoint != null && isSelectedTrackRecording()) {
|
||||
boolean firstLocation = setCurrentLocation(lastTrackPoint);
|
||||
if (firstLocation) {
|
||||
keepCurrentLocationVisible = true;
|
||||
keepCurrentLocationVisible = true;
|
||||
}
|
||||
updateCurrentLocation(firstLocation);
|
||||
setWarningMessage(true);
|
||||
@@ -470,8 +471,8 @@ public class MyTracksMapFragment extends SupportMapFragment implements TrackData
|
||||
if (isResumed()) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if (isResumed() && googleMap != null) {
|
||||
mapOverlay.update(googleMap, paths, true);
|
||||
if (isResumed() && googleMap != null && currentTrack != null) {
|
||||
mapOverlay.update(googleMap, paths, currentTrack.getTripStatistics(), true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+1
-17
@@ -16,11 +16,7 @@
|
||||
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||
@@ -30,7 +26,6 @@ import com.google.common.annotations.VisibleForTesting;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* A dynamic speed path descriptor.
|
||||
@@ -79,18 +74,7 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState() {
|
||||
long selectedTrackId = PreferencesUtils.getLong(context, R.string.selected_track_id_key);
|
||||
if (selectedTrackId == PreferencesUtils.SELECTED_TRACK_ID_DEFAULT) {
|
||||
Log.d(TAG, "No selected track id.");
|
||||
return false;
|
||||
}
|
||||
Track track = MyTracksProviderUtils.Factory.get(context).getTrack(selectedTrackId);
|
||||
if (track == null) {
|
||||
Log.d(TAG, "No track for " + selectedTrackId);
|
||||
return false;
|
||||
}
|
||||
TripStatistics tripStatistics = track.getTripStatistics();
|
||||
public boolean updateState(TripStatistics tripStatistics) {
|
||||
double newAverageMovingSpeed = (int) Math.floor(
|
||||
tripStatistics.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH);
|
||||
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -71,7 +72,7 @@ public class FixedSpeedTrackPathDescriptor implements TrackPathDescriptor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState() {
|
||||
public boolean updateState(TripStatistics tripStatistics) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.MapOverlay.CachedLocation;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.Polyline;
|
||||
@@ -47,8 +48,8 @@ public class MultiColorTrackPath implements TrackPath {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState() {
|
||||
return trackPathDescriptor.updateState();
|
||||
public boolean updateState(TripStatistics tripStatistics) {
|
||||
return trackPathDescriptor.updateState(tripStatistics);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.MapOverlay.CachedLocation;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.Polyline;
|
||||
@@ -40,7 +41,7 @@ public class SingleColorTrackPath implements TrackPath {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateState() {
|
||||
public boolean updateState(TripStatistics tripStatistics) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.MapOverlay.CachedLocation;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.model.Polyline;
|
||||
|
||||
@@ -30,7 +31,13 @@ import java.util.List;
|
||||
*/
|
||||
public interface TrackPath {
|
||||
|
||||
public boolean updateState();
|
||||
/**
|
||||
* Updates state.
|
||||
*
|
||||
* @param tripstatistics the trip statistics
|
||||
* @return true if the state is updated.
|
||||
*/
|
||||
public boolean updateState(TripStatistics tripStatistrics);
|
||||
|
||||
/**
|
||||
* Updates the path.
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
|
||||
/**
|
||||
* An interface for classes which describe how to draw a track path.
|
||||
*
|
||||
@@ -34,7 +36,10 @@ public interface TrackPathDescriptor {
|
||||
public int getNormalSpeed();
|
||||
|
||||
/**
|
||||
* Updates state. Returns true if the state is updated.
|
||||
* Updates state.
|
||||
*
|
||||
* @param tripstatistics the trip statistics
|
||||
* @return true if the state is updated.
|
||||
*/
|
||||
public boolean updateState();
|
||||
public boolean updateState(TripStatistics tripstatistics);
|
||||
}
|
||||
-12
@@ -77,18 +77,6 @@ public class DynamicSpeedTrackPathDescriptorTest extends AndroidTestCase {
|
||||
assertEquals(55, dynamicSpeedTrackPathDescriptor.getNormalSpeed());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#updateState()} by wrong track
|
||||
* id.
|
||||
*/
|
||||
public void testNeedsRedraw_WrongTrackId() {
|
||||
PreferencesUtils.setLong(context, R.string.selected_track_id_key,
|
||||
PreferencesUtils.SELECTED_TRACK_ID_DEFAULT);
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
assertEquals(false, dynamicSpeedTrackPathDescriptor.updateState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link DynamicSpeedTrackPathDescriptor#updateState()} by different
|
||||
* averageMovingSpeed.
|
||||
|
||||
Reference in New Issue
Block a user