forked from upstream-mirrors/OpenTracks
Move Track Points table constants to TrackPointsColumns.java.
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.content;
|
||||
|
||||
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
/**
|
||||
@@ -24,7 +26,7 @@ import android.location.Location;
|
||||
*/
|
||||
public class MyTracksLocation extends Location {
|
||||
|
||||
private Sensor.SensorDataSet sensorDataSet = null;
|
||||
private SensorDataSet sensorDataSet = null;
|
||||
|
||||
/**
|
||||
* The id of this location from the provider.
|
||||
@@ -40,12 +42,12 @@ public class MyTracksLocation extends Location {
|
||||
super(provider);
|
||||
}
|
||||
|
||||
public Sensor.SensorDataSet getSensorDataSet() {
|
||||
public SensorDataSet getSensorDataSet() {
|
||||
return sensorDataSet;
|
||||
}
|
||||
|
||||
public void setSensorData(Sensor.SensorDataSet sensorData) {
|
||||
this.sensorDataSet = sensorData;
|
||||
public void setSensorDataSet(SensorDataSet sensorDataSet) {
|
||||
this.sensorDataSet = sensorDataSet;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
|
||||
+32
-37
@@ -17,6 +17,7 @@ package com.google.android.apps.mytracks.content;
|
||||
|
||||
import static com.google.android.apps.mytracks.lib.MyTracksLibConstants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
@@ -54,32 +55,29 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
* @param trackId the id of the track it belongs to
|
||||
* @return a filled in ContentValues object
|
||||
*/
|
||||
private static ContentValues createContentValues(
|
||||
Location location, long trackId) {
|
||||
private static ContentValues createContentValues(Location location, long trackId) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(TrackPointsColumns.TRACKID, trackId);
|
||||
values.put(TrackPointsColumns.LATITUDE,
|
||||
(int) (location.getLatitude() * 1E6));
|
||||
values.put(TrackPointsColumns.LONGITUDE,
|
||||
(int) (location.getLongitude() * 1E6));
|
||||
values.put(TrackPointsColumns.LONGITUDE, (int) (location.getLongitude() * 1E6));
|
||||
values.put(TrackPointsColumns.LATITUDE, (int) (location.getLatitude() * 1E6));
|
||||
|
||||
// This is an ugly hack for Samsung phones that don't properly populate the
|
||||
// time field.
|
||||
values.put(TrackPointsColumns.TIME,
|
||||
(location.getTime() == 0)
|
||||
? System.currentTimeMillis()
|
||||
: location.getTime());
|
||||
(location.getTime() == 0) ? System.currentTimeMillis() : location.getTime());
|
||||
if (location.hasAltitude()) {
|
||||
values.put(TrackPointsColumns.ALTITUDE, location.getAltitude());
|
||||
}
|
||||
if (location.hasBearing()) {
|
||||
values.put(TrackPointsColumns.BEARING, location.getBearing());
|
||||
}
|
||||
if (location.hasAccuracy()) {
|
||||
values.put(TrackPointsColumns.ACCURACY, location.getAccuracy());
|
||||
}
|
||||
if (location.hasSpeed()) {
|
||||
values.put(TrackPointsColumns.SPEED, location.getSpeed());
|
||||
}
|
||||
if (location.hasBearing()) {
|
||||
values.put(TrackPointsColumns.BEARING, location.getBearing());
|
||||
}
|
||||
|
||||
if (location instanceof MyTracksLocation) {
|
||||
MyTracksLocation mtLocation = (MyTracksLocation) location;
|
||||
if (mtLocation.getSensorDataSet() != null) {
|
||||
@@ -197,61 +195,58 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
||||
*/
|
||||
private static class CachedTrackColumnIndices {
|
||||
public final int idxId;
|
||||
public final int idxLatitude;
|
||||
public final int idxLongitude;
|
||||
public final int idxAltitude;
|
||||
public final int idxLatitude;
|
||||
public final int idxTime;
|
||||
public final int idxBearing;
|
||||
public final int idxAltitude;
|
||||
public final int idxAccuracy;
|
||||
public final int idxSpeed;
|
||||
public final int idxBearing;
|
||||
public final int idxSensor;
|
||||
|
||||
public CachedTrackColumnIndices(Cursor cursor) {
|
||||
idxId = cursor.getColumnIndex(TrackPointsColumns._ID);
|
||||
idxLatitude = cursor.getColumnIndexOrThrow(TrackPointsColumns.LATITUDE);
|
||||
idxLongitude = cursor.getColumnIndexOrThrow(TrackPointsColumns.LONGITUDE);
|
||||
idxAltitude = cursor.getColumnIndexOrThrow(TrackPointsColumns.ALTITUDE);
|
||||
idxLatitude = cursor.getColumnIndexOrThrow(TrackPointsColumns.LATITUDE);
|
||||
idxTime = cursor.getColumnIndexOrThrow(TrackPointsColumns.TIME);
|
||||
idxBearing = cursor.getColumnIndexOrThrow(TrackPointsColumns.BEARING);
|
||||
idxAltitude = cursor.getColumnIndexOrThrow(TrackPointsColumns.ALTITUDE);
|
||||
idxAccuracy = cursor.getColumnIndexOrThrow(TrackPointsColumns.ACCURACY);
|
||||
idxSpeed = cursor.getColumnIndexOrThrow(TrackPointsColumns.SPEED);
|
||||
idxBearing = cursor.getColumnIndexOrThrow(TrackPointsColumns.BEARING);
|
||||
idxSensor = cursor.getColumnIndexOrThrow(TrackPointsColumns.SENSOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void fillLocation(Cursor cursor, CachedTrackColumnIndices columnIndices,
|
||||
Location location) {
|
||||
private void fillLocation(
|
||||
Cursor cursor, CachedTrackColumnIndices columnIndices, Location location) {
|
||||
location.reset();
|
||||
|
||||
if (!cursor.isNull(columnIndices.idxLatitude)) {
|
||||
location.setLatitude(1. * cursor.getInt(columnIndices.idxLatitude) / 1E6);
|
||||
}
|
||||
if (!cursor.isNull(columnIndices.idxLongitude)) {
|
||||
location.setLongitude(1. * cursor.getInt(columnIndices.idxLongitude) / 1E6);
|
||||
}
|
||||
if (!cursor.isNull(columnIndices.idxAltitude)) {
|
||||
location.setAltitude(cursor.getFloat(columnIndices.idxAltitude));
|
||||
if (!cursor.isNull(columnIndices.idxLatitude)) {
|
||||
location.setLatitude(1. * cursor.getInt(columnIndices.idxLatitude) / 1E6);
|
||||
}
|
||||
if (!cursor.isNull(columnIndices.idxTime)) {
|
||||
location.setTime(cursor.getLong(columnIndices.idxTime));
|
||||
}
|
||||
if (!cursor.isNull(columnIndices.idxBearing)) {
|
||||
location.setBearing(cursor.getFloat(columnIndices.idxBearing));
|
||||
}
|
||||
if (!cursor.isNull(columnIndices.idxSpeed)) {
|
||||
location.setSpeed(cursor.getFloat(columnIndices.idxSpeed));
|
||||
if (!cursor.isNull(columnIndices.idxAltitude)) {
|
||||
location.setAltitude(cursor.getFloat(columnIndices.idxAltitude));
|
||||
}
|
||||
if (!cursor.isNull(columnIndices.idxAccuracy)) {
|
||||
location.setAccuracy(cursor.getFloat(columnIndices.idxAccuracy));
|
||||
}
|
||||
if (location instanceof MyTracksLocation &&
|
||||
!cursor.isNull(columnIndices.idxSensor)) {
|
||||
MyTracksLocation mtLocation = (MyTracksLocation) location;
|
||||
// TODO get the right buffer.
|
||||
Sensor.SensorDataSet sensorData;
|
||||
if (!cursor.isNull(columnIndices.idxSpeed)) {
|
||||
location.setSpeed(cursor.getFloat(columnIndices.idxSpeed));
|
||||
}
|
||||
if (!cursor.isNull(columnIndices.idxBearing)) {
|
||||
location.setBearing(cursor.getFloat(columnIndices.idxBearing));
|
||||
}
|
||||
if (location instanceof MyTracksLocation && !cursor.isNull(columnIndices.idxSensor)) {
|
||||
MyTracksLocation myTracksLocation = (MyTracksLocation) location;
|
||||
try {
|
||||
sensorData = Sensor.SensorDataSet.parseFrom(cursor.getBlob(columnIndices.idxSensor));
|
||||
mtLocation.setSensorData(sensorData);
|
||||
myTracksLocation.setSensorDataSet(
|
||||
SensorDataSet.parseFrom(cursor.getBlob(columnIndices.idxSensor)));
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
Log.w(TAG, "Failed to parse sensor data.", e);
|
||||
}
|
||||
|
||||
@@ -13,34 +13,77 @@
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Defines the URI for the track points provider and the available column names
|
||||
* and content types.
|
||||
* Constants for the track points table.
|
||||
*
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public interface TrackPointsColumns extends BaseColumns {
|
||||
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 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";
|
||||
|
||||
/* All columns */
|
||||
public static final String TRACKID = "trackid";
|
||||
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 SENSOR = "sensor";
|
||||
// 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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user