Transport route menu fix

This commit is contained in:
crimean 2019-07-10 15:52:20 +03:00
parent 5277b156df
commit 6cdfc14432
7 changed files with 152 additions and 22 deletions

View file

@ -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) {

View file

@ -80,6 +80,15 @@
android:paddingLeft="@dimen/context_menu_padding_margin_default"
android:paddingRight="@dimen/context_menu_padding_margin_default">
<LinearLayout
android:id="@+id/main_transport_route_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/context_menu_padding_margin_tiny"
android:gravity="top"
android:orientation="horizontal"
android:visibility="gone"/>
<GridView
android:id="@+id/transport_stop_routes_grid"
android:layout_width="match_parent"

View file

@ -7,6 +7,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
@ -46,6 +47,7 @@ import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportRoute;
import net.osmand.plus.LockableScrollView;
@ -72,6 +74,9 @@ import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.views.controls.SingleTapConfirm;
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import net.osmand.router.TransportRoutePlanner;
import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
@ -102,6 +107,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
private View topButtonContainer;
private LockableScrollView menuScrollView;
private LinearLayout mainRouteBadgeContainer;
private LinearLayout nearbyRoutesLayout;
private LinearLayout routesBadgesContainer;
private GridView localTransportStopRoutesGrid;
@ -523,6 +529,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
localRoutesMoreTv = (TextView) view.findViewById(R.id.local_routes_more_text_view);
nearbyRoutesLayout = (LinearLayout) view.findViewById(R.id.nearby_routes);
routesBadgesContainer = (LinearLayout) view.findViewById(R.id.transport_badges_container);
mainRouteBadgeContainer = (LinearLayout) view.findViewById(R.id.main_transport_route_badge);
if (nightMode) {
nearbyRoutesWithinTv.setTextColor(ContextCompat.getColor(mapActivity, R.color.text_color_secondary_dark));
@ -1396,8 +1403,86 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
}
private View createRouteBadge(TransportStopRoute transportStopRoute) {
LinearLayout convertView = null;
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
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, nightMode);
TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text);
ImageView transportStopRouteImageView = (ImageView) convertView.findViewById(R.id.transport_stop_route_icon);
int drawableResId = transportStopRoute.type == null ? R.drawable.ic_action_bus_dark : transportStopRoute.type.getResourceId();
transportStopRouteImageView.setImageDrawable(app.getUIUtilities().getPaintedIcon(drawableResId, UiUtilities.getContrastColor(mapActivity, bgColor, true)));
transportStopRouteTextView.setText(routeRef + ": " + routeDescription);
GradientDrawable gradientDrawableBg = (GradientDrawable) convertView.getBackground();
gradientDrawableBg.setColor(bgColor);
transportStopRouteTextView.setTextColor(UiUtilities.getContrastColor(mapActivity, bgColor, true));
}
}
return convertView;
}
public void fitRectOnMap(QuadRect rect) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
int tileBoxWidthPx = 0;
int tileBoxHeightPx;
if (menu.isLandscapeLayout()) {
tileBoxWidthPx = tb.getPixWidth() - mainView.getWidth();
tileBoxHeightPx = viewHeight;
} else {
tileBoxHeightPx = viewHeight - menuFullHeight;
}
if (tileBoxHeightPx > 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<TransportStopRoute> 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;

View file

@ -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());

View file

@ -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()) {

View file

@ -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()) {

View file

@ -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);
}