Add test cases about TripStatisticsUpdater.addLocation().

This commit is contained in:
youtaol
2013-02-27 18:29:30 +08:00
commit dbfbfb1b1f
910 changed files with 72953 additions and 0 deletions
@@ -0,0 +1,35 @@
/*
* 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
/**
* Utilities for serializing primitive types.
*
* @author Rodrigo Damazio
*/
public class ContentTypeIds {
private ContentTypeIds() {}
public static final byte BOOLEAN_TYPE_ID = 0;
public static final byte LONG_TYPE_ID = 1;
public static final byte INT_TYPE_ID = 2;
public static final byte FLOAT_TYPE_ID = 3;
public static final byte DOUBLE_TYPE_ID = 4;
public static final byte STRING_TYPE_ID = 5;
public static final byte BLOB_TYPE_ID = 6;
}
@@ -0,0 +1,47 @@
/*
* 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.stats.TripStatistics;
import java.util.Vector;
/**
* An interface for an object that can generate descriptions of track and
* waypoint.
*
* @author Sandor Dornbush
*/
public interface DescriptionGenerator {
/**
* Generates a track description.
*
* @param track the track
* @param distances a vector of distances to generate the elevation chart
* @param elevations a vector of elevations to generate the elevation chart
* @param html true to output html, false to output plain text
*/
public String generateTrackDescription(
Track track, Vector<Double> distances, Vector<Double> elevations, boolean html);
/**
* Generate a waypoint description from a trip statistics.
*
* @param tripStatistics the trip statistics
*/
public String generateWaypointDescription(TripStatistics tripStatistics);
}
@@ -0,0 +1,66 @@
/*
* 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
import android.location.Location;
/**
* This class extends the standard Android location with extra information.
*
* @author Sandor Dornbush
*/
public class MyTracksLocation extends Location {
private SensorDataSet sensorDataSet = null;
/**
* The id of this location from the provider.
*/
private int id = -1;
public MyTracksLocation(Location location, Sensor.SensorDataSet sd) {
super(location);
this.sensorDataSet = sd;
}
public MyTracksLocation(String provider) {
super(provider);
}
public SensorDataSet getSensorDataSet() {
return sensorDataSet;
}
public void setSensorDataSet(SensorDataSet sensorDataSet) {
this.sensorDataSet = sensorDataSet;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public void reset() {
super.reset();
sensorDataSet = null;
id = -1;
}
}
@@ -0,0 +1,385 @@
/*
* 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import android.content.Context;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import java.util.Iterator;
import java.util.List;
/**
* Utilities to access data from the My Tracks content provider.
*
* @author Rodrigo Damazio
*/
public interface MyTracksProviderUtils {
/**
* The authority (the first part of the URI) for the My Tracks content
* provider.
*/
public static final String AUTHORITY = "com.google.android.maps.mytracks";
/**
* Clears a track. Removes waypoints and trackpoints. Only keeps the track id.
*
* @param trackId the track id
*/
public void clearTrack(long trackId);
/**
* Creates a {@link Track} from a cursor.
*
* @param cursor the cursor pointing to the track
*/
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.
* <p>
* Note that the returned tracks do not have any track points attached.
*/
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.
* <p>
* Note that the returned track doesn't have any track points attached.
*
* @param trackId the track id.
*/
public Track getTrack(long trackId);
/**
* Gets a track cursor. The caller owns the returned cursor and is responsible
* for closing it.
*
* @param selection the selection. Can be null
* @param selectionArgs the selection arguments. Can be null
* @param sortOrder the sort order. Can be null
*/
public Cursor getTrackCursor(String selection, String[] selectionArgs, String sortOrder);
/**
* Inserts a track.
* <p>
* Note: This doesn't insert any track points.
*
* @param track the track
* @return the content provider URI of the inserted track.
*/
public Uri insertTrack(Track track);
/**
* Updates a track.
* <p>
* Note: This doesn't update any track points.
*
* @param track the track
*/
public void updateTrack(Track track);
/**
* Creates a waypoint from a cursor.
*
* @param cursor the cursor pointing to the waypoint
*/
public Waypoint createWaypoint(Cursor cursor);
/**
* 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 waypointId the waypoint id
* @param descriptionGenerator the description generator. Can be null for
* waypoint marker
*/
public void deleteWaypoint(long waypointId, DescriptionGenerator descriptionGenerator);
/**
* Gets the first waypoint id for a track. The first waypoint is special as it
* contains the stats for the track. Returns -1L if it doesn't exist.
*
* @param trackId the track id
*/
public long getFirstWaypointId(long trackId);
/**
* Gets the last waypoint for a type. Returns null if it doesn't exist.
*
* @param trackId the track id
* @param waypointType the waypoint type
*/
public Waypoint getLastWaypoint(long trackId, WaypointType waypointType);
/**
* Gets the next waypoint number for a type. Returns -1 if not able to get the
* next waypoint number.
*
* @param trackId the track id
* @param waypointType the waypoint type
*/
public int getNextWaypointNumber(long trackId, WaypointType waypointType);
/**
* Gets a waypoint from a waypoint id. Returns null if not found.
*
* @param waypointId the waypoint id
*/
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. Can be null
* @param selectionArgs the selection arguments. Can be null
* @param sortOrder the sort order. Can be null
* @param maxWaypoints the maximum number of waypoints to return. -1 for no
* limit
*/
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. -1L to ignore
* @param maxWaypoints the maximum number of waypoints to return. -1 for no
* limit
*/
public Cursor getWaypointCursor(long trackId, long minWaypointId, int maxWaypoints);
/**
* Inserts a waypoint.
*
* @param waypoint the waypoint
* @return the content provider URI of the inserted waypoint.
*/
public Uri insertWaypoint(Waypoint waypoint);
/**
* Updates a waypoint. Returns true if successful.
*
* @param waypoint the waypoint
*/
public boolean updateWaypoint(Waypoint waypoint);
/**
* 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 bulkInsertTrackPoint(Location[] locations, int length, long trackId);
/**
* Creates a location object from a cursor.
*
* @param cursor the cursor pointing to the location
*/
public Location createTrackPoint(Cursor cursor);
/**
* Gets the first location id for a track. Returns -1L if it doesn't exist.
*
* @param trackId the track id
*/
public long getFirstTrackPointId(long trackId);
/**
* Gets the last location id for a track. Returns -1L if it doesn't exist.
*
* @param trackId the track id
*/
public long getLastTrackPointId(long trackId);
/**
* Gets the first valid location for a track. Returns null if it doesn't
* exist.
*
* @param trackId the track id
*/
public Location getFirstValidTrackPoint(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);
/**
* Gets the last valid location recorded. Returns null if it doesn't exist.
*/
public Location getLastValidTrackPoint();
/**
* Creates a location cursor. The caller owns the returned cursor and is
* responsible for closing it.
*
* @param trackId the track id
* @param startTrackPointId the starting track point id. -1L to ignore
* @param maxLocations maximum number of locations to return. -1 for no limit
* @param descending true to sort the result in descending order (latest
* location first)
*/
public Cursor getTrackPointCursor(
long trackId, long startTrackPointId, int maxLocations, boolean descending);
/**
* Creates a new read-only iterator over a given track's points. 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
* {@link 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, {@link LocationIterator#close()} must be called.
*
* @param trackId the track id
* @param startTrackPointId the starting track point id. -1L to ignore
* @param descending true to sort the result in descending order (latest
* location first)
* @param locationFactory the location factory
*/
public LocationIterator getTrackPointLocationIterator(
long trackId, long startTrackPointId, boolean descending, LocationFactory locationFactory);
/**
* Inserts a track point.
*
* @param location the location
* @param trackId the track id
* @return the content provider URI of the inserted track point
*/
public Uri insertTrackPoint(Location location, long trackId);
/**
* A lightweight wrapper around the original {@link Cursor} with a method to
* clean up.
*/
public interface LocationIterator extends Iterator<Location> {
/**
* Gets the most recently retrieved track point id by {@link #next()}.
*/
public long getLocationId();
/**
* Closes the iterator.
*/
public void close();
}
/**
* A factory for creating new {@link Location}.
*/
public interface LocationFactory {
/**
* Creates a new {@link Location}. An implementation can create new
* instances or reuse existing instances for optimization.
*/
public Location createLocation();
}
/**
* The default {@link LocationFactory} which creates a location each time.
*/
public LocationFactory DEFAULT_LOCATION_FACTORY = new LocationFactory() {
@Override
public Location createLocation() {
return new MyTracksLocation(LocationManager.GPS_PROVIDER);
}
};
/**
* A factory which can produce instances of {@link MyTracksProviderUtils}, and
* can be overridden for testing.
*/
public static class Factory {
private static Factory instance = new Factory();
/**
* Creates an instance of {@link MyTracksProviderUtils}.
*
* @param context the context
*/
public static MyTracksProviderUtils get(Context context) {
return instance.newForContext(context);
}
/**
* Returns the factory instance.
*/
public static Factory getInstance() {
return instance;
}
/**
* Overrides the factory instance for testing. Don't forget to set it back
* to the original value after testing.
*
* @param factory the factory
*/
public static void overrideInstance(Factory factory) {
instance = factory;
}
/**
* Creates an instance of {@link MyTracksProviderUtils}. Allows subclasses
* to override for testing.
*
* @param context the context
*/
protected MyTracksProviderUtils newForContext(Context context) {
return new MyTracksProviderUtilsImpl(context.getContentResolver());
}
}
}
@@ -0,0 +1,883 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: proto/sensor.proto
package com.google.android.apps.mytracks.content;
public final class Sensor {
private Sensor() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistryLite registry) {
}
public enum SensorState
implements com.google.protobuf.Internal.EnumLite {
NONE(0, 1),
CONNECTING(1, 2),
CONNECTED(2, 3),
DISCONNECTED(3, 4),
SENDING(4, 5),
;
public final int getNumber() { return value; }
public static SensorState valueOf(int value) {
switch (value) {
case 1: return NONE;
case 2: return CONNECTING;
case 3: return CONNECTED;
case 4: return DISCONNECTED;
case 5: return SENDING;
default: return null;
}
}
public static com.google.protobuf.Internal.EnumLiteMap<SensorState>
internalGetValueMap() {
return internalValueMap;
}
private static com.google.protobuf.Internal.EnumLiteMap<SensorState>
internalValueMap =
new com.google.protobuf.Internal.EnumLiteMap<SensorState>() {
public SensorState findValueByNumber(int number) {
return SensorState.valueOf(number)
; }
};
private final int index;
private final int value;
private SensorState(int index, int value) {
this.index = index;
this.value = value;
}
// @@protoc_insertion_point(enum_scope:com.google.android.apps.mytracks.content.SensorState)
}
public static final class SensorData extends
com.google.protobuf.GeneratedMessageLite {
// Use SensorData.newBuilder() to construct.
private SensorData() {
initFields();
}
private SensorData(boolean noInit) {}
private static final SensorData defaultInstance;
public static SensorData getDefaultInstance() {
return defaultInstance;
}
public SensorData getDefaultInstanceForType() {
return defaultInstance;
}
// required .com.google.android.apps.mytracks.content.SensorState state = 1 [default = NONE];
public static final int STATE_FIELD_NUMBER = 1;
private boolean hasState;
private com.google.android.apps.mytracks.content.Sensor.SensorState state_;
public boolean hasState() { return hasState; }
public com.google.android.apps.mytracks.content.Sensor.SensorState getState() { return state_; }
// optional int32 value = 2;
public static final int VALUE_FIELD_NUMBER = 2;
private boolean hasValue;
private int value_ = 0;
public boolean hasValue() { return hasValue; }
public int getValue() { return value_; }
private void initFields() {
state_ = com.google.android.apps.mytracks.content.Sensor.SensorState.NONE;
}
public final boolean isInitialized() {
if (!hasState) return false;
return true;
}
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
getSerializedSize();
if (hasState()) {
output.writeEnum(1, getState().getNumber());
}
if (hasValue()) {
output.writeInt32(2, getValue());
}
}
private int memoizedSerializedSize = -1;
public int getSerializedSize() {
int size = memoizedSerializedSize;
if (size != -1) return size;
size = 0;
if (hasState()) {
size += com.google.protobuf.CodedOutputStream
.computeEnumSize(1, getState().getNumber());
}
if (hasValue()) {
size += com.google.protobuf.CodedOutputStream
.computeInt32Size(2, getValue());
}
memoizedSerializedSize = size;
return size;
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return newBuilder().mergeFrom(data).buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return newBuilder().mergeFrom(data, extensionRegistry)
.buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return newBuilder().mergeFrom(data).buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return newBuilder().mergeFrom(data, extensionRegistry)
.buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseFrom(java.io.InputStream input)
throws java.io.IOException {
return newBuilder().mergeFrom(input).buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return newBuilder().mergeFrom(input, extensionRegistry)
.buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
Builder builder = newBuilder();
if (builder.mergeDelimitedFrom(input)) {
return builder.buildParsed();
} else {
return null;
}
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
Builder builder = newBuilder();
if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
return builder.buildParsed();
} else {
return null;
}
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return newBuilder().mergeFrom(input).buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorData parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return newBuilder().mergeFrom(input, extensionRegistry)
.buildParsed();
}
public static Builder newBuilder() { return Builder.create(); }
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder(com.google.android.apps.mytracks.content.Sensor.SensorData prototype) {
return newBuilder().mergeFrom(prototype);
}
public Builder toBuilder() { return newBuilder(this); }
public static final class Builder extends
com.google.protobuf.GeneratedMessageLite.Builder<
com.google.android.apps.mytracks.content.Sensor.SensorData, Builder> {
private com.google.android.apps.mytracks.content.Sensor.SensorData result;
// Construct using com.google.android.apps.mytracks.content.Sensor.SensorData.newBuilder()
private Builder() {}
private static Builder create() {
Builder builder = new Builder();
builder.result = new com.google.android.apps.mytracks.content.Sensor.SensorData();
return builder;
}
protected com.google.android.apps.mytracks.content.Sensor.SensorData internalGetResult() {
return result;
}
public Builder clear() {
if (result == null) {
throw new IllegalStateException(
"Cannot call clear() after build().");
}
result = new com.google.android.apps.mytracks.content.Sensor.SensorData();
return this;
}
public Builder clone() {
return create().mergeFrom(result);
}
public com.google.android.apps.mytracks.content.Sensor.SensorData getDefaultInstanceForType() {
return com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance();
}
public boolean isInitialized() {
return result.isInitialized();
}
public com.google.android.apps.mytracks.content.Sensor.SensorData build() {
if (result != null && !isInitialized()) {
throw newUninitializedMessageException(result);
}
return buildPartial();
}
private com.google.android.apps.mytracks.content.Sensor.SensorData buildParsed()
throws com.google.protobuf.InvalidProtocolBufferException {
if (!isInitialized()) {
throw newUninitializedMessageException(
result).asInvalidProtocolBufferException();
}
return buildPartial();
}
public com.google.android.apps.mytracks.content.Sensor.SensorData buildPartial() {
if (result == null) {
throw new IllegalStateException(
"build() has already been called on this Builder.");
}
com.google.android.apps.mytracks.content.Sensor.SensorData returnMe = result;
result = null;
return returnMe;
}
public Builder mergeFrom(com.google.android.apps.mytracks.content.Sensor.SensorData other) {
if (other == com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance()) return this;
if (other.hasState()) {
setState(other.getState());
}
if (other.hasValue()) {
setValue(other.getValue());
}
return this;
}
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
while (true) {
int tag = input.readTag();
switch (tag) {
case 0:
return this;
default: {
if (!parseUnknownField(input, extensionRegistry, tag)) {
return this;
}
break;
}
case 8: {
int rawValue = input.readEnum();
com.google.android.apps.mytracks.content.Sensor.SensorState value = com.google.android.apps.mytracks.content.Sensor.SensorState.valueOf(rawValue);
if (value != null) {
setState(value);
}
break;
}
case 16: {
setValue(input.readInt32());
break;
}
}
}
}
// required .com.google.android.apps.mytracks.content.SensorState state = 1 [default = NONE];
public boolean hasState() {
return result.hasState();
}
public com.google.android.apps.mytracks.content.Sensor.SensorState getState() {
return result.getState();
}
public Builder setState(com.google.android.apps.mytracks.content.Sensor.SensorState value) {
if (value == null) {
throw new NullPointerException();
}
result.hasState = true;
result.state_ = value;
return this;
}
public Builder clearState() {
result.hasState = false;
result.state_ = com.google.android.apps.mytracks.content.Sensor.SensorState.NONE;
return this;
}
// optional int32 value = 2;
public boolean hasValue() {
return result.hasValue();
}
public int getValue() {
return result.getValue();
}
public Builder setValue(int value) {
result.hasValue = true;
result.value_ = value;
return this;
}
public Builder clearValue() {
result.hasValue = false;
result.value_ = 0;
return this;
}
// @@protoc_insertion_point(builder_scope:com.google.android.apps.mytracks.content.SensorData)
}
static {
defaultInstance = new SensorData(true);
com.google.android.apps.mytracks.content.Sensor.internalForceInit();
defaultInstance.initFields();
}
// @@protoc_insertion_point(class_scope:com.google.android.apps.mytracks.content.SensorData)
}
public static final class SensorDataSet extends
com.google.protobuf.GeneratedMessageLite {
// Use SensorDataSet.newBuilder() to construct.
private SensorDataSet() {
initFields();
}
private SensorDataSet(boolean noInit) {}
private static final SensorDataSet defaultInstance;
public static SensorDataSet getDefaultInstance() {
return defaultInstance;
}
public SensorDataSet getDefaultInstanceForType() {
return defaultInstance;
}
// optional uint64 creation_time = 1 [default = 0];
public static final int CREATION_TIME_FIELD_NUMBER = 1;
private boolean hasCreationTime;
private long creationTime_ = 0L;
public boolean hasCreationTime() { return hasCreationTime; }
public long getCreationTime() { return creationTime_; }
// optional .com.google.android.apps.mytracks.content.SensorData heart_rate = 2;
public static final int HEART_RATE_FIELD_NUMBER = 2;
private boolean hasHeartRate;
private com.google.android.apps.mytracks.content.Sensor.SensorData heartRate_;
public boolean hasHeartRate() { return hasHeartRate; }
public com.google.android.apps.mytracks.content.Sensor.SensorData getHeartRate() { return heartRate_; }
// optional .com.google.android.apps.mytracks.content.SensorData cadence = 3;
public static final int CADENCE_FIELD_NUMBER = 3;
private boolean hasCadence;
private com.google.android.apps.mytracks.content.Sensor.SensorData cadence_;
public boolean hasCadence() { return hasCadence; }
public com.google.android.apps.mytracks.content.Sensor.SensorData getCadence() { return cadence_; }
// optional .com.google.android.apps.mytracks.content.SensorData power = 4;
public static final int POWER_FIELD_NUMBER = 4;
private boolean hasPower;
private com.google.android.apps.mytracks.content.Sensor.SensorData power_;
public boolean hasPower() { return hasPower; }
public com.google.android.apps.mytracks.content.Sensor.SensorData getPower() { return power_; }
// optional .com.google.android.apps.mytracks.content.SensorData battery_level = 5;
public static final int BATTERY_LEVEL_FIELD_NUMBER = 5;
private boolean hasBatteryLevel;
private com.google.android.apps.mytracks.content.Sensor.SensorData batteryLevel_;
public boolean hasBatteryLevel() { return hasBatteryLevel; }
public com.google.android.apps.mytracks.content.Sensor.SensorData getBatteryLevel() { return batteryLevel_; }
private void initFields() {
heartRate_ = com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance();
cadence_ = com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance();
power_ = com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance();
batteryLevel_ = com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance();
}
public final boolean isInitialized() {
if (hasHeartRate()) {
if (!getHeartRate().isInitialized()) return false;
}
if (hasCadence()) {
if (!getCadence().isInitialized()) return false;
}
if (hasPower()) {
if (!getPower().isInitialized()) return false;
}
if (hasBatteryLevel()) {
if (!getBatteryLevel().isInitialized()) return false;
}
return true;
}
public void writeTo(com.google.protobuf.CodedOutputStream output)
throws java.io.IOException {
getSerializedSize();
if (hasCreationTime()) {
output.writeUInt64(1, getCreationTime());
}
if (hasHeartRate()) {
output.writeMessage(2, getHeartRate());
}
if (hasCadence()) {
output.writeMessage(3, getCadence());
}
if (hasPower()) {
output.writeMessage(4, getPower());
}
if (hasBatteryLevel()) {
output.writeMessage(5, getBatteryLevel());
}
}
private int memoizedSerializedSize = -1;
public int getSerializedSize() {
int size = memoizedSerializedSize;
if (size != -1) return size;
size = 0;
if (hasCreationTime()) {
size += com.google.protobuf.CodedOutputStream
.computeUInt64Size(1, getCreationTime());
}
if (hasHeartRate()) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(2, getHeartRate());
}
if (hasCadence()) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(3, getCadence());
}
if (hasPower()) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(4, getPower());
}
if (hasBatteryLevel()) {
size += com.google.protobuf.CodedOutputStream
.computeMessageSize(5, getBatteryLevel());
}
memoizedSerializedSize = size;
return size;
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseFrom(
com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {
return newBuilder().mergeFrom(data).buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseFrom(
com.google.protobuf.ByteString data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return newBuilder().mergeFrom(data, extensionRegistry)
.buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseFrom(byte[] data)
throws com.google.protobuf.InvalidProtocolBufferException {
return newBuilder().mergeFrom(data).buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseFrom(
byte[] data,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws com.google.protobuf.InvalidProtocolBufferException {
return newBuilder().mergeFrom(data, extensionRegistry)
.buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseFrom(java.io.InputStream input)
throws java.io.IOException {
return newBuilder().mergeFrom(input).buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return newBuilder().mergeFrom(input, extensionRegistry)
.buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseDelimitedFrom(java.io.InputStream input)
throws java.io.IOException {
Builder builder = newBuilder();
if (builder.mergeDelimitedFrom(input)) {
return builder.buildParsed();
} else {
return null;
}
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseDelimitedFrom(
java.io.InputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
Builder builder = newBuilder();
if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
return builder.buildParsed();
} else {
return null;
}
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseFrom(
com.google.protobuf.CodedInputStream input)
throws java.io.IOException {
return newBuilder().mergeFrom(input).buildParsed();
}
public static com.google.android.apps.mytracks.content.Sensor.SensorDataSet parseFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
return newBuilder().mergeFrom(input, extensionRegistry)
.buildParsed();
}
public static Builder newBuilder() { return Builder.create(); }
public Builder newBuilderForType() { return newBuilder(); }
public static Builder newBuilder(com.google.android.apps.mytracks.content.Sensor.SensorDataSet prototype) {
return newBuilder().mergeFrom(prototype);
}
public Builder toBuilder() { return newBuilder(this); }
public static final class Builder extends
com.google.protobuf.GeneratedMessageLite.Builder<
com.google.android.apps.mytracks.content.Sensor.SensorDataSet, Builder> {
private com.google.android.apps.mytracks.content.Sensor.SensorDataSet result;
// Construct using com.google.android.apps.mytracks.content.Sensor.SensorDataSet.newBuilder()
private Builder() {}
private static Builder create() {
Builder builder = new Builder();
builder.result = new com.google.android.apps.mytracks.content.Sensor.SensorDataSet();
return builder;
}
protected com.google.android.apps.mytracks.content.Sensor.SensorDataSet internalGetResult() {
return result;
}
public Builder clear() {
if (result == null) {
throw new IllegalStateException(
"Cannot call clear() after build().");
}
result = new com.google.android.apps.mytracks.content.Sensor.SensorDataSet();
return this;
}
public Builder clone() {
return create().mergeFrom(result);
}
public com.google.android.apps.mytracks.content.Sensor.SensorDataSet getDefaultInstanceForType() {
return com.google.android.apps.mytracks.content.Sensor.SensorDataSet.getDefaultInstance();
}
public boolean isInitialized() {
return result.isInitialized();
}
public com.google.android.apps.mytracks.content.Sensor.SensorDataSet build() {
if (result != null && !isInitialized()) {
throw newUninitializedMessageException(result);
}
return buildPartial();
}
private com.google.android.apps.mytracks.content.Sensor.SensorDataSet buildParsed()
throws com.google.protobuf.InvalidProtocolBufferException {
if (!isInitialized()) {
throw newUninitializedMessageException(
result).asInvalidProtocolBufferException();
}
return buildPartial();
}
public com.google.android.apps.mytracks.content.Sensor.SensorDataSet buildPartial() {
if (result == null) {
throw new IllegalStateException(
"build() has already been called on this Builder.");
}
com.google.android.apps.mytracks.content.Sensor.SensorDataSet returnMe = result;
result = null;
return returnMe;
}
public Builder mergeFrom(com.google.android.apps.mytracks.content.Sensor.SensorDataSet other) {
if (other == com.google.android.apps.mytracks.content.Sensor.SensorDataSet.getDefaultInstance()) return this;
if (other.hasCreationTime()) {
setCreationTime(other.getCreationTime());
}
if (other.hasHeartRate()) {
mergeHeartRate(other.getHeartRate());
}
if (other.hasCadence()) {
mergeCadence(other.getCadence());
}
if (other.hasPower()) {
mergePower(other.getPower());
}
if (other.hasBatteryLevel()) {
mergeBatteryLevel(other.getBatteryLevel());
}
return this;
}
public Builder mergeFrom(
com.google.protobuf.CodedInputStream input,
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
throws java.io.IOException {
while (true) {
int tag = input.readTag();
switch (tag) {
case 0:
return this;
default: {
if (!parseUnknownField(input, extensionRegistry, tag)) {
return this;
}
break;
}
case 8: {
setCreationTime(input.readUInt64());
break;
}
case 18: {
com.google.android.apps.mytracks.content.Sensor.SensorData.Builder subBuilder = com.google.android.apps.mytracks.content.Sensor.SensorData.newBuilder();
if (hasHeartRate()) {
subBuilder.mergeFrom(getHeartRate());
}
input.readMessage(subBuilder, extensionRegistry);
setHeartRate(subBuilder.buildPartial());
break;
}
case 26: {
com.google.android.apps.mytracks.content.Sensor.SensorData.Builder subBuilder = com.google.android.apps.mytracks.content.Sensor.SensorData.newBuilder();
if (hasCadence()) {
subBuilder.mergeFrom(getCadence());
}
input.readMessage(subBuilder, extensionRegistry);
setCadence(subBuilder.buildPartial());
break;
}
case 34: {
com.google.android.apps.mytracks.content.Sensor.SensorData.Builder subBuilder = com.google.android.apps.mytracks.content.Sensor.SensorData.newBuilder();
if (hasPower()) {
subBuilder.mergeFrom(getPower());
}
input.readMessage(subBuilder, extensionRegistry);
setPower(subBuilder.buildPartial());
break;
}
case 42: {
com.google.android.apps.mytracks.content.Sensor.SensorData.Builder subBuilder = com.google.android.apps.mytracks.content.Sensor.SensorData.newBuilder();
if (hasBatteryLevel()) {
subBuilder.mergeFrom(getBatteryLevel());
}
input.readMessage(subBuilder, extensionRegistry);
setBatteryLevel(subBuilder.buildPartial());
break;
}
}
}
}
// optional uint64 creation_time = 1 [default = 0];
public boolean hasCreationTime() {
return result.hasCreationTime();
}
public long getCreationTime() {
return result.getCreationTime();
}
public Builder setCreationTime(long value) {
result.hasCreationTime = true;
result.creationTime_ = value;
return this;
}
public Builder clearCreationTime() {
result.hasCreationTime = false;
result.creationTime_ = 0L;
return this;
}
// optional .com.google.android.apps.mytracks.content.SensorData heart_rate = 2;
public boolean hasHeartRate() {
return result.hasHeartRate();
}
public com.google.android.apps.mytracks.content.Sensor.SensorData getHeartRate() {
return result.getHeartRate();
}
public Builder setHeartRate(com.google.android.apps.mytracks.content.Sensor.SensorData value) {
if (value == null) {
throw new NullPointerException();
}
result.hasHeartRate = true;
result.heartRate_ = value;
return this;
}
public Builder setHeartRate(com.google.android.apps.mytracks.content.Sensor.SensorData.Builder builderForValue) {
result.hasHeartRate = true;
result.heartRate_ = builderForValue.build();
return this;
}
public Builder mergeHeartRate(com.google.android.apps.mytracks.content.Sensor.SensorData value) {
if (result.hasHeartRate() &&
result.heartRate_ != com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance()) {
result.heartRate_ =
com.google.android.apps.mytracks.content.Sensor.SensorData.newBuilder(result.heartRate_).mergeFrom(value).buildPartial();
} else {
result.heartRate_ = value;
}
result.hasHeartRate = true;
return this;
}
public Builder clearHeartRate() {
result.hasHeartRate = false;
result.heartRate_ = com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance();
return this;
}
// optional .com.google.android.apps.mytracks.content.SensorData cadence = 3;
public boolean hasCadence() {
return result.hasCadence();
}
public com.google.android.apps.mytracks.content.Sensor.SensorData getCadence() {
return result.getCadence();
}
public Builder setCadence(com.google.android.apps.mytracks.content.Sensor.SensorData value) {
if (value == null) {
throw new NullPointerException();
}
result.hasCadence = true;
result.cadence_ = value;
return this;
}
public Builder setCadence(com.google.android.apps.mytracks.content.Sensor.SensorData.Builder builderForValue) {
result.hasCadence = true;
result.cadence_ = builderForValue.build();
return this;
}
public Builder mergeCadence(com.google.android.apps.mytracks.content.Sensor.SensorData value) {
if (result.hasCadence() &&
result.cadence_ != com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance()) {
result.cadence_ =
com.google.android.apps.mytracks.content.Sensor.SensorData.newBuilder(result.cadence_).mergeFrom(value).buildPartial();
} else {
result.cadence_ = value;
}
result.hasCadence = true;
return this;
}
public Builder clearCadence() {
result.hasCadence = false;
result.cadence_ = com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance();
return this;
}
// optional .com.google.android.apps.mytracks.content.SensorData power = 4;
public boolean hasPower() {
return result.hasPower();
}
public com.google.android.apps.mytracks.content.Sensor.SensorData getPower() {
return result.getPower();
}
public Builder setPower(com.google.android.apps.mytracks.content.Sensor.SensorData value) {
if (value == null) {
throw new NullPointerException();
}
result.hasPower = true;
result.power_ = value;
return this;
}
public Builder setPower(com.google.android.apps.mytracks.content.Sensor.SensorData.Builder builderForValue) {
result.hasPower = true;
result.power_ = builderForValue.build();
return this;
}
public Builder mergePower(com.google.android.apps.mytracks.content.Sensor.SensorData value) {
if (result.hasPower() &&
result.power_ != com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance()) {
result.power_ =
com.google.android.apps.mytracks.content.Sensor.SensorData.newBuilder(result.power_).mergeFrom(value).buildPartial();
} else {
result.power_ = value;
}
result.hasPower = true;
return this;
}
public Builder clearPower() {
result.hasPower = false;
result.power_ = com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance();
return this;
}
// optional .com.google.android.apps.mytracks.content.SensorData battery_level = 5;
public boolean hasBatteryLevel() {
return result.hasBatteryLevel();
}
public com.google.android.apps.mytracks.content.Sensor.SensorData getBatteryLevel() {
return result.getBatteryLevel();
}
public Builder setBatteryLevel(com.google.android.apps.mytracks.content.Sensor.SensorData value) {
if (value == null) {
throw new NullPointerException();
}
result.hasBatteryLevel = true;
result.batteryLevel_ = value;
return this;
}
public Builder setBatteryLevel(com.google.android.apps.mytracks.content.Sensor.SensorData.Builder builderForValue) {
result.hasBatteryLevel = true;
result.batteryLevel_ = builderForValue.build();
return this;
}
public Builder mergeBatteryLevel(com.google.android.apps.mytracks.content.Sensor.SensorData value) {
if (result.hasBatteryLevel() &&
result.batteryLevel_ != com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance()) {
result.batteryLevel_ =
com.google.android.apps.mytracks.content.Sensor.SensorData.newBuilder(result.batteryLevel_).mergeFrom(value).buildPartial();
} else {
result.batteryLevel_ = value;
}
result.hasBatteryLevel = true;
return this;
}
public Builder clearBatteryLevel() {
result.hasBatteryLevel = false;
result.batteryLevel_ = com.google.android.apps.mytracks.content.Sensor.SensorData.getDefaultInstance();
return this;
}
// @@protoc_insertion_point(builder_scope:com.google.android.apps.mytracks.content.SensorDataSet)
}
static {
defaultInstance = new SensorDataSet(true);
com.google.android.apps.mytracks.content.Sensor.internalForceInit();
defaultInstance.initFields();
}
// @@protoc_insertion_point(class_scope:com.google.android.apps.mytracks.content.SensorDataSet)
}
static {
}
public static void internalForceInit() {}
// @@protoc_insertion_point(outer_class_scope)
}
@@ -0,0 +1,258 @@
/*
* Copyright 2008 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.stats.TripStatistics;
import android.location.Location;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
/**
* A track.
*
* @author Leif Hendrik Wilden
* @author Rodrigo Damazio
*/
public class Track implements Parcelable {
private long id = -1L;
private String name = "";
private String description = "";
private String category = "";
private long startId = -1L;
private long stopId = -1L;
/*
* The number of location points (present even if the points themselves are
* not loaded)
*/
private int numberOfPoints = 0;
private String mapId = "";
private String tableId = "";
private String icon = "";
private String driveId = "";
private long modifiedTime = -1L;
private boolean sharedWithMe = false;
private String sharedOwner = "";
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();
startId = in.readLong();
stopId = in.readLong();
numberOfPoints = in.readInt();
mapId = in.readString();
tableId = in.readString();
icon = in.readString();
driveId = in.readString();
modifiedTime = in.readLong();
sharedWithMe = in.readByte() == 1;
sharedOwner = in.readString();
ClassLoader classLoader = getClass().getClassLoader();
tripStatistics = in.readParcelable(classLoader);
for (int i = 0; i < numberOfPoints; ++i) {
Location location = in.readParcelable(classLoader);
locations.add(location);
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(name);
dest.writeString(description);
dest.writeString(category);
dest.writeLong(startId);
dest.writeLong(stopId);
dest.writeInt(numberOfPoints);
dest.writeString(mapId);
dest.writeString(tableId);
dest.writeString(icon);
dest.writeString(driveId);
dest.writeLong(modifiedTime);
dest.writeByte((byte) (sharedWithMe ? 1 : 0));
dest.writeString(sharedOwner);
dest.writeParcelable(tripStatistics, 0);
for (int i = 0; i < numberOfPoints; ++i) {
dest.writeParcelable(locations.get(i), 0);
}
}
public static final Parcelable.Creator<Track> CREATOR = new Parcelable.Creator<Track>() {
@Override
public Track createFromParcel(Parcel in) {
return new Track(in);
}
@Override
public Track[] newArray(int size) {
return new Track[size];
}
};
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String 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 long getStartId() {
return startId;
}
public void setStartId(long startId) {
this.startId = startId;
}
public long getStopId() {
return stopId;
}
public void setStopId(long stopId) {
this.stopId = stopId;
}
public int getNumberOfPoints() {
return numberOfPoints;
}
public void setNumberOfPoints(int numberOfPoints) {
this.numberOfPoints = numberOfPoints;
}
public String getMapId() {
return mapId;
}
public void setMapId(String mapId) {
this.mapId = mapId;
}
public String getTableId() {
return tableId;
}
public void setTableId(String tableId) {
this.tableId = tableId;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getDriveId() {
return driveId;
}
public void setDriveId(String driveId) {
this.driveId = driveId;
}
public long getModifiedTime() {
return modifiedTime;
}
public void setModifiedTime(long modifiedTime) {
this.modifiedTime = modifiedTime;
}
public boolean isSharedWithMe() {
return sharedWithMe;
}
public void setSharedWithMe(boolean sharedWithMe) {
this.sharedWithMe = sharedWithMe;
}
public String getSharedOwner() {
return sharedOwner;
}
public void setSharedOwner(String sharedOwner) {
this.sharedOwner = sharedOwner;
}
public TripStatistics getTripStatistics() {
return tripStatistics;
}
public void setTripStatistics(TripStatistics tripStatistics) {
this.tripStatistics = tripStatistics;
}
public void addLocation(Location location) {
locations.add(location);
}
public ArrayList<Location> getLocations() {
return locations;
}
public void setLocations(ArrayList<Location> locations) {
this.locations = locations;
}
}
@@ -0,0 +1,90 @@
/*
* Copyright 2008 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
import static com.google.android.apps.mytracks.content.ContentTypeIds.BLOB_TYPE_ID;
import static com.google.android.apps.mytracks.content.ContentTypeIds.FLOAT_TYPE_ID;
import static com.google.android.apps.mytracks.content.ContentTypeIds.INT_TYPE_ID;
import static com.google.android.apps.mytracks.content.ContentTypeIds.LONG_TYPE_ID;
import android.net.Uri;
import android.provider.BaseColumns;
/**
* Constants for the track points table.
*
* @author Leif Hendrik Wilden
*/
public interface TrackPointsColumns extends BaseColumns {
public static final String TABLE_NAME = "trackpoints";
public static final Uri CONTENT_URI = Uri.parse(
"content://com.google.android.maps.mytracks/trackpoints");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.trackpoint";
public static final String CONTENT_ITEMTYPE = "vnd.android.cursor.item/vnd.google.trackpoint";
public static final String DEFAULT_SORT_ORDER = "_id";
// Columns
public static final String TRACKID = "trackid"; // track id
public static final String LONGITUDE = "longitude"; // longitude
public static final String LATITUDE = "latitude"; // latitude
public static final String TIME = "time"; // time
public static final String ALTITUDE = "elevation"; // altitude
public static final String ACCURACY = "accuracy"; // accuracy
public static final String SPEED = "speed"; // speed
public static final String BEARING = "bearing"; // bearing
public static final String SENSOR = "sensor"; // sensor
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " ("
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ TRACKID + " INTEGER, "
+ LONGITUDE + " INTEGER, "
+ LATITUDE + " INTEGER, "
+ TIME + " INTEGER, "
+ ALTITUDE + " FLOAT, "
+ ACCURACY + " FLOAT, "
+ SPEED + " FLOAT, "
+ BEARING + " FLOAT, "
+ SENSOR + " BLOB"
+ ");";
public static final String[] COLUMNS = {
_ID,
TRACKID,
LONGITUDE,
LATITUDE,
TIME,
ALTITUDE,
ACCURACY,
SPEED,
BEARING,
SENSOR
};
public static final byte[] COLUMN_TYPES = {
LONG_TYPE_ID, // id
LONG_TYPE_ID, // track id
INT_TYPE_ID, // longitude
INT_TYPE_ID, // latitude
LONG_TYPE_ID, // time
FLOAT_TYPE_ID, // altitude
FLOAT_TYPE_ID, // accuracy
FLOAT_TYPE_ID, // speed
FLOAT_TYPE_ID, // bearing
BLOB_TYPE_ID // sensor
};
}
@@ -0,0 +1,189 @@
/*
* Copyright 2008 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
import android.net.Uri;
import android.provider.BaseColumns;
/**
* Constants for the tracks table.
*
* @author Leif Hendrik Wilden
*/
public interface TracksColumns extends BaseColumns {
public static final String TABLE_NAME = "tracks";
/**
* Tracks provider uri.
*/
public static final Uri CONTENT_URI = Uri.parse(
"content://com.google.android.maps.mytracks/tracks");
/**
* 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";
// Columns
public static final String NAME = "name"; // track name
public static final String DESCRIPTION = "description"; // track description
public static final String CATEGORY = "category"; // track activity type
public static final String STARTID = "startid"; // first track point id
public static final String STOPID = "stopid"; // last track point id
public static final String STARTTIME = "starttime"; // track start time
public static final String STOPTIME = "stoptime"; // track stop time
public static final String NUMPOINTS = "numpoints"; // number of track points
public static final String TOTALDISTANCE = "totaldistance"; // total distance
public static final String TOTALTIME = "totaltime"; // total time
public static final String MOVINGTIME = "movingtime"; // moving time
public static final String MINLAT = "minlat"; // minimum latitude
public static final String MAXLAT = "maxlat"; // maximum latitude
public static final String MINLON = "minlon"; // minimum longitude
public static final String MAXLON = "maxlon"; // maximum longitude
public static final String AVGSPEED = "avgspeed"; // average speed
// average moving speed
public static final String AVGMOVINGSPEED = "avgmovingspeed";
public static final String MAXSPEED = "maxspeed"; // maximum speed
public static final String MINELEVATION = "minelevation"; // minimum elevation
public static final String MAXELEVATION = "maxelevation"; // maximum elevation
public static final String ELEVATIONGAIN = "elevationgain"; // elevation gain
public static final String MINGRADE = "mingrade"; // minimum grade
public static final String MAXGRADE = "maxgrade"; // maximum grade
public static final String MAPID = "mapid"; // Google Maps id
public static final String TABLEID = "tableid"; // Google Fusion Tables id
public static final String ICON = "icon"; // track activity type icon
public static final String DRIVEID = "driveid"; // Google Drive file id
// Google drive file modified time
public static final String MODIFIEDTIME = "modifiedtime";
// 1 if the Google Drive file is from the "Shared with me" directory
public static final String SHAREDWITHME = "sharedwithme";
// The owner of the shared with me track
public static final String SHAREDOWNER = "sharedOwner";
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" // table
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " // id
+ NAME + " STRING, " // name
+ DESCRIPTION + " STRING, " // description
+ CATEGORY + " STRING, " // category
+ STARTID + " INTEGER, " // start id
+ STOPID + " INTEGER, " // stop id
+ STARTTIME + " INTEGER, " // start time
+ STOPTIME + " INTEGER, " // stop time
+ NUMPOINTS + " INTEGER, " // num points
+ TOTALDISTANCE + " FLOAT, " // total distance
+ TOTALTIME + " INTEGER, " // total time
+ MOVINGTIME + " INTEGER, " // moving time
+ MINLAT + " INTEGER, " // min latitude
+ MAXLAT + " INTEGER, " // max latitude
+ MINLON + " INTEGER, " // min longitude
+ MAXLON + " INTEGER, " // max longitude
+ AVGSPEED + " FLOAT, " // average speed
+ AVGMOVINGSPEED + " FLOAT, " // average moving speed
+ MAXSPEED + " FLOAT, " // max speed
+ MINELEVATION + " FLOAT, " // min elevation
+ MAXELEVATION + " FLOAT, " // max elevation
+ ELEVATIONGAIN + " FLOAT, " // elevation gain
+ MINGRADE + " FLOAT, " // min grade
+ MAXGRADE + " FLOAT, " // max grade
+ MAPID + " STRING, " // map id
+ TABLEID + " STRING, " // table id
+ ICON + " STRING, " // icon
+ DRIVEID + " STRING, " // drive id
+ MODIFIEDTIME + " INTEGER, " // modified time
+ SHAREDWITHME + " INTEGER, " // shared with me
+ SHAREDOWNER + " STRING" + ");"; // shared owner
public static final String[] COLUMNS = { _ID, // id
NAME, // name
DESCRIPTION, // description
CATEGORY, // category
STARTID, // start id
STOPID, // stop id
STARTTIME, // start time
STOPTIME, // stop time
NUMPOINTS, // num points
TOTALDISTANCE, // total distance
TOTALTIME, // total time
MOVINGTIME, // moving time
MINLAT, // min latitude
MAXLAT, // max latitude
MINLON, // min longitude
MAXLON, // max longitude
AVGSPEED, // average speed
AVGMOVINGSPEED, // average moving speed
MAXSPEED, // max speed
MINELEVATION, // min elevation
MAXELEVATION, // max elevation
ELEVATIONGAIN, // elevation gain
MINGRADE, // min grade
MAXGRADE, // max grade
MAPID, // map id
TABLEID, // table id
ICON, // icon
DRIVEID, // drive id
MODIFIEDTIME, // modified time
SHAREDWITHME, // shared with me
SHAREDOWNER }; // shared owner
public static final byte[] COLUMN_TYPES = { ContentTypeIds.LONG_TYPE_ID, // id
ContentTypeIds.STRING_TYPE_ID, // name
ContentTypeIds.STRING_TYPE_ID, // description
ContentTypeIds.STRING_TYPE_ID, // category
ContentTypeIds.LONG_TYPE_ID, // start id
ContentTypeIds.LONG_TYPE_ID, // stop id
ContentTypeIds.LONG_TYPE_ID, // start time
ContentTypeIds.LONG_TYPE_ID, // stop time
ContentTypeIds.INT_TYPE_ID, // num points
ContentTypeIds.FLOAT_TYPE_ID, // total distance
ContentTypeIds.LONG_TYPE_ID, // total time
ContentTypeIds.LONG_TYPE_ID, // moving time
ContentTypeIds.INT_TYPE_ID, // min latitude
ContentTypeIds.INT_TYPE_ID, // max latitude
ContentTypeIds.INT_TYPE_ID, // min longitude
ContentTypeIds.INT_TYPE_ID, // max longitude
ContentTypeIds.FLOAT_TYPE_ID, // average speed
ContentTypeIds.FLOAT_TYPE_ID, // average moving speed
ContentTypeIds.FLOAT_TYPE_ID, // max speed
ContentTypeIds.FLOAT_TYPE_ID, // min elevation
ContentTypeIds.FLOAT_TYPE_ID, // max elevation
ContentTypeIds.FLOAT_TYPE_ID, // elevation gain
ContentTypeIds.FLOAT_TYPE_ID, // min grade
ContentTypeIds.FLOAT_TYPE_ID, // max grade
ContentTypeIds.STRING_TYPE_ID, // map id
ContentTypeIds.STRING_TYPE_ID, // table id
ContentTypeIds.STRING_TYPE_ID, // icon
ContentTypeIds.STRING_TYPE_ID, // drive id
ContentTypeIds.LONG_TYPE_ID, // modified time
ContentTypeIds.BOOLEAN_TYPE_ID, // shared with me
ContentTypeIds.STRING_TYPE_ID // shared owner
};
}
@@ -0,0 +1,2 @@
package com.google.android.apps.mytracks.content;
parcelable Waypoint;
@@ -0,0 +1,237 @@
/*
* Copyright 2009 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.stats.TripStatistics;
import android.location.Location;
import android.os.Parcel;
import android.os.Parcelable;
/**
* A waypoint.
*
* @author Leif Hendrik Wilden
* @author Rodrigo Damazio
*/
public final class Waypoint implements Parcelable {
public static enum WaypointType {
WAYPOINT, STATISTICS;
}
private long id = -1L;
private String name = "";
private String description = "";
private String category = "";
private String icon = "";
private long trackId = -1L;
private WaypointType type = WaypointType.WAYPOINT;
private double length = 0.0;
private long duration = 0;
private long startId = -1L;
private long stopId = -1L;
private Location location = null;
private TripStatistics tripStatistics = null;
public Waypoint() {}
public Waypoint(String name, String description, String category, String icon, long trackId,
WaypointType type, double length, long duration, long startId, long stopId, Location location,
TripStatistics tripStatistics) {
this.name = name;
this.description = description;
this.category = category;
this.icon = icon;
this.trackId = trackId;
this.type = type;
this.length = length;
this.duration = duration;
this.startId = startId;
this.stopId = stopId;
this.location = location;
this.tripStatistics = tripStatistics;
}
private Waypoint(Parcel source) {
id = source.readLong();
name = source.readString();
description = source.readString();
category = source.readString();
icon = source.readString();
trackId = source.readLong();
type = WaypointType.values()[source.readInt()];
length = source.readDouble();
duration = source.readLong();
startId = source.readLong();
stopId = source.readLong();
ClassLoader classLoader = getClass().getClassLoader();
byte hasLocation = source.readByte();
if (hasLocation > 0) {
location = source.readParcelable(classLoader);
}
byte hasStats = source.readByte();
if (hasStats > 0) {
tripStatistics = source.readParcelable(classLoader);
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(name);
dest.writeString(description);
dest.writeString(category);
dest.writeString(icon);
dest.writeLong(trackId);
dest.writeInt(type.ordinal());
dest.writeDouble(length);
dest.writeLong(duration);
dest.writeLong(startId);
dest.writeLong(stopId);
dest.writeByte(location == null ? (byte) 0 : (byte) 1);
if (location != null) {
dest.writeParcelable(location, 0);
}
dest.writeByte(tripStatistics == null ? (byte) 0 : (byte) 1);
if (tripStatistics != null) {
dest.writeParcelable(tripStatistics, 0);
}
}
public static final Parcelable.Creator<Waypoint> CREATOR = new Parcelable.Creator<Waypoint>() {
@Override
public Waypoint createFromParcel(Parcel in) {
return new Waypoint(in);
}
@Override
public Waypoint[] newArray(int size) {
return new Waypoint[size];
}
};
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String 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 getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public long getTrackId() {
return trackId;
}
public void setTrackId(long trackId) {
this.trackId = trackId;
}
public WaypointType getType() {
return type;
}
public void setType(WaypointType type) {
this.type = type;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public long getDuration() {
return duration;
}
public void setDuration(long duration) {
this.duration = duration;
}
public long getStartId() {
return startId;
}
public void setStartId(long startId) {
this.startId = startId;
}
public long getStopId() {
return stopId;
}
public void setStopId(long stopId) {
this.stopId = stopId;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
public TripStatistics getTripStatistics() {
return tripStatistics;
}
public void setTripStatistics(TripStatistics tripStatistics) {
this.tripStatistics = tripStatistics;
}
}
@@ -0,0 +1,2 @@
package com.google.android.apps.mytracks.content;
parcelable WaypointCreationRequest;
@@ -0,0 +1,118 @@
/*
* 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import android.os.Parcel;
import android.os.Parcelable;
/**
* A request for the service to create a waypoint at the current location.
*
* @author Sandor Dornbush
*/
public class WaypointCreationRequest implements Parcelable {
private WaypointType type;
// true if this marker contains the track statistics
private boolean isTrackStatistics;
private String name;
private String category;
private String description;
private String iconUrl;
public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(
WaypointType.WAYPOINT, false);
public final static WaypointCreationRequest DEFAULT_STATISTICS = new WaypointCreationRequest(
WaypointType.STATISTICS, false);
public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(
WaypointType.STATISTICS, true);
private WaypointCreationRequest(WaypointType type, boolean isTrackStatistics) {
this(type, isTrackStatistics, null, null, null, null);
}
public WaypointCreationRequest(WaypointType type, boolean isTrackStatistics, String name,
String category, String description, String iconUrl) {
this.type = type;
this.isTrackStatistics = isTrackStatistics;
this.name = name;
this.category = category;
this.description = description;
this.iconUrl = iconUrl;
}
public static class Creator implements Parcelable.Creator<WaypointCreationRequest> {
@Override
public WaypointCreationRequest createFromParcel(Parcel source) {
WaypointCreationRequest request = new WaypointCreationRequest(
WaypointType.values()[source.readInt()],
source.readByte() == 1,
source.readString(),
source.readString(),
source.readString(),
source.readString());
return request;
}
public WaypointCreationRequest[] newArray(int size) {
return new WaypointCreationRequest[size];
}
}
public static final Creator CREATOR = new Creator();
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int arg1) {
parcel.writeInt(type.ordinal());
parcel.writeByte((byte) (isTrackStatistics ? 1 : 0));
parcel.writeString(name);
parcel.writeString(category);
parcel.writeString(description);
parcel.writeString(iconUrl);
}
public WaypointType getType() {
return type;
}
public boolean isTrackStatistics() {
return isTrackStatistics;
}
public String getName() {
return name;
}
public String getCategory() {
return category;
}
public String getDescription() {
return description;
}
public String getIconUrl() {
return iconUrl;
}
}
@@ -0,0 +1,172 @@
/*
* Copyright 2009 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.content;
import static com.google.android.apps.mytracks.content.ContentTypeIds.FLOAT_TYPE_ID;
import static com.google.android.apps.mytracks.content.ContentTypeIds.INT_TYPE_ID;
import static com.google.android.apps.mytracks.content.ContentTypeIds.LONG_TYPE_ID;
import static com.google.android.apps.mytracks.content.ContentTypeIds.STRING_TYPE_ID;
import android.net.Uri;
import android.provider.BaseColumns;
/**
* Constants for waypoints table.
*
* @author Leif Hendrik Wilden
*/
public interface WaypointsColumns extends BaseColumns {
public static final String TABLE_NAME = "waypoints";
public static final Uri CONTENT_URI = Uri.parse(
"content://com.google.android.maps.mytracks/waypoints");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.google.waypoint";
public static final String CONTENT_ITEMTYPE = "vnd.android.cursor.item/vnd.google.waypoint";
public static final String DEFAULT_SORT_ORDER = "_id";
// Columns
public static final String NAME = "name"; // waypoint name
public static final String DESCRIPTION = "description"; // waypoint description
public static final String CATEGORY = "category"; // waypoint category
public static final String ICON = "icon"; // waypoint icon
public static final String TRACKID = "trackid"; // track id
public static final String TYPE = "type"; // type
public static final String LENGTH = "length"; // length of the track (without smoothing)
public static final String DURATION = "duration"; // total duration of the track (not from last waypoint)
public static final String STARTTIME = "starttime"; // start time of the trip statistics
public static final String STARTID = "startid"; // start track point id
public static final String STOPID = "stopid"; // stop track point id
public static final String LONGITUDE = "longitude"; // longitude
public static final String LATITUDE = "latitude"; // latitude
public static final String TIME = "time"; // time
public static final String ALTITUDE = "elevation"; // altitude
public static final String ACCURACY = "accuracy"; // accuracy
public static final String SPEED = "speed"; // speed
public static final String BEARING = "bearing"; // bearing
public static final String TOTALDISTANCE = "totaldistance"; // total distance
public static final String TOTALTIME = "totaltime"; // total time
public static final String MOVINGTIME = "movingtime"; // moving time
public static final String AVGSPEED = "avgspeed"; // average speed
public static final String AVGMOVINGSPEED = "avgmovingspeed"; // average moving speed
public static final String MAXSPEED = "maxspeed"; // max speed
public static final String MINELEVATION = "minelevation"; // min elevation
public static final String MAXELEVATION = "maxelevation"; // max elevation
public static final String ELEVATIONGAIN = "elevationgain"; // elevation gain
public static final String MINGRADE = "mingrade"; // min grade
public static final String MAXGRADE = "maxgrade"; // max grade
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " ("
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ NAME + " STRING, "
+ DESCRIPTION + " STRING, "
+ CATEGORY + " STRING, "
+ ICON + " STRING, "
+ TRACKID + " INTEGER, "
+ TYPE + " INTEGER, "
+ LENGTH + " FLOAT, "
+ DURATION + " INTEGER, "
+ STARTTIME + " INTEGER, "
+ STARTID + " INTEGER, "
+ STOPID + " INTEGER, "
+ LONGITUDE + " INTEGER, "
+ LATITUDE + " INTEGER, "
+ TIME + " INTEGER, "
+ ALTITUDE + " FLOAT, "
+ ACCURACY + " FLOAT, "
+ SPEED + " FLOAT, "
+ BEARING + " FLOAT, "
+ TOTALDISTANCE + " FLOAT, "
+ TOTALTIME + " INTEGER, "
+ MOVINGTIME + " INTEGER, "
+ AVGSPEED + " FLOAT, "
+ AVGMOVINGSPEED + " FLOAT, "
+ MAXSPEED + " FLOAT, "
+ MINELEVATION + " FLOAT, "
+ MAXELEVATION + " FLOAT, "
+ ELEVATIONGAIN + " FLOAT, "
+ MINGRADE + " FLOAT, "
+ MAXGRADE + " FLOAT"
+ ");";
public static final String[] COLUMNS = {
_ID,
NAME,
DESCRIPTION,
CATEGORY,
ICON,
TRACKID,
TYPE,
LENGTH,
DURATION,
STARTTIME,
STARTID,
STOPID,
LONGITUDE,
LATITUDE,
TIME,
ALTITUDE,
ACCURACY,
SPEED,
BEARING,
TOTALDISTANCE,
TOTALTIME,
MOVINGTIME,
AVGSPEED,
AVGMOVINGSPEED,
MAXSPEED,
MINELEVATION,
MAXELEVATION,
ELEVATIONGAIN,
MINGRADE,
MAXGRADE
};
public static final byte[] COLUMN_TYPES = {
LONG_TYPE_ID, // id
STRING_TYPE_ID, // name
STRING_TYPE_ID, // description
STRING_TYPE_ID, // category
STRING_TYPE_ID, // icon
LONG_TYPE_ID, // track id
INT_TYPE_ID, // type
FLOAT_TYPE_ID, // length
LONG_TYPE_ID, // duration
LONG_TYPE_ID, // start time
LONG_TYPE_ID, // start id
LONG_TYPE_ID, // stop id
INT_TYPE_ID, // longitude
INT_TYPE_ID, // latitude
LONG_TYPE_ID, // time
FLOAT_TYPE_ID, // altitude
FLOAT_TYPE_ID, // accuracy
FLOAT_TYPE_ID, // speed
FLOAT_TYPE_ID, // bearing
FLOAT_TYPE_ID, // total distance
LONG_TYPE_ID, // total time
LONG_TYPE_ID, // moving time
FLOAT_TYPE_ID, // average speed
FLOAT_TYPE_ID, // average moving speed
FLOAT_TYPE_ID, // max speed
FLOAT_TYPE_ID, // min elevation
FLOAT_TYPE_ID, // max elevation
FLOAT_TYPE_ID, // elevation gain
FLOAT_TYPE_ID, // min grade
FLOAT_TYPE_ID // max grade
};
}
@@ -0,0 +1,28 @@
/*
* 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.lib;
/**
* Constants for the My Tracks common library.
* These constants should ideally not be used by third-party applications.
*
* @author Rodrigo Damazio
*/
public class MyTracksLibConstants {
public static final String TAG = "MyTracksLib";
private MyTracksLibConstants() {}
}
@@ -0,0 +1,99 @@
/*
* Copyright 2008 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.services;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
/**
* MyTracks service.
* This service is the process that actually records and manages tracks.
*/
interface ITrackRecordingService {
/**
* Starts recording a new track.
*
* @return the track ID of the new track.
*/
long startNewTrack();
/**
* Pauses the current recording track.
*/
void pauseCurrentTrack();
/**
* Resumes the current recording track.
*/
void resumeCurrentTrack();
/**
* Ends the current recording track.
*/
void endCurrentTrack();
/**
* Returns true if currently recording a track.
*/
boolean isRecording();
/**
* Returns true if the current recording track is paused. Returns true if not recording.
*/
boolean isPaused();
/**
* Gets the current recording track ID. Returns -1 if not recording.
*/
long getRecordingTrackId();
/**
* Gets the total time for the current recording track. Returns 0 if not recording.
*/
long getTotalTime();
/**
* Inserts a waypoint in the current recording track.
*
* @param request the details of the waypoint to be inserted
* @return the ID of the inserted waypoint
*/
long insertWaypoint(in WaypointCreationRequest request);
/**
* Inserts a track point in the current recording track.
*
* When recording a track, GPS locations are automatically inserted. This is used for
* inserting special track points or for testing.
*
* @param location the track point to be inserted
*/
void insertTrackPoint(in Location location);
/**
* Gets the current sensor data. Returns null if there is no data.
* @return a byte array of the binary version of the Sensor.SensorDataSet object.
*/
byte[] getSensorData();
/**
* Gets the current sensor manager state.
*
* return a Sensor.SensorState enum value.
*/
int getSensorState();
}
@@ -0,0 +1,117 @@
/*
* Copyright 2009 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.stats;
/**
* A helper class that tracks a minimum and a maximum of a variable.
*
* @author Sandor Dornbush
*/
public class ExtremityMonitor {
// The smallest value seen so far.
private double min;
// The largest value seen so far.
private double max;
public ExtremityMonitor() {
reset();
}
/**
* Resets this object to it's initial state where the min and max are unknown.
*/
public void reset() {
min = Double.POSITIVE_INFINITY;
max = Double.NEGATIVE_INFINITY;
}
/**
* Gets the minimum value seen.
*/
public double getMin() {
return min;
}
/**
* Gets the maximum value seen.
*/
public double getMax() {
return max;
}
/**
* Updates the min and the max with a new value.
*
* @param value the new value
* @return true if an extremity was found
*/
public boolean update(double value) {
boolean changed = false;
if (value < min) {
min = value;
changed = true;
}
if (value > max) {
max = value;
changed = true;
}
return changed;
}
/**
* Sets the minimum and maximum values.
*
* @param min the minimum value
* @param max the maximum value
*/
public void set(double min, double max) {
this.min = min;
this.max = max;
}
/**
* Sets the minimum value.
*
* @param min the minimum value
*/
public void setMin(double min) {
this.min = min;
}
/**
* Sets the maximum value.
*
* @param max the maximum value
*/
public void setMax(double max) {
this.max = max;
}
/**
* Returns true if has data.
*/
public boolean hasData() {
return min != Double.POSITIVE_INFINITY && max != Double.NEGATIVE_INFINITY;
}
@Override
public String toString() {
return "Min: " + min + " Max: " + max;
}
}
@@ -0,0 +1,2 @@
package com.google.android.apps.mytracks.stats;
parcelable TripStatistics;
@@ -0,0 +1,567 @@
/*
* 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
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.android.apps.mytracks.stats;
import android.os.Parcel;
import android.os.Parcelable;
/**
* Statistical data about a trip. The data in this class should be filled out by
* TripStatisticsBuilder.
* <p>
* TODO: hashCode and equals
*
* @author Rodrigo Damazio
*/
public class TripStatistics implements Parcelable {
// The trip start time. This is the system time, might not match the GPs time.
private long startTime = -1L;
// The trip stop time. This is the system time, might not match the GPS time.
private long stopTime = -1L;
// The total trip distance (meters).
private double totalDistance;
// The total time (ms). Updated when new points are received, may be stale.
private long totalTime;
// The total moving time (ms). Based on when we believe the user is traveling.
private long movingTime;
// The min and max latitude seen in this trip.
private final ExtremityMonitor latitudeExtremities = new ExtremityMonitor();
// The min and max longitude seen in this trip.
private final ExtremityMonitor longitudeExtremities = new ExtremityMonitor();
// The maximum speed (meters/second) that we believe is valid.
private double maxSpeed;
// The min and max elevation (meters) seen on this trip.
private final ExtremityMonitor elevationExtremities = new ExtremityMonitor();
// The total elevation gained (meters).
private double totalElevationGain;
// The min and max grade seen on this trip.
private final ExtremityMonitor gradeExtremities = new ExtremityMonitor();
/**
* Default constructor.
*/
public TripStatistics() {}
/**
* Copy constructor.
*
* @param other another statistics data object to copy from
*/
public TripStatistics(TripStatistics other) {
this.startTime = other.startTime;
this.stopTime = other.stopTime;
this.totalDistance = other.totalDistance;
this.totalTime = other.totalTime;
this.movingTime = other.movingTime;
this.latitudeExtremities.set(
other.latitudeExtremities.getMin(), other.latitudeExtremities.getMax());
this.longitudeExtremities.set(
other.longitudeExtremities.getMin(), other.longitudeExtremities.getMax());
this.maxSpeed = other.maxSpeed;
this.elevationExtremities.set(
other.elevationExtremities.getMin(), other.elevationExtremities.getMax());
this.totalElevationGain = other.totalElevationGain;
this.gradeExtremities.set(other.gradeExtremities.getMin(), other.gradeExtremities.getMax());
}
/**
* Combines these statistics with those from another object. This assumes that
* the time periods covered by each do not intersect.
*
* @param other another statistics data object
*/
public void merge(TripStatistics other) {
startTime = Math.min(startTime, other.startTime);
stopTime = Math.max(stopTime, other.stopTime);
totalDistance += other.totalDistance;
totalTime += other.totalTime;
movingTime += other.movingTime;
if (other.latitudeExtremities.hasData()) {
latitudeExtremities.update(other.latitudeExtremities.getMin());
latitudeExtremities.update(other.latitudeExtremities.getMax());
}
if (other.longitudeExtremities.hasData()) {
longitudeExtremities.update(other.longitudeExtremities.getMin());
longitudeExtremities.update(other.longitudeExtremities.getMax());
}
maxSpeed = Math.max(maxSpeed, other.maxSpeed);
if (other.elevationExtremities.hasData()) {
elevationExtremities.update(other.elevationExtremities.getMin());
elevationExtremities.update(other.elevationExtremities.getMax());
}
totalElevationGain += other.totalElevationGain;
if (other.gradeExtremities.hasData()) {
gradeExtremities.update(other.gradeExtremities.getMin());
gradeExtremities.update(other.gradeExtremities.getMax());
}
}
/**
* Gets the trip start time. The number of milliseconds since epoch.
*/
public long getStartTime() {
return startTime;
}
/**
* Gets the trip stop time. The number of milliseconds since epoch.
*/
public long getStopTime() {
return stopTime;
}
/**
* Gets the total distance the user traveled in meters.
*/
public double getTotalDistance() {
return totalDistance;
}
/**
* Gets the total time in milliseconds that this track has been active. This
* statistic is only updated when a new point is added to the statistics, so
* it may be off. If you need to calculate the proper total time, use
* {@link #getStartTime} with the current time.
*/
public long getTotalTime() {
return totalTime;
}
/**
* Gets the moving time in milliseconds.
*/
public long getMovingTime() {
return movingTime;
}
/**
* Gets the topmost position (highest latitude) of the track, in signed
* degrees.
*/
public double getTopDegrees() {
return latitudeExtremities.getMax();
}
/**
* Gets the topmost position (highest latitude) of the track, in signed
* millions of degrees.
*/
public int getTop() {
return (int) (latitudeExtremities.getMax() * 1E6);
}
/**
* Gets the bottommost position (lowest latitude) of the track, in signed
* degrees.
*/
public double getBottomDegrees() {
return latitudeExtremities.getMin();
}
/**
* Gets the bottommost position (lowest latitude) of the track, in signed
* millions of degrees.
*/
public int getBottom() {
return (int) (latitudeExtremities.getMin() * 1E6);
}
/**
* Gets the leftmost position (lowest longitude) of the track, in signed
* degrees.
*/
public double getLeftDegrees() {
return longitudeExtremities.getMin();
}
/**
* Gets the leftmost position (lowest longitude) of the track, in signed
* millions of degrees.
*/
public int getLeft() {
return (int) (longitudeExtremities.getMin() * 1E6);
}
/**
* Gets the rightmost position (highest longitude) of the track, in signed
* degrees.
*/
public double getRightDegrees() {
return longitudeExtremities.getMax();
}
/**
* Gets the rightmost position (highest longitude) of the track, in signed
* millions of degrees.
*/
public int getRight() {
return (int) (longitudeExtremities.getMax() * 1E6);
}
/**
* Gets the mean latitude position of the track, in signed degrees.
*/
public double getMeanLatitude() {
return (getBottomDegrees() + getTopDegrees()) / 2.0;
}
/**
* Gets the mean longitude position of the track, in signed degrees.
*/
public double getMeanLongitude() {
return (getLeftDegrees() + getRightDegrees()) / 2.0;
}
/**
* Gets the average speed in meters/second. This calculation only takes into
* account the displacement until the last point that was accounted for in
* statistics.
*/
public double getAverageSpeed() {
if (totalTime == 0L) {
return 0.0;
}
return totalDistance / ((double) totalTime / 1000.0);
}
/**
* Gets the average moving speed in meters/second.
*/
public double getAverageMovingSpeed() {
if (movingTime == 0L) {
return 0.0;
}
return totalDistance / ((double) movingTime / 1000.0);
}
/**
* Gets the maximum speed in meters/second.
*/
public double getMaxSpeed() {
return maxSpeed;
}
/**
* Gets the minimum elevation. This is calculated from the smoothed elevation
* so this can actually be more than the current elevation.
*/
public double getMinElevation() {
return elevationExtremities.getMin();
}
/**
* Gets the maximum elevation. This is calculated from the smoothed elevation
* so this can actually be less than the current elevation.
*/
public double getMaxElevation() {
return elevationExtremities.getMax();
}
/**
* Gets the total elevation gain in meters. This is calculated as the sum of
* all positive differences in the smoothed elevation.
*/
public double getTotalElevationGain() {
return totalElevationGain;
}
/**
* Gets the minimum grade for this trip.
*/
public double getMinGrade() {
return gradeExtremities.getMin();
}
/**
* Gets the maximum grade for this trip.
*/
public double getMaxGrade() {
return gradeExtremities.getMax();
}
/**
* Sets the trip start time.
*
* @param startTime the trip start time in milliseconds since the epoch
*/
public void setStartTime(long startTime) {
this.startTime = startTime;
}
/**
* Sets the trip stop time.
*
* @param stopTime the stop time in milliseconds since the epoch
*/
public void setStopTime(long stopTime) {
this.stopTime = stopTime;
}
/**
* Sets the total trip distance.
*
* @param totalDistance the trip distance in meters
*/
public void setTotalDistance(double totalDistance) {
this.totalDistance = totalDistance;
}
/**
* Adds to the current total distance.
*
* @param distance the distance to add in meters
*/
void addTotalDistance(double distance) {
totalDistance += distance;
}
/**
* Sets the trip total time.
*
* @param totalTime the trip total time in milliseconds
*/
public void setTotalTime(long totalTime) {
this.totalTime = totalTime;
}
/**
* Sets the trip total moving time.
*
* @param movingTime the trip total moving time in milliseconds
*/
public void setMovingTime(long movingTime) {
this.movingTime = movingTime;
}
/**
* Adds to the trip total moving time.
*
* @param time the time in milliseconds
*/
void addMovingTime(long time) {
movingTime += time;
}
/**
* Sets the bounding box for this trip. The unit for all parameters is signed
* millions of degree (degrees * 1E6).
*
* @param leftE6 the leftmost longitude reached
* @param topE6 the topmost latitude reached
* @param rightE6 the rightmost longitude reached
* @param bottomE6 the bottommost latitude reached
*/
public void setBounds(int leftE6, int topE6, int rightE6, int bottomE6) {
latitudeExtremities.set(bottomE6 / 1E6, topE6 / 1E6);
longitudeExtremities.set(leftE6 / 1E6, rightE6 / 1E6);
}
/**
* Updates a new latitude value.
*
* @param latitude the latitude value in signed decimal degrees
*/
void updateLatitudeExtremities(double latitude) {
latitudeExtremities.update(latitude);
}
/**
* Updates a new longitude value.
*
* @param longitude the longitude value in signed decimal degrees
*/
void updateLongitudeExtremities(double longitude) {
longitudeExtremities.update(longitude);
}
/**
* Sets the maximum speed.
*
* @param maxSpeed the maximum speed in meters/second
*/
public void setMaxSpeed(double maxSpeed) {
this.maxSpeed = maxSpeed;
}
/**
* Sets the minimum elevation.
*
* @param elevation the minimum elevation in meters
*/
public void setMinElevation(double elevation) {
elevationExtremities.setMin(elevation);
}
/**
* Sets the maximum elevation.
*
* @param elevation the maximum elevation in meters
*/
public void setMaxElevation(double elevation) {
elevationExtremities.setMax(elevation);
}
/**
* Updates a new elevation.
*
* @param elevation the elevation value in meters
*/
void updateElevationExtremities(double elevation) {
elevationExtremities.update(elevation);
}
/**
* Sets the total elevation gain.
*
* @param totalElevationGain the elevation gain in meters
*/
public void setTotalElevationGain(double totalElevationGain) {
this.totalElevationGain = totalElevationGain;
}
/**
* Adds to the total elevation gain.
*
* @param gain the elevation gain in meters
*/
void addTotalElevationGain(double gain) {
totalElevationGain += gain;
}
/**
* Sets the minimum grade.
*
* @param grade the grade as a fraction (-1.0 would mean vertical downwards)
*/
public void setMinGrade(double grade) {
gradeExtremities.setMin(grade);
}
/**
* Sets the maximum grade.
*
* @param grade the grade as a fraction (1.0 would mean vertical upwards)
*/
public void setMaxGrade(double grade) {
gradeExtremities.setMax(grade);
}
/**
* Updates a new grade value.
*
* @param grade the grade value as a fraction
*/
void updateGradeExtremities(double grade) {
gradeExtremities.update(grade);
}
@Override
public String toString() {
return "TripStatistics { Start Time: " + getStartTime() + "; Stop Time: " + getStopTime()
+ "; Total Time: " + getTotalTime() + "; Total Distance: " + getTotalDistance()
+ "; Total Time: " + getTotalTime() + "; Moving Time: " + getMovingTime()
+ "; Min Latitude: " + getBottomDegrees() + "; Max Latitude: " + getTopDegrees()
+ "; Min Longitude: " + getLeftDegrees() + "; Max Longitude: " + getRightDegrees()
+ "; Max Elevation: " + getMaxElevation() + "; Max Speed: " + getMaxSpeed()
+ "; Min Elevation: " + getMinElevation() + "; Max Elevation: " + getMaxElevation()
+ "; Elevation Gain: " + getTotalElevationGain() + "; Min Grade: " + getMinGrade()
+ "; Max Grade: " + getMaxGrade() + "}";
}
/**
* Creator of statistics data from parcels.
*/
public static class Creator implements Parcelable.Creator<TripStatistics> {
@Override
public TripStatistics createFromParcel(Parcel source) {
TripStatistics data = new TripStatistics();
data.startTime = source.readLong();
data.stopTime = source.readLong();
data.totalDistance = source.readDouble();
data.totalTime = source.readLong();
data.movingTime = source.readLong();
double minLat = source.readDouble();
double maxLat = source.readDouble();
data.latitudeExtremities.set(minLat, maxLat);
double minLong = source.readDouble();
double maxLong = source.readDouble();
data.longitudeExtremities.set(minLong, maxLong);
data.maxSpeed = source.readDouble();
double minElev = source.readDouble();
double maxElev = source.readDouble();
data.elevationExtremities.set(minElev, maxElev);
data.totalElevationGain = source.readDouble();
double minGrade = source.readDouble();
double maxGrade = source.readDouble();
data.gradeExtremities.set(minGrade, maxGrade);
return data;
}
@Override
public TripStatistics[] newArray(int size) {
return new TripStatistics[size];
}
}
/**
* Creator of {@link TripStatistics} from parcels.
*/
public static final Creator CREATOR = new Creator();
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(startTime);
dest.writeLong(stopTime);
dest.writeDouble(totalDistance);
dest.writeLong(totalTime);
dest.writeLong(movingTime);
dest.writeDouble(latitudeExtremities.getMin());
dest.writeDouble(latitudeExtremities.getMax());
dest.writeDouble(longitudeExtremities.getMin());
dest.writeDouble(longitudeExtremities.getMax());
dest.writeDouble(maxSpeed);
dest.writeDouble(elevationExtremities.getMin());
dest.writeDouble(elevationExtremities.getMax());
dest.writeDouble(totalElevationGain);
dest.writeDouble(gradeExtremities.getMin());
dest.writeDouble(gradeExtremities.getMax());
}
}