diff --git a/OsmAnd/res/layout/warning_card.xml b/OsmAnd/res/layout/warning_card.xml index 9ea416e570..2f2c0811a0 100644 --- a/OsmAnd/res/layout/warning_card.xml +++ b/OsmAnd/res/layout/warning_card.xml @@ -38,7 +38,7 @@ tools:text="@string/public_transport_warning_title" /> + Unfortunately, OsmAnd could not find a route suitable for your settings. + Try the pedestrian navigation. + Try changing the settings. + Calculate pedestrian route + Transport type Send log Avoid trams Avoid trams diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 6f72eacd80..52e1cbd138 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -71,12 +71,15 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.routepreparationmenu.cards.HistoryCard; import net.osmand.plus.routepreparationmenu.cards.HomeWorkCard; +import net.osmand.plus.routepreparationmenu.cards.LongDistanceWarningCard; import net.osmand.plus.routepreparationmenu.cards.MapMarkersCard; import net.osmand.plus.routepreparationmenu.cards.PreviousRouteCard; +import net.osmand.plus.routepreparationmenu.cards.PublicTransportBetaWarningCard; import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard; +import net.osmand.plus.routepreparationmenu.cards.PublicTransportNotFoundSettingsWarningCard; +import net.osmand.plus.routepreparationmenu.cards.PublicTransportNotFoundWarningCard; import net.osmand.plus.routepreparationmenu.cards.SimpleRouteCard; import net.osmand.plus.routepreparationmenu.cards.TracksCard; -import net.osmand.plus.routepreparationmenu.cards.WarningCard; import net.osmand.plus.routing.IRouteInformationListener; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.TransportRoutingHelper; @@ -503,20 +506,40 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } else if (isTransportRouteCalculated()) { TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper(); List routes = transportRoutingHelper.getRoutes(); - for (int i = 0; i < routes.size(); i++) { - PublicTransportCard card = new PublicTransportCard(mapActivity, transportRoutingHelper.getStartLocation(), - transportRoutingHelper.getEndLocation(), routes.get(i), i); - card.setShowBottomShadow(i == routes.size() - 1); - card.setShowTopShadow(i != 0); - card.setListener(this); - menuCards.add(card); + if (routes != null && routes.size() > 0) { + for (int i = 0; i < routes.size(); i++) { + PublicTransportCard card = new PublicTransportCard(mapActivity, transportRoutingHelper.getStartLocation(), + transportRoutingHelper.getEndLocation(), routes.get(i), i); + card.setShowBottomShadow(i == routes.size() - 1); + card.setShowTopShadow(i != 0); + card.setListener(this); + menuCards.add(card); + } + bottomShadowVisible = routes.size() == 0; + } else { + RouteMenuAppModes mode = app.getRoutingOptionsHelper().modes.get(routingHelper.getAppMode()); + boolean avoidPTTypesCustomized = false; + for (LocalRoutingParameter parameter : mode.parameters) { + if (parameter instanceof AvoidPTTypesRoutingParameter) { + avoidPTTypesCustomized = true; + break; + } + } + if (avoidPTTypesCustomized) { + PublicTransportNotFoundSettingsWarningCard warningCard = new PublicTransportNotFoundSettingsWarningCard(mapActivity); + warningCard.setListener(this); + menuCards.add(warningCard); + } else { + PublicTransportNotFoundWarningCard warningCard = new PublicTransportNotFoundWarningCard(mapActivity); + warningCard.setListener(this); + menuCards.add(warningCard); + } } - bottomShadowVisible = routes.size() == 0; } else if (routeCalculationInProgress) { - if (app.getTargetPointsHelper().hasTooLongDistanceToNavigate() || routingHelper.isPublicTransportMode()) { - // WarningCard card - WarningCard warningCard = new WarningCard(mapActivity); - menuCards.add(warningCard); + if (app.getRoutingHelper().isPublicTransportMode()) { + menuCards.add(new PublicTransportBetaWarningCard(mapActivity)); + } else if (app.getTargetPointsHelper().hasTooLongDistanceToNavigate()) { + menuCards.add(new LongDistanceWarningCard(mapActivity)); } } else { // Home/work card @@ -631,6 +654,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } else if (card instanceof SimpleRouteCard) { hide(); ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), 0, MenuState.FULL_SCREEN); + } else if (card instanceof PublicTransportNotFoundWarningCard) { + updateApplicationMode(null, ApplicationMode.PEDESTRIAN); + } else if (card instanceof PublicTransportNotFoundSettingsWarningCard) { + AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(true); + avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG); } } } @@ -647,6 +675,15 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener return false; } + public boolean hasTransportRoutes() { + OsmandApplication app = getApp(); + if (app != null) { + List routes = app.getTransportRoutingHelper().getRoutes(); + return routes != null && routes.size() > 0; + } + return false; + } + public boolean isBasicRouteCalculated() { OsmandApplication app = getApp(); if (app != null) { @@ -868,7 +905,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener int color1; int color2; if (publicTransportMode) { - if (routeCalculated) { + if (routeCalculated && hasTransportRoutes()) { color1 = nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light; AndroidUtils.setBackground(app, startButton, nightMode, R.color.card_and_list_background_light, R.color.card_and_list_background_dark); color2 = color1; @@ -1315,15 +1352,18 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { OsmandApplication app = mapActivity.getMyApplication(); - if (mapActivity.getPointToNavigate() != null) { - hide(); - } if (app.getRoutingHelper().isPublicTransportMode()) { - if (isTransportRouteCalculated()) { + if (isTransportRouteCalculated() && hasTransportRoutes()) { + if (mapActivity.getPointToNavigate() != null) { + hide(); + } ChooseRouteFragment.showFromRouteInfo(mapActivity.getSupportFragmentManager(), app.getTransportRoutingHelper().getCurrentRoute(), MenuState.HEADER_ONLY); } } else { + if (mapActivity.getPointToNavigate() != null) { + hide(); + } mapActivity.getMapLayers().getMapControlsLayer().startNavigation(); } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/LongDistanceWarningCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/LongDistanceWarningCard.java new file mode 100644 index 0000000000..f34b5de5fb --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/LongDistanceWarningCard.java @@ -0,0 +1,23 @@ +package net.osmand.plus.routepreparationmenu.cards; + +import android.support.annotation.NonNull; + +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.routepreparationmenu.AddPointBottomSheetDialog; +import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; + +public class LongDistanceWarningCard extends WarningCard { + + public LongDistanceWarningCard(@NonNull MapActivity mapActivity) { + super(mapActivity); + imageId = R.drawable.ic_action_waypoint; + title = mapActivity.getString(R.string.route_is_too_long_v2); + linkText = mapActivity.getString(R.string.add_intermediate); + } + + @Override + protected void onLinkClicked() { + AddPointBottomSheetDialog.showInstance(mapActivity, MapRouteInfoMenu.PointType.INTERMEDIATE); + } +} diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportBetaWarningCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportBetaWarningCard.java new file mode 100644 index 0000000000..08e7861cfc --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportBetaWarningCard.java @@ -0,0 +1,27 @@ +package net.osmand.plus.routepreparationmenu.cards; + +import android.net.Uri; +import android.support.annotation.NonNull; + +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.wikipedia.WikipediaDialogFragment; + +public class PublicTransportBetaWarningCard extends WarningCard { + + private static final String OSMAND_BLOG_LINK = "https://osmand.net/blog/guideline-pt"; + + public PublicTransportBetaWarningCard(@NonNull MapActivity mapActivity) { + super(mapActivity); + imageId = R.drawable.ic_action_bus_dark; + title = mapActivity.getString(R.string.public_transport_warning_title); + linkText = mapActivity.getString(R.string.public_transport_warning_descr_blog); + startLinkIndex = linkText.lastIndexOf(" "); + endLinkIndex = linkText.length() - 1; + } + + @Override + protected void onLinkClicked() { + WikipediaDialogFragment.showFullArticle(mapActivity, Uri.parse(OSMAND_BLOG_LINK), nightMode); + } +} diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportNotFoundSettingsWarningCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportNotFoundSettingsWarningCard.java new file mode 100644 index 0000000000..883a0645a9 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportNotFoundSettingsWarningCard.java @@ -0,0 +1,16 @@ +package net.osmand.plus.routepreparationmenu.cards; + +import android.support.annotation.NonNull; + +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; + +public class PublicTransportNotFoundSettingsWarningCard extends WarningCard { + + public PublicTransportNotFoundSettingsWarningCard(@NonNull MapActivity mapActivity) { + super(mapActivity); + imageId = R.drawable.ic_action_no_route; + title = mapActivity.getString(R.string.public_transport_no_route_title) + "\n\n" + mapActivity.getString(R.string.public_transport_try_change_settings); + linkText = mapActivity.getString(R.string.public_transport_type); + } +} diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportNotFoundWarningCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportNotFoundWarningCard.java new file mode 100644 index 0000000000..42f28cf001 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportNotFoundWarningCard.java @@ -0,0 +1,16 @@ +package net.osmand.plus.routepreparationmenu.cards; + +import android.support.annotation.NonNull; + +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; + +public class PublicTransportNotFoundWarningCard extends WarningCard { + + public PublicTransportNotFoundWarningCard(@NonNull MapActivity mapActivity) { + super(mapActivity); + imageId = R.drawable.ic_action_pedestrian_dark; + title = mapActivity.getString(R.string.public_transport_no_route_title) + "\n\n" + mapActivity.getString(R.string.public_transport_try_ped); + linkText = mapActivity.getString(R.string.public_transport_calc_pedestrian); + } +} diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/WarningCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/WarningCard.java index f02032e257..7ad203f867 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/WarningCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/WarningCard.java @@ -1,7 +1,7 @@ package net.osmand.plus.routepreparationmenu.cards; import android.graphics.Typeface; -import android.net.Uri; +import android.graphics.drawable.Drawable; import android.support.annotation.NonNull; import android.text.SpannableString; import android.text.Spanned; @@ -15,18 +15,40 @@ import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.routepreparationmenu.AddPointBottomSheetDialog; -import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType; -import net.osmand.plus.wikipedia.WikipediaDialogFragment; +import net.osmand.util.Algorithms; -public class WarningCard extends BaseCard { +public abstract class WarningCard extends BaseCard { - public static final String OSMAND_BLOG_LINK = "https://osmand.net/blog/guideline-pt"; + protected int imageId; + protected Drawable imageDrawable; + protected String title; + protected String linkText; + protected int startLinkIndex = -1; + protected int endLinkIndex; - public WarningCard(MapActivity mapActivity) { + protected WarningCard(@NonNull MapActivity mapActivity) { super(mapActivity); } + public int getImageId() { + return imageId; + } + + public Drawable getImageDrawable() { + return imageDrawable; + } + + public String getTitle() { + return title; + } + + public String getLinkText() { + return linkText; + } + + protected void onLinkClicked() { + } + @Override public int getCardLayoutId() { return R.layout.warning_card; @@ -36,13 +58,18 @@ public class WarningCard extends BaseCard { protected void updateContent() { ImageView icon = (ImageView) view.findViewById(R.id.warning_img); TextView warningTitle = (TextView) view.findViewById(R.id.warning_title); - TextView warningDescr = (TextView) view.findViewById(R.id.warning_descr); + TextView warningLink = (TextView) view.findViewById(R.id.warning_link); - if (app.getRoutingHelper().isPublicTransportMode()) { - icon.setImageDrawable(getContentIcon(R.drawable.ic_action_bus_dark)); - warningTitle.setText(R.string.public_transport_warning_title); + if (imageDrawable != null) { + icon.setImageDrawable(imageDrawable); + } else if (imageId != 0) { + icon.setImageDrawable(getContentIcon(imageId)); + } + warningTitle.setText(title); + warningLink.setVisibility(!Algorithms.isEmpty(title) ? View.VISIBLE : View.GONE); - String text = app.getString(R.string.public_transport_warning_descr_blog); + if (!Algorithms.isEmpty(linkText)) { + String text = linkText; SpannableString spannable = new SpannableString(text); ClickableSpan clickableSpan = new ClickableSpan() { @Override @@ -53,37 +80,28 @@ public class WarningCard extends BaseCard { @Override public void onClick(@NonNull View widget) { - WikipediaDialogFragment.showFullArticle(mapActivity, Uri.parse(OSMAND_BLOG_LINK), nightMode); + CardListener listener = getListener(); + if (listener != null) { + listener.onCardButtonPressed(WarningCard.this, 0); + } else { + onLinkClicked(); + } } }; - int startIndex = text.lastIndexOf(" "); - if (startIndex != -1) { - spannable.setSpan(clickableSpan, startIndex, text.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - spannable.setSpan(new StyleSpan(Typeface.BOLD), startIndex, text.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - warningDescr.setMovementMethod(LinkMovementMethod.getInstance()); + int startLinkIndex = this.startLinkIndex; + int endLinkIndex = this.endLinkIndex; + if (startLinkIndex < 0 || endLinkIndex == 0) { + startLinkIndex = 0; + endLinkIndex = text.length(); + warningLink.setTextSize(15); } - warningDescr.setText(spannable); + spannable.setSpan(clickableSpan, startLinkIndex, endLinkIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + spannable.setSpan(new StyleSpan(Typeface.BOLD), startLinkIndex, endLinkIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + warningLink.setMovementMethod(LinkMovementMethod.getInstance()); + warningLink.setText(spannable); + warningLink.setVisibility(View.VISIBLE); } else { - icon.setImageDrawable(getContentIcon(R.drawable.ic_action_waypoint)); - warningTitle.setText(R.string.route_is_too_long_v2); - SpannableString text = new SpannableString(app.getString(R.string.add_intermediate)); - ClickableSpan clickableSpan = new ClickableSpan() { - @Override - public void updateDrawState(@NonNull TextPaint ds) { - ds.setColor(getActiveColor()); - ds.setUnderlineText(false); - } - - @Override - public void onClick(@NonNull View widget) { - AddPointBottomSheetDialog.showInstance(mapActivity, PointType.INTERMEDIATE); - } - }; - text.setSpan(clickableSpan, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - text.setSpan(new StyleSpan(Typeface.BOLD), 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - warningDescr.setMovementMethod(LinkMovementMethod.getInstance()); - warningDescr.setTextSize(15); - warningDescr.setText(text); + warningLink.setVisibility(View.GONE); } } } \ No newline at end of file