From b79de3c9c70c0a7c4ea684b1415977c3fb38b45b Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Wed, 25 Apr 2018 09:03:58 -0400 Subject: [PATCH] Add map widget to show arrival time at first intermediate point --- OsmAnd/res/values/strings.xml | 2 ++ .../src/net/osmand/plus/ApplicationMode.java | 2 ++ .../src/net/osmand/plus/OsmandSettings.java | 3 ++ .../plus/routing/RouteCalculationResult.java | 9 +++++ .../osmand/plus/routing/RoutingHelper.java | 4 +++ .../net/osmand/plus/views/MapInfoLayer.java | 15 ++++---- .../mapwidgets/RouteInfoWidgetsFactory.java | 35 +++++++++++++++---- 7 files changed, 57 insertions(+), 13 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 76705a0755..778f5e6ecf 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1591,6 +1591,7 @@ Hillshade layer GPS info Arrival time + Intermediate arrival time checked unchecked Prefer motorways @@ -1693,6 +1694,7 @@ You have arrived at your intermediate destination Add as intermediate destination Intermediate destination + Intermediate time Ending point too far from nearest road. Add Tag Advanced Modeā€¦ diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index 8531912c7f..0ca973cdbc 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -79,6 +79,7 @@ public class ApplicationMode { regWidgetVisibility("intermediate_distance", all); regWidgetVisibility("distance", all); regWidgetVisibility("time", all); + regWidgetVisibility("intermediate_time", all); regWidgetVisibility("speed", exceptPedestrianAndDefault); regWidgetVisibility("max_speed", CAR); regWidgetVisibility("altitude", pedestrianBicycle); @@ -86,6 +87,7 @@ public class ApplicationMode { regWidgetAvailability("intermediate_distance", all); regWidgetAvailability("distance", all); regWidgetAvailability("time", all); + regWidgetAvailability("intermediate_time", all); regWidgetAvailability("map_marker_1st", none); regWidgetAvailability("map_marker_2nd", none); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index a55d451289..394c34b0a9 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -3013,6 +3013,9 @@ public class OsmandSettings { public final OsmandPreference SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME = new BooleanPreference("show_arrival_time", true).makeGlobal(); + public final OsmandPreference SHOW_INTERMEDIATE_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME = + new BooleanPreference("show_intermediate_arrival_time", true).makeGlobal(); + public final OsmandPreference SHOW_RELATIVE_BEARING_OTHERWISE_REGULAR_BEARING = new BooleanPreference("show_relative_bearing", true).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 3ca74781e8..e94ad62486 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -992,6 +992,15 @@ public class RouteCalculationResult { return time; } + public int getLeftTimeToNextIntermediate(Location fromLoc){ + + if(nextIntermediate >= intermediatePoints.length ){ + return 0; + } else { + return getLeftTime(fromLoc) - directions.get(intermediatePoints[nextIntermediate]).afterLeftTime; + } + } + public static class NextDirectionInfo { public RouteDirectionInfo directionInfo; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 9a6fe402c3..29006d7be0 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -700,6 +700,10 @@ public class RoutingHelper { return route.getLeftTime(lastFixedLocation); } + public int getLeftTimeNextIntermediate() { + return route.getLeftTimeToNextIntermediate(lastFixedLocation); + } + public OsmandSettings getSettings() { return settings; } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 2a6c89d79a..3ffa5611c4 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -163,17 +163,20 @@ public class MapInfoLayer extends OsmandMapLayer { // priorityOrder: 10s navigation-related, 20s position-related, 30s recording- and other plugin-related, 40s general device information, 50s debugging-purpose TextInfoWidget intermediateDist = ric.createIntermediateDistanceControl(map); registerSideWidget(intermediateDist, R.drawable.ic_action_intermediate, R.string.map_widget_intermediate_distance, "intermediate_distance", false, 13); + TextInfoWidget intermediateTime = ric.createTimeControl(map, true); + registerSideWidget(intermediateTime, new TimeControlWidgetState(app, true), "intermediate_time", false, 14); TextInfoWidget dist = ric.createDistanceControl(map); - registerSideWidget(dist, R.drawable.ic_action_target, R.string.map_widget_distance, "distance", false, 14); - TextInfoWidget time = ric.createTimeControl(map); - registerSideWidget(time, new TimeControlWidgetState(app), "time", false, 15); + registerSideWidget(dist, R.drawable.ic_action_target, R.string.map_widget_distance, "distance", false, 15); + TextInfoWidget time = ric.createTimeControl(map, false); + registerSideWidget(time, new TimeControlWidgetState(app, false), "time", false, 16); + TextInfoWidget marker = mwf.createMapMarkerControl(map, true); - registerSideWidget(marker, R.drawable.ic_action_flag_dark, R.string.map_marker_1st, "map_marker_1st", false, 16); + registerSideWidget(marker, R.drawable.ic_action_flag_dark, R.string.map_marker_1st, "map_marker_1st", false, 17); TextInfoWidget bearing = ric.createBearingControl(map); - registerSideWidget(bearing, new BearingWidgetState(app), "bearing", false, 17); + registerSideWidget(bearing, new BearingWidgetState(app), "bearing", false, 18); TextInfoWidget marker2nd = mwf.createMapMarkerControl(map, false); - registerSideWidget(marker2nd, R.drawable.ic_action_flag_dark, R.string.map_marker_2nd, "map_marker_2nd", false, 18); + registerSideWidget(marker2nd, R.drawable.ic_action_flag_dark, R.string.map_marker_2nd, "map_marker_2nd", false, 19); TextInfoWidget speed = ric.createSpeedControl(map); registerSideWidget(speed, R.drawable.ic_action_speed, R.string.map_widget_speed, "speed", false, 20); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index bcdb75f92c..bf103299a3 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -198,15 +198,26 @@ public class RouteInfoWidgetsFactory { public static final int TIME_CONTROL_WIDGET_STATE_TIME_TO_GO = R.id.time_control_widget_state_time_to_go; private final OsmandPreference showArrival; + private final boolean intermediate; - public TimeControlWidgetState(OsmandApplication ctx) { + public TimeControlWidgetState(OsmandApplication ctx, boolean intermediate) { super(ctx); - showArrival = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME; + if (intermediate) { + showArrival = ctx.getSettings().SHOW_INTERMEDIATE_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME; + } else { + showArrival = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME; + } + + this.intermediate = intermediate; } @Override public int getMenuTitleId() { - return showArrival.get() ? R.string.access_arrival_time : R.string.map_widget_time; + if (intermediate) { + return showArrival.get() ? R.string.access_intermediate_arrival_time : R.string.map_widget_intermediate_time; + } else { + return showArrival.get() ? R.string.access_arrival_time : R.string.map_widget_time; + } } @Override @@ -221,7 +232,11 @@ public class RouteInfoWidgetsFactory { @Override public int[] getMenuTitleIds() { - return new int[]{R.string.access_arrival_time, R.string.map_widget_time}; + if (intermediate) { + return new int[]{R.string.access_intermediate_arrival_time, R.string.map_widget_intermediate_time}; + } else { + return new int[]{R.string.access_arrival_time, R.string.map_widget_time}; + } } @Override @@ -240,14 +255,15 @@ public class RouteInfoWidgetsFactory { } } - public TextInfoWidget createTimeControl(final MapActivity map){ + public TextInfoWidget createTimeControl(final MapActivity map, final boolean intermediate){ final RoutingHelper routingHelper = map.getRoutingHelper(); final int time = R.drawable.widget_time_day; final int timeN = R.drawable.widget_time_night; final int timeToGo = R.drawable.widget_time_to_distance_day; final int timeToGoN = R.drawable.widget_time_to_distance_night; final OsmandApplication ctx = map.getMyApplication(); - final OsmandPreference showArrival = ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME; + final OsmandPreference showArrival = intermediate?ctx.getSettings().SHOW_INTERMEDIATE_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME + :ctx.getSettings().SHOW_ARRIVAL_TIME_OTHERWISE_EXPECTED_TIME; final TextInfoWidget leftTimeControl = new TextInfoWidget(map) { private long cachedLeftTime = 0; @@ -257,7 +273,12 @@ public class RouteInfoWidgetsFactory { int time = 0; if (routingHelper != null && routingHelper.isRouteCalculated()) { //boolean followingMode = routingHelper.isFollowingMode(); - time = routingHelper.getLeftTime(); + if (intermediate) { + time = routingHelper.getLeftTimeNextIntermediate(); + } else { + time = routingHelper.getLeftTime(); + } + if (time != 0) { if (/*followingMode && */showArrival.get()) { long toFindTime = time * 1000 + System.currentTimeMillis();