mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-03 18:03:06 +02:00
merge heads
This commit is contained in:
+33
-19
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
@@ -154,7 +154,7 @@ public interface MyTracksProviderUtils {
|
||||
/**
|
||||
* Creates a cursor over the locations in the track points provider which
|
||||
* iterates over a given range of unique ids.
|
||||
* Caller gets to own the returned cursor. Don't forget to close it.
|
||||
* Caller owns the returned cursor and is responsible for closing it.
|
||||
*
|
||||
* @param trackId the id of the track for which to get the points
|
||||
* @param minTrackPointId the minimum id for the track points
|
||||
@@ -168,7 +168,7 @@ public interface MyTracksProviderUtils {
|
||||
|
||||
/**
|
||||
* Creates a cursor over the waypoints of a track.
|
||||
* Caller gets to own the returned cursor. Don't forget to close it.
|
||||
* Caller owns the returned cursor and is responsible for closing it.
|
||||
*
|
||||
* @param trackId the id of the track for which to get the points
|
||||
* @param minWaypointId the minimum id for the track points
|
||||
@@ -178,6 +178,18 @@ public interface MyTracksProviderUtils {
|
||||
Cursor getWaypointsCursor(long trackId, long minWaypointId,
|
||||
int maxWaypoints);
|
||||
|
||||
/**
|
||||
* Creates a cursor over waypoints with the given selection.
|
||||
* Caller owns the returned cursor and is responsible for closing it.
|
||||
*
|
||||
* @param selection a given selection
|
||||
* @param selectionArgs arguments for the given selection
|
||||
* @param order the order in which to return results
|
||||
* @param maxWaypoints the maximum number of waypoints to return
|
||||
* @return a cursor of the selected waypoints
|
||||
*/
|
||||
Cursor getWaypointsCursor(String selection, String[] selectionArgs, String order, int maxWaypoints);
|
||||
|
||||
/**
|
||||
* Finds a track by given unique track id.
|
||||
* Note that the returned track object does not have any track points attached.
|
||||
@@ -188,24 +200,26 @@ public interface MyTracksProviderUtils {
|
||||
* @return a Track object, or null if not found
|
||||
*/
|
||||
Track getTrack(long id);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves all tracks without track points. If no tracks exist, an empty
|
||||
* list will be returned. Use {@link #getLocationIterator(long, long, boolean, LocationFactory)}
|
||||
* to load the track points.
|
||||
*
|
||||
*
|
||||
* @return a list of all the recorded tracks
|
||||
*/
|
||||
List<Track> getAllTracks();
|
||||
|
||||
/**
|
||||
* Creates a cursor over the tracks provider with a given selection.
|
||||
* Caller gets to own the returned cursor. Don't forget to close it.
|
||||
* Caller owns the returned cursor and is responsible for closing it.
|
||||
*
|
||||
* @param selection a given selection
|
||||
* @param selectionArgs parameters for the given selection
|
||||
* @param order the order to return results in
|
||||
* @return a cursor of the selected tracks
|
||||
*/
|
||||
Cursor getTracksCursor(String selection);
|
||||
Cursor getTracksCursor(String selection, String[] selectionArgs, String order);
|
||||
|
||||
/**
|
||||
* Inserts a track in the tracks provider.
|
||||
@@ -288,7 +302,7 @@ public interface MyTracksProviderUtils {
|
||||
|
||||
/**
|
||||
* Fill a location object with values from a given cursor.
|
||||
*
|
||||
*
|
||||
* @param cursor a cursor pointing at a db or provider with locations
|
||||
* @param location a location object to be overwritten
|
||||
*/
|
||||
@@ -308,7 +322,7 @@ public interface MyTracksProviderUtils {
|
||||
interface LocationIterator extends Iterator<Location> {
|
||||
/**
|
||||
* Returns ID of the most recently retrieved track point through a call to {@link #next()}.
|
||||
*
|
||||
*
|
||||
* @return the ID of the most recent track point ID.
|
||||
*/
|
||||
long getLocationId();
|
||||
@@ -328,12 +342,12 @@ public interface MyTracksProviderUtils {
|
||||
* Creates a new {@link Location} object to be populated from the underlying database record.
|
||||
* It's up to the implementing class to decide whether to create a new instance or reuse
|
||||
* existing to optimize for speed.
|
||||
*
|
||||
*
|
||||
* @return a {@link Location} to be populated from the database.
|
||||
*/
|
||||
Location createLocation();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The default {@class Location}s factory, which creates a new location of 'gps' type.
|
||||
*/
|
||||
@@ -361,20 +375,20 @@ public interface MyTracksProviderUtils {
|
||||
return locs[lastLoc];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new read-only iterator over all track points for the given track. It provides
|
||||
* a lightweight way of iterating over long tracks without failing due to the underlying cursor
|
||||
* limitations. Since it's a read-only iterator, {@link Iterator#remove()} always throws
|
||||
* {@class UnsupportedOperationException}.
|
||||
*
|
||||
*
|
||||
* Each call to {@link LocationIterator#next()} may advance to the next DB record, and if so,
|
||||
* the iterator calls {@link LocationFactory#createLocation()} and populates it with information
|
||||
* retrieved from the record.
|
||||
*
|
||||
*
|
||||
* When done with iteration, you must call {@link LocationIterator#close()} to make sure that all
|
||||
* resources are properly deallocated.
|
||||
*
|
||||
*
|
||||
* Example use:
|
||||
* <code>
|
||||
* ...
|
||||
@@ -389,14 +403,14 @@ public interface MyTracksProviderUtils {
|
||||
* }
|
||||
* ...
|
||||
* </code>
|
||||
*
|
||||
*
|
||||
* @param trackId the ID of a track to retrieve locations for.
|
||||
* @param startTrackPointId the ID of the first track point to load, or -1 to start from
|
||||
* the first point.
|
||||
* @param descending if true the results will be returned in descending ID
|
||||
* order (latest location first).
|
||||
* @param locationFactory the factory for creating new locations.
|
||||
*
|
||||
*
|
||||
* @return the read-only iterator over the given track's points.
|
||||
*/
|
||||
LocationIterator getLocationIterator(long trackId, long startTrackPointId, boolean descending,
|
||||
|
||||
+25
-14
@@ -16,7 +16,7 @@
|
||||
package com.google.android.apps.mytracks.content;
|
||||
|
||||
import static com.google.android.apps.mytracks.lib.MyTracksLibConstants.TAG;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
@@ -875,22 +875,34 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
}
|
||||
|
||||
String selection;
|
||||
String[] selectionArgs;
|
||||
if (minWaypointId > 0) {
|
||||
selection = String.format("%s=%d AND %s>=%d",
|
||||
WaypointsColumns.TRACKID, trackId,
|
||||
WaypointsColumns._ID, minWaypointId);
|
||||
selection = String.format("%s = ? AND %s >= ?",
|
||||
WaypointsColumns.TRACKID,
|
||||
WaypointsColumns._ID);
|
||||
selectionArgs = new String[] {
|
||||
Long.toString(trackId),
|
||||
Long.toString(minWaypointId)
|
||||
};
|
||||
} else {
|
||||
selection = String.format("%s=%d",
|
||||
WaypointsColumns.TRACKID, trackId);
|
||||
selection = String.format("%s=?", WaypointsColumns.TRACKID);
|
||||
selectionArgs = new String[] { Long.toString(trackId) };
|
||||
}
|
||||
|
||||
String sortOrder = "_id ASC";
|
||||
return getWaypointsCursor(selection, selectionArgs, null, maxWaypoints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor getWaypointsCursor(String selection, String[] selectionArgs, String order, int maxWaypoints) {
|
||||
if (order == null) {
|
||||
order = "_id ASC";
|
||||
}
|
||||
if (maxWaypoints > 0) {
|
||||
sortOrder += " LIMIT " + maxWaypoints;
|
||||
order += " LIMIT " + maxWaypoints;
|
||||
}
|
||||
|
||||
return contentResolver.query(
|
||||
WaypointsColumns.CONTENT_URI, null, selection, null, sortOrder);
|
||||
WaypointsColumns.CONTENT_URI, null, selection, selectionArgs, order);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -905,7 +917,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
|
||||
@Override
|
||||
public List<Track> getAllTracks() {
|
||||
Cursor cursor = getTracksCursor(null);
|
||||
Cursor cursor = getTracksCursor(null, null, TracksColumns._ID);
|
||||
ArrayList<Track> tracks = new ArrayList<Track>();
|
||||
if (cursor != null) {
|
||||
tracks.ensureCapacity(cursor.getCount());
|
||||
@@ -923,10 +935,9 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor getTracksCursor(String selection) {
|
||||
Cursor cursor = contentResolver.query(
|
||||
TracksColumns.CONTENT_URI, null, selection, null, "_id");
|
||||
return cursor;
|
||||
public Cursor getTracksCursor(String selection, String[] selectionArgs, String order) {
|
||||
return contentResolver.query(
|
||||
TracksColumns.CONTENT_URI, null, selection, selectionArgs, order);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010 Google Inc.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
@@ -26,19 +26,19 @@ import android.os.Parcelable;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class TripStatistics implements Parcelable {
|
||||
public class TripStatistics implements Parcelable {
|
||||
|
||||
/**
|
||||
* The start time for the trip. This is system time which might not match gps
|
||||
* time.
|
||||
*/
|
||||
private long startTime = -1;
|
||||
private long startTime = -1L;
|
||||
|
||||
/**
|
||||
* The stop time for the trip. This is the system time which might not match
|
||||
* gps time.
|
||||
*/
|
||||
private long stopTime = -1;
|
||||
private long stopTime = -1L;
|
||||
|
||||
/**
|
||||
* The total time that we believe the user was traveling in milliseconds.
|
||||
@@ -144,7 +144,7 @@ public class TripStatistics implements Parcelable {
|
||||
|
||||
/**
|
||||
* Gets the time that this track started.
|
||||
*
|
||||
*
|
||||
* @return The number of milliseconds since epoch to the time when this track
|
||||
* started
|
||||
*/
|
||||
@@ -154,7 +154,7 @@ public class TripStatistics implements Parcelable {
|
||||
|
||||
/**
|
||||
* Gets the time that this track stopped.
|
||||
*
|
||||
*
|
||||
* @return The number of milliseconds since epoch to the time when this track
|
||||
* stopped
|
||||
*/
|
||||
@@ -176,7 +176,7 @@ public class TripStatistics implements Parcelable {
|
||||
|
||||
/**
|
||||
* Gets the total distance the user traveled.
|
||||
*
|
||||
*
|
||||
* @return The total distance traveled in meters
|
||||
*/
|
||||
public double getTotalDistance() {
|
||||
@@ -191,22 +191,28 @@ public class TripStatistics implements Parcelable {
|
||||
* @return The average speed in m/s
|
||||
*/
|
||||
public double getAverageSpeed() {
|
||||
return totalDistance / ((double) totalTime / 1000);
|
||||
if (totalTime == 0L) {
|
||||
return 0.0;
|
||||
}
|
||||
return totalDistance / ((double) totalTime / 1000.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the the average speed the user traveled when they were actively
|
||||
* moving.
|
||||
*
|
||||
*
|
||||
* @return The average moving speed in m/s
|
||||
*/
|
||||
public double getAverageMovingSpeed() {
|
||||
return totalDistance / ((double) movingTime / 1000);
|
||||
if (movingTime == 0L) {
|
||||
return 0.0;
|
||||
}
|
||||
return totalDistance / ((double) movingTime / 1000.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the the maximum speed for this track.
|
||||
*
|
||||
*
|
||||
* @return The maximum speed in m/s
|
||||
*/
|
||||
public double getMaxSpeed() {
|
||||
@@ -215,7 +221,7 @@ public class TripStatistics implements Parcelable {
|
||||
|
||||
/**
|
||||
* Gets the moving time.
|
||||
*
|
||||
*
|
||||
* @return The total number of milliseconds the user was moving
|
||||
*/
|
||||
public long getMovingTime() {
|
||||
@@ -225,7 +231,7 @@ public class TripStatistics implements Parcelable {
|
||||
/**
|
||||
* Gets the total elevation gain for this trip. This is calculated as the sum
|
||||
* of all positive differences in the smoothed elevation.
|
||||
*
|
||||
*
|
||||
* @return The elevation gain in meters for this trip
|
||||
*/
|
||||
public double getTotalElevationGain() {
|
||||
@@ -233,39 +239,79 @@ public class TripStatistics implements Parcelable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the leftmost position (lowest longitude) of the track, in signed
|
||||
* decimal degrees.
|
||||
* Returns the leftmost position (lowest longitude) of the track, in signed degrees.
|
||||
*/
|
||||
public double getLeftDegrees() {
|
||||
return longitudeExtremities.getMin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the leftmost position (lowest longitude) of the track, in signed millions of degrees.
|
||||
*/
|
||||
public int getLeft() {
|
||||
return (int) (longitudeExtremities.getMin() * 1E6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rightmost position (highest longitude) of the track, in signed
|
||||
* decimal degrees.
|
||||
* Returns the rightmost position (highest longitude) of the track, in signed degrees.
|
||||
*/
|
||||
public double getRightDegrees() {
|
||||
return longitudeExtremities.getMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rightmost position (highest longitude) of the track, in signed millions of degrees.
|
||||
*/
|
||||
public int getRight() {
|
||||
return (int) (longitudeExtremities.getMax() * 1E6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bottommost position (lowest latitude) of the track, in meters.
|
||||
* Returns the bottommost position (lowest latitude) of the track, in signed degrees.
|
||||
*/
|
||||
public double getBottomDegrees() {
|
||||
return latitudeExtremities.getMin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bottommost position (lowest latitude) of the track, in signed millions of degrees.
|
||||
*/
|
||||
public int getBottom() {
|
||||
return (int) (latitudeExtremities.getMin() * 1E6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the topmost position (highest latitude) of the track, in meters.
|
||||
* Returns the topmost position (highest latitude) of the track, in signed degrees.
|
||||
*/
|
||||
public double getTopDegrees() {
|
||||
return latitudeExtremities.getMax();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the topmost position (highest latitude) of the track, in signed millions of degrees.
|
||||
*/
|
||||
public int getTop() {
|
||||
return (int) (latitudeExtremities.getMax() * 1E6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mean position (center latitude) of the track, in signed degrees.
|
||||
*/
|
||||
public double getMeanLatitude() {
|
||||
return (getBottomDegrees() + getTopDegrees()) / 2.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mean position (center longitude) of the track, in signed degrees.
|
||||
*/
|
||||
public double getMeanLongitude() {
|
||||
return (getLeftDegrees() + getRightDegrees()) / 2.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the minimum elevation seen on this trip. This is calculated from the
|
||||
* smoothed elevation so this can actually be more than the current elevation.
|
||||
*
|
||||
*
|
||||
* @return The smallest elevation reading for this trip in meters
|
||||
*/
|
||||
public double getMinElevation() {
|
||||
@@ -275,7 +321,7 @@ public class TripStatistics implements Parcelable {
|
||||
/**
|
||||
* Gets the maximum elevation seen on this trip. This is calculated from the
|
||||
* smoothed elevation so this can actually be less than the current elevation.
|
||||
*
|
||||
*
|
||||
* @return The largest elevation reading for this trip in meters
|
||||
*/
|
||||
public double getMaxElevation() {
|
||||
@@ -284,7 +330,7 @@ public class TripStatistics implements Parcelable {
|
||||
|
||||
/**
|
||||
* Gets the maximum grade for this trip.
|
||||
*
|
||||
*
|
||||
* @return The maximum grade for this trip as a fraction
|
||||
*/
|
||||
public double getMaxGrade() {
|
||||
@@ -293,7 +339,7 @@ public class TripStatistics implements Parcelable {
|
||||
|
||||
/**
|
||||
* Gets the minimum grade for this trip.
|
||||
*
|
||||
*
|
||||
* @return The minimum grade for this trip as a fraction
|
||||
*/
|
||||
public double getMinGrade() {
|
||||
@@ -443,7 +489,7 @@ public class TripStatistics implements Parcelable {
|
||||
void addMovingTime(long time) {
|
||||
movingTime += time;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Accounts for a new latitude value for the bounding box.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user