forked from upstream-mirrors/OpenTracks
Addressing review suggestions for fusion tables upload warning.
This commit is contained in:
@@ -69,7 +69,7 @@ import java.util.Vector;
|
|||||||
*/
|
*/
|
||||||
public class SendToFusionTables implements Runnable {
|
public class SendToFusionTables implements Runnable {
|
||||||
|
|
||||||
private static final String CONTENT_TYPE = "application/x-www-form-urlencoded";
|
private static final String CONTENT_TYPE = "application/x-www-form-urlencoded";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener invoked when sending to fusion tables completes.
|
* Listener invoked when sending to fusion tables completes.
|
||||||
@@ -95,6 +95,9 @@ public class SendToFusionTables implements Runnable {
|
|||||||
|
|
||||||
private static final String GDATA_VERSION = "2";
|
private static final String GDATA_VERSION = "2";
|
||||||
|
|
||||||
|
/** Response line which identifies a table ID. */
|
||||||
|
private static final String TABLE_ID_LINE = "tableid";
|
||||||
|
|
||||||
// This class reports upload status to the user as a completion percentage
|
// This class reports upload status to the user as a completion percentage
|
||||||
// using a progress bar. Progress is defined as follows:
|
// using a progress bar. Progress is defined as follows:
|
||||||
//
|
//
|
||||||
@@ -148,7 +151,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.d(Constants.TAG, "Sending to Fusion tables: trackId = " + trackId);
|
Log.d(TAG, "Sending to Fusion tables: trackId = " + trackId);
|
||||||
doUpload();
|
doUpload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +184,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
// Get the track meta-data
|
// Get the track meta-data
|
||||||
Track track = providerUtils.getTrack(trackId);
|
Track track = providerUtils.getTrack(trackId);
|
||||||
if (track == null) {
|
if (track == null) {
|
||||||
Log.w(Constants.TAG, "Cannot get track.");
|
Log.w(TAG, "Cannot get track.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +215,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(Constants.TAG, "SendToFusionTables: Done: " + success);
|
Log.d(TAG, "SendToFusionTables: Done: " + success);
|
||||||
progressIndicator.setProgressValue(PROGRESS_COMPLETE);
|
progressIndicator.setProgressValue(PROGRESS_COMPLETE);
|
||||||
} finally {
|
} finally {
|
||||||
final boolean finalSuccess = success;
|
final boolean finalSuccess = success;
|
||||||
@@ -233,21 +236,21 @@ public class SendToFusionTables implements Runnable {
|
|||||||
* @return true in case of success.
|
* @return true in case of success.
|
||||||
*/
|
*/
|
||||||
private boolean createNewTable(Track track) {
|
private boolean createNewTable(Track track) {
|
||||||
Log.d(Constants.TAG, "Creating a new fusion table.");
|
Log.d(TAG, "Creating a new fusion table.");
|
||||||
String query = "CREATE TABLE '" + sqlEscape(track.getName()) +
|
String query = "CREATE TABLE '" + sqlEscape(track.getName()) +
|
||||||
"' (name:STRING,description:STRING,geometry:LOCATION,marker:STRING)";
|
"' (name:STRING,description:STRING,geometry:LOCATION,marker:STRING)";
|
||||||
|
|
||||||
List<String> resultLines = new ArrayList<String>();
|
List<String> resultLines = new ArrayList<String>();
|
||||||
boolean success = runUpdate(query, resultLines);
|
boolean success = runUpdate(query, resultLines);
|
||||||
if (success && resultLines.size() >= 2 && resultLines.get(0).equals("tableid")) {
|
if (success && resultLines.size() >= 2 && resultLines.get(0).equals(TABLE_ID_LINE)) {
|
||||||
tableId = resultLines.get(1);
|
tableId = resultLines.get(1);
|
||||||
Log.d(Constants.TAG, "tableId = " + tableId);
|
Log.d(TAG, "tableId = " + tableId);
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean makeTableUnlisted() {
|
private boolean makeTableUnlisted() {
|
||||||
Log.d(Constants.TAG, "Setting visibility to unlisted.");
|
Log.d(TAG, "Setting visibility to unlisted.");
|
||||||
String query = "UPDATE TABLE " + tableId + " SET VISIBILITY = UNLISTED";
|
String query = "UPDATE TABLE " + tableId + " SET VISIBILITY = UNLISTED";
|
||||||
return runUpdate(query, null);
|
return runUpdate(query, null);
|
||||||
}
|
}
|
||||||
@@ -286,7 +289,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
*/
|
*/
|
||||||
private boolean createNewPoint(String name, String description, Location location,
|
private boolean createNewPoint(String name, String description, Location location,
|
||||||
String marker) {
|
String marker) {
|
||||||
Log.d(Constants.TAG, "Creating a new row with a point.");
|
Log.d(TAG, "Creating a new row with a point.");
|
||||||
String query = "INSERT INTO " + tableId + " (name,description,geometry,marker) VALUES "
|
String query = "INSERT INTO " + tableId + " (name,description,geometry,marker) VALUES "
|
||||||
+ values(name, description, getKmlPoint(location), marker);
|
+ values(name, description, getKmlPoint(location), marker);
|
||||||
return runUpdate(query, null);
|
return runUpdate(query, null);
|
||||||
@@ -299,7 +302,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
* @return true in case of success.
|
* @return true in case of success.
|
||||||
*/
|
*/
|
||||||
private boolean createNewLineString(Track track) {
|
private boolean createNewLineString(Track track) {
|
||||||
Log.d(Constants.TAG, "Creating a new row with a point.");
|
Log.d(TAG, "Creating a new row with a point.");
|
||||||
String query = "INSERT INTO " + tableId
|
String query = "INSERT INTO " + tableId
|
||||||
+ " (name,description,geometry) VALUES "
|
+ " (name,description,geometry) VALUES "
|
||||||
+ values(track.getName(), track.getDescription(), getKmlLineString(track));
|
+ values(track.getName(), track.getDescription(), getKmlLineString(track));
|
||||||
@@ -317,7 +320,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
Cursor locationsCursor = providerUtils.getLocationsCursor(track.getId(), 0, -1, false);
|
Cursor locationsCursor = providerUtils.getLocationsCursor(track.getId(), 0, -1, false);
|
||||||
try {
|
try {
|
||||||
if (locationsCursor == null || !locationsCursor.moveToFirst()) {
|
if (locationsCursor == null || !locationsCursor.moveToFirst()) {
|
||||||
Log.w(Constants.TAG, "Unable to get any points to upload");
|
Log.w(TAG, "Unable to get any points to upload");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +333,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
// Limit the number of elevation readings. Ideally we would want around 250.
|
// Limit the number of elevation readings. Ideally we would want around 250.
|
||||||
int elevationSamplingFrequency =
|
int elevationSamplingFrequency =
|
||||||
Math.max(1, (int) (totalLocations / 250.0));
|
Math.max(1, (int) (totalLocations / 250.0));
|
||||||
Log.d(Constants.TAG,
|
Log.d(TAG,
|
||||||
"Using elevation sampling factor: " + elevationSamplingFrequency
|
"Using elevation sampling factor: " + elevationSamplingFrequency
|
||||||
+ " on " + totalLocations);
|
+ " on " + totalLocations);
|
||||||
double totalDistance = 0;
|
double totalDistance = 0;
|
||||||
@@ -461,7 +464,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
|
|
||||||
int numLocations = locations.size();
|
int numLocations = locations.size();
|
||||||
if (numLocations < 2) {
|
if (numLocations < 2) {
|
||||||
Log.d(Constants.TAG, "Not preparing/uploading too few points");
|
Log.d(TAG, "Not preparing/uploading too few points");
|
||||||
totalLocationsUploaded += numLocations;
|
totalLocationsUploaded += numLocations;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -477,16 +480,16 @@ public class SendToFusionTables implements Runnable {
|
|||||||
context.getString(R.string.send_google_track_part_label), totalSegmentsUploaded));
|
context.getString(R.string.send_google_track_part_label), totalSegmentsUploaded));
|
||||||
}
|
}
|
||||||
totalSegmentsUploaded++;
|
totalSegmentsUploaded++;
|
||||||
Log.d(Constants.TAG,
|
Log.d(TAG,
|
||||||
"SendToFusionTables: Prepared feature for upload w/ "
|
"SendToFusionTables: Prepared feature for upload w/ "
|
||||||
+ splitTrack.getLocations().size() + " points.");
|
+ splitTrack.getLocations().size() + " points.");
|
||||||
|
|
||||||
// Transmit tracks via GData feed:
|
// Transmit tracks via GData feed:
|
||||||
// -------------------------------
|
// -------------------------------
|
||||||
Log.d(Constants.TAG,
|
Log.d(TAG,
|
||||||
"SendToFusionTables: Uploading to table " + tableId + " w/ auth " + auth);
|
"SendToFusionTables: Uploading to table " + tableId + " w/ auth " + auth);
|
||||||
if (!uploadTrackPoints(splitTrack)) {
|
if (!uploadTrackPoints(splitTrack)) {
|
||||||
Log.e(Constants.TAG, "Uploading failed");
|
Log.e(TAG, "Uploading failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -532,7 +535,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
// Close up the last segment.
|
// Close up the last segment.
|
||||||
prepareTrackSegment(segment, splitTracks);
|
prepareTrackSegment(segment, splitTracks);
|
||||||
|
|
||||||
Log.d(Constants.TAG,
|
Log.d(TAG,
|
||||||
"MyTracksSendToFusionTables: Starting new track segment...");
|
"MyTracksSendToFusionTables: Starting new track segment...");
|
||||||
startNewTrackSegment = false;
|
startNewTrackSegment = false;
|
||||||
segment = new Track();
|
segment = new Track();
|
||||||
@@ -595,7 +598,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
int numLocations = splitTrack.getLocations().size();
|
int numLocations = splitTrack.getLocations().size();
|
||||||
if (numLocations < 2) {
|
if (numLocations < 2) {
|
||||||
// Need at least two points for a polyline:
|
// Need at least two points for a polyline:
|
||||||
Log.w(Constants.TAG, "Not uploading too few points");
|
Log.w(TAG, "Not uploading too few points");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return createNewLineString(splitTrack);
|
return createNewLineString(splitTrack);
|
||||||
@@ -625,7 +628,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
// last segment).
|
// last segment).
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
Waypoint wpt = providerUtils.createWaypoint(c);
|
Waypoint wpt = providerUtils.createWaypoint(c);
|
||||||
Log.d(Constants.TAG, "SendToFusionTables: Creating waypoint.");
|
Log.d(TAG, "SendToFusionTables: Creating waypoint.");
|
||||||
success = createNewPoint(wpt.getName(), wpt.getDescription(), wpt.getLocation(),
|
success = createNewPoint(wpt.getName(), wpt.getDescription(), wpt.getLocation(),
|
||||||
MARKER_TYPE_WAYPOINT);
|
MARKER_TYPE_WAYPOINT);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
@@ -635,7 +638,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
Log.w(Constants.TAG, "SendToFusionTables: upload waypoints failed.");
|
Log.w(TAG, "SendToFusionTables: upload waypoints failed.");
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -671,7 +674,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
wrapper.setAuthManager(auth);
|
wrapper.setAuthManager(auth);
|
||||||
wrapper.setRetryOnAuthFailure(true);
|
wrapper.setRetryOnAuthFailure(true);
|
||||||
wrapper.setClient(httpRequestFactory);
|
wrapper.setClient(httpRequestFactory);
|
||||||
Log.d(Constants.TAG, "GData connection prepared: " + this.auth);
|
Log.d(TAG, "GData connection prepared: " + this.auth);
|
||||||
wrapper.runQuery(new QueryFunction<HttpRequestFactory>() {
|
wrapper.runQuery(new QueryFunction<HttpRequestFactory>() {
|
||||||
@Override
|
@Override
|
||||||
public void query(HttpRequestFactory factory)
|
public void query(HttpRequestFactory factory)
|
||||||
@@ -692,7 +695,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
headers.setContentType(CONTENT_TYPE);
|
headers.setContentType(CONTENT_TYPE);
|
||||||
request.setHeaders(headers);
|
request.setHeaders(headers);
|
||||||
|
|
||||||
Log.d(Constants.TAG, "Running update query " + url.toString() + ": " + sql);
|
Log.d(TAG, "Running update query " + url.toString() + ": " + sql);
|
||||||
HttpResponse response;
|
HttpResponse response;
|
||||||
try {
|
try {
|
||||||
response = request.execute();
|
response = request.execute();
|
||||||
@@ -712,7 +715,7 @@ public class SendToFusionTables implements Runnable {
|
|||||||
resultReader.close();
|
resultReader.close();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.d(Constants.TAG,
|
Log.d(TAG,
|
||||||
"Query failed: " + response.getStatusMessage() + " ("
|
"Query failed: " + response.getStatusMessage() + " ("
|
||||||
+ response.getStatusCode() + ")");
|
+ response.getStatusCode() + ")");
|
||||||
throw new GDataWrapper.HttpException(
|
throw new GDataWrapper.HttpException(
|
||||||
|
|||||||
Reference in New Issue
Block a user