Clean up WaypointsColumns.java.

This commit is contained in:
Jimmy Shih
2012-06-14 15:54:52 -07:00
parent 984521b034
commit 7d5ec3b043
16 changed files with 373 additions and 361 deletions
@@ -86,7 +86,7 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity {
} else {
waypointSection.setVisibility(View.GONE);
statisticsSection.setVisibility(View.VISIBLE);
StatsUtils.setTripStatisticsValues(this, waypoint.getStatistics());
StatsUtils.setTripStatisticsValues(this, waypoint.getTripStatistics());
StatsUtils.setLocationValues(this, waypoint.getLocation(), false);
}
}
@@ -59,12 +59,13 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
private static final String TAG = MarkerListActivity.class.getSimpleName();
private static final String[] PROJECTION = new String[] { WaypointsColumns._ID,
WaypointsColumns.TYPE,
private static final String[] PROJECTION = new String[] {
WaypointsColumns._ID,
WaypointsColumns.NAME,
WaypointsColumns.DESCRIPTION,
WaypointsColumns.CATEGORY,
WaypointsColumns.TIME,
WaypointsColumns.DESCRIPTION };
WaypointsColumns.TYPE,
WaypointsColumns.TIME};
// Callback when an item is selected in the contextual action mode
private ContextualActionModeCallback contextualActionModeCallback =
@@ -128,11 +129,11 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) {
@Override
public void bindView(View view, Context context, Cursor cursor) {
int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE);
int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME);
int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY);
int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME);
int descriptionIndex = cursor.getColumnIndex(WaypointsColumns.DESCRIPTION);
int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY);
int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE);
int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME);
boolean statistics = cursor.getInt(typeIndex) == Waypoint.TYPE_STATISTICS;
String name = cursor.getString(nameIndex);
@@ -77,7 +77,7 @@ public class DescriptionGeneratorImpl implements DescriptionGenerator {
@Override
public String generateWaypointDescription(Waypoint waypoint) {
return generateTripStatisticsDescription(waypoint.getStatistics(), false);
return generateTripStatisticsDescription(waypoint.getTripStatistics(), false);
}
/**
@@ -52,7 +52,6 @@ public class MyTracksProvider extends ContentProvider {
private static final int TRACKS_ID = 4;
private static final int WAYPOINTS = 5;
private static final int WAYPOINTS_ID = 6;
private static final String WAYPOINTS_TABLE = "waypoints";
private static final String TAG = MyTracksProvider.class.getSimpleName();
/**
@@ -68,37 +67,7 @@ public class MyTracksProvider extends ContentProvider {
public void onCreate(SQLiteDatabase db) {
db.execSQL(TrackPointsColumns.CREATE_TABLE);
db.execSQL(TracksColumns.CREATE_TABLE);
db.execSQL("CREATE TABLE " + WAYPOINTS_TABLE + " ("
+ WaypointsColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ WaypointsColumns.NAME + " STRING, "
+ WaypointsColumns.DESCRIPTION + " STRING, "
+ WaypointsColumns.CATEGORY + " STRING, "
+ WaypointsColumns.ICON + " STRING, "
+ WaypointsColumns.TRACKID + " INTEGER, "
+ WaypointsColumns.TYPE + " INTEGER, "
+ WaypointsColumns.LENGTH + " FLOAT, "
+ WaypointsColumns.DURATION + " INTEGER, "
+ WaypointsColumns.STARTTIME + " INTEGER, "
+ WaypointsColumns.STARTID + " INTEGER, "
+ WaypointsColumns.STOPID + " INTEGER, "
+ WaypointsColumns.LONGITUDE + " INTEGER, "
+ WaypointsColumns.LATITUDE + " INTEGER, "
+ WaypointsColumns.TIME + " INTEGER, "
+ WaypointsColumns.ALTITUDE + " FLOAT, "
+ WaypointsColumns.ACCURACY + " FLOAT, "
+ WaypointsColumns.SPEED + " FLOAT, "
+ WaypointsColumns.BEARING + " FLOAT, "
+ WaypointsColumns.TOTALDISTANCE + " FLOAT, "
+ WaypointsColumns.TOTALTIME + " INTEGER, "
+ WaypointsColumns.MOVINGTIME + " INTEGER, "
+ WaypointsColumns.AVGSPEED + " FLOAT, "
+ WaypointsColumns.AVGMOVINGSPEED + " FLOAT, "
+ WaypointsColumns.MAXSPEED + " FLOAT, "
+ WaypointsColumns.MINELEVATION + " FLOAT, "
+ WaypointsColumns.MAXELEVATION + " FLOAT, "
+ WaypointsColumns.ELEVATIONGAIN + " FLOAT, "
+ WaypointsColumns.MINGRADE + " FLOAT, "
+ WaypointsColumns.MAXGRADE + " FLOAT);");
db.execSQL(WaypointsColumns.CREATE_TABLE);
}
@Override
@@ -109,7 +78,7 @@ public class MyTracksProvider extends ContentProvider {
Log.w(TAG, "Delete all old data");
db.execSQL("DROP TABLE IF EXISTS " + TrackPointsColumns.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + TracksColumns.TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + WAYPOINTS_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + WaypointsColumns.TABLE_NAME);
onCreate(db);
} else {
// Incremental updates go here. For each DB version, add a corresponding if clause.
@@ -192,7 +161,7 @@ public class MyTracksProvider extends ContentProvider {
shouldVacuum = true;
break;
case WAYPOINTS:
table = WAYPOINTS_TABLE;
table = WaypointsColumns.TABLE_NAME;
break;
default:
throw new IllegalArgumentException("Unknown URL " + url);
@@ -328,7 +297,7 @@ public class MyTracksProvider extends ContentProvider {
}
private Uri insertWaypoint(Uri url, ContentValues values) {
long rowId = db.insert(WAYPOINTS_TABLE, WaypointsColumns._ID, values);
long rowId = db.insert(WaypointsColumns.TABLE_NAME, WaypointsColumns._ID, values);
if (rowId > 0) {
Uri uri = ContentUris.appendId(
WaypointsColumns.CONTENT_URI.buildUpon(), rowId).build();
@@ -369,14 +338,14 @@ public class MyTracksProvider extends ContentProvider {
qb.setTables(TracksColumns.TABLE_NAME);
qb.appendWhere("_id=" + url.getPathSegments().get(1));
} else if (match == WAYPOINTS) {
qb.setTables(WAYPOINTS_TABLE);
qb.setTables(WaypointsColumns.TABLE_NAME);
if (sort != null) {
sortOrder = sort;
} else {
sortOrder = WaypointsColumns.DEFAULT_SORT_ORDER;
}
} else if (match == WAYPOINTS_ID) {
qb.setTables(WAYPOINTS_TABLE);
qb.setTables(WaypointsColumns.TABLE_NAME);
qb.appendWhere("_id=" + url.getPathSegments().get(1));
} else {
throw new IllegalArgumentException("Unknown URL " + url);
@@ -417,10 +386,10 @@ public class MyTracksProvider extends ContentProvider {
: ""),
selectionArgs);
} else if (match == WAYPOINTS) {
count = db.update(WAYPOINTS_TABLE, values, where, selectionArgs);
count = db.update(WaypointsColumns.TABLE_NAME, values, where, selectionArgs);
} else if (match == WAYPOINTS_ID) {
String segment = url.getPathSegments().get(1);
count = db.update(WAYPOINTS_TABLE, values, "_id=" + segment
count = db.update(WaypointsColumns.TABLE_NAME, values, "_id=" + segment
+ (!TextUtils.isEmpty(where)
? " AND (" + where + ')'
: ""),
@@ -1,46 +0,0 @@
/*
* 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.io.backup;
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 com.google.android.apps.mytracks.content.WaypointsColumns;
public class BackupColumns {
/** Columns that go into the backup. */
public static final String[] WAYPOINTS_BACKUP_COLUMNS = {
WaypointsColumns._ID, WaypointsColumns.TRACKID, WaypointsColumns.NAME,
WaypointsColumns.DESCRIPTION, WaypointsColumns.CATEGORY, WaypointsColumns.ICON,
WaypointsColumns.TYPE, WaypointsColumns.LENGTH, WaypointsColumns.DURATION,
WaypointsColumns.STARTTIME, WaypointsColumns.STARTID, WaypointsColumns.STOPID,
WaypointsColumns.LATITUDE, WaypointsColumns.LONGITUDE, WaypointsColumns.ALTITUDE,
WaypointsColumns.BEARING, WaypointsColumns.TIME, WaypointsColumns.ACCURACY,
WaypointsColumns.SPEED, WaypointsColumns.TOTALDISTANCE, WaypointsColumns.TOTALTIME,
WaypointsColumns.MOVINGTIME, WaypointsColumns.AVGSPEED, WaypointsColumns.AVGMOVINGSPEED,
WaypointsColumns.MAXSPEED, WaypointsColumns.MINELEVATION, WaypointsColumns.MAXELEVATION,
WaypointsColumns.ELEVATIONGAIN, WaypointsColumns.MINGRADE, WaypointsColumns.MAXGRADE };
public static final byte[] WAYPOINTS_BACKUP_COLUMN_TYPES = {
LONG_TYPE_ID, LONG_TYPE_ID, STRING_TYPE_ID, STRING_TYPE_ID,
STRING_TYPE_ID, STRING_TYPE_ID, INT_TYPE_ID, FLOAT_TYPE_ID, LONG_TYPE_ID,
LONG_TYPE_ID, LONG_TYPE_ID, LONG_TYPE_ID, INT_TYPE_ID, INT_TYPE_ID,
FLOAT_TYPE_ID, FLOAT_TYPE_ID, LONG_TYPE_ID, FLOAT_TYPE_ID, FLOAT_TYPE_ID,
FLOAT_TYPE_ID, LONG_TYPE_ID, LONG_TYPE_ID, FLOAT_TYPE_ID, FLOAT_TYPE_ID,
FLOAT_TYPE_ID, FLOAT_TYPE_ID, FLOAT_TYPE_ID, FLOAT_TYPE_ID, FLOAT_TYPE_ID,
FLOAT_TYPE_ID };
}
@@ -156,8 +156,8 @@ class ExternalFileBackup {
TracksColumns.COLUMN_TYPES,
false);
DatabaseDumper waypointDumper = new DatabaseDumper(
BackupColumns.WAYPOINTS_BACKUP_COLUMNS,
BackupColumns.WAYPOINTS_BACKUP_COLUMN_TYPES,
WaypointsColumns.COLUMNS,
WaypointsColumns.COLUMN_TYPES,
false);
DatabaseDumper pointDumper = new DatabaseDumper(
TrackPointsColumns.COLUMNS,
@@ -628,10 +628,10 @@ public class TrackRecordingService extends Service {
lastValidLocation = null;
Waypoint waypoint = providerUtils.getFirstWaypoint(recordingTrackId);
if (waypoint != null && waypoint.getStatistics() != null) {
if (waypoint != null && waypoint.getTripStatistics() != null) {
currentWaypointId = waypoint.getId();
waypointStatsBuilder = new TripStatisticsBuilder(
waypoint.getStatistics());
waypoint.getTripStatistics());
} else {
// This should never happen, but we got to do something so life goes on:
waypointStatsBuilder = new TripStatisticsBuilder(stats.getStartTime());
@@ -1010,7 +1010,7 @@ public class TrackRecordingService extends Service {
name = getString(R.string.marker_split_name_format, nextMarkerNumber);
}
waypoint.setName(name);
waypoint.setStatistics(waypointStatsBuilder.getStatistics());
waypoint.setTripStatistics(waypointStatsBuilder.getStatistics());
waypoint.setDescription(descriptionGenerator.generateWaypointDescription(waypoint));
waypoint.setIcon(getString(R.string.marker_statistics_icon_url));
@@ -13,14 +13,18 @@
* 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;
@@ -28,6 +32,4 @@ public class ContentTypeIds {
public static final byte DOUBLE_TYPE_ID = 4;
public static final byte STRING_TYPE_ID = 5;
public static final byte BLOB_TYPE_ID = 6;
private ContentTypeIds() { /* Not instantiable */ }
}
@@ -143,8 +143,28 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
values.put(WaypointsColumns.STARTID, waypoint.getStartId());
values.put(WaypointsColumns.STOPID, waypoint.getStopId());
TripStatistics stats = waypoint.getStatistics();
Location location = waypoint.getLocation();
if (location != null) {
values.put(WaypointsColumns.LONGITUDE, (int) (location.getLongitude() * 1E6));
values.put(WaypointsColumns.LATITUDE, (int) (location.getLatitude() * 1E6));
values.put(WaypointsColumns.TIME, location.getTime());
if (location.hasAltitude()) {
values.put(WaypointsColumns.ALTITUDE, location.getAltitude());
}
if (location.hasAccuracy()) {
values.put(WaypointsColumns.ACCURACY, location.getAccuracy());
}
if (location.hasSpeed()) {
values.put(WaypointsColumns.SPEED, location.getSpeed());
}
if (location.hasBearing()) {
values.put(WaypointsColumns.BEARING, location.getBearing());
}
}
TripStatistics stats = waypoint.getTripStatistics();
if (stats != null) {
values.put(WaypointsColumns.STARTTIME, stats.getStartTime());
values.put(WaypointsColumns.TOTALDISTANCE, stats.getTotalDistance());
values.put(WaypointsColumns.TOTALTIME, stats.getTotalTime());
values.put(WaypointsColumns.MOVINGTIME, stats.getMovingTime());
@@ -156,30 +176,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
values.put(WaypointsColumns.ELEVATIONGAIN, stats.getTotalElevationGain());
values.put(WaypointsColumns.MINGRADE, stats.getMinGrade());
values.put(WaypointsColumns.MAXGRADE, stats.getMaxGrade());
values.put(WaypointsColumns.STARTTIME, stats.getStartTime());
}
Location location = waypoint.getLocation();
if (location != null) {
values.put(WaypointsColumns.LATITUDE,
(int) (location.getLatitude() * 1E6));
values.put(WaypointsColumns.LONGITUDE,
(int) (location.getLongitude() * 1E6));
values.put(WaypointsColumns.TIME, location.getTime());
if (location.hasAltitude()) {
values.put(WaypointsColumns.ALTITUDE, location.getAltitude());
}
if (location.hasBearing()) {
values.put(WaypointsColumns.BEARING, location.getBearing());
}
if (location.hasAccuracy()) {
values.put(WaypointsColumns.ACCURACY, location.getAccuracy());
}
if (location.hasSpeed()) {
values.put(WaypointsColumns.SPEED, location.getSpeed());
}
}
return values;
}
@@ -369,8 +366,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
public Waypoint createWaypoint(Cursor cursor) {
int idxId = cursor.getColumnIndexOrThrow(WaypointsColumns._ID);
int idxName = cursor.getColumnIndexOrThrow(WaypointsColumns.NAME);
int idxDescription =
cursor.getColumnIndexOrThrow(WaypointsColumns.DESCRIPTION);
int idxDescription = cursor.getColumnIndexOrThrow(WaypointsColumns.DESCRIPTION);
int idxCategory = cursor.getColumnIndexOrThrow(WaypointsColumns.CATEGORY);
int idxIcon = cursor.getColumnIndexOrThrow(WaypointsColumns.ICON);
int idxTrackId = cursor.getColumnIndexOrThrow(WaypointsColumns.TRACKID);
@@ -381,28 +377,23 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
int idxStartId = cursor.getColumnIndexOrThrow(WaypointsColumns.STARTID);
int idxStopId = cursor.getColumnIndexOrThrow(WaypointsColumns.STOPID);
int idxTotalDistance =
cursor.getColumnIndexOrThrow(WaypointsColumns.TOTALDISTANCE);
int idxTotalTime = cursor.getColumnIndexOrThrow(WaypointsColumns.TOTALTIME);
int idxMovingTime =
cursor.getColumnIndexOrThrow(WaypointsColumns.MOVINGTIME);
int idxMaxSpeed = cursor.getColumnIndexOrThrow(WaypointsColumns.MAXSPEED);
int idxMinElevation =
cursor.getColumnIndexOrThrow(WaypointsColumns.MINELEVATION);
int idxMaxElevation =
cursor.getColumnIndexOrThrow(WaypointsColumns.MAXELEVATION);
int idxElevationGain =
cursor.getColumnIndexOrThrow(WaypointsColumns.ELEVATIONGAIN);
int idxMinGrade = cursor.getColumnIndexOrThrow(WaypointsColumns.MINGRADE);
int idxMaxGrade = cursor.getColumnIndexOrThrow(WaypointsColumns.MAXGRADE);
int idxLatitude = cursor.getColumnIndexOrThrow(WaypointsColumns.LATITUDE);
int idxLongitude = cursor.getColumnIndexOrThrow(WaypointsColumns.LONGITUDE);
int idxAltitude = cursor.getColumnIndexOrThrow(WaypointsColumns.ALTITUDE);
int idxLatitude = cursor.getColumnIndexOrThrow(WaypointsColumns.LATITUDE);
int idxTime = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME);
int idxBearing = cursor.getColumnIndexOrThrow(WaypointsColumns.BEARING);
int idxAltitude = cursor.getColumnIndexOrThrow(WaypointsColumns.ALTITUDE);
int idxAccuracy = cursor.getColumnIndexOrThrow(WaypointsColumns.ACCURACY);
int idxSpeed = cursor.getColumnIndexOrThrow(WaypointsColumns.SPEED);
int idxBearing = cursor.getColumnIndexOrThrow(WaypointsColumns.BEARING);
int idxTotalDistance = cursor.getColumnIndexOrThrow(WaypointsColumns.TOTALDISTANCE);
int idxTotalTime = cursor.getColumnIndexOrThrow(WaypointsColumns.TOTALTIME);
int idxMovingTime = cursor.getColumnIndexOrThrow(WaypointsColumns.MOVINGTIME);
int idxMaxSpeed = cursor.getColumnIndexOrThrow(WaypointsColumns.MAXSPEED);
int idxMinElevation = cursor.getColumnIndexOrThrow(WaypointsColumns.MINELEVATION);
int idxMaxElevation = cursor.getColumnIndexOrThrow(WaypointsColumns.MAXELEVATION);
int idxElevationGain = cursor.getColumnIndexOrThrow(WaypointsColumns.ELEVATIONGAIN);
int idxMinGrade = cursor.getColumnIndexOrThrow(WaypointsColumns.MINGRADE);
int idxMaxGrade = cursor.getColumnIndexOrThrow(WaypointsColumns.MAXGRADE);
Waypoint waypoint = new Waypoint();
@@ -440,73 +431,74 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
waypoint.setStopId(cursor.getLong(idxStopId));
}
TripStatistics stats = new TripStatistics();
boolean hasStats = false;
if (!cursor.isNull(idxStartTime)) {
stats.setStartTime(cursor.getLong(idxStartTime));
hasStats = true;
}
if (!cursor.isNull(idxTotalDistance)) {
stats.setTotalDistance(cursor.getFloat(idxTotalDistance));
hasStats = true;
}
if (!cursor.isNull(idxTotalTime)) {
stats.setTotalTime(cursor.getLong(idxTotalTime));
hasStats = true;
}
if (!cursor.isNull(idxMovingTime)) {
stats.setMovingTime(cursor.getLong(idxMovingTime));
hasStats = true;
}
if (!cursor.isNull(idxMaxSpeed)) {
stats.setMaxSpeed(cursor.getFloat(idxMaxSpeed));
hasStats = true;
}
if (!cursor.isNull(idxMinElevation)) {
stats.setMinElevation(cursor.getFloat(idxMinElevation));
hasStats = true;
}
if (!cursor.isNull(idxMaxElevation)) {
stats.setMaxElevation(cursor.getFloat(idxMaxElevation));
hasStats = true;
}
if (!cursor.isNull(idxElevationGain)) {
stats.setTotalElevationGain(cursor.getFloat(idxElevationGain));
hasStats = true;
}
if (!cursor.isNull(idxMinGrade)) {
stats.setMinGrade(cursor.getFloat(idxMinGrade));
hasStats = true;
}
if (!cursor.isNull(idxMaxGrade)) {
stats.setMaxGrade(cursor.getFloat(idxMaxGrade));
hasStats = true;
}
if (hasStats) {
waypoint.setStatistics(stats);
}
Location location = new Location("");
if (!cursor.isNull(idxLatitude) && !cursor.isNull(idxLongitude)) {
location.setLatitude(1. * cursor.getInt(idxLatitude) / 1E6);
if (!cursor.isNull(idxLongitude) && !cursor.isNull(idxLatitude)) {
location.setLongitude(1. * cursor.getInt(idxLongitude) / 1E6);
}
if (!cursor.isNull(idxAltitude)) {
location.setAltitude(cursor.getFloat(idxAltitude));
location.setLatitude(1. * cursor.getInt(idxLatitude) / 1E6);
}
if (!cursor.isNull(idxTime)) {
location.setTime(cursor.getLong(idxTime));
}
if (!cursor.isNull(idxBearing)) {
location.setBearing(cursor.getFloat(idxBearing));
}
if (!cursor.isNull(idxSpeed)) {
location.setSpeed(cursor.getFloat(idxSpeed));
if (!cursor.isNull(idxAltitude)) {
location.setAltitude(cursor.getFloat(idxAltitude));
}
if (!cursor.isNull(idxAccuracy)) {
location.setAccuracy(cursor.getFloat(idxAccuracy));
}
if (!cursor.isNull(idxSpeed)) {
location.setSpeed(cursor.getFloat(idxSpeed));
}
if (!cursor.isNull(idxBearing)) {
location.setBearing(cursor.getFloat(idxBearing));
}
waypoint.setLocation(location);
TripStatistics tripStatistics = new TripStatistics();
boolean hasTripStatistics = false;
if (!cursor.isNull(idxStartTime)) {
tripStatistics.setStartTime(cursor.getLong(idxStartTime));
hasTripStatistics = true;
}
if (!cursor.isNull(idxTotalDistance)) {
tripStatistics.setTotalDistance(cursor.getFloat(idxTotalDistance));
hasTripStatistics = true;
}
if (!cursor.isNull(idxTotalTime)) {
tripStatistics.setTotalTime(cursor.getLong(idxTotalTime));
hasTripStatistics = true;
}
if (!cursor.isNull(idxMovingTime)) {
tripStatistics.setMovingTime(cursor.getLong(idxMovingTime));
hasTripStatistics = true;
}
if (!cursor.isNull(idxMaxSpeed)) {
tripStatistics.setMaxSpeed(cursor.getFloat(idxMaxSpeed));
hasTripStatistics = true;
}
if (!cursor.isNull(idxMinElevation)) {
tripStatistics.setMinElevation(cursor.getFloat(idxMinElevation));
hasTripStatistics = true;
}
if (!cursor.isNull(idxMaxElevation)) {
tripStatistics.setMaxElevation(cursor.getFloat(idxMaxElevation));
hasTripStatistics = true;
}
if (!cursor.isNull(idxElevationGain)) {
tripStatistics.setTotalElevationGain(cursor.getFloat(idxElevationGain));
hasTripStatistics = true;
}
if (!cursor.isNull(idxMinGrade)) {
tripStatistics.setMinGrade(cursor.getFloat(idxMinGrade));
hasTripStatistics = true;
}
if (!cursor.isNull(idxMaxGrade)) {
tripStatistics.setMaxGrade(cursor.getFloat(idxMaxGrade));
hasTripStatistics = true;
}
if (hasTripStatistics) {
waypoint.setTripStatistics(tripStatistics);
}
return waypoint;
}
@@ -543,7 +535,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
if (nextWaypoint != null) {
Log.d(TAG, "Correcting marker " + nextWaypoint.getId()
+ " after deleted marker " + deletedWaypoint.getId());
nextWaypoint.getStatistics().merge(deletedWaypoint.getStatistics());
nextWaypoint.getTripStatistics().merge(deletedWaypoint.getTripStatistics());
nextWaypoint.setDescription(
descriptionGenerator.generateWaypointDescription(nextWaypoint));
if (!updateWaypoint(nextWaypoint)) {
@@ -59,7 +59,8 @@ public interface TrackPointsColumns extends BaseColumns {
+ ACCURACY + " FLOAT, "
+ SPEED + " FLOAT, "
+ BEARING + " FLOAT, "
+ SENSOR + " BLOB);";
+ SENSOR + " BLOB"
+ ");";
public static final String[] COLUMNS = {
_ID,
@@ -13,6 +13,7 @@
* 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;
@@ -22,51 +23,13 @@ import android.os.Parcel;
import android.os.Parcelable;
/**
* A way point. It has a location, meta data such as name, description,
* category, and icon, plus it can store track statistics for a "sub-track".
*
* TODO: hashCode and equals
*
* A waypoint.
*
* @author Leif Hendrik Wilden
* @author Rodrigo Damazio
*/
public final class Waypoint implements Parcelable {
/**
* Creator for a Waypoint object
*/
public static class Creator implements Parcelable.Creator<Waypoint> {
public Waypoint createFromParcel(Parcel source) {
ClassLoader classLoader = getClass().getClassLoader();
Waypoint waypoint = new Waypoint();
waypoint.id = source.readLong();
waypoint.name = source.readString();
waypoint.description = source.readString();
waypoint.category = source.readString();
waypoint.icon = source.readString();
waypoint.trackId = source.readLong();
waypoint.type = source.readInt();
waypoint.startId = source.readLong();
waypoint.stopId = source.readLong();
byte hasStats = source.readByte();
if (hasStats > 0) {
waypoint.stats = source.readParcelable(classLoader);
}
byte hasLocation = source.readByte();
if (hasLocation > 0) {
waypoint.location = source.readParcelable(classLoader);
}
return waypoint;
}
public Waypoint[] newArray(int size) {
return new Waypoint[size];
}
}
public static final Creator CREATOR = new Creator();
public static final int TYPE_WAYPOINT = 0;
public static final int TYPE_STATISTICS = 1;
@@ -77,22 +40,45 @@ public final class Waypoint implements Parcelable {
private String icon = "";
private long trackId = -1;
private int type = 0;
private Location location;
/** Start track point id */
private double length = 0.0;
private long duration = 0;
private long startId = -1;
/** Stop track point id */
private long stopId = -1;
private Location location = null;
private TripStatistics tripStatistics = null;
private TripStatistics stats;
public Waypoint() {}
private Waypoint(Parcel source) {
id = source.readLong();
name = source.readString();
description = source.readString();
category = source.readString();
icon = source.readString();
trackId = source.readLong();
type = 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);
}
}
/** The length of the track, without smoothing. */
private double length;
/** The total duration of the track (not from the last waypoint) */
private long duration;
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeString(name);
@@ -101,40 +87,31 @@ public final class Waypoint implements Parcelable {
dest.writeString(icon);
dest.writeLong(trackId);
dest.writeInt(type);
dest.writeDouble(length);
dest.writeLong(duration);
dest.writeLong(startId);
dest.writeLong(stopId);
dest.writeByte(stats == null ? (byte) 0 : (byte) 1);
if (stats != null) {
dest.writeParcelable(stats, 0);
}
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);
}
}
// Getters and setters:
//---------------------
public static final Parcelable.Creator<Waypoint> CREATOR = new Parcelable.Creator<Waypoint>() {
@Override
public Waypoint createFromParcel(Parcel in) {
return new Waypoint(in);
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public Location getLocation() {
return location;
}
public void setTrackId(long trackId) {
this.trackId = trackId;
}
public int describeContents() {
return 0;
}
@Override
public Waypoint[] newArray(int size) {
return new Waypoint[size];
}
};
public long getId() {
return id;
@@ -152,34 +129,6 @@ public final class Waypoint implements Parcelable {
this.name = name;
}
public long getTrackId() {
return trackId;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
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 String getDescription() {
return description;
}
@@ -196,20 +145,29 @@ public final class Waypoint implements Parcelable {
this.category = category;
}
public void setLocation(Location location) {
this.location = location;
public String getIcon() {
return icon;
}
public TripStatistics getStatistics() {
return stats;
public void setIcon(String icon) {
this.icon = icon;
}
public void setStatistics(TripStatistics stats) {
this.stats = stats;
public long getTrackId() {
return trackId;
}
// WARNING: These fields are used for internal state keeping. You probably
// want to look at getStatistics instead.
public void setTrackId(long trackId) {
this.trackId = trackId;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public double getLength() {
return length;
@@ -226,4 +184,36 @@ public final class Waypoint implements Parcelable {
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;
}
}
@@ -13,57 +13,160 @@
* 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;
/**
* Defines the URI for the tracks provider and the available column names
* and content types.
*
* Constants for waypoints table.
*
* @author Leif Hendrik Wilden
*/
public interface WaypointsColumns extends BaseColumns {
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 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";
/* All columns */
public static final String NAME = "name";
public static final String DESCRIPTION = "description";
public static final String CATEGORY = "category";
public static final String ICON = "icon";
public static final String TRACKID = "trackid";
public static final String TYPE = "type";
public static final String LENGTH = "length";
public static final String DURATION = "duration";
public static final String STARTTIME = "starttime";
public static final String STARTID = "startid";
public static final String STOPID = "stopid";
// 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 LATITUDE = "latitude";
public static final String LONGITUDE = "longitude";
public static final String ALTITUDE = "elevation";
public static final String BEARING = "bearing";
public static final String TIME = "time";
public static final String ACCURACY = "accuracy";
public static final String SPEED = "speed";
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";
public static final String TOTALTIME = "totaltime";
public static final String MOVINGTIME = "movingtime";
public static final String AVGSPEED = "avgspeed";
public static final String AVGMOVINGSPEED = "avgmovingspeed";
public static final String MAXSPEED = "maxspeed";
public static final String MINELEVATION = "minelevation";
public static final String MAXELEVATION = "maxelevation";
public static final String ELEVATIONGAIN = "elevationgain";
public static final String MINGRADE = "mingrade";
public static final String MAXGRADE = "maxgrade";
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
};
}
@@ -96,7 +96,7 @@ public class DescriptionGeneratorImplTest extends AndroidTestCase {
stats.setMaxGrade(0.42);
stats.setMinGrade(0.11);
stats.setStartTime(START_TIME);
waypoint.setStatistics(stats);
waypoint.setTripStatistics(stats);
String expected = "Total distance: 20.00 km (12.4 mi)\n"
+ "Total time: 10:00\n"
+ "Moving time: 05:00\n"
@@ -72,7 +72,7 @@ public class ChartFragmentTest extends AndroidTestCase {
.setCadence(cadenceData)
.setPower(powerData)
.build();
myTracksLocation.setSensorData(sensorDataSet);
myTracksLocation.setSensorDataSet(sensorDataSet);
// Test.
point = fillDataPointTestHelper(myTracksLocation);
assertEquals(Double.NaN, point[ChartView.HEART_RATE_SERIES + 1]);
@@ -107,7 +107,7 @@ public class ChartFragmentTest extends AndroidTestCase {
.setCadence(cadenceData)
.setPower(powerData)
.build();
myTracksLocation.setSensorData(sensorDataSet);
myTracksLocation.setSensorDataSet(sensorDataSet);
// Test.
point = fillDataPointTestHelper(myTracksLocation);
assertEquals(100.0, point[ChartView.HEART_RATE_SERIES + 1]);
@@ -104,7 +104,7 @@ public abstract class TrackFormatWriterTest extends AndroidTestCase {
.setState(Sensor.SensorState.SENDING);
Sensor.SensorDataSet sensorDataSet = Sensor.SensorDataSet.newBuilder().setPower(power)
.setCadence(cadence).setHeartRate(heartRate).setBatteryLevel(batteryLevel).build();
location.setSensorData(sensorDataSet);
location.setSensorDataSet(sensorDataSet);
}
}
@@ -507,7 +507,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
assertEquals(123L, wpt.getTrackId());
assertEquals(0.0, wpt.getLength());
assertNotNull(wpt.getLocation());
assertNotNull(wpt.getStatistics());
assertNotNull(wpt.getTripStatistics());
// TODO check the rest of the params.
// TODO: Check waypoint 2.
@@ -543,7 +543,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
assertEquals(123L, wpt.getTrackId());
assertEquals(0.0, wpt.getLength());
assertNotNull(wpt.getLocation());
assertNull(wpt.getStatistics());
assertNull(wpt.getTripStatistics());
}
@MediumTest