Add track description when sharing a url or a file with friends.

This commit is contained in:
Jimmy Shih
2012-05-16 10:17:31 -07:00
parent 7fe7ace504
commit 17c495bc97
13 changed files with 123 additions and 62 deletions
@@ -73,7 +73,7 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity {
finish();
return;
}
name.setText(getString(R.string.marker_detail_name, waypoint.getName()));
name.setText(getString(R.string.generic_name_line, waypoint.getName()));
if (waypoint.getType() == Waypoint.TYPE_WAYPOINT) {
waypointSection.setVisibility(View.VISIBLE);
statisticsSection.setVisibility(View.GONE);
@@ -81,7 +81,7 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity {
TextView markerType = (TextView) findViewById(R.id.marker_detail_waypoint_marker_type);
markerType.setText(getString(R.string.marker_detail_marker_type, waypoint.getCategory()));
TextView description = (TextView) findViewById(R.id.marker_detail_waypoint_description);
description.setText(getString(R.string.marker_detail_description, waypoint.getDescription()));
description.setText(getString(R.string.generic_description_line, waypoint.getDescription()));
} else {
waypointSection.setVisibility(View.GONE);
statisticsSection.setVisibility(View.VISIBLE);
@@ -36,7 +36,9 @@ import java.util.Vector;
public class DescriptionGeneratorImpl implements DescriptionGenerator {
private static final String HTML_LINE_BREAK = "<br>";
private static final String HTML_PARAGRAPH_SEPARATOR = "<p>";
private static final String TEXT_LINE_BREAK = "\n";
private static final String TEXT_PARAGRAPH_SEPARATOR = "\n\n";
private Context context;
@@ -46,26 +48,26 @@ public class DescriptionGeneratorImpl implements DescriptionGenerator {
@Override
public String generateTrackDescription(
Track track, Vector<Double> distances, Vector<Double> elevations) {
Track track, Vector<Double> distances, Vector<Double> elevations, boolean html) {
String paragraphSeparator = html ? HTML_PARAGRAPH_SEPARATOR : TEXT_PARAGRAPH_SEPARATOR;
String lineBreak = html ? HTML_LINE_BREAK : TEXT_LINE_BREAK;
StringBuilder builder = new StringBuilder();
// Created by
String url = context.getString(R.string.my_tracks_web_url);
builder.append(context.getString(
R.string.send_google_by_my_tracks, "<a href='http://" + url + "'>", "</a>"));
builder.append("<p>");
String beginAnchor = html
? "<a href='http://" + context.getString(R.string.my_tracks_web_url) + "'>"
: "";
String endAnchor = html ? "</a>" : "";
builder.append(context.getString(R.string.send_google_by_my_tracks, beginAnchor, endAnchor));
builder.append(paragraphSeparator);
builder.append(generateTripStatisticsDescription(track.getStatistics(), true));
// Activity type
String trackCategory = track.getCategory();
String category = trackCategory != null && trackCategory.length() > 0 ? trackCategory
: context.getString(R.string.value_unknown);
builder.append(context.getString(R.string.description_activity_type, category));
builder.append(HTML_LINE_BREAK);
writeString(track.getName(), builder, R.string.generic_name_line, lineBreak);
writeString(track.getCategory(), builder, R.string.description_activity_type, lineBreak);
writeString(track.getDescription(), builder, R.string.generic_description_line, lineBreak);
builder.append(generateTripStatisticsDescription(track.getStatistics(), html));
// Elevation chart
if (distances != null && elevations != null) {
if (html && distances != null && elevations != null) {
builder.append("<img border=\"0\" src=\""
+ ChartURLGenerator.getChartUrl(distances, elevations, track, context) + "\"/>");
builder.append(HTML_LINE_BREAK);
@@ -78,6 +80,22 @@ public class DescriptionGeneratorImpl implements DescriptionGenerator {
return generateTripStatisticsDescription(waypoint.getStatistics(), false);
}
/**
* Writes a string to a string builder.
*
* @param text the string
* @param builder the string builder
* @param resId the resource id containing one string placeholder
* @param lineBreak the line break
*/
private void writeString(String text, StringBuilder builder, int resId, String lineBreak) {
if (text == null || text.length() == 0) {
text = context.getString(R.string.value_unknown);
}
builder.append(context.getString(resId, text));
builder.append(lineBreak);
}
/**
* Generates a description for a {@link TripStatistics}.
*
@@ -109,9 +109,10 @@ public class ChooseActivityDialogFragment extends DialogFragment {
String packageName = activityInfo.applicationInfo.packageName;
String className = activityInfo.name;
long trackId = getArguments().getLong(KEY_TRACK_ID);
String trackUrl = getArguments().getString(KEY_TRACK_URL);
if (trackUrl == null) {
SendRequest sendRequest = new SendRequest(getArguments().getLong(KEY_TRACK_ID));
SendRequest sendRequest = new SendRequest(trackId);
sendRequest.setSendMaps(true);
sendRequest.setNewMap(true);
sendRequest.setSharingAppPackageName(packageName);
@@ -122,7 +123,7 @@ public class ChooseActivityDialogFragment extends DialogFragment {
dismiss();
} else {
Intent intent = IntentUtils.newShareUrlIntent(
getActivity(), trackUrl, packageName, className);
getActivity(), trackId, trackUrl, packageName, className);
startActivity(intent);
getActivity().finish();
}
@@ -197,7 +197,7 @@ public class KmlTrackWriter implements TrackFormatWriter {
printWriter.println("</gx:MultiTrack>");
printWriter.println("</Placemark>");
String name = context.getString(R.string.marker_label_end, track.getName());
String description = descriptionGenerator.generateTrackDescription(track, null, null);
String description = descriptionGenerator.generateTrackDescription(track, null, null, false);
writePlacemark(name, description, END_STYLE, lastLocation);
}
}
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.io.file;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
@@ -135,14 +136,11 @@ public class SaveActivity extends Activity {
R.string.share_track_share_file, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(savedPath)))
.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_track_subject))
.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_track_file_body_format))
.putExtra(getString(R.string.track_id_broadcast_extra), trackId)
.setType(trackFileFormat.getMimeType());
Intent intent = IntentUtils.newShareFileIntent(
SaveActivity.this, trackId, savedPath, trackFileFormat);
startActivity(
Intent.createChooser(intent, getString(R.string.share_track_picker_title)));
finish();
}
});
}
@@ -277,7 +277,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
elevations.add(elevationBuffer.getAverage());
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
track.setDescription("<p>" + track.getDescription() + "</p><p>"
+ descriptionGenerator.generateTrackDescription(track, distances, elevations) + "</p>");
+ descriptionGenerator.generateTrackDescription(track, distances, elevations, true)
+ "</p>");
String name = context.getString(R.string.marker_label_end, track.getName());
if (!createNewPoint(name, track.getDescription(), lastLocation, MARKER_TYPE_END)) {
Log.d(TAG, "Unable to create the end marker");
@@ -353,7 +353,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
String getTrackDescription(Track track, Vector<Double> distances, Vector<Double> elevations) {
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
return "<p>" + track.getDescription() + "</p><p>"
+ descriptionGenerator.generateTrackDescription(track, distances, elevations) + "</p>";
+ descriptionGenerator.generateTrackDescription(track, distances, elevations, true)
+ "</p>";
}
/**
@@ -59,7 +59,7 @@ public class UploadResultActivity extends FragmentActivity {
if (sendRequest.isSendMaps() && sendRequest.isMapsSuccess()) {
shareUrl = SendMapsUtils.getMapUrl(getTrack());
if (sendRequest.getSharingAppPackageName() != null) {
Intent intent = IntentUtils.newShareUrlIntent(this, shareUrl,
Intent intent = IntentUtils.newShareUrlIntent(this, sendRequest.getTrackId(), shareUrl,
sendRequest.getSharingAppPackageName(), sendRequest.getSharingAppClassName());
startActivity(intent);
finish();
@@ -16,11 +16,18 @@
package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
import com.google.android.maps.mytracks.R;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import java.io.File;
/**
* Utilities for creating intents.
@@ -47,21 +54,50 @@ public class IntentUtils {
}
/**
* Creates an intent to share a url with a sharing app.
* Creates an intent to share a track url with an app.
*
* @param context the context
* @param url the url
* @param trackId the track id
* @param trackUrl the track url
* @param packageName the sharing app package name
* @param className the sharing app class name
*/
public static final Intent newShareUrlIntent(
Context context, String url, String packageName, String className) {
Context context, long trackId, String trackUrl, String packageName, String className) {
Track track = MyTracksProviderUtils.Factory.get(context).getTrack(trackId);
String trackDescription = new DescriptionGeneratorImpl(context).generateTrackDescription(
track, null, null, false);
return new Intent(Intent.ACTION_SEND)
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP)
.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.share_track_subject))
.putExtra(Intent.EXTRA_TEXT, TWITTER_PACKAGE_NAME.equals(packageName)
? url : context.getString(R.string.share_track_url_body_format, url))
? trackUrl
: context.getString(R.string.share_track_share_url_body, trackUrl, trackDescription))
.setComponent(new ComponentName(packageName, className))
.setType(TEXT_PLAIN_TYPE);
}
/**
* Creates an intent to share a track file with an app.
*
* @param context the context
* @param trackId the track id
* @param filePath the file path
* @param trackFileFormat the track file format
*/
public static final Intent newShareFileIntent(
Context context, long trackId, String filePath, TrackFileFormat trackFileFormat) {
Track track = MyTracksProviderUtils.Factory.get(context).getTrack(trackId);
String trackDescription = new DescriptionGeneratorImpl(context).generateTrackDescription(
track, null, null, false);
return new Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath)))
.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.share_track_subject))
.putExtra(Intent.EXTRA_TEXT,
context.getString(R.string.share_track_share_file_body, trackDescription))
.putExtra(context.getString(R.string.track_id_broadcast_extra), trackId)
.setType(trackFileFormat.getMimeType());
}
}