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
+28 -25
View File
@@ -630,6 +630,12 @@ limitations under the License.
translation_description="The text label for entering a description.">
Description
</string>
<string name="generic_description_line"
translation_description="A line containing a description.
%1$s description. E.g., 'At the top'.">
Description: %1$s
</string>
<string name="generic_error_title"
translation_description="The title on an alert dialog indicating error.">
Error
@@ -638,6 +644,12 @@ limitations under the License.
translation_description="The text label for entering a name.">
Name
</string>
<string name="generic_name_line"
translation_description="A line containing a name.
%1$s name. E.g., 'Track 1'.">
Name: %1$s
</string>
<string name="generic_ok"
translation_description="The text on a button to say ok.">
OK
@@ -924,18 +936,6 @@ limitations under the License.
user that the marker will be permanently deleted from the phone.">
The marker will be permanently deleted from the phone.
</string>
<string name="marker_detail_name"
translation_description="In the marker detail page, the label for the marker name.
%1$s marker name. E.g., 'Marker 1'.">
Name: %1$s
</string>
<string name="marker_detail_description"
translation_description="In the marker detail page, the label for the description.
%1$s marker description. E.g., 'At the top'.">
Description: %1$s
</string>
<string name="marker_detail_marker_type"
translation_description="In the marker detail page, the label for the marker type.
@@ -1946,36 +1946,39 @@ limitations under the License.
</string>
<!-- Share Track -->
<string name="share_track_file_body_format"
translation_description="When sharing a track file with friends, the body of the message.">
I think you might be interested in this track.\n\nTo view this track use Google Earth or other
mapping software.
</string>
<string name="share_track_picker_title"
translation_description="When sharing a track URL with friends, the title on the picker to ask
translation_description="When sharing a track with friends, the title on the picker to ask
the user to select an application.">
Select an application
</string>
<string name="share_track_share_file"
translation_description="After saving a track to SD card, the button on the result dialog to
translation_description="After saving a track to the SD card, the button on the result dialog to
share the saved track file with friends.">
Share track file
</string>
<string name="share_track_share_file_body"
translation_description="When sharing a track file with friends, the body of the message.
%1$s: track description.">
I think you might be interested in this track.\n\nTo view this track, use Google Earth or other
mapping software.\n\n%1$s
</string>
<string name="share_track_share_url"
translation_description="After sending a track to Google, the button on the result dialog to
share the uploaded track URL with friends.">
Share track URL
</string>
<string name="share_track_share_url_body"
translation_description="When sharing a track URL with friends, the body of the message.
%1$s: url. E.g, 'https://maps.google.com/maps'.
%2$s: track description.">
I think you might be interested in this track:\n\n%1$s\n\n%2$s
</string>
<string name="share_track_subject"
translation_description="When sharing a track with friends, the subject line.">
I would like to share a track with you
</string>
<string name="share_track_url_body_format"
translation_description="When sharing a track URL with friends, the body of the message.
%1$s: url. E.g, 'https://maps.google.com/maps'.">
I think you might be interested in this track:\n\n%1$s
</string>
<!-- Stats Page -->
<string name="stats_average_moving_pace"
@@ -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());
}
}
@@ -31,9 +31,10 @@ public interface DescriptionGenerator {
* @param track the track
* @param distances a vector of distances to generate the elevation chart
* @param elevations a vector of elevations to generate the elevation chart
* @param html true to output html, false to output plain text
*/
public String generateTrackDescription(
Track track, Vector<Double> distances, Vector<Double> elevations);
Track track, Vector<Double> distances, Vector<Double> elevations, boolean html);
/**
* Generate a waypoint description.
@@ -59,6 +59,9 @@ public class DescriptionGeneratorImplTest extends AndroidTestCase {
track.setCategory("hiking");
String expected = "Created by"
+ " <a href='http://www.google.com/mobile/mytracks'>My Tracks</a> on Android.<p>"
+ "Name: -<br>"
+ "Activity type: hiking<br>"
+ "Description: -<br>"
+ "Total distance: 20.00 km (12.4 mi)<br>"
+ "Total time: 10:00<br>"
+ "Moving time: 05:00<br>"
@@ -73,9 +76,8 @@ public class DescriptionGeneratorImplTest extends AndroidTestCase {
+ "Elevation gain: 6000 m (19685 ft)<br>"
+ "Max grade: 42 %<br>"
+ "Min grade: 11 %<br>"
+ "Recorded: " + StringUtils.formatDateTime(getContext(), START_TIME) + "<br>"
+ "Activity type: hiking<br>";
assertEquals(expected, descriptionGenerator.generateTrackDescription(track, null, null));
+ "Recorded: " + StringUtils.formatDateTime(getContext(), START_TIME) + "<br>";
assertEquals(expected, descriptionGenerator.generateTrackDescription(track, null, null, true));
}
/**
@@ -43,7 +43,7 @@ public class KmlTrackWriterTest extends TrackFormatWriterTest {
private class FakeDescriptionGenerator implements DescriptionGenerator {
@Override
public String generateTrackDescription(
Track aTrack, Vector<Double> distances, Vector<Double> elevations) {
Track aTrack, Vector<Double> distances, Vector<Double> elevations, boolean html) {
return FULL_TRACK_DESCRIPTION;
}