diff --git a/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java b/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java index c242dab252..f033992a46 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/MapUtils.java @@ -553,10 +553,6 @@ public class MapUtils { return sa < 0; } - - - - public static long deinterleaveY(long coord) { long x = 0; for (byte b = 31; b >= 0; b--) { @@ -607,6 +603,20 @@ public class MapUtils { return y1; } } + + public static void insetLatLonRect(QuadRect r, double latitude, double longitude) { + if (r.left == 0 && r.right == 0) { + r.left = longitude; + r.right = longitude; + r.top = latitude; + r.bottom = latitude; + } else { + r.left = Math.min(r.left, longitude); + r.right = Math.max(r.right, longitude); + r.top = Math.max(r.top, latitude); + r.bottom = Math.min(r.bottom, latitude); + } + } } diff --git a/OsmAnd/res/drawable/btn_active_dark.xml b/OsmAnd/res/drawable/btn_active_dark.xml new file mode 100644 index 0000000000..30d5835f31 --- /dev/null +++ b/OsmAnd/res/drawable/btn_active_dark.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/btn_active_light.xml b/OsmAnd/res/drawable/btn_active_light.xml new file mode 100644 index 0000000000..c53e42ef98 --- /dev/null +++ b/OsmAnd/res/drawable/btn_active_light.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/btn_active_trans_dark.xml b/OsmAnd/res/drawable/btn_active_trans_dark.xml new file mode 100644 index 0000000000..c09053eb61 --- /dev/null +++ b/OsmAnd/res/drawable/btn_active_trans_dark.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/btn_active_trans_light.xml b/OsmAnd/res/drawable/btn_active_trans_light.xml new file mode 100644 index 0000000000..b4bcb2dbb2 --- /dev/null +++ b/OsmAnd/res/drawable/btn_active_trans_light.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/ripple_active_dark.xml b/OsmAnd/res/drawable/ripple_active_dark.xml new file mode 100644 index 0000000000..fb06db30be --- /dev/null +++ b/OsmAnd/res/drawable/ripple_active_dark.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/ripple_active_light.xml b/OsmAnd/res/drawable/ripple_active_light.xml new file mode 100644 index 0000000000..e35f875a09 --- /dev/null +++ b/OsmAnd/res/drawable/ripple_active_light.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/transport_route_card.xml b/OsmAnd/res/layout/transport_route_card.xml index 6301bd4fcc..f1bed0bafa 100644 --- a/OsmAnd/res/layout/transport_route_card.xml +++ b/OsmAnd/res/layout/transport_route_card.xml @@ -107,8 +107,7 @@ android:layout_marginLeft="@dimen/content_padding" android:layout_marginRight="@dimen/content_padding" android:layout_weight="1" - android:orientation="horizontal" - android:visibility="gone"> + android:orientation="horizontal"> nodes = segment.getNodes(); - for (Node n : nodes) { - 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); - } - - @Nullable - private QuadRect getWalkingSegmentRect(@NonNull RouteCalculationResult result) { - double left = 0, right = 0; - double top = 0, bottom = 0; - for (Location p : result.getRouteLocations()) { - if (left == 0 && right == 0) { - left = p.getLongitude(); - right = p.getLongitude(); - top = p.getLatitude(); - bottom = p.getLatitude(); - } else { - left = Math.min(left, p.getLongitude()); - right = Math.max(right, p.getLongitude()); - top = Math.max(top, p.getLatitude()); - bottom = Math.min(bottom, p.getLatitude()); - } - } - return left == 0 && right == 0 ? null : new QuadRect(left, top, right, bottom); - } - private void showOnMap(@NonNull LatLon latLon) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { int currentZoom = mapActivity.getMapView().getZoom(); - mapActivity.getMapView().getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), Math.max(13, currentZoom), true); + mapActivity.getMapView().getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), Math.max(15, currentZoom), true); } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index fea72f9462..ec59d1da56 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -19,28 +19,27 @@ import android.widget.LinearLayout; import net.osmand.AndroidUtils; import net.osmand.Location; +import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; -import net.osmand.osm.edit.Node; import net.osmand.plus.LockableViewPager; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.ShowRouteInfoDialogFragment; import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.TransportRoutingHelper; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.router.TransportRoutePlanner.TransportRouteResult; -import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment; import java.util.ArrayList; import java.util.List; -public class ChooseRouteFragment extends BaseOsmAndFragment { +public class ChooseRouteFragment extends BaseOsmAndFragment implements CardListener { public static final String TAG = "ChooseRouteFragment"; @@ -50,6 +49,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment { private View view; private LockableViewPager viewPager; private ImageButton myLocButtonView; + private List routeCards = new ArrayList<>(); private boolean portrait; private boolean nightMode; @@ -58,21 +58,21 @@ public class ChooseRouteFragment extends BaseOsmAndFragment { @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - mapActivity = (MapActivity) getActivity(); + mapActivity = (MapActivity) requireActivity(); nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); map = getMapActivity().getMapView(); - List routes = getMyApplication().getTransportRoutingHelper().getRoutes(); + OsmandApplication app = mapActivity.getMyApplication(); + List routes = app.getTransportRoutingHelper().getRoutes(); if (routes != null && !routes.isEmpty()) { view = inflater.inflate(R.layout.fragment_show_all_routes, null); viewPager = view.findViewById(R.id.pager); AndroidUtils.addStatusBarPadding21v(mapActivity, view); - final List routeCards = new ArrayList<>(); for (int i = 0; i < routes.size(); i++) { PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i); - card.setSecondButtonVisible(true); + card.setListener(this); card.setShowTopShadow(false); card.setShowBottomShadow(false); routeCards.add(card); @@ -91,11 +91,14 @@ public class ChooseRouteFragment extends BaseOsmAndFragment { public void onPageSelected(int position) { mapActivity.getMyApplication().getTransportRoutingHelper().setCurrentRoute(routeCards.get(position).getRouteId()); mapActivity.refreshMap(); + for (PublicTransportCard card : routeCards) { + card.update(); + } } }); if (!portrait) { - LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(getMyApplication(), 200f)); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(app, 200f)); params.gravity = Gravity.BOTTOM; viewPager.setLayoutParams(params); } @@ -154,43 +157,20 @@ public class ChooseRouteFragment extends BaseOsmAndFragment { } private void adjustMapPosition() { - RoutingHelper rh = mapActivity.getRoutingHelper(); - OsmandApplication app = mapActivity.getMyApplication(); - TransportRoutingHelper transportRoutingHelper = rh.getTransportRoutingHelper(); - if (getMapActivity().getMapView() != null) { - Location lt = rh.getLastProjection(); - if (lt == null) { - lt = app.getTargetPointsHelper().getPointToStartLocation(); - } - if (lt != null) { - double left = lt.getLongitude(), right = lt.getLongitude(); - double top = lt.getLatitude(), bottom = lt.getLatitude(); - List list = rh.getCurrentCalculatedRoute(); - for (Location l : list) { - left = Math.min(left, l.getLongitude()); - right = Math.max(right, l.getLongitude()); - top = Math.max(top, l.getLatitude()); - bottom = Math.min(bottom, l.getLatitude()); - } + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + OsmandMapTileView mapView = mapActivity.getMapView(); + if (mapView != null) { + RoutingHelper rh = mapActivity.getRoutingHelper(); + OsmandApplication app = mapActivity.getMyApplication(); + TransportRoutingHelper transportRoutingHelper = rh.getTransportRoutingHelper(); + + QuadRect rect = null; TransportRouteResult result = transportRoutingHelper.getCurrentRouteResult(); if (result != null) { - for (TransportRouteResultSegment segment : result.getSegments()) { - for (Node n : segment.getNodes()) { - left = Math.min(left, n.getLongitude()); - right = Math.max(right, n.getLongitude()); - top = Math.max(top, n.getLatitude()); - bottom = Math.min(bottom, n.getLatitude()); - } - } + rect = transportRoutingHelper.getTransportRouteRect(result); } - List targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget(); - for (TargetPointsHelper.TargetPoint l : targetPoints) { - left = Math.min(left, l.getLongitude()); - right = Math.max(right, l.getLongitude()); - top = Math.max(top, l.getLatitude()); - bottom = Math.min(bottom, l.getLatitude()); - } - RotatedTileBox tb = getMapActivity().getMapView().getCurrentRotatedTileBox().copy(); + RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy(); int tileBoxWidthPx = 0; int tileBoxHeightPx = 0; @@ -200,7 +180,9 @@ public class ChooseRouteFragment extends BaseOsmAndFragment { int fHeight = viewPager.getHeight() + AndroidUtils.getStatusBarHeight(app); tileBoxHeightPx = tb.getPixHeight() - fHeight; } - getMapActivity().getMapView().fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0); + if (rect != null) { + mapView.fitRectToMap(rect.left, rect.right, rect.top, rect.bottom, tileBoxWidthPx, tileBoxHeightPx, 0); + } } } } @@ -302,6 +284,21 @@ public class ChooseRouteFragment extends BaseOsmAndFragment { } } + @Override + public void onCardLayoutNeeded(@NonNull BaseCard card) { + } + + @Override + public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) { + if (card instanceof PublicTransportCard) { + if (buttonIndex == PublicTransportCard.SHOW_BUTTON_INDEX) { + for (PublicTransportCard transportCard : routeCards) { + transportCard.update(); + } + } + } + } + private class ViewsPagerAdapter extends PagerAdapter { private List cards; @@ -338,29 +335,10 @@ public class ChooseRouteFragment extends BaseOsmAndFragment { @NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, final int position) { - View view = createPageView(position); view.setBackgroundDrawable(null); view.setBackgroundResource(R.drawable.route_cards_topsides_light); - view.findViewById(R.id.details_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (position < cards.size()) { - int routeId = cards.get(position).getRouteId(); - mapActivity.getMyApplication().getTransportRoutingHelper().setCurrentRoute(routeId); - mapActivity.getMapView().refreshMap(true); - ShowRouteInfoDialogFragment.showInstance(mapActivity, routeId); - } - } - }); - view.findViewById(R.id.show_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - adjustMapPosition(); - } - }); container.addView(view, 0); - return view; } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index ce5eb6f8e4..bfc39ac32c 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -487,6 +487,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i); card.setShowBottomShadow(i == routes.size() - 1); card.setShowTopShadow(i != 0); + card.setListener(this); menuCards.add(card); } bottomShadowVisible = routes.size() == 0; @@ -580,6 +581,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener updateOptionsButtons(); app.getTargetPointsHelper().restoreTargetPoints(true); + } else if (card instanceof PublicTransportCard) { + if (buttonIndex == PublicTransportCard.SHOW_BUTTON_INDEX) { + setupCards(); + openMenuHeaderOnly(); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java index c1a8383666..e17f684b7e 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenuFragment.java @@ -31,22 +31,24 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.Location; +import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; -import net.osmand.osm.edit.Node; import net.osmand.plus.LockableScrollView; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; +import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.routing.TransportRoutingHelper; import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.widgets.ImageViewExProgress; import net.osmand.plus.widgets.TextViewExProgress; import net.osmand.router.TransportRoutePlanner.TransportRouteResult; -import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment; +import net.osmand.util.MapUtils; import java.util.List; @@ -725,52 +727,48 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment { RoutingHelper rh = app.getRoutingHelper(); if (rh.isRoutePlanningMode() && mapActivity.getMapView() != null) { - Location lt = rh.getLastProjection(); - if (lt == null) { - lt = app.getTargetPointsHelper().getPointToStartLocation(); - } - if (lt != null) { - double left = lt.getLongitude(), right = lt.getLongitude(); - double top = lt.getLatitude(), bottom = lt.getLatitude(); - List list = rh.getCurrentCalculatedRoute(); - for (Location l : list) { - left = Math.min(left, l.getLongitude()); - right = Math.max(right, l.getLongitude()); - top = Math.max(top, l.getLatitude()); - bottom = Math.min(bottom, l.getLatitude()); - } - if (menu.isTransportRouteCalculated()) { - TransportRouteResult result = app.getTransportRoutingHelper().getCurrentRouteResult(); - if (result != null) { - for (TransportRouteResultSegment segment : result.getSegments()) { - for (Node n : segment.getNodes()) { - left = Math.min(left, n.getLongitude()); - right = Math.max(right, n.getLongitude()); - top = Math.max(top, n.getLatitude()); - bottom = Math.min(bottom, n.getLatitude()); - } - } + QuadRect r = new QuadRect(0, 0, 0, 0); + if (menu.isTransportRouteCalculated()) { + TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper(); + TransportRouteResult result = transportRoutingHelper.getCurrentRouteResult(); + if (result != null) { + QuadRect transportRouteRect = transportRoutingHelper.getTransportRouteRect(result); + if (transportRouteRect != null) { + r = transportRouteRect; } } - List targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget(); - for (TargetPointsHelper.TargetPoint l : targetPoints) { - left = Math.min(left, l.getLongitude()); - right = Math.max(right, l.getLongitude()); - top = Math.max(top, l.getLatitude()); - bottom = Math.min(bottom, l.getLatitude()); + } else if (rh.isRouteCalculated()) { + Location lt = rh.getLastProjection(); + if (lt == null) { + lt = app.getTargetPointsHelper().getPointToStartLocation(); } - - RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy(); - int tileBoxWidthPx = 0; - int tileBoxHeightPx = 0; - - if (!portrait) { - tileBoxWidthPx = tb.getPixWidth() - getWidth(); - } else { - int fHeight = viewHeight - y - AndroidUtils.getStatusBarHeight(app); - tileBoxHeightPx = tb.getPixHeight() - fHeight; + if (lt == null) { + lt = app.getLocationProvider().getLastKnownLocation(); } - mapActivity.getMapView().fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0); + if (lt != null) { + MapUtils.insetLatLonRect(r, lt.getLatitude(), lt.getLongitude()); + } + List list = rh.getCurrentCalculatedRoute(); + for (Location l : list) { + MapUtils.insetLatLonRect(r, l.getLatitude(), l.getLongitude()); + } + List targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget(); + for (TargetPoint l : targetPoints) { + MapUtils.insetLatLonRect(r, l.getLatitude(), l.getLongitude()); + } + } + RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy(); + int tileBoxWidthPx = 0; + int tileBoxHeightPx = 0; + + if (!portrait) { + tileBoxWidthPx = tb.getPixWidth() - getWidth(); + } else { + int fHeight = viewHeight - y - AndroidUtils.getStatusBarHeight(app); + tileBoxHeightPx = tb.getPixHeight() - fHeight; + } + if (r.left != 0 && r.right != 0) { + mapActivity.getMapView().fitRectToMap(r.left, r.right, r.top, r.bottom, tileBoxWidthPx, tileBoxHeightPx, 0); } } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java index e6883be710..0e239a9fb0 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java @@ -33,11 +33,12 @@ import java.util.List; public class PublicTransportCard extends BaseCard { private static final int MIN_WALK_TIME = 120; + public static final int DETAILS_BUTTON_INDEX = 0; + public static final int SHOW_BUTTON_INDEX = 1; private TransportRouteResult routeResult; private int routeId; - private boolean secondButtonVisible; public PublicTransportCard(MapActivity mapActivity, TransportRouteResult routeResult, int routeId) { super(mapActivity); @@ -61,14 +62,6 @@ public class PublicTransportCard extends BaseCard { fromLine.setText(getFirstLineDescrSpan()); wayLine.setText(getSecondLineDescrSpan()); - view.findViewById(R.id.details_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - app.getTransportRoutingHelper().setCurrentRoute(routeId); - getMapActivity().refreshMap(); - ShowRouteInfoDialogFragment.showInstance(mapActivity, routeId); - } - }); FrameLayout detailsButton = (FrameLayout) view.findViewById(R.id.details_button); TextView detailsButtonDescr = (TextView) view.findViewById(R.id.details_button_descr); @@ -80,21 +73,44 @@ public class PublicTransportCard extends BaseCard { } int color = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light); detailsButtonDescr.setTextColor(color); + detailsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + app.getTransportRoutingHelper().setCurrentRoute(routeId); + getMapActivity().refreshMap(); + ShowRouteInfoDialogFragment.showInstance(mapActivity, routeId); + } + }); FrameLayout showButton = (FrameLayout) view.findViewById(R.id.show_button); - if (secondButtonVisible) { - TextView showButtonDescr = (TextView) view.findViewById(R.id.show_button_descr); + TextView showButtonDescr = (TextView) view.findViewById(R.id.show_button_descr); + if (isCurrentRoute()) { + color = ContextCompat.getColor(app, R.color.color_white); + AndroidUtils.setBackground(app, showButton, nightMode, R.drawable.btn_active_light, R.drawable.btn_active_dark); + showButtonDescr.setText(R.string.shared_string_selected); + showButton.setOnClickListener(null); + } else { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { AndroidUtils.setBackground(app, showButton, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark); AndroidUtils.setBackground(app, showButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); } else { AndroidUtils.setBackground(app, showButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); } - showButtonDescr.setTextColor(color); - showButton.setVisibility(View.VISIBLE); - } else { - showButton.setVisibility(View.GONE); + showButtonDescr.setText(R.string.shared_string_show_on_map); + showButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + app.getTransportRoutingHelper().setCurrentRoute(routeId); + getMapActivity().refreshMap(); + CardListener listener = getListener(); + if (listener != null) { + listener.onCardButtonPressed(PublicTransportCard.this, SHOW_BUTTON_INDEX); + } + } + }); } + showButtonDescr.setTextColor(color); + view.findViewById(R.id.bottom_shadow).setVisibility(showBottomShadow ? View.VISIBLE : View.GONE); view.findViewById(R.id.card_divider).setVisibility(showTopShadow ? View.VISIBLE : View.GONE); view.findViewById(R.id.top_divider).setVisibility(!showTopShadow ? View.VISIBLE : View.GONE); @@ -104,8 +120,8 @@ public class PublicTransportCard extends BaseCard { return routeId; } - public void setSecondButtonVisible(boolean secondButtonVisible) { - this.secondButtonVisible = secondButtonVisible; + public boolean isCurrentRoute() { + return routeId == app.getTransportRoutingHelper().getCurrentRoute(); } private SpannableString getFirstLineDescrSpan() { @@ -114,7 +130,7 @@ public class PublicTransportCard extends BaseCard { String firstLine = app.getString(R.string.route_from) + " " + name; if (segments.size() > 1) { - firstLine += ", " + app.getString(R.string.transfers) +": "+(segments.size() - 1); + firstLine += ", " + app.getString(R.string.transfers) + ": " + (segments.size() - 1); } SpannableString firstLineDesc = new SpannableString(firstLine); @@ -153,6 +169,7 @@ public class PublicTransportCard extends BaseCard { private void createRouteBadges(List segments) { int itemsSpacing = AndroidUtils.dpToPx(app, 6); FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges); + routesBadges.removeAllViews(); Iterator iterator = segments.iterator(); while (iterator.hasNext()) { @@ -213,11 +230,11 @@ public class PublicTransportCard extends BaseCard { TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text); ImageView transportStopRouteImageView = (ImageView) convertView.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 )); + 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)); + 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); } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 07beecfc44..630993d80d 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -1,6 +1,7 @@ package net.osmand.plus.routing; import android.content.Context; +import android.support.annotation.Nullable; import net.osmand.Location; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; @@ -8,6 +9,7 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; import net.osmand.data.LocationPoint; +import net.osmand.data.QuadRect; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -512,7 +514,26 @@ public class RouteCalculationResult { sum += originalDirections.get(i).getExpectedTime(); } } - + + @Nullable + public QuadRect getLocationsRect() { + double left = 0, right = 0; + double top = 0, bottom = 0; + for (Location p : locations) { + if (left == 0 && right == 0) { + left = p.getLongitude(); + right = p.getLongitude(); + top = p.getLatitude(); + bottom = p.getLatitude(); + } else { + left = Math.min(left, p.getLongitude()); + right = Math.max(right, p.getLongitude()); + top = Math.max(top, p.getLatitude()); + bottom = Math.min(bottom, p.getLatitude()); + } + } + return left == 0 && right == 0 ? null : new QuadRect(left, top, right, bottom); + } public static String toString(TurnType type, Context ctx, boolean shortName) { if(type.isRoundAbout()){ diff --git a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java index 1125c0a815..7f0db299c4 100644 --- a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java @@ -9,6 +9,8 @@ import net.osmand.PlatformUtil; import net.osmand.ValueHolder; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.LatLon; +import net.osmand.data.QuadRect; +import net.osmand.osm.edit.Node; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -281,6 +283,35 @@ public class TransportRoutingHelper { }); } + @Nullable + public QuadRect getTransportRouteRect(@NonNull TransportRouteResult result) { + TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper(); + QuadRect r = new QuadRect(0, 0, 0, 0); + TransportRouteResultSegment s1; + TransportRouteResultSegment s2 = null; + for (TransportRouteResultSegment segment : result.getSegments()) { + s1 = segment; + for (Node n : segment.getNodes()) { + MapUtils.insetLatLonRect(r, n.getLatitude(), n.getLongitude()); + } + RouteCalculationResult wrs = s2 == null ? transportRoutingHelper.getWalkingRouteSegment(null, s1) : + transportRoutingHelper.getWalkingRouteSegment(s1, s2); + if (wrs != null) { + for (Location p : wrs.getRouteLocations()) { + MapUtils.insetLatLonRect(r, p.getLatitude(), p.getLongitude()); + } + } + s2 = s1; + } + RouteCalculationResult wrs = transportRoutingHelper.getWalkingRouteSegment(s2, null); + if (wrs != null) { + for (Location p : wrs.getRouteLocations()) { + MapUtils.insetLatLonRect(r, p.getLatitude(), p.getLongitude()); + } + } + return r.left == 0 && r.right == 0 ? null : r; + } + public interface TransportRouteCalculationProgressCallback { void start();