Improve zoom to transport route

This commit is contained in:
Chumva 2018-12-20 13:28:09 +02:00
parent 16a6d7eea6
commit ecc39707e4
9 changed files with 347 additions and 167 deletions

View file

@ -1,19 +1,5 @@
package net.osmand.router;
import gnu.trove.iterator.TIntIterator;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.map.hash.TLongObjectHashMap;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.data.LatLon;
@ -24,6 +10,20 @@ import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.util.MapUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import gnu.trove.iterator.TIntIterator;
import gnu.trove.list.array.TIntArrayList;
import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.map.hash.TLongObjectHashMap;
public class TransportRoutePlanner {
@ -274,6 +274,15 @@ public class TransportRoutePlanner {
return route.getForwardStops().get(end);
}
public List<Node> getNodes() {
List<Node> nodes = new ArrayList<>();
List<Way> ways = getGeometry();
for (Way way : ways) {
nodes.addAll(way.getNodes());
}
return nodes;
}
public List<Way> getGeometry() {
List<Way> list = new ArrayList<Way>();
route.mergeForwardWays();

View file

@ -63,12 +63,19 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/route_info_details_padding"
android:baselineAligned="false"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/details_button"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="36dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="@dimen/route_info_details_padding"
android:layout_weight="1"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
@ -88,6 +95,36 @@
</FrameLayout>
<FrameLayout
android:id="@+id/show_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_weight="1"
android:orientation="horizontal"
android:visibility="gone">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/show_button_descr"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_gravity="center"
android:ellipsize="end"
android:gravity="center"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:maxLines="1"
android:text="@string/shared_string_show_on_map"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:ignore="UnusedAttribute"
tools:textColor="?attr/wikivoyage_active_color" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
<ImageView

View file

@ -10,6 +10,7 @@ import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
@ -19,14 +20,18 @@ import android.widget.LinearLayout;
import net.osmand.AndroidUtils;
import net.osmand.Location;
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.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.routeCards.PublicTransportCard;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.router.TransportRoutePlanner;
@ -40,6 +45,8 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
private OsmandMapTileView map;
private MapActivity mapActivity;
private View view;
private LockableViewPager viewPager;
private ImageButton myLocButtonView;
private boolean portrait;
@ -53,25 +60,38 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
map = getMapActivity().getMapView();
View view = inflater.inflate(R.layout.fragment_show_all_routes, null);
view = inflater.inflate(R.layout.fragment_show_all_routes, null);
AndroidUtils.addStatusBarPadding21v(mapActivity, view);
LockableViewPager viewPager = view.findViewById(R.id.pager);
viewPager = view.findViewById(R.id.pager);
List<PublicTransportCard> routeCards = new ArrayList<>();
final List<PublicTransportCard> routeCards = new ArrayList<>();
List<TransportRoutePlanner.TransportRouteResult> routes = getMyApplication().getTransportRoutingHelper().getRoutes();
for (int i = 0; i < routes.size(); i++) {
PublicTransportCard card = new PublicTransportCard(mapActivity, nightMode, routes.get(i), i);
PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i);
card.setSecondButtonVisible(true);
card.setShowTopShadow(false);
card.setShowBottomShadow(false);
routeCards.add(card);
}
viewPager.setClipToPadding(false);
ViewsPagerAdapter pagerAdapter = new ViewsPagerAdapter(mapActivity, routeCards);
final ViewsPagerAdapter pagerAdapter = new ViewsPagerAdapter(mapActivity, routeCards);
viewPager.setAdapter(pagerAdapter);
viewPager.setSwipeLocked(routeCards.size() < 2);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
public void onPageScrollStateChanged(int state) {
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
public void onPageSelected(int position) {
mapActivity.getMyApplication().getTransportRoutingHelper().setCurrentRoute(routeCards.get(position).getRouteId());
mapActivity.refreshMap();
}
});
if (!portrait) {
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(getMyApplication(), 200f));
@ -132,6 +152,55 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
return view;
}
private void adjustMapPosition() {
RoutingHelper rh = mapActivity.getRoutingHelper();
TransportRoutingHelper transportRoutingHelper = rh.getTransportRoutingHelper();
if (getMapActivity().getMapView() != null) {
Location lt = rh.getLastProjection();
if (lt == null) {
lt = getMyApplication().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());
}
TransportRoutePlanner.TransportRouteResult result = transportRoutingHelper.getCurrentRouteResult();
for (TransportRoutePlanner.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 = getMyApplication().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 tileBoxHeightPx = 0;
if (!portrait) {
tileBoxWidthPx = tb.getPixWidth() - view.getWidth();
} else {
int fHeight = viewPager.getHeight() + AndroidUtils.getStatusBarHeight(getMyApplication());
tileBoxHeightPx = tb.getPixHeight() - fHeight;
}
getMapActivity().getMapView().fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0);
}
}
}
@Override
public void onResume() {
super.onResume();
@ -155,7 +224,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
if (!enabled) {
myLocButtonView.setImageResource(R.drawable.map_my_location);
myLocButtonView.setImageDrawable(getContentIcon(R.drawable.map_my_location));
AndroidUtils.setBackground(mapActivity, myLocButtonView, nightMode, R.drawable.btn_circle_trans, R.drawable.btn_circle_night);
myLocButtonView.setContentDescription(mapActivity.getString(R.string.unknown_location));
} else if (tracked) {
@ -262,7 +331,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
}
private View createPageView(int position) {
return cards.get(position).createCardView();
return cards.get(position).build(mapActivity);
}
@NonNull
@ -279,6 +348,12 @@ public class ChooseRouteFragment extends BaseOsmAndFragment {
mapActivity.getMapView().refreshMap(true);
}
});
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

@ -338,7 +338,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
public void build(LinearLayout rootView) {
rootView.removeAllViews();
for (BaseRouteCard card : routeCards) {
rootView.addView(card.createCardView());
rootView.addView(card.build(mapActivity));
}
}
@ -356,14 +356,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
if (isBasicRouteCalculated()) {
GPXUtilities.GPXFile gpx = GPXUtilities.makeGpxFromRoute(routingHelper.getRoute());
if (gpx != null) {
routeCards.add(new SimpleRouteCard(mapActivity, nightMode, gpx));
routeCards.add(new SimpleRouteCard(mapActivity, gpx));
LinearLayout cardsContainer = (LinearLayout) mainView.findViewById(R.id.route_menu_cards_container);
build(cardsContainer);
}
} else if (isTransportRouteCalculated()) {
List<TransportRoutePlanner.TransportRouteResult> routes = transportHelper.getRoutes();
for (int i = 0; i < routes.size(); i++) {
PublicTransportCard card = new PublicTransportCard(mapActivity, nightMode, routes.get(i), i);
PublicTransportCard card = new PublicTransportCard(mapActivity, routes.get(i), i);
card.setShowBottomShadow(i == routes.size() - 1);
card.setShowTopShadow(i != 0);
routeCards.add(card);
@ -379,11 +379,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
return isBasicRouteCalculated() || isTransportRouteCalculated();
}
private boolean isTransportRouteCalculated() {
public boolean isTransportRouteCalculated() {
return routingHelper.isPublicTransportMode() && transportHelper.getRoutes() != null;
}
private boolean isBasicRouteCalculated() {
public boolean isBasicRouteCalculated() {
return routingHelper.getFinalLocation() != null && routingHelper.isRouteCalculated();
}
@ -855,8 +855,12 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
if (getTargets().getPointToNavigate() != null) {
hide();
}
if (isTransportRouteCalculated()) {
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager());
} else {
mapControlsLayer.startNavigation();
}
}
private void clickRouteCancel() {
mapControlsLayer.stopNavigation();

View file

@ -31,6 +31,7 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.Location;
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;
@ -43,6 +44,7 @@ import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.widgets.ImageViewExProgress;
import net.osmand.plus.widgets.TextViewExProgress;
import net.osmand.router.TransportRoutePlanner;
import java.util.List;
@ -645,6 +647,17 @@ public class MapRouteInfoMenuFragment extends BaseOsmAndFragment {
top = Math.max(top, l.getLatitude());
bottom = Math.min(bottom, l.getLatitude());
}
if (menu.isTransportRouteCalculated()) {
TransportRoutePlanner.TransportRouteResult result = getMyApplication().getTransportRoutingHelper().getCurrentRouteResult();
for (TransportRoutePlanner.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 = getMyApplication().getTargetPointsHelper().getIntermediatePointsWithTarget();
for (TargetPointsHelper.TargetPoint l : targetPoints) {
left = Math.min(left, l.getLongitude());

View file

@ -1,29 +1,51 @@
package net.osmand.plus.routepreparationmenu.routeCards;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
public abstract class BaseRouteCard {
protected OsmandApplication app;
protected MapActivity mapActivity;
protected View view;
boolean showTopShadow;
boolean showBottomShadow;
protected boolean nightMode;
public BaseRouteCard(OsmandApplication app, boolean nightMode) {
this.app = app;
this.nightMode = nightMode;
public BaseRouteCard(MapActivity mapActivity) {
this.mapActivity = mapActivity;
this.app = mapActivity.getMyApplication();
}
public abstract View createCardView();
public abstract int getCardLayoutId();
public abstract void update();
public View build(Context ctx) {
view = LayoutInflater.from(ctx).inflate(getCardLayoutId(), null);
update();
return view;
}
public MapActivity getMapActivity() {
return mapActivity;
}
public OsmandApplication getMyApplication() {
return app;
}
protected abstract void applyDayNightMode();

View file

@ -22,7 +22,6 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.routepreparationmenu.FlowLayout;
import net.osmand.plus.routepreparationmenu.ChooseRouteFragment;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.transport.TransportStopType;
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
@ -36,53 +35,25 @@ public class PublicTransportCard extends BaseRouteCard {
private static final int MIN_WALK_TIME = 120;
private MapActivity mapActivity;
private TransportRouteResult routeResult;
private View view;
private int routeId;
private boolean secondButtonVisible;
public PublicTransportCard(MapActivity mapActivity, boolean nightMode, TransportRouteResult routeResult, int routeId) {
super(mapActivity.getMyApplication(), nightMode);
this.mapActivity = mapActivity;
public PublicTransportCard(MapActivity mapActivity, TransportRouteResult routeResult, int routeId) {
super(mapActivity);
this.routeResult = routeResult;
this.routeId = routeId;
}
@Override
public View createCardView() {
view = mapActivity.getLayoutInflater().inflate(R.layout.transport_route_card, null);
view.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light));
List<TransportRouteResultSegment> segments = routeResult.getSegments();
createRouteBadges(segments);
TextView fromLine = (TextView) view.findViewById(R.id.from_line);
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
fromLine.setText(getFirstLineDescrSpan());
wayLine.setText(getSecondLineDescrSpan());
view.findViewById(R.id.details_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide();
ChooseRouteFragment.showInstance(mapActivity.getSupportFragmentManager());
}
});
view.findViewById(R.id.bottom_shadow).setVisibility(showBottomShadow ? View.VISIBLE : View.GONE);
view.findViewById(R.id.card_divider).setVisibility(showTopShadow ? View.VISIBLE : View.GONE);
applyDayNightMode();
return view;
}
public int getRouteId() {
return routeId;
}
public void setSecondButtonVisible(boolean secondButtonVisible) {
this.secondButtonVisible = secondButtonVisible;
}
protected void applyDayNightMode() {
TextView fromLine = (TextView) view.findViewById(R.id.from_line);
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
@ -98,12 +69,27 @@ public class PublicTransportCard extends BaseRouteCard {
} else {
AndroidUtils.setBackground(app, detailsButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
}
int color = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
detailsButtonDescr.setTextColor(color);
FrameLayout showButton = (FrameLayout) view.findViewById(R.id.show_button);
if (secondButtonVisible) {
TextView showButtonDescr = (TextView) view.findViewById(R.id.show_button_descr);
AndroidUtils.setBackground(app, showButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, showButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
} else {
AndroidUtils.setBackground(app, showButtonDescr, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
}
showButtonDescr.setTextColor(color);
showButton.setVisibility(View.VISIBLE);
} else {
showButton.setVisibility(View.GONE);
}
AndroidUtils.setBackground(app, view, nightMode, R.color.activity_background_light, R.color.activity_background_dark);
AndroidUtils.setBackground(app, view.findViewById(R.id.top_divider), nightMode, R.color.divider_light, R.color.divider_dark);
AndroidUtils.setBackground(app, view.findViewById(R.id.routes_info_container), nightMode, R.color.route_info_bg_light, R.color.route_info_bg_dark);
int color = ContextCompat.getColor(mapActivity, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
detailsButtonDescr.setTextColor(color);
}
private SpannableString getFirstLineDescrSpan() {
@ -181,7 +167,7 @@ public class PublicTransportCard extends BaseRouteCard {
}
private View createRouteBadge(TransportRouteResultSegment segment) {
LinearLayout convertView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
LinearLayout convertView = (LinearLayout) getMapActivity().getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
if (segment != null) {
TransportRoute transportRoute = segment.route;
TransportStopRoute transportStopRoute = getTransportStopRoute(transportRoute, segment.getStart());
@ -203,7 +189,7 @@ public class PublicTransportCard extends BaseRouteCard {
}
private View createWalkRouteBadge(String walkTime) {
LinearLayout convertView = (LinearLayout) mapActivity.getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
LinearLayout convertView = (LinearLayout) getMapActivity().getLayoutInflater().inflate(R.layout.transport_stop_route_item_with_icon, null, false);
if (walkTime != null) {
int bgColor = ContextCompat.getColor(app, nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light);
@ -244,4 +230,37 @@ public class PublicTransportCard extends BaseRouteCard {
private double getWalkTime(double walkDist, double walkSpeed) {
return walkDist / walkSpeed;
}
@Override
public int getCardLayoutId() {
return R.layout.transport_route_card;
}
@Override
public void update() {
if (view != null) {
view.setBackgroundColor(ContextCompat.getColor(app, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light));
List<TransportRouteResultSegment> segments = routeResult.getSegments();
createRouteBadges(segments);
TextView fromLine = (TextView) view.findViewById(R.id.from_line);
TextView wayLine = (TextView) view.findViewById(R.id.way_line);
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();
}
});
view.findViewById(R.id.bottom_shadow).setVisibility(showBottomShadow ? View.VISIBLE : View.GONE);
view.findViewById(R.id.card_divider).setVisibility(showTopShadow ? View.VISIBLE : View.GONE);
applyDayNightMode();
}
}
}

View file

@ -14,7 +14,6 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import net.osmand.AndroidUtils;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.ShowRouteInfoDialogFragment;
@ -31,87 +30,15 @@ public class SimpleRouteCard extends BaseRouteCard {
private MapActivity mapActivity;
private GPXUtilities.GPXFile gpx;
private RoutingHelper routingHelper;
private View view;
public SimpleRouteCard(MapActivity mapActivity, boolean nightMode, GPXUtilities.GPXFile gpx) {
super(mapActivity.getMyApplication(), nightMode);
public SimpleRouteCard(MapActivity mapActivity, GPXUtilities.GPXFile gpx) {
super(mapActivity);
this.mapActivity = mapActivity;
this.gpx = gpx;
routingHelper = mapActivity.getRoutingHelper();
}
@Override
public View createCardView() {
view = mapActivity.getLayoutInflater().inflate(R.layout.route_info_statistic, null);
view.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light));
view.findViewById(R.id.dividerToDropDown).setVisibility(View.VISIBLE);
view.findViewById(R.id.route_info_details_card).setVisibility(View.VISIBLE);
final OsmandApplication ctx = mapActivity.getMyApplication();
View info = view.findViewById(R.id.info_container);
info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowRouteInfoDialogFragment.showDialog(mapActivity.getSupportFragmentManager());
}
});
ImageView infoIcon = (ImageView) view.findViewById(R.id.InfoIcon);
ImageView durationIcon = (ImageView) view.findViewById(R.id.DurationIcon);
View infoDistanceView = view.findViewById(R.id.InfoDistance);
View infoDurationView = view.findViewById(R.id.InfoDuration);
if (directionInfo >= 0) {
infoIcon.setVisibility(View.GONE);
durationIcon.setVisibility(View.GONE);
infoDistanceView.setVisibility(View.GONE);
infoDurationView.setVisibility(View.GONE);
} else {
infoIcon.setImageDrawable(ctx.getUIUtilities().getIcon(R.drawable.ic_action_route_distance, R.color.route_info_unchecked_mode_icon_color));
infoIcon.setVisibility(View.VISIBLE);
durationIcon.setImageDrawable(ctx.getUIUtilities().getIcon(R.drawable.ic_action_time_span, R.color.route_info_unchecked_mode_icon_color));
durationIcon.setVisibility(View.VISIBLE);
infoDistanceView.setVisibility(View.VISIBLE);
infoDurationView.setVisibility(View.VISIBLE);
}
if (directionInfo >= 0 && routingHelper.getRouteDirections() != null
&& directionInfo < routingHelper.getRouteDirections().size()) {
RouteDirectionInfo ri = routingHelper.getRouteDirections().get(directionInfo);
} else {
TextView distanceText = (TextView) view.findViewById(R.id.DistanceText);
TextView distanceTitle = (TextView) view.findViewById(R.id.DistanceTitle);
TextView durationText = (TextView) view.findViewById(R.id.DurationText);
TextView durationTitle = (TextView) view.findViewById(R.id.DurationTitle);
distanceText.setText(OsmAndFormatter.getFormattedDistance(ctx.getRoutingHelper().getLeftDistance(), ctx));
durationText.setText(OsmAndFormatter.getFormattedDuration(ctx.getRoutingHelper().getLeftTime(), ctx));
durationTitle.setText(ctx.getString(R.string.arrive_at_time, OsmAndFormatter.getFormattedTime(ctx.getRoutingHelper().getLeftTime(), true)));
AndroidUtils.setTextPrimaryColor(ctx, distanceText, nightMode);
AndroidUtils.setTextSecondaryColor(ctx, distanceTitle, nightMode);
AndroidUtils.setTextPrimaryColor(ctx, durationText, nightMode);
AndroidUtils.setTextSecondaryColor(ctx, durationTitle, nightMode);
}
applyDayNightMode();
view.findViewById(R.id.details_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowRouteInfoDialogFragment.showDialog(mapActivity.getSupportFragmentManager());
}
});
buildHeader(view);
return view;
}
protected void applyDayNightMode() {
FrameLayout detailsButton = view.findViewById(R.id.details_button);
AndroidUtils.setBackground(app, detailsButton, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, view.findViewById(R.id.details_button_descr), nightMode, R.drawable.ripple_light, R.drawable.ripple_dark);
@ -128,7 +55,6 @@ public class SimpleRouteCard extends BaseRouteCard {
}
private void buildHeader(View headerView) {
OsmandApplication app = mapActivity.getMyApplication();
final LineChart mChart = (LineChart) headerView.findViewById(R.id.chart);
final GPXUtilities.GPXTrackAnalysis analysis = gpx.getAnalysis(0);
@ -153,4 +79,75 @@ public class SimpleRouteCard extends BaseRouteCard {
mChart.setVisibility(View.GONE);
}
}
@Override
public int getCardLayoutId() {
return R.layout.route_info_statistic;
}
@Override
public void update() {
if (view != null) {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
view.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.route_info_bg_dark : R.color.route_info_bg_light));
view.findViewById(R.id.dividerToDropDown).setVisibility(View.VISIBLE);
view.findViewById(R.id.route_info_details_card).setVisibility(View.VISIBLE);
View info = view.findViewById(R.id.info_container);
info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowRouteInfoDialogFragment.showDialog(mapActivity.getSupportFragmentManager());
}
});
ImageView infoIcon = (ImageView) view.findViewById(R.id.InfoIcon);
ImageView durationIcon = (ImageView) view.findViewById(R.id.DurationIcon);
View infoDistanceView = view.findViewById(R.id.InfoDistance);
View infoDurationView = view.findViewById(R.id.InfoDuration);
if (directionInfo >= 0) {
infoIcon.setVisibility(View.GONE);
durationIcon.setVisibility(View.GONE);
infoDistanceView.setVisibility(View.GONE);
infoDurationView.setVisibility(View.GONE);
} else {
infoIcon.setImageDrawable(getColoredIcon(R.drawable.ic_action_route_distance, R.color.route_info_unchecked_mode_icon_color));
infoIcon.setVisibility(View.VISIBLE);
durationIcon.setImageDrawable(getColoredIcon(R.drawable.ic_action_time_span, R.color.route_info_unchecked_mode_icon_color));
durationIcon.setVisibility(View.VISIBLE);
infoDistanceView.setVisibility(View.VISIBLE);
infoDurationView.setVisibility(View.VISIBLE);
}
if (directionInfo >= 0 && routingHelper.getRouteDirections() != null
&& directionInfo < routingHelper.getRouteDirections().size()) {
RouteDirectionInfo ri = routingHelper.getRouteDirections().get(directionInfo);
} else {
TextView distanceText = (TextView) view.findViewById(R.id.DistanceText);
TextView distanceTitle = (TextView) view.findViewById(R.id.DistanceTitle);
TextView durationText = (TextView) view.findViewById(R.id.DurationText);
TextView durationTitle = (TextView) view.findViewById(R.id.DurationTitle);
distanceText.setText(OsmAndFormatter.getFormattedDistance(app.getRoutingHelper().getLeftDistance(), app));
durationText.setText(OsmAndFormatter.getFormattedDuration(app.getRoutingHelper().getLeftTime(), app));
durationTitle.setText(app.getString(R.string.arrive_at_time, OsmAndFormatter.getFormattedTime(app.getRoutingHelper().getLeftTime(), true)));
AndroidUtils.setTextPrimaryColor(app, distanceText, nightMode);
AndroidUtils.setTextSecondaryColor(app, distanceTitle, nightMode);
AndroidUtils.setTextPrimaryColor(app, durationText, nightMode);
AndroidUtils.setTextSecondaryColor(app, durationTitle, nightMode);
}
view.findViewById(R.id.details_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowRouteInfoDialogFragment.showDialog(mapActivity.getSupportFragmentManager());
}
});
buildHeader(view);
applyDayNightMode();
}
}
}

View file

@ -89,6 +89,10 @@ public class TransportRoutingHelper {
return currentRoute;
}
public TransportRouteResult getCurrentRouteResult() {
return routes.get(currentRoute);
}
public List<TransportRouteResult> getRoutes() {
return routes;
}