From 31ee70675a44e1ba7891daa7c83c36b947d4d178 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Wed, 15 Feb 2017 19:15:23 +0300 Subject: [PATCH] Route info screen done --- OsmAnd/AndroidManifest.xml | 1 - OsmAnd/build.gradle | 6 + OsmAnd/res/layout/route_details_header.xml | 3 +- OsmAnd/res/layout/route_info_header.xml | 265 +++++++++ OsmAnd/res/layout/route_info_layout.xml | 237 ++++++++ OsmAnd/res/layout/route_info_list_item.xml | 155 +++--- OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/strings.xml | 7 + OsmAnd/res/values/styles.xml | 2 + OsmAnd/src/net/osmand/plus/GPXUtilities.java | 121 +++++ .../osmand/plus/activities/MapActivity.java | 7 - .../plus/activities/MapActivityActions.java | 8 - .../activities/ShowRouteInfoActivity.java | 390 -------------- .../ShowRouteInfoDialogFragment.java | 506 ++++++++++++++++++ .../dashboard/DashNavigationFragment.java | 6 +- .../other/MapRouteInfoMenu.java | 8 +- .../plus/myplaces/SelectedGPXFragment.java | 102 +--- 17 files changed, 1247 insertions(+), 578 deletions(-) create mode 100644 OsmAnd/res/layout/route_info_header.xml create mode 100644 OsmAnd/res/layout/route_info_layout.xml delete mode 100644 OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java create mode 100644 OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 1f91048e96..69e0d49daa 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -179,7 +179,6 @@ - diff --git a/OsmAnd/build.gradle b/OsmAnd/build.gradle index d1b00cbf3c..aba500859c 100644 --- a/OsmAnd/build.gradle +++ b/OsmAnd/build.gradle @@ -129,6 +129,12 @@ android { dimension "version" applicationId "net.osmand.plus" } + fulldev { + dimension "version" + applicationId "net.osmand.plus" + resConfig "en" + //resConfigs "xxhdpi", "nodpi" + } // CoreVersion legacy { diff --git a/OsmAnd/res/layout/route_details_header.xml b/OsmAnd/res/layout/route_details_header.xml index a196f87b9c..d6a560b082 100644 --- a/OsmAnd/res/layout/route_details_header.xml +++ b/OsmAnd/res/layout/route_details_header.xml @@ -10,7 +10,8 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:layout_weight="1"/> + android:layout_weight="1" + android:text="Route details"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/route_info_layout.xml b/OsmAnd/res/layout/route_info_layout.xml new file mode 100644 index 0000000000..08685ae667 --- /dev/null +++ b/OsmAnd/res/layout/route_info_layout.xml @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/route_info_list_item.xml b/OsmAnd/res/layout/route_info_list_item.xml index b54b80ee6b..2d81a94c6d 100644 --- a/OsmAnd/res/layout/route_info_list_item.xml +++ b/OsmAnd/res/layout/route_info_list_item.xml @@ -1,77 +1,102 @@ + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:background="?attr/bg_color" + android:orientation="vertical"> - + - + - - + - + + - + - + - - + - + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index ace43f1e12..d44c7f088c 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -4,6 +4,7 @@ + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index e428f78e81..ee591db181 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,13 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Route altitude + Descent + Ascent + Altitude range + Average + Time + Total distance Relief smoothness factor More plains or more hills Use elevation data diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index ee308b286a..146401dbb5 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -76,6 +76,7 @@ "); - 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/activities/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java new file mode 100644 index 0000000000..80248b4fdc --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java @@ -0,0 +1,506 @@ +package net.osmand.plus.activities; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.content.FileProvider; +import android.support.v7.widget.Toolbar; +import android.text.Html; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; + +import com.github.mikephil.charting.charts.LineChart; +import com.github.mikephil.charting.utils.Utils; + +import net.osmand.Location; +import net.osmand.data.PointDescription; +import net.osmand.plus.GPXUtilities; +import net.osmand.plus.GPXUtilities.Elevation; +import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; +import net.osmand.plus.GPXUtilities.TrkSegment; +import net.osmand.plus.IconsCache; +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.router.RouteSegmentResult; +import net.osmand.util.Algorithms; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class ShowRouteInfoDialogFragment extends DialogFragment { + + public static final String TAG = "ShowRouteInfoDialogFragment"; + + private RoutingHelper helper; + private View view; + private ListView listView; + private RouteInfoAdapter adapter; + + public ShowRouteInfoDialogFragment() { + } + + private OsmandApplication getMyApplication() { + return (OsmandApplication) getActivity().getApplication(); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + boolean isLightTheme = getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; + setStyle(STYLE_NO_FRAME, themeId); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + final OsmandApplication app = getMyApplication(); + helper = app.getRoutingHelper(); + + view = inflater.inflate(R.layout.route_info_layout, container, false); + + Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); + toolbar.setNavigationIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha)); + toolbar.setNavigationContentDescription(R.string.shared_string_close); + toolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }); + + ((ImageView) view.findViewById(R.id.distance_icon)) + .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_polygom_dark)); + ((ImageView) view.findViewById(R.id.time_icon)) + .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_time_span)); + + buildMenuButtons(); + + listView = (ListView) view.findViewById(android.R.id.list); + listView.setBackgroundColor(getResources().getColor( + app.getSettings().isLightContent() ? R.color.ctx_menu_info_view_bg_light + : R.color.ctx_menu_info_view_bg_dark)); + + View topShadowView = inflater.inflate(R.layout.list_shadow_header, listView, false); + listView.addHeaderView(topShadowView, null, false); + View bottomShadowView = inflater.inflate(R.layout.list_shadow_footer, listView, false); + listView.addFooterView(bottomShadowView, null, false); + + adapter = new RouteInfoAdapter(helper.getRouteDirections()); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (position < 2) { + return; + } + RouteDirectionInfo item = adapter.getItem(position - 2); + Location loc = helper.getLocationFromRouteDirection(item); + if(loc != null){ + MapRouteInfoMenu.directionInfo = position - 2; + OsmandSettings settings = getMyApplication().getSettings(); + settings.setMapLocationToShow(loc.getLatitude(),loc.getLongitude(), + Math.max(13, settings.getLastKnownMapZoom()), + new PointDescription(PointDescription.POINT_TYPE_MARKER, item.getDescriptionRoutePart() + " " + getTimeDescription(item)), + false, null); + MapActivity.launchMapActivityMoveToTop(getActivity()); + dismiss(); + } + } + }); + + int dist = helper.getLeftDistance(); + int time = helper.getLeftTime(); + int hours = time / (60 * 60); + int minutes = (time / 60) % 60; + ((TextView)view.findViewById(R.id.distance)).setText(OsmAndFormatter.getFormattedDistance(dist, app)); + StringBuilder timeStr = new StringBuilder(); + if (hours > 0) { + timeStr.append(hours).append(" ").append(getString(R.string.osmand_parking_hour)).append(" "); + } + if (minutes > 0) { + timeStr.append(minutes).append(" ").append(getString(R.string.osmand_parking_minute)); + } + ((TextView)view.findViewById(R.id.time)).setText(timeStr); + + view.findViewById(R.id.go_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MapActivity activity = (MapActivity)getActivity(); + if (activity != null) { + activity.getMapLayers().getMapControlsLayer().startNavigation(); + dismiss(); + } + } + }); + + View headerView = inflater.inflate(R.layout.route_info_header, null); + if (buildHeader(headerView)) { + listView.addHeaderView(headerView); + } + + return view; + } + + private boolean buildHeader(View headerView) { + OsmandApplication app = getMyApplication(); + OsmandSettings.MetricsConstants mc = app.getSettings().METRIC_SYSTEM.get(); + final boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS); + LineChart mChart = (LineChart) headerView.findViewById(R.id.chart); + GPXUtilities.setupGPXChart(mChart, useFeet); + List route = helper.getRoute().getOriginalRoute(); + List heightList = new ArrayList<>(); + int count = 0; + for (RouteSegmentResult s : route) { + float[] arr = s.getHeightValues(); + if (arr.length > 0) { + heightList.add(arr); + count += arr.length; + } + } + float[] heightArray = new float[count]; + int i = 0; + for (float[] arr : heightList) { + System.arraycopy(arr, 0, heightArray, i, arr.length); + i += arr.length; + } + TrkSegment seg = GPXUtilities.buildTrkSegment(heightArray); + GPXTrackAnalysis analysis = GPXTrackAnalysis.segment(0, seg); + i = 0; + for (Elevation e : analysis.elevationData) { + e.distance = heightArray[i * 2]; + i++; + } + analysis.totalDistance = helper.getLeftDistance(); + GPXUtilities.setGPXChartData(mChart, analysis, Utils.getSDKInt() >= 18 + ? R.drawable.line_chart_fade_orange : R.color.osmand_orange, useFeet); + + ((TextView) headerView.findViewById(R.id.average_text)) + .setText(OsmAndFormatter.getFormattedAlt(analysis.avgElevation, app)); + + String min = OsmAndFormatter.getFormattedAlt(analysis.minElevation, app); + String max = OsmAndFormatter.getFormattedAlt(analysis.maxElevation, app); + ((TextView) headerView.findViewById(R.id.range_text)) + .setText(min + " " + max); + + String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app); + String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app); + ((TextView) headerView.findViewById(R.id.descent_text)).setText(desc); + ((TextView) headerView.findViewById(R.id.ascent_text)).setText(asc); + + ((ImageView) headerView.findViewById(R.id.average_icon)) + .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_average)); + ((ImageView) headerView.findViewById(R.id.range_icon)) + .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_average)); + ((ImageView) headerView.findViewById(R.id.descent_icon)) + .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_descent)); + ((ImageView) headerView.findViewById(R.id.ascent_icon)) + .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_ascent)); + + return count > 0; + } + + private void buildMenuButtons() { + IconsCache iconsCache = getMyApplication().getIconsCache(); + ImageButton printRoute = (ImageButton) view.findViewById(R.id.print_route); + printRoute.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_gprint_dark)); + printRoute.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + print(); + } + }); + + ImageButton saveRoute = (ImageButton) view.findViewById(R.id.save_as_gpx); + saveRoute.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_gsave_dark)); + saveRoute.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MapActivityActions.createSaveDirections(getActivity(), helper).show(); + } + }); + + ImageButton shareRoute = (ImageButton) view.findViewById(R.id.share_as_gpx); + shareRoute.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_gshare_dark)); + shareRoute.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final GPXFile gpx = helper.generateGPXFileWithRoute(); + final Uri fileUri = Uri.fromFile(new File(gpx.path)); + File dir = new File(getActivity().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(adapter, + 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(getActivity(), + getActivity().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(); + } + } + }); + } + + public static void showDialog(FragmentManager fragmentManager) { + ShowRouteInfoDialogFragment fragment = new ShowRouteInfoDialogFragment(); + fragment.show(fragmentManager, TAG); + } + + class RouteInfoAdapter extends ArrayAdapter { + public class CumulativeInfo { + public int distance; + public int time; + + public CumulativeInfo() { + distance = 0; + time = 0; + } + } + + private final int lastItemIndex; + private boolean light; + + RouteInfoAdapter(List list) { + super(getActivity(), R.layout.route_info_list_item, list); + lastItemIndex = list.size() - 1; + this.setNotifyOnChange(false); + light = getMyApplication().getSettings().isLightContent(); + } + + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View row = convertView; + if (row == null) { + LayoutInflater inflater = + (LayoutInflater) getMyApplication().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + row = inflater.inflate(R.layout.route_info_list_item, parent, false); + } + RouteDirectionInfo model = getItem(position); + TextView label = (TextView) row.findViewById(R.id.description); + TextView distanceLabel = (TextView) row.findViewById(R.id.distance); + TextView timeLabel = (TextView) row.findViewById(R.id.time); + TextView cumulativeDistanceLabel = (TextView) row.findViewById(R.id.cumulative_distance); + TextView cumulativeTimeLabel = (TextView) row.findViewById(R.id.cumulative_time); + ImageView icon = (ImageView) row.findViewById(R.id.direction); + row.findViewById(R.id.divider).setVisibility(position == getCount() - 1 ? View.INVISIBLE : View.VISIBLE); + + TurnPathHelper.RouteDrawable drawable = new TurnPathHelper.RouteDrawable(getResources(), true); + drawable.setColorFilter(new PorterDuffColorFilter(light ? getResources().getColor(R.color.icon_color) : Color.WHITE, PorterDuff.Mode.SRC_ATOP)); + drawable.setRouteType(model.getTurnType()); + icon.setImageDrawable(drawable); + + label.setText(String.valueOf(position + 1) + ". " + model.getDescriptionRoutePart()); + if (model.distance > 0) { + distanceLabel.setText(OsmAndFormatter.getFormattedDistance( + model.distance, getMyApplication())); + timeLabel.setText(getTimeDescription(model)); + row.setContentDescription(label.getText() + " " + timeLabel.getText()); //$NON-NLS-1$ + } else { + if (label.getText().equals(String.valueOf(position + 1) + ". ")) { + label.setText(String.valueOf(position + 1) + ". " + getString((position != lastItemIndex) ? R.string.arrived_at_intermediate_point : R.string.arrived_at_destination)); + } + distanceLabel.setText(""); //$NON-NLS-1$ + timeLabel.setText(""); //$NON-NLS-1$ + row.setContentDescription(""); //$NON-NLS-1$ + } + CumulativeInfo cumulativeInfo = getRouteDirectionCumulativeInfo(position); + cumulativeDistanceLabel.setText(OsmAndFormatter.getFormattedDistance( + cumulativeInfo.distance, getMyApplication())); + cumulativeTimeLabel.setText(Algorithms.formatDuration(cumulativeInfo.time, getMyApplication().accessibilityEnabled())); + return row; + } + + public CumulativeInfo getRouteDirectionCumulativeInfo(int position) { + CumulativeInfo cumulativeInfo = new CumulativeInfo(); + for (int i = 0; i < position; i++) { + RouteDirectionInfo routeDirectionInfo = (RouteDirectionInfo) getItem(i); + cumulativeInfo.time += routeDirectionInfo.getExpectedTime(); + cumulativeInfo.distance += routeDirectionInfo.distance; + } + return cumulativeInfo; + } + } + + private String getTimeDescription(RouteDirectionInfo model) { + final int timeInSeconds = model.getExpectedTime(); + return Algorithms.formatDuration(timeInSeconds, getMyApplication().accessibilityEnabled()); + } + + void print() { + File file = generateRouteInfoHtml(adapter, helper.getGeneralRouteInformation()); + if (file.exists()) { + Uri uri = Uri.fromFile(file); + Intent browserIntent; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // use Android Print Framework + browserIntent = new Intent(getActivity(), PrintDialogActivity.class) + .setDataAndType(uri, "text/html"); + } else { // just open html document + browserIntent = new Intent(Intent.ACTION_VIEW).setDataAndType( + uri, "text/html"); + } + startActivity(browserIntent); + } + } + + private File generateRouteInfoHtml(RouteInfoAdapter routeInfo, String title) { + File file = null; + if (routeInfo == null) { + return file; + } + + final String fileName = "route_info.html"; + StringBuilder html = generateHtmlPrint(routeInfo, title); + FileOutputStream fos = null; + try { + file = getMyApplication().getAppPath(fileName); + fos = new FileOutputStream(file); + fos.write(html.toString().getBytes("UTF-8")); + fos.flush(); + } catch (IOException e) { + file = null; + e.printStackTrace(); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (Exception e) { + file = null; + e.printStackTrace(); + } + } + } + + 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/dashboard/DashNavigationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java index 12e3c39f40..db19d784ec 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java @@ -15,7 +15,7 @@ import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.ShowRouteInfoActivity; +import net.osmand.plus.activities.ShowRouteInfoDialogFragment; import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.routing.RoutingHelper; @@ -40,7 +40,9 @@ public class DashNavigationFragment extends DashBaseFragment { (view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Intent intent = new Intent(view.getContext(), ShowRouteInfoActivity.class); + + ShowRouteInfoDialogFragment.showDialog(getActivity().getSupportFragmentManager()); + Intent intent = new Intent(view.getContext(), ShowRouteInfoDialogFragment.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); view.getContext().startActivity(intent); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java index 07cfc0c3b9..919a0b8d66 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java @@ -20,7 +20,6 @@ import android.widget.Spinner; import android.widget.TextView; import net.osmand.AndroidUtils; -import net.osmand.Location; import net.osmand.ValueHolder; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; @@ -34,14 +33,13 @@ import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.FavoritesListFragment.FavouritesAdapter; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.ShowRouteInfoActivity; +import net.osmand.plus.activities.ShowRouteInfoDialogFragment; import net.osmand.plus.activities.actions.AppModeDialog; import net.osmand.plus.activities.search.SearchAddressActivity; import net.osmand.plus.dialogs.FavoriteDialogs; @@ -581,9 +579,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { info.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(mapView.getContext(), ShowRouteInfoActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - mapView.getContext().startActivity(intent); + ShowRouteInfoDialogFragment.showDialog(mapActivity.getSupportFragmentManager()); } }); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java index 553c9c2661..8730d3f56d 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java @@ -13,7 +13,6 @@ import android.os.Bundle; import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; @@ -33,10 +32,7 @@ import android.widget.Spinner; import android.widget.TextView; import com.github.mikephil.charting.charts.LineChart; -import com.github.mikephil.charting.components.Legend; import com.github.mikephil.charting.components.MarkerView; -import com.github.mikephil.charting.components.XAxis; -import com.github.mikephil.charting.components.YAxis; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineDataSet; @@ -49,6 +45,7 @@ import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.Elevation; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; @@ -78,8 +75,6 @@ import java.util.List; import gnu.trove.list.array.TIntArrayList; -import static com.github.mikephil.charting.components.XAxis.XAxisPosition.BOTTOM; - public class SelectedGPXFragment extends OsmAndListFragment { public static final String ARG_TO_EXPAND_TRACK_INFO = "ARG_TO_EXPAND_TRACK_INFO"; @@ -478,46 +473,7 @@ public class SelectedGPXFragment extends OsmAndListFragment { row = inflater.inflate(R.layout.gpx_item_list_item, parent, false); mChart = (LineChart) row.findViewById(R.id.chart); - //mChart.setHardwareAccelerationEnabled(true); - mChart.setTouchEnabled(true); - mChart.setDragEnabled(true); - mChart.setScaleEnabled(true); - mChart.setPinchZoom(true); - mChart.setScaleYEnabled(false); - mChart.setAutoScaleMinMaxEnabled(true); - mChart.setDrawBorders(false); - mChart.getDescription().setEnabled(false); - mChart.setMaxVisibleValueCount(10); - mChart.setMinOffset(0f); - - mChart.setExtraTopOffset(24f); - mChart.setExtraBottomOffset(16f); - - // create a custom MarkerView (extend MarkerView) and specify the layout - // to use for it - MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.chart_marker_view, useFeet); - mv.setChartView(mChart); // For bounds control - mChart.setMarker(mv); // Set the marker to the chart - mChart.setDrawMarkers(true); - - XAxis xAxis = mChart.getXAxis(); - xAxis.setDrawAxisLine(false); - xAxis.setDrawGridLines(false); - xAxis.setDrawAxisLine(false); - xAxis.setPosition(BOTTOM); - - YAxis yAxis = mChart.getAxisLeft(); - yAxis.enableGridDashedLine(10f, 5f, 0f); - yAxis.setGridColor(ActivityCompat.getColor(getActivity(), R.color.divider_color)); - yAxis.setDrawAxisLine(false); - yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); - yAxis.setXOffset(16f); - yAxis.setYOffset(-6f); - - Legend legend = mChart.getLegend(); - legend.setEnabled(false); - - mChart.getAxisRight().setEnabled(false); + GPXUtilities.setupGPXChart(mChart, useFeet); } GpxDisplayItem child = getItem(position); TextView label = (TextView) row.findViewById(R.id.name); @@ -561,58 +517,8 @@ public class SelectedGPXFragment extends OsmAndListFragment { if (mChart != null) { if (child.analysis != null && child.analysis.elevationData != null && child.analysis.isElevationSpecified() && (child.analysis.totalDistance > 0)) { - if (child.analysis.minElevation >= 0) { - //mChart.getAxisLeft().setAxisMinimum(0f); - } - - final float convEle = useFeet ? 3.28084f : 1.0f; - final float divX = child.analysis.totalDistance > 1000 ? 1000f : 1f; - - ArrayList values = new ArrayList<>(); - List elevationData = child.analysis.elevationData; - float nextX = 0; - float nextY; - for (Elevation e : elevationData) { - if (e.distance > 0) { - nextX += (float) e.distance / divX; - nextY = (float) (e.elevation * convEle); - values.add(new Entry(nextX, nextY)); - } - } - - LineDataSet dataSet = new LineDataSet(values, ""); - - dataSet.setColor(Color.BLACK); - dataSet.setDrawValues(false); - dataSet.setLineWidth(0f); - dataSet.setValueTextSize(9f); - dataSet.setDrawFilled(true); - dataSet.setFormLineWidth(1f); - dataSet.setFormSize(15.f); - - dataSet.setDrawCircles(false); - dataSet.setDrawCircleHole(false); - - dataSet.setHighlightEnabled(true); - dataSet.setDrawVerticalHighlightIndicator(true); - dataSet.setDrawHorizontalHighlightIndicator(false); - dataSet.setHighLightColor(Color.BLACK); - - if (Utils.getSDKInt() >= 18) { - // fill drawable only supported on api level 18 and above - Drawable drawable = ContextCompat.getDrawable(getActivity(), R.drawable.line_chart_fade_orange); - dataSet.setFillDrawable(drawable); - } else { - dataSet.setFillColor(ContextCompat.getColor(getActivity(), R.color.osmand_orange)); - } - ArrayList dataSets = new ArrayList(); - dataSets.add(dataSet); // add the datasets - - // create a data object with the datasets - LineData data = new LineData(dataSets); - - // set data - mChart.setData(data); + GPXUtilities.setGPXChartData(mChart, child.analysis, Utils.getSDKInt() >= 18 + ? R.drawable.line_chart_fade_orange : R.color.osmand_orange, useFeet); mChart.setVisibility(View.VISIBLE); } else {