diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java index dd9a7ec9b1..2482fa166f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java @@ -1,19 +1,5 @@ package net.osmand.router; -import gnu.trove.iterator.TIntIterator; -import gnu.trove.list.array.TIntArrayList; -import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.map.hash.TLongObjectHashMap; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.PriorityQueue; - import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.data.LatLon; @@ -25,6 +11,20 @@ import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Way; import net.osmand.util.MapUtils; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.PriorityQueue; + +import gnu.trove.iterator.TIntIterator; +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.map.hash.TIntObjectHashMap; +import gnu.trove.map.hash.TLongObjectHashMap; + public class TransportRoutePlanner { private static final boolean MEASURE_TIME = false; @@ -478,7 +478,25 @@ public class TransportRoutePlanner { } return stops; } - + + public boolean isRouteStop(TransportStop stop) { + for(TransportRouteResultSegment s : segments) { + if (s.getTravelStops().contains(stop)) { + return true; + } + } + return false; + } + + public TransportRouteResultSegment getRouteStopSegment(TransportStop stop) { + for(TransportRouteResultSegment s : segments) { + if (s.getTravelStops().contains(stop)) { + return s; + } + } + return null; + } + public double getTravelDist() { double d = 0; for (TransportRouteResultSegment s : segments) { diff --git a/OsmAnd/res/layout/map_context_menu_fragment.xml b/OsmAnd/res/layout/map_context_menu_fragment.xml index ba09d7dab8..8e52bcae4b 100644 --- a/OsmAnd/res/layout/map_context_menu_fragment.xml +++ b/OsmAnd/res/layout/map_context_menu_fragment.xml @@ -80,6 +80,15 @@ android:paddingLeft="@dimen/context_menu_padding_margin_default" android:paddingRight="@dimen/context_menu_padding_margin_default"> + + 0 || tileBoxWidthPx > 0) { + int topMarginPx = AndroidUtils.getStatusBarHeight(mapActivity); + int leftMarginPx = mainView.getWidth(); + restoreCustomMapRatio(); + mapActivity.getMapView().fitRectToMap(rect.left, rect.right, rect.top, rect.bottom, + tileBoxWidthPx, tileBoxHeightPx, topMarginPx, leftMarginPx); + } + } + } + private void updateLocalRoutesBadges(List localTransportStopRoutes, int localColumnsPerRow) { int localRoutesSize = localTransportStopRoutes.size(); + OsmandApplication app = requireMyApplication(); + TransportRouteResult activeRoute = app.getRoutingHelper().getTransportRoutingHelper().getActiveRoute(); + if (localRoutesSize > 0 && activeRoute != null) { + for (int i = 0; i < localTransportStopRoutes.size(); i++) { + final TransportStopRoute stopRoute = localTransportStopRoutes.get(i); + if (activeRoute.isRouteStop(stopRoute.stop)) { + View routeBadge = createRouteBadge(stopRoute); + mainRouteBadgeContainer.addView(routeBadge); + mainRouteBadgeContainer.setVisibility(View.VISIBLE); + mainRouteBadgeContainer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + TransportRouteResult activeRoute = requireMyApplication().getRoutingHelper().getTransportRoutingHelper().getActiveRoute(); + if (activeRoute != null) { + TransportRouteResultSegment segment = activeRoute.getRouteStopSegment(stopRoute.stop); + if (segment != null) { + QuadRect rect = segment.getSegmentRect(); + if (rect != null) { + //openMenuHeaderOnly(); + fitRectOnMap(rect); + } + } + } + } + }); + localTransportStopRoutes.remove(i); + localRoutesSize--; + break; + } + } + } if (localRoutesSize > 0) { int maxLocalBadges = localColumnsPerRow * 5; TransportStopRouteAdapter adapter; diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java index a8818dd603..021886fba0 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteDetailsFragment.java @@ -1025,7 +1025,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT LinearLayout llText = buildTextContainerView(view.getContext()); ll.addView(llText); - View routeBadge = createRouteBadge(mapActivity, transportStopRoute, routeDescription); + View routeBadge = createRouteBadge(mapActivity, transportStopRoute); LinearLayout.LayoutParams routeBadgeParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); routeBadgeParams.setMargins(0, dpToPx(6), 0, dpToPx(8)); routeBadge.setLayoutParams(routeBadgeParams); @@ -1430,10 +1430,11 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT return ll; } - public View createRouteBadge(@NonNull MapActivity mapActivity, TransportStopRoute transportStopRoute, String routeDescription) { + public View createRouteBadge(@NonNull MapActivity mapActivity, TransportStopRoute transportStopRoute) { OsmandApplication app = mapActivity.getMyApplication(); LinearLayout convertView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false); if (transportStopRoute != null) { + String routeDescription = transportStopRoute.getDescription(app); String routeRef = transportStopRoute.route.getAdjustedRouteRef(true); int bgColor = transportStopRoute.getColor(app, isNightMode()); diff --git a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java index 48d681d283..368daa4793 100644 --- a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java @@ -84,11 +84,19 @@ public class TransportRoutingHelper { return endLocation; } - public int getCurrentRoute() { return currentRoute; } + public boolean hasActiveRoute() { + return routingHelper.isPublicTransportMode() && currentRoute >= 0; + } + + @Nullable + public TransportRouteResult getActiveRoute() { + return routes != null && routes.size() > currentRoute && currentRoute >= 0 ? routes.get(currentRoute) : null; + } + @Nullable public TransportRouteResult getCurrentRouteResult() { if (routes != null && currentRoute != -1 && currentRoute < routes.size()) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index e71b7e7495..034c203f35 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -400,7 +400,7 @@ public class MapControlsLayer extends OsmandMapLayer { mapActivity.dismissCardDialog(); RoutingHelper routingHelper = mapActivity.getRoutingHelper(); TransportRoutingHelper transportRoutingHelper = routingHelper.getTransportRoutingHelper(); - if (routingHelper.isPublicTransportMode() && transportRoutingHelper.getCurrentRoute() >= 0) { + if (transportRoutingHelper.hasActiveRoute()) { ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), transportRoutingHelper.getCurrentRoute(), MenuState.FULL_SCREEN); } else { doRoute(false); @@ -782,7 +782,7 @@ public class MapControlsLayer extends OsmandMapLayer { boolean showButtons = (showRouteCalculationControls || !routeFollowingMode) && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened && !isInChoosingRoutesMode() && !isInWaypointsChoosingMode(); //routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions); - if (rh.isPublicTransportMode() && trh.getCurrentRoute() >= 0) { + if (trh.hasActiveRoute()) { routePlanningBtn.setIconResId(R.drawable.map_action_bus_dark); routePlanningBtn.setIconColorId(R.color.color_myloc_distance); } else if (rh.isFollowingMode()) { diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 8dda1d73b3..9909badc2c 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -931,14 +931,23 @@ public class OsmandMapTileView implements IMapDownloaderCallback { public void fitRectToMap(double left, double right, double top, double bottom, int tileBoxWidthPx, int tileBoxHeightPx, int marginTopPx) { + fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, marginTopPx, 0); + } + + public void fitRectToMap(double left, double right, double top, double bottom, + int tileBoxWidthPx, int tileBoxHeightPx, int marginTopPx, int marginLeftPx) { RotatedTileBox tb = currentViewport.copy(); double border = 0.8; + int dx = 0; int dy = 0; int tbw = (int) (tb.getPixWidth() * border); int tbh = (int) (tb.getPixHeight() * border); if (tileBoxWidthPx > 0) { tbw = (int) (tileBoxWidthPx * border); + if (marginLeftPx > 0) { + dx = (tb.getPixWidth() - tileBoxWidthPx) / 2 - marginLeftPx; + } } else if (tileBoxHeightPx > 0) { tbh = (int) (tileBoxHeightPx * border); dy = (tb.getPixHeight() - tileBoxHeightPx) / 2 - marginTopPx; @@ -954,9 +963,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback { while (tb.getZoom() >= 7 && (!tb.containsLatLon(top, left) || !tb.containsLatLon(bottom, right))) { tb.setZoom(tb.getZoom() - 1); } - if (dy != 0) { + if (dy != 0 || dx != 0) { clat = tb.getLatFromPixel(tb.getPixWidth() / 2, tb.getPixHeight() / 2 + dy); - clon = tb.getLonFromPixel(tb.getPixWidth() / 2, tb.getPixHeight() / 2); + clon = tb.getLonFromPixel(tb.getPixWidth() / 2 + dx, tb.getPixHeight() / 2); } animatedDraggingThread.startMoving(clat, clon, tb.getZoom(), true); }