Add an icon column in track table.

This commit is contained in:
Jimmy Shih
2012-06-13 14:52:42 -07:00
parent b4fee2de94
commit 68dabec4a6
8 changed files with 224 additions and 167 deletions
@@ -0,0 +1,33 @@
/*
* 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 {
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;
private ContentTypeIds() { /* Not instantiable */ }
}
@@ -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;
}
@@ -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<Track> CREATOR = new Parcelable.Creator<Track>() {
@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<Location> locations) {
this.locations = locations;
}
public TripStatistics getTripStatistics() {
return tripStatistics;
}
public void setTripStatistics(TripStatistics tripStatistics) {
this.tripStatistics = tripStatistics;
}
}
@@ -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
};
}