Added selected button to transport card

This commit is contained in:
crimean 2019-03-12 18:43:40 +03:00
parent 29b66f3f1d
commit a109fe6167
15 changed files with 289 additions and 179 deletions

View file

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

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_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="gone">
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/show_button_descr"

View file

@ -67,7 +67,6 @@ import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportRoute;
import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node;
import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
@ -868,7 +867,17 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
public void showWalkingRouteOnMap(TransportRouteResultSegment startSegment, TransportRouteResultSegment endSegment) {
RouteCalculationResult walkingRouteSegment = app.getTransportRoutingHelper().getWalkingRouteSegment(startSegment, endSegment);
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) {
openMenuHeaderOnly();
fitRectOnMap(rect, null, true);
@ -1236,52 +1245,11 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment {
((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) {
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);
}
}

View file

@ -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<PublicTransportCard> 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<TransportRouteResult> routes = getMyApplication().getTransportRoutingHelper().getRoutes();
OsmandApplication app = mapActivity.getMyApplication();
List<TransportRouteResult> 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<PublicTransportCard> 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<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());
}
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<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();
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<PublicTransportCard> 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;
}

View file

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

View file

@ -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<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());
}
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<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());
} 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<Location> list = rh.getCurrentCalculatedRoute();
for (Location l : list) {
MapUtils.insetLatLonRect(r, l.getLatitude(), l.getLongitude());
}
List<TargetPoint> 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);
}
}
}

View file

@ -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<TransportRouteResultSegment> segments) {
int itemsSpacing = AndroidUtils.dpToPx(app, 6);
FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges);
routesBadges.removeAllViews();
Iterator<TransportRouteResultSegment> 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);
}

View file

@ -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()){

View file

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