forked from upstream-mirrors/OpenTracks
Add track description when sharing a url or a file with friends.
This commit is contained in:
@@ -630,6 +630,12 @@ limitations under the License.
|
|||||||
translation_description="The text label for entering a description.">
|
translation_description="The text label for entering a description.">
|
||||||
Description
|
Description
|
||||||
</string>
|
</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"
|
<string name="generic_error_title"
|
||||||
translation_description="The title on an alert dialog indicating error.">
|
translation_description="The title on an alert dialog indicating error.">
|
||||||
Error
|
Error
|
||||||
@@ -638,6 +644,12 @@ limitations under the License.
|
|||||||
translation_description="The text label for entering a name.">
|
translation_description="The text label for entering a name.">
|
||||||
Name
|
Name
|
||||||
</string>
|
</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"
|
<string name="generic_ok"
|
||||||
translation_description="The text on a button to say ok.">
|
translation_description="The text on a button to say ok.">
|
||||||
OK
|
OK
|
||||||
@@ -924,18 +936,6 @@ limitations under the License.
|
|||||||
user that the marker will be permanently deleted from the phone.">
|
user that the marker will be permanently deleted from the phone.">
|
||||||
The marker will be permanently deleted from the phone.
|
The marker will be permanently deleted from the phone.
|
||||||
</string>
|
</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"
|
<string name="marker_detail_marker_type"
|
||||||
translation_description="In the marker detail page, the label for the marker type.
|
translation_description="In the marker detail page, the label for the marker type.
|
||||||
|
|
||||||
@@ -1946,36 +1946,39 @@ limitations under the License.
|
|||||||
</string>
|
</string>
|
||||||
|
|
||||||
<!-- Share Track -->
|
<!-- 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"
|
<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.">
|
the user to select an application.">
|
||||||
Select an application
|
Select an application
|
||||||
</string>
|
</string>
|
||||||
<string name="share_track_share_file"
|
<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 the saved track file with friends.">
|
||||||
Share track file
|
Share track file
|
||||||
</string>
|
</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"
|
<string name="share_track_share_url"
|
||||||
translation_description="After sending a track to Google, the button on the result dialog to
|
translation_description="After sending a track to Google, the button on the result dialog to
|
||||||
share the uploaded track URL with friends.">
|
share the uploaded track URL with friends.">
|
||||||
Share track URL
|
Share track URL
|
||||||
</string>
|
</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"
|
<string name="share_track_subject"
|
||||||
translation_description="When sharing a track with friends, the subject line.">
|
translation_description="When sharing a track with friends, the subject line.">
|
||||||
I would like to share a track with you
|
I would like to share a track with you
|
||||||
</string>
|
</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 -->
|
<!-- Stats Page -->
|
||||||
<string name="stats_average_moving_pace"
|
<string name="stats_average_moving_pace"
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity {
|
|||||||
finish();
|
finish();
|
||||||
return;
|
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) {
|
if (waypoint.getType() == Waypoint.TYPE_WAYPOINT) {
|
||||||
waypointSection.setVisibility(View.VISIBLE);
|
waypointSection.setVisibility(View.VISIBLE);
|
||||||
statisticsSection.setVisibility(View.GONE);
|
statisticsSection.setVisibility(View.GONE);
|
||||||
@@ -81,7 +81,7 @@ public class MarkerDetailActivity extends AbstractMyTracksActivity {
|
|||||||
TextView markerType = (TextView) findViewById(R.id.marker_detail_waypoint_marker_type);
|
TextView markerType = (TextView) findViewById(R.id.marker_detail_waypoint_marker_type);
|
||||||
markerType.setText(getString(R.string.marker_detail_marker_type, waypoint.getCategory()));
|
markerType.setText(getString(R.string.marker_detail_marker_type, waypoint.getCategory()));
|
||||||
TextView description = (TextView) findViewById(R.id.marker_detail_waypoint_description);
|
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 {
|
} else {
|
||||||
waypointSection.setVisibility(View.GONE);
|
waypointSection.setVisibility(View.GONE);
|
||||||
statisticsSection.setVisibility(View.VISIBLE);
|
statisticsSection.setVisibility(View.VISIBLE);
|
||||||
|
|||||||
+32
-14
@@ -36,7 +36,9 @@ import java.util.Vector;
|
|||||||
public class DescriptionGeneratorImpl implements DescriptionGenerator {
|
public class DescriptionGeneratorImpl implements DescriptionGenerator {
|
||||||
|
|
||||||
private static final String HTML_LINE_BREAK = "<br>";
|
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_LINE_BREAK = "\n";
|
||||||
|
private static final String TEXT_PARAGRAPH_SEPARATOR = "\n\n";
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
@@ -46,26 +48,26 @@ public class DescriptionGeneratorImpl implements DescriptionGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateTrackDescription(
|
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();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
// Created by
|
// Created by
|
||||||
String url = context.getString(R.string.my_tracks_web_url);
|
String beginAnchor = html
|
||||||
builder.append(context.getString(
|
? "<a href='http://" + context.getString(R.string.my_tracks_web_url) + "'>"
|
||||||
R.string.send_google_by_my_tracks, "<a href='http://" + url + "'>", "</a>"));
|
: "";
|
||||||
builder.append("<p>");
|
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));
|
writeString(track.getName(), builder, R.string.generic_name_line, lineBreak);
|
||||||
|
writeString(track.getCategory(), builder, R.string.description_activity_type, lineBreak);
|
||||||
// Activity type
|
writeString(track.getDescription(), builder, R.string.generic_description_line, lineBreak);
|
||||||
String trackCategory = track.getCategory();
|
builder.append(generateTripStatisticsDescription(track.getStatistics(), html));
|
||||||
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);
|
|
||||||
|
|
||||||
// Elevation chart
|
// Elevation chart
|
||||||
if (distances != null && elevations != null) {
|
if (html && distances != null && elevations != null) {
|
||||||
builder.append("<img border=\"0\" src=\""
|
builder.append("<img border=\"0\" src=\""
|
||||||
+ ChartURLGenerator.getChartUrl(distances, elevations, track, context) + "\"/>");
|
+ ChartURLGenerator.getChartUrl(distances, elevations, track, context) + "\"/>");
|
||||||
builder.append(HTML_LINE_BREAK);
|
builder.append(HTML_LINE_BREAK);
|
||||||
@@ -78,6 +80,22 @@ public class DescriptionGeneratorImpl implements DescriptionGenerator {
|
|||||||
return generateTripStatisticsDescription(waypoint.getStatistics(), false);
|
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}.
|
* Generates a description for a {@link TripStatistics}.
|
||||||
*
|
*
|
||||||
|
|||||||
+3
-2
@@ -109,9 +109,10 @@ public class ChooseActivityDialogFragment extends DialogFragment {
|
|||||||
String packageName = activityInfo.applicationInfo.packageName;
|
String packageName = activityInfo.applicationInfo.packageName;
|
||||||
String className = activityInfo.name;
|
String className = activityInfo.name;
|
||||||
|
|
||||||
|
long trackId = getArguments().getLong(KEY_TRACK_ID);
|
||||||
String trackUrl = getArguments().getString(KEY_TRACK_URL);
|
String trackUrl = getArguments().getString(KEY_TRACK_URL);
|
||||||
if (trackUrl == null) {
|
if (trackUrl == null) {
|
||||||
SendRequest sendRequest = new SendRequest(getArguments().getLong(KEY_TRACK_ID));
|
SendRequest sendRequest = new SendRequest(trackId);
|
||||||
sendRequest.setSendMaps(true);
|
sendRequest.setSendMaps(true);
|
||||||
sendRequest.setNewMap(true);
|
sendRequest.setNewMap(true);
|
||||||
sendRequest.setSharingAppPackageName(packageName);
|
sendRequest.setSharingAppPackageName(packageName);
|
||||||
@@ -122,7 +123,7 @@ public class ChooseActivityDialogFragment extends DialogFragment {
|
|||||||
dismiss();
|
dismiss();
|
||||||
} else {
|
} else {
|
||||||
Intent intent = IntentUtils.newShareUrlIntent(
|
Intent intent = IntentUtils.newShareUrlIntent(
|
||||||
getActivity(), trackUrl, packageName, className);
|
getActivity(), trackId, trackUrl, packageName, className);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
getActivity().finish();
|
getActivity().finish();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class KmlTrackWriter implements TrackFormatWriter {
|
|||||||
printWriter.println("</gx:MultiTrack>");
|
printWriter.println("</gx:MultiTrack>");
|
||||||
printWriter.println("</Placemark>");
|
printWriter.println("</Placemark>");
|
||||||
String name = context.getString(R.string.marker_label_end, track.getName());
|
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);
|
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.io.file.TrackWriterFactory.TrackFileFormat;
|
||||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -135,14 +136,11 @@ public class SaveActivity extends Activity {
|
|||||||
R.string.share_track_share_file, new DialogInterface.OnClickListener() {
|
R.string.share_track_share_file, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND)
|
Intent intent = IntentUtils.newShareFileIntent(
|
||||||
.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(savedPath)))
|
SaveActivity.this, trackId, savedPath, trackFileFormat);
|
||||||
.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());
|
|
||||||
startActivity(
|
startActivity(
|
||||||
Intent.createChooser(intent, getString(R.string.share_track_picker_title)));
|
Intent.createChooser(intent, getString(R.string.share_track_picker_title)));
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -277,7 +277,8 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
|||||||
elevations.add(elevationBuffer.getAverage());
|
elevations.add(elevationBuffer.getAverage());
|
||||||
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
||||||
track.setDescription("<p>" + track.getDescription() + "</p><p>"
|
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());
|
String name = context.getString(R.string.marker_label_end, track.getName());
|
||||||
if (!createNewPoint(name, track.getDescription(), lastLocation, MARKER_TYPE_END)) {
|
if (!createNewPoint(name, track.getDescription(), lastLocation, MARKER_TYPE_END)) {
|
||||||
Log.d(TAG, "Unable to create the end marker");
|
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) {
|
String getTrackDescription(Track track, Vector<Double> distances, Vector<Double> elevations) {
|
||||||
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
|
||||||
return "<p>" + track.getDescription() + "</p><p>"
|
return "<p>" + track.getDescription() + "</p><p>"
|
||||||
+ descriptionGenerator.generateTrackDescription(track, distances, elevations) + "</p>";
|
+ descriptionGenerator.generateTrackDescription(track, distances, elevations, true)
|
||||||
|
+ "</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -59,7 +59,7 @@ public class UploadResultActivity extends FragmentActivity {
|
|||||||
if (sendRequest.isSendMaps() && sendRequest.isMapsSuccess()) {
|
if (sendRequest.isSendMaps() && sendRequest.isMapsSuccess()) {
|
||||||
shareUrl = SendMapsUtils.getMapUrl(getTrack());
|
shareUrl = SendMapsUtils.getMapUrl(getTrack());
|
||||||
if (sendRequest.getSharingAppPackageName() != null) {
|
if (sendRequest.getSharingAppPackageName() != null) {
|
||||||
Intent intent = IntentUtils.newShareUrlIntent(this, shareUrl,
|
Intent intent = IntentUtils.newShareUrlIntent(this, sendRequest.getTrackId(), shareUrl,
|
||||||
sendRequest.getSharingAppPackageName(), sendRequest.getSharingAppClassName());
|
sendRequest.getSharingAppPackageName(), sendRequest.getSharingAppClassName());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
|
|||||||
@@ -16,11 +16,18 @@
|
|||||||
|
|
||||||
package com.google.android.apps.mytracks.util;
|
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 com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities for creating intents.
|
* 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 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 packageName the sharing app package name
|
||||||
* @param className the sharing app class name
|
* @param className the sharing app class name
|
||||||
*/
|
*/
|
||||||
public static final Intent newShareUrlIntent(
|
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)
|
return new Intent(Intent.ACTION_SEND)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP)
|
.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_SUBJECT, context.getString(R.string.share_track_subject))
|
||||||
.putExtra(Intent.EXTRA_TEXT, TWITTER_PACKAGE_NAME.equals(packageName)
|
.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))
|
.setComponent(new ComponentName(packageName, className))
|
||||||
.setType(TEXT_PLAIN_TYPE);
|
.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 track the track
|
||||||
* @param distances a vector of distances to generate the elevation chart
|
* @param distances a vector of distances to generate the elevation chart
|
||||||
* @param elevations a vector of elevations 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(
|
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.
|
* Generate a waypoint description.
|
||||||
|
|||||||
+5
-3
@@ -59,6 +59,9 @@ public class DescriptionGeneratorImplTest extends AndroidTestCase {
|
|||||||
track.setCategory("hiking");
|
track.setCategory("hiking");
|
||||||
String expected = "Created by"
|
String expected = "Created by"
|
||||||
+ " <a href='http://www.google.com/mobile/mytracks'>My Tracks</a> on Android.<p>"
|
+ " <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 distance: 20.00 km (12.4 mi)<br>"
|
||||||
+ "Total time: 10:00<br>"
|
+ "Total time: 10:00<br>"
|
||||||
+ "Moving time: 05:00<br>"
|
+ "Moving time: 05:00<br>"
|
||||||
@@ -73,9 +76,8 @@ public class DescriptionGeneratorImplTest extends AndroidTestCase {
|
|||||||
+ "Elevation gain: 6000 m (19685 ft)<br>"
|
+ "Elevation gain: 6000 m (19685 ft)<br>"
|
||||||
+ "Max grade: 42 %<br>"
|
+ "Max grade: 42 %<br>"
|
||||||
+ "Min grade: 11 %<br>"
|
+ "Min grade: 11 %<br>"
|
||||||
+ "Recorded: " + StringUtils.formatDateTime(getContext(), START_TIME) + "<br>"
|
+ "Recorded: " + StringUtils.formatDateTime(getContext(), START_TIME) + "<br>";
|
||||||
+ "Activity type: hiking<br>";
|
assertEquals(expected, descriptionGenerator.generateTrackDescription(track, null, null, true));
|
||||||
assertEquals(expected, descriptionGenerator.generateTrackDescription(track, null, null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class KmlTrackWriterTest extends TrackFormatWriterTest {
|
|||||||
private class FakeDescriptionGenerator implements DescriptionGenerator {
|
private class FakeDescriptionGenerator implements DescriptionGenerator {
|
||||||
@Override
|
@Override
|
||||||
public String generateTrackDescription(
|
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;
|
return FULL_TRACK_DESCRIPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user