Commit ab3c2fad authored by Chris Scott's avatar Chris Scott

Implement bug fixes for isses 63 (add altitude, bearing) & 38 (post in ISO-8601 foramt)

parent b6614822
...@@ -650,7 +650,7 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -650,7 +650,7 @@ public class LocationUpdateService extends Service implements LocationListener {
Log.d(TAG, "afterexecute " + task.getStatus()); Log.d(TAG, "afterexecute " + task.getStatus());
} }
private boolean postLocation(com.tenforwardconsulting.cordova.bgloc.data.Location l) { private boolean postLocation(com.tenforwardconsulting.cordova.bgloc.data.Location l, LocationDAO dao) {
if (l == null) { if (l == null) {
Log.w(TAG, "postLocation: null location"); Log.w(TAG, "postLocation: null location");
return false; return false;
...@@ -666,9 +666,13 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -666,9 +666,13 @@ public class LocationUpdateService extends Service implements LocationListener {
location.put("longitude", l.getLongitude()); location.put("longitude", l.getLongitude());
location.put("accuracy", l.getAccuracy()); location.put("accuracy", l.getAccuracy());
location.put("speed", l.getSpeed()); location.put("speed", l.getSpeed());
location.put("recorded_at", l.getRecordedAt()); location.put("bearing", l.getBearing());
location.put("altitude", l.getAltitude());
location.put("recorded_at", dao.dateToString(l.getRecordedAt()));
params.put("location", location); params.put("location", location);
Log.i(TAG, "location: " + location.toString());
StringEntity se = new StringEntity(params.toString()); StringEntity se = new StringEntity(params.toString());
request.setEntity(se); request.setEntity(se);
request.setHeader("Accept", "application/json"); request.setHeader("Accept", "application/json");
...@@ -761,7 +765,7 @@ public class LocationUpdateService extends Service implements LocationListener { ...@@ -761,7 +765,7 @@ public class LocationUpdateService extends Service implements LocationListener {
LocationDAO locationDAO = DAOFactory.createLocationDAO(LocationUpdateService.this.getApplicationContext()); LocationDAO locationDAO = DAOFactory.createLocationDAO(LocationUpdateService.this.getApplicationContext());
for (com.tenforwardconsulting.cordova.bgloc.data.Location savedLocation : locationDAO.getAllLocations()) { for (com.tenforwardconsulting.cordova.bgloc.data.Location savedLocation : locationDAO.getAllLocations()) {
Log.d(TAG, "Posting saved location"); Log.d(TAG, "Posting saved location");
if (postLocation(savedLocation)) { if (postLocation(savedLocation, locationDAO)) {
locationDAO.deleteLocation(savedLocation); locationDAO.deleteLocation(savedLocation);
} }
} }
......
...@@ -11,6 +11,8 @@ public class Location { ...@@ -11,6 +11,8 @@ public class Location {
private Date recordedAt; private Date recordedAt;
private String accuracy; private String accuracy;
private String speed; private String speed;
private String altitude;
private String bearing;
private Long id; private Long id;
...@@ -50,6 +52,18 @@ public class Location { ...@@ -50,6 +52,18 @@ public class Location {
public void setSpeed(String speed) { public void setSpeed(String speed) {
this.speed = speed; this.speed = speed;
} }
public String getBearing() {
return bearing;
}
public void setBearing(String bearing) {
this.bearing = bearing;
}
public String getAltitude() {
return altitude;
}
public void setAltitude(String altitude) {
this.altitude = altitude;
}
public static Location fromAndroidLocation(android.location.Location originalLocation) { public static Location fromAndroidLocation(android.location.Location originalLocation) {
Location location = new Location(); Location location = new Location();
...@@ -58,6 +72,8 @@ public class Location { ...@@ -58,6 +72,8 @@ public class Location {
location.setLatitude(String.valueOf(originalLocation.getLatitude())); location.setLatitude(String.valueOf(originalLocation.getLatitude()));
location.setAccuracy(String.valueOf(originalLocation.getAccuracy())); location.setAccuracy(String.valueOf(originalLocation.getAccuracy()));
location.setSpeed(String.valueOf(originalLocation.getSpeed())); location.setSpeed(String.valueOf(originalLocation.getSpeed()));
location.setBearing(String.valueOf(originalLocation.getBearing()));
location.setAltitude(String.valueOf(originalLocation.getAltitude()));
return location; return location;
} }
......
package com.tenforwardconsulting.cordova.bgloc.data; package com.tenforwardconsulting.cordova.bgloc.data;
import java.util.Date;
public interface LocationDAO { public interface LocationDAO {
public Location[] getAllLocations(); public Location[] getAllLocations();
public boolean persistLocation(Location l); public boolean persistLocation(Location l);
public void deleteLocation(Location l); public void deleteLocation(Location l);
public String dateToString(Date date);
} }
...@@ -15,6 +15,8 @@ public class LocationOpenHelper extends SQLiteOpenHelper { ...@@ -15,6 +15,8 @@ public class LocationOpenHelper extends SQLiteOpenHelper {
" recordedAt TEXT," + " recordedAt TEXT," +
" accuracy TEXT," + " accuracy TEXT," +
" speed TEXT," + " speed TEXT," +
" bearing TEXT," +
" altitude TEXT," +
" latitude TEXT," + " latitude TEXT," +
" longitude TEXT"; " longitude TEXT";
private static final String LOCATION_TABLE_CREATE = private static final String LOCATION_TABLE_CREATE =
......
...@@ -4,6 +4,7 @@ import java.text.ParseException; ...@@ -4,6 +4,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.TimeZone;
import java.util.List; import java.util.List;
import android.content.ContentValues; import android.content.ContentValues;
...@@ -16,7 +17,7 @@ import com.tenforwardconsulting.cordova.bgloc.data.Location; ...@@ -16,7 +17,7 @@ import com.tenforwardconsulting.cordova.bgloc.data.Location;
import com.tenforwardconsulting.cordova.bgloc.data.LocationDAO; import com.tenforwardconsulting.cordova.bgloc.data.LocationDAO;
public class SQLiteLocationDAO implements LocationDAO { public class SQLiteLocationDAO implements LocationDAO {
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm'Z'";
private static final String TAG = "SQLiteLocationDAO"; private static final String TAG = "SQLiteLocationDAO";
private Context context; private Context context;
...@@ -80,6 +81,8 @@ public class SQLiteLocationDAO implements LocationDAO { ...@@ -80,6 +81,8 @@ public class SQLiteLocationDAO implements LocationDAO {
l.setLongitude(c.getString(c.getColumnIndex("longitude"))); l.setLongitude(c.getString(c.getColumnIndex("longitude")));
l.setAccuracy(c.getString(c.getColumnIndex("accuracy"))); l.setAccuracy(c.getString(c.getColumnIndex("accuracy")));
l.setSpeed(c.getString(c.getColumnIndex("speed"))); l.setSpeed(c.getString(c.getColumnIndex("speed")));
l.setAltitude(c.getString(c.getColumnIndex("altitude")));
l.setBearing(c.getString(c.getColumnIndex("bearing")));
return l; return l;
} }
...@@ -90,26 +93,31 @@ public class SQLiteLocationDAO implements LocationDAO { ...@@ -90,26 +93,31 @@ public class SQLiteLocationDAO implements LocationDAO {
values.put("longitude", location.getLongitude()); values.put("longitude", location.getLongitude());
values.put("recordedAt", dateToString(location.getRecordedAt())); values.put("recordedAt", dateToString(location.getRecordedAt()));
values.put("accuracy", location.getAccuracy()); values.put("accuracy", location.getAccuracy());
values.put("altitude", location.getAltitude());
values.put("bearing", location.getBearing());
values.put("speed", location.getSpeed()); values.put("speed", location.getSpeed());
return values; return values;
} }
public Date stringToDate(String dateTime) { public Date stringToDate(String dateTime) {
TimeZone tz = TimeZone.getTimeZone("UTC");
SimpleDateFormat iso8601Format = new SimpleDateFormat(DATE_FORMAT); SimpleDateFormat iso8601Format = new SimpleDateFormat(DATE_FORMAT);
iso8601Format.setTimeZone(tz);
Date date = null; Date date = null;
try { try {
date = iso8601Format.parse(dateTime); date = iso8601Format.parse(dateTime);
} catch (ParseException e) { } catch (ParseException e) {
Log.e("DBUtil", "Parsing ISO8601 datetime ("+ dateTime +") failed", e); Log.e("DBUtil", "Parsing ISO8601 datetime ("+ dateTime +") failed", e);
} }
return date; return date;
} }
public String dateToString(Date date) { public String dateToString(Date date) {
TimeZone tz = TimeZone.getTimeZone("UTC");
SimpleDateFormat iso8601Format = new SimpleDateFormat(DATE_FORMAT); SimpleDateFormat iso8601Format = new SimpleDateFormat(DATE_FORMAT);
iso8601Format.setTimeZone(tz);
return iso8601Format.format(date); return iso8601Format.format(date);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment