forked from upstream-mirrors/OpenTracks
In Docs spreadsheet, add a Fusion Table url column.
This commit is contained in:
Binary file not shown.
@@ -124,8 +124,6 @@ public abstract class Constants {
|
|||||||
public static final String
|
public static final String
|
||||||
RESUME_TRACK_EXTRA_NAME = "com.google.android.apps.mytracks.RESUME_TRACK";
|
RESUME_TRACK_EXTRA_NAME = "com.google.android.apps.mytracks.RESUME_TRACK";
|
||||||
|
|
||||||
public static final String MAPSHOP_BASE_URL = "https://maps.google.com/maps/ms";
|
|
||||||
|
|
||||||
public static final String SETTINGS_NAME = "SettingsActivity";
|
public static final String SETTINGS_NAME = "SettingsActivity";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ import android.content.Context;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AsyncTask to send a track to Google Docs.
|
* AsyncTask to send a track to Google Docs.
|
||||||
@@ -127,6 +129,13 @@ public class SendDocsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
if (track.getCategory() != null && !track.getCategory().equals("")) {
|
if (track.getCategory() != null && !track.getCategory().equals("")) {
|
||||||
title += "-" + track.getCategory();
|
title += "-" + track.getCategory();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
title = URLEncoder.encode(title, "UTF-8");
|
||||||
|
title = title.replace('+', ' ');
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
Log.d(TAG, "No UTF-8 encoding", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the spreadsheet ID
|
// Get the spreadsheet ID
|
||||||
publishProgress(PROGRESS_GET_SPREADSHEET_ID);
|
publishProgress(PROGRESS_GET_SPREADSHEET_ID);
|
||||||
@@ -259,7 +268,8 @@ public class SendDocsAsyncTask extends AbstractSendAsyncTask {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
spreadsheetId = SendDocsUtils.createSpreadsheet(spreadsheetTitle, documentsAuthToken, context);
|
spreadsheetId = SendDocsUtils.createSpreadsheet(
|
||||||
|
spreadsheetTitle, documentsAuthToken, context);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.d(TAG, "Unable to create spreadsheet", e);
|
Log.d(TAG, "Unable to create spreadsheet", e);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -15,11 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks.io.docs;
|
package com.google.android.apps.mytracks.io.docs;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
|
||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
|
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesUtils;
|
||||||
import com.google.android.apps.mytracks.io.gdata.docs.DocumentsClient;
|
import com.google.android.apps.mytracks.io.gdata.docs.DocumentsClient;
|
||||||
import com.google.android.apps.mytracks.io.gdata.docs.SpreadsheetsClient;
|
import com.google.android.apps.mytracks.io.gdata.docs.SpreadsheetsClient;
|
||||||
import com.google.android.apps.mytracks.io.gdata.docs.SpreadsheetsClient.WorksheetEntry;
|
import com.google.android.apps.mytracks.io.gdata.docs.SpreadsheetsClient.WorksheetEntry;
|
||||||
|
import com.google.android.apps.mytracks.io.maps.SendMapsUtils;
|
||||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.apps.mytracks.util.ResourceUtils;
|
import com.google.android.apps.mytracks.util.ResourceUtils;
|
||||||
@@ -153,7 +154,7 @@ public class SendDocsUtils {
|
|||||||
URL url = new URL(CREATE_SPREADSHEET_URI);
|
URL url = new URL(CREATE_SPREADSHEET_URI);
|
||||||
URLConnection conn = url.openConnection();
|
URLConnection conn = url.openConnection();
|
||||||
conn.addRequestProperty(CONTENT_TYPE, OPENDOCUMENT_SPREADSHEET_MIME_TYPE);
|
conn.addRequestProperty(CONTENT_TYPE, OPENDOCUMENT_SPREADSHEET_MIME_TYPE);
|
||||||
conn.addRequestProperty(SLUG, URLEncoder.encode(title, "UTF-8"));
|
conn.addRequestProperty(SLUG, title);
|
||||||
conn.addRequestProperty(AUTHORIZATION, AUTHORIZATION_PREFIX + authToken);
|
conn.addRequestProperty(AUTHORIZATION, AUTHORIZATION_PREFIX + authToken);
|
||||||
conn.setDoOutput(true);
|
conn.setDoOutput(true);
|
||||||
OutputStream outputStream = conn.getOutputStream();
|
OutputStream outputStream = conn.getOutputStream();
|
||||||
@@ -311,10 +312,17 @@ public class SendDocsUtils {
|
|||||||
appendTag(builder, "maxelevation", getElevation(stats.getMaxElevation(), metricUnits));
|
appendTag(builder, "maxelevation", getElevation(stats.getMaxElevation(), metricUnits));
|
||||||
appendTag(builder, "elevationunit", elevationUnit);
|
appendTag(builder, "elevationunit", elevationUnit);
|
||||||
|
|
||||||
if (track.getMapId().length() > 0) {
|
String map = SendMapsUtils.getMapUrl(track);
|
||||||
appendTag(builder, "map", String.format(
|
if (map == null) {
|
||||||
Locale.US, "%s?msa=0&msid=%s", Constants.MAPSHOP_BASE_URL, track.getMapId()));
|
map = context.getString(R.string.value_unknown);
|
||||||
}
|
}
|
||||||
|
appendTag(builder, "map", map);
|
||||||
|
|
||||||
|
String fusionTable = SendFusionTablesUtils.getMapUrl(track);
|
||||||
|
if (fusionTable == null) {
|
||||||
|
fusionTable = context.getString(R.string.value_unknown);
|
||||||
|
}
|
||||||
|
appendTag(builder, "fusiontable", fusionTable);
|
||||||
|
|
||||||
builder.append("</entry>");
|
builder.append("</entry>");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
|
|||||||
+4
-1
@@ -52,7 +52,10 @@ public class SendFusionTablesUtils {
|
|||||||
* @return the url.
|
* @return the url.
|
||||||
*/
|
*/
|
||||||
public static String getMapUrl(Track track) {
|
public static String getMapUrl(Track track) {
|
||||||
if (track == null || track.getTripStatistics() == null || track.getTableId() == null) {
|
if (track == null
|
||||||
|
|| track.getTripStatistics() == null
|
||||||
|
|| track.getTableId() == null
|
||||||
|
|| track.getTableId().length() == 0) {
|
||||||
Log.e(TAG, "Invalid track");
|
Log.e(TAG, "Invalid track");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,11 +54,12 @@ public class SendMapsUtils {
|
|||||||
* @return the url if available.
|
* @return the url if available.
|
||||||
*/
|
*/
|
||||||
public static String getMapUrl(Track track) {
|
public static String getMapUrl(Track track) {
|
||||||
if (track == null || track.getMapId() == null) {
|
if (track == null
|
||||||
|
|| track.getMapId() == null
|
||||||
|
|| track.getMapId().length() == 0) {
|
||||||
Log.e(TAG, "Invalid track");
|
Log.e(TAG, "Invalid track");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MapsClient.buildMapUrl(track.getMapId());
|
return MapsClient.buildMapUrl(track.getMapId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user