Merge branch 'r3.3'

This commit is contained in:
crimean 2019-04-22 17:11:47 +03:00
commit 0e4e09372e
9 changed files with 204 additions and 59 deletions

View file

@ -38,7 +38,7 @@
tools:text="@string/public_transport_warning_title" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/warning_descr"
android:id="@+id/warning_link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/text_button_letter_spacing"

View file

@ -11,6 +11,11 @@
Thx - Hardy
-->
<string name="public_transport_no_route_title">Unfortunately, OsmAnd could not find a route suitable for your settings.</string>
<string name="public_transport_try_ped">Try the pedestrian navigation.</string>
<string name="public_transport_try_change_settings">Try changing the settings.</string>
<string name="public_transport_calc_pedestrian">Calculate pedestrian route</string>
<string name="public_transport_type">Transport type</string>
<string name="send_log">Send log</string>
<string name="routing_attr_avoid_tram_name">Avoid trams</string>
<string name="routing_attr_avoid_tram_description">Avoid trams</string>

View file

@ -147,7 +147,7 @@ public class TrackDetailsMenu {
if (mapActivity != null && gpxItem != null) {
OsmandApplication app = mapActivity.getMyApplication();
GPXFile groupGpx = gpxItem.group.getGpx();
if (groupGpx != null) {
if (groupGpx != null && !gpxItem.route) {
gpxItem.wasHidden = app.getSelectedGpxHelper().getSelectedFileByPath(groupGpx.path) == null;
app.getSelectedGpxHelper().setGpxFileToDisplay(groupGpx);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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