Search in sources :

Example 1 with TransportRoutingHelper

use of net.osmand.plus.routing.TransportRoutingHelper in project Osmand by osmandapp.

the class ChooseRouteFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    MapActivity mapActivity = (MapActivity) requireActivity();
    nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
    portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
    OsmandApplication app = mapActivity.getMyApplication();
    TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
    List<TransportRouteResult> routes = transportRoutingHelper.getRoutes();
    int routeIndex = 0;
    int initialMenuState = MenuState.HEADER_ONLY;
    Bundle args = getArguments();
    if (args == null) {
        args = savedInstanceState;
    }
    if (args != null) {
        routeIndex = args.getInt(ROUTE_INDEX_KEY);
        needAdjustMap = args.getBoolean(ADJUST_MAP_KEY, false);
        initialMenuState = args.getInt(INITIAL_MENU_STATE_KEY, initialMenuState);
    }
    routesCount = 1;
    if (routes != null && !routes.isEmpty()) {
        publicTransportMode = true;
        routesCount = routes.size();
    }
    ContextThemeWrapper context = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    View view = LayoutInflater.from(context).inflate(R.layout.fragment_show_all_routes, null);
    AndroidUtils.addStatusBarPadding21v(mapActivity, view);
    View solidToolbarView = view.findViewById(R.id.toolbar_layout);
    this.solidToolbarView = solidToolbarView;
    LockableViewPager viewPager = view.findViewById(R.id.pager);
    this.viewPager = viewPager;
    if (!portrait) {
        initialMenuState = MenuState.FULL_SCREEN;
        int width = getResources().getDimensionPixelSize(R.dimen.dashboard_land_width) - getResources().getDimensionPixelSize(R.dimen.dashboard_land_shadow_width);
        solidToolbarView.setLayoutParams(new FrameLayout.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));
        solidToolbarView.setVisibility(View.VISIBLE);
        final TypedValue typedValueAttr = new TypedValue();
        int bgAttrId = AndroidUtils.isLayoutRtl(mapActivity) ? R.attr.right_menu_view_bg : R.attr.left_menu_view_bg;
        mapActivity.getTheme().resolveAttribute(bgAttrId, typedValueAttr, true);
        view.findViewById(R.id.pager_container).setBackgroundResource(typedValueAttr.resourceId);
        view.setLayoutParams(new FrameLayout.LayoutParams(getResources().getDimensionPixelSize(R.dimen.dashboard_land_width), ViewGroup.LayoutParams.MATCH_PARENT));
    }
    viewPager.setClipToPadding(false);
    currentMenuState = initialMenuState;
    final RoutesPagerAdapter pagerAdapter = new RoutesPagerAdapter(getChildFragmentManager(), routesCount);
    viewPager.setAdapter(pagerAdapter);
    viewPager.setCurrentItem(routeIndex);
    viewPager.setOffscreenPageLimit(1);
    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 mapActivity = getMapActivity();
            View view = getView();
            if (mapActivity != null && view != null) {
                mapActivity.getMyApplication().getTransportRoutingHelper().setCurrentRoute(position);
                mapActivity.refreshMap();
                buildPagesControl(view);
                List<WeakReference<RouteDetailsFragment>> routeDetailsFragments = ChooseRouteFragment.this.routeDetailsFragments;
                RouteDetailsFragment current = getCurrentFragment();
                for (WeakReference<RouteDetailsFragment> ref : routeDetailsFragments) {
                    RouteDetailsFragment f = ref.get();
                    if (f != null) {
                        PublicTransportCard card = f.getTransportCard();
                        if (card != null) {
                            card.updateButtons();
                        }
                        if (f == current) {
                            updateZoomButtonsPos(f, f.getViewY(), true);
                            updatePagesViewPos(f, f.getViewY(), true);
                        }
                        Bundle args = f.getArguments();
                        if (args != null) {
                            args.putInt(ContextMenuFragment.MENU_STATE_KEY, currentMenuState);
                        }
                    }
                }
            }
        }
    });
    this.pagesView = (ViewGroup) view.findViewById(R.id.pages_control);
    buildPagesControl(view);
    buildZoomButtons(view);
    buildMenuButtons(view);
    return view;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) Bundle(android.os.Bundle) TransportRouteResult(net.osmand.router.TransportRouteResult) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) View(android.view.View) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) LockableViewPager(net.osmand.plus.LockableViewPager) ViewPager(androidx.viewpager.widget.ViewPager) LockableViewPager(net.osmand.plus.LockableViewPager) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) FrameLayout(android.widget.FrameLayout) WeakReference(java.lang.ref.WeakReference) TransportRoutingHelper(net.osmand.plus.routing.TransportRoutingHelper) List(java.util.List) ArrayList(java.util.ArrayList) MapActivity(net.osmand.plus.activities.MapActivity) TypedValue(android.util.TypedValue) PublicTransportCard(net.osmand.plus.routepreparationmenu.cards.PublicTransportCard) Nullable(androidx.annotation.Nullable)

Example 2 with TransportRoutingHelper

use of net.osmand.plus.routing.TransportRoutingHelper in project Osmand by osmandapp.

the class AppInitializer method onCreateApplication.

public void onCreateApplication() {
    // always update application mode to default
    OsmandSettings osmandSettings = app.getSettings();
    if (osmandSettings.FOLLOW_THE_ROUTE.get()) {
        ApplicationMode savedMode = osmandSettings.readApplicationMode();
        if (!osmandSettings.APPLICATION_MODE.get().getStringKey().equals(savedMode.getStringKey())) {
            osmandSettings.setApplicationMode(savedMode);
        }
    } else {
        osmandSettings.setApplicationMode(osmandSettings.DEFAULT_APPLICATION_MODE.get());
    }
    startTime = System.currentTimeMillis();
    getLazyRoutingConfig();
    app.applyTheme(app);
    startupInit(app.reconnectToBRouter(), IBRouterService.class);
    app.backupHelper = startupInit(new BackupHelper(app), BackupHelper.class);
    app.inAppPurchaseHelper = startupInit(new InAppPurchaseHelperImpl(app), InAppPurchaseHelperImpl.class);
    app.poiTypes = startupInit(MapPoiTypes.getDefaultNoInit(), MapPoiTypes.class);
    app.transportRoutingHelper = startupInit(new TransportRoutingHelper(app), TransportRoutingHelper.class);
    app.routingHelper = startupInit(new RoutingHelper(app), RoutingHelper.class);
    app.routingOptionsHelper = startupInit(new RoutingOptionsHelper(app), RoutingOptionsHelper.class);
    app.resourceManager = startupInit(new ResourceManager(app), ResourceManager.class);
    app.daynightHelper = startupInit(new DayNightHelper(app), DayNightHelper.class);
    app.locationProvider = startupInit(new OsmAndLocationProvider(app), OsmAndLocationProvider.class);
    app.avoidSpecificRoads = startupInit(new AvoidSpecificRoads(app), AvoidSpecificRoads.class);
    app.avoidRoadsHelper = startupInit(new AvoidRoadsHelper(app), AvoidRoadsHelper.class);
    app.savingTrackHelper = startupInit(new SavingTrackHelper(app), SavingTrackHelper.class);
    app.analyticsHelper = startupInit(new AnalyticsHelper(app), AnalyticsHelper.class);
    app.notificationHelper = startupInit(new NotificationHelper(app), NotificationHelper.class);
    app.liveMonitoringHelper = startupInit(new LiveMonitoringHelper(app), LiveMonitoringHelper.class);
    app.selectedGpxHelper = startupInit(new GpxSelectionHelper(app, app.savingTrackHelper), GpxSelectionHelper.class);
    app.gpxDbHelper = startupInit(new GpxDbHelper(app), GpxDbHelper.class);
    app.favoritesHelper = startupInit(new FavouritesHelper(app), FavouritesHelper.class);
    app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class);
    app.aidlApi = startupInit(new OsmandAidlApi(app), OsmandAidlApi.class);
    app.regions = startupInit(new OsmandRegions(), OsmandRegions.class);
    updateRegionVars();
    app.poiFilters = startupInit(new PoiFiltersHelper(app), PoiFiltersHelper.class);
    app.rendererRegistry = startupInit(new RendererRegistry(app), RendererRegistry.class);
    app.geocodingLookupService = startupInit(new GeocodingLookupService(app), GeocodingLookupService.class);
    app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class);
    app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class);
    app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class);
    app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class);
    app.mapViewTrackingUtilities = startupInit(new MapViewTrackingUtilities(app), MapViewTrackingUtilities.class);
    app.osmandMap = startupInit(new OsmandMap(app), OsmandMap.class);
    // TODO TRAVEL_OBF_HELPER check ResourceManager and use TravelObfHelper
    TravelHelper travelHelper = !TravelDbHelper.checkIfDbFileExists(app) ? new TravelObfHelper(app) : new TravelDbHelper(app);
    app.travelHelper = startupInit(travelHelper, TravelHelper.class);
    app.travelRendererHelper = startupInit(new TravelRendererHelper(app), TravelRendererHelper.class);
    app.lockHelper = startupInit(new LockHelper(app), LockHelper.class);
    app.fileSettingsHelper = startupInit(new FileSettingsHelper(app), FileSettingsHelper.class);
    app.networkSettingsHelper = startupInit(new NetworkSettingsHelper(app), NetworkSettingsHelper.class);
    app.quickActionRegistry = startupInit(new QuickActionRegistry(app.getSettings()), QuickActionRegistry.class);
    app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class);
    app.oprAuthHelper = startupInit(new OprAuthHelper(app), OprAuthHelper.class);
    app.onlineRoutingHelper = startupInit(new OnlineRoutingHelper(app), OnlineRoutingHelper.class);
    app.launcherShortcutsHelper = startupInit(new LauncherShortcutsHelper(app), LauncherShortcutsHelper.class);
    app.gpsFilterHelper = startupInit(new GpsFilterHelper(app), GpsFilterHelper.class);
    app.downloadTilesHelper = startupInit(new DownloadTilesHelper(app), DownloadTilesHelper.class);
    initOpeningHoursParser();
}
Also used : DayNightHelper(net.osmand.plus.helpers.DayNightHelper) OsmOAuthHelper(net.osmand.plus.plugins.osmedit.oauth.OsmOAuthHelper) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) AvoidSpecificRoads(net.osmand.plus.helpers.AvoidSpecificRoads) BackupHelper(net.osmand.plus.backup.BackupHelper) MapViewTrackingUtilities(net.osmand.plus.base.MapViewTrackingUtilities) WaypointHelper(net.osmand.plus.helpers.WaypointHelper) OnlineRoutingHelper(net.osmand.plus.onlinerouting.OnlineRoutingHelper) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) SavingTrackHelper(net.osmand.plus.track.helpers.SavingTrackHelper) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) TravelObfHelper(net.osmand.plus.wikivoyage.data.TravelObfHelper) AvoidRoadsHelper(net.osmand.plus.routing.AvoidRoadsHelper) GpxDbHelper(net.osmand.plus.track.helpers.GpxDbHelper) OsmandRegions(net.osmand.map.OsmandRegions) LauncherShortcutsHelper(net.osmand.plus.helpers.LauncherShortcutsHelper) RendererRegistry(net.osmand.plus.render.RendererRegistry) DownloadTilesHelper(net.osmand.plus.plugins.rastermaps.DownloadTilesHelper) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) QuickActionRegistry(net.osmand.plus.quickaction.QuickActionRegistry) AnalyticsHelper(net.osmand.plus.helpers.AnalyticsHelper) TravelHelper(net.osmand.plus.wikivoyage.data.TravelHelper) OsmandMap(net.osmand.plus.views.OsmandMap) TravelDbHelper(net.osmand.plus.wikivoyage.data.TravelDbHelper) MapMarkersDbHelper(net.osmand.plus.mapmarkers.MapMarkersDbHelper) GpsFilterHelper(net.osmand.plus.track.helpers.GpsFilterHelper) OnlineRoutingHelper(net.osmand.plus.onlinerouting.OnlineRoutingHelper) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TransportRoutingHelper(net.osmand.plus.routing.TransportRoutingHelper) ResourceManager(net.osmand.plus.resources.ResourceManager) GpxSelectionHelper(net.osmand.plus.track.helpers.GpxSelectionHelper) TravelRendererHelper(net.osmand.plus.render.TravelRendererHelper) LiveMonitoringHelper(net.osmand.plus.plugins.monitoring.LiveMonitoringHelper) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) MapPoiTypes(net.osmand.osm.MapPoiTypes) QuickSearchHelper(net.osmand.plus.search.QuickSearchHelper) NetworkSettingsHelper(net.osmand.plus.backup.NetworkSettingsHelper) RoutingOptionsHelper(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) NotificationHelper(net.osmand.plus.notifications.NotificationHelper) InAppPurchaseHelperImpl(net.osmand.plus.inapp.InAppPurchaseHelperImpl) TransportRoutingHelper(net.osmand.plus.routing.TransportRoutingHelper) FileSettingsHelper(net.osmand.plus.settings.backend.backup.FileSettingsHelper) OprAuthHelper(net.osmand.plus.plugins.openplacereviews.OprAuthHelper) OsmandAidlApi(net.osmand.aidl.OsmandAidlApi) LockHelper(net.osmand.plus.helpers.LockHelper)

Example 3 with TransportRoutingHelper

use of net.osmand.plus.routing.TransportRoutingHelper in project Osmand by osmandapp.

the class PublicTransportCard method createRouteBadges.

private void createRouteBadges(List<TransportRouteResultSegment> segments, boolean badgesRowClickable) {
    int itemsSpacing = AndroidUtils.dpToPx(app, 6);
    FlowLayout routesBadges = (FlowLayout) view.findViewById(R.id.routes_badges);
    routesBadges.removeAllViews();
    TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
    Iterator<TransportRouteResultSegment> iterator = segments.iterator();
    TransportRouteResultSegment prevSegment = null;
    while (iterator.hasNext()) {
        TransportRouteResultSegment s = iterator.next();
        RouteCalculationResult walkingSegment = transportRoutingHelper.getWalkingRouteSegment(prevSegment, s);
        if (walkingSegment != null) {
            double walkTime = walkingSegment.getRoutingTime();
            if (walkTime > MIN_WALK_TIME) {
                routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
                routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
            }
        } else if (s.walkDist > 0) {
            double walkTime = getWalkTime(s.walkDist, routeResult.getWalkSpeed());
            if (walkTime > MIN_WALK_TIME) {
                LatLon start;
                LatLon end = s.getStart().getLocation();
                if (prevSegment != null) {
                    start = prevSegment.getEnd().getLocation();
                } else {
                    start = this.startLocation;
                }
                routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
                routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
            }
        }
        routesBadges.addView(createRouteBadge(s, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
        if (iterator.hasNext()) {
            routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
        } else {
            walkingSegment = transportRoutingHelper.getWalkingRouteSegment(s, null);
            if (walkingSegment != null) {
                double walkTime = walkingSegment.getRoutingTime();
                if (walkTime > MIN_WALK_TIME) {
                    routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
                    routesBadges.addView(createWalkRouteBadge(walkingSegment, badgesRowClickable), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
                }
            } else {
                double finishWalkDist = routeResult.getFinishWalkDist();
                if (finishWalkDist > 0) {
                    double walkTime = getWalkTime(finishWalkDist, routeResult.getWalkSpeed());
                    if (walkTime > MIN_WALK_TIME) {
                        LatLon start = s.getEnd().getLocation();
                        LatLon end = this.endLocation;
                        routesBadges.addView(createArrow(), new FlowLayout.LayoutParams(itemsSpacing, itemsSpacing));
                        routesBadges.addView(createWalkRouteBadge(walkTime, start, end, badgesRowClickable));
                    }
                }
            }
        }
        prevSegment = s;
    }
}
Also used : LatLon(net.osmand.data.LatLon) FlowLayout(net.osmand.plus.widgets.FlowLayout) TransportRouteResultSegment(net.osmand.router.TransportRoutePlanner.TransportRouteResultSegment) RouteCalculationResult(net.osmand.plus.routing.RouteCalculationResult) TransportRoutingHelper(net.osmand.plus.routing.TransportRoutingHelper)

Example 4 with TransportRoutingHelper

use of net.osmand.plus.routing.TransportRoutingHelper in project Osmand by osmandapp.

the class PublicTransportCard method getSecondLineDescrSpan.

private SpannableString getSecondLineDescrSpan(List<TransportRouteResultSegment> segments) {
    TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
    Typeface typeface = FontCache.getRobotoMedium(app);
    int walkTimeReal = transportRoutingHelper.getWalkingTime(segments);
    int walkTimePT = (int) routeResult.getWalkTime();
    int walkTime = walkTimeReal > 0 ? walkTimeReal : walkTimePT;
    String walkTimeStr = OsmAndFormatter.getFormattedDuration(walkTime, app);
    int walkDistanceReal = transportRoutingHelper.getWalkingDistance(segments);
    int walkDistancePT = (int) routeResult.getWalkDist();
    int walkDistance = walkDistanceReal > 0 ? walkDistanceReal : walkDistancePT;
    String walkDistanceStr = OsmAndFormatter.getFormattedDistance(walkDistance, app);
    int travelTime = (int) routeResult.getTravelTime() + walkTime;
    String travelTimeStr = OsmAndFormatter.getFormattedDuration(travelTime, app);
    int travelDist = (int) routeResult.getTravelDist() + walkDistance;
    String travelDistStr = OsmAndFormatter.getFormattedDistance(travelDist, app);
    String secondLine = travelTimeStr + ", " + travelDistStr + "  •  " + app.getString(R.string.shared_string_walk) + " " + walkTimeStr + ", " + walkDistanceStr;
    SpannableString secondLineDesc = new SpannableString(secondLine);
    int mainFontColor = getMainFontColor();
    int startTravelTime = secondLine.indexOf(travelTimeStr);
    secondLineDesc.setSpan(new ForegroundColorSpan(mainFontColor), startTravelTime, startTravelTime + travelTimeStr.length(), 0);
    secondLineDesc.setSpan(new CustomTypefaceSpan(typeface), startTravelTime, startTravelTime + travelTimeStr.length(), 0);
    int startWalkTime = secondLine.lastIndexOf(walkTimeStr);
    secondLineDesc.setSpan(new ForegroundColorSpan(mainFontColor), startWalkTime, startWalkTime + walkTimeStr.length(), 0);
    secondLineDesc.setSpan(new CustomTypefaceSpan(typeface), startWalkTime, startWalkTime + walkTimeStr.length(), 0);
    return secondLineDesc;
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) CustomTypefaceSpan(net.osmand.plus.widgets.style.CustomTypefaceSpan) Typeface(android.graphics.Typeface) TransportRoutingHelper(net.osmand.plus.routing.TransportRoutingHelper) SpannableString(android.text.SpannableString)

Example 5 with TransportRoutingHelper

use of net.osmand.plus.routing.TransportRoutingHelper in project Osmand by osmandapp.

the class MapRouteInfoMenu method updateCards.

private void updateCards() {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return;
    }
    OsmandApplication app = mapActivity.getMyApplication();
    nightMode = app.getDaynightHelper().isNightModeForMapControls();
    TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
    RoutingHelper routingHelper = app.getRoutingHelper();
    boolean hasPrecalculatedMissingMaps = hasPrecalculatedMissingMaps();
    boolean hasCalculatedMissingMaps = hasCalculatedMissingMaps(app);
    List<BaseCard> menuCards = new ArrayList<>();
    boolean bottomShadowVisible = true;
    if (isBasicRouteCalculated()) {
        GPXFile gpx = GpxUiHelper.makeGpxFromRoute(routingHelper.getRoute(), app);
        SimpleRouteCard simpleRouteCard = new SimpleRouteCard(mapActivity, gpx);
        simpleRouteCard.setListener(this);
        menuCards.add(simpleRouteCard);
        bottomShadowVisible = false;
    } else if (isTransportRouteCalculated()) {
        TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
        List<TransportRouteResult> routes = transportRoutingHelper.getRoutes();
        if (routes != null && routes.size() > 0) {
            TransportRouteResult route = routes.get(0);
            int walkTimeReal = transportRoutingHelper.getWalkingTime(route.getSegments());
            int walkTimePT = (int) route.getWalkTime();
            int walkTime = walkTimeReal > 0 ? walkTimeReal : walkTimePT;
            int travelTime = (int) route.getTravelTime() + walkTime;
            LatLon startLocation = transportRoutingHelper.getStartLocation();
            LatLon endLocation = transportRoutingHelper.getEndLocation();
            int approxPedestrianTime = (int) MapUtils.getDistance(startLocation, endLocation);
            boolean showPedestrianCard = approxPedestrianTime < travelTime + 60 && approxPedestrianTime < MAX_PEDESTRIAN_ROUTE_DURATION;
            boolean hasTopCard = false;
            if (routes.size() > 1 && routeSelected) {
                int currentRoute = app.getTransportRoutingHelper().getCurrentRoute();
                if (currentRoute >= 0 && currentRoute < routes.size()) {
                    route = routes.get(currentRoute);
                    PublicTransportCard card = new PublicTransportCard(mapActivity, startLocation, endLocation, route, currentRoute);
                    card.setRouteInfoVisible(false);
                    card.setRouteButtonsVisible(false);
                    card.setShowBottomShadow(false);
                    card.setShowTopShadow(false);
                    card.setListener(this);
                    menuCards.add(card);
                    hasTopCard = true;
                }
            }
            for (int i = 0; i < routes.size(); i++) {
                route = routes.get(i);
                PublicTransportCard card = new PublicTransportCard(mapActivity, startLocation, endLocation, route, i);
                card.setShowButtonCustomTitle(mapActivity.getString(R.string.shared_string_show_on_map));
                card.setShowBottomShadow(i == routes.size() - 1 && !showPedestrianCard);
                card.setShowTopShadow(i != 0 || hasTopCard);
                card.setListener(this);
                menuCards.add(card);
            }
            if (showPedestrianCard) {
                PedestrianRouteCard pedestrianRouteCard = new PedestrianRouteCard(mapActivity, approxPedestrianTime);
                pedestrianRouteCard.setListener(this);
                menuCards.add(pedestrianRouteCard);
            }
            bottomShadowVisible = routes.size() == 0;
        } else {
            RouteMenuAppModes mode = app.getRoutingOptionsHelper().getRouteMenuAppMode(routingHelper.getAppMode());
            boolean avoidPTTypesCustomized = false;
            for (LocalRoutingParameter parameter : mode.parameters) {
                if (parameter instanceof AvoidPTTypesRoutingParameter) {
                    avoidPTTypesCustomized = true;
                    break;
                }
            }
            if (avoidPTTypesCustomized) {
                PublicTransportNotFoundSettingsWarningCard warningCard = new PublicTransportNotFoundSettingsWarningCard(mapActivity);
                warningCard.setListener(this);
                menuCards.add(warningCard);
            } else {
                PublicTransportNotFoundWarningCard warningCard = new PublicTransportNotFoundWarningCard(mapActivity);
                warningCard.setListener(this);
                menuCards.add(warningCard);
            }
        }
    } else if (routeCalculationInProgress) {
        if (app.getRoutingHelper().isPublicTransportMode()) {
            menuCards.add(new PublicTransportBetaWarningCard(mapActivity));
        } else if (app.getRoutingHelper().isBoatMode()) {
            menuCards.add(new NauticalBridgeHeightWarningCard(mapActivity));
        } else if (hasPrecalculatedMissingMaps || suggestedMapsOnlineSearch) {
            menuCards.add(new SuggestionsMapsDownloadWarningCard(mapActivity));
        } else if (app.getTargetPointsHelper().hasTooLongDistanceToNavigate() && !hasCalculatedMissingMaps) {
            menuCards.add(new LongDistanceWarningCard(mapActivity));
        }
    } else {
        if (hasCalculatedMissingMaps) {
            menuCards.add(new SuggestionsMapsDownloadWarningCard(mapActivity));
        } else {
            // Home/work card
            HomeWorkCard homeWorkCard = new HomeWorkCard(mapActivity);
            menuCards.add(homeWorkCard);
            // Previous route card
            boolean historyEnabled = app.getSettings().NAVIGATION_HISTORY.get();
            if (historyEnabled) {
                TargetPoint startBackup = targetPointsHelper.getPointToStartBackup();
                if (startBackup == null) {
                    startBackup = targetPointsHelper.getMyLocationToStart();
                }
                TargetPoint destinationBackup = targetPointsHelper.getPointToNavigateBackup();
                if (startBackup != null && destinationBackup != null) {
                    PreviousRouteCard previousRouteCard = new PreviousRouteCard(mapActivity);
                    previousRouteCard.setListener(this);
                    menuCards.add(previousRouteCard);
                }
            }
            // Gpx card
            List<SelectedGpxFile> selectedGPXFiles = app.getSelectedGpxHelper().getSelectedGPXFiles();
            final List<GPXFile> gpxFiles = new ArrayList<>();
            for (SelectedGpxFile gs : selectedGPXFiles) {
                if (!gs.isShowCurrentTrack()) {
                    if (gs.getGpxFile().hasRtePt() || gs.getGpxFile().hasTrkPt()) {
                        gpxFiles.add(gs.getGpxFile());
                    }
                }
            }
            if (gpxFiles.size() > 0) {
                TracksCard tracksCard = new TracksCard(mapActivity, gpxFiles);
                tracksCard.setListener(this);
                menuCards.add(tracksCard);
            }
            // Map markers card
            List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
            if (mapMarkers.size() > 0) {
                MapMarkersCard mapMarkersCard = new MapMarkersCard(mapActivity, mapMarkers);
                menuCards.add(mapMarkersCard);
            }
            // History card
            if (historyEnabled) {
                try {
                    SearchResultCollection res = app.getSearchUICore().getCore().shallowSearch(SearchHistoryAPI.class, "", null, false, false);
                    if (res != null) {
                        List<SearchResult> results = res.getCurrentSearchResults();
                        if (results.size() > 0) {
                            HistoryCard historyCard = new HistoryCard(mapActivity, results);
                            historyCard.setListener(this);
                            menuCards.add(historyCard);
                        }
                    }
                } catch (IOException e) {
                    LOG.error(e);
                }
            }
        }
    }
    applyCardsState(menuCards, this.menuCards);
    this.menuCards = menuCards;
    setBottomShadowVisible(bottomShadowVisible);
    setupCards();
}
Also used : RouteMenuAppModes(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.RouteMenuAppModes) OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.mapmarkers.MapMarker) PedestrianRouteCard(net.osmand.plus.routepreparationmenu.cards.PedestrianRouteCard) AvoidPTTypesRoutingParameter(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter) SuggestionsMapsDownloadWarningCard(net.osmand.plus.routepreparationmenu.cards.SuggestionsMapsDownloadWarningCard) ArrayList(java.util.ArrayList) TransportRouteResult(net.osmand.router.TransportRouteResult) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) OtherLocalRoutingParameter(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.OtherLocalRoutingParameter) LocalRoutingParameter(net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter) PublicTransportBetaWarningCard(net.osmand.plus.routepreparationmenu.cards.PublicTransportBetaWarningCard) BaseCard(net.osmand.plus.routepreparationmenu.cards.BaseCard) MapMarkersCard(net.osmand.plus.routepreparationmenu.cards.MapMarkersCard) ArrayList(java.util.ArrayList) List(java.util.List) NauticalBridgeHeightWarningCard(net.osmand.plus.routepreparationmenu.cards.NauticalBridgeHeightWarningCard) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity) TracksCard(net.osmand.plus.routepreparationmenu.cards.TracksCard) PublicTransportNotFoundSettingsWarningCard(net.osmand.plus.routepreparationmenu.cards.PublicTransportNotFoundSettingsWarningCard) PreviousRouteCard(net.osmand.plus.routepreparationmenu.cards.PreviousRouteCard) LongDistanceWarningCard(net.osmand.plus.routepreparationmenu.cards.LongDistanceWarningCard) SearchResult(net.osmand.search.core.SearchResult) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TransportRoutingHelper(net.osmand.plus.routing.TransportRoutingHelper) PublicTransportNotFoundWarningCard(net.osmand.plus.routepreparationmenu.cards.PublicTransportNotFoundWarningCard) HomeWorkCard(net.osmand.plus.routepreparationmenu.cards.HomeWorkCard) IOException(java.io.IOException) LatLon(net.osmand.data.LatLon) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) TransportRoutingHelper(net.osmand.plus.routing.TransportRoutingHelper) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) HistoryCard(net.osmand.plus.routepreparationmenu.cards.HistoryCard) GPXFile(net.osmand.GPXUtilities.GPXFile) SimpleRouteCard(net.osmand.plus.routepreparationmenu.cards.SimpleRouteCard) PublicTransportCard(net.osmand.plus.routepreparationmenu.cards.PublicTransportCard)

Aggregations

TransportRoutingHelper (net.osmand.plus.routing.TransportRoutingHelper)7 OsmandApplication (net.osmand.plus.OsmandApplication)4 MapActivity (net.osmand.plus.activities.MapActivity)3 RoutingHelper (net.osmand.plus.routing.RoutingHelper)3 TransportRouteResult (net.osmand.router.TransportRouteResult)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LatLon (net.osmand.data.LatLon)2 TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)2 PublicTransportCard (net.osmand.plus.routepreparationmenu.cards.PublicTransportCard)2 Typeface (android.graphics.Typeface)1 Bundle (android.os.Bundle)1 SpannableString (android.text.SpannableString)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 TypedValue (android.util.TypedValue)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 NonNull (androidx.annotation.NonNull)1