Rename methods in MyTracksProviderUtils.

No logic change
This commit is contained in:
Jimmy Shih
2012-08-24 15:21:39 -07:00
parent 784ce8bc26
commit be6fd6d633
17 changed files with 1061 additions and 1060 deletions
@@ -114,12 +114,12 @@ public class MarkerEditActivity extends AbstractMyTracksActivity {
if (newMarker) {
statisticsSection.setVisibility(View.GONE);
waypointSection.setVisibility(View.VISIBLE);
int nextMarkerNumber = trackId == -1L ? -1
: MyTracksProviderUtils.Factory.get(this).getNextMarkerNumber(trackId, false);
if (nextMarkerNumber == -1) {
nextMarkerNumber = 0;
int nextWaypointNumber = trackId == -1L ? -1
: MyTracksProviderUtils.Factory.get(this).getNextWaypointNumber(trackId, false);
if (nextWaypointNumber == -1) {
nextWaypointNumber = 0;
}
waypointName.setText(getString(R.string.marker_name_format, nextMarkerNumber));
waypointName.setText(getString(R.string.marker_name_format, nextWaypointNumber));
waypointName.selectAll();
waypointMarkerType.setText("");
waypointDescription.setText("");
@@ -125,7 +125,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity {
Button cancel = (Button) findViewById(R.id.track_edit_cancel);
if (getIntent().getBooleanExtra(EXTRA_NEW_TRACK, false)) {
String trackName = TrackNameUtils.getTrackName(
this, -1L, -1L, myTracksProviderUtils.getLastValidTrackLocation(trackId));
this, -1L, -1L, myTracksProviderUtils.getLastValidTrackPoint(trackId));
if (trackName != null) {
name.setText(trackName);
}
@@ -186,7 +186,7 @@ public class SearchEngine {
queryLikeSelection,
queryLikeSelection };
Cursor tracksCursor = providerUtils.getTracksCursor(
Cursor tracksCursor = providerUtils.getTrackCursor(
TRACK_SELECTION_QUERY, trackSelectionArgs, TRACK_SELECTION_ORDER);
if (tracksCursor != null) {
try {
@@ -213,21 +213,21 @@ public class SearchEngine {
queryLikeSelection2,
queryLikeSelection2,
queryLikeSelection2 };
Cursor waypointsCursor = providerUtils.getWaypointsCursor(
Cursor waypointCursor = providerUtils.getWaypointCursor(
WAYPOINT_SELECTION_QUERY, waypointSelectionArgs, WAYPOINT_SELECTION_ORDER,
MAX_SCORED_WAYPOINTS);
if (waypointsCursor != null) {
if (waypointCursor != null) {
try {
waypoints.ensureCapacity(waypointsCursor.getCount());
waypoints.ensureCapacity(waypointCursor.getCount());
while (waypointsCursor.moveToNext()) {
Waypoint waypoint = providerUtils.createWaypoint(waypointsCursor);
while (waypointCursor.moveToNext()) {
Waypoint waypoint = providerUtils.createWaypoint(waypointCursor);
if (LocationUtils.isValidLocation(waypoint.getLocation())) {
waypoints.add(waypoint);
}
}
} finally {
waypointsCursor.close();
waypointCursor.close();
}
}
}
@@ -563,7 +563,7 @@ public class TrackDataHub implements DataSourceListener {
Cursor cursor = null;
try {
cursor = myTracksProviderUtils.getWaypointsCursor(
cursor = myTracksProviderUtils.getWaypointCursor(
selectedTrackId, 0L, MAX_DISPLAYED_WAYPOINTS_POINTS);
if (cursor != null && cursor.moveToFirst()) {
do {
@@ -614,9 +614,9 @@ public class TrackDataHub implements DataSourceListener {
long localLastSeenLocationId = updateSamplingState ? lastSeenLocationId : -1L;
long maxPointId = updateSamplingState ? -1L : lastSeenLocationId;
long lastLocationId = myTracksProviderUtils.getLastTrackLocationId(selectedTrackId);
long lastTrackPointId = myTracksProviderUtils.getLastTrackPointId(selectedTrackId);
int samplingFrequency = -1;
LocationIterator iterator = myTracksProviderUtils.getLocationIterator(
LocationIterator iterator = myTracksProviderUtils.getTrackPointLocationIterator(
selectedTrackId, localLastSeenLocationId + 1, false, locationFactory);
boolean includeNextPoint = false;
while (iterator.hasNext()) {
@@ -633,7 +633,7 @@ public class TrackDataHub implements DataSourceListener {
}
if (samplingFrequency == -1) {
long numTotalPoints = Math.max(0L, lastLocationId - localFirstSeenLocationId);
long numTotalPoints = Math.max(0L, lastTrackPointId - localFirstSeenLocationId);
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
}
@@ -646,7 +646,7 @@ public class TrackDataHub implements DataSourceListener {
} else {
// Also include the last point if the selected track is not recording.
if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0)
|| (locationId == lastLocationId && !isSelectedTrackRecording())) {
|| (locationId == lastTrackPointId && !isSelectedTrackRecording())) {
includeNextPoint = false;
for (TrackDataListener trackDataListener : sampledInListeners) {
trackDataListener.onSampledInTrackPoint(location);
@@ -506,7 +506,7 @@ public class GpxImporter extends DefaultHandler {
if (numBufferedPointInserts <= 0) {
return;
}
myTracksProviderUtils.bulkInsertTrackPoints(
myTracksProviderUtils.bulkInsertTrackPoint(
bufferedPointInserts, numBufferedPointInserts, track.getId());
numBufferedPointInserts = 0;
}
@@ -528,7 +528,7 @@ public class GpxImporter extends DefaultHandler {
*/
private long getLastPointId() {
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() {
Cursor cursor = null;
try {
cursor = myTracksProviderUtils.getTracksCursor(null, null, TracksColumns._ID);
cursor = myTracksProviderUtils.getTrackCursor(null, null, TracksColumns._ID);
if (cursor == null) {
messageId = R.string.sd_card_save_error_no_track;
return false;
@@ -245,7 +245,7 @@ class TrackWriterImpl implements TrackWriter {
// problem because we don't try to load them into objects all at the
// same time.
Cursor cursor = null;
cursor = providerUtils.getWaypointsCursor(trackId, 0,
cursor = providerUtils.getWaypointCursor(trackId, 0,
Constants.MAX_LOADED_WAYPOINTS_POINTS);
boolean hasWaypoints = false;
if (cursor != null) {
@@ -314,7 +314,7 @@ class TrackWriterImpl implements TrackWriter {
};
TrackWriterLocationFactory locationFactory = new TrackWriterLocationFactory();
LocationIterator it = providerUtils.getLocationIterator(track.getId(), 0, false,
LocationIterator it = providerUtils.getTrackPointLocationIterator(track.getId(), 0, false,
locationFactory);
try {
if (!it.hasNext()) {
@@ -208,20 +208,20 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
* @return true if success.
*/
private boolean uploadAllTrackPoints(Track track) {
Cursor locationsCursor = null;
Cursor cursor = null;
try {
locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false);
if (locationsCursor == null) {
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, 0, -1, false);
if (cursor == null) {
Log.d(TAG, "Location cursor is null");
return false;
}
int locationsCount = locationsCursor.getCount();
int count = cursor.getCount();
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
Location lastLocation = null;
// 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> elevations = new Vector<Double>();
TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder(
@@ -229,10 +229,10 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
int minRecordingDistance = PreferencesUtils.getInt(context,
R.string.min_recording_distance_key, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
for (int i = 0; i < locationsCount; i++) {
locationsCursor.moveToPosition(i);
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
Location location = myTracksProviderUtils.createLocation(locationsCursor);
Location location = myTracksProviderUtils.createTrackPoint(cursor);
locations.add(location);
if (i == 0) {
@@ -260,7 +260,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
Log.d(TAG, "Unable to upload points");
return false;
}
updateProgress(readCount, locationsCount);
updateProgress(readCount, count);
locations.clear();
}
}
@@ -287,8 +287,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
return true;
} finally {
if (locationsCursor != null) {
locationsCursor.close();
if (cursor != null) {
cursor.close();
}
}
}
@@ -328,7 +328,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
private boolean uploadWaypoints() {
Cursor cursor = null;
try {
cursor = myTracksProviderUtils.getWaypointsCursor(
cursor = myTracksProviderUtils.getWaypointCursor(
trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS);
if (cursor != null && cursor.moveToFirst()) {
// This will skip the first waypoint (it carries the stats for the
@@ -251,20 +251,20 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
*/
@VisibleForTesting
boolean uploadAllTrackPoints(Track track) {
Cursor locationsCursor = null;
Cursor cursor = null;
try {
locationsCursor = myTracksProviderUtils.getLocationsCursor(trackId, 0, -1, false);
if (locationsCursor == null) {
cursor = myTracksProviderUtils.getTrackPointCursor(trackId, 0, -1, false);
if (cursor == null) {
Log.d(TAG, "Location cursor is null");
return false;
}
int locationsCount = locationsCursor.getCount();
int count = cursor.getCount();
List<Location> locations = new ArrayList<Location>(MAX_POINTS_PER_UPLOAD);
Location lastLocation = null;
// 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> elevations = new Vector<Double>();
TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder(
@@ -272,10 +272,10 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
int minRecordingDistance = PreferencesUtils.getInt(context,
R.string.min_recording_distance_key, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
for (int i = 0; i < locationsCount; i++) {
locationsCursor.moveToPosition(i);
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
Location location = myTracksProviderUtils.createLocation(locationsCursor);
Location location = myTracksProviderUtils.createTrackPoint(cursor);
locations.add(location);
if (i == 0) {
@@ -303,7 +303,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
Log.d(TAG, "Unable to upload points");
return false;
}
updateProgress(readCount, locationsCount);
updateProgress(readCount, count);
locations.clear();
}
}
@@ -329,8 +329,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
}
return true;
} finally {
if (locationsCursor != null) {
locationsCursor.close();
if (cursor != null) {
cursor.close();
}
}
}
@@ -436,7 +436,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
boolean uploadWaypoints() {
Cursor cursor = null;
try {
cursor = myTracksProviderUtils.getWaypointsCursor(
cursor = myTracksProviderUtils.getWaypointCursor(
trackId, 0, Constants.MAX_LOADED_WAYPOINTS_POINTS);
if (cursor != null && cursor.moveToFirst()) {
// This will skip the first waypoint (it carries the stats for the
@@ -419,14 +419,14 @@ public class TrackRecordingService extends Service {
if (waypointCreationRequest.getName() != null) {
name = waypointCreationRequest.getName();
} else {
int nextMarkerNumber = myTracksProviderUtils.getNextMarkerNumber(
int nextWaypointNumber = myTracksProviderUtils.getNextWaypointNumber(
recordingTrackId, isStatistics);
if (nextMarkerNumber == -1) {
nextMarkerNumber = 0;
if (nextWaypointNumber == -1) {
nextWaypointNumber = 0;
}
name = getString(
isStatistics ? R.string.marker_split_name_format : R.string.marker_name_format,
nextMarkerNumber);
nextWaypointNumber);
}
TripStatistics tripStatistics;
@@ -452,8 +452,8 @@ public class TrackRecordingService extends Service {
int type = isStatistics ? Waypoint.TYPE_STATISTICS : Waypoint.TYPE_WAYPOINT;
long duration;
double length;
Location lastTrackLocation = myTracksProviderUtils.getLastTrackLocation(recordingTrackId);
if (currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackLocation)
Location lastTrackPoint = myTracksProviderUtils.getLastTrackPoint(recordingTrackId);
if (currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackPoint)
&& trackTripStatisticsBuilder != null) {
TripStatistics stats = trackTripStatisticsBuilder.getTripStatistics();
length = stats.getTotalDistance();
@@ -463,14 +463,14 @@ public class TrackRecordingService extends Service {
return -1L;
}
// For track statistics, make it an impossible location
lastTrackLocation = new Location("");
lastTrackLocation.setLatitude(100);
lastTrackLocation.setLongitude(180);
lastTrackPoint = new Location("");
lastTrackPoint.setLatitude(100);
lastTrackPoint.setLongitude(180);
length = 0;
duration = 0;
}
Waypoint waypoint = new Waypoint(name, description, category, icon, recordingTrackId, type,
length, duration, -1L, -1L, lastTrackLocation, tripStatistics);
length, duration, -1L, -1L, lastTrackPoint, tripStatistics);
Uri uri = myTracksProviderUtils.insertWaypoint(waypoint);
return Long.parseLong(uri.getLastPathSegment());
}
@@ -605,14 +605,14 @@ public class TrackRecordingService extends Service {
Cursor cursor = null;
try {
// TODO: how to handle very long track.
cursor = myTracksProviderUtils.getLocationsCursor(
cursor = myTracksProviderUtils.getTrackPointCursor(
recordingTrackId, -1, Constants.MAX_LOADED_TRACK_POINTS, true);
if (cursor == null) {
Log.e(TAG, "Cursor is null.");
} else {
if (cursor.moveToLast()) {
do {
Location location = myTracksProviderUtils.createLocation(cursor);
Location location = myTracksProviderUtils.createTrackPoint(cursor);
trackTripStatisticsBuilder.addLocation(location, minRecordingDistance);
if (location.getTime() > markerStartTime) {
markerTripStatisticsBuilder.addLocation(location, minRecordingDistance);
@@ -701,8 +701,8 @@ public class TrackRecordingService extends Service {
// Update database
Track track = myTracksProviderUtils.getTrack(trackId);
if (track != null) {
insertLocation(track, lastLocation, myTracksProviderUtils.getLastTrackLocation(trackId));
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackLocationId(trackId), false);
insertLocation(track, lastLocation, myTracksProviderUtils.getLastTrackPoint(trackId));
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false);
}
endRecording(true, trackId);
@@ -726,7 +726,7 @@ public class TrackRecordingService extends Service {
Track track = myTracksProviderUtils.getTrack(recordingTrackId);
if (track != null) {
insertLocation(
track, lastLocation, myTracksProviderUtils.getLastTrackLocation(track.getId()));
track, lastLocation, myTracksProviderUtils.getLastTrackPoint(track.getId()));
Location pause = new Location(LocationManager.GPS_PROVIDER);
pause.setLongitude(0);
@@ -809,9 +809,9 @@ public class TrackRecordingService extends Service {
return;
}
Location lastTrackLocation = myTracksProviderUtils.getLastTrackLocation(track.getId());
long idleTime = currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackLocation) ?
location.getTime() - lastTrackLocation.getTime()
Location lastTrackPoint = myTracksProviderUtils.getLastTrackPoint(track.getId());
long idleTime = currentSegmentHasLocation && LocationUtils.isValidLocation(lastTrackPoint) ?
location.getTime() - lastTrackPoint.getTime()
: 0L;
locationListenerPolicy.updateIdleTime(idleTime);
if (currentRecordingInterval != locationListenerPolicy.getDesiredPollingInterval()) {
@@ -825,41 +825,41 @@ public class TrackRecordingService extends Service {
// Always insert the first segment location
if (!currentSegmentHasLocation) {
insertLocation(track, location, lastTrackLocation);
insertLocation(track, location, lastTrackPoint);
currentSegmentHasLocation = true;
lastLocation = location;
return;
}
if (!LocationUtils.isValidLocation(lastTrackLocation)) {
if (!LocationUtils.isValidLocation(lastTrackPoint)) {
/*
* Should not happen. The current segment should have a location. Just
* insert the current location.
*/
insertLocation(track, location, lastTrackLocation);
insertLocation(track, location, lastTrackPoint);
lastLocation = location;
return;
}
double distanceToLastTrackLocation = location.distanceTo(lastTrackLocation);
double distanceToLastTrackLocation = location.distanceTo(lastTrackPoint);
if (distanceToLastTrackLocation < minRecordingDistance && sensorDataSet == null) {
Log.d(TAG, "Not recording location due to min recording distance.");
} else if (distanceToLastTrackLocation > maxRecordingDistance) {
insertLocation(track, lastLocation, lastTrackLocation);
insertLocation(track, lastLocation, lastTrackPoint);
Location pause = new Location(LocationManager.GPS_PROVIDER);
pause.setLongitude(0);
pause.setLatitude(PAUSE_LATITUDE);
pause.setTime(lastLocation.getTime());
insertLocation(track, pause, null);
insertLocation(track, location, lastTrackLocation);
insertLocation(track, location, lastTrackPoint);
} else {
/*
* (distanceToLastTrackLocation >= minRecordingDistance ||
* hasSensorData) && distanceToLastTrackLocation <= maxRecordingDistance
*/
insertLocation(track, lastLocation, lastTrackLocation);
insertLocation(track, location, lastTrackLocation);
insertLocation(track, lastLocation, lastTrackPoint);
insertLocation(track, location, lastTrackPoint);
}
lastLocation = location;
} catch (Error e) {