Search in sources :

Example 46 with TargetPoint

use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint 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)

Example 47 with TargetPoint

use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class MapRouteInfoMenu method generateViaDescription.

public String generateViaDescription() {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        OsmandApplication app = mapActivity.getMyApplication();
        TargetPointsHelper targets = app.getTargetPointsHelper();
        List<TargetPoint> points = targets.getIntermediatePointsNavigation();
        if (points.size() == 0) {
            return "";
        }
        StringBuilder via = new StringBuilder();
        for (int i = 0; i < points.size(); i++) {
            if (i > 0) {
                via.append(" ");
            }
            TargetPoint p = points.get(i);
            String description = p.getOnlyName();
            via.append(getRoutePointDescription(p.point, description));
            boolean needAddress = new PointDescription(PointDescription.POINT_TYPE_LOCATION, description).isSearchingAddress(mapActivity) && !intermediateRequestsLatLon.contains(p.point);
            if (needAddress) {
                AddressLookupRequest lookupRequest = new AddressLookupRequest(p.point, address -> updateMenu(), null);
                intermediateRequestsLatLon.add(p.point);
                app.getGeocodingLookupService().lookupAddress(lookupRequest);
            }
        }
        return via.toString();
    }
    return "";
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) PointDescription(net.osmand.data.PointDescription) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) FavouritePoint(net.osmand.data.FavouritePoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) AddressLookupRequest(net.osmand.plus.GeocodingLookupService.AddressLookupRequest) MapActivity(net.osmand.plus.activities.MapActivity)

Example 48 with TargetPoint

use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class RouteDetailsFragment method buildDestinationItem.

private void buildDestinationItem(@NonNull View view, final TargetPoint destination, int[] startTime, final TransportRouteResultSegment segment, double walkSpeed) {
    OsmandApplication app = requireMyApplication();
    Typeface typeface = FontCache.getRobotoMedium(app);
    FrameLayout baseItemView = new FrameLayout(view.getContext());
    LinearLayout imagesContainer = (LinearLayout) createImagesContainer(view.getContext());
    baseItemView.addView(imagesContainer);
    LinearLayout infoContainer = (LinearLayout) createInfoContainer(view.getContext());
    baseItemView.addView(infoContainer);
    buildRowDivider(infoContainer, true);
    double walkDist = (long) getWalkDistance(segment, null, segment.walkDist);
    int walkTime = (int) getWalkTime(segment, null, walkDist, walkSpeed);
    if (walkTime < 60) {
        walkTime = 60;
    }
    SpannableStringBuilder spannable = new SpannableStringBuilder(getString(R.string.shared_string_walk)).append(" ");
    spannable.setSpan(new ForegroundColorSpan(getSecondaryColor()), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    int startIndex = spannable.length();
    spannable.append("~").append(OsmAndFormatter.getFormattedDuration(walkTime, app));
    spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    startIndex = spannable.length();
    spannable.append(", ").append(OsmAndFormatter.getFormattedDistance((float) walkDist, app));
    spannable.setSpan(new ForegroundColorSpan(getSecondaryColor()), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    buildWalkRow(infoContainer, spannable, imagesContainer, new OnClickListener() {

        @Override
        public void onClick(View v) {
            showWalkingRouteOnMap(segment, null);
        }
    });
    buildRowDivider(infoContainer, true);
    addWalkRouteIcon(imagesContainer);
    String timeStr = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0] + walkTime);
    String name = getRoutePointDescription(destination.point, destination.getOnlyName());
    SpannableString title = new SpannableString(name);
    title.setSpan(new CustomTypefaceSpan(typeface), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    title.setSpan(new ForegroundColorSpan(getActiveColor()), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    SpannableString secondaryText = new SpannableString(getString(R.string.route_descr_destination));
    secondaryText.setSpan(new CustomTypefaceSpan(typeface), 0, secondaryText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    secondaryText.setSpan(new ForegroundColorSpan(getMainFontColor()), 0, secondaryText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    buildDestinationRow(infoContainer, timeStr, title, secondaryText, destination.point, imagesContainer, new OnClickListener() {

        @Override
        public void onClick(View v) {
            showLocationOnMap(destination.point);
        }
    });
    ((ViewGroup) view).addView(baseItemView);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ForegroundColorSpan(android.text.style.ForegroundColorSpan) CustomTypefaceSpan(net.osmand.plus.widgets.style.CustomTypefaceSpan) Typeface(android.graphics.Typeface) ViewGroup(android.view.ViewGroup) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) View(android.view.View) CollapsableView(net.osmand.plus.mapcontextmenu.CollapsableView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) SpannableString(android.text.SpannableString) FrameLayout(android.widget.FrameLayout) OnClickListener(android.view.View.OnClickListener) LinearLayout(android.widget.LinearLayout) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 49 with TargetPoint

use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class AddPointBottomSheetDialog method createSwitchStartAndEndItem.

private void createSwitchStartAndEndItem() {
    final View switchStartAndEndView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_simple_56dp, null);
    TextView title = (TextView) switchStartAndEndView.findViewById(R.id.title);
    String start = getString(R.string.route_start_point);
    String destination = getString(R.string.route_descr_destination);
    String titleS = getString(R.string.swap_two_places, start, destination);
    SpannableString titleSpan = new SpannableString(titleS);
    int startIndex = titleS.indexOf(start);
    int destinationIndex = titleS.indexOf(destination);
    if (startIndex != -1 && destinationIndex != -1) {
        Typeface typeface = FontCache.getRobotoMedium(getContext());
        titleSpan.setSpan(new CustomTypefaceSpan(typeface), startIndex, startIndex + start.length(), 0);
        titleSpan.setSpan(new CustomTypefaceSpan(typeface), destinationIndex, destinationIndex + destination.length(), 0);
    }
    title.setText(titleSpan);
    BaseBottomSheetItem switchStartAndEndItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_change_navigation_points)).setCustomView(switchStartAndEndView).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = (MapActivity) getActivity();
            if (mapActivity != null) {
                TargetPointsHelper targetsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
                TargetPoint startPoint = targetsHelper.getPointToStart();
                if (startPoint == null) {
                    mapActivity.getMyApplication().showShortToastMessage(R.string.route_add_start_point);
                    return;
                }
                WaypointDialogHelper.switchStartAndFinish(mapActivity.getMyApplication(), mapActivity, mapActivity.getDashboard().getWaypointDialogHelper(), true);
            }
            dismiss();
        }
    }).create();
    items.add(switchStartAndEndItem);
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) CustomTypefaceSpan(net.osmand.plus.widgets.style.CustomTypefaceSpan) Typeface(android.graphics.Typeface) SpannableString(android.text.SpannableString) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) FavouritePoint(net.osmand.data.FavouritePoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) SpannableString(android.text.SpannableString) ContextThemeWrapper(android.view.ContextThemeWrapper) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)49 TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)23 OsmandApplication (net.osmand.plus.OsmandApplication)20 LatLon (net.osmand.data.LatLon)19 MapActivity (net.osmand.plus.activities.MapActivity)15 View (android.view.View)13 TextView (android.widget.TextView)13 Location (net.osmand.Location)13 ArrayList (java.util.ArrayList)12 ImageView (android.widget.ImageView)11 FavouritePoint (net.osmand.data.FavouritePoint)10 PointDescription (net.osmand.data.PointDescription)10 MapMarker (net.osmand.plus.mapmarkers.MapMarker)8 List (java.util.List)7 RoutingHelper (net.osmand.plus.routing.RoutingHelper)7 SuppressLint (android.annotation.SuppressLint)6 FrameLayout (android.widget.FrameLayout)6 LinearLayout (android.widget.LinearLayout)6 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)6 OnClickListener (android.view.View.OnClickListener)5