Added pedestrian route proposal card

This commit is contained in:
crimean 2019-04-22 22:24:15 +03:00
parent ae0c12902c
commit ea63ffcf4f
5 changed files with 196 additions and 4 deletions

View file

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/route_info_details_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/card_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/list_item_divider" />
</LinearLayout>
<View
android:id="@+id/top_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/divider_color_basic"
android:focusable="false" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/card_and_list_background_basic"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginTop="@dimen/context_menu_padding_margin_large"
android:layout_marginEnd="@dimen/favorites_icon_right_margin"
android:layout_marginRight="@dimen/favorites_icon_right_margin"
android:src="@drawable/ic_action_pedestrian_dark"
android:tint="@color/description_font_and_bottom_sheet_icons" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/context_menu_padding_margin_large"
android:layout_marginEnd="@dimen/route_info_settings_buttons_height"
android:layout_marginRight="@dimen/route_info_settings_buttons_height"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:textColor="@color/description_font_and_bottom_sheet_icons"
android:textSize="@dimen/default_desc_text_size"
tools:ignore="UnusedAttribute"
tools:text="@string/public_transport_ped_route_title" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="@dimen/route_info_buttons_height"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/route_info_buttons_padding_top_bottom"
android:layout_marginTop="@dimen/route_info_details_padding"
android:layout_marginRight="@dimen/route_info_buttons_padding_top_bottom"
android:layout_marginBottom="@dimen/route_info_details_padding"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_descr"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:text="@string/public_transport_calc_pedestrian"
android:textColor="?attr/active_color_basic"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute" />
</FrameLayout>
</LinearLayout>
<include
android:id="@+id/shadow"
layout="@layout/card_bottom_divider"
android:visibility="visible" />
</LinearLayout>

View file

@ -11,6 +11,7 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="public_transport_ped_route_title">The route by foot is approximately %1$s and it could be faster than by public transport</string>
<string name="public_transport_no_route_title">Unfortunately, OsmAnd could not find a route suitable for your settings.</string> <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_ped">Try the pedestrian navigation.</string>
<string name="public_transport_try_change_settings">Try changing the settings.</string> <string name="public_transport_try_change_settings">Try changing the settings.</string>

View file

@ -73,6 +73,7 @@ import net.osmand.plus.routepreparationmenu.cards.HistoryCard;
import net.osmand.plus.routepreparationmenu.cards.HomeWorkCard; import net.osmand.plus.routepreparationmenu.cards.HomeWorkCard;
import net.osmand.plus.routepreparationmenu.cards.LongDistanceWarningCard; import net.osmand.plus.routepreparationmenu.cards.LongDistanceWarningCard;
import net.osmand.plus.routepreparationmenu.cards.MapMarkersCard; import net.osmand.plus.routepreparationmenu.cards.MapMarkersCard;
import net.osmand.plus.routepreparationmenu.cards.PedestrianRouteCard;
import net.osmand.plus.routepreparationmenu.cards.PreviousRouteCard; import net.osmand.plus.routepreparationmenu.cards.PreviousRouteCard;
import net.osmand.plus.routepreparationmenu.cards.PublicTransportBetaWarningCard; import net.osmand.plus.routepreparationmenu.cards.PublicTransportBetaWarningCard;
import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard; import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard;
@ -90,6 +91,7 @@ import net.osmand.router.GeneralRouter.RoutingParameter;
import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.SearchUICore.SearchResultCollection;
import net.osmand.search.core.SearchResult; import net.osmand.search.core.SearchResult;
import net.osmand.util.MapUtils;
import java.io.IOException; import java.io.IOException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -106,6 +108,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
private static final int BUTTON_ANIMATION_DELAY = 2000; private static final int BUTTON_ANIMATION_DELAY = 2000;
public static final int DEFAULT_MENU_STATE = 0; public static final int DEFAULT_MENU_STATE = 0;
private static final int MAX_PEDESTRIAN_ROUTE_DURATION = 30 * 60;
public static int directionInfo = -1; public static int directionInfo = -1;
public static boolean chooseRoutesVisible = false; public static boolean chooseRoutesVisible = false;
@ -507,14 +510,28 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper(); TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
List<TransportRouteResult> routes = transportRoutingHelper.getRoutes(); List<TransportRouteResult> routes = transportRoutingHelper.getRoutes();
if (routes != null && routes.size() > 0) { if (routes != null && routes.size() > 0) {
TransportRouteResult route = routes.get(0);
int walkTimeReal = transportRoutingHelper.getWalkingTime(route.getSegments());
int walkTimePT = (int) route.getWalkTime();
int walkTime = walkTimeReal > 0 ? walkTimeReal : walkTimePT;
int travelTime = (int) route.getTravelTime() + walkTime;
LatLon startLocation = transportRoutingHelper.getStartLocation();
LatLon endLocation = transportRoutingHelper.getEndLocation();
int approxPedestrianTime = (int) MapUtils.getDistance(startLocation, endLocation);
boolean showPedestrianCard = approxPedestrianTime < travelTime + 60 && approxPedestrianTime < MAX_PEDESTRIAN_ROUTE_DURATION;
for (int i = 0; i < routes.size(); i++) { for (int i = 0; i < routes.size(); i++) {
PublicTransportCard card = new PublicTransportCard(mapActivity, transportRoutingHelper.getStartLocation(), route = routes.get(i);
transportRoutingHelper.getEndLocation(), routes.get(i), i); PublicTransportCard card = new PublicTransportCard(mapActivity, startLocation, endLocation, route, i);
card.setShowBottomShadow(i == routes.size() - 1); card.setShowBottomShadow(i == routes.size() - 1 && !showPedestrianCard);
card.setShowTopShadow(i != 0); card.setShowTopShadow(i != 0);
card.setListener(this); card.setListener(this);
menuCards.add(card); menuCards.add(card);
} }
if (showPedestrianCard) {
PedestrianRouteCard pedestrianRouteCard = new PedestrianRouteCard(mapActivity, approxPedestrianTime);
pedestrianRouteCard.setListener(this);
menuCards.add(pedestrianRouteCard);
}
bottomShadowVisible = routes.size() == 0; bottomShadowVisible = routes.size() == 0;
} else { } else {
RouteMenuAppModes mode = app.getRoutingOptionsHelper().modes.get(routingHelper.getAppMode()); RouteMenuAppModes mode = app.getRoutingOptionsHelper().modes.get(routingHelper.getAppMode());
@ -659,6 +676,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} else if (card instanceof PublicTransportNotFoundSettingsWarningCard) { } else if (card instanceof PublicTransportNotFoundSettingsWarningCard) {
AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(true); AvoidRoadsBottomSheetDialogFragment avoidRoadsFragment = new AvoidRoadsBottomSheetDialogFragment(true);
avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG); avoidRoadsFragment.show(mapActivity.getSupportFragmentManager(), AvoidRoadsBottomSheetDialogFragment.TAG);
} else if (card instanceof PedestrianRouteCard) {
updateApplicationMode(null, ApplicationMode.PEDESTRIAN);
} }
} }
} }

View file

@ -35,7 +35,6 @@ import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider; import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider;
import com.github.mikephil.charting.listener.ChartTouchListener;
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture; import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture;
import com.github.mikephil.charting.renderer.HorizontalBarChartRenderer; import com.github.mikephil.charting.renderer.HorizontalBarChartRenderer;
import com.github.mikephil.charting.utils.ViewPortHandler; import com.github.mikephil.charting.utils.ViewPortHandler;
@ -214,6 +213,7 @@ public class RouteDetailsFragment extends ContextMenuFragment implements PublicT
mapActivity.findViewById(R.id.bottom_controls_container).setVisibility(View.VISIBLE); mapActivity.findViewById(R.id.bottom_controls_container).setVisibility(View.VISIBLE);
if (routeDetailsMenu != null) { if (routeDetailsMenu != null) {
routeDetailsMenu.setMapActivity(null); routeDetailsMenu.setMapActivity(null);
mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(null);
} }
} }
super.onPause(); super.onPause();

View file

@ -0,0 +1,64 @@
package net.osmand.plus.routepreparationmenu.cards;
import android.graphics.Typeface;
import android.os.Build;
import android.support.annotation.NonNull;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
public class PedestrianRouteCard extends BaseCard {
private int approxPedestrianTime;
public PedestrianRouteCard(@NonNull MapActivity mapActivity, int approxPedestrianTime) {
super(mapActivity);
this.approxPedestrianTime = approxPedestrianTime;
}
@Override
public int getCardLayoutId() {
return R.layout.route_ped_info;
}
@Override
protected void updateContent() {
TextView titleView = (TextView) view.findViewById(R.id.title);
String text = app.getString(R.string.public_transport_ped_route_title);
String formattedDuration = OsmAndFormatter.getFormattedDuration(approxPedestrianTime, app);
int start = text.indexOf("%1$s");
int end = start + formattedDuration.length();
text = text.replace("%1$s", formattedDuration);
SpannableString spannable = new SpannableString(text);
spannable.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
titleView.setText(spannable);
FrameLayout button = view.findViewById(R.id.button);
View buttonDescr = view.findViewById(R.id.button_descr);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CardListener listener = getListener();
if (listener != null) {
listener.onCardButtonPressed(PedestrianRouteCard.this, 0);
}
}
});
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, button, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark);
AndroidUtils.setBackground(app, buttonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setBackground(app, buttonDescr, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark);
}
view.findViewById(R.id.card_divider).setVisibility(View.VISIBLE);
view.findViewById(R.id.top_divider).setVisibility(View.GONE);
}
}