forked from upstream-mirrors/OpenTracks
Merge heads
This commit is contained in:
@@ -114,12 +114,12 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
|
|||||||
if (newMarker) {
|
if (newMarker) {
|
||||||
statisticsSection.setVisibility(View.GONE);
|
statisticsSection.setVisibility(View.GONE);
|
||||||
waypointSection.setVisibility(View.VISIBLE);
|
waypointSection.setVisibility(View.VISIBLE);
|
||||||
int nextMarkerNumber = trackId == -1L ? -1
|
int nextWaypointNumber = trackId == -1L ? -1
|
||||||
: MyTracksProviderUtils.Factory.get(this).getNextMarkerNumber(trackId, false);
|
: MyTracksProviderUtils.Factory.get(this).getNextWaypointNumber(trackId, false);
|
||||||
if (nextMarkerNumber == -1) {
|
if (nextWaypointNumber == -1) {
|
||||||
nextMarkerNumber = 0;
|
nextWaypointNumber = 0;
|
||||||
}
|
}
|
||||||
waypointName.setText(getString(R.string.marker_name_format, nextMarkerNumber));
|
waypointName.setText(getString(R.string.marker_name_format, nextWaypointNumber));
|
||||||
waypointName.selectAll();
|
waypointName.selectAll();
|
||||||
waypointMarkerType.setText("");
|
waypointMarkerType.setText("");
|
||||||
waypointDescription.setText("");
|
waypointDescription.setText("");
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity {
|
|||||||
Button cancel = (Button) findViewById(R.id.track_edit_cancel);
|
Button cancel = (Button) findViewById(R.id.track_edit_cancel);
|
||||||
if (getIntent().getBooleanExtra(EXTRA_NEW_TRACK, false)) {
|
if (getIntent().getBooleanExtra(EXTRA_NEW_TRACK, false)) {
|
||||||
String trackName = TrackNameUtils.getTrackName(
|
String trackName = TrackNameUtils.getTrackName(
|
||||||
this, -1L, -1L, myTracksProviderUtils.getLastLocation());
|
this, -1L, -1L, myTracksProviderUtils.getLastValidTrackPoint(trackId));
|
||||||
if (trackName != null) {
|
if (trackName != null) {
|
||||||
name.setText(trackName);
|
name.setText(trackName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ public class SearchEngine {
|
|||||||
queryLikeSelection,
|
queryLikeSelection,
|
||||||
queryLikeSelection };
|
queryLikeSelection };
|
||||||
|
|
||||||
Cursor tracksCursor = providerUtils.getTracksCursor(
|
Cursor tracksCursor = providerUtils.getTrackCursor(
|
||||||
TRACK_SELECTION_QUERY, trackSelectionArgs, TRACK_SELECTION_ORDER);
|
TRACK_SELECTION_QUERY, trackSelectionArgs, TRACK_SELECTION_ORDER);
|
||||||
if (tracksCursor != null) {
|
if (tracksCursor != null) {
|
||||||
try {
|
try {
|
||||||
@@ -213,21 +213,21 @@ public class SearchEngine {
|
|||||||
queryLikeSelection2,
|
queryLikeSelection2,
|
||||||
queryLikeSelection2,
|
queryLikeSelection2,
|
||||||
queryLikeSelection2 };
|
queryLikeSelection2 };
|
||||||
Cursor waypointsCursor = providerUtils.getWaypointsCursor(
|
Cursor waypointCursor = providerUtils.getWaypointCursor(
|
||||||
WAYPOINT_SELECTION_QUERY, waypointSelectionArgs, WAYPOINT_SELECTION_ORDER,
|
WAYPOINT_SELECTION_QUERY, waypointSelectionArgs, WAYPOINT_SELECTION_ORDER,
|
||||||
MAX_SCORED_WAYPOINTS);
|
MAX_SCORED_WAYPOINTS);
|
||||||
if (waypointsCursor != null) {
|
if (waypointCursor != null) {
|
||||||
try {
|
try {
|
||||||
waypoints.ensureCapacity(waypointsCursor.getCount());
|
waypoints.ensureCapacity(waypointCursor.getCount());
|
||||||
|
|
||||||
while (waypointsCursor.moveToNext()) {
|
while (waypointCursor.moveToNext()) {
|
||||||
Waypoint waypoint = providerUtils.createWaypoint(waypointsCursor);
|
Waypoint waypoint = providerUtils.createWaypoint(waypointCursor);
|
||||||
if (LocationUtils.isValidLocation(waypoint.getLocation())) {
|
if (LocationUtils.isValidLocation(waypoint.getLocation())) {
|
||||||
waypoints.add(waypoint);
|
waypoints.add(waypoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
waypointsCursor.close();
|
waypointCursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -563,7 +563,7 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
|
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = myTracksProviderUtils.getWaypointsCursor(
|
cursor = myTracksProviderUtils.getWaypointCursor(
|
||||||
selectedTrackId, 0L, MAX_DISPLAYED_WAYPOINTS_POINTS);
|
selectedTrackId, 0L, MAX_DISPLAYED_WAYPOINTS_POINTS);
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
@@ -614,9 +614,9 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
long localLastSeenLocationId = updateSamplingState ? lastSeenLocationId : -1L;
|
long localLastSeenLocationId = updateSamplingState ? lastSeenLocationId : -1L;
|
||||||
long maxPointId = updateSamplingState ? -1L : lastSeenLocationId;
|
long maxPointId = updateSamplingState ? -1L : lastSeenLocationId;
|
||||||
|
|
||||||
long lastLocationId = myTracksProviderUtils.getLastTrackLocationId(selectedTrackId);
|
long lastTrackPointId = myTracksProviderUtils.getLastTrackPointId(selectedTrackId);
|
||||||
int samplingFrequency = -1;
|
int samplingFrequency = -1;
|
||||||
LocationIterator iterator = myTracksProviderUtils.getLocationIterator(
|
LocationIterator iterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
selectedTrackId, localLastSeenLocationId + 1, false, locationFactory);
|
selectedTrackId, localLastSeenLocationId + 1, false, locationFactory);
|
||||||
boolean includeNextPoint = false;
|
boolean includeNextPoint = false;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
@@ -633,7 +633,7 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (samplingFrequency == -1) {
|
if (samplingFrequency == -1) {
|
||||||
long numTotalPoints = Math.max(0L, lastLocationId - localFirstSeenLocationId);
|
long numTotalPoints = Math.max(0L, lastTrackPointId - localFirstSeenLocationId);
|
||||||
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,7 +646,7 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
} else {
|
} else {
|
||||||
// Also include the last point if the selected track is not recording.
|
// Also include the last point if the selected track is not recording.
|
||||||
if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0)
|
if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0)
|
||||||
|| (locationId == lastLocationId && !isSelectedTrackRecording())) {
|
|| (locationId == lastTrackPointId && !isSelectedTrackRecording())) {
|
||||||
includeNextPoint = false;
|
includeNextPoint = false;
|
||||||
for (TrackDataListener trackDataListener : sampledInListeners) {
|
for (TrackDataListener trackDataListener : sampledInListeners) {
|
||||||
trackDataListener.onSampledInTrackPoint(location);
|
trackDataListener.onSampledInTrackPoint(location);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import com.google.android.apps.mytracks.content.TrackDataListener;
|
|||||||
import com.google.android.apps.mytracks.content.TrackDataType;
|
import com.google.android.apps.mytracks.content.TrackDataType;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatisticsBuilder;
|
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater;
|
||||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.apps.mytracks.util.UnitConversions;
|
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||||
@@ -61,7 +61,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
private TrackDataHub trackDataHub;
|
private TrackDataHub trackDataHub;
|
||||||
|
|
||||||
// Stats gathered from the received data
|
// Stats gathered from the received data
|
||||||
private TripStatisticsBuilder tripStatisticsBuilder;
|
private TripStatisticsUpdater tripStatisticsUpdater;
|
||||||
private long startTime;
|
private long startTime;
|
||||||
|
|
||||||
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
private boolean metricUnits = PreferencesUtils.METRIC_UNITS_DEFAULT;
|
||||||
@@ -83,7 +83,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
private final Runnable updateChart = new Runnable() {
|
private final Runnable updateChart = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (trackDataHub == null) {
|
if (!isResumed() || trackDataHub == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,111 +178,141 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrackUpdated(Track track) {
|
public void onTrackUpdated(Track track) {
|
||||||
if (track == null || track.getTripStatistics() == null) {
|
if (isResumed()) {
|
||||||
startTime = -1L;
|
if (track == null || track.getTripStatistics() == null) {
|
||||||
return;
|
startTime = -1L;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
startTime = track.getTripStatistics().getStartTime();
|
||||||
}
|
}
|
||||||
startTime = track.getTripStatistics().getStartTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearTrackPoints() {
|
public void clearTrackPoints() {
|
||||||
tripStatisticsBuilder = startTime != -1L ? new TripStatisticsBuilder(startTime) : null;
|
if (isResumed()) {
|
||||||
pendingPoints.clear();
|
tripStatisticsUpdater = startTime != -1L ? new TripStatisticsUpdater(startTime) : null;
|
||||||
chartView.reset();
|
pendingPoints.clear();
|
||||||
|
chartView.reset();
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
chartView.resetScroll();
|
if (isResumed()) {
|
||||||
}
|
chartView.resetScroll();
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSampledInTrackPoint(Location location) {
|
public void onSampledInTrackPoint(Location location) {
|
||||||
double[] data = new double[ChartView.NUM_SERIES + 1];
|
if (isResumed()) {
|
||||||
fillDataPoint(location, data);
|
double[] data = new double[ChartView.NUM_SERIES + 1];
|
||||||
pendingPoints.add(data);
|
fillDataPoint(location, data);
|
||||||
|
pendingPoints.add(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSampledOutTrackPoint(Location location) {
|
public void onSampledOutTrackPoint(Location location) {
|
||||||
fillDataPoint(location, null);
|
if (isResumed()) {
|
||||||
|
fillDataPoint(location, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSegmentSplit(Location location) {
|
public void onSegmentSplit(Location location) {
|
||||||
fillDataPoint(location, null);
|
if (isResumed()) {
|
||||||
|
fillDataPoint(location, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewTrackPointsDone() {
|
public void onNewTrackPointsDone() {
|
||||||
chartView.addDataPoints(pendingPoints);
|
if (isResumed()) {
|
||||||
pendingPoints.clear();
|
chartView.addDataPoints(pendingPoints);
|
||||||
getActivity().runOnUiThread(updateChart);
|
pendingPoints.clear();
|
||||||
|
getActivity().runOnUiThread(updateChart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearWaypoints() {
|
public void clearWaypoints() {
|
||||||
chartView.clearWaypoints();
|
if (isResumed()) {
|
||||||
|
chartView.clearWaypoints();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewWaypoint(Waypoint waypoint) {
|
public void onNewWaypoint(Waypoint waypoint) {
|
||||||
if (waypoint != null && LocationUtils.isValidLocation(waypoint.getLocation())) {
|
if (isResumed() && waypoint != null && LocationUtils.isValidLocation(waypoint.getLocation())) {
|
||||||
chartView.addWaypoint(waypoint);
|
chartView.addWaypoint(waypoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewWaypointsDone() {
|
public void onNewWaypointsDone() {
|
||||||
getActivity().runOnUiThread(updateChart);
|
if (isResumed()) {
|
||||||
|
getActivity().runOnUiThread(updateChart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMetricUnitsChanged(boolean metric) {
|
public boolean onMetricUnitsChanged(boolean metric) {
|
||||||
if (metricUnits == metric) {
|
if (isResumed()) {
|
||||||
return false;
|
if (metricUnits == metric) {
|
||||||
}
|
return false;
|
||||||
metricUnits = metric;
|
|
||||||
chartView.setMetricUnits(metricUnits);
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
chartView.requestLayout();
|
|
||||||
}
|
}
|
||||||
});
|
metricUnits = metric;
|
||||||
return true;
|
chartView.setMetricUnits(metricUnits);
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (isResumed()) {
|
||||||
|
chartView.requestLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onReportSpeedChanged(boolean speed) {
|
public boolean onReportSpeedChanged(boolean speed) {
|
||||||
if (reportSpeed == speed) {
|
if (isResumed()) {
|
||||||
return false;
|
if (reportSpeed == speed) {
|
||||||
}
|
return false;
|
||||||
reportSpeed = speed;
|
|
||||||
chartView.setReportSpeed(reportSpeed);
|
|
||||||
boolean chartShowSpeed = PreferencesUtils.getBoolean(
|
|
||||||
getActivity(), R.string.chart_show_speed_key, PreferencesUtils.CHART_SHOW_SPEED_DEFAULT);
|
|
||||||
setSeriesEnabled(ChartView.SPEED_SERIES, chartShowSpeed && reportSpeed);
|
|
||||||
setSeriesEnabled(ChartView.PACE_SERIES, chartShowSpeed && !reportSpeed);
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
chartView.requestLayout();
|
|
||||||
}
|
}
|
||||||
});
|
reportSpeed = speed;
|
||||||
return true;
|
chartView.setReportSpeed(reportSpeed);
|
||||||
|
boolean chartShowSpeed = PreferencesUtils.getBoolean(
|
||||||
|
getActivity(), R.string.chart_show_speed_key, PreferencesUtils.CHART_SHOW_SPEED_DEFAULT);
|
||||||
|
setSeriesEnabled(ChartView.SPEED_SERIES, chartShowSpeed && reportSpeed);
|
||||||
|
setSeriesEnabled(ChartView.PACE_SERIES, chartShowSpeed && !reportSpeed);
|
||||||
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (isResumed()) {
|
||||||
|
chartView.requestLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMinRecordingDistanceChanged(int value) {
|
public boolean onMinRecordingDistanceChanged(int value) {
|
||||||
if (minRecordingDistance == value) {
|
if (isResumed()) {
|
||||||
return false;
|
if (minRecordingDistance == value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
minRecordingDistance = value;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
minRecordingDistance = value;
|
return false;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -424,9 +454,9 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
double cadence = Double.NaN;
|
double cadence = Double.NaN;
|
||||||
double power = Double.NaN;
|
double power = Double.NaN;
|
||||||
|
|
||||||
if (tripStatisticsBuilder != null) {
|
if (tripStatisticsUpdater != null) {
|
||||||
tripStatisticsBuilder.addLocation(location, minRecordingDistance);
|
tripStatisticsUpdater.addLocation(location, minRecordingDistance);
|
||||||
TripStatistics tripStatistics = tripStatisticsBuilder.getTripStatistics();
|
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
if (chartByDistance) {
|
if (chartByDistance) {
|
||||||
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
||||||
if (!metricUnits) {
|
if (!metricUnits) {
|
||||||
@@ -436,13 +466,13 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
} else {
|
} else {
|
||||||
timeOrDistance = tripStatistics.getTotalTime();
|
timeOrDistance = tripStatistics.getTotalTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
elevation = tripStatisticsBuilder.getSmoothedElevation();
|
elevation = tripStatisticsUpdater.getSmoothedElevation();
|
||||||
if (!metricUnits) {
|
if (!metricUnits) {
|
||||||
elevation *= UnitConversions.M_TO_FT;
|
elevation *= UnitConversions.M_TO_FT;
|
||||||
}
|
}
|
||||||
|
|
||||||
speed = tripStatisticsBuilder.getSmoothedSpeed() * UnitConversions.MS_TO_KMH;
|
speed = tripStatisticsUpdater.getSmoothedSpeed() * UnitConversions.MS_TO_KMH;
|
||||||
if (!metricUnits) {
|
if (!metricUnits) {
|
||||||
speed *= UnitConversions.KM_TO_MI;
|
speed *= UnitConversions.KM_TO_MI;
|
||||||
}
|
}
|
||||||
@@ -485,8 +515,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setTripStatisticsBuilder(long time) {
|
void setTripStatisticsUpdater(long time) {
|
||||||
tripStatisticsBuilder = new TripStatisticsBuilder(time);
|
tripStatisticsUpdater = new TripStatisticsUpdater(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
@@ -275,93 +275,104 @@ public class MapFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationStateChanged(LocationState state) {
|
public void onLocationStateChanged(LocationState state) {
|
||||||
final String message;
|
if (isResumed()) {
|
||||||
final boolean isGpsDisabled;
|
final String message;
|
||||||
if (!isSelectedTrackRecording()) {
|
final boolean isGpsDisabled;
|
||||||
message = null;
|
if (!isSelectedTrackRecording()) {
|
||||||
isGpsDisabled = false;
|
message = null;
|
||||||
} else {
|
isGpsDisabled = false;
|
||||||
switch (state) {
|
} else {
|
||||||
case DISABLED:
|
switch (state) {
|
||||||
String setting = getString(
|
case DISABLED:
|
||||||
GoogleLocationUtils.isAvailable(getActivity()) ? R.string.gps_google_location_settings
|
String setting = getString(
|
||||||
: R.string.gps_location_access);
|
GoogleLocationUtils.isAvailable(getActivity()) ? R.string.gps_google_location_settings
|
||||||
message = getString(R.string.gps_disabled, setting);
|
: R.string.gps_location_access);
|
||||||
isGpsDisabled = true;
|
message = getString(R.string.gps_disabled, setting);
|
||||||
break;
|
isGpsDisabled = true;
|
||||||
case NO_FIX:
|
break;
|
||||||
message = getString(R.string.gps_wait_for_signal);
|
case NO_FIX:
|
||||||
isGpsDisabled = false;
|
message = getString(R.string.gps_wait_for_signal);
|
||||||
break;
|
isGpsDisabled = false;
|
||||||
case BAD_FIX:
|
break;
|
||||||
message = getString(R.string.gps_wait_for_better_signal);
|
case BAD_FIX:
|
||||||
isGpsDisabled = false;
|
message = getString(R.string.gps_wait_for_better_signal);
|
||||||
break;
|
isGpsDisabled = false;
|
||||||
case GOOD_FIX:
|
break;
|
||||||
message = null;
|
case GOOD_FIX:
|
||||||
isGpsDisabled = false;
|
message = null;
|
||||||
break;
|
isGpsDisabled = false;
|
||||||
default:
|
break;
|
||||||
throw new IllegalArgumentException("Unexpected state: " + state);
|
default:
|
||||||
}
|
throw new IllegalArgumentException("Unexpected state: " + state);
|
||||||
}
|
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (message != null) {
|
|
||||||
messageTextView.setText(message);
|
|
||||||
messageTextView.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
if (isGpsDisabled) {
|
|
||||||
Toast.makeText(getActivity(), R.string.gps_not_found, Toast.LENGTH_LONG).show();
|
|
||||||
|
|
||||||
// Click to show the location source settings
|
|
||||||
messageTextView.setOnClickListener(MapFragment.this);
|
|
||||||
} else {
|
|
||||||
messageTextView.setOnClickListener(null);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
messageTextView.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (isResumed()) {
|
||||||
|
if (message == null) {
|
||||||
|
messageTextView.setVisibility(View.GONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
messageTextView.setText(message);
|
||||||
|
messageTextView.setVisibility(View.VISIBLE);
|
||||||
|
if (isGpsDisabled) {
|
||||||
|
Toast.makeText(getActivity(), R.string.gps_not_found, Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
|
// Click to show the location source settings
|
||||||
|
messageTextView.setOnClickListener(MapFragment.this);
|
||||||
|
} else {
|
||||||
|
messageTextView.setOnClickListener(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
currentLocation = location;
|
if (isResumed()) {
|
||||||
updateCurrentLocation();
|
currentLocation = location;
|
||||||
|
updateCurrentLocation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHeadingChanged(double heading) {
|
public void onHeadingChanged(double heading) {
|
||||||
if (mapOverlay.setHeading((float) heading)) {
|
if (isResumed()) {
|
||||||
mapView.postInvalidate();
|
if (mapOverlay.setHeading((float) heading)) {
|
||||||
|
mapView.postInvalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSelectedTrackChanged(final Track track) {
|
public void onSelectedTrackChanged(final Track track) {
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
if (isResumed()) {
|
||||||
@Override
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
boolean hasTrack = track != null;
|
public void run() {
|
||||||
mapOverlay.setTrackDrawingEnabled(hasTrack);
|
if (isResumed()) {
|
||||||
|
boolean hasTrack = track != null;
|
||||||
|
mapOverlay.setTrackDrawingEnabled(hasTrack);
|
||||||
|
|
||||||
if (hasTrack) {
|
if (hasTrack) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
/*
|
/*
|
||||||
* Synchronize to prevent race condition in changing markerTrackId
|
* Synchronize to prevent race condition in changing
|
||||||
* and markerId variables.
|
* markerTrackId and markerId variables.
|
||||||
*/
|
*/
|
||||||
currentSelectedTrackId = track.getId();
|
currentSelectedTrackId = track.getId();
|
||||||
updateMap(track);
|
updateMap(track);
|
||||||
|
}
|
||||||
|
mapOverlay.setShowEndMarker(!isSelectedTrackRecording());
|
||||||
|
}
|
||||||
|
mapView.invalidate();
|
||||||
}
|
}
|
||||||
mapOverlay.setShowEndMarker(!isSelectedTrackRecording());
|
|
||||||
}
|
}
|
||||||
mapView.invalidate();
|
});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -371,12 +382,16 @@ public class MapFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearTrackPoints() {
|
public void clearTrackPoints() {
|
||||||
mapOverlay.clearPoints();
|
if (isResumed()) {
|
||||||
|
mapOverlay.clearPoints();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSampledInTrackPoint(Location location) {
|
public void onSampledInTrackPoint(Location location) {
|
||||||
mapOverlay.addLocation(location);
|
if (isResumed()) {
|
||||||
|
mapOverlay.addLocation(location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -386,22 +401,28 @@ public class MapFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSegmentSplit(Location location) {
|
public void onSegmentSplit(Location location) {
|
||||||
mapOverlay.addSegmentSplit();
|
if (isResumed()) {
|
||||||
|
mapOverlay.addSegmentSplit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewTrackPointsDone() {
|
public void onNewTrackPointsDone() {
|
||||||
mapView.postInvalidate();
|
if (isResumed()) {
|
||||||
|
mapView.postInvalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearWaypoints() {
|
public void clearWaypoints() {
|
||||||
mapOverlay.clearWaypoints();
|
if (isResumed()) {
|
||||||
|
mapOverlay.clearWaypoints();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewWaypoint(Waypoint waypoint) {
|
public void onNewWaypoint(Waypoint waypoint) {
|
||||||
if (waypoint != null && LocationUtils.isValidLocation(waypoint.getLocation())) {
|
if (isResumed() && waypoint != null && LocationUtils.isValidLocation(waypoint.getLocation())) {
|
||||||
// TODO: Optimize locking inside addWaypoint
|
// TODO: Optimize locking inside addWaypoint
|
||||||
mapOverlay.addWaypoint(waypoint);
|
mapOverlay.addWaypoint(waypoint);
|
||||||
}
|
}
|
||||||
@@ -409,7 +430,9 @@ public class MapFragment extends Fragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewWaypointsDone() {
|
public void onNewWaypointsDone() {
|
||||||
mapView.postInvalidate();
|
if (isResumed()) {
|
||||||
|
mapView.postInvalidate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.google.android.maps.mytracks.R;
|
|||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -57,7 +58,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
// A runnable to update the total time field.
|
// A runnable to update the total time field.
|
||||||
private final Runnable updateTotalTime = new Runnable() {
|
private final Runnable updateTotalTime = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (isSelectedTrackRecording() && !isSelectedTrackPaused() && lastTripStatistics != null) {
|
if (isResumed() && isSelectedTrackRecording() && !isSelectedTrackPaused()
|
||||||
|
&& lastTripStatistics != null) {
|
||||||
StatsUtils.setTotalTimeValue(getActivity(), System.currentTimeMillis()
|
StatsUtils.setTotalTimeValue(getActivity(), System.currentTimeMillis()
|
||||||
- lastTripStatistics.getStopTime() + lastTripStatistics.getTotalTime());
|
- lastTripStatistics.getStopTime() + lastTripStatistics.getTotalTime());
|
||||||
}
|
}
|
||||||
@@ -71,7 +73,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.d(TAG, "UI update thread started");
|
Log.d(TAG, "UI update thread started");
|
||||||
while (true) {
|
while (isResumed() && isSelectedTrackRecording()) {
|
||||||
getActivity().runOnUiThread(updateTotalTime);
|
getActivity().runOnUiThread(updateTotalTime);
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000L);
|
Thread.sleep(1000L);
|
||||||
@@ -93,7 +95,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
updateUi();
|
updateUi(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -114,12 +116,14 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationStateChanged(LocationState state) {
|
public void onLocationStateChanged(LocationState state) {
|
||||||
if (isResumed() && (state == LocationState.DISABLED || state == LocationState.NO_FIX)) {
|
if (isResumed() && state != LocationState.GOOD_FIX) {
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
lastLocation = null;
|
if (isResumed()) {
|
||||||
StatsUtils.setLocationValues(getActivity(), lastLocation, true);
|
lastLocation = null;
|
||||||
|
StatsUtils.setLocationValues(getActivity(), lastLocation, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -127,12 +131,21 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(final Location location) {
|
public void onLocationChanged(final Location location) {
|
||||||
if (isResumed() && isSelectedTrackRecording()) {
|
if (isResumed()) {
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
lastLocation = location;
|
if (isResumed()) {
|
||||||
StatsUtils.setLocationValues(getActivity(), lastLocation, true);
|
if (isSelectedTrackRecording() && !isSelectedTrackPaused()) {
|
||||||
|
lastLocation = location;
|
||||||
|
StatsUtils.setLocationValues(getActivity(), location, true);
|
||||||
|
} else {
|
||||||
|
if (lastLocation != null) {
|
||||||
|
lastLocation = null;
|
||||||
|
StatsUtils.setLocationValues(getActivity(), lastLocation, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -146,14 +159,14 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onSelectedTrackChanged(Track track) {
|
public void onSelectedTrackChanged(Track track) {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
boolean isRecording = isSelectedTrackRecording();
|
if (uiUpdateThread != null) {
|
||||||
if (uiUpdateThread == null && isRecording) {
|
|
||||||
uiUpdateThread = new UiUpdateThread();
|
|
||||||
uiUpdateThread.start();
|
|
||||||
} else if (uiUpdateThread != null && !isRecording) {
|
|
||||||
uiUpdateThread.interrupt();
|
uiUpdateThread.interrupt();
|
||||||
uiUpdateThread = null;
|
uiUpdateThread = null;
|
||||||
}
|
}
|
||||||
|
if (isSelectedTrackRecording()) {
|
||||||
|
uiUpdateThread = new UiUpdateThread();
|
||||||
|
uiUpdateThread.start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,18 +176,10 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (track == null || track.getTripStatistics() == null) {
|
if (isResumed()) {
|
||||||
lastLocation = null;
|
lastTripStatistics = track != null ? track.getTripStatistics() : null;
|
||||||
lastTripStatistics = null;
|
updateUi(getActivity());
|
||||||
updateUi();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
lastTripStatistics = track.getTripStatistics();
|
|
||||||
|
|
||||||
if (!isSelectedTrackRecording()) {
|
|
||||||
lastLocation = null;
|
|
||||||
}
|
|
||||||
updateUi();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -226,7 +231,9 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
updateUi();
|
if (isResumed()) {
|
||||||
|
updateUi(getActivity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -239,7 +246,9 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
updateUi();
|
if (isResumed()) {
|
||||||
|
updateUi(getActivity());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -258,11 +267,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
*/
|
*/
|
||||||
private synchronized void resumeTrackDataHub() {
|
private synchronized void resumeTrackDataHub() {
|
||||||
trackDataHub = ((TrackDetailActivity) getActivity()).getTrackDataHub();
|
trackDataHub = ((TrackDetailActivity) getActivity()).getTrackDataHub();
|
||||||
trackDataHub.registerTrackDataListener(this, EnumSet.of(
|
trackDataHub.registerTrackDataListener(this, EnumSet.of(TrackDataType.SELECTED_TRACK,
|
||||||
TrackDataType.SELECTED_TRACK,
|
TrackDataType.TRACKS_TABLE, TrackDataType.LOCATION, TrackDataType.PREFERENCE));
|
||||||
TrackDataType.TRACKS_TABLE,
|
|
||||||
TrackDataType.LOCATION,
|
|
||||||
TrackDataType.PREFERENCE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -293,8 +299,8 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
|||||||
/**
|
/**
|
||||||
* Updates the UI.
|
* Updates the UI.
|
||||||
*/
|
*/
|
||||||
private void updateUi() {
|
private void updateUi(FragmentActivity activity) {
|
||||||
StatsUtils.setTripStatisticsValues(getActivity(), lastTripStatistics);
|
StatsUtils.setTripStatisticsValues(activity, lastTripStatistics);
|
||||||
StatsUtils.setLocationValues(getActivity(), lastLocation, true);
|
StatsUtils.setLocationValues(activity, lastLocation, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package com.google.android.apps.mytracks.io.file;
|
|||||||
import com.google.android.apps.mytracks.Constants;
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatisticsBuilder;
|
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater;
|
||||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.apps.mytracks.util.StringUtils;
|
import com.google.android.apps.mytracks.util.StringUtils;
|
||||||
@@ -106,9 +106,9 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
private Track track;
|
private Track track;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statistics builder for the current track.
|
* Trip statistics updater for the current track.
|
||||||
*/
|
*/
|
||||||
private TripStatisticsBuilder tripStatisticsBuilder;
|
private TripStatisticsUpdater tripStatisticsUpdater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buffer of locations to be bulk-inserted into the database.
|
* Buffer of locations to be bulk-inserted into the database.
|
||||||
@@ -301,20 +301,20 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
flushPoints();
|
flushPoints();
|
||||||
|
|
||||||
// Calculate statistics for the imported track
|
// Calculate statistics for the imported track
|
||||||
tripStatisticsBuilder.updateTime(lastLocation.getTime());
|
tripStatisticsUpdater.updateTime(lastLocation.getTime());
|
||||||
track.setStopId(getLastPointId());
|
track.setStopId(getLastPointId());
|
||||||
} else {
|
} else {
|
||||||
tripStatisticsBuilder = new TripStatisticsBuilder(0L);
|
tripStatisticsUpdater = new TripStatisticsUpdater(0L);
|
||||||
tripStatisticsBuilder.updateTime(0L);
|
tripStatisticsUpdater.updateTime(0L);
|
||||||
}
|
}
|
||||||
track.setTripStatistics(tripStatisticsBuilder.getTripStatistics());
|
track.setTripStatistics(tripStatisticsUpdater.getTripStatistics());
|
||||||
track.setNumberOfPoints(numberOfLocations);
|
track.setNumberOfPoints(numberOfLocations);
|
||||||
myTracksProviderUtils.updateTrack(track);
|
myTracksProviderUtils.updateTrack(track);
|
||||||
tracksIds.add(track.getId());
|
tracksIds.add(track.getId());
|
||||||
isCurrentTrackRollbackable = false;
|
isCurrentTrackRollbackable = false;
|
||||||
lastSegmentLocation = null;
|
lastSegmentLocation = null;
|
||||||
lastLocation = null;
|
lastLocation = null;
|
||||||
tripStatisticsBuilder = null;
|
tripStatisticsUpdater = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -377,11 +377,11 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
*/
|
*/
|
||||||
private void onTrackPointElementEnd() throws SAXException {
|
private void onTrackPointElementEnd() throws SAXException {
|
||||||
if (LocationUtils.isValidLocation(location)) {
|
if (LocationUtils.isValidLocation(location)) {
|
||||||
if (tripStatisticsBuilder == null) {
|
if (tripStatisticsUpdater == null) {
|
||||||
// first point did not have a time, start stats builder without it
|
// first point did not have a time, start stats builder without it
|
||||||
tripStatisticsBuilder = new TripStatisticsBuilder(0);
|
tripStatisticsUpdater = new TripStatisticsUpdater(0);
|
||||||
}
|
}
|
||||||
tripStatisticsBuilder.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
tripStatisticsUpdater.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
||||||
|
|
||||||
// insert in db
|
// insert in db
|
||||||
insertPoint(location);
|
insertPoint(location);
|
||||||
@@ -448,8 +448,8 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
location.setTime(time);
|
location.setTime(time);
|
||||||
|
|
||||||
// initialize start time with time of first track point
|
// initialize start time with time of first track point
|
||||||
if (tripStatisticsBuilder == null) {
|
if (tripStatisticsUpdater == null) {
|
||||||
tripStatisticsBuilder = new TripStatisticsBuilder(time);
|
tripStatisticsUpdater = new TripStatisticsUpdater(time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,7 +506,7 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
if (numBufferedPointInserts <= 0) {
|
if (numBufferedPointInserts <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
myTracksProviderUtils.bulkInsertTrackPoints(
|
myTracksProviderUtils.bulkInsertTrackPoint(
|
||||||
bufferedPointInserts, numBufferedPointInserts, track.getId());
|
bufferedPointInserts, numBufferedPointInserts, track.getId());
|
||||||
numBufferedPointInserts = 0;
|
numBufferedPointInserts = 0;
|
||||||
}
|
}
|
||||||
@@ -528,7 +528,7 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
*/
|
*/
|
||||||
private long getLastPointId() {
|
private long getLastPointId() {
|
||||||
flushPoints();
|
flushPoints();
|
||||||
return myTracksProviderUtils.getLastTrackLocationId(track.getId());
|
return myTracksProviderUtils.getLastTrackPointId(track.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ public class SaveAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
private Boolean saveAllTracks() {
|
private Boolean saveAllTracks() {
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = myTracksProviderUtils.getTracksCursor(null, null, TracksColumns._ID);
|
cursor = myTracksProviderUtils.getTrackCursor(null, null, TracksColumns._ID);
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
messageId = R.string.sd_card_save_error_no_track;
|
messageId = R.string.sd_card_save_error_no_track;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ class TrackWriterImpl implements TrackWriter {
|
|||||||
// problem because we don't try to load them into objects all at the
|
// problem because we don't try to load them into objects all at the
|
||||||
// same time.
|
// same time.
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
cursor = providerUtils.getWaypointsCursor(trackId, 0,
|
cursor = providerUtils.getWaypointCursor(trackId, 0,
|
||||||
Constants.MAX_LOADED_WAYPOINTS_POINTS);
|
Constants.MAX_LOADED_WAYPOINTS_POINTS);
|
||||||
boolean hasWaypoints = false;
|
boolean hasWaypoints = false;
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
@@ -314,7 +314,7 @@ class TrackWriterImpl implements TrackWriter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
TrackWriterLocationFactory locationFactory = new TrackWriterLocationFactory();
|
TrackWriterLocationFactory locationFactory = new TrackWriterLocationFactory();
|
||||||
LocationIterator it = providerUtils.getLocationIterator(track.getId(), 0, false,
|
LocationIterator it = providerUtils.getTrackPointLocationIterator(track.getId(), 0, false,
|
||||||
locationFactory);
|
locationFactory);
|
||||||
try {
|
try {
|
||||||
if (!it.hasNext()) {
|
if (!it.hasNext()) {
|
||||||
|
|||||||
+19
-19
@@ -10,7 +10,7 @@ import com.google.android.apps.mytracks.content.Track;
|
|||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask;
|
import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask;
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatisticsBuilder;
|
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater;
|
||||||
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
import com.google.android.apps.mytracks.util.ApiAdapterFactory;
|
||||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
@@ -208,31 +208,31 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
* @return true if success.
|
* @return true if success.
|
||||||
*/
|
*/
|
||||||
private boolean uploadAllTrackPoints(Track track) {
|
private boolean uploadAllTrackPoints(Track track) {
|
||||||
Cursor locationsCursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false);
|
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, 0, -1, false);
|
||||||
if (locationsCursor == null) {
|
if (cursor == null) {
|
||||||
Log.d(TAG, "Location cursor is null");
|
Log.d(TAG, "Location cursor is null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int locationsCount = locationsCursor.getCount();
|
int count = cursor.getCount();
|
||||||
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
||||||
Location lastLocation = null;
|
Location lastLocation = null;
|
||||||
|
|
||||||
// For chart server, limit the number of elevation readings to 250.
|
// For chart server, limit the number of elevation readings to 250.
|
||||||
int elevationSamplingFrequency = Math.max(1, (int) (locationsCount / 250.0));
|
int elevationSamplingFrequency = Math.max(1, (int) (count / 250.0));
|
||||||
Vector<Double> distances = new Vector<Double>();
|
Vector<Double> distances = new Vector<Double>();
|
||||||
Vector<Double> elevations = new Vector<Double>();
|
Vector<Double> elevations = new Vector<Double>();
|
||||||
TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder(
|
TripStatisticsUpdater tripStatisticsUpdater = new TripStatisticsUpdater(
|
||||||
track.getTripStatistics().getStartTime());
|
track.getTripStatistics().getStartTime());
|
||||||
int minRecordingDistance = PreferencesUtils.getInt(context,
|
int minRecordingDistance = PreferencesUtils.getInt(context,
|
||||||
R.string.min_recording_distance_key, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
R.string.min_recording_distance_key, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
||||||
|
|
||||||
for (int i = 0; i < locationsCount; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
locationsCursor.moveToPosition(i);
|
cursor.moveToPosition(i);
|
||||||
|
|
||||||
Location location = myTracksProviderUtils.createLocation(locationsCursor);
|
Location location = myTracksProviderUtils.createTrackPoint(cursor);
|
||||||
locations.add(location);
|
locations.add(location);
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@@ -244,10 +244,10 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tripStatisticsBuilder.addLocation(location, minRecordingDistance);
|
tripStatisticsUpdater.addLocation(location, minRecordingDistance);
|
||||||
if (i % elevationSamplingFrequency == 0) {
|
if (i % elevationSamplingFrequency == 0) {
|
||||||
distances.add(tripStatisticsBuilder.getTripStatistics().getTotalDistance());
|
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
||||||
elevations.add(tripStatisticsBuilder.getSmoothedElevation());
|
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
||||||
}
|
}
|
||||||
if (LocationUtils.isValidLocation(location)) {
|
if (LocationUtils.isValidLocation(location)) {
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
@@ -260,7 +260,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
Log.d(TAG, "Unable to upload points");
|
Log.d(TAG, "Unable to upload points");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
updateProgress(readCount, locationsCount);
|
updateProgress(readCount, count);
|
||||||
locations.clear();
|
locations.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -273,8 +273,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
|
|
||||||
// Create an end marker
|
// Create an end marker
|
||||||
if (lastLocation != null) {
|
if (lastLocation != null) {
|
||||||
distances.add(tripStatisticsBuilder.getTripStatistics().getTotalDistance());
|
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
||||||
elevations.add(tripStatisticsBuilder.getSmoothedElevation());
|
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
||||||
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
||||||
track.setDescription(
|
track.setDescription(
|
||||||
descriptionGenerator.generateTrackDescription(track, distances, elevations, true));
|
descriptionGenerator.generateTrackDescription(track, distances, elevations, true));
|
||||||
@@ -287,8 +287,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
if (locationsCursor != null) {
|
if (cursor != null) {
|
||||||
locationsCursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,7 +328,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
private boolean uploadWaypoints() {
|
private boolean uploadWaypoints() {
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = myTracksProviderUtils.getWaypointsCursor(
|
cursor = myTracksProviderUtils.getWaypointCursor(
|
||||||
trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS);
|
trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS);
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
// This will skip the first waypoint (it carries the stats for the
|
// This will skip the first waypoint (it carries the stats for the
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import com.google.android.apps.mytracks.io.gdata.maps.MapsGDataConverter;
|
|||||||
import com.google.android.apps.mytracks.io.gdata.maps.XmlMapsGDataParserFactory;
|
import com.google.android.apps.mytracks.io.gdata.maps.XmlMapsGDataParserFactory;
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask;
|
import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask;
|
||||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatisticsBuilder;
|
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater;
|
||||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.common.gdata.AndroidXmlParserFactory;
|
import com.google.android.common.gdata.AndroidXmlParserFactory;
|
||||||
@@ -251,31 +251,31 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean uploadAllTrackPoints(Track track) {
|
boolean uploadAllTrackPoints(Track track) {
|
||||||
Cursor locationsCursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false);
|
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, 0, -1, false);
|
||||||
if (locationsCursor == null) {
|
if (cursor == null) {
|
||||||
Log.d(TAG, "Location cursor is null");
|
Log.d(TAG, "Location cursor is null");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int locationsCount = locationsCursor.getCount();
|
int count = cursor.getCount();
|
||||||
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
|
||||||
Location lastLocation = null;
|
Location lastLocation = null;
|
||||||
|
|
||||||
// For chart server, limit the number of elevation readings to 250.
|
// For chart server, limit the number of elevation readings to 250.
|
||||||
int elevationSamplingFrequency = Math.max(1, (int) (locationsCount / 250.0));
|
int elevationSamplingFrequency = Math.max(1, (int) (count / 250.0));
|
||||||
Vector<Double> distances = new Vector<Double>();
|
Vector<Double> distances = new Vector<Double>();
|
||||||
Vector<Double> elevations = new Vector<Double>();
|
Vector<Double> elevations = new Vector<Double>();
|
||||||
TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder(
|
TripStatisticsUpdater tripStatisticsUpdater = new TripStatisticsUpdater(
|
||||||
track.getTripStatistics().getStartTime());
|
track.getTripStatistics().getStartTime());
|
||||||
int minRecordingDistance = PreferencesUtils.getInt(context,
|
int minRecordingDistance = PreferencesUtils.getInt(context,
|
||||||
R.string.min_recording_distance_key, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
R.string.min_recording_distance_key, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
||||||
|
|
||||||
for (int i = 0; i < locationsCount; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
locationsCursor.moveToPosition(i);
|
cursor.moveToPosition(i);
|
||||||
|
|
||||||
Location location = myTracksProviderUtils.createLocation(locationsCursor);
|
Location location = myTracksProviderUtils.createTrackPoint(cursor);
|
||||||
locations.add(location);
|
locations.add(location);
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
@@ -287,10 +287,10 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tripStatisticsBuilder.addLocation(location, minRecordingDistance);
|
tripStatisticsUpdater.addLocation(location, minRecordingDistance);
|
||||||
if (i % elevationSamplingFrequency == 0) {
|
if (i % elevationSamplingFrequency == 0) {
|
||||||
distances.add(tripStatisticsBuilder.getTripStatistics().getTotalDistance());
|
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
||||||
elevations.add(tripStatisticsBuilder.getSmoothedElevation());
|
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
||||||
}
|
}
|
||||||
if (LocationUtils.isValidLocation(location)) {
|
if (LocationUtils.isValidLocation(location)) {
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
@@ -303,7 +303,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
Log.d(TAG, "Unable to upload points");
|
Log.d(TAG, "Unable to upload points");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
updateProgress(readCount, locationsCount);
|
updateProgress(readCount, count);
|
||||||
locations.clear();
|
locations.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,8 +316,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
|
|
||||||
// Create an end marker
|
// Create an end marker
|
||||||
if (lastLocation != null) {
|
if (lastLocation != null) {
|
||||||
distances.add(tripStatisticsBuilder.getTripStatistics().getTotalDistance());
|
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
||||||
elevations.add(tripStatisticsBuilder.getSmoothedElevation());
|
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
||||||
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
||||||
track.setDescription(
|
track.setDescription(
|
||||||
descriptionGenerator.generateTrackDescription(track, distances, elevations, true));
|
descriptionGenerator.generateTrackDescription(track, distances, elevations, true));
|
||||||
@@ -329,8 +329,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
if (locationsCursor != null) {
|
if (cursor != null) {
|
||||||
locationsCursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -436,7 +436,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
boolean uploadWaypoints() {
|
boolean uploadWaypoints() {
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = myTracksProviderUtils.getWaypointsCursor(
|
cursor = myTracksProviderUtils.getWaypointCursor(
|
||||||
trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS);
|
trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS);
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
// This will skip the first waypoint (it carries the stats for the
|
// This will skip the first waypoint (it carries the stats for the
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import com.google.android.apps.mytracks.services.tasks.AnnouncementPeriodicTaskF
|
|||||||
import com.google.android.apps.mytracks.services.tasks.PeriodicTaskExecutor;
|
import com.google.android.apps.mytracks.services.tasks.PeriodicTaskExecutor;
|
||||||
import com.google.android.apps.mytracks.services.tasks.SplitPeriodicTaskFactory;
|
import com.google.android.apps.mytracks.services.tasks.SplitPeriodicTaskFactory;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatisticsBuilder;
|
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater;
|
||||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
@@ -82,8 +82,8 @@ import java.util.concurrent.Executors;
|
|||||||
public class TrackRecordingService extends Service {
|
public class TrackRecordingService extends Service {
|
||||||
|
|
||||||
private static final String TAG = TrackRecordingService.class.getSimpleName();
|
private static final String TAG = TrackRecordingService.class.getSimpleName();
|
||||||
public static final int PAUSE_LATITUDE = 100;
|
public static final double PAUSE_LATITUDE = 100.0;
|
||||||
private static final int RESUME_LATITUDE = 200;
|
private static final double RESUME_LATITUDE = 200.0;
|
||||||
|
|
||||||
// One second in milliseconds
|
// One second in milliseconds
|
||||||
private static final long ONE_SECOND = 1000;
|
private static final long ONE_SECOND = 1000;
|
||||||
@@ -110,8 +110,8 @@ public class TrackRecordingService extends Service {
|
|||||||
private long currentRecordingInterval;
|
private long currentRecordingInterval;
|
||||||
|
|
||||||
// The following variables are set when recording:
|
// The following variables are set when recording:
|
||||||
private TripStatisticsBuilder trackTripStatisticsBuilder;
|
private TripStatisticsUpdater trackTripStatisticsUpdater;
|
||||||
private TripStatisticsBuilder markerTripStatisticsBuilder;
|
private TripStatisticsUpdater markerTripStatisticsUpdater;
|
||||||
private WakeLock wakeLock;
|
private WakeLock wakeLock;
|
||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
private Location lastLocation;
|
private Location lastLocation;
|
||||||
@@ -397,10 +397,10 @@ public class TrackRecordingService extends Service {
|
|||||||
* Gets the trip statistics.
|
* Gets the trip statistics.
|
||||||
*/
|
*/
|
||||||
public TripStatistics getTripStatistics() {
|
public TripStatistics getTripStatistics() {
|
||||||
if (trackTripStatisticsBuilder == null) {
|
if (trackTripStatisticsUpdater == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return trackTripStatisticsBuilder.getTripStatistics();
|
return trackTripStatisticsUpdater.getTripStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -419,23 +419,23 @@ public class TrackRecordingService extends Service {
|
|||||||
if (waypointCreationRequest.getName() != null) {
|
if (waypointCreationRequest.getName() != null) {
|
||||||
name = waypointCreationRequest.getName();
|
name = waypointCreationRequest.getName();
|
||||||
} else {
|
} else {
|
||||||
int nextMarkerNumber = myTracksProviderUtils.getNextMarkerNumber(
|
int nextWaypointNumber = myTracksProviderUtils.getNextWaypointNumber(
|
||||||
recordingTrackId, isStatistics);
|
recordingTrackId, isStatistics);
|
||||||
if (nextMarkerNumber == -1) {
|
if (nextWaypointNumber == -1) {
|
||||||
nextMarkerNumber = 0;
|
nextWaypointNumber = 0;
|
||||||
}
|
}
|
||||||
name = getString(
|
name = getString(
|
||||||
isStatistics ? R.string.marker_split_name_format : R.string.marker_name_format,
|
isStatistics ? R.string.marker_split_name_format : R.string.marker_name_format,
|
||||||
nextMarkerNumber);
|
nextWaypointNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
TripStatistics tripStatistics;
|
TripStatistics tripStatistics;
|
||||||
String description;
|
String description;
|
||||||
if (isStatistics) {
|
if (isStatistics) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
markerTripStatisticsBuilder.updateTime(now);
|
markerTripStatisticsUpdater.updateTime(now);
|
||||||
tripStatistics = markerTripStatisticsBuilder.getTripStatistics();
|
tripStatistics = markerTripStatisticsUpdater.getTripStatistics();
|
||||||
markerTripStatisticsBuilder = new TripStatisticsBuilder(now);
|
markerTripStatisticsUpdater = new TripStatisticsUpdater(now);
|
||||||
description = new DescriptionGeneratorImpl(this).generateWaypointDescription(tripStatistics);
|
description = new DescriptionGeneratorImpl(this).generateWaypointDescription(tripStatistics);
|
||||||
} else {
|
} else {
|
||||||
tripStatistics = null;
|
tripStatistics = null;
|
||||||
@@ -452,10 +452,9 @@ public class TrackRecordingService extends Service {
|
|||||||
int type = isStatistics ? Waypoint.TYPE_STATISTICS : Waypoint.TYPE_WAYPOINT;
|
int type = isStatistics ? Waypoint.TYPE_STATISTICS : Waypoint.TYPE_WAYPOINT;
|
||||||
long duration;
|
long duration;
|
||||||
double length;
|
double length;
|
||||||
Location lastTrackLocation = myTracksProviderUtils.getLastTrackLocation(recordingTrackId);
|
Location location = getLastValidTrackPointInCurrentSegment(recordingTrackId);
|
||||||
if (currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackLocation)
|
if (location != null && trackTripStatisticsUpdater != null) {
|
||||||
&& trackTripStatisticsBuilder != null) {
|
TripStatistics stats = trackTripStatisticsUpdater.getTripStatistics();
|
||||||
TripStatistics stats = trackTripStatisticsBuilder.getTripStatistics();
|
|
||||||
length = stats.getTotalDistance();
|
length = stats.getTotalDistance();
|
||||||
duration = stats.getTotalTime();
|
duration = stats.getTotalTime();
|
||||||
} else {
|
} else {
|
||||||
@@ -463,14 +462,14 @@ public class TrackRecordingService extends Service {
|
|||||||
return -1L;
|
return -1L;
|
||||||
}
|
}
|
||||||
// For track statistics, make it an impossible location
|
// For track statistics, make it an impossible location
|
||||||
lastTrackLocation = new Location("");
|
location = new Location("");
|
||||||
lastTrackLocation.setLatitude(100);
|
location.setLatitude(100);
|
||||||
lastTrackLocation.setLongitude(180);
|
location.setLongitude(180);
|
||||||
length = 0;
|
length = 0;
|
||||||
duration = 0;
|
duration = 0;
|
||||||
}
|
}
|
||||||
Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, type,
|
Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, type,
|
||||||
length, duration, -1L, -1L, lastTrackLocation, tripStatistics);
|
length, duration, -1L, -1L, location, tripStatistics);
|
||||||
Uri uri = myTracksProviderUtils.insertWaypoint(waypoint);
|
Uri uri = myTracksProviderUtils.insertWaypoint(waypoint);
|
||||||
return Long.parseLong(uri.getLastPathSegment());
|
return Long.parseLong(uri.getLastPathSegment());
|
||||||
}
|
}
|
||||||
@@ -557,8 +556,8 @@ public class TrackRecordingService extends Service {
|
|||||||
return -1L;
|
return -1L;
|
||||||
}
|
}
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
trackTripStatisticsBuilder = new TripStatisticsBuilder(now);
|
trackTripStatisticsUpdater = new TripStatisticsUpdater(now);
|
||||||
markerTripStatisticsBuilder = new TripStatisticsBuilder(now);
|
markerTripStatisticsUpdater = new TripStatisticsUpdater(now);
|
||||||
|
|
||||||
// Insert a track
|
// Insert a track
|
||||||
Track track = new Track();
|
Track track = new Track();
|
||||||
@@ -574,7 +573,7 @@ public class TrackRecordingService extends Service {
|
|||||||
track.setName(TrackNameUtils.getTrackName(this, trackId, now, null));
|
track.setName(TrackNameUtils.getTrackName(this, trackId, now, null));
|
||||||
track.setCategory(PreferencesUtils.getString(
|
track.setCategory(PreferencesUtils.getString(
|
||||||
this, R.string.default_activity_key, PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT));
|
this, R.string.default_activity_key, PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT));
|
||||||
track.setTripStatistics(trackTripStatisticsBuilder.getTripStatistics());
|
track.setTripStatistics(trackTripStatisticsUpdater.getTripStatistics());
|
||||||
myTracksProviderUtils.updateTrack(track);
|
myTracksProviderUtils.updateTrack(track);
|
||||||
insertWaypoint(WaypointCreationRequest.DEFAULT_START_TRACK);
|
insertWaypoint(WaypointCreationRequest.DEFAULT_START_TRACK);
|
||||||
|
|
||||||
@@ -591,7 +590,7 @@ public class TrackRecordingService extends Service {
|
|||||||
Log.d(TAG, "Restarting track: " + track.getId());
|
Log.d(TAG, "Restarting track: " + track.getId());
|
||||||
|
|
||||||
TripStatistics tripStatistics = track.getTripStatistics();
|
TripStatistics tripStatistics = track.getTripStatistics();
|
||||||
trackTripStatisticsBuilder = new TripStatisticsBuilder(tripStatistics.getStartTime());
|
trackTripStatisticsUpdater = new TripStatisticsUpdater(tripStatistics.getStartTime());
|
||||||
|
|
||||||
long markerStartTime;
|
long markerStartTime;
|
||||||
Waypoint waypoint = myTracksProviderUtils.getLastStatisticsWaypoint(recordingTrackId);
|
Waypoint waypoint = myTracksProviderUtils.getLastStatisticsWaypoint(recordingTrackId);
|
||||||
@@ -600,22 +599,22 @@ public class TrackRecordingService extends Service {
|
|||||||
} else {
|
} else {
|
||||||
markerStartTime = tripStatistics.getStartTime();
|
markerStartTime = tripStatistics.getStartTime();
|
||||||
}
|
}
|
||||||
markerTripStatisticsBuilder = new TripStatisticsBuilder(markerStartTime);
|
markerTripStatisticsUpdater = new TripStatisticsUpdater(markerStartTime);
|
||||||
|
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
// TODO: how to handle very long track.
|
// TODO: how to handle very long track.
|
||||||
cursor = myTracksProviderUtils.getLocationsCursor(
|
cursor = myTracksProviderUtils.getTrackPointCursor(
|
||||||
recordingTrackId, -1, Constants.MAX_LOADED_TRACK_POINTS, true);
|
recordingTrackId, -1, Constants.MAX_LOADED_TRACK_POINTS, true);
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
Log.e(TAG, "Cursor is null.");
|
Log.e(TAG, "Cursor is null.");
|
||||||
} else {
|
} else {
|
||||||
if (cursor.moveToLast()) {
|
if (cursor.moveToLast()) {
|
||||||
do {
|
do {
|
||||||
Location location = myTracksProviderUtils.createLocation(cursor);
|
Location location = myTracksProviderUtils.createTrackPoint(cursor);
|
||||||
trackTripStatisticsBuilder.addLocation(location, minRecordingDistance);
|
trackTripStatisticsUpdater.addLocation(location, minRecordingDistance);
|
||||||
if (location.getTime() > markerStartTime) {
|
if (location.getTime() > markerStartTime) {
|
||||||
markerTripStatisticsBuilder.addLocation(location, minRecordingDistance);
|
markerTripStatisticsUpdater.addLocation(location, minRecordingDistance);
|
||||||
}
|
}
|
||||||
} while (cursor.moveToPrevious());
|
} while (cursor.moveToPrevious());
|
||||||
}
|
}
|
||||||
@@ -701,14 +700,26 @@ public class TrackRecordingService extends Service {
|
|||||||
// Update database
|
// Update database
|
||||||
Track track = myTracksProviderUtils.getTrack(trackId);
|
Track track = myTracksProviderUtils.getTrack(trackId);
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
insertLocation(track, lastLocation, myTracksProviderUtils.getLastTrackLocation(trackId));
|
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(trackId));
|
||||||
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackLocationId(trackId), false);
|
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
endRecording(true, trackId);
|
endRecording(true, trackId);
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the last valid track point in the current segment. Returns null if not available.
|
||||||
|
*
|
||||||
|
* @param trackId the track id
|
||||||
|
*/
|
||||||
|
private Location getLastValidTrackPointInCurrentSegment(long trackId) {
|
||||||
|
if (!currentSegmentHasLocation) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return myTracksProviderUtils.getLastValidTrackPoint(trackId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pauses the current track.
|
* Pauses the current track.
|
||||||
*/
|
*/
|
||||||
@@ -725,8 +736,7 @@ public class TrackRecordingService extends Service {
|
|||||||
// Update database
|
// Update database
|
||||||
Track track = myTracksProviderUtils.getTrack(recordingTrackId);
|
Track track = myTracksProviderUtils.getTrack(recordingTrackId);
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
insertLocation(
|
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(track.getId()));
|
||||||
track, lastLocation, myTracksProviderUtils.getLastTrackLocation(track.getId()));
|
|
||||||
|
|
||||||
Location pause = new Location(LocationManager.GPS_PROVIDER);
|
Location pause = new Location(LocationManager.GPS_PROVIDER);
|
||||||
pause.setLongitude(0);
|
pause.setLongitude(0);
|
||||||
@@ -809,9 +819,8 @@ public class TrackRecordingService extends Service {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Location lastTrackLocation = myTracksProviderUtils.getLastTrackLocation(track.getId());
|
Location lastValidTrackPoint = getLastValidTrackPointInCurrentSegment(track.getId());
|
||||||
long idleTime = currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackLocation) ?
|
long idleTime = lastValidTrackPoint != null ? location.getTime() - lastValidTrackPoint.getTime()
|
||||||
location.getTime() - lastTrackLocation.getTime()
|
|
||||||
: 0L;
|
: 0L;
|
||||||
locationListenerPolicy.updateIdleTime(idleTime);
|
locationListenerPolicy.updateIdleTime(idleTime);
|
||||||
if (currentRecordingInterval != locationListenerPolicy.getDesiredPollingInterval()) {
|
if (currentRecordingInterval != locationListenerPolicy.getDesiredPollingInterval()) {
|
||||||
@@ -825,41 +834,41 @@ public class TrackRecordingService extends Service {
|
|||||||
|
|
||||||
// Always insert the first segment location
|
// Always insert the first segment location
|
||||||
if (!currentSegmentHasLocation) {
|
if (!currentSegmentHasLocation) {
|
||||||
insertLocation(track, location, lastTrackLocation);
|
insertLocation(track, location, null);
|
||||||
currentSegmentHasLocation = true;
|
currentSegmentHasLocation = true;
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LocationUtils.isValidLocation(lastTrackLocation)) {
|
if (!LocationUtils.isValidLocation(lastValidTrackPoint)) {
|
||||||
/*
|
/*
|
||||||
* Should not happen. The current segment should have a location. Just
|
* Should not happen. The current segment should have a location. Just
|
||||||
* insert the current location.
|
* insert the current location.
|
||||||
*/
|
*/
|
||||||
insertLocation(track, location, lastTrackLocation);
|
insertLocation(track, location, null);
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double distanceToLastTrackLocation = location.distanceTo(lastTrackLocation);
|
double distanceToLastTrackLocation = location.distanceTo(lastValidTrackPoint);
|
||||||
if (distanceToLastTrackLocation < minRecordingDistance && sensorDataSet == null) {
|
if (distanceToLastTrackLocation < minRecordingDistance && sensorDataSet == null) {
|
||||||
Log.d(TAG, "Not recording location due to min recording distance.");
|
Log.d(TAG, "Not recording location due to min recording distance.");
|
||||||
} else if (distanceToLastTrackLocation > maxRecordingDistance) {
|
} else if (distanceToLastTrackLocation > maxRecordingDistance) {
|
||||||
insertLocation(track, lastLocation, lastTrackLocation);
|
insertLocation(track, lastLocation, lastValidTrackPoint);
|
||||||
Location pause = new Location(LocationManager.GPS_PROVIDER);
|
Location pause = new Location(LocationManager.GPS_PROVIDER);
|
||||||
pause.setLongitude(0);
|
pause.setLongitude(0);
|
||||||
pause.setLatitude(PAUSE_LATITUDE);
|
pause.setLatitude(PAUSE_LATITUDE);
|
||||||
pause.setTime(lastLocation.getTime());
|
pause.setTime(lastLocation.getTime());
|
||||||
insertLocation(track, pause, null);
|
insertLocation(track, pause, null);
|
||||||
|
|
||||||
insertLocation(track, location, lastTrackLocation);
|
insertLocation(track, location, null);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* (distanceToLastTrackLocation >= minRecordingDistance ||
|
* (distanceToLastTrackLocation >= minRecordingDistance ||
|
||||||
* hasSensorData) && distanceToLastTrackLocation <= maxRecordingDistance
|
* hasSensorData) && distanceToLastTrackLocation <= maxRecordingDistance
|
||||||
*/
|
*/
|
||||||
insertLocation(track, lastLocation, lastTrackLocation);
|
insertLocation(track, lastLocation, lastValidTrackPoint);
|
||||||
insertLocation(track, location, lastTrackLocation);
|
insertLocation(track, location, null);
|
||||||
}
|
}
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
@@ -871,21 +880,29 @@ public class TrackRecordingService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertLocation(Track track, Location location, Location lastRecordedLocation) {
|
/**
|
||||||
|
* Inserts a location.
|
||||||
|
*
|
||||||
|
* @param track the track
|
||||||
|
* @param location the location
|
||||||
|
* @param lastValidTrackPoint the last valid track point, can be null
|
||||||
|
*/
|
||||||
|
private void insertLocation(Track track, Location location, Location lastValidTrackPoint) {
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
Log.w(TAG, "Ignore insertLocation. loation is null.");
|
Log.w(TAG, "Ignore insertLocation. loation is null.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (location.equals(lastRecordedLocation)) {
|
// Do not insert if inserted already
|
||||||
Log.w(TAG, "Ignore insertLocation. loation same as last recorded location.");
|
if (lastValidTrackPoint != null && lastValidTrackPoint.getTime() == location.getTime()) {
|
||||||
|
Log.w(TAG, "Ignore insertLocation. location time same as last valid track point time.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId());
|
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId());
|
||||||
long trackPointId = Long.parseLong(uri.getLastPathSegment());
|
long trackPointId = Long.parseLong(uri.getLastPathSegment());
|
||||||
trackTripStatisticsBuilder.addLocation(location, minRecordingDistance);
|
trackTripStatisticsUpdater.addLocation(location, minRecordingDistance);
|
||||||
markerTripStatisticsBuilder.addLocation(location, minRecordingDistance);
|
markerTripStatisticsUpdater.addLocation(location, minRecordingDistance);
|
||||||
updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location));
|
updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location));
|
||||||
} catch (SQLiteException e) {
|
} catch (SQLiteException e) {
|
||||||
/*
|
/*
|
||||||
@@ -911,8 +928,8 @@ public class TrackRecordingService extends Service {
|
|||||||
track.setNumberOfPoints(track.getNumberOfPoints() + 1);
|
track.setNumberOfPoints(track.getNumberOfPoints() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
trackTripStatisticsBuilder.updateTime(System.currentTimeMillis());
|
trackTripStatisticsUpdater.updateTime(System.currentTimeMillis());
|
||||||
track.setTripStatistics(trackTripStatisticsBuilder.getTripStatistics());
|
track.setTripStatistics(trackTripStatisticsUpdater.getTripStatistics());
|
||||||
myTracksProviderUtils.updateTrack(track);
|
myTracksProviderUtils.updateTrack(track);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -27,14 +27,14 @@ import android.location.Location;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for {@link TripStatistics}. For keeping track statistics as new
|
* Updater for {@link TripStatistics}. For updating track trip statistics as new
|
||||||
* locations are added. Note that some of the locations represent pause/resume
|
* locations are added. Note that some of the locations represent pause/resume
|
||||||
* separator.
|
* separator.
|
||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class TripStatisticsBuilder {
|
public class TripStatisticsUpdater {
|
||||||
|
|
||||||
// The track's trip statistics
|
// The track's trip statistics
|
||||||
private final TripStatistics tripStatistics;
|
private final TripStatistics tripStatistics;
|
||||||
@@ -62,11 +62,11 @@ public class TripStatisticsBuilder {
|
|||||||
private final DoubleBuffer gradeBuffer = new DoubleBuffer(Constants.GRADE_SMOOTHING_FACTOR);
|
private final DoubleBuffer gradeBuffer = new DoubleBuffer(Constants.GRADE_SMOOTHING_FACTOR);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new trip statistics builder.
|
* Creates a new trip statistics updater.
|
||||||
*
|
*
|
||||||
* @param startTime the start time
|
* @param startTime the start time
|
||||||
*/
|
*/
|
||||||
public TripStatisticsBuilder(long startTime) {
|
public TripStatisticsUpdater(long startTime) {
|
||||||
tripStatistics = init(startTime);
|
tripStatistics = init(startTime);
|
||||||
currentSegment = init(startTime);
|
currentSegment = init(startTime);
|
||||||
}
|
}
|
||||||
@@ -96,6 +96,10 @@ public class TripStatisticsBuilder {
|
|||||||
if (!LocationUtils.isValidLocation(location)) {
|
if (!LocationUtils.isValidLocation(location)) {
|
||||||
updateTime(location.getTime());
|
updateTime(location.getTime());
|
||||||
if (location.getLatitude() == TrackRecordingService.PAUSE_LATITUDE) {
|
if (location.getLatitude() == TrackRecordingService.PAUSE_LATITUDE) {
|
||||||
|
if (lastLocation != null && lastMovingLocation != null
|
||||||
|
&& lastLocation != lastMovingLocation) {
|
||||||
|
currentSegment.addTotalDistance(lastMovingLocation.distanceTo(lastLocation));
|
||||||
|
}
|
||||||
tripStatistics.merge(currentSegment);
|
tripStatistics.merge(currentSegment);
|
||||||
}
|
}
|
||||||
currentSegment = init(location.getTime());
|
currentSegment = init(location.getTime());
|
||||||
+84
-153
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.google.android.apps.mytracks.content;
|
package com.google.android.apps.mytracks.content;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
@@ -40,14 +39,23 @@ public interface MyTracksProviderUtils {
|
|||||||
public static final String AUTHORITY = "com.google.android.maps.mytracks";
|
public static final String AUTHORITY = "com.google.android.maps.mytracks";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a track cursor. The caller owns the returned cursor and is responsible
|
* Creates a {@link Track} from a cursor.
|
||||||
* for closing it.
|
|
||||||
*
|
*
|
||||||
* @param selection the selection
|
* @param cursor the cursor pointing to the track
|
||||||
* @param selectionArgs the selection arguments
|
|
||||||
* @param sortOrder the sort order
|
|
||||||
*/
|
*/
|
||||||
public Cursor getTracksCursor(String selection, String[] selectionArgs, String sortOrder);
|
public Track createTrack(Cursor cursor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all tracks (including waypoints and track points).
|
||||||
|
*/
|
||||||
|
public void deleteAllTracks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a track.
|
||||||
|
*
|
||||||
|
* @param trackId the track id
|
||||||
|
*/
|
||||||
|
public void deleteTrack(long trackId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all the tracks. If no track exists, an empty list is returned.
|
* Gets all the tracks. If no track exists, an empty list is returned.
|
||||||
@@ -56,6 +64,11 @@ public interface MyTracksProviderUtils {
|
|||||||
*/
|
*/
|
||||||
public List<Track> getAllTracks();
|
public List<Track> getAllTracks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the last track. Returns null if doesn't exist.
|
||||||
|
*/
|
||||||
|
public Track getLastTrack();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a track by a track id. Returns null if not found.
|
* Gets a track by a track id. Returns null if not found.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -66,21 +79,14 @@ public interface MyTracksProviderUtils {
|
|||||||
public Track getTrack(long trackId);
|
public Track getTrack(long trackId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the last track. Returns null if doesn't exist.
|
* Gets a track cursor. The caller owns the returned cursor and is responsible
|
||||||
*/
|
* for closing it.
|
||||||
public Track getLastTrack();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the last track id. Returns -1L if doesn't exist.
|
|
||||||
*/
|
|
||||||
public long getLastTrackId();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if a track exists.
|
|
||||||
*
|
*
|
||||||
* @param trackId the track id
|
* @param selection the selection
|
||||||
|
* @param selectionArgs the selection arguments
|
||||||
|
* @param sortOrder the sort order
|
||||||
*/
|
*/
|
||||||
public boolean trackExists(long trackId);
|
public Cursor getTrackCursor(String selection, String[] selectionArgs, String sortOrder);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a track.
|
* Inserts a track.
|
||||||
@@ -102,61 +108,21 @@ public interface MyTracksProviderUtils {
|
|||||||
public void updateTrack(Track track);
|
public void updateTrack(Track track);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all tracks (including waypoints and track points).
|
* Creates a waypoint from a cursor.
|
||||||
|
*
|
||||||
|
* @param cursor the cursor pointing to the waypoint
|
||||||
*/
|
*/
|
||||||
public void deleteAllTracks();
|
public Waypoint createWaypoint(Cursor cursor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a track.
|
* Deletes a waypoint. If deleting a statistics waypoint, this will also
|
||||||
|
* correct the next statistics waypoint after the deleted one to reflect the
|
||||||
|
* deletion. The generator is used to update the next statistics waypoint.
|
||||||
*
|
*
|
||||||
* @param trackId the track id
|
* @param waypointId the waypoint id
|
||||||
|
* @param descriptionGenerator the description generator
|
||||||
*/
|
*/
|
||||||
public void deleteTrack(long trackId);
|
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link Track} from a cursor.
|
|
||||||
*
|
|
||||||
* @param cursor the cursor pointing to the track
|
|
||||||
*/
|
|
||||||
public Track createTrack(Cursor cursor);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link ContentValues} from a track.
|
|
||||||
*
|
|
||||||
* @param track the track
|
|
||||||
*/
|
|
||||||
public ContentValues createContentValues(Track track);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a waypoint cursor. The caller owns the returned cursor and is
|
|
||||||
* responsible for closing it.
|
|
||||||
*
|
|
||||||
* @param selection the selection
|
|
||||||
* @param selectionArgs the selection arguments
|
|
||||||
* @param sortOrder the sort order
|
|
||||||
* @param maxWaypoints the maximum number of waypoints to return
|
|
||||||
*/
|
|
||||||
public Cursor getWaypointsCursor(
|
|
||||||
String selection, String[] selectionArgs, String sortOrder, int maxWaypoints);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a waypoint cursor for a track. The caller owns the returned cursor and
|
|
||||||
* is responsible for closing it.
|
|
||||||
*
|
|
||||||
* @param trackId the track id
|
|
||||||
* @param minWaypointId the minimum waypoint id
|
|
||||||
* @param maxWaypoints the maximum number of waypoints to return
|
|
||||||
*/
|
|
||||||
public Cursor getWaypointsCursor(long trackId, long minWaypointId, int maxWaypoints);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the first recorded waypoint for a track. The first waypoint is special
|
|
||||||
* as it contains the stats for the current segment. Returns null if it
|
|
||||||
* doesn't exist.
|
|
||||||
*
|
|
||||||
* @param trackId the track id
|
|
||||||
*/
|
|
||||||
public Waypoint getFirstWaypoint(long trackId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the first waypoint id for a track. The first waypoint is special as it
|
* Gets the first waypoint id for a track. The first waypoint is special as it
|
||||||
@@ -167,36 +133,21 @@ public interface MyTracksProviderUtils {
|
|||||||
*/
|
*/
|
||||||
public long getFirstWaypointId(long trackId);
|
public long getFirstWaypointId(long trackId);
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the last waypoint id for a track. Returns -1L if it doesn't exist.
|
|
||||||
*
|
|
||||||
* @param trackId the track id
|
|
||||||
*/
|
|
||||||
public long getLastWaypointId(long trackId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the last statistics waypoint for a track. Returns null if it doesn't exist.
|
* Gets the last statistics waypoint for a track. Returns null if it doesn't exist.
|
||||||
*
|
*
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
*/
|
*/
|
||||||
public Waypoint getLastStatisticsWaypoint(long trackId);
|
public Waypoint getLastStatisticsWaypoint(long trackId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the next marker number. Returns -1 if not able to get the next marker
|
* Gets the next waypoint number. Returns -1 if not able to get the next
|
||||||
* number.
|
* waypoint number.
|
||||||
*
|
*
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
* @param statistics true for statistics marker, false for waypoint marker
|
* @param statistics true for statistics marker, false for waypoint marker
|
||||||
*/
|
*/
|
||||||
public int getNextMarkerNumber(long trackId, boolean statistics);
|
public int getNextWaypointNumber(long trackId, boolean statistics);
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the next statistics waypoint after the given waypoint. Returns null if
|
|
||||||
* it doesn't exists.
|
|
||||||
*
|
|
||||||
* @param waypoint the given waypoint
|
|
||||||
*/
|
|
||||||
public Waypoint getNextStatisticsWaypointAfter(Waypoint waypoint);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a waypoint from a waypoint id. Returns null if not found.
|
* Gets a waypoint from a waypoint id. Returns null if not found.
|
||||||
@@ -205,6 +156,28 @@ public interface MyTracksProviderUtils {
|
|||||||
*/
|
*/
|
||||||
public Waypoint getWaypoint(long waypointId);
|
public Waypoint getWaypoint(long waypointId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a waypoint cursor. The caller owns the returned cursor and is
|
||||||
|
* responsible for closing it.
|
||||||
|
*
|
||||||
|
* @param selection the selection
|
||||||
|
* @param selectionArgs the selection arguments
|
||||||
|
* @param sortOrder the sort order
|
||||||
|
* @param maxWaypoints the maximum number of waypoints to return
|
||||||
|
*/
|
||||||
|
public Cursor getWaypointCursor(
|
||||||
|
String selection, String[] selectionArgs, String sortOrder, int maxWaypoints);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a waypoint cursor for a track. The caller owns the returned cursor and
|
||||||
|
* is responsible for closing it.
|
||||||
|
*
|
||||||
|
* @param trackId the track id
|
||||||
|
* @param minWaypointId the minimum waypoint id
|
||||||
|
* @param maxWaypoints the maximum number of waypoints to return
|
||||||
|
*/
|
||||||
|
public Cursor getWaypointCursor(long trackId, long minWaypointId, int maxWaypoints);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a waypoint.
|
* Inserts a waypoint.
|
||||||
*
|
*
|
||||||
@@ -221,38 +194,36 @@ public interface MyTracksProviderUtils {
|
|||||||
public boolean updateWaypoint(Waypoint waypoint);
|
public boolean updateWaypoint(Waypoint waypoint);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a waypoint. If deleting a statistics waypoint, this will also
|
* Inserts multiple track points.
|
||||||
* correct the next statistics waypoint after the deleted one to reflect the
|
|
||||||
* deletion. The generator is used to update the next statistics waypoint.
|
|
||||||
*
|
*
|
||||||
* @param waypointId the waypoint id
|
* @param locations an array of locations
|
||||||
* @param descriptionGenerator the description generator
|
* @param length the number of locations (from the beginning of the array) to
|
||||||
|
* insert, or -1 for all of them
|
||||||
|
* @param trackId the track id
|
||||||
|
* @return the number of points inserted
|
||||||
*/
|
*/
|
||||||
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator);
|
public int bulkInsertTrackPoint(Location[] locations, int length, long trackId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a waypoint from a cursor.
|
* Creates a location object from a cursor.
|
||||||
*
|
*
|
||||||
* @param cursor the cursor pointing to the waypoint
|
* @param cursor the cursor pointing to the location
|
||||||
*/
|
*/
|
||||||
public Waypoint createWaypoint(Cursor cursor);
|
public Location createTrackPoint(Cursor cursor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the first recorded location. Returns null if it doesn't exist.
|
* Gets the last location id for a track. Returns -1L if it doesn't exist.
|
||||||
*/
|
|
||||||
public Location getFirstLocation();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the last recorded location. Returns null if it doesn't exist.
|
|
||||||
*/
|
|
||||||
public Location getLastLocation();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a location by track point id. Returns null if not found.
|
|
||||||
*
|
*
|
||||||
* @param trackPointId the track point id
|
* @param trackId the track id
|
||||||
*/
|
*/
|
||||||
public Location getLocation(long trackPointId);
|
public long getLastTrackPointId(long trackId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the last valid location for a track. Returns null if it doesn't exist.
|
||||||
|
*
|
||||||
|
* @param trackId the track id
|
||||||
|
*/
|
||||||
|
public Location getLastValidTrackPoint(long trackId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a location cursor. The caller owns the returned cursor and is
|
* Creates a location cursor. The caller owns the returned cursor and is
|
||||||
@@ -264,7 +235,7 @@ public interface MyTracksProviderUtils {
|
|||||||
* @param descending true to sort the result in descending order (latest
|
* @param descending true to sort the result in descending order (latest
|
||||||
* location first)
|
* location first)
|
||||||
*/
|
*/
|
||||||
public Cursor getLocationsCursor(
|
public Cursor getTrackPointCursor(
|
||||||
long trackId, long startTrackPointId, int maxLocations, boolean descending);
|
long trackId, long startTrackPointId, int maxLocations, boolean descending);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -285,23 +256,9 @@ public interface MyTracksProviderUtils {
|
|||||||
* location first)
|
* location first)
|
||||||
* @param locationFactory the location factory
|
* @param locationFactory the location factory
|
||||||
*/
|
*/
|
||||||
public LocationIterator getLocationIterator(
|
public LocationIterator getTrackPointLocationIterator(
|
||||||
long trackId, long startTrackPointId, boolean descending, LocationFactory locationFactory);
|
long trackId, long startTrackPointId, boolean descending, LocationFactory locationFactory);
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the last location id for a track. Returns -1L if it doesn't exist.
|
|
||||||
*
|
|
||||||
* @param trackId the track id
|
|
||||||
*/
|
|
||||||
public long getLastTrackLocationId(long trackId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the last location for a track. Returns -1L if it doesn't exist.
|
|
||||||
*
|
|
||||||
* @param trackId the track id
|
|
||||||
*/
|
|
||||||
public Location getLastTrackLocation(long trackId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a track point.
|
* Inserts a track point.
|
||||||
*
|
*
|
||||||
@@ -311,32 +268,6 @@ public interface MyTracksProviderUtils {
|
|||||||
*/
|
*/
|
||||||
public Uri insertTrackPoint(Location location, long trackId);
|
public Uri insertTrackPoint(Location location, long trackId);
|
||||||
|
|
||||||
/**
|
|
||||||
* Inserts multiple track points.
|
|
||||||
*
|
|
||||||
* @param locations an array of locations
|
|
||||||
* @param length the number of locations (from the beginning of the array) to
|
|
||||||
* insert, or -1 for all of them
|
|
||||||
* @param trackId the track id
|
|
||||||
* @return the number of points inserted
|
|
||||||
*/
|
|
||||||
public int bulkInsertTrackPoints(Location[] locations, int length, long trackId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fills a location from a cursor.
|
|
||||||
*
|
|
||||||
* @param cursor the cursor pointing to the location
|
|
||||||
* @param location the location to be overwritten
|
|
||||||
*/
|
|
||||||
public void fillLocation(Cursor cursor, Location location);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a location object from a cursor.
|
|
||||||
*
|
|
||||||
* @param cursor the cursor pointing to the location
|
|
||||||
*/
|
|
||||||
public Location createLocation(Cursor cursor);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A lightweight wrapper around the original {@link Cursor} with a method to
|
* A lightweight wrapper around the original {@link Cursor} with a method to
|
||||||
* clean up.
|
* clean up.
|
||||||
|
|||||||
+408
-518
File diff suppressed because it is too large
Load Diff
+402
-565
File diff suppressed because it is too large
Load Diff
@@ -203,7 +203,7 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
|
|
||||||
// Register two listeners
|
// Register two listeners
|
||||||
Capture<ContentObserver> contentObserverCapture = new Capture<ContentObserver>();
|
Capture<ContentObserver> contentObserverCapture = new Capture<ContentObserver>();
|
||||||
expect(myTracksProviderUtils.getWaypointsCursor(
|
expect(myTracksProviderUtils.getWaypointCursor(
|
||||||
eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
|
eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
|
||||||
.andStubAnswer(new FixedSizeCursorAnswer(2));
|
.andStubAnswer(new FixedSizeCursorAnswer(2));
|
||||||
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class)))
|
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class)))
|
||||||
@@ -230,7 +230,7 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
|
|
||||||
// Cause waypoints table update
|
// Cause waypoints table update
|
||||||
ContentObserver contentObserver = contentObserverCapture.getValue();
|
ContentObserver contentObserver = contentObserverCapture.getValue();
|
||||||
expect(myTracksProviderUtils.getWaypointsCursor(
|
expect(myTracksProviderUtils.getWaypointCursor(
|
||||||
eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
|
eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
|
||||||
.andStubAnswer(new FixedSizeCursorAnswer(3));
|
.andStubAnswer(new FixedSizeCursorAnswer(3));
|
||||||
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class)))
|
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class)))
|
||||||
@@ -251,7 +251,7 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
verifyAndReset();
|
verifyAndReset();
|
||||||
|
|
||||||
// Unregister one listener
|
// Unregister one listener
|
||||||
expect(myTracksProviderUtils.getWaypointsCursor(
|
expect(myTracksProviderUtils.getWaypointCursor(
|
||||||
eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
|
eq(TRACK_ID), AndroidMock.leq(0L), eq(Constants.MAX_DISPLAYED_WAYPOINTS_POINTS)))
|
||||||
.andStubAnswer(new FixedSizeCursorAnswer(4));
|
.andStubAnswer(new FixedSizeCursorAnswer(4));
|
||||||
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class)))
|
expect(myTracksProviderUtils.createWaypoint(isA(Cursor.class)))
|
||||||
@@ -288,9 +288,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
|
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
|
||||||
|
|
||||||
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
|
||||||
trackDataListener1.clearTrackPoints();
|
trackDataListener1.clearTrackPoints();
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener1);
|
locationIterator.expectLocationsDelivered(trackDataListener1);
|
||||||
trackDataListener1.onNewTrackPointsDone();
|
trackDataListener1.onNewTrackPointsDone();
|
||||||
@@ -303,9 +303,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
|
|
||||||
// Register a second listener
|
// Register a second listener
|
||||||
locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
|
||||||
trackDataListener2.clearTrackPoints();
|
trackDataListener2.clearTrackPoints();
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener2);
|
locationIterator.expectLocationsDelivered(trackDataListener2);
|
||||||
trackDataListener2.onNewTrackPointsDone();
|
trackDataListener2.onNewTrackPointsDone();
|
||||||
@@ -318,9 +318,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
// Deliver more points - should go to both listeners without clearing
|
// Deliver more points - should go to both listeners without clearing
|
||||||
ContentObserver contentObserver = contentObserverCapture.getValue();
|
ContentObserver contentObserver = contentObserverCapture.getValue();
|
||||||
locationIterator = new FixedSizeLocationIterator(11, 10, 1);
|
locationIterator = new FixedSizeLocationIterator(11, 10, 1);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(11L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
eq(TRACK_ID), eq(11L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(20L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(20L);
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener1);
|
locationIterator.expectLocationsDelivered(trackDataListener1);
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener2);
|
locationIterator.expectLocationsDelivered(trackDataListener2);
|
||||||
trackDataListener1.onNewTrackPointsDone();
|
trackDataListener1.onNewTrackPointsDone();
|
||||||
@@ -332,10 +332,10 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
|
|
||||||
// Unregister one listener and change track
|
// Unregister one listener and change track
|
||||||
locationIterator = new FixedSizeLocationIterator(101, 10);
|
locationIterator = new FixedSizeLocationIterator(101, 10);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
|
eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
|
||||||
.andReturn(locationIterator);
|
.andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID + 1)).andReturn(110L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID + 1)).andReturn(110L);
|
||||||
trackDataListener2.clearTrackPoints();
|
trackDataListener2.clearTrackPoints();
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener2);
|
locationIterator.expectLocationsDelivered(trackDataListener2);
|
||||||
trackDataListener2.onNewTrackPointsDone();
|
trackDataListener2.onNewTrackPointsDone();
|
||||||
@@ -358,9 +358,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
|
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
|
||||||
|
|
||||||
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
|
||||||
|
|
||||||
trackDataListener1.clearTrackPoints();
|
trackDataListener1.clearTrackPoints();
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener1);
|
locationIterator.expectLocationsDelivered(trackDataListener1);
|
||||||
@@ -384,9 +384,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
dataSource.registerContentObserver(
|
dataSource.registerContentObserver(
|
||||||
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
|
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
|
||||||
locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
|
||||||
trackDataListener1.clearTrackPoints();
|
trackDataListener1.clearTrackPoints();
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener1);
|
locationIterator.expectLocationsDelivered(trackDataListener1);
|
||||||
trackDataListener1.onNewTrackPointsDone();
|
trackDataListener1.onNewTrackPointsDone();
|
||||||
@@ -409,9 +409,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture));
|
eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture));
|
||||||
|
|
||||||
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 10, 5);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(10L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(10L);
|
||||||
trackDataListener1.clearTrackPoints();
|
trackDataListener1.clearTrackPoints();
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener1);
|
locationIterator.expectLocationsDelivered(trackDataListener1);
|
||||||
trackDataListener1.onNewTrackPointsDone();
|
trackDataListener1.onNewTrackPointsDone();
|
||||||
@@ -434,10 +434,10 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
dataSource.registerContentObserver(
|
dataSource.registerContentObserver(
|
||||||
eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture));
|
eq(TrackPointsColumns.CONTENT_URI), capture(observerCapture));
|
||||||
locationIterator = new FixedSizeLocationIterator(1, 10);
|
locationIterator = new FixedSizeLocationIterator(1, 10);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
|
eq(TRACK_ID + 1), eq(0L), eq(false), isA(LocationFactory.class)))
|
||||||
.andReturn(locationIterator);
|
.andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID + 1)).andReturn(10L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID + 1)).andReturn(10L);
|
||||||
trackDataListener1.clearTrackPoints();
|
trackDataListener1.clearTrackPoints();
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener1);
|
locationIterator.expectLocationsDelivered(trackDataListener1);
|
||||||
trackDataListener1.onNewTrackPointsDone();
|
trackDataListener1.onNewTrackPointsDone();
|
||||||
@@ -458,15 +458,15 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
dataSource.registerContentObserver(
|
dataSource.registerContentObserver(
|
||||||
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
|
eq(TrackPointsColumns.CONTENT_URI), capture(contentObserverCapture));
|
||||||
|
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(200L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(200L);
|
||||||
AndroidMock.expectLastCall().anyTimes();
|
AndroidMock.expectLastCall().anyTimes();
|
||||||
FixedSizeLocationIterator locationIterator1 = new FixedSizeLocationIterator(
|
FixedSizeLocationIterator locationIterator1 = new FixedSizeLocationIterator(
|
||||||
1, 200, 4, 25, 71, 120);
|
1, 200, 4, 25, 71, 120);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator1);
|
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator1);
|
||||||
FixedSizeLocationIterator locationIterator2 = new FixedSizeLocationIterator(
|
FixedSizeLocationIterator locationIterator2 = new FixedSizeLocationIterator(
|
||||||
1, 200, 4, 25, 71, 120);
|
1, 200, 4, 25, 71, 120);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator2);
|
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator2);
|
||||||
|
|
||||||
trackDataListener1.clearTrackPoints();
|
trackDataListener1.clearTrackPoints();
|
||||||
@@ -496,9 +496,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
|
|
||||||
// Deliver 30 points (no sampling happens)
|
// Deliver 30 points (no sampling happens)
|
||||||
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 30, 5);
|
FixedSizeLocationIterator locationIterator = new FixedSizeLocationIterator(1, 30, 5);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(30L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(30L);
|
||||||
|
|
||||||
trackDataListener1.clearTrackPoints();
|
trackDataListener1.clearTrackPoints();
|
||||||
locationIterator.expectLocationsDelivered(trackDataListener1);
|
locationIterator.expectLocationsDelivered(trackDataListener1);
|
||||||
@@ -513,9 +513,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
// Now deliver 30 more (incrementally sampled)
|
// Now deliver 30 more (incrementally sampled)
|
||||||
ContentObserver observer = observerCapture.getValue();
|
ContentObserver observer = observerCapture.getValue();
|
||||||
locationIterator = new FixedSizeLocationIterator(31, 30);
|
locationIterator = new FixedSizeLocationIterator(31, 30);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(31L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
eq(TRACK_ID), eq(31L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(60L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(60L);
|
||||||
locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false);
|
locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false);
|
||||||
trackDataListener1.onNewTrackPointsDone();
|
trackDataListener1.onNewTrackPointsDone();
|
||||||
replay();
|
replay();
|
||||||
@@ -525,9 +525,9 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
|
|
||||||
// Now another 30 (triggers resampling)
|
// Now another 30 (triggers resampling)
|
||||||
locationIterator = new FixedSizeLocationIterator(1, 90);
|
locationIterator = new FixedSizeLocationIterator(1, 90);
|
||||||
expect(myTracksProviderUtils.getLocationIterator(
|
expect(myTracksProviderUtils.getTrackPointLocationIterator(
|
||||||
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
eq(TRACK_ID), eq(0L), eq(false), isA(LocationFactory.class))).andReturn(locationIterator);
|
||||||
expect(myTracksProviderUtils.getLastTrackLocationId(TRACK_ID)).andReturn(90L);
|
expect(myTracksProviderUtils.getLastTrackPointId(TRACK_ID)).andReturn(90L);
|
||||||
trackDataListener1.clearTrackPoints();
|
trackDataListener1.clearTrackPoints();
|
||||||
locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false);
|
locationIterator.expectSampledLocationsDelivered(trackDataListener1, 2, false);
|
||||||
trackDataListener1.onNewTrackPointsDone();
|
trackDataListener1.onNewTrackPointsDone();
|
||||||
@@ -840,7 +840,7 @@ public class TrackDataHubTest extends AndroidTestCase {
|
|||||||
dataSource.registerOnSharedPreferenceChangeListener(capture(preferenceChangeListenerCapture));
|
dataSource.registerOnSharedPreferenceChangeListener(capture(preferenceChangeListenerCapture));
|
||||||
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
|
Capture<ContentObserver> observerCapture = new Capture<ContentObserver>();
|
||||||
dataSource.registerContentObserver(eq(WaypointsColumns.CONTENT_URI), capture(observerCapture));
|
dataSource.registerContentObserver(eq(WaypointsColumns.CONTENT_URI), capture(observerCapture));
|
||||||
expect(myTracksProviderUtils.getWaypointsCursor(capture(new Capture<Long>()), capture(new Capture<Long>()),
|
expect(myTracksProviderUtils.getWaypointCursor(capture(new Capture<Long>()), capture(new Capture<Long>()),
|
||||||
capture(new Capture<Integer>()))).andReturn(null);
|
capture(new Capture<Integer>()))).andReturn(null);
|
||||||
trackDataListener1.clearWaypoints();
|
trackDataListener1.clearWaypoints();
|
||||||
trackDataListener1.onNewWaypointsDone();
|
trackDataListener1.onNewWaypointsDone();
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class ChartFragmentTest extends AndroidTestCase {
|
|||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
chartFragment = new ChartFragment();
|
chartFragment = new ChartFragment();
|
||||||
chartFragment.setChartView(new ChartView(getContext()));
|
chartFragment.setChartView(new ChartView(getContext()));
|
||||||
chartFragment.setTripStatisticsBuilder(TrackStubUtils.INITIAL_TIME);
|
chartFragment.setTripStatisticsUpdater(TrackStubUtils.INITIAL_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -148,13 +148,13 @@ public class GpxImporterTest extends AndroidTestCase {
|
|||||||
expect(providerUtils.insertTrack(AndroidMock.capture(trackParam)))
|
expect(providerUtils.insertTrack(AndroidMock.capture(trackParam)))
|
||||||
.andReturn(TRACK_ID_URI);
|
.andReturn(TRACK_ID_URI);
|
||||||
|
|
||||||
expect(providerUtils.getLastTrackLocationId(TRACK_ID)).andReturn(TRACK_POINT_ID_1).andReturn(TRACK_POINT_ID_2);
|
expect(providerUtils.getLastTrackPointId(TRACK_ID)).andReturn(TRACK_POINT_ID_1).andReturn(TRACK_POINT_ID_2);
|
||||||
|
|
||||||
// A flush happens after the first insertion to get the starting point ID,
|
// A flush happens after the first insertion to get the starting point ID,
|
||||||
// which is why we get two calls
|
// which is why we get two calls
|
||||||
expect(providerUtils.bulkInsertTrackPoints(LocationsMatcher.eqLoc(loc1),
|
expect(providerUtils.bulkInsertTrackPoint(LocationsMatcher.eqLoc(loc1),
|
||||||
eq(1), eq(TRACK_ID))).andReturn(1);
|
eq(1), eq(TRACK_ID))).andReturn(1);
|
||||||
expect(providerUtils.bulkInsertTrackPoints(LocationsMatcher.eqLoc(loc2),
|
expect(providerUtils.bulkInsertTrackPoint(LocationsMatcher.eqLoc(loc2),
|
||||||
eq(1), eq(TRACK_ID))).andReturn(1);
|
eq(1), eq(TRACK_ID))).andReturn(1);
|
||||||
|
|
||||||
providerUtils.updateTrack(AndroidMock.capture(trackParam));
|
providerUtils.updateTrack(AndroidMock.capture(trackParam));
|
||||||
@@ -223,9 +223,9 @@ public class GpxImporterTest extends AndroidTestCase {
|
|||||||
expect(providerUtils.insertTrack((Track) AndroidMock.anyObject()))
|
expect(providerUtils.insertTrack((Track) AndroidMock.anyObject()))
|
||||||
.andReturn(TRACK_ID_URI);
|
.andReturn(TRACK_ID_URI);
|
||||||
|
|
||||||
expect(providerUtils.bulkInsertTrackPoints((Location[]) AndroidMock.anyObject(),
|
expect(providerUtils.bulkInsertTrackPoint((Location[]) AndroidMock.anyObject(),
|
||||||
AndroidMock.anyInt(), AndroidMock.anyLong())).andStubReturn(1);
|
AndroidMock.anyInt(), AndroidMock.anyLong())).andStubReturn(1);
|
||||||
expect(providerUtils.getLastTrackLocationId(TRACK_ID)).andStubReturn(TRACK_POINT_ID_1);
|
expect(providerUtils.getLastTrackPointId(TRACK_ID)).andStubReturn(TRACK_POINT_ID_1);
|
||||||
|
|
||||||
providerUtils.deleteTrack(TRACK_ID);
|
providerUtils.deleteTrack(TRACK_ID);
|
||||||
|
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ public class TrackWriterTest extends AndroidTestCase {
|
|||||||
// Make location 3 invalid
|
// Make location 3 invalid
|
||||||
locs[2].setLatitude(100);
|
locs[2].setLatitude(100);
|
||||||
|
|
||||||
assertEquals(locs.length, providerUtils.bulkInsertTrackPoints(locs, locs.length, TRACK_ID));
|
assertEquals(locs.length, providerUtils.bulkInsertTrackPoint(locs, locs.length, TRACK_ID));
|
||||||
for (int i = 0; i < wps.length; ++i) {
|
for (int i = 0; i < wps.length; ++i) {
|
||||||
Waypoint wpt = wps[i];
|
Waypoint wpt = wps[i];
|
||||||
wpt.setTrackId(TRACK_ID);
|
wpt.setTrackId(TRACK_ID);
|
||||||
|
|||||||
+12
-12
@@ -144,7 +144,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
|||||||
*/
|
*/
|
||||||
public void testUploadAllTrackPoints_nullCursor() {
|
public void testUploadAllTrackPoints_nullCursor() {
|
||||||
Track track = TrackStubUtils.createTrack(1);
|
Track track = TrackStubUtils.createTrack(1);
|
||||||
AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false))
|
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
|
||||||
.andReturn(null);
|
.andReturn(null);
|
||||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
|
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||||
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
||||||
@@ -164,9 +164,9 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
|||||||
AndroidMock.expect(cursorMock.getCount()).andReturn(2);
|
AndroidMock.expect(cursorMock.getCount()).andReturn(2);
|
||||||
AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true);
|
AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true);
|
||||||
cursorMock.close();
|
cursorMock.close();
|
||||||
AndroidMock.expect(myTracksProviderUtilsMock.createLocation(cursorMock)).andReturn(
|
AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock)).andReturn(
|
||||||
new Location("1"));
|
new Location("1"));
|
||||||
AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false))
|
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
|
||||||
.andReturn(cursorMock);
|
.andReturn(cursorMock);
|
||||||
|
|
||||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||||
@@ -191,9 +191,9 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
|||||||
AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true);
|
AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true);
|
||||||
AndroidMock.expect(cursorMock.moveToPosition(1)).andReturn(true);
|
AndroidMock.expect(cursorMock.moveToPosition(1)).andReturn(true);
|
||||||
cursorMock.close();
|
cursorMock.close();
|
||||||
AndroidMock.expect(myTracksProviderUtilsMock.createLocation(cursorMock))
|
AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock))
|
||||||
.andReturn(new Location("1")).times(2);
|
.andReturn(new Location("1")).times(2);
|
||||||
AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false))
|
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
|
||||||
.andReturn(cursorMock);
|
.andReturn(cursorMock);
|
||||||
|
|
||||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||||
@@ -221,9 +221,9 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
|||||||
AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true);
|
AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true);
|
||||||
AndroidMock.expect(cursorMock.moveToPosition(1)).andReturn(true);
|
AndroidMock.expect(cursorMock.moveToPosition(1)).andReturn(true);
|
||||||
cursorMock.close();
|
cursorMock.close();
|
||||||
AndroidMock.expect(myTracksProviderUtilsMock.createLocation(cursorMock))
|
AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock))
|
||||||
.andReturn(new Location("1")).times(2);
|
.andReturn(new Location("1")).times(2);
|
||||||
AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false))
|
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
|
||||||
.andReturn(cursorMock);
|
.andReturn(cursorMock);
|
||||||
|
|
||||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||||
@@ -250,9 +250,9 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
|||||||
AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true);
|
AndroidMock.expect(cursorMock.moveToPosition(0)).andReturn(true);
|
||||||
AndroidMock.expect(cursorMock.moveToPosition(1)).andReturn(true);
|
AndroidMock.expect(cursorMock.moveToPosition(1)).andReturn(true);
|
||||||
cursorMock.close();
|
cursorMock.close();
|
||||||
AndroidMock.expect(myTracksProviderUtilsMock.createLocation(cursorMock))
|
AndroidMock.expect(myTracksProviderUtilsMock.createTrackPoint(cursorMock))
|
||||||
.andReturn(new Location("1")).times(2);
|
.andReturn(new Location("1")).times(2);
|
||||||
AndroidMock.expect(myTracksProviderUtilsMock.getLocationsCursor(TRACK_ID, 0, -1, false))
|
AndroidMock.expect(myTracksProviderUtilsMock.getTrackPointCursor(TRACK_ID, 0, -1, false))
|
||||||
.andReturn(cursorMock);
|
.andReturn(cursorMock);
|
||||||
|
|
||||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||||
@@ -274,7 +274,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
|||||||
@UsesMocks(Cursor.class)
|
@UsesMocks(Cursor.class)
|
||||||
public void testUploadWaypoints_nullCursor() {
|
public void testUploadWaypoints_nullCursor() {
|
||||||
AndroidMock.expect(
|
AndroidMock.expect(
|
||||||
myTracksProviderUtilsMock.getWaypointsCursor(TRACK_ID, 0,
|
myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, 0,
|
||||||
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(null);
|
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(null);
|
||||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
|
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock);
|
||||||
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
SendMapsAsyncTask sendMapsAsyncTask = new SendMapsAsyncTask(sendMapsActivityMock,
|
||||||
@@ -296,7 +296,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
|||||||
cursorMock.close();
|
cursorMock.close();
|
||||||
|
|
||||||
AndroidMock.expect(
|
AndroidMock.expect(
|
||||||
myTracksProviderUtilsMock.getWaypointsCursor(TRACK_ID, 0,
|
myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, 0,
|
||||||
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(cursorMock);
|
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(cursorMock);
|
||||||
|
|
||||||
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
AndroidMock.replay(sendMapsActivityMock, myTracksProviderUtilsMock, cursorMock);
|
||||||
@@ -323,7 +323,7 @@ public class SendMapsAsyncTaskTest extends AndroidTestCase {
|
|||||||
cursorMock.close();
|
cursorMock.close();
|
||||||
|
|
||||||
AndroidMock.expect(
|
AndroidMock.expect(
|
||||||
myTracksProviderUtilsMock.getWaypointsCursor(TRACK_ID, 0,
|
myTracksProviderUtilsMock.getWaypointCursor(TRACK_ID, 0,
|
||||||
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(cursorMock);
|
Constants.MAX_LOADED_WAYPOINTS_POINTS)).andReturn(cursorMock);
|
||||||
Waypoint waypoint = new Waypoint();
|
Waypoint waypoint = new Waypoint();
|
||||||
waypoint.setLocation(TrackStubUtils.createMyTracksLocation());
|
waypoint.setLocation(TrackStubUtils.createMyTracksLocation());
|
||||||
|
|||||||
+45
-45
@@ -10,28 +10,28 @@ import android.location.Location;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsBuilder}.
|
* Tests {@link TripStatisticsUpdater}.
|
||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
public class TripStatisticsBuilderTest extends TestCase {
|
public class TripStatisticsUpdaterTest extends TestCase {
|
||||||
|
|
||||||
private static final long ONE_SECOND = 1000;
|
private static final long ONE_SECOND = 1000;
|
||||||
private static final long TEN_SECONDS = 10 * ONE_SECOND;
|
private static final long TEN_SECONDS = 10 * ONE_SECOND;
|
||||||
|
|
||||||
private TripStatisticsBuilder tripStatisticsBuilder = null;
|
private TripStatisticsUpdater tripStatisticsUpdater = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
tripStatisticsBuilder = new TripStatisticsBuilder(System.currentTimeMillis());
|
tripStatisticsUpdater = new TripStatisticsUpdater(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAddLocationSimple() throws Exception {
|
public void testAddLocationSimple() throws Exception {
|
||||||
long startTime = 1000;
|
long startTime = 1000;
|
||||||
tripStatisticsBuilder = new TripStatisticsBuilder(startTime);
|
tripStatisticsUpdater = new TripStatisticsUpdater(startTime);
|
||||||
TripStatistics tripStatistics = tripStatisticsBuilder.getTripStatistics();
|
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
|
|
||||||
assertEquals(0.0, tripStatisticsBuilder.getSmoothedElevation());
|
assertEquals(0.0, tripStatisticsUpdater.getSmoothedElevation());
|
||||||
assertEquals(Double.POSITIVE_INFINITY, tripStatistics.getMinElevation());
|
assertEquals(Double.POSITIVE_INFINITY, tripStatistics.getMinElevation());
|
||||||
assertEquals(Double.NEGATIVE_INFINITY, tripStatistics.getMaxElevation());
|
assertEquals(Double.NEGATIVE_INFINITY, tripStatistics.getMaxElevation());
|
||||||
assertEquals(0.0, tripStatistics.getMaxSpeed());
|
assertEquals(0.0, tripStatistics.getMaxSpeed());
|
||||||
@@ -57,12 +57,12 @@ public class TripStatisticsBuilderTest extends TestCase {
|
|||||||
|
|
||||||
// Each time slice is 10 seconds.
|
// Each time slice is 10 seconds.
|
||||||
location.setTime(startTime + i * TEN_SECONDS);
|
location.setTime(startTime + i * TEN_SECONDS);
|
||||||
tripStatisticsBuilder.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
tripStatisticsUpdater.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
||||||
|
|
||||||
tripStatistics = tripStatisticsBuilder.getTripStatistics();
|
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
assertEquals(i * TEN_SECONDS, tripStatistics.getTotalTime());
|
assertEquals(i * TEN_SECONDS, tripStatistics.getTotalTime());
|
||||||
assertEquals(i * TEN_SECONDS, tripStatistics.getMovingTime());
|
assertEquals(i * TEN_SECONDS, tripStatistics.getMovingTime());
|
||||||
assertEquals(i, tripStatisticsBuilder.getSmoothedElevation(),
|
assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(),
|
||||||
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
assertEquals(0.0, tripStatistics.getMinElevation());
|
assertEquals(0.0, tripStatistics.getMinElevation());
|
||||||
assertEquals(i, tripStatistics.getMaxElevation(), Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
assertEquals(i, tripStatistics.getMaxElevation(), Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
@@ -81,17 +81,17 @@ public class TripStatisticsBuilderTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsBuilder#updateElevation(double)} with constant
|
* Tests {@link TripStatisticsUpdater#updateElevation(double)} with constant
|
||||||
* elevations.
|
* elevations.
|
||||||
*/
|
*/
|
||||||
public void testElevationSimple() throws Exception {
|
public void testElevationSimple() throws Exception {
|
||||||
for (double elevation = 0; elevation < 1000; elevation += 10) {
|
for (double elevation = 0; elevation < 1000; elevation += 10) {
|
||||||
tripStatisticsBuilder = new TripStatisticsBuilder(System.currentTimeMillis());
|
tripStatisticsUpdater = new TripStatisticsUpdater(System.currentTimeMillis());
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
assertEquals(0.0, tripStatisticsBuilder.updateElevation(elevation));
|
assertEquals(0.0, tripStatisticsUpdater.updateElevation(elevation));
|
||||||
assertEquals(elevation, tripStatisticsBuilder.getSmoothedElevation());
|
assertEquals(elevation, tripStatisticsUpdater.getSmoothedElevation());
|
||||||
|
|
||||||
TripStatistics tripStatistics = tripStatisticsBuilder.getTripStatistics();
|
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||||
assertEquals(elevation, tripStatistics.getMinElevation());
|
assertEquals(elevation, tripStatistics.getMinElevation());
|
||||||
assertEquals(elevation, tripStatistics.getMaxElevation());
|
assertEquals(elevation, tripStatistics.getMaxElevation());
|
||||||
assertEquals(0.0, tripStatistics.getTotalElevationGain());
|
assertEquals(0.0, tripStatistics.getTotalElevationGain());
|
||||||
@@ -100,7 +100,7 @@ public class TripStatisticsBuilderTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsBuilder#updateGrade(double, double)} with
|
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with
|
||||||
* elevation gain.
|
* elevation gain.
|
||||||
*/
|
*/
|
||||||
public void testElevationGain() throws Exception {
|
public void testElevationGain() throws Exception {
|
||||||
@@ -113,11 +113,11 @@ public class TripStatisticsBuilderTest extends TestCase {
|
|||||||
} else {
|
} else {
|
||||||
expectedGain = 1.0;
|
expectedGain = 1.0;
|
||||||
}
|
}
|
||||||
assertEquals(expectedGain, tripStatisticsBuilder.updateElevation(i));
|
assertEquals(expectedGain, tripStatisticsUpdater.updateElevation(i));
|
||||||
assertEquals(i, tripStatisticsBuilder.getSmoothedElevation(),
|
assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(),
|
||||||
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
|
|
||||||
TripStatistics data = tripStatisticsBuilder.getTripStatistics();
|
TripStatistics data = tripStatisticsUpdater.getTripStatistics();
|
||||||
assertEquals(0.0, data.getMinElevation());
|
assertEquals(0.0, data.getMinElevation());
|
||||||
assertEquals(i, data.getMaxElevation(), Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
assertEquals(i, data.getMaxElevation(), Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||||
assertEquals(i, data.getTotalElevationGain(), Constants.ELEVATION_SMOOTHING_FACTOR);
|
assertEquals(i, data.getTotalElevationGain(), Constants.ELEVATION_SMOOTHING_FACTOR);
|
||||||
@@ -125,7 +125,7 @@ public class TripStatisticsBuilderTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsBuilder#updateGrade(double, double)} with grade
|
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with grade
|
||||||
* of 1 and -1.
|
* of 1 and -1.
|
||||||
*/
|
*/
|
||||||
public void testGradeSimple() throws Exception {
|
public void testGradeSimple() throws Exception {
|
||||||
@@ -134,11 +134,11 @@ public class TripStatisticsBuilderTest extends TestCase {
|
|||||||
* The value of the elevation does not matter. This is just to fill the
|
* The value of the elevation does not matter. This is just to fill the
|
||||||
* elevation buffer.
|
* elevation buffer.
|
||||||
*/
|
*/
|
||||||
tripStatisticsBuilder.updateElevation(i);
|
tripStatisticsUpdater.updateElevation(i);
|
||||||
tripStatisticsBuilder.updateGrade(100, 100);
|
tripStatisticsUpdater.updateGrade(100, 100);
|
||||||
if (i >= Constants.GRADE_SMOOTHING_FACTOR && i >= Constants.ELEVATION_SMOOTHING_FACTOR) {
|
if (i >= Constants.GRADE_SMOOTHING_FACTOR && i >= Constants.ELEVATION_SMOOTHING_FACTOR) {
|
||||||
assertEquals(1.0, tripStatisticsBuilder.getTripStatistics().getMaxGrade());
|
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||||
assertEquals(1.0, tripStatisticsBuilder.getTripStatistics().getMinGrade());
|
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (double i = 0; i < 1000; i++) {
|
for (double i = 0; i < 1000; i++) {
|
||||||
@@ -146,17 +146,17 @@ public class TripStatisticsBuilderTest extends TestCase {
|
|||||||
* The value of the elevation does not matter. This is just to fill the
|
* The value of the elevation does not matter. This is just to fill the
|
||||||
* elevation buffer.
|
* elevation buffer.
|
||||||
*/
|
*/
|
||||||
tripStatisticsBuilder.updateElevation(i);
|
tripStatisticsUpdater.updateElevation(i);
|
||||||
tripStatisticsBuilder.updateGrade(100, -100);
|
tripStatisticsUpdater.updateGrade(100, -100);
|
||||||
if (i >= Constants.GRADE_SMOOTHING_FACTOR && i >= Constants.ELEVATION_SMOOTHING_FACTOR) {
|
if (i >= Constants.GRADE_SMOOTHING_FACTOR && i >= Constants.ELEVATION_SMOOTHING_FACTOR) {
|
||||||
assertEquals(1.0, tripStatisticsBuilder.getTripStatistics().getMaxGrade());
|
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||||
assertEquals(-1.0, tripStatisticsBuilder.getTripStatistics().getMinGrade());
|
assertEquals(-1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsBuilder#updateGrade(double, double)} with
|
* Tests {@link TripStatisticsUpdater#updateGrade(double, double)} with
|
||||||
* distance of 1. The grade should get ignored.
|
* distance of 1. The grade should get ignored.
|
||||||
*/
|
*/
|
||||||
public void testGradeIgnoreShort() throws Exception {
|
public void testGradeIgnoreShort() throws Exception {
|
||||||
@@ -165,56 +165,56 @@ public class TripStatisticsBuilderTest extends TestCase {
|
|||||||
* The value of the elevation does not matter. This is just to fill the
|
* The value of the elevation does not matter. This is just to fill the
|
||||||
* elevation buffer.
|
* elevation buffer.
|
||||||
*/
|
*/
|
||||||
tripStatisticsBuilder.updateElevation(i);
|
tripStatisticsUpdater.updateElevation(i);
|
||||||
tripStatisticsBuilder.updateGrade(1, 100);
|
tripStatisticsUpdater.updateGrade(1, 100);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Double.NEGATIVE_INFINITY, tripStatisticsBuilder.getTripStatistics().getMaxGrade());
|
Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||||
assertEquals(
|
assertEquals(
|
||||||
Double.POSITIVE_INFINITY, tripStatisticsBuilder.getTripStatistics().getMinGrade());
|
Double.POSITIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsBuilder#updateSpeed(long, double, long, double)}
|
* Tests {@link TripStatisticsUpdater#updateSpeed(long, double, long, double)}
|
||||||
* with speed of zero.
|
* with speed of zero.
|
||||||
*/
|
*/
|
||||||
public void testUpdateSpeedIncludeZero() {
|
public void testUpdateSpeedIncludeZero() {
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
tripStatisticsBuilder.updateSpeed(i + ONE_SECOND, 0.0, i, 4.0);
|
tripStatisticsUpdater.updateSpeed(i + ONE_SECOND, 0.0, i, 4.0);
|
||||||
assertEquals(0.0, tripStatisticsBuilder.getTripStatistics().getMaxSpeed());
|
assertEquals(0.0, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsBuilder#updateSpeed(long, double, long, double)}
|
* Tests {@link TripStatisticsUpdater#updateSpeed(long, double, long, double)}
|
||||||
* with the error code 128. The speed should get ignored.
|
* with the error code 128. The speed should get ignored.
|
||||||
*/
|
*/
|
||||||
public void testUpdateSpeedIngoreErrorCode() {
|
public void testUpdateSpeedIngoreErrorCode() {
|
||||||
long time = 12344000;
|
long time = 12344000;
|
||||||
tripStatisticsBuilder.updateSpeed(time + ONE_SECOND, 128.0, time, 0.0);
|
tripStatisticsUpdater.updateSpeed(time + ONE_SECOND, 128.0, time, 0.0);
|
||||||
assertEquals(0.0, tripStatisticsBuilder.getTripStatistics().getMaxSpeed());
|
assertEquals(0.0, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsBuilder#updateSpeed(long, double, long, double)}
|
* Tests {@link TripStatisticsUpdater#updateSpeed(long, double, long, double)}
|
||||||
* with a large speed change. The speed should get ignored.
|
* with a large speed change. The speed should get ignored.
|
||||||
*/
|
*/
|
||||||
public void testUpdateSpeedIngoreLargeAcceleration() {
|
public void testUpdateSpeedIngoreLargeAcceleration() {
|
||||||
long time = 12344000;
|
long time = 12344000;
|
||||||
tripStatisticsBuilder.updateSpeed(time + ONE_SECOND, 100.0, time, 1.0);
|
tripStatisticsUpdater.updateSpeed(time + ONE_SECOND, 100.0, time, 1.0);
|
||||||
assertEquals(0.0, tripStatisticsBuilder.getTripStatistics().getMaxSpeed());
|
assertEquals(0.0, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link TripStatisticsBuilder#updateSpeed(long, double, long, double)}
|
* Tests {@link TripStatisticsUpdater#updateSpeed(long, double, long, double)}
|
||||||
* with constant speed.
|
* with constant speed.
|
||||||
*/
|
*/
|
||||||
public void testUpdateSpeed() {
|
public void testUpdateSpeed() {
|
||||||
double speed = 4.0;
|
double speed = 4.0;
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
tripStatisticsBuilder.updateSpeed(i + ONE_SECOND, speed, i, speed);
|
tripStatisticsUpdater.updateSpeed(i + ONE_SECOND, speed, i, speed);
|
||||||
if (i >= Constants.SPEED_SMOOTHING_FACTOR) {
|
if (i >= Constants.SPEED_SMOOTHING_FACTOR) {
|
||||||
assertEquals(speed, tripStatisticsBuilder.getTripStatistics().getMaxSpeed());
|
assertEquals(speed, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user