Search in sources :

Example 26 with TargetPoint

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

the class RouteDetailsFragment method buildStartItem.

private void buildStartItem(@NonNull View view, final TargetPoint start, int[] startTime, final TransportRouteResultSegment segment, double walkSpeed) {
    OsmandApplication app = requireMyApplication();
    FrameLayout baseItemView = new FrameLayout(view.getContext());
    LinearLayout imagesContainer = (LinearLayout) createImagesContainer(view.getContext());
    baseItemView.addView(imagesContainer);
    LinearLayout infoContainer = (LinearLayout) createInfoContainer(view.getContext());
    baseItemView.addView(infoContainer);
    String name;
    if (start != null) {
        name = start.getOnlyName().length() > 0 ? start.getOnlyName() : (getString(R.string.route_descr_map_location) + " " + getRoutePointDescription(start.getLatitude(), start.getLongitude()));
    } else {
        name = getString(R.string.shared_string_my_location);
    }
    Spannable startTitle = new SpannableString(name);
    String text = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0]);
    int drawableId = start == null ? R.drawable.ic_action_location_color : R.drawable.list_startpoint;
    Drawable icon = app.getUIUtilities().getIcon(drawableId);
    buildStartRow(infoContainer, icon, text, startTitle, imagesContainer, new OnClickListener() {

        @Override
        public void onClick(View v) {
            showLocationOnMap(start != null ? start.point : null);
        }
    });
    addWalkRouteIcon(imagesContainer);
    buildRowDivider(infoContainer, true);
    double walkDist = (long) getWalkDistance(null, segment, segment.walkDist);
    int walkTime = (int) getWalkTime(null, segment, walkDist, walkSpeed);
    if (walkTime < 60) {
        walkTime = 60;
    }
    startTime[0] += walkTime;
    SpannableStringBuilder title = new SpannableStringBuilder(Algorithms.capitalizeFirstLetter(getString(R.string.shared_string_walk)));
    title.setSpan(new ForegroundColorSpan(getSecondaryColor()), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    int startIndex = title.length();
    title.append(" ").append(OsmAndFormatter.getFormattedDuration(walkTime, app));
    title.setSpan(new CustomTypefaceSpan(FontCache.getRobotoMedium(app)), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    startIndex = title.length();
    title.append(", ").append(OsmAndFormatter.getFormattedDistance((float) walkDist, app));
    title.setSpan(new ForegroundColorSpan(getSecondaryColor()), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    buildWalkRow(infoContainer, title, imagesContainer, new OnClickListener() {

        @Override
        public void onClick(View v) {
            showWalkingRouteOnMap(null, segment);
        }
    });
    buildRowDivider(infoContainer, true);
    ((ViewGroup) view).addView(baseItemView);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ForegroundColorSpan(android.text.style.ForegroundColorSpan) CustomTypefaceSpan(net.osmand.plus.widgets.style.CustomTypefaceSpan) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) 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) Spannable(android.text.Spannable) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 27 with TargetPoint

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

the class RouteInfoWidgetsFactory method createIntermediateDistanceControl.

public TextInfoWidget createIntermediateDistanceControl(final MapActivity map) {
    final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper();
    DistanceToPointWidget distanceControl = new DistanceToPointWidget(map, R.drawable.widget_intermediate_day, R.drawable.widget_intermediate_night) {

        @Override
        protected void click(OsmandMapTileView view) {
            if (targets.getIntermediatePoints().size() > 1) {
                map.getMapActions().openIntermediatePointsDialog();
            } else {
                super.click(view);
            }
        }

        @Override
        public LatLon getPointToNavigate() {
            TargetPoint p = targets.getFirstIntermediatePoint();
            return p == null ? null : p.point;
        }

        @Override
        public int getDistance() {
            if (getPointToNavigate() != null && map.getRoutingHelper().isRouteCalculated()) {
                return map.getRoutingHelper().getLeftDistanceNextIntermediate();
            }
            return super.getDistance();
        }
    };
    return distanceControl;
}
Also used : DistanceToPointWidget(net.osmand.plus.views.mapwidgets.widgets.DistanceToPointWidget) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 28 with TargetPoint

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

the class SearchScreen method reloadHistoryInternal.

private void reloadHistoryInternal() {
    if (!destroyed) {
        OsmandApplication app = getApp();
        try {
            List<SearchResult> recentResults = new ArrayList<>();
            // Home / work
            /* Disable since points exists at favorites screen
				FavouritesDbHelper favorites = app.getFavorites();
				FavouritePoint homePoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.HOME);
				FavouritePoint workPoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.WORK);
				if (homePoint != null) {
					SearchResult result = new SearchResult();
					result.location = new LatLon(homePoint.getLatitude(), homePoint.getLongitude());
					result.objectType = ObjectType.FAVORITE;
					result.object = homePoint;
					result.localeName = homePoint.getAddress();
					recentResults.add(result);
				}
				if (workPoint != null) {
					SearchResult result = new SearchResult();
					result.location = new LatLon(workPoint.getLatitude(), workPoint.getLongitude());
					result.objectType = ObjectType.FAVORITE;
					result.object = workPoint;
					result.localeName = workPoint.getAddress();
					recentResults.add(result);
				}
				*/
            // Previous route card
            TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
            TargetPoint startPoint = targetPointsHelper.getPointToStartBackup();
            boolean myLocation = false;
            if (startPoint == null) {
                myLocation = true;
                startPoint = targetPointsHelper.getMyLocationToStart();
            }
            TargetPoint destinationPoint = targetPointsHelper.getPointToNavigateBackup();
            if (startPoint != null && destinationPoint != null) {
                StringBuilder startText = new StringBuilder(myLocation ? app.getText(R.string.my_location) : "");
                String startDescr = getPointName(startPoint);
                if (!Algorithms.isEmpty(startDescr)) {
                    if (startText.length() > 0) {
                        startText.append(" — ");
                    }
                    startText.append(startDescr);
                }
                String destDescr = getPointName(destinationPoint);
                SearchResult result = new SearchResult();
                result.location = new LatLon(destinationPoint.getLatitude(), destinationPoint.getLongitude());
                result.objectType = ObjectType.ROUTE;
                result.object = destinationPoint;
                result.localeName = destDescr;
                result.relatedObject = startPoint;
                result.localeRelatedObjectName = startText.toString();
                recentResults.add(result);
            }
            // Map markers
            List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
            int mapMarkersCount = 0;
            for (MapMarker marker : mapMarkers) {
                SearchResult result = new SearchResult();
                result.location = new LatLon(marker.getLatitude(), marker.getLongitude());
                result.objectType = ObjectType.MAP_MARKER;
                result.object = marker;
                result.localeName = marker.getName(app);
                recentResults.add(result);
                mapMarkersCount++;
                if (mapMarkersCount >= MAP_MARKERS_LIMIT) {
                    break;
                }
            }
            // History
            SearchResultCollection res = getSearchUICore().shallowSearch(SearchHistoryAPI.class, "", null, false, false);
            if (res != null) {
                recentResults.addAll(res.getCurrentSearchResults());
            }
            this.recentResults = recentResults;
            if (!searchHelper.isSearching() && Algorithms.isEmpty(searchHelper.getSearchQuery())) {
                showRecents();
                invalidate();
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            app.showToastMessage(e.getMessage());
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.mapmarkers.MapMarker) ArrayList(java.util.ArrayList) SearchResult(net.osmand.search.core.SearchResult) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper)

Example 29 with TargetPoint

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

the class DestinationReachedMenuFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null || menu == null) {
        return null;
    }
    ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, menu.isLight() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    LayoutInflater inf = LayoutInflater.from(ctx);
    View view = inf.inflate(R.layout.dest_reached_menu_fragment, container, false);
    AndroidUtils.addStatusBarPadding21v(ctx, view);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finishNavigation();
        }
    });
    UiUtilities iconsCache = mapActivity.getMyApplication().getUIUtilities();
    ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
    closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight()));
    closeImageButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finishNavigation();
        }
    });
    Button removeDestButton = (Button) view.findViewById(R.id.removeDestButton);
    removeDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_done, menu.isLight()), null, null, null);
    removeDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finishNavigation();
        }
    });
    Button recalcDestButton = (Button) view.findViewById(R.id.recalcDestButton);
    recalcDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_gdirections_dark, menu.isLight()), null, null, null);
    recalcDestButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = getMapActivity();
            if (mapActivity != null) {
                TargetPointsHelper helper = mapActivity.getMyApplication().getTargetPointsHelper();
                TargetPoint target = helper.getPointToNavigate();
                dismissMenu();
                if (target != null) {
                    helper.navigateToPoint(new LatLon(target.getLatitude(), target.getLongitude()), true, -1, target.getOriginalPointDescription());
                    mapActivity.getMapActions().recalculateRoute(false);
                    mapActivity.getMapLayers().getMapControlsLayer().startNavigation();
                }
            }
        }
    });
    Button findParkingButton = (Button) view.findViewById(R.id.findParkingButton);
    ApplicationMode appMode = mapActivity.getMyApplication().getRoutingHelper().getAppMode();
    if (!appMode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
        findParkingButton.setVisibility(View.GONE);
    }
    findParkingButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_parking_dark, menu.isLight()), null, null, null);
    findParkingButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = getMapActivity();
            if (mapActivity != null) {
                PoiFiltersHelper helper = mapActivity.getMyApplication().getPoiFilters();
                PoiUIFilter parkingFilter = helper.getFilterById(PoiUIFilter.STD_PREFIX + "parking");
                mapActivity.showQuickSearch(parkingFilter);
            }
            dismissMenu();
        }
    });
    View mainView = view.findViewById(R.id.main_view);
    if (menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_left_menu_light, R.drawable.bg_left_menu_dark);
    } else {
        AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
    }
    return view;
}
Also used : ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) PoiFiltersHelper(net.osmand.plus.poi.PoiFiltersHelper) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) View(android.view.View) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) UiUtilities(net.osmand.plus.utils.UiUtilities) LatLon(net.osmand.data.LatLon) ImageButton(android.widget.ImageButton) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(androidx.annotation.Nullable)

Example 30 with TargetPoint

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

the class DestinationReachedMenuFragment method finishNavigation.

private void finishNavigation() {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        mapActivity.getMyApplication().getTargetPointsHelper().removeWayPoint(true, -1);
        Object contextMenuObj = mapActivity.getContextMenu().getObject();
        if (mapActivity.getContextMenu().isActive() && contextMenuObj instanceof TargetPoint) {
            TargetPoint targetPoint = (TargetPoint) contextMenuObj;
            if (!targetPoint.start && !targetPoint.intermediate) {
                mapActivity.getContextMenu().close();
            }
        }
        OsmandSettings settings = mapActivity.getMyApplication().getSettings();
        settings.setApplicationMode(settings.DEFAULT_APPLICATION_MODE.get());
        mapActivity.getMapActions().stopNavigationWithoutConfirm();
        dismissMenu();
    }
}
Also used : TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) 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