Make PT bages clickable

This commit is contained in:
crimean 2019-03-14 22:13:04 +03:00
parent f4a96eb194
commit fb2245e73c
8 changed files with 298 additions and 108 deletions

View file

@ -1,8 +1,10 @@
package net.osmand.router; package net.osmand.router;
import net.osmand.Location;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.TransportRoute; import net.osmand.data.TransportRoute;
import net.osmand.data.TransportSchedule; import net.osmand.data.TransportSchedule;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
@ -319,6 +321,25 @@ public class TransportRoutePlanner {
return route.getForwardStops().subList(start, end + 1); return route.getForwardStops().subList(start, end + 1);
} }
public QuadRect getSegmentRect() {
double left = 0, right = 0;
double top = 0, bottom = 0;
for (Node n : getNodes()) {
if (left == 0 && right == 0) {
left = n.getLongitude();
right = n.getLongitude();
top = n.getLatitude();
bottom = n.getLatitude();
} else {
left = Math.min(left, n.getLongitude());
right = Math.max(right, n.getLongitude());
top = Math.max(top, n.getLatitude());
bottom = Math.min(bottom, n.getLatitude());
}
}
return left == 0 && right == 0 ? null : new QuadRect(left, top, right, bottom);
}
public List<Node> getNodes() { public List<Node> getNodes() {
List<Node> nodes = new ArrayList<>(); List<Node> nodes = new ArrayList<>();
List<Way> ways = getGeometry(); List<Way> ways = getGeometry();

View file

@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height" android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?android:attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height" android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"

View file

@ -7,24 +7,32 @@
android:background="@drawable/transport_stop_route_bg" android:background="@drawable/transport_stop_route_bg"
android:orientation="horizontal"> android:orientation="horizontal">
<ImageView <LinearLayout
android:id="@+id/transport_stop_route_icon" android:id="@+id/button"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center_vertical"
android:layout_margin="4dp"
tools:src="@drawable/ic_action_bus_dark" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/transport_stop_route_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="28dp" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:background="?attr/selectableItemBackgroundBorderless">
android:layout_marginRight="8dp"
android:gravity="center" <ImageView
android:textColor="@color/color_white" android:id="@+id/transport_stop_route_icon"
android:textSize="@dimen/default_desc_text_size" android:layout_width="20dp"
osmand:typeface="@string/font_roboto_medium" android:layout_height="20dp"
tools:text="3" /> android:layout_gravity="center_vertical"
android:layout_margin="4dp"
tools:src="@drawable/ic_action_bus_dark" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/transport_stop_route_text"
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center"
android:textColor="@color/color_white"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="3" />
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -25,6 +25,7 @@ import net.osmand.plus.LockableViewPager;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
@ -63,6 +64,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements CardListe
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
map = getMapActivity().getMapView(); map = getMapActivity().getMapView();
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
List<TransportRouteResult> routes = app.getTransportRoutingHelper().getRoutes(); List<TransportRouteResult> routes = app.getTransportRoutingHelper().getRoutes();
if (routes != null && !routes.isEmpty()) { if (routes != null && !routes.isEmpty()) {
view = inflater.inflate(R.layout.fragment_show_all_routes, null); view = inflater.inflate(R.layout.fragment_show_all_routes, null);
@ -71,7 +73,8 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements CardListe
AndroidUtils.addStatusBarPadding21v(mapActivity, view); AndroidUtils.addStatusBarPadding21v(mapActivity, view);
for (int i = 0; i < routes.size(); i++) { for (int i = 0; i < routes.size(); i++) {
PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i); PublicTransportCard card = new PublicTransportCard(mapActivity, targetPointsHelper.getPointToStart(),
targetPointsHelper.getPointToNavigate(), routes.get(i), i);
card.setListener(this); card.setListener(this);
card.setShowTopShadow(false); card.setShowTopShadow(false);
card.setShowBottomShadow(false); card.setShowBottomShadow(false);

View file

@ -36,6 +36,7 @@ import net.osmand.ValueHolder;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.GeocodingLookupService; import net.osmand.plus.GeocodingLookupService;
@ -72,15 +73,18 @@ import net.osmand.plus.routepreparationmenu.cards.HomeWorkCard;
import net.osmand.plus.routepreparationmenu.cards.MapMarkersCard; import net.osmand.plus.routepreparationmenu.cards.MapMarkersCard;
import net.osmand.plus.routepreparationmenu.cards.PreviousRouteCard; import net.osmand.plus.routepreparationmenu.cards.PreviousRouteCard;
import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard; import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard;
import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard.PublicTransportCardListener;
import net.osmand.plus.routepreparationmenu.cards.SimpleRouteCard; import net.osmand.plus.routepreparationmenu.cards.SimpleRouteCard;
import net.osmand.plus.routepreparationmenu.cards.TracksCard; import net.osmand.plus.routepreparationmenu.cards.TracksCard;
import net.osmand.plus.routepreparationmenu.cards.WarningCard; import net.osmand.plus.routepreparationmenu.cards.WarningCard;
import net.osmand.plus.routing.IRouteInformationListener; import net.osmand.plus.routing.IRouteInformationListener;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.search.QuickSearchHelper; import net.osmand.plus.search.QuickSearchHelper;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter; import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment;
import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.SearchUICore.SearchResultCollection;
import net.osmand.search.core.SearchResult; import net.osmand.search.core.SearchResult;
@ -465,6 +469,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
mainView = main; mainView = main;
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
nightMode = app.getDaynightHelper().isNightModeForMapControls(); nightMode = app.getDaynightHelper().isNightModeForMapControls();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
updateStartPointView(); updateStartPointView();
updateWaypointsView(); updateWaypointsView();
@ -486,7 +491,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} else if (isTransportRouteCalculated()) { } else if (isTransportRouteCalculated()) {
List<TransportRouteResult> routes = app.getTransportRoutingHelper().getRoutes(); List<TransportRouteResult> routes = app.getTransportRoutingHelper().getRoutes();
for (int i = 0; i < routes.size(); i++) { for (int i = 0; i < routes.size(); i++) {
PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i); PublicTransportCard card = new PublicTransportCard(mapActivity, targetPointsHelper.getPointToStart(),
targetPointsHelper.getPointToNavigate(), routes.get(i), i);
card.setShowBottomShadow(i == routes.size() - 1); card.setShowBottomShadow(i == routes.size() - 1);
card.setShowTopShadow(i != 0); card.setShowTopShadow(i != 0);
card.setListener(this); card.setListener(this);
@ -502,7 +508,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
menuCards.add(homeWorkCard); menuCards.add(homeWorkCard);
// Previous route card // Previous route card
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
TargetPoint startBackup = targetPointsHelper.getPointToStartBackup(); TargetPoint startBackup = targetPointsHelper.getPointToStartBackup();
if (startBackup == null) { if (startBackup == null) {
startBackup = targetPointsHelper.getMyLocationToStart(); startBackup = targetPointsHelper.getMyLocationToStart();

View file

@ -92,6 +92,7 @@ import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView;
import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard; import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard;
import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard.PublicTransportCardListener;
import net.osmand.plus.routepreparationmenu.cards.RouteInfoCard; import net.osmand.plus.routepreparationmenu.cards.RouteInfoCard;
import net.osmand.plus.routepreparationmenu.cards.RouteStatisticCard; import net.osmand.plus.routepreparationmenu.cards.RouteStatisticCard;
import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteCalculationResult;
@ -128,7 +129,7 @@ import static net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.MenuState.FU
import static net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.MenuState.HALF_SCREEN; import static net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.MenuState.HALF_SCREEN;
import static net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.MenuState.HEADER_ONLY; import static net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.MenuState.HEADER_ONLY;
public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment { public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements PublicTransportCardListener {
public static final String TAG = "ShowRouteInfoDialogFragment"; public static final String TAG = "ShowRouteInfoDialogFragment";
@ -443,7 +444,10 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
List<TransportRouteResult> routes = routingHelper.getTransportRoutingHelper().getRoutes(); List<TransportRouteResult> routes = routingHelper.getTransportRoutingHelper().getRoutes();
if (routes != null && routes.size() > transportRouteId) { if (routes != null && routes.size() > transportRouteId) {
TransportRouteResult routeResult = routingHelper.getTransportRoutingHelper().getRoutes().get(transportRouteId); TransportRouteResult routeResult = routingHelper.getTransportRoutingHelper().getRoutes().get(transportRouteId);
PublicTransportCard card = new PublicTransportCard(mapActivity, routeResult, transportRouteId); TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
PublicTransportCard card = new PublicTransportCard(mapActivity, targetPointsHelper.getPointToStart(),
targetPointsHelper.getPointToNavigate(), routeResult, transportRouteId);
card.setTransportCardListener(this);
menuCards.add(card); menuCards.add(card);
cardsContainer.addView(card.build(mapActivity)); cardsContainer.addView(card.build(mapActivity));
buildRowDivider(cardsContainer, false); buildRowDivider(cardsContainer, false);
@ -595,7 +599,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
!nightMode ? R.color.ctx_menu_collapse_icon_color_light : R.color.ctx_menu_collapse_icon_color_dark); !nightMode ? R.color.ctx_menu_collapse_icon_color_light : R.color.ctx_menu_collapse_icon_color_dark);
} }
private void buildSegmentItem(View view, TransportRouteResultSegment segment, long startTime) { private void buildSegmentItem(View view, final TransportRouteResultSegment segment, long startTime) {
TransportRoute transportRoute = segment.route; TransportRoute transportRoute = segment.route;
List<TransportStop> stops = segment.getTravelStops(); List<TransportStop> stops = segment.getTravelStops();
final TransportStop startStop = stops.get(0); final TransportStop startStop = stops.get(0);
@ -629,13 +633,20 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
title.setSpan(new CustomTypefaceSpan(typeface), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); title.setSpan(new CustomTypefaceSpan(typeface), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
title.setSpan(new ForegroundColorSpan(getActiveColor()), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); title.setSpan(new ForegroundColorSpan(getActiveColor()), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
buildStartStopRow(stopsContainer, icon, timeText, transportStopRoute, title, secondaryText, new OnClickListener() { buildStartStopRow(stopsContainer, icon, timeText, title, secondaryText, new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
showLocationOnMap(startStop.getLocation()); showLocationOnMap(startStop.getLocation());
} }
}); });
buildTransportStopRouteRow(stopsContainer, transportStopRoute, new OnClickListener() {
@Override
public void onClick(View v) {
showRouteSegmentOnMap(segment);
}
});
CollapsableView collapsableView = null; CollapsableView collapsableView = null;
if (stops.size() > 2) { if (stops.size() > 2) {
collapsableView = getCollapsableTransportStopRoutesView(app, transportStopRoute, stops.subList(1, stops.size() - 1)); collapsableView = getCollapsableTransportStopRoutesView(app, transportStopRoute, stops.subList(1, stops.size() - 1));
@ -873,14 +884,26 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
} }
} }
public void showWalkingRouteOnMap(TransportRouteResultSegment startSegment, TransportRouteResultSegment endSegment) { public void showRouteOnMap(@NonNull RouteCalculationResult result) {
QuadRect rect = result.getLocationsRect();
if (rect != null) {
openMenuHeaderOnly();
fitRectOnMap(rect);
}
}
public void showWalkingRouteOnMap(@Nullable TransportRouteResultSegment startSegment, @Nullable TransportRouteResultSegment endSegment) {
RouteCalculationResult walkingRouteSegment = app.getTransportRoutingHelper().getWalkingRouteSegment(startSegment, endSegment); RouteCalculationResult walkingRouteSegment = app.getTransportRoutingHelper().getWalkingRouteSegment(startSegment, endSegment);
if (walkingRouteSegment != null) { if (walkingRouteSegment != null) {
QuadRect rect = walkingRouteSegment.getLocationsRect(); showRouteOnMap(walkingRouteSegment);
if (rect != null) { }
openMenuHeaderOnly(); }
fitRectOnMap(rect, null, true);
} public void showRouteSegmentOnMap(@NonNull TransportRouteResultSegment segment) {
QuadRect rect = segment.getSegmentRect();
if (rect != null) {
openMenuHeaderOnly();
fitRectOnMap(rect);
} }
} }
@ -889,7 +912,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
QuadRect rect = app.getTransportRoutingHelper().getTransportRouteRect(result); QuadRect rect = app.getTransportRoutingHelper().getTransportRouteRect(result);
if (rect != null) { if (rect != null) {
openMenuHeaderOnly(); openMenuHeaderOnly();
fitRectOnMap(rect, null, true); fitRectOnMap(rect);
} }
} }
} }
@ -1039,8 +1062,8 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
((LinearLayout) view).addView(baseItemView); ((LinearLayout) view).addView(baseItemView);
} }
public void buildStartStopRow(final View view, Drawable icon, String timeText, TransportStopRoute transportStopRoute, public void buildStartStopRow(final View view, Drawable icon, String timeText, final Spannable title,
final Spannable title, Spannable secondaryText, OnClickListener onClickListener) { Spannable secondaryText, OnClickListener onClickListener) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity == null) { if (mapActivity == null) {
return; return;
@ -1102,23 +1125,58 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
baseItemView.addView(timeView); baseItemView.addView(timeView);
} }
if (transportStopRoute != null) { if (onClickListener != null) {
TextView routeTypeView = new TextView(view.getContext()); ll.setOnClickListener(onClickListener);
LinearLayout.LayoutParams routeTypeParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
routeTypeParams.setMargins(0, dpToPx(4), 0, 0);
routeTypeView.setLayoutParams(routeTypeParams);
routeTypeView.setTextSize(16);
AndroidUtils.setTextSecondaryColor(app, routeTypeView, nightMode);
routeTypeView.setText(transportStopRoute.getDescription(app));
llText.addView(routeTypeView);
View routeBadge = createRouteBadge(mapActivity, transportStopRoute, nightMode);
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);
llText.addView(routeBadge);
} }
((LinearLayout) view).addView(baseItemView);
}
public void buildTransportStopRouteRow(final View view, @NonNull TransportStopRoute transportStopRoute,
OnClickListener onClickListener) {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
final String routeDescription = transportStopRoute.getDescription(app);
FrameLayout baseItemView = new FrameLayout(view.getContext());
FrameLayout.LayoutParams baseViewLayoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
baseItemView.setLayoutParams(baseViewLayoutParams);
LinearLayout baseView = new LinearLayout(view.getContext());
baseView.setOrientation(LinearLayout.VERTICAL);
baseView.setLayoutParams(baseViewLayoutParams);
baseView.setGravity(Gravity.END);
baseView.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
baseItemView.addView(baseView);
LinearLayout ll = buildHorizontalContainerView(36, new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
copyToClipboard(routeDescription, view.getContext());
return true;
}
});
baseView.addView(ll);
LinearLayout llText = buildTextContainerView();
ll.addView(llText);
TextView routeTypeView = new TextView(view.getContext());
LinearLayout.LayoutParams routeTypeParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
routeTypeParams.setMargins(0, dpToPx(4), 0, 0);
routeTypeView.setLayoutParams(routeTypeParams);
routeTypeView.setTextSize(16);
AndroidUtils.setTextSecondaryColor(app, routeTypeView, nightMode);
routeTypeView.setText(routeDescription);
llText.addView(routeTypeView);
View routeBadge = createRouteBadge(mapActivity, transportStopRoute, nightMode);
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);
llText.addView(routeBadge);
if (onClickListener != null) { if (onClickListener != null) {
ll.setOnClickListener(onClickListener); ll.setOnClickListener(onClickListener);
} }
@ -1263,7 +1321,17 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
} }
} }
private void fitRectOnMap(QuadRect rect, LatLon location, boolean forceFit) { private void showOnMap(@NonNull LatLon start, @NonNull LatLon end) {
double left = Math.min(start.getLongitude(), end.getLongitude());
double right = Math.max(start.getLongitude(), end.getLongitude());
double top = Math.max(start.getLatitude(), end.getLatitude());
double bottom = Math.min(start.getLatitude(), end.getLatitude());
QuadRect rect = new QuadRect(left, top, right, bottom);
openMenuHeaderOnly();
fitRectOnMap(rect);
}
private void fitRectOnMap(QuadRect rect) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy(); RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
@ -1278,17 +1346,8 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
} }
if (tileBoxHeightPx > 0) { if (tileBoxHeightPx > 0) {
int topMarginPx = toolbar.getHeight(); int topMarginPx = toolbar.getHeight();
if (forceFit) { mapActivity.getMapView().fitRectToMap(rect.left, rect.right, rect.top, rect.bottom,
mapActivity.getMapView().fitRectToMap(rect.left, rect.right, rect.top, rect.bottom, tileBoxWidthPx, tileBoxHeightPx, topMarginPx);
tileBoxWidthPx, tileBoxHeightPx, topMarginPx);
} else if (location != null &&
!mapActivity.getMapView().getTileBox(tileBoxWidthPx, tileBoxHeightPx, topMarginPx).containsLatLon(location)) {
boolean animating = mapActivity.getMapView().getAnimatedDraggingThread().isAnimating();
mapActivity.getMapView().fitLocationToMap(location.getLatitude(), location.getLongitude(),
mapActivity.getMapView().getZoom(), tileBoxWidthPx, tileBoxHeightPx, topMarginPx, !animating);
} else {
mapActivity.refreshMap();
}
} }
} }
} }
@ -1773,6 +1832,21 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
} }
} }
@Override
public void onPublicTransportCardBadgePressed(@NonNull PublicTransportCard card, @NonNull TransportRouteResultSegment segment) {
showRouteSegmentOnMap(segment);
}
@Override
public void onPublicTransportCardBadgePressed(@NonNull PublicTransportCard card, @NonNull RouteCalculationResult result) {
showRouteOnMap(result);
}
@Override
public void onPublicTransportCardBadgePressed(@NonNull PublicTransportCard card, @NonNull LatLon start, @NonNull LatLon end) {
showOnMap(start, end);
}
public class CumulativeInfo { public class CumulativeInfo {
public int distance; public int distance;
public int time; public int time;
@ -2399,7 +2473,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
} }
private void doLayoutMenu() { private void doLayoutMenu() {
final int posY = getPosY(getViewY(), false, getCurrentMenuState()); final int posY = getPosY(initLayout ? CURRENT_Y_UNDEFINED : getViewY(), false, getCurrentMenuState());
setViewY(posY, true, !initLayout); setViewY(posY, true, !initLayout);
updateMainViewLayout(posY); updateMainViewLayout(posY);
} }

View file

@ -3,6 +3,8 @@ package net.osmand.plus.routepreparationmenu.cards;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.os.Build; import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
@ -14,13 +16,17 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
import net.osmand.data.TransportRoute; import net.osmand.data.TransportRoute;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routepreparationmenu.ShowRouteInfoDialogFragment;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.routepreparationmenu.ShowRouteInfoDialogFragment;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.widgets.FlowLayout; import net.osmand.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.style.CustomTypefaceSpan; import net.osmand.plus.widgets.style.CustomTypefaceSpan;
@ -37,12 +43,23 @@ public class PublicTransportCard extends BaseCard {
public static final int DETAILS_BUTTON_INDEX = 0; public static final int DETAILS_BUTTON_INDEX = 0;
public static final int SHOW_BUTTON_INDEX = 1; public static final int SHOW_BUTTON_INDEX = 1;
private TargetPoint startPoint;
private TargetPoint endPoint;
private TransportRouteResult routeResult; private TransportRouteResult routeResult;
private PublicTransportCardListener transportCardListener;
private int routeId; private int routeId;
public PublicTransportCard(MapActivity mapActivity, TransportRouteResult routeResult, int routeId) { public interface PublicTransportCardListener {
void onPublicTransportCardBadgePressed(@NonNull PublicTransportCard card, @NonNull TransportRouteResultSegment segment);
void onPublicTransportCardBadgePressed(@NonNull PublicTransportCard card, @NonNull RouteCalculationResult result);
void onPublicTransportCardBadgePressed(@NonNull PublicTransportCard card, @NonNull LatLon start, @NonNull LatLon end);
}
public PublicTransportCard(MapActivity mapActivity, TargetPoint startPoint, TargetPoint endPoint, TransportRouteResult routeResult, int routeId) {
super(mapActivity); super(mapActivity);
this.startPoint = startPoint;
this.endPoint = endPoint;
this.routeResult = routeResult; this.routeResult = routeResult;
this.routeId = routeId; this.routeId = routeId;
} }
@ -52,6 +69,14 @@ public class PublicTransportCard extends BaseCard {
return R.layout.transport_route_card; return R.layout.transport_route_card;
} }
public PublicTransportCardListener getTransportCardListener() {
return transportCardListener;
}
public void setTransportCardListener(PublicTransportCardListener listener) {
this.transportCardListener = listener;
}
@Override @Override
protected void updateContent() { protected void updateContent() {
List<TransportRouteResultSegment> segments = routeResult.getSegments(); List<TransportRouteResultSegment> segments = routeResult.getSegments();
@ -177,14 +202,29 @@ public class PublicTransportCard extends BaseCard {
FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges); FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges);
routesBadges.removeAllViews(); routesBadges.removeAllViews();
TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
Iterator<TransportRouteResultSegment> iterator = segments.iterator(); Iterator<TransportRouteResultSegment> iterator = segments.iterator();
TransportRouteResultSegment prevSegment = null;
while (iterator.hasNext()) { while (iterator.hasNext()) {
TransportRouteResultSegment s = iterator.next(); TransportRouteResultSegment s = iterator.next();
if (s.walkDist > 0) { RouteCalculationResult walkingSegment = transportRoutingHelper.getWalkingRouteSegment(prevSegment, s);
if (walkingSegment != null) {
double walkTime = walkingSegment.getRoutingTime();
if (walkTime > MIN_WALK_TIME) {
routesBadges.addView(createWalkRouteBadge(walkingSegment), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
}
} else if (s.walkDist > 0) {
double walkTime = getWalkTime(s.walkDist, routeResult.getWalkSpeed()); double walkTime = getWalkTime(s.walkDist, routeResult.getWalkSpeed());
if (walkTime > MIN_WALK_TIME) { if (walkTime > MIN_WALK_TIME) {
String walkTimeS = OsmAndFormatter.getFormattedDuration((int) walkTime, app); LatLon start;
routesBadges.addView(createWalkRouteBadge(walkTimeS), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); LatLon end = s.getEnd().getLocation();
if (prevSegment != null) {
start = prevSegment.getStart().getLocation();
} else {
start = this.startPoint.point;
}
routesBadges.addView(createWalkRouteBadge(walkTime, start, end), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} }
} }
@ -192,60 +232,96 @@ public class PublicTransportCard extends BaseCard {
if (iterator.hasNext()) { if (iterator.hasNext()) {
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
} else { } else {
double finishWalkDist = routeResult.getFinishWalkDist(); walkingSegment = transportRoutingHelper.getWalkingRouteSegment(s, null);
if (finishWalkDist > 0) { if (walkingSegment != null) {
double walkTime2 = getWalkTime(finishWalkDist, routeResult.getWalkSpeed()); double walkTime = walkingSegment.getRoutingTime();
if (walkTime2 > MIN_WALK_TIME) { if (walkTime > MIN_WALK_TIME) {
String walkTimeS = OsmAndFormatter.getFormattedDuration((int) walkTime2, app);
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing)); routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createWalkRouteBadge(walkTimeS)); routesBadges.addView(createWalkRouteBadge(walkingSegment), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
}
} else {
double finishWalkDist = routeResult.getFinishWalkDist();
if (finishWalkDist > 0) {
double walkTime = getWalkTime(finishWalkDist, routeResult.getWalkSpeed());
if (walkTime > MIN_WALK_TIME) {
LatLon start = s.getEnd().getLocation();
LatLon end = this.endPoint.point;
routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
routesBadges.addView(createWalkRouteBadge(walkTime, start, end));
}
} }
} }
} }
prevSegment = s;
} }
} }
private View createRouteBadge(TransportRouteResultSegment segment) { private View createRouteBadge(@NonNull final TransportRouteResultSegment segment) {
LinearLayout convertView = (LinearLayout) getMapActivity().getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false); LinearLayout bageView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
if (segment != null) { TransportRoute transportRoute = segment.route;
TransportRoute transportRoute = segment.route; TransportStopRoute transportStopRoute = TransportStopRoute.getTransportStopRoute(transportRoute, segment.getStart());
TransportStopRoute transportStopRoute = TransportStopRoute.getTransportStopRoute(transportRoute, segment.getStart());
String routeRef = segment.route.getAdjustedRouteRef(); String routeRef = segment.route.getAdjustedRouteRef();
int bgColor = transportStopRoute.getColor(app, nightMode); int bgColor = transportStopRoute.getColor(app, nightMode);
TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text); TextView transportStopRouteTextView = (TextView) bageView.findViewById(R.id.transport_stop_route_text);
ImageView transportStopRouteImageView = (ImageView) convertView.findViewById(R.id.transport_stop_route_icon); ImageView transportStopRouteImageView = (ImageView) bageView.findViewById(R.id.transport_stop_route_icon);
int drawableResId = transportStopRoute.type == null ? R.drawable.ic_action_bus_dark : transportStopRoute.type.getResourceId(); int drawableResId = transportStopRoute.type == null ? R.drawable.ic_action_bus_dark : transportStopRoute.type.getResourceId();
transportStopRouteImageView.setImageDrawable(app.getUIUtilities().getPaintedIcon(drawableResId, UiUtilities.getContrastColor(app, bgColor, true))); transportStopRouteImageView.setImageDrawable(app.getUIUtilities().getPaintedIcon(drawableResId, UiUtilities.getContrastColor(app, bgColor, true)));
transportStopRouteTextView.setText(routeRef); transportStopRouteTextView.setText(routeRef);
GradientDrawable gradientDrawableBg = (GradientDrawable) convertView.getBackground(); GradientDrawable gradientDrawableBg = (GradientDrawable) bageView.getBackground();
gradientDrawableBg.setColor(bgColor); gradientDrawableBg.setColor(bgColor);
transportStopRouteTextView.setTextColor(UiUtilities.getContrastColor(app, bgColor, true)); transportStopRouteTextView.setTextColor(UiUtilities.getContrastColor(app, bgColor, true));
if (transportCardListener != null) {
bageView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
transportCardListener.onPublicTransportCardBadgePressed(PublicTransportCard.this, segment);
}
});
} }
return bageView;
return convertView;
} }
private View createWalkRouteBadge(String walkTime) { private View createWalkRouteBadge(@NonNull final RouteCalculationResult result) {
LinearLayout convertView = (LinearLayout) getMapActivity().getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false); View v = createWalkRouteBadge(result.getRoutingTime(), null, null);
if (walkTime != null) { if (transportCardListener != null) {
int bgColor = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); v.setOnClickListener(new View.OnClickListener() {
@Override
TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text); public void onClick(View v) {
ImageView transportStopRouteImageView = (ImageView) convertView.findViewById(R.id.transport_stop_route_icon); transportCardListener.onPublicTransportCardBadgePressed(PublicTransportCard.this, result);
}
transportStopRouteImageView.setImageDrawable(getColoredIcon(R.drawable.ic_action_pedestrian_dark, nightMode ? R.color.ctx_menu_bottom_view_url_color_dark : R.color.ctx_menu_bottom_view_url_color_light)); });
transportStopRouteTextView.setText(walkTime);
GradientDrawable gradientDrawableBg = (GradientDrawable) convertView.getBackground();
gradientDrawableBg.setColor(bgColor);
transportStopRouteTextView.setTextColor(ContextCompat.getColor(app, nightMode ? R.color.ctx_menu_bottom_view_url_color_dark : R.color.ctx_menu_bottom_view_url_color_light));
AndroidUtils.setBackground(app, convertView, nightMode, R.drawable.btn_border_active_light, R.drawable.btn_border_active_dark);
} }
return v;
}
return convertView; private View createWalkRouteBadge(double walkTime, @Nullable final LatLon start, @Nullable final LatLon end) {
LinearLayout bageView = (LinearLayout) getMapActivity().getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
int bgColor = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
TextView transportStopRouteTextView = (TextView) bageView.findViewById(R.id.transport_stop_route_text);
ImageView transportStopRouteImageView = (ImageView) bageView.findViewById(R.id.transport_stop_route_icon);
transportStopRouteImageView.setImageDrawable(getColoredIcon(R.drawable.ic_action_pedestrian_dark, nightMode ? R.color.ctx_menu_bottom_view_url_color_dark : R.color.ctx_menu_bottom_view_url_color_light));
transportStopRouteTextView.setText(OsmAndFormatter.getFormattedDuration((int) walkTime, app));
GradientDrawable gradientDrawableBg = (GradientDrawable) bageView.getBackground();
gradientDrawableBg.setColor(bgColor);
transportStopRouteTextView.setTextColor(ContextCompat.getColor(app, nightMode ? R.color.ctx_menu_bottom_view_url_color_dark : R.color.ctx_menu_bottom_view_url_color_light));
AndroidUtils.setBackground(app, bageView, nightMode, R.drawable.btn_border_active_light, R.drawable.btn_border_active_dark);
if (transportCardListener != null && start != null && end != null) {
bageView.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
transportCardListener.onPublicTransportCardBadgePressed(PublicTransportCard.this, start, end);
}
});
}
return bageView;
} }
private View createArrow() { private View createArrow() {

View file

@ -105,7 +105,10 @@ public class TransportRoutingHelper {
@Nullable @Nullable
public RouteCalculationResult getWalkingRouteSegment(TransportRouteResultSegment s1, TransportRouteResultSegment s2) { public RouteCalculationResult getWalkingRouteSegment(TransportRouteResultSegment s1, TransportRouteResultSegment s2) {
return walkingRouteSegments.get(new Pair<>(s1, s2)); if (walkingRouteSegments != null) {
return walkingRouteSegments.get(new Pair<>(s1, s2));
}
return null;
} }
public void setCurrentRoute(int currentRoute) { public void setCurrentRoute(int currentRoute) {