diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java index f998cd771..ef75a3b26 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java @@ -78,11 +78,12 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac private static final String[] PROJECTION = new String[] { TracksColumns._ID, TracksColumns.NAME, + TracksColumns.DESCRIPTION, TracksColumns.CATEGORY, - TracksColumns.TOTALTIME, - TracksColumns.TOTALDISTANCE, TracksColumns.STARTTIME, - TracksColumns.DESCRIPTION }; + TracksColumns.TOTALDISTANCE, + TracksColumns.TOTALTIME, + TracksColumns.ICON}; // Callback when the trackRecordingServiceConnection binding changes. private final Runnable bindChangedCallback = new Runnable() { @@ -211,12 +212,13 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac public void bindView(View view, Context context, Cursor cursor) { int idIndex = cursor.getColumnIndex(TracksColumns._ID); int nameIndex = cursor.getColumnIndex(TracksColumns.NAME); - int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY); - int timeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME); - int distanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE); - int startIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME); int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION); - + int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY); + int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME); + int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE); + int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME); + int iconIndex = cursor.getColumnIndex(TracksColumns.ICON); + boolean isRecording = cursor.getLong(idIndex) == recordingTrackId; String name = cursor.getString(nameIndex); int iconId = isRecording ? R.drawable.menu_record_track : R.drawable.track; @@ -224,10 +226,10 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac : R.string.icon_track); String category = cursor.getString(categoryIndex); String totalTime = isRecording - ? null : StringUtils.formatElapsedTime(cursor.getLong(timeIndex)); + ? null : StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex)); String totalDistance = isRecording ? null : StringUtils.formatDistance( - TrackListActivity.this, cursor.getDouble(distanceIndex), metricUnits); - long startTime = cursor.getLong(startIndex); + TrackListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits); + long startTime = cursor.getLong(startTimeIndex); String description = cursor.getString(descriptionIndex); ListItemUtils.setListItem(TrackListActivity.this, view, diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java b/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java index 5b0e01585..f4ec7bf72 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java +++ b/MyTracks/src/com/google/android/apps/mytracks/content/MyTracksProvider.java @@ -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.Constants; @@ -44,7 +45,7 @@ import android.util.Log; public class MyTracksProvider extends ContentProvider { private static final String DATABASE_NAME = "mytracks.db"; - private static final int DATABASE_VERSION = 19; + private static final int DATABASE_VERSION = 20; private static final int TRACKPOINTS = 1; private static final int TRACKPOINTS_ID = 2; private static final int TRACKS = 3; @@ -52,9 +53,8 @@ public class MyTracksProvider extends ContentProvider { private static final int WAYPOINTS = 5; private static final int WAYPOINTS_ID = 6; private static final String TRACKPOINTS_TABLE = "trackpoints"; - private static final String TRACKS_TABLE = "tracks"; private static final String WAYPOINTS_TABLE = "waypoints"; - public static final String TAG = "MyTracksProvider"; + private static final String TAG = MyTracksProvider.class.getSimpleName(); /** * Helper which creates or upgrades the database if necessary. @@ -78,33 +78,7 @@ public class MyTracksProvider extends ContentProvider { + TrackPointsColumns.SPEED + " FLOAT, " + TrackPointsColumns.BEARING + " FLOAT, " + TrackPointsColumns.SENSOR + " BLOB);"); - db.execSQL("CREATE TABLE " + TRACKS_TABLE + " (" - + TracksColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " - + TracksColumns.NAME + " STRING, " - + TracksColumns.DESCRIPTION + " STRING, " - + TracksColumns.CATEGORY + " STRING, " - + TracksColumns.STARTID + " INTEGER, " - + TracksColumns.STOPID + " INTEGER, " - + TracksColumns.STARTTIME + " INTEGER, " - + TracksColumns.STOPTIME + " INTEGER, " - + TracksColumns.NUMPOINTS + " INTEGER, " - + TracksColumns.TOTALDISTANCE + " FLOAT, " - + TracksColumns.TOTALTIME + " INTEGER, " - + TracksColumns.MOVINGTIME + " INTEGER, " - + TracksColumns.MINLAT + " INTEGER, " - + TracksColumns.MAXLAT + " INTEGER, " - + TracksColumns.MINLON + " INTEGER, " - + TracksColumns.MAXLON + " INTEGER, " - + TracksColumns.AVGSPEED + " FLOAT, " - + TracksColumns.AVGMOVINGSPEED + " FLOAT, " - + TracksColumns.MAXSPEED + " FLOAT, " - + TracksColumns.MINELEVATION + " FLOAT, " - + TracksColumns.MAXELEVATION + " FLOAT, " - + TracksColumns.ELEVATIONGAIN + " FLOAT, " - + TracksColumns.MINGRADE + " FLOAT, " - + TracksColumns.MAXGRADE + " FLOAT, " - + TracksColumns.MAPID + " STRING, " - + TracksColumns.TABLEID + " STRING);"); + db.execSQL(TracksColumns.CREATE_TABLE); db.execSQL("CREATE TABLE " + WAYPOINTS_TABLE + " (" + WaypointsColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + WaypointsColumns.NAME + " STRING, " @@ -140,30 +114,34 @@ public class MyTracksProvider extends ContentProvider { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion); if (oldVersion < 17) { - // Wipe the old data. - Log.w(TAG, "Upgrading database from version " + oldVersion + " to " - + newVersion + ", which will destroy all old data"); + // Delete the old data + Log.w(TAG, "Delete all old data"); db.execSQL("DROP TABLE IF EXISTS " + TRACKPOINTS_TABLE); - db.execSQL("DROP TABLE IF EXISTS " + TRACKS_TABLE); + db.execSQL("DROP TABLE IF EXISTS " + TracksColumns.TABLE_NAME); db.execSQL("DROP TABLE IF EXISTS " + WAYPOINTS_TABLE); onCreate(db); } else { - // Incremental updates go here. - // Each time you increase the DB version, add a corresponding if clause. - Log.w(TAG, "Upgrading database from version " + oldVersion + " to " - + newVersion); + // Incremental updates go here. For each DB version, add a corresponding if clause. - // Sensor data. + // Track points sensor column if (oldVersion <= 17) { Log.w(TAG, "Upgrade DB: Adding sensor column."); - db.execSQL("ALTER TABLE " + TRACKPOINTS_TABLE - + " ADD " + TrackPointsColumns.SENSOR + " BLOB"); + db.execSQL( + "ALTER TABLE " + TRACKPOINTS_TABLE + " ADD " + TrackPointsColumns.SENSOR + " BLOB"); } + // Tracks table id column if (oldVersion <= 18) { Log.w(TAG, "Upgrade DB: Adding tableid column."); - db.execSQL("ALTER TABLE " + TRACKS_TABLE - + " ADD " + TracksColumns.TABLEID + " STRING"); + db.execSQL("ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.TABLEID + + " STRING"); + } + // Tracks table icon column + if (oldVersion <= 19) { + Log.w(TAG, "Upgrade DB: Adding icon column."); + db.execSQL( + "ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.ICON + " STRING"); } } } @@ -221,7 +199,7 @@ public class MyTracksProvider extends ContentProvider { table = TRACKPOINTS_TABLE; break; case TRACKS: - table = TRACKS_TABLE; + table = TracksColumns.TABLE_NAME; shouldVacuum = true; break; case WAYPOINTS: @@ -350,7 +328,7 @@ public class MyTracksProvider extends ContentProvider { throw new IllegalArgumentException( "Both start time and start id values are required."); } - long rowId = db.insert(TRACKS_TABLE, TracksColumns._ID, values); + long rowId = db.insert(TracksColumns.TABLE_NAME, TracksColumns._ID, values); if (rowId > 0) { Uri uri = ContentUris.appendId( TracksColumns.CONTENT_URI.buildUpon(), rowId).build(); @@ -392,14 +370,14 @@ public class MyTracksProvider extends ContentProvider { qb.setTables(TRACKPOINTS_TABLE); qb.appendWhere("_id=" + url.getPathSegments().get(1)); } else if (match == TRACKS) { - qb.setTables(TRACKS_TABLE); + qb.setTables(TracksColumns.TABLE_NAME); if (sort != null) { sortOrder = sort; } else { sortOrder = TracksColumns.DEFAULT_SORT_ORDER; } } else if (match == TRACKS_ID) { - qb.setTables(TRACKS_TABLE); + qb.setTables(TracksColumns.TABLE_NAME); qb.appendWhere("_id=" + url.getPathSegments().get(1)); } else if (match == WAYPOINTS) { qb.setTables(WAYPOINTS_TABLE); @@ -441,10 +419,10 @@ public class MyTracksProvider extends ContentProvider { : ""), selectionArgs); } else if (match == TRACKS) { - count = db.update(TRACKS_TABLE, values, where, selectionArgs); + count = db.update(TracksColumns.TABLE_NAME, values, where, selectionArgs); } else if (match == TRACKS_ID) { String segment = url.getPathSegments().get(1); - count = db.update(TRACKS_TABLE, values, "_id=" + segment + count = db.update(TracksColumns.TABLE_NAME, values, "_id=" + segment + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""), diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/backup/BackupColumns.java b/MyTracks/src/com/google/android/apps/mytracks/io/backup/BackupColumns.java index 29bb2c869..a12020e0c 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/backup/BackupColumns.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/backup/BackupColumns.java @@ -15,9 +15,13 @@ */ package com.google.android.apps.mytracks.io.backup; -import static com.google.android.apps.mytracks.content.ContentTypeIds.*; +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 static com.google.android.apps.mytracks.content.ContentTypeIds.STRING_TYPE_ID; + import com.google.android.apps.mytracks.content.TrackPointsColumns; -import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.WaypointsColumns; public class BackupColumns { @@ -31,23 +35,6 @@ public class BackupColumns { { 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, BLOB_TYPE_ID }; - public static final String[] TRACKS_BACKUP_COLUMNS = { - TracksColumns._ID, TracksColumns.NAME, TracksColumns.DESCRIPTION, TracksColumns.CATEGORY, - TracksColumns.STARTID, TracksColumns.STOPID, TracksColumns.STARTTIME, TracksColumns.STOPTIME, - TracksColumns.NUMPOINTS, TracksColumns.TOTALDISTANCE, TracksColumns.TOTALTIME, - TracksColumns.MOVINGTIME, TracksColumns.AVGSPEED, TracksColumns.AVGMOVINGSPEED, - TracksColumns.MAXSPEED, TracksColumns.MINELEVATION, TracksColumns.MAXELEVATION, - TracksColumns.ELEVATIONGAIN, TracksColumns.MINGRADE, TracksColumns.MAXGRADE, - TracksColumns.MINLAT, TracksColumns.MAXLAT, TracksColumns.MINLON, TracksColumns.MAXLON, - TracksColumns.MAPID, TracksColumns.TABLEID}; - public static final byte[] TRACKS_BACKUP_COLUMN_TYPES = { - LONG_TYPE_ID, STRING_TYPE_ID, STRING_TYPE_ID, STRING_TYPE_ID, - LONG_TYPE_ID, LONG_TYPE_ID, LONG_TYPE_ID, LONG_TYPE_ID, INT_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, INT_TYPE_ID, INT_TYPE_ID, INT_TYPE_ID, INT_TYPE_ID, STRING_TYPE_ID, - STRING_TYPE_ID}; - public static final String[] WAYPOINTS_BACKUP_COLUMNS = { WaypointsColumns._ID, WaypointsColumns.TRACKID, WaypointsColumns.NAME, WaypointsColumns.DESCRIPTION, WaypointsColumns.CATEGORY, WaypointsColumns.ICON, diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/backup/ExternalFileBackup.java b/MyTracks/src/com/google/android/apps/mytracks/io/backup/ExternalFileBackup.java index 7fe2b3c2b..3e9468ac9 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/backup/ExternalFileBackup.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/backup/ExternalFileBackup.java @@ -152,8 +152,8 @@ class ExternalFileBackup { // Create all the auxiliary classes that will do the writing PreferenceBackupHelper preferencesHelper = new PreferenceBackupHelper(); DatabaseDumper trackDumper = new DatabaseDumper( - BackupColumns.TRACKS_BACKUP_COLUMNS, - BackupColumns.TRACKS_BACKUP_COLUMN_TYPES, + TracksColumns.COLUMNS, + TracksColumns.COLUMN_TYPES, false); DatabaseDumper waypointDumper = new DatabaseDumper( BackupColumns.WAYPOINTS_BACKUP_COLUMNS, diff --git a/MyTracks/src/com/google/android/apps/mytracks/content/ContentTypeIds.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/ContentTypeIds.java similarity index 100% rename from MyTracks/src/com/google/android/apps/mytracks/content/ContentTypeIds.java rename to MyTracksLib/src/com/google/android/apps/mytracks/content/ContentTypeIds.java diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java index 78320f6a8..e78116d78 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/MyTracksProviderUtilsImpl.java @@ -100,21 +100,19 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { } values.put(TracksColumns.NAME, track.getName()); values.put(TracksColumns.DESCRIPTION, track.getDescription()); - values.put(TracksColumns.MAPID, track.getMapId()); - values.put(TracksColumns.TABLEID, track.getTableId()); values.put(TracksColumns.CATEGORY, track.getCategory()); - values.put(TracksColumns.NUMPOINTS, track.getNumberOfPoints()); values.put(TracksColumns.STARTID, track.getStartId()); + values.put(TracksColumns.STOPID, track.getStopId()); values.put(TracksColumns.STARTTIME, stats.getStartTime()); values.put(TracksColumns.STOPTIME, stats.getStopTime()); - values.put(TracksColumns.STOPID, track.getStopId()); + values.put(TracksColumns.NUMPOINTS, track.getNumberOfPoints()); values.put(TracksColumns.TOTALDISTANCE, stats.getTotalDistance()); values.put(TracksColumns.TOTALTIME, stats.getTotalTime()); values.put(TracksColumns.MOVINGTIME, stats.getMovingTime()); - values.put(TracksColumns.MAXLAT, stats.getTop()); values.put(TracksColumns.MINLAT, stats.getBottom()); - values.put(TracksColumns.MAXLON, stats.getRight()); + values.put(TracksColumns.MAXLAT, stats.getTop()); values.put(TracksColumns.MINLON, stats.getLeft()); + values.put(TracksColumns.MAXLON, stats.getRight()); values.put(TracksColumns.AVGSPEED, stats.getAverageSpeed()); values.put(TracksColumns.AVGMOVINGSPEED, stats.getAverageMovingSpeed()); values.put(TracksColumns.MAXSPEED, stats.getMaxSpeed()); @@ -123,6 +121,9 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { values.put(TracksColumns.ELEVATIONGAIN, stats.getTotalElevationGain()); values.put(TracksColumns.MINGRADE, stats.getMinGrade()); values.put(TracksColumns.MAXGRADE, stats.getMaxGrade()); + values.put(TracksColumns.MAPID, track.getMapId()); + values.put(TracksColumns.TABLEID, track.getTableId()); + values.put(TracksColumns.ICON, track.getIcon()); return values; } @@ -267,37 +268,32 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { public Track createTrack(Cursor cursor) { int idxId = cursor.getColumnIndexOrThrow(TracksColumns._ID); int idxName = cursor.getColumnIndexOrThrow(TracksColumns.NAME); - int idxDescription = - cursor.getColumnIndexOrThrow(TracksColumns.DESCRIPTION); - int idxMapId = cursor.getColumnIndexOrThrow(TracksColumns.MAPID); - int idxTableId = cursor.getColumnIndexOrThrow(TracksColumns.TABLEID); + int idxDescription = cursor.getColumnIndexOrThrow(TracksColumns.DESCRIPTION); int idxCategory = cursor.getColumnIndexOrThrow(TracksColumns.CATEGORY); int idxStartId = cursor.getColumnIndexOrThrow(TracksColumns.STARTID); + int idxStopId = cursor.getColumnIndexOrThrow(TracksColumns.STOPID); int idxStartTime = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME); int idxStopTime = cursor.getColumnIndexOrThrow(TracksColumns.STOPTIME); - int idxStopId = cursor.getColumnIndexOrThrow(TracksColumns.STOPID); int idxNumPoints = cursor.getColumnIndexOrThrow(TracksColumns.NUMPOINTS); - int idxMaxlat = cursor.getColumnIndexOrThrow(TracksColumns.MAXLAT); - int idxMinlat = cursor.getColumnIndexOrThrow(TracksColumns.MINLAT); - int idxMaxlon = cursor.getColumnIndexOrThrow(TracksColumns.MAXLON); - int idxMinlon = cursor.getColumnIndexOrThrow(TracksColumns.MINLON); - - int idxTotalDistance = - cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE); + int idxTotalDistance = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE); int idxTotalTime = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME); int idxMovingTime = cursor.getColumnIndexOrThrow(TracksColumns.MOVINGTIME); + int idxMinlat = cursor.getColumnIndexOrThrow(TracksColumns.MINLAT); + int idxMaxlat = cursor.getColumnIndexOrThrow(TracksColumns.MAXLAT); + int idxMinlon = cursor.getColumnIndexOrThrow(TracksColumns.MINLON); + int idxMaxlon = cursor.getColumnIndexOrThrow(TracksColumns.MAXLON); int idxMaxSpeed = cursor.getColumnIndexOrThrow(TracksColumns.MAXSPEED); - int idxMinElevation = - cursor.getColumnIndexOrThrow(TracksColumns.MINELEVATION); - int idxMaxElevation = - cursor.getColumnIndexOrThrow(TracksColumns.MAXELEVATION); - int idxElevationGain = - cursor.getColumnIndexOrThrow(TracksColumns.ELEVATIONGAIN); + int idxMinElevation = cursor.getColumnIndexOrThrow(TracksColumns.MINELEVATION); + int idxMaxElevation = cursor.getColumnIndexOrThrow(TracksColumns.MAXELEVATION); + int idxElevationGain = cursor.getColumnIndexOrThrow(TracksColumns.ELEVATIONGAIN); int idxMinGrade = cursor.getColumnIndexOrThrow(TracksColumns.MINGRADE); int idxMaxGrade = cursor.getColumnIndexOrThrow(TracksColumns.MAXGRADE); + int idxMapId = cursor.getColumnIndexOrThrow(TracksColumns.MAPID); + int idxTableId = cursor.getColumnIndexOrThrow(TracksColumns.TABLEID); + int idxIcon = cursor.getColumnIndexOrThrow(TracksColumns.ICON); Track track = new Track(); - TripStatistics stats = track.getTripStatistics(); + TripStatistics tripStatistics = track.getTripStatistics(); if (!cursor.isNull(idxId)) { track.setId(cursor.getLong(idxId)); } @@ -307,66 +303,69 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils { if (!cursor.isNull(idxDescription)) { track.setDescription(cursor.getString(idxDescription)); } - if (!cursor.isNull(idxMapId)) { - track.setMapId(cursor.getString(idxMapId)); - } - if (!cursor.isNull(idxTableId)) { - track.setTableId(cursor.getString(idxTableId)); - } if (!cursor.isNull(idxCategory)) { track.setCategory(cursor.getString(idxCategory)); } if (!cursor.isNull(idxStartId)) { track.setStartId(cursor.getInt(idxStartId)); } - if (!cursor.isNull(idxStartTime)) { - stats.setStartTime(cursor.getLong(idxStartTime)); - } - if (!cursor.isNull(idxStopTime)) { - stats.setStopTime(cursor.getLong(idxStopTime)); - } if (!cursor.isNull(idxStopId)) { track.setStopId(cursor.getInt(idxStopId)); } + if (!cursor.isNull(idxStartTime)) { + tripStatistics.setStartTime(cursor.getLong(idxStartTime)); + } + if (!cursor.isNull(idxStopTime)) { + tripStatistics.setStopTime(cursor.getLong(idxStopTime)); + } if (!cursor.isNull(idxNumPoints)) { track.setNumberOfPoints(cursor.getInt(idxNumPoints)); } if (!cursor.isNull(idxTotalDistance)) { - stats.setTotalDistance(cursor.getFloat(idxTotalDistance)); + tripStatistics.setTotalDistance(cursor.getFloat(idxTotalDistance)); } if (!cursor.isNull(idxTotalTime)) { - stats.setTotalTime(cursor.getLong(idxTotalTime)); + tripStatistics.setTotalTime(cursor.getLong(idxTotalTime)); } if (!cursor.isNull(idxMovingTime)) { - stats.setMovingTime(cursor.getLong(idxMovingTime)); + tripStatistics.setMovingTime(cursor.getLong(idxMovingTime)); } - if (!cursor.isNull(idxMaxlat) - && !cursor.isNull(idxMinlat) - && !cursor.isNull(idxMaxlon) - && !cursor.isNull(idxMinlon)) { - int top = cursor.getInt(idxMaxlat); + if (!cursor.isNull(idxMinlat) + && !cursor.isNull(idxMaxlat) + && !cursor.isNull(idxMinlon) + && !cursor.isNull(idxMaxlon)) { int bottom = cursor.getInt(idxMinlat); - int right = cursor.getInt(idxMaxlon); + int top = cursor.getInt(idxMaxlat); int left = cursor.getInt(idxMinlon); - stats.setBounds(left, top, right, bottom); + int right = cursor.getInt(idxMaxlon); + tripStatistics.setBounds(left, top, right, bottom); } if (!cursor.isNull(idxMaxSpeed)) { - stats.setMaxSpeed(cursor.getFloat(idxMaxSpeed)); + tripStatistics.setMaxSpeed(cursor.getFloat(idxMaxSpeed)); } if (!cursor.isNull(idxMinElevation)) { - stats.setMinElevation(cursor.getFloat(idxMinElevation)); + tripStatistics.setMinElevation(cursor.getFloat(idxMinElevation)); } if (!cursor.isNull(idxMaxElevation)) { - stats.setMaxElevation(cursor.getFloat(idxMaxElevation)); + tripStatistics.setMaxElevation(cursor.getFloat(idxMaxElevation)); } if (!cursor.isNull(idxElevationGain)) { - stats.setTotalElevationGain(cursor.getFloat(idxElevationGain)); + tripStatistics.setTotalElevationGain(cursor.getFloat(idxElevationGain)); } if (!cursor.isNull(idxMinGrade)) { - stats.setMinGrade(cursor.getFloat(idxMinGrade)); + tripStatistics.setMinGrade(cursor.getFloat(idxMinGrade)); } if (!cursor.isNull(idxMaxGrade)) { - stats.setMaxGrade(cursor.getFloat(idxMaxGrade)); + tripStatistics.setMaxGrade(cursor.getFloat(idxMaxGrade)); + } + if (!cursor.isNull(idxMapId)) { + track.setMapId(cursor.getString(idxMapId)); + } + if (!cursor.isNull(idxTableId)) { + track.setTableId(cursor.getString(idxTableId)); + } + if (!cursor.isNull(idxIcon)) { + track.setIcon(cursor.getString(idxIcon)); } return track; } diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/Track.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/Track.java index 90923853f..d3656a64e 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/Track.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/Track.java @@ -36,7 +36,6 @@ public class Track implements Parcelable { private String name = ""; private String description = ""; private String category = ""; - private String categoryIcon = ""; private long startId = -1; private long stopId = -1; @@ -45,6 +44,7 @@ public class Track implements Parcelable { private int numberOfPoints = 0; private String mapId = ""; private String tableId = ""; + private String icon = ""; private TripStatistics tripStatistics = new TripStatistics(); @@ -58,20 +58,20 @@ public class Track implements Parcelable { name = in.readString(); description = in.readString(); category = in.readString(); - categoryIcon = in.readString(); startId = in.readLong(); stopId = in.readLong(); numberOfPoints = in.readInt(); mapId = in.readString(); tableId = in.readString(); + icon = in.readString(); ClassLoader classLoader = getClass().getClassLoader(); + tripStatistics = in.readParcelable(classLoader); + for (int i = 0; i < numberOfPoints; ++i) { Location loc = in.readParcelable(classLoader); locations.add(loc); } - - tripStatistics = in.readParcelable(classLoader); } @Override @@ -85,25 +85,25 @@ public class Track implements Parcelable { dest.writeString(name); dest.writeString(description); dest.writeString(category); - dest.writeString(categoryIcon); dest.writeLong(startId); dest.writeLong(stopId); dest.writeInt(numberOfPoints); dest.writeString(mapId); dest.writeString(tableId); + dest.writeString(icon); + dest.writeParcelable(tripStatistics, 0); for (int i = 0; i < numberOfPoints; ++i) { dest.writeParcelable(locations.get(i), 0); } - dest.writeParcelable(tripStatistics, 0); } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override + @Override public Track createFromParcel(Parcel in) { return new Track(in); } - @Override + @Override public Track[] newArray(int size) { return new Track[size]; } @@ -141,14 +141,6 @@ public class Track implements Parcelable { this.category = category; } - public String getCategoryIcon() { - return categoryIcon; - } - - public void setCategoryIcon(String categoryIcon) { - this.categoryIcon = categoryIcon; - } - public long getStartId() { return startId; } @@ -189,6 +181,22 @@ public class Track implements Parcelable { this.tableId = tableId; } + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public TripStatistics getTripStatistics() { + return tripStatistics; + } + + public void setTripStatistics(TripStatistics tripStatistics) { + this.tripStatistics = tripStatistics; + } + public void addLocation(Location l) { locations.add(l); } @@ -200,12 +208,4 @@ public class Track implements Parcelable { public void setLocations(ArrayList locations) { this.locations = locations; } - - public TripStatistics getTripStatistics() { - return tripStatistics; - } - - public void setTripStatistics(TripStatistics tripStatistics) { - this.tripStatistics = tripStatistics; - } } diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/content/TracksColumns.java b/MyTracksLib/src/com/google/android/apps/mytracks/content/TracksColumns.java index f34b686c7..916485c50 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/content/TracksColumns.java +++ b/MyTracksLib/src/com/google/android/apps/mytracks/content/TracksColumns.java @@ -20,12 +20,14 @@ import android.net.Uri; import android.provider.BaseColumns; /** - * Constants for track table. + * Constants for the tracks table. * * @author Leif Hendrik Wilden */ public interface TracksColumns extends BaseColumns { + public static final String TABLE_NAME = "tracks"; + /** * Tracks provider uri. */ @@ -47,11 +49,10 @@ public interface TracksColumns extends BaseColumns { */ public static final String DEFAULT_SORT_ORDER = "_id"; - // Tracks table columns + // 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 CATEGORY_ICON = "categoryicon"; // track activity type icon 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 @@ -60,19 +61,109 @@ public interface TracksColumns extends BaseColumns { 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 - public static final String AVGMOVINGSPEED = "avgmovingspeed"; // average - // moving speed + public static final String AVGMOVINGSPEED = "avgmovingspeed"; // average moving speed 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 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 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 CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + + NAME + " STRING, " + + DESCRIPTION + " STRING, " + + CATEGORY + " STRING, " + + STARTID + " INTEGER, " + + STOPID + " INTEGER, " + + STARTTIME + " INTEGER, " + + STOPTIME + " INTEGER, " + + NUMPOINTS + " INTEGER, " + + TOTALDISTANCE + " FLOAT, " + + TOTALTIME + " INTEGER, " + + MOVINGTIME + " INTEGER, " + + MINLAT + " INTEGER, " + + MAXLAT + " INTEGER, " + + MINLON + " INTEGER, " + + MAXLON + " INTEGER, " + + AVGSPEED + " FLOAT, " + + AVGMOVINGSPEED + " FLOAT, " + + MAXSPEED + " FLOAT, " + + MINELEVATION + " FLOAT, " + + MAXELEVATION + " FLOAT, " + + ELEVATIONGAIN + " FLOAT, " + + MINGRADE + " FLOAT, " + + MAXGRADE + " FLOAT, " + + MAPID + " STRING, " + + TABLEID + " STRING, " + + ICON + " STRING" + + ");"; + + public static final String[] COLUMNS = { + _ID, + NAME, + DESCRIPTION, + CATEGORY, + STARTID, + STOPID, + STARTTIME, + STOPTIME, + NUMPOINTS, + TOTALDISTANCE, + TOTALTIME, + MOVINGTIME, + MINLAT, + MAXLAT, + MINLON, + MAXLON, + AVGSPEED, + AVGMOVINGSPEED, + MAXSPEED, + MINELEVATION, + MAXELEVATION, + ELEVATIONGAIN, + MINGRADE, + MAXGRADE, + MAPID, + TABLEID, + ICON + }; + + 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 + }; }