forked from upstream-mirrors/OpenTracks
More cleanups. Towards a working solution.
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.android.maps.mytracks.R;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@@ -84,6 +85,13 @@ public class DialogManager {
|
||||
builder.setTitle("Title");
|
||||
builder.setMessage("Message");
|
||||
builder.setPositiveButton(activity.getString(R.string.ok), null);
|
||||
builder.setNeutralButton(activity.getString(R.string.share_map),
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
activity.shareLinkToFusionTable(activity.sendToTrackId);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
sendToGoogleResultDialog = builder.create();
|
||||
return sendToGoogleResultDialog;
|
||||
case DIALOG_WRITE_PROGRESS:
|
||||
|
||||
@@ -126,6 +126,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
* Used by SendToGoogleResultDialog.
|
||||
*/
|
||||
|
||||
public long sendToTrackId = -1;
|
||||
public boolean sendToFusionTablesSuccess = false;
|
||||
public boolean sendToDocsSuccess = false;
|
||||
public String sendToFusionTablesTableId;
|
||||
@@ -150,6 +151,11 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
*/
|
||||
private long selectedTrackId = -1;
|
||||
|
||||
/**
|
||||
* Does the user want to share the current track.
|
||||
*/
|
||||
private boolean shareRequested = false;
|
||||
|
||||
/**
|
||||
* Utilities to deal with the database.
|
||||
*/
|
||||
@@ -549,6 +555,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
setProgressValue(50);
|
||||
setProgressMessage(R.string.progress_message_sending_docs);
|
||||
final long trackId = results.getLongExtra("trackid", selectedTrackId);
|
||||
sendToTrackId = trackId;
|
||||
final SendToDocs sender = new SendToDocs(this, authMap.get("wise"),
|
||||
authMap.get("writely"), trackId);
|
||||
Runnable onCompletion = new Runnable() {
|
||||
@@ -559,7 +566,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
public void run() {
|
||||
sendToDocsMessage = sender.getStatusMessage();
|
||||
sendToDocsSuccess = sender.wasSuccess();
|
||||
handleFusionTablesFinish();
|
||||
handleFusionTablesFinish(trackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -572,6 +579,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
break;
|
||||
}
|
||||
case MyTracksConstants.SEND_TO_GOOGLE_DIALOG: {
|
||||
shareRequested = false;
|
||||
dialogManager.showDialogSafely(DIALOG_SEND_TO_GOOGLE);
|
||||
break;
|
||||
}
|
||||
@@ -609,12 +617,13 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
dialogManager.dismissDialogSafely(DIALOG_PROGRESS);
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
handleFusionTablesFinish();
|
||||
handleFusionTablesFinish(trackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
sendToTrackId = trackId;
|
||||
final SendToFusionTables sender = new SendToFusionTables(this, auth,
|
||||
trackId, this/*progressIndicator*/, onCompletion);
|
||||
|
||||
@@ -650,8 +659,9 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
Track selectedTrack = providerUtils.getTrack(selectedTrackId);
|
||||
if (selectedTrack != null) {
|
||||
if (selectedTrack.getTableId().length() > 0) {
|
||||
shareLinkToFusionTable(selectedTrack);
|
||||
shareLinkToFusionTable(selectedTrackId);
|
||||
} else {
|
||||
shareRequested = true;
|
||||
dialogManager.showDialogSafely(DIALOG_SEND_TO_GOOGLE);
|
||||
}
|
||||
}
|
||||
@@ -793,7 +803,7 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
* Shares a link to a fusion table via external app (email, gmail, ...)
|
||||
* A chooser with apps that support text/plain will be shown to the user.
|
||||
*/
|
||||
public void shareLinkToFusionTable(Track track) {
|
||||
public void shareLinkToFusionTable(long trackId) {
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT,
|
||||
@@ -805,12 +815,13 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
getString(R.string.share_url_only_key), false);
|
||||
}
|
||||
|
||||
Track track = providerUtils.getTrack(trackId);
|
||||
String url = SendToFusionTables.getMapVisualizationUrl(track);
|
||||
String msg = shareUrlOnly ? url : String.format(
|
||||
getResources().getText(R.string.share_map_body_format).toString(), url);
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, msg);
|
||||
startActivity(Intent.createChooser(shareIntent,
|
||||
getResources().getText(R.string.share_map_subject).toString()));
|
||||
getResources().getText(R.string.share_map).toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1223,9 +1234,14 @@ public class MyTracks extends TabActivity implements OnTouchListener,
|
||||
/**
|
||||
* Notifies that uploading to fusion tables is finished.
|
||||
*/
|
||||
private void handleFusionTablesFinish() {
|
||||
dialogManager.showDialogSafely(
|
||||
DialogManager.DIALOG_SEND_TO_GOOGLE_RESULT);
|
||||
private void handleFusionTablesFinish(long trackId) {
|
||||
if (shareRequested && sendToFusionTablesSuccess) {
|
||||
// Just share
|
||||
Toast.makeText(this, getFusionTablesResultMessage(), Toast.LENGTH_LONG).show();
|
||||
shareLinkToFusionTable(trackId);
|
||||
} else {
|
||||
dialogManager.showDialogSafely(DialogManager.DIALOG_SEND_TO_GOOGLE_RESULT);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFusionTablesResultMessage() {
|
||||
|
||||
@@ -789,7 +789,7 @@ public class MyTracksMap extends MapActivity
|
||||
SubMenu share = menu.addSubMenu(0, MyTracksConstants.MENU_SHARE, 0,
|
||||
R.string.tracklist_share_track);
|
||||
share.add(0, MyTracksConstants.MENU_SHARE_LINK, 0,
|
||||
R.string.tracklist_share_link);
|
||||
R.string.tracklist_share_linkfusion);
|
||||
share.add(0, MyTracksConstants.MENU_SHARE_GPX_FILE, 0,
|
||||
R.string.tracklist_share_gpx_file);
|
||||
share.add(0, MyTracksConstants.MENU_SHARE_KML_FILE, 0,
|
||||
|
||||
@@ -29,7 +29,6 @@ import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
/**
|
||||
* A dialog where the user can choose where to send the tracks to, i.e.
|
||||
|
||||
@@ -19,11 +19,7 @@ import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.google.api.client.http.GenericUrl;
|
||||
import com.google.api.client.http.HttpRequest;
|
||||
import com.google.api.client.http.HttpResponse;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.InputStreamContent;
|
||||
import com.google.api.client.util.Strings;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -44,6 +45,7 @@ import android.database.Cursor;
|
||||
import android.location.Location;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
@@ -65,9 +67,6 @@ public class SendToFusionTables implements Runnable {
|
||||
/** The GData service id for Fusion Tables. */
|
||||
public static final String SERVICE_ID = "fusiontables";
|
||||
|
||||
/** The base url for viewing a fusion table. */
|
||||
public static final String FUSIONTABLES_TABLE_URL = "http://www.google.com/fusiontables";
|
||||
|
||||
/** The path for viewing a map visualization of a table. */
|
||||
private static final String FUSIONTABLES_MAP =
|
||||
"http://www.google.com/fusiontables/embedviz?" +
|
||||
@@ -121,12 +120,12 @@ public class SendToFusionTables implements Runnable {
|
||||
}
|
||||
|
||||
public static String getMapVisualizationUrl(Track track) {
|
||||
// TODO(leifhendrik): Determine correct bounding box and zoom level.
|
||||
Location start = track.getLocations().get(0);
|
||||
double lat = start != null ? start.getLatitude() : 37.0;
|
||||
double lng = start != null ? start.getLongitude() : -121.0;
|
||||
// TODO(leifhendrik): Determine correct bounding box and zoom level that will show the entire track.
|
||||
TripStatistics stats = track.getStatistics();
|
||||
double latE6 = stats.getBottom() + (stats.getTop() - stats.getBottom()) / 2;
|
||||
double lonE6 = stats.getLeft() + (stats.getRight() - stats.getLeft()) / 2;
|
||||
int z = 15;
|
||||
return String.format(FUSIONTABLES_MAP, track.getTableId(), lat, lng, z);
|
||||
return String.format(FUSIONTABLES_MAP, track.getTableId(), latE6 / 1.E6, lonE6 / 1.E6, z);
|
||||
}
|
||||
|
||||
private void doUpload() {
|
||||
@@ -281,7 +280,8 @@ public class SendToFusionTables implements Runnable {
|
||||
|
||||
if (totalLocationsRead == 0) {
|
||||
// Put a marker at the first point of the first valid segment:
|
||||
createNewPoint(track.getName(), track.getDescription(), loc, "large_green");
|
||||
String name = track.getName() + " " + context.getString(R.string.start);
|
||||
createNewPoint(name, "", loc, "large_green");
|
||||
}
|
||||
|
||||
// Add to the elevation profile.
|
||||
@@ -328,9 +328,10 @@ public class SendToFusionTables implements Runnable {
|
||||
+ stringUtils.generateTrackDescription(
|
||||
track, distances, elevations)
|
||||
+ "</p>");
|
||||
return createNewPoint(track.getName(), track.getDescription(), lastLocation, "large_red");
|
||||
String name = track.getName() + " " + context.getString(R.string.end);
|
||||
return createNewPoint(name, track.getDescription(), lastLocation, "large_red");
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
} finally {
|
||||
locationsCursor.close();
|
||||
@@ -600,14 +601,13 @@ public class SendToFusionTables implements Runnable {
|
||||
throws IOException, GDataWrapper.ParseException, GDataWrapper.HttpException {
|
||||
HttpRequest request = transport.buildPostRequest();
|
||||
request.headers.contentType = "application/x-www-form-urlencoded";
|
||||
String sql = "sql=" + URLEncoder.encode(query, "UTF-8");
|
||||
GenericUrl url = new GenericUrl(FUSIONTABLES_BASE_FEED_URL + "?" + sql);
|
||||
GenericUrl url = new GenericUrl(FUSIONTABLES_BASE_FEED_URL);
|
||||
request.url = url;
|
||||
//OutputStream outputStream = new ByteArrayOutputStream();
|
||||
//outputStream.write(Strings.toBytesUtf8(sql));
|
||||
//outputStream.flush();
|
||||
//request.content.writeTo(outputStream);
|
||||
Log.d(MyTracksConstants.TAG, "Running update query: " + url.toString());
|
||||
InputStreamContent isc = new InputStreamContent();
|
||||
String sql = "sql=" + URLEncoder.encode(query, "UTF-8");
|
||||
isc.inputStream = new ByteArrayInputStream(Strings.toBytesUtf8(sql));
|
||||
request.content = isc;
|
||||
Log.d(MyTracksConstants.TAG, "Running update query " + url.toString() + ": " + sql);
|
||||
HttpResponse response = request.execute();
|
||||
boolean success = response.isSuccessStatusCode;
|
||||
if (success) {
|
||||
|
||||
Reference in New Issue
Block a user