diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index b9666d328b..965645f3a7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -15,6 +15,8 @@ import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; import android.support.v7.widget.SearchView; +import android.text.Html; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -30,7 +32,6 @@ import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; - import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -43,11 +44,13 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; +import net.osmand.plus.activities.ShowRouteInfoActivity.RouteInfoAdapter; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.OsmandExpandableListFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.myplaces.FavoritesActivity; +import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -473,6 +476,26 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { b.show(); } } + + private StringBuilder generateHtmlPrint() { + StringBuilder html = new StringBuilder(); + html.append("

My Favorites

"); + List groups = getMyApplication().getFavorites().getFavoriteGroups(); + for(FavoriteGroup group : groups) { + html.append("

"+group.name+"

"); + for(FavouritePoint fp : group.points) { + String url = "geo:"+((float)fp.getLatitude())+","+((float)fp.getLongitude())+"?m="+fp.getName(); + html.append("

" + fp.getName() + " - " + "geo:" + + ((float) fp.getLatitude()) + "," + ((float) fp.getLongitude()) + "
"); + + if(!Algorithms.isEmpty(fp.getDescription())) { + html.append(": " + fp.getDescription()); + } + html.append("

"); + } + } + return html; + } private void shareFavourites() { @@ -503,7 +526,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { Algorithms.fileCopy(src, dst); final Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_TEXT, "Content of the attached file Favourites.gpx:\n\n\n" + GPXUtilities.asString(gpxFile, getMyApplication())); + sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtmlPrint().toString())); sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject)); sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getActivity(), diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java index 48f4415d59..989e3d3852 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java @@ -8,6 +8,7 @@ package net.osmand.plus.activities; import java.io.File; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.util.List; @@ -19,16 +20,18 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.TurnPathHelper; -import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.util.Algorithms; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.support.v4.content.FileProvider; import android.support.v4.view.MenuItemCompat; +import android.text.Html; import android.text.TextUtils; import android.util.DisplayMetrics; import android.view.LayoutInflater; @@ -89,22 +92,41 @@ public class ShowRouteInfoActivity extends OsmandListActivity { MapActivityActions.createSaveDirections(ShowRouteInfoActivity.this, helper).show(); return true; } - if (item.getItemId() == SHARE) { - final GPXFile gpx = helper.generateGPXFileWithRoute(); - - final Intent sendIntent = new Intent(); - sendIntent.setAction(Intent.ACTION_SEND); - sendIntent.putExtra(Intent.EXTRA_TEXT, GPXUtilities.asString(gpx, getMyApplication())); - sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_route_subject)); - sendIntent.setType("application/gpx+xml"); - startActivity(sendIntent); - return true; - } - if (item.getItemId() == PRINT) { - print(); - return true; - } - + if (item.getItemId() == SHARE) { + final GPXFile gpx = helper.generateGPXFileWithRoute(); + final Uri fileUri = Uri.fromFile(new File(gpx.path)); + File dir = new File(ShowRouteInfoActivity.this.getCacheDir(), "share"); + if (!dir.exists()) { + dir.mkdir(); + } + File dst = new File(dir, "route.gpx"); + try { + FileWriter fw = new FileWriter(dst); + GPXUtilities.writeGpx(fw, gpx, getMyApplication()); + fw.close(); + final Intent sendIntent = new Intent(); + sendIntent.setAction(Intent.ACTION_SEND); + sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtml(((RouteInfoAdapter)getListAdapter()), + helper.getGeneralRouteInformation()).toString())); + sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_route_subject)); + sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri); + sendIntent.putExtra( + Intent.EXTRA_STREAM, + FileProvider.getUriForFile(ShowRouteInfoActivity.this, + ShowRouteInfoActivity.this.getPackageName() + ".fileprovider", dst)); + sendIntent.setType("text/plain"); + startActivity(sendIntent); + } catch (IOException e) { + // Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), + // Toast.LENGTH_LONG).show(); + e.printStackTrace(); + } + return true; + } + if (item.getItemId() == PRINT) { + print(); + return true; + } return super.onOptionsItemSelected(item); } @@ -254,74 +276,9 @@ public class ShowRouteInfoActivity extends OsmandListActivity { } final String FILE_NAME = "route_info.html"; - StringBuilder html = new StringBuilder(); - html.append(""); - html.append(""); - html.append(""); - html.append("Route info"); - html.append(""); - html.append(""); - html.append(""); - html.append(""); - + StringBuilder html = generateHtmlPrint(routeInfo, title); FileOutputStream fos = null; try { - if (!TextUtils.isEmpty(title)) { - html.append("

"); - html.append(title); - html.append("

"); - } - html.append(""); - final String NBSP = " "; - final String BR = "
"; - for (int i = 0; i < routeInfo.getCount(); i++) { - RouteDirectionInfo routeDirectionInfo = (RouteDirectionInfo) routeInfo - .getItem(i); - html.append(""); - StringBuilder sb = new StringBuilder(); - sb.append(OsmAndFormatter.getFormattedDistance( - routeDirectionInfo.distance, getMyApplication())); - sb.append(", "); - sb.append(getTimeDescription(routeDirectionInfo)); - String distance = sb.toString().replaceAll("\\s", NBSP); - html.append(""); - String description = routeDirectionInfo - .getDescriptionRoutePart(); - html.append(""); - RouteInfoAdapter.CumulativeInfo cumulativeInfo = routeInfo - .getRouteDirectionCumulativeInfo(i); - html.append(""); - html.append(""); - } - html.append("
"); - html.append(distance); - html.append(""); - html.append(String.valueOf(i+1) + ". " + description); - html.append(""); - sb = new StringBuilder(); - sb.append(OsmAndFormatter.getFormattedDistance( - cumulativeInfo.distance, getMyApplication())); - sb.append(" - "); - sb.append(OsmAndFormatter.getFormattedDistance( - cumulativeInfo.distance + routeDirectionInfo.distance, - getMyApplication())); - sb.append(BR); - sb.append(Algorithms.formatDuration(cumulativeInfo.time, getMyApplication().accessibilityEnabled())); - sb.append(" - "); - sb.append(Algorithms.formatDuration(cumulativeInfo.time - + routeDirectionInfo.getExpectedTime(), getMyApplication().accessibilityEnabled())); - String cumulativeTimeAndDistance = sb.toString().replaceAll("\\s", NBSP); - html.append(cumulativeTimeAndDistance); - html.append("
"); - html.append(""); - html.append(""); - file = ((OsmandApplication) getApplication()).getAppPath(FILE_NAME); fos = new FileOutputStream(file); fos.write(html.toString().getBytes("UTF-8")); @@ -342,5 +299,92 @@ public class ShowRouteInfoActivity extends OsmandListActivity { return file; } + + private StringBuilder generateHtml(RouteInfoAdapter routeInfo, String title) { + StringBuilder html = new StringBuilder(); + if (!TextUtils.isEmpty(title)) { + html.append("

"); + html.append(title); + html.append("

"); + } + final String NBSP = " "; + final String BR = "
"; + for (int i = 0; i < routeInfo.getCount(); i++) { + RouteDirectionInfo routeDirectionInfo = (RouteDirectionInfo) routeInfo.getItem(i); + StringBuilder sb = new StringBuilder(); + sb.append(OsmAndFormatter.getFormattedDistance(routeDirectionInfo.distance, getMyApplication())); + sb.append(", ").append(NBSP); + sb.append(getTimeDescription(routeDirectionInfo)); + String distance = sb.toString().replaceAll("\\s", NBSP); + String description = routeDirectionInfo.getDescriptionRoutePart(); + html.append(BR); + html.append("

" + String.valueOf(i + 1) + ". " + NBSP + description + NBSP + "(" + distance + ")

"); + } + return html; + } + + private StringBuilder generateHtmlPrint(RouteInfoAdapter routeInfo, String title) { + StringBuilder html = new StringBuilder(); + html.append(""); + html.append(""); + html.append(""); + html.append("Route info"); + html.append(""); + html.append(""); + html.append(""); + html.append(""); + + + if (!TextUtils.isEmpty(title)) { + html.append("

"); + html.append(title); + html.append("

"); + } + html.append(""); + final String NBSP = " "; + final String BR = "
"; + for (int i = 0; i < routeInfo.getCount(); i++) { + RouteDirectionInfo routeDirectionInfo = (RouteDirectionInfo) routeInfo.getItem(i); + html.append(""); + StringBuilder sb = new StringBuilder(); + sb.append(OsmAndFormatter.getFormattedDistance(routeDirectionInfo.distance, getMyApplication())); + sb.append(", "); + sb.append(getTimeDescription(routeDirectionInfo)); + String distance = sb.toString().replaceAll("\\s", NBSP); + html.append(""); + String description = routeDirectionInfo.getDescriptionRoutePart(); + html.append(""); + RouteInfoAdapter.CumulativeInfo cumulativeInfo = routeInfo.getRouteDirectionCumulativeInfo(i); + html.append(""); + html.append(""); + } + html.append("
"); + html.append(distance); + html.append(""); + html.append(String.valueOf(i + 1) + ". " + description); + html.append(""); + sb = new StringBuilder(); + sb.append(OsmAndFormatter.getFormattedDistance(cumulativeInfo.distance, getMyApplication())); + sb.append(" - "); + sb.append(OsmAndFormatter.getFormattedDistance(cumulativeInfo.distance + routeDirectionInfo.distance, + getMyApplication())); + sb.append(BR); + sb.append(Algorithms.formatDuration(cumulativeInfo.time, getMyApplication().accessibilityEnabled())); + sb.append(" - "); + sb.append(Algorithms.formatDuration(cumulativeInfo.time + routeDirectionInfo.getExpectedTime(), + getMyApplication().accessibilityEnabled())); + String cumulativeTimeAndDistance = sb.toString().replaceAll("\\s", NBSP); + html.append(cumulativeTimeAndDistance); + html.append("
"); + html.append(""); + html.append(""); + return html; + } } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index fe44ea5b78..539afd1fd6 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -820,7 +820,8 @@ public class RouteCalculationResult { // if(p == null || !i.getTurnType().isSkipToSpeak() || // (!Algorithms.objectEquals(p.getRef(), i.getRef()) && // !Algorithms.objectEquals(p.getStreetName(), i.getStreetName()))) { - if(i.getTurnType() != null && !i.getTurnType().isSkipToSpeak()) { + if(p == null || + (i.getTurnType() != null && !i.getTurnType().isSkipToSpeak())) { p = new RouteDirectionInfo(i.getAverageSpeed(), i.getTurnType()); p.routePointOffset = i.routePointOffset; p.routeEndPointOffset = i.routeEndPointOffset;