From 33134102b4ad5e55379f8ea3d0ba17dbe195a168 Mon Sep 17 00:00:00 2001 From: Dmitriy Prodchenko Date: Tue, 12 Mar 2019 15:29:10 +0200 Subject: [PATCH 1/4] Delete wrong 9Patch image --- .../drawable-xhdpi/bt_route_details_shadow.9.png | Bin 4005 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 OsmAnd/res/drawable-xhdpi/bt_route_details_shadow.9.png diff --git a/OsmAnd/res/drawable-xhdpi/bt_route_details_shadow.9.png b/OsmAnd/res/drawable-xhdpi/bt_route_details_shadow.9.png deleted file mode 100644 index ed172f4c6e8d79ebcca85bd48ee59a12a6147a11..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4005 zcmbVPc{r5&-=49SwUv{ti4+kOH3iXl4xv3K9SS zK-%2Q#6~a%Zr)qO1WzOh-Xj?Hu(6J8Te=53fWRaJj+5x_WRN+P;7PV26G#`%w~~(n z0K$P3oFm)O>LiLtr)m>6G1`GthJXzK95oDN5QsixHprdqNui-t=c{W~K@<{N)d6Ou zW5vLby(nfuOtNi|HI5kMLqw8P4Ud722BHK8sAM()6iD@@u~30%)xYeb1oO>ph$`qW z2-^p(`nM=YtJ5G1ok<44wBcYPR9^>#Kx#wbI{Gl^VUVs46amqJL3H3?9Vkl20Hq5B z{kl{I-k2m0l#Pk$FJFQcTGflqW}qODfPet)06lFw(-Q(kB9RasU5KtOSbzYtF3{M7 zKroG^_S=F9nMGt$7;Fli2HLbpaHspR(W(Nae;fkZfb5O>hE)#keL*JGRc%lr-J^9 zG>Y;sD%=S~UAQ|O3P$MYdk7+c&;h#>1v4lT1}8uf`XoIhLiHD)^#6?@L?8;XSuX#l ze12~UYI1Y>PcsM>|FjdCCg>ripjloA%xC}rk`3l2$8mwfpYKrBaQl=&9uQ?l@i;FOn}2{`qQ*dW+UXDzZX&_%)v$kt+`jg4YFpJ2@MFCAY3-XF4;! zvMamE1`JS+Z2oFIVKj4N|6Jg1JRn(UwuP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correct 9Patch image --- .../drawable-xhdpi/bt_route_details_shadow.9.png | Bin 0 -> 4009 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 OsmAnd/res/drawable-xhdpi/bt_route_details_shadow.9.png diff --git a/OsmAnd/res/drawable-xhdpi/bt_route_details_shadow.9.png b/OsmAnd/res/drawable-xhdpi/bt_route_details_shadow.9.png new file mode 100644 index 0000000000000000000000000000000000000000..b4b5fc1928be13098991e42340a69f13738f93af GIT binary patch literal 4009 zcmbVPdpwi<`=3xKJSuc>SS!NX5t}WOj2spUD-|-^n8OZi4iQEnJV_!E!l{o{Fk|M=do*L{Bu_w~LG@9Vnm*ZqkZY_vkdU-Q&pwAB;fq>o=9O$T_E!>uc zr_#KwLIbFdp>|H>P+u~J0@`N+G!DUv70{_15-^1B$6#YaaG<~RV#V{-Z5Rmnmk7rf z2m0ldv+W@uo*6&|8bVPJGQt23L}Q=`6x_fNu?L8RBhWCoAq#2{0D+x8aQ{)I&z_^((jK7dN% zFaw;JOuye%aEQj_FxfOF3y83!b z`(M1!*GG98pgoNsXbhSPG4Rwkf?!a{RYHu=24ob*$Pg)J;1{0qzcL6DI|W-Um;WfA z-&^9ET%G>Y4C2Ko!U{9={<$LL?WjN*K->gAzHYg&jQavll+AU_T(Q3Z zCsB~jJ%FcDmSXkI-eD`~!rhNg;($NA$a`E~RQ+tI|cJ;c@Ol_Mj z+R|a~Z1ZSu@|#94FVRYfS8Am%Rh6ov`Ws z5*lq9JUSZVEHBaRx_MTO+iBX#km92XmqYe6Y3u#SOl(&hW?bcc)dkqa5Qq;f+#908 z6?eNAzR|$6a)H%m9w^MPu7qODgZ*RgK%I4lBb`rVGe4mPu_IQmAP)ZM-NP7wVpL+< z;w4Nj*odUR>9sb&2(SR3#H)j7MI~HDKt)Qb~9p& z=60lGrT?ZaXqM;4zMpxmyX7929u7!(_#jXBMt_EH)l74L+oJ624i`c2^vp6lp;SZi zMEbb~m!Adf7ZDG`Wjmp7)ubkiT0<*(T{yJB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r;`|qHT{xRDF4tXgsxO+ljudD+HUZMz%%WUt4(5!o6cT+R=&?E%&G>DR73C@2D~9pu%V zS&UXc;$7n5b!M-Y$myAIr1*MqsPePG&v@y}X|30;39_+(qn0^OxGjk-L8IBBTT8XG zvo@w6BE?E(b6UyQfPTX_*x9nN|SY=84t? z70IA@?hb&ZD&H#hXG9WG^_U&4WuUv$>}N;(qf)tg+m<<1deLl*pSo4XocYSouBaS6 zQEJkW7}Cw_(E?tT(+#b!TS~Q9M;L;V#=)u^Z4oP~?f`pK>&qurkJ45T&(;=p=4EE? G(f Date: Tue, 12 Mar 2019 18:43:40 +0300 Subject: [PATCH 3/4] Added selected button to transport card --- .../main/java/net/osmand/util/MapUtils.java | 18 ++- OsmAnd/res/drawable/btn_active_dark.xml | 9 ++ OsmAnd/res/drawable/btn_active_light.xml | 9 ++ OsmAnd/res/drawable/btn_active_trans_dark.xml | 23 ++++ .../res/drawable/btn_active_trans_light.xml | 23 ++++ OsmAnd/res/drawable/ripple_active_dark.xml | 9 ++ OsmAnd/res/drawable/ripple_active_light.xml | 9 ++ OsmAnd/res/layout/transport_route_card.xml | 3 +- .../ShowRouteInfoDialogFragment.java | 56 ++------- .../ChooseRouteFragment.java | 106 +++++++----------- .../MapRouteInfoMenu.java | 6 + .../MapRouteInfoMenuFragment.java | 86 +++++++------- .../cards/PublicTransportCard.java | 57 ++++++---- .../plus/routing/RouteCalculationResult.java | 23 +++- .../plus/routing/TransportRoutingHelper.java | 31 +++++ 15 files changed, 289 insertions(+), 179 deletions(-) create mode 100644 OsmAnd/res/drawable/btn_active_dark.xml create mode 100644 OsmAnd/res/drawable/btn_active_light.xml create mode 100644 OsmAnd/res/drawable/btn_active_trans_dark.xml create mode 100644 OsmAnd/res/drawable/btn_active_trans_light.xml create mode 100644 OsmAnd/res/drawable/ripple_active_dark.xml create mode 100644 OsmAnd/res/drawable/ripple_active_light.xml 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(); From b2924dab1d4010b550cd019f1851b784e3c63282 Mon Sep 17 00:00:00 2001 From: crimean Date: Tue, 12 Mar 2019 19:36:34 +0300 Subject: [PATCH 4/4] Fixed transport route card labels. Fixed expanded layout of route details menu. --- OsmAnd/res/values/strings.xml | 1 + .../activities/ShowRouteInfoDialogFragment.java | 1 + .../cards/PublicTransportCard.java | 17 ++++++++++------- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 8affa58f36..ed1b3a4875 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + %1$d transfers Unpaved Sand Grass diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java index 61ce037ce1..b3f4513980 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java @@ -1013,6 +1013,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment { iconViewCollapse.setImageDrawable(getCollapseIcon(false)); collapsableView.setCollapsed(false); } + doAfterMenuStateChange(0, 0); } }); if (collapsableView.isCollapsed()) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java index 0e239a9fb0..0f63deac93 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/PublicTransportCard.java @@ -26,6 +26,7 @@ import net.osmand.plus.widgets.FlowLayout; import net.osmand.plus.widgets.style.CustomTypefaceSpan; import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment; +import net.osmand.util.Algorithms; import java.util.Iterator; import java.util.List; @@ -127,10 +128,10 @@ public class PublicTransportCard extends BaseCard { private SpannableString getFirstLineDescrSpan() { List segments = routeResult.getSegments(); String name = segments.get(0).getStart().getName(); - String firstLine = app.getString(R.string.route_from) + " " + name; + String firstLine = Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_from)) + " " + name; if (segments.size() > 1) { - firstLine += ", " + app.getString(R.string.transfers) + ": " + (segments.size() - 1); + firstLine += " • " + app.getString(R.string.transfers_size, (segments.size() - 1)); } SpannableString firstLineDesc = new SpannableString(firstLine); @@ -149,19 +150,21 @@ public class PublicTransportCard extends BaseCard { String walkTime = OsmAndFormatter.getFormattedDuration((int) routeResult.getWalkTime(), app); String walkDistance = OsmAndFormatter.getFormattedDistance((int) routeResult.getWalkDist(), app); - String secondLine = app.getString(R.string.route_way) + ": " + travelTime + " • " + app.getString(R.string.on_foot) + ": " + walkTime + " • " + walkDistance; + String secondLine = travelTime + " • " + app.getString(R.string.on_foot) + " " + walkTime + ", " + walkDistance; SpannableString secondLineDesc = new SpannableString(secondLine); + int startTravelTime = secondLine.indexOf(travelTime); secondLineDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), - secondLine.indexOf(travelTime), secondLine.indexOf(travelTime) + travelTime.length(), 0); + startTravelTime, startTravelTime + travelTime.length(), 0); secondLineDesc.setSpan(new CustomTypefaceSpan(typeface), - secondLine.indexOf(travelTime), secondLine.indexOf(travelTime) + travelTime.length(), 0); + startTravelTime, startTravelTime + travelTime.length(), 0); + int startWalkTime = secondLine.lastIndexOf(walkTime); secondLineDesc.setSpan(new ForegroundColorSpan(ContextCompat.getColor(app, nightMode ? R.color.primary_text_dark : R.color.primary_text_light)), - secondLine.indexOf(walkTime), secondLine.indexOf(walkTime) + walkTime.length(), 0); + startWalkTime, startWalkTime + walkTime.length(), 0); secondLineDesc.setSpan(new CustomTypefaceSpan(typeface), - secondLine.indexOf(walkTime), secondLine.indexOf(walkTime) + walkTime.length(), 0); + startWalkTime, startWalkTime + walkTime.length(), 0); return secondLineDesc; }