Add a category icon in Track.java and TracksColumns.java.

Clean up Track.java and TracksColumns.java.
This commit is contained in:
Jimmy Shih
2012-06-13 12:49:28 -07:00
parent 4bdf8ab3bd
commit b4fee2de94
30 changed files with 190 additions and 175 deletions
@@ -49,9 +49,9 @@ public class AggregatedStatsActivity extends AbstractMyTracksActivity {
List<Track> tracks = MyTracksProviderUtils.Factory.get(this).getAllTracks(); List<Track> tracks = MyTracksProviderUtils.Factory.get(this).getAllTracks();
TripStatistics tripStatistics = null; TripStatistics tripStatistics = null;
if (!tracks.isEmpty()) { if (!tracks.isEmpty()) {
tripStatistics = new TripStatistics(tracks.iterator().next().getStatistics()); tripStatistics = new TripStatistics(tracks.iterator().next().getTripStatistics());
for (int i = 1; i < tracks.size(); i++) { for (int i = 1; i < tracks.size(); i++) {
tripStatistics.merge(tracks.get(i).getStatistics()); tripStatistics.merge(tracks.get(i).getTripStatistics());
} }
} }
return tripStatistics; return tripStatistics;
@@ -419,7 +419,7 @@ public class SearchListActivity extends AbstractMyTracksActivity implements Dele
*/ */
private void prepareTrackForDisplay(Track track, Map<String, Object> resultMap) { private void prepareTrackForDisplay(Track track, Map<String, Object> resultMap) {
boolean isRecording = track.getId() == recordingTrackId; boolean isRecording = track.getId() == recordingTrackId;
TripStatistics tripStatitics = track.getStatistics(); TripStatistics tripStatitics = track.getTripStatistics();
resultMap.put(NAME_FIELD, track.getName()); resultMap.put(NAME_FIELD, track.getName());
resultMap.put(ICON_FIELD, isRecording ? R.drawable.menu_record_track : R.drawable.track); resultMap.put(ICON_FIELD, isRecording ? R.drawable.menu_record_track : R.drawable.track);
resultMap.put(ICON_CONTENT_DESCRIPTION_FIELD, getString(isRecording ? R.string.icon_recording resultMap.put(ICON_CONTENT_DESCRIPTION_FIELD, getString(isRecording ? R.string.icon_recording
@@ -64,7 +64,7 @@ public class DescriptionGeneratorImpl implements DescriptionGenerator {
writeString(track.getName(), builder, R.string.generic_name_line, lineBreak); writeString(track.getName(), builder, R.string.generic_name_line, lineBreak);
writeString(track.getCategory(), builder, R.string.description_activity_type, lineBreak); writeString(track.getCategory(), builder, R.string.description_activity_type, lineBreak);
writeString(track.getDescription(), builder, R.string.generic_description_line, lineBreak); writeString(track.getDescription(), builder, R.string.generic_description_line, lineBreak);
builder.append(generateTripStatisticsDescription(track.getStatistics(), html)); builder.append(generateTripStatisticsDescription(track.getTripStatistics(), html));
// Elevation chart // Elevation chart
if (html && distances != null && elevations != null) { if (html && distances != null && elevations != null) {
@@ -261,7 +261,7 @@ public class SearchEngine {
score *= getTitleBoost(query, track.getName(), track.getDescription(), track.getCategory()); score *= getTitleBoost(query, track.getName(), track.getDescription(), track.getCategory());
TripStatistics statistics = track.getStatistics(); TripStatistics statistics = track.getTripStatistics();
// TODO: Also boost for proximity to the currently-centered position on the map. // TODO: Also boost for proximity to the currently-centered position on the map.
score *= getDistanceBoost(query, statistics.getMeanLatitude(), statistics.getMeanLongitude()); score *= getDistanceBoost(query, statistics.getMeanLatitude(), statistics.getMeanLongitude());
@@ -185,11 +185,11 @@ public class ChartFragment extends Fragment implements TrackDataListener {
@Override @Override
public void onTrackUpdated(Track track) { public void onTrackUpdated(Track track) {
if (track == null || track.getStatistics() == null) { if (track == null || track.getTripStatistics() == null) {
trackMaxSpeed = 0.0; trackMaxSpeed = 0.0;
return; return;
} }
trackMaxSpeed = track.getStatistics().getMaxSpeed(); trackMaxSpeed = track.getTripStatistics().getMaxSpeed();
} }
@Override @Override
@@ -522,7 +522,7 @@ public class MapFragment extends Fragment
return; return;
} }
TripStatistics tripStatistics = track.getStatistics(); TripStatistics tripStatistics = track.getTripStatistics();
int bottom = tripStatistics.getBottom(); int bottom = tripStatistics.getBottom();
int left = tripStatistics.getLeft(); int left = tripStatistics.getLeft();
int latitudeSpanE6 = tripStatistics.getTop() - bottom; int latitudeSpanE6 = tripStatistics.getTop() - bottom;
@@ -163,15 +163,15 @@ 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.getStatistics() == null) { if (track == null || track.getTripStatistics() == null) {
lastLocation = null; lastLocation = null;
lastTripStatistics = null; lastTripStatistics = null;
updateUi(); updateUi();
return; return;
} }
lastTripStatistics = track.getStatistics(); lastTripStatistics = track.getTripStatistics();
startTime = track.getStatistics().getStartTime(); startTime = track.getTripStatistics().getStartTime();
if (!isRecording()) { if (!isRecording()) {
lastLocation = null; lastLocation = null;
} }
@@ -284,7 +284,7 @@ public class SendDocsUtils {
*/ */
@VisibleForTesting @VisibleForTesting
static String getRowContent(Track track, boolean metricUnits, Context context) { static String getRowContent(Track track, boolean metricUnits, Context context) {
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getTripStatistics();
String distanceUnit = context.getString( String distanceUnit = context.getString(
metricUnits ? R.string.unit_kilometer : R.string.unit_mile); metricUnits ? R.string.unit_kilometer : R.string.unit_mile);
@@ -422,7 +422,7 @@ public class GpxImporter extends DefaultHandler {
statsBuilder.pauseAt(lastLocation.getTime()); statsBuilder.pauseAt(lastLocation.getTime());
track.setStopId(getLastPointId()); track.setStopId(getLastPointId());
track.setNumberOfPoints(numberOfLocations); track.setNumberOfPoints(numberOfLocations);
track.setStatistics(statsBuilder.getStatistics()); track.setTripStatistics(statsBuilder.getStatistics());
providerUtils.updateTrack(track); providerUtils.updateTrack(track);
tracksWritten.add(track.getId()); tracksWritten.add(track.getId());
isCurrentTrackRollbackable = false; isCurrentTrackRollbackable = false;
@@ -147,15 +147,16 @@ public class TcxTrackWriter implements TrackFormatWriter {
@Override @Override
public void writeBeginTrack(Location firstPoint) { public void writeBeginTrack(Location firstPoint) {
if (printWriter != null) { if (printWriter != null) {
String startTime = StringUtils.formatDateTimeIso8601(track.getStatistics().getStartTime()); String startTime = StringUtils.formatDateTimeIso8601(
long totalTimeInSeconds = track.getStatistics().getTotalTime() / 1000; track.getTripStatistics().getStartTime());
long totalTimeInSeconds = track.getTripStatistics().getTotalTime() / 1000;
printWriter.println("<Activities>"); printWriter.println("<Activities>");
printWriter.println("<Activity Sport=\"" + sportType.getName() + "\">"); printWriter.println("<Activity Sport=\"" + sportType.getName() + "\">");
printWriter.println("<Id>" + startTime + "</Id>"); printWriter.println("<Id>" + startTime + "</Id>");
printWriter.println("<Lap StartTime=\"" + startTime + "\">"); printWriter.println("<Lap StartTime=\"" + startTime + "\">");
printWriter.println("<TotalTimeSeconds>" + totalTimeInSeconds + "</TotalTimeSeconds>"); printWriter.println("<TotalTimeSeconds>" + totalTimeInSeconds + "</TotalTimeSeconds>");
printWriter.println("<DistanceMeters>" + track.getStatistics().getTotalDistance() printWriter.println("<DistanceMeters>" + track.getTripStatistics().getTotalDistance()
+ "</DistanceMeters>"); + "</DistanceMeters>");
// <Calories> is required, just put in 0. // <Calories> is required, just put in 0.
printWriter.println("<Calories>0</Calories>"); printWriter.println("<Calories>0</Calories>");
@@ -221,7 +221,7 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
// 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) (locationsCount / 250.0));
TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder( TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder(
track.getStatistics().getStartTime()); track.getTripStatistics().getStartTime());
DoubleBuffer elevationBuffer = new DoubleBuffer(Constants.ELEVATION_SMOOTHING_FACTOR); DoubleBuffer elevationBuffer = new DoubleBuffer(Constants.ELEVATION_SMOOTHING_FACTOR);
Vector<Double> distances = new Vector<Double>(); Vector<Double> distances = new Vector<Double>();
Vector<Double> elevations = new Vector<Double>(); Vector<Double> elevations = new Vector<Double>();
@@ -52,14 +52,14 @@ public class SendFusionTablesUtils {
* @return the url. * @return the url.
*/ */
public static String getMapUrl(Track track) { public static String getMapUrl(Track track) {
if (track == null || track.getStatistics() == null || track.getTableId() == null) { if (track == null || track.getTripStatistics() == null || track.getTableId() == null) {
Log.e(TAG, "Invalid track"); Log.e(TAG, "Invalid track");
return null; return null;
} }
// TODO(jshih): Determine the correct bounding box and zoom level that // TODO(jshih): Determine the correct bounding box and zoom level that
// will show the entire track. // will show the entire track.
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getTripStatistics();
double latE6 = stats.getBottom() + (stats.getTop() - stats.getBottom()) / 2; double latE6 = stats.getBottom() + (stats.getTop() - stats.getBottom()) / 2;
double lonE6 = stats.getLeft() + (stats.getRight() - stats.getLeft()) / 2; double lonE6 = stats.getLeft() + (stats.getRight() - stats.getLeft()) / 2;
int z = 15; int z = 15;
@@ -270,7 +270,7 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
// 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) (locationsCount / 250.0));
TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder( TripStatisticsBuilder tripStatisticsBuilder = new TripStatisticsBuilder(
track.getStatistics().getStartTime()); track.getTripStatistics().getStartTime());
DoubleBuffer elevationBuffer = new DoubleBuffer(Constants.ELEVATION_SMOOTHING_FACTOR); DoubleBuffer elevationBuffer = new DoubleBuffer(Constants.ELEVATION_SMOOTHING_FACTOR);
Vector<Double> distances = new Vector<Double>(); Vector<Double> distances = new Vector<Double>();
Vector<Double> elevations = new Vector<Double>(); Vector<Double> elevations = new Vector<Double>();
@@ -56,8 +56,8 @@ public class SendToGoogleUtils {
segment.setDescription(""); segment.setDescription("");
segment.setCategory(track.getCategory()); segment.setCategory(track.getCategory());
TripStatistics segmentStats = segment.getStatistics(); TripStatistics segmentStats = segment.getTripStatistics();
TripStatistics trackStats = track.getStatistics(); TripStatistics trackStats = track.getTripStatistics();
segmentStats.setStartTime(trackStats.getStartTime()); segmentStats.setStartTime(trackStats.getStartTime());
segmentStats.setStopTime(trackStats.getStopTime()); segmentStats.setStopTime(trackStats.getStopTime());
boolean startNewTrackSegment = false; boolean startNewTrackSegment = false;
@@ -78,7 +78,7 @@ public class SendToGoogleUtils {
segment.setName(track.getName()); segment.setName(track.getName());
segment.setDescription(""); segment.setDescription("");
segment.setCategory(track.getCategory()); segment.setCategory(track.getCategory());
segmentStats = segment.getStatistics(); segmentStats = segment.getTripStatistics();
} }
if (loc.getLatitude() <= 90) { if (loc.getLatitude() <= 90) {
@@ -119,7 +119,7 @@ public class SendToGoogleUtils {
} }
// For a new segment, sets it stop time // For a new segment, sets it stop time
TripStatistics segmentStats = segment.getStatistics(); TripStatistics segmentStats = segment.getTripStatistics();
if (segmentStats.getStopTime() < 0) { if (segmentStats.getStopTime() < 0) {
Location lastLocation = segment.getLocations().get(segment.getLocations().size() - 1); Location lastLocation = segment.getLocations().get(segment.getLocations().size() - 1);
segmentStats.setStopTime(lastLocation.getTime()); segmentStats.setStopTime(lastLocation.getTime());
@@ -97,7 +97,7 @@ public class DynamicSpeedTrackPathDescriptor implements TrackPathDescriptor,
Log.d(TAG, "No track for " + selectedTrackId); Log.d(TAG, "No track for " + selectedTrackId);
return false; return false;
} }
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getTripStatistics();
double newAverageMovingSpeed = (int) Math.floor( double newAverageMovingSpeed = (int) Math.floor(
stats.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH); stats.getAverageMovingSpeed() * UnitConversions.MS_TO_KMH);
@@ -420,7 +420,7 @@ public class TrackRecordingService extends Service {
// Check if the last modified time is within the acceptable range. // Check if the last modified time is within the acceptable range.
long lastModified = long lastModified =
track.getStatistics() != null ? track.getStatistics().getStopTime() : 0; track.getTripStatistics() != null ? track.getTripStatistics().getStopTime() : 0;
Log.d(TAG, Log.d(TAG,
"shouldResumeTrack: lastModified = " + lastModified "shouldResumeTrack: lastModified = " + lastModified
+ ", autoResumeTrackTimeout: " + autoResumeTrackTimeout); + ", autoResumeTrackTimeout: " + autoResumeTrackTimeout);
@@ -579,7 +579,7 @@ public class TrackRecordingService extends Service {
acquireWakeLock(); acquireWakeLock();
Track track = new Track(); Track track = new Track();
TripStatistics trackStats = track.getStatistics(); TripStatistics trackStats = track.getTripStatistics();
trackStats.setStartTime(startTime); trackStats.setStartTime(startTime);
track.setStartId(-1); track.setStartId(-1);
Uri trackUri = providerUtils.insertTrack(track); Uri trackUri = providerUtils.insertTrack(track);
@@ -620,7 +620,7 @@ public class TrackRecordingService extends Service {
Log.d(TAG, Log.d(TAG,
"Restoring stats of track with ID: " + track.getId()); "Restoring stats of track with ID: " + track.getId());
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getTripStatistics();
statsBuilder = new TripStatisticsBuilder(stats.getStartTime()); statsBuilder = new TripStatisticsBuilder(stats.getStartTime());
statsBuilder.setMinRecordingDistance(minRecordingDistance); statsBuilder.setMinRecordingDistance(minRecordingDistance);
@@ -1031,7 +1031,7 @@ public class TrackRecordingService extends Service {
isRecording = false; isRecording = false;
Track recordedTrack = providerUtils.getTrack(recordingTrackId); Track recordedTrack = providerUtils.getTrack(recordingTrackId);
if (recordedTrack != null) { if (recordedTrack != null) {
TripStatistics stats = recordedTrack.getStatistics(); TripStatistics stats = recordedTrack.getTripStatistics();
stats.setStopTime(System.currentTimeMillis()); stats.setStopTime(System.currentTimeMillis());
stats.setTotalTime(stats.getStopTime() - stats.getStartTime()); stats.setTotalTime(stats.getStopTime() - stats.getStartTime());
long lastRecordedLocationId = long lastRecordedLocationId =
@@ -75,7 +75,7 @@ public class ChartURLGenerator {
} }
// Round it up. // Round it up.
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getTripStatistics();
double effectiveMaxY = metricUnits double effectiveMaxY = metricUnits
? stats.getMaxElevation() ? stats.getMaxElevation()
: stats.getMaxElevation() * UnitConversions.M_TO_FT; : stats.getMaxElevation() * UnitConversions.M_TO_FT;
@@ -155,7 +155,7 @@ public class ChartURLGenerator {
} }
private static double getNormalizedDistance(double d, Track track) { private static double getNormalizedDistance(double d, Track track) {
return d / track.getStatistics().getTotalDistance(); return d / track.getTripStatistics().getTotalDistance();
} }
private static double getNormalizedElevation( private static double getNormalizedElevation(
@@ -18,7 +18,6 @@ package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.Constants; import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.maps.GeoPoint; import com.google.android.maps.GeoPoint;
import android.location.Location; import android.location.Location;
@@ -181,7 +180,7 @@ public class LocationUtils {
Track piece = null; Track piece = null;
do { do {
piece = new Track(); piece = new Track();
TripStatistics pieceStats = piece.getStatistics(); TripStatistics pieceStats = piece.getTripStatistics();
piece.setId(track.getId()); piece.setId(track.getId());
piece.setName(track.getName()); piece.setName(track.getName());
piece.setDescription(track.getDescription()); piece.setDescription(track.getDescription());
@@ -216,7 +216,7 @@ public class TrackWidgetProvider extends AppWidgetProvider
private void updateStatistics(RemoteViews remoteViews) { private void updateStatistics(RemoteViews remoteViews) {
Track track = selectedTrackId != PreferencesUtils.SELECTED_TRACK_ID_DEFAULT Track track = selectedTrackId != PreferencesUtils.SELECTED_TRACK_ID_DEFAULT
? myTracksProviderUtils.getTrack(selectedTrackId) : myTracksProviderUtils.getLastTrack(); ? myTracksProviderUtils.getTrack(selectedTrackId) : myTracksProviderUtils.getLastTrack();
TripStatistics tripStatistics = track == null ? null : track.getStatistics(); TripStatistics tripStatistics = track == null ? null : track.getTripStatistics();
String distance = tripStatistics == null ? unknown String distance = tripStatistics == null ? unknown
: StringUtils.formatDistance(context, tripStatistics.getTotalDistance(), metricUnits); : StringUtils.formatDistance(context, tripStatistics.getTotalDistance(), metricUnits);
int timeLabelId = useTotalTime ? R.string.stats_total_time : R.string.stats_moving_time; int timeLabelId = useTotalTime ? R.string.stats_total_time : R.string.stats_moving_time;
@@ -92,7 +92,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
@Override @Override
public ContentValues createContentValues(Track track) { public ContentValues createContentValues(Track track) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getTripStatistics();
// Values id < 0 indicate no id is available: // Values id < 0 indicate no id is available:
if (track.getId() >= 0) { if (track.getId() >= 0) {
@@ -297,7 +297,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
int idxMaxGrade = cursor.getColumnIndexOrThrow(TracksColumns.MAXGRADE); int idxMaxGrade = cursor.getColumnIndexOrThrow(TracksColumns.MAXGRADE);
Track track = new Track(); Track track = new Track();
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getTripStatistics();
if (!cursor.isNull(idxId)) { if (!cursor.isNull(idxId)) {
track.setId(cursor.getLong(idxId)); track.setId(cursor.getLong(idxId));
} }
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations under * License for the specific language governing permissions and limitations under
* the License. * the License.
*/ */
package com.google.android.apps.mytracks.content; package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatistics;
@@ -24,98 +25,89 @@ import android.os.Parcelable;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* A class representing a (GPS) Track. * A track.
* *
* TODO: hashCode and equals
*
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
* @author Rodrigo Damazio * @author Rodrigo Damazio
*/ */
public class Track implements Parcelable { public class Track implements Parcelable {
/**
* Creator for a Track object.
*/
public static class Creator implements Parcelable.Creator<Track> {
public Track createFromParcel(Parcel source) {
ClassLoader classLoader = getClass().getClassLoader();
Track track = new Track();
track.id = source.readLong();
track.name = source.readString();
track.description = source.readString();
track.mapId = source.readString();
track.category = source.readString();
track.startId = source.readLong();
track.stopId = source.readLong();
track.stats = source.readParcelable(classLoader);
track.numberOfPoints = source.readInt();
for (int i = 0; i < track.numberOfPoints; ++i) {
Location loc = source.readParcelable(classLoader);
track.locations.add(loc);
}
track.tableId = source.readString();
return track;
}
public Track[] newArray(int size) {
return new Track[size];
}
}
public static final Creator CREATOR = new Creator();
/**
* The track points (which may not have been loaded).
*/
private ArrayList<Location> locations = new ArrayList<Location>();
/**
* The number of location points (present even if the points themselves were
* not loaded).
*/
private int numberOfPoints = 0;
private long id = -1; private long id = -1;
private String name = ""; private String name = "";
private String description = ""; private String description = "";
private String mapId = ""; private String category = "";
private String tableId = ""; private String categoryIcon = "";
private long startId = -1; private long startId = -1;
private long stopId = -1; private long stopId = -1;
private String category = "";
private TripStatistics stats = new TripStatistics(); // The number of location points (present even if the points themselves are
// not loaded)
private int numberOfPoints = 0;
private String mapId = "";
private String tableId = "";
public Track() { private TripStatistics tripStatistics = new TripStatistics();
// Location points (which may not have been loaded)
private ArrayList<Location> locations = new ArrayList<Location>();
public Track() {}
private Track(Parcel in) {
id = in.readLong();
name = in.readString();
description = in.readString();
category = in.readString();
categoryIcon = in.readString();
startId = in.readLong();
stopId = in.readLong();
numberOfPoints = in.readInt();
mapId = in.readString();
tableId = in.readString();
ClassLoader classLoader = getClass().getClassLoader();
for (int i = 0; i < numberOfPoints; ++i) {
Location loc = in.readParcelable(classLoader);
locations.add(loc);
}
tripStatistics = in.readParcelable(classLoader);
} }
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id); dest.writeLong(id);
dest.writeString(name); dest.writeString(name);
dest.writeString(description); dest.writeString(description);
dest.writeString(mapId);
dest.writeString(category); dest.writeString(category);
dest.writeString(categoryIcon);
dest.writeLong(startId); dest.writeLong(startId);
dest.writeLong(stopId); dest.writeLong(stopId);
dest.writeParcelable(stats, 0);
dest.writeInt(numberOfPoints); dest.writeInt(numberOfPoints);
dest.writeString(mapId);
dest.writeString(tableId);
for (int i = 0; i < numberOfPoints; ++i) { for (int i = 0; i < numberOfPoints; ++i) {
dest.writeParcelable(locations.get(i), 0); dest.writeParcelable(locations.get(i), 0);
} }
dest.writeParcelable(tripStatistics, 0);
dest.writeString(tableId);
} }
// Getters and setters: public static final Parcelable.Creator<Track> CREATOR = new Parcelable.Creator<Track>() {
//--------------------- @Override
public Track createFromParcel(Parcel in) {
return new Track(in);
}
public int describeContents() { @Override
return 0; public Track[] newArray(int size) {
} return new Track[size];
}
};
public long getId() { public long getId() {
return id; return id;
@@ -133,6 +125,30 @@ public class Track implements Parcelable {
this.name = name; this.name = name;
} }
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getCategoryIcon() {
return categoryIcon;
}
public void setCategoryIcon(String categoryIcon) {
this.categoryIcon = categoryIcon;
}
public long getStartId() { public long getStartId() {
return startId; return startId;
} }
@@ -149,12 +165,12 @@ public class Track implements Parcelable {
this.stopId = stopId; this.stopId = stopId;
} }
public String getDescription() { public int getNumberOfPoints() {
return description; return numberOfPoints;
} }
public void setDescription(String description) { public void setNumberOfPoints(int numberOfPoints) {
this.description = description; this.numberOfPoints = numberOfPoints;
} }
public String getMapId() { public String getMapId() {
@@ -173,22 +189,6 @@ public class Track implements Parcelable {
this.tableId = tableId; this.tableId = tableId;
} }
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public int getNumberOfPoints() {
return numberOfPoints;
}
public void setNumberOfPoints(int numberOfPoints) {
this.numberOfPoints = numberOfPoints;
}
public void addLocation(Location l) { public void addLocation(Location l) {
locations.add(l); locations.add(l);
} }
@@ -201,11 +201,11 @@ public class Track implements Parcelable {
this.locations = locations; this.locations = locations;
} }
public TripStatistics getStatistics() { public TripStatistics getTripStatistics() {
return stats; return tripStatistics;
} }
public void setStatistics(TripStatistics stats) { public void setTripStatistics(TripStatistics tripStatistics) {
this.stats = stats; this.tripStatistics = tripStatistics;
} }
} }
@@ -13,51 +13,66 @@
* License for the specific language governing permissions and limitations under * License for the specific language governing permissions and limitations under
* the License. * the License.
*/ */
package com.google.android.apps.mytracks.content; package com.google.android.apps.mytracks.content;
import android.net.Uri; import android.net.Uri;
import android.provider.BaseColumns; import android.provider.BaseColumns;
/** /**
* Defines the URI for the tracks provider and the available column names * Constants for track table.
* and content types. *
*
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
*/ */
public interface TracksColumns extends BaseColumns { public interface TracksColumns extends BaseColumns {
public static final Uri CONTENT_URI = /**
Uri.parse("content://com.google.android.maps.mytracks/tracks"); * Tracks provider uri.
public static final String CONTENT_TYPE = */
"vnd.android.cursor.dir/vnd.google.track"; public static final Uri CONTENT_URI = Uri.parse(
public static final String CONTENT_ITEMTYPE = "content://com.google.android.maps.mytracks/tracks");
"vnd.android.cursor.item/vnd.google.track";
/**
* Track content type.
*/
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.track";
/**
* Track id content type.
*/
public static final String CONTENT_ITEMTYPE = "vnd.android.cursor.item/vnd.google.track";
/**
* Tracks table default sort order.
*/
public static final String DEFAULT_SORT_ORDER = "_id"; public static final String DEFAULT_SORT_ORDER = "_id";
/* All columns */ // Tracks table columns
public static final String NAME = "name"; public static final String NAME = "name"; // track name
public static final String DESCRIPTION = "description"; public static final String DESCRIPTION = "description"; // track description
public static final String CATEGORY = "category"; public static final String CATEGORY = "category"; // track activity type
public static final String STARTID = "startid"; public static final String CATEGORY_ICON = "categoryicon"; // track activity type icon
public static final String STOPID = "stopid"; public static final String STARTID = "startid"; // first track point id
public static final String STARTTIME = "starttime"; public static final String STOPID = "stopid"; // last track point id
public static final String STOPTIME = "stoptime"; public static final String STARTTIME = "starttime"; // track start time
public static final String NUMPOINTS = "numpoints"; public static final String STOPTIME = "stoptime"; // track stop time
public static final String TOTALDISTANCE = "totaldistance"; public static final String NUMPOINTS = "numpoints"; // number of track points
public static final String TOTALTIME = "totaltime"; public static final String TOTALDISTANCE = "totaldistance"; // total distance
public static final String MOVINGTIME = "movingtime"; public static final String TOTALTIME = "totaltime"; // total time
public static final String AVGSPEED = "avgspeed"; public static final String MOVINGTIME = "movingtime"; // moving time
public static final String AVGMOVINGSPEED = "avgmovingspeed"; public static final String AVGSPEED = "avgspeed"; // average speed
public static final String MAXSPEED = "maxspeed"; public static final String AVGMOVINGSPEED = "avgmovingspeed"; // average
public static final String MINELEVATION = "minelevation"; // moving speed
public static final String MAXELEVATION = "maxelevation"; public static final String MAXSPEED = "maxspeed"; // maximum speed
public static final String ELEVATIONGAIN = "elevationgain"; public static final String MINELEVATION = "minelevation"; // minimum elevation
public static final String MINGRADE = "mingrade"; public static final String MAXELEVATION = "maxelevation"; // maximum elevation
public static final String MAXGRADE = "maxgrade"; public static final String ELEVATIONGAIN = "elevationgain"; // elevation gain
public static final String MINLAT = "minlat"; public static final String MINGRADE = "mingrade"; // minimum grade
public static final String MAXLAT = "maxlat"; public static final String MAXGRADE = "maxgrade"; // maximum grade
public static final String MINLON = "minlon"; public static final String MINLAT = "minlat"; // minimum latitude
public static final String MAXLON = "maxlon"; public static final String MAXLAT = "maxlat"; // maximum latitude
public static final String MAPID = "mapid"; public static final String MINLON = "minlon"; // minimum longitude
public static final String TABLEID = "tableid"; public static final String MAXLON = "maxlon"; // maximum longitude
public static final String MAPID = "mapid"; // Google Maps id
public static final String TABLEID = "tableid"; // Google Fusion Tables id
} }
@@ -55,7 +55,7 @@ public class DescriptionGeneratorImplTest extends AndroidTestCase {
stats.setMaxGrade(0.42); stats.setMaxGrade(0.42);
stats.setMinGrade(0.11); stats.setMinGrade(0.11);
stats.setStartTime(START_TIME); stats.setStartTime(START_TIME);
track.setStatistics(stats); track.setTripStatistics(stats);
track.setCategory("hiking"); track.setCategory("hiking");
String expected = "Created by" String expected = "Created by"
+ " <a href='http://www.google.com/mobile/mytracks'>My Tracks</a> on Android.<p>" + " <a href='http://www.google.com/mobile/mytracks'>My Tracks</a> on Android.<p>"
@@ -77,7 +77,7 @@ public class SearchEngineTest extends AndroidTestCase {
track.setDescription(description); track.setDescription(description);
track.setCategory(category); track.setCategory(category);
TripStatistics stats = track.getStatistics(); TripStatistics stats = track.getTripStatistics();
if (hoursAgo > 0) { if (hoursAgo > 0) {
// Started twice hoursAgo, so the average time is hoursAgo. // Started twice hoursAgo, so the average time is hoursAgo.
stats.setStartTime(NOW - hoursAgo * 1000L * 60L * 60L * 2); stats.setStartTime(NOW - hoursAgo * 1000L * 60L * 60L * 2);
@@ -180,7 +180,7 @@ public class SendDocsUtilsTest extends AndroidTestCase {
track.setName("trackName"); track.setName("trackName");
track.setDescription("trackDescription"); track.setDescription("trackDescription");
track.setMapId("trackMapId"); track.setMapId("trackMapId");
track.setStatistics(stats); track.setTripStatistics(stats);
return track; return track;
} }
@@ -19,10 +19,9 @@ import static com.google.android.testing.mocking.AndroidMock.eq;
import static com.google.android.testing.mocking.AndroidMock.expect; import static com.google.android.testing.mocking.AndroidMock.expect;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.Factory;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.Factory;
import com.google.android.apps.mytracks.io.file.GpxImporter;
import com.google.android.apps.mytracks.testing.TestingProviderUtilsFactory; import com.google.android.apps.mytracks.testing.TestingProviderUtilsFactory;
import com.google.android.testing.mocking.AndroidMock; import com.google.android.testing.mocking.AndroidMock;
import com.google.android.testing.mocking.UsesMocks; import com.google.android.testing.mocking.UsesMocks;
@@ -171,7 +170,7 @@ public class GpxImporterTest extends AndroidTestCase {
Track track = trackParam.getValue(); Track track = trackParam.getValue();
assertEquals(TRACK_NAME, track.getName()); assertEquals(TRACK_NAME, track.getName());
assertEquals(TRACK_DESC, track.getDescription()); assertEquals(TRACK_DESC, track.getDescription());
assertEquals(DATE_FORMAT2.parse(TRACK_TIME_1).getTime(), track.getStatistics() assertEquals(DATE_FORMAT2.parse(TRACK_TIME_1).getTime(), track.getTripStatistics()
.getStartTime()); .getStartTime());
assertNotSame(-1, track.getStartId()); assertNotSame(-1, track.getStartId());
assertNotSame(-1, track.getStopId()); assertNotSame(-1, track.getStopId());
@@ -47,7 +47,7 @@ public class SendFusionTablesUtilsTest extends TestCase {
Track track = new Track(); Track track = new Track();
TripStatistics stats = new TripStatistics(); TripStatistics stats = new TripStatistics();
stats.setBounds((int) 100.E6, (int) 10.E6, (int) 50.E6, (int) 5.E6); stats.setBounds((int) 100.E6, (int) 10.E6, (int) 50.E6, (int) 5.E6);
track.setStatistics(stats); track.setTripStatistics(stats);
track.setTableId(null); track.setTableId(null);
assertEquals(null, SendFusionTablesUtils.getMapUrl(track)); assertEquals(null, SendFusionTablesUtils.getMapUrl(track));
} }
@@ -57,7 +57,7 @@ public class SendFusionTablesUtilsTest extends TestCase {
*/ */
public void testGetMapUrl_null_stats() { public void testGetMapUrl_null_stats() {
Track track = new Track(); Track track = new Track();
track.setStatistics(null); track.setTripStatistics(null);
track.setTableId("123"); track.setTableId("123");
assertEquals(null, SendFusionTablesUtils.getMapUrl(track)); assertEquals(null, SendFusionTablesUtils.getMapUrl(track));
} }
@@ -69,7 +69,7 @@ public class SendFusionTablesUtilsTest extends TestCase {
Track track = new Track(); Track track = new Track();
TripStatistics stats = new TripStatistics(); TripStatistics stats = new TripStatistics();
stats.setBounds((int) 100.E6, (int) 10.E6, (int) 50.E6, (int) 5.E6); stats.setBounds((int) 100.E6, (int) 10.E6, (int) 50.E6, (int) 5.E6);
track.setStatistics(stats); track.setTripStatistics(stats);
track.setTableId("123"); track.setTableId("123");
assertEquals( assertEquals(
"https://www.google.com/fusiontables/embedviz?" "https://www.google.com/fusiontables/embedviz?"
@@ -56,13 +56,14 @@ public class SendToGoogleUtilsTest extends TestCase {
*/ */
public void testPrepareTrackSegment_noStopTime() { public void testPrepareTrackSegment_noStopTime() {
Track trackStub = TrackStubUtils.createTrack(2); Track trackStub = TrackStubUtils.createTrack(2);
assertEquals(-1L, trackStub.getStatistics().getStopTime()); assertEquals(-1L, trackStub.getTripStatistics().getStopTime());
ArrayList<Track> tracksArray = new ArrayList<Track>(); ArrayList<Track> tracksArray = new ArrayList<Track>();
assertTrue(SendToGoogleUtils.prepareTrackSegment(trackStub, tracksArray)); assertTrue(SendToGoogleUtils.prepareTrackSegment(trackStub, tracksArray));
assertEquals(trackStub, tracksArray.get(0)); assertEquals(trackStub, tracksArray.get(0));
// The stop time should be the time of last location // The stop time should be the time of last location
assertEquals(trackStub.getLocations().get(1).getTime(), trackStub.getStatistics().getStopTime()); assertEquals(
trackStub.getLocations().get(1).getTime(), trackStub.getTripStatistics().getStopTime());
} }
/** /**
@@ -75,12 +76,12 @@ public class SendToGoogleUtilsTest extends TestCase {
// Gives a margin to make sure the this time will be not same with the last // Gives a margin to make sure the this time will be not same with the last
// location in the track. // location in the track.
long stopTime = System.currentTimeMillis() + 1000; long stopTime = System.currentTimeMillis() + 1000;
trackStub.getStatistics().setStopTime(stopTime); trackStub.getTripStatistics().setStopTime(stopTime);
ArrayList<Track> tracksArray = new ArrayList<Track>(); ArrayList<Track> tracksArray = new ArrayList<Track>();
SendToGoogleUtils.prepareTrackSegment(trackStub, tracksArray); SendToGoogleUtils.prepareTrackSegment(trackStub, tracksArray);
assertEquals(trackStub, tracksArray.get(0)); assertEquals(trackStub, tracksArray.get(0));
assertEquals(stopTime, trackStub.getStatistics().getStopTime()); assertEquals(stopTime, trackStub.getTripStatistics().getStopTime());
} }
/** /**
@@ -676,7 +676,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
dummyTrack.setName("Dummy Track"); dummyTrack.setName("Dummy Track");
TripStatistics tripStatistics = new TripStatistics(); TripStatistics tripStatistics = new TripStatistics();
tripStatistics.setStopTime(stopTime); tripStatistics.setStopTime(stopTime);
dummyTrack.setStatistics(tripStatistics); dummyTrack.setTripStatistics(tripStatistics);
addTrack(dummyTrack, isRecording); addTrack(dummyTrack, isRecording);
return dummyTrack; return dummyTrack;
} }
@@ -740,7 +740,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
track = providerUtils.getTrack(id); track = providerUtils.getTrack(id);
assertNotNull(track); assertNotNull(track);
assertEquals(id, track.getId()); assertEquals(id, track.getId());
TripStatistics tripStatistics = track.getStatistics(); TripStatistics tripStatistics = track.getTripStatistics();
assertNotNull(tripStatistics); assertNotNull(tripStatistics);
assertTrue(tripStatistics.getStartTime() > 0); assertTrue(tripStatistics.getStartTime() > 0);
assertTrue(tripStatistics.getStopTime() >= tripStatistics.getStartTime()); assertTrue(tripStatistics.getStopTime() >= tripStatistics.getStartTime());
@@ -33,7 +33,7 @@ public class ChartURLGeneratorTest extends TestCase {
Vector<Double> distances = new Vector<Double>(); Vector<Double> distances = new Vector<Double>();
Vector<Double> elevations = new Vector<Double>(); Vector<Double> elevations = new Vector<Double>();
Track t = new Track(); Track t = new Track();
TripStatistics stats = t.getStatistics(); TripStatistics stats = t.getTripStatistics();
stats.setMinElevation(0); stats.setMinElevation(0);
stats.setMaxElevation(2000); stats.setMaxElevation(2000);
stats.setTotalDistance(100); stats.setTotalDistance(100);