Merge branch 'master' of ssh://github.com/osmandapp/Osmand into RoutePreparationUiImprovements

This commit is contained in:
Chumva 2019-03-12 18:57:12 +02:00
commit 25641f5266
17 changed files with 300 additions and 185 deletions

View file

@ -553,10 +553,6 @@ public class MapUtils {
return sa < 0; return sa < 0;
} }
public static long deinterleaveY(long coord) { public static long deinterleaveY(long coord) {
long x = 0; long x = 0;
for (byte b = 31; b >= 0; b--) { for (byte b = 31; b >= 0; b--) {
@ -607,6 +603,20 @@ public class MapUtils {
return y1; 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);
}
}
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_dark" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_light" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_trans_dark" />
<stroke android:width="1dp" android:color="@color/active_buttons_and_links_dark" />
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/activity_background_light" />
<corners android:radius="4dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@null" />
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_dark" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_trans_light" />
<stroke android:width="1dp" android:color="@color/active_buttons_and_links_light" />
</shape>
</item>
<item android:state_enabled="false">
<shape android:shape="rectangle">
<solid android:color="@color/activity_background_light" />
<corners android:radius="4dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@null" />
<corners android:radius="4dp" />
<solid android:color="@color/active_buttons_and_links_light" />
</shape>
</item>
</selector>

View file

@ -0,0 +1,9 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/per42black">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/active_buttons_and_links_dark" />
<corners android:radius="4dp" />
</shape>
</item>
</ripple>

View file

@ -0,0 +1,9 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/per42black">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/active_buttons_and_links_light" />
<corners android:radius="4dp" />
</shape>
</item>
</ripple>

View file

@ -107,8 +107,7 @@
android:layout_marginLeft="@dimen/content_padding" android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding" android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1" android:layout_weight="1"
android:orientation="horizontal" android:orientation="horizontal">
android:visibility="gone">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/show_button_descr" android:id="@+id/show_button_descr"

View file

@ -11,6 +11,7 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="transfers_size">%1$d transfers</string>
<string name="add_start_and_end_points">Add start and end points</string> <string name="add_start_and_end_points">Add start and end points</string>
<string name="route_add_start_point">Add start point</string> <string name="route_add_start_point">Add start point</string>
<string name="route_descr_select_start_point">Select start point</string> <string name="route_descr_select_start_point">Select start point</string>

View file

@ -67,7 +67,6 @@ import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportRoute; import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node;
import net.osmand.plus.GeocodingLookupService; import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
@ -869,7 +868,17 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
public void showWalkingRouteOnMap(TransportRouteResultSegment startSegment, TransportRouteResultSegment endSegment) { public void showWalkingRouteOnMap(TransportRouteResultSegment startSegment, TransportRouteResultSegment endSegment) {
RouteCalculationResult walkingRouteSegment = app.getTransportRoutingHelper().getWalkingRouteSegment(startSegment, endSegment); RouteCalculationResult walkingRouteSegment = app.getTransportRoutingHelper().getWalkingRouteSegment(startSegment, endSegment);
if (walkingRouteSegment != null) { if (walkingRouteSegment != null) {
QuadRect rect = getWalkingSegmentRect(walkingRouteSegment); QuadRect rect = walkingRouteSegment.getLocationsRect();
if (rect != null) {
openMenuHeaderOnly();
fitRectOnMap(rect, null, true);
}
}
}
public void showRouteOnMap(TransportRouteResult result) {
if (result != null) {
QuadRect rect = app.getTransportRoutingHelper().getTransportRouteRect(result);
if (rect != null) { if (rect != null) {
openMenuHeaderOnly(); openMenuHeaderOnly();
fitRectOnMap(rect, null, true); fitRectOnMap(rect, null, true);
@ -1005,6 +1014,7 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
iconViewCollapse.setImageDrawable(getCollapseIcon(false)); iconViewCollapse.setImageDrawable(getCollapseIcon(false));
collapsableView.setCollapsed(false); collapsableView.setCollapsed(false);
} }
doAfterMenuStateChange(0, 0);
} }
}); });
if (collapsableView.isCollapsed()) { if (collapsableView.isCollapsed()) {
@ -1237,52 +1247,11 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
((LinearLayout) view).addView(baseItemView); ((LinearLayout) view).addView(baseItemView);
} }
@Nullable
private QuadRect getTransportSegmentRect(@NonNull TransportRouteResultSegment segment) {
double left = 0, right = 0;
double top = 0, bottom = 0;
List<Node> 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) { private void showOnMap(@NonNull LatLon latLon) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
int currentZoom = mapActivity.getMapView().getZoom(); 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);
} }
} }

View file

@ -19,28 +19,27 @@ import android.widget.LinearLayout;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.osm.edit.Node;
import net.osmand.plus.LockableViewPager; import net.osmand.plus.LockableViewPager;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.ShowRouteInfoDialogFragment;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper; 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.routepreparationmenu.cards.PublicTransportCard;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.TransportRoutingHelper; import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ChooseRouteFragment extends BaseOsmAndFragment { public class ChooseRouteFragment extends BaseOsmAndFragment implements CardListener {
public static final String TAG = "ChooseRouteFragment"; public static final String TAG = "ChooseRouteFragment";
@ -50,6 +49,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
private View view; private View view;
private LockableViewPager viewPager; private LockableViewPager viewPager;
private ImageButton myLocButtonView; private ImageButton myLocButtonView;
private List<PublicTransportCard> routeCards = new ArrayList<>();
private boolean portrait; private boolean portrait;
private boolean nightMode; private boolean nightMode;
@ -58,21 +58,21 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mapActivity = (MapActivity) getActivity(); mapActivity = (MapActivity) requireActivity();
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
map = getMapActivity().getMapView(); map = getMapActivity().getMapView();
List<TransportRouteResult> routes = getMyApplication().getTransportRoutingHelper().getRoutes(); OsmandApplication app = mapActivity.getMyApplication();
List<TransportRouteResult> routes = app.getTransportRoutingHelper().getRoutes();
if (routes != null && !routes.isEmpty()) { if (routes != null && !routes.isEmpty()) {
view = inflater.inflate(R.layout.fragment_show_all_routes, null); view = inflater.inflate(R.layout.fragment_show_all_routes, null);
viewPager = view.findViewById(R.id.pager); viewPager = view.findViewById(R.id.pager);
AndroidUtils.addStatusBarPadding21v(mapActivity, view); AndroidUtils.addStatusBarPadding21v(mapActivity, view);
final List<PublicTransportCard> routeCards = new ArrayList<>();
for (int i = 0; i < routes.size(); i++) { for (int i = 0; i < routes.size(); i++) {
PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i); PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i);
card.setSecondButtonVisible(true); card.setListener(this);
card.setShowTopShadow(false); card.setShowTopShadow(false);
card.setShowBottomShadow(false); card.setShowBottomShadow(false);
routeCards.add(card); routeCards.add(card);
@ -91,11 +91,14 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
public void onPageSelected(int position) { public void onPageSelected(int position) {
mapActivity.getMyApplication().getTransportRoutingHelper().setCurrentRoute(routeCards.get(position).getRouteId()); mapActivity.getMyApplication().getTransportRoutingHelper().setCurrentRoute(routeCards.get(position).getRouteId());
mapActivity.refreshMap(); mapActivity.refreshMap();
for (PublicTransportCard card : routeCards) {
card.update();
}
} }
}); });
if (!portrait) { 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; params.gravity = Gravity.BOTTOM;
viewPager.setLayoutParams(params); viewPager.setLayoutParams(params);
} }
@ -154,43 +157,20 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
} }
private void adjustMapPosition() { private void adjustMapPosition() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandMapTileView mapView = mapActivity.getMapView();
if (mapView != null) {
RoutingHelper rh = mapActivity.getRoutingHelper(); RoutingHelper rh = mapActivity.getRoutingHelper();
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
TransportRoutingHelper transportRoutingHelper = rh.getTransportRoutingHelper(); TransportRoutingHelper transportRoutingHelper = rh.getTransportRoutingHelper();
if (getMapActivity().getMapView() != null) {
Location lt = rh.getLastProjection(); QuadRect rect = null;
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<Location> 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());
}
TransportRouteResult result = transportRoutingHelper.getCurrentRouteResult(); TransportRouteResult result = transportRoutingHelper.getCurrentRouteResult();
if (result != null) { if (result != null) {
for (TransportRouteResultSegment segment : result.getSegments()) { rect = transportRoutingHelper.getTransportRouteRect(result);
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());
} }
} RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
}
List<TargetPointsHelper.TargetPoint> 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();
int tileBoxWidthPx = 0; int tileBoxWidthPx = 0;
int tileBoxHeightPx = 0; int tileBoxHeightPx = 0;
@ -200,7 +180,9 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
int fHeight = viewPager.getHeight() + AndroidUtils.getStatusBarHeight(app); int fHeight = viewPager.getHeight() + AndroidUtils.getStatusBarHeight(app);
tileBoxHeightPx = tb.getPixHeight() - fHeight; 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 class ViewsPagerAdapter extends PagerAdapter {
private List<PublicTransportCard> cards; private List<PublicTransportCard> cards;
@ -338,29 +335,10 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
@NonNull @NonNull
@Override @Override
public Object instantiateItem(@NonNull ViewGroup container, final int position) { public Object instantiateItem(@NonNull ViewGroup container, final int position) {
View view = createPageView(position); View view = createPageView(position);
view.setBackgroundDrawable(null); view.setBackgroundDrawable(null);
view.setBackgroundResource(R.drawable.route_cards_topsides_light); 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); container.addView(view, 0);
return view; return view;
} }

View file

@ -488,6 +488,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i); PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i);
card.setShowBottomShadow(i == routes.size() - 1); card.setShowBottomShadow(i == routes.size() - 1);
card.setShowTopShadow(i != 0); card.setShowTopShadow(i != 0);
card.setListener(this);
menuCards.add(card); menuCards.add(card);
} }
bottomShadowVisible = routes.size() == 0; bottomShadowVisible = routes.size() == 0;
@ -581,6 +582,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
updateOptionsButtons(); updateOptionsButtons();
app.getTargetPointsHelper().restoreTargetPoints(true); app.getTargetPointsHelper().restoreTargetPoints(true);
} else if (card instanceof PublicTransportCard) {
if (buttonIndex == PublicTransportCard.SHOW_BUTTON_INDEX) {
setupCards();
openMenuHeaderOnly();
}
} }
} }
} }

View file

@ -30,6 +30,7 @@ import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
@ -37,16 +38,18 @@ import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout; import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.widgets.ImageViewExProgress; import net.osmand.plus.widgets.ImageViewExProgress;
import net.osmand.plus.widgets.TextViewExProgress; import net.osmand.plus.widgets.TextViewExProgress;
import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment; import net.osmand.util.MapUtils;
import java.util.List; import java.util.List;
@ -335,7 +338,6 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
} }
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
updateInfo();
mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden(); mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
wasDrawerDisabled = mapActivity.isDrawerDisabled(); wasDrawerDisabled = mapActivity.isDrawerDisabled();
if (!wasDrawerDisabled) { if (!wasDrawerDisabled) {
@ -726,41 +728,36 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
RoutingHelper rh = app.getRoutingHelper(); RoutingHelper rh = app.getRoutingHelper();
if (rh.isRoutePlanningMode() && mapActivity.getMapView() != null) { if (rh.isRoutePlanningMode() && mapActivity.getMapView() != null) {
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;
}
}
} else if (rh.isRouteCalculated()) {
Location lt = rh.getLastProjection(); Location lt = rh.getLastProjection();
if (lt == null) { if (lt == null) {
lt = app.getTargetPointsHelper().getPointToStartLocation(); lt = app.getTargetPointsHelper().getPointToStartLocation();
} }
if (lt == null) {
lt = app.getLocationProvider().getLastKnownLocation();
}
if (lt != null) { if (lt != null) {
double left = lt.getLongitude(), right = lt.getLongitude(); MapUtils.insetLatLonRect(r, lt.getLatitude(), lt.getLongitude());
double top = lt.getLatitude(), bottom = lt.getLatitude(); }
List<Location> list = rh.getCurrentCalculatedRoute(); List<Location> list = rh.getCurrentCalculatedRoute();
for (Location l : list) { for (Location l : list) {
left = Math.min(left, l.getLongitude()); MapUtils.insetLatLonRect(r, l.getLatitude(), l.getLongitude());
right = Math.max(right, l.getLongitude());
top = Math.max(top, l.getLatitude());
bottom = Math.min(bottom, l.getLatitude());
} }
if (menu.isTransportRouteCalculated()) { List<TargetPoint> targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
TransportRouteResult result = app.getTransportRoutingHelper().getCurrentRouteResult(); for (TargetPoint l : targetPoints) {
if (result != null) { MapUtils.insetLatLonRect(r, l.getLatitude(), l.getLongitude());
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());
} }
} }
}
}
List<TargetPointsHelper.TargetPoint> 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 = mapActivity.getMapView().getCurrentRotatedTileBox().copy(); RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
int tileBoxWidthPx = 0; int tileBoxWidthPx = 0;
int tileBoxHeightPx = 0; int tileBoxHeightPx = 0;
@ -771,7 +768,8 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
int fHeight = viewHeight - y - AndroidUtils.getStatusBarHeight(app); int fHeight = viewHeight - y - AndroidUtils.getStatusBarHeight(app);
tileBoxHeightPx = tb.getPixHeight() - fHeight; tileBoxHeightPx = tb.getPixHeight() - fHeight;
} }
mapActivity.getMapView().fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0); if (r.left != 0 && r.right != 0) {
mapActivity.getMapView().fitRectToMap(r.left, r.right, r.top, r.bottom, tileBoxWidthPx, tileBoxHeightPx, 0);
} }
} }
} }

View file

@ -26,6 +26,7 @@ import net.osmand.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.style.CustomTypefaceSpan; import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import net.osmand.router.TransportRoutePlanner.TransportRouteResult; import net.osmand.router.TransportRoutePlanner.TransportRouteResult;
import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment; import net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment;
import net.osmand.util.Algorithms;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -33,11 +34,12 @@ import java.util.List;
public class PublicTransportCard extends BaseCard { public class PublicTransportCard extends BaseCard {
private static final int MIN_WALK_TIME = 120; 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 TransportRouteResult routeResult;
private int routeId; private int routeId;
private boolean secondButtonVisible;
public PublicTransportCard(MapActivity mapActivity, TransportRouteResult routeResult, int routeId) { public PublicTransportCard(MapActivity mapActivity, TransportRouteResult routeResult, int routeId) {
super(mapActivity); super(mapActivity);
@ -61,14 +63,6 @@ public class PublicTransportCard extends BaseCard {
fromLine.setText(getFirstLineDescrSpan()); fromLine.setText(getFirstLineDescrSpan());
wayLine.setText(getSecondLineDescrSpan()); 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); FrameLayout detailsButton = (FrameLayout) view.findViewById(R.id.details_button);
TextView detailsButtonDescr = (TextView) view.findViewById(R.id.details_button_descr); TextView detailsButtonDescr = (TextView) view.findViewById(R.id.details_button_descr);
@ -80,21 +74,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); int color = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
detailsButtonDescr.setTextColor(color); 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); 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) { 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, 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); AndroidUtils.setBackground(app, showButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else { } else {
AndroidUtils.setBackground(app, showButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); AndroidUtils.setBackground(app, showButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark);
} }
showButtonDescr.setTextColor(color); showButtonDescr.setText(R.string.shared_string_show_on_map);
showButton.setVisibility(View.VISIBLE); showButton.setOnClickListener(new View.OnClickListener() {
} else { @Override
showButton.setVisibility(View.GONE); 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.bottom_shadow).setVisibility(showBottomShadow ? View.VISIBLE : View.GONE);
view.findViewById(R.id.card_divider).setVisibility(showTopShadow ? 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); view.findViewById(R.id.top_divider).setVisibility(!showTopShadow ? View.VISIBLE : View.GONE);
@ -104,17 +121,17 @@ public class PublicTransportCard extends BaseCard {
return routeId; return routeId;
} }
public void setSecondButtonVisible(boolean secondButtonVisible) { public boolean isCurrentRoute() {
this.secondButtonVisible = secondButtonVisible; return routeId == app.getTransportRoutingHelper().getCurrentRoute();
} }
private SpannableString getFirstLineDescrSpan() { private SpannableString getFirstLineDescrSpan() {
List<TransportRouteResultSegment> segments = routeResult.getSegments(); List<TransportRouteResultSegment> segments = routeResult.getSegments();
String name = segments.get(0).getStart().getName(); 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) { 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); SpannableString firstLineDesc = new SpannableString(firstLine);
@ -133,19 +150,21 @@ public class PublicTransportCard extends BaseCard {
String walkTime = OsmAndFormatter.getFormattedDuration((int) routeResult.getWalkTime(), app); String walkTime = OsmAndFormatter.getFormattedDuration((int) routeResult.getWalkTime(), app);
String walkDistance = OsmAndFormatter.getFormattedDistance((int) routeResult.getWalkDist(), 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); 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)), 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), 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)), 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), secondLineDesc.setSpan(new CustomTypefaceSpan(typeface),
secondLine.indexOf(walkTime), secondLine.indexOf(walkTime) + walkTime.length(), 0); startWalkTime, startWalkTime + walkTime.length(), 0);
return secondLineDesc; return secondLineDesc;
} }
@ -153,6 +172,7 @@ public class PublicTransportCard extends BaseCard {
private void createRouteBadges(List<TransportRouteResultSegment> segments) { private void createRouteBadges(List<TransportRouteResultSegment> segments) {
int itemsSpacing = AndroidUtils.dpToPx(app, 6); int itemsSpacing = AndroidUtils.dpToPx(app, 6);
FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges); FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges);
routesBadges.removeAllViews();
Iterator<TransportRouteResultSegment> iterator = segments.iterator(); Iterator<TransportRouteResultSegment> iterator = segments.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {

View file

@ -1,6 +1,7 @@
package net.osmand.plus.routing; package net.osmand.plus.routing;
import android.content.Context; import android.content.Context;
import android.support.annotation.Nullable;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
@ -8,6 +9,7 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.data.QuadRect;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -513,6 +515,25 @@ public class RouteCalculationResult {
} }
} }
@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) { public static String toString(TurnType type, Context ctx, boolean shortName) {
if(type.isRoundAbout()){ if(type.isRoundAbout()){

View file

@ -9,6 +9,8 @@ import net.osmand.PlatformUtil;
import net.osmand.ValueHolder; import net.osmand.ValueHolder;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.LatLon; 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.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; 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 { public interface TransportRouteCalculationProgressCallback {
void start(); void start();