mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
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
|
||||
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";
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,6 +38,8 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
/**
|
||||
* AsyncTask to send a track to Google Docs.
|
||||
@@ -127,6 +129,13 @@ public class SendDocsAsyncTask extends AbstractSendAsyncTask {
|
||||
if (track.getCategory() != null && !track.getCategory().equals("")) {
|
||||
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
|
||||
publishProgress(PROGRESS_GET_SPREADSHEET_ID);
|
||||
@@ -259,7 +268,8 @@ public class SendDocsAsyncTask extends AbstractSendAsyncTask {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
spreadsheetId = SendDocsUtils.createSpreadsheet(spreadsheetTitle, documentsAuthToken, context);
|
||||
spreadsheetId = SendDocsUtils.createSpreadsheet(
|
||||
spreadsheetTitle, documentsAuthToken, context);
|
||||
} catch (IOException e) {
|
||||
Log.d(TAG, "Unable to create spreadsheet", e);
|
||||
return false;
|
||||
|
||||
@@ -15,11 +15,12 @@
|
||||
*/
|
||||
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.io.fusiontables.SendFusionTablesUtils;
|
||||
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.WorksheetEntry;
|
||||
import com.google.android.apps.mytracks.io.maps.SendMapsUtils;
|
||||
import com.google.android.apps.mytracks.stats.TripStatistics;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.ResourceUtils;
|
||||
@@ -153,7 +154,7 @@ public class SendDocsUtils {
|
||||
URL url = new URL(CREATE_SPREADSHEET_URI);
|
||||
URLConnection conn = url.openConnection();
|
||||
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.setDoOutput(true);
|
||||
OutputStream outputStream = conn.getOutputStream();
|
||||
@@ -311,10 +312,17 @@ public class SendDocsUtils {
|
||||
appendTag(builder, "maxelevation", getElevation(stats.getMaxElevation(), metricUnits));
|
||||
appendTag(builder, "elevationunit", elevationUnit);
|
||||
|
||||
if (track.getMapId().length() > 0) {
|
||||
appendTag(builder, "map", String.format(
|
||||
Locale.US, "%s?msa=0&msid=%s", Constants.MAPSHOP_BASE_URL, track.getMapId()));
|
||||
String map = SendMapsUtils.getMapUrl(track);
|
||||
if (map == null) {
|
||||
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>");
|
||||
return builder.toString();
|
||||
|
||||
+4
-1
@@ -52,7 +52,10 @@ public class SendFusionTablesUtils {
|
||||
* @return the url.
|
||||
*/
|
||||
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");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -54,11 +54,12 @@ public class SendMapsUtils {
|
||||
* @return the url if available.
|
||||
*/
|
||||
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");
|
||||
return null;
|
||||
}
|
||||
|
||||
return MapsClient.buildMapUrl(track.getMapId());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user