Search in sources :

Example 41 with TargetPointsHelper

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

Example 42 with TargetPointsHelper

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

the class MapActions method setGPXRouteParams.

public void setGPXRouteParams(GPXFile result) {
    if (result == null) {
        app.getRoutingHelper().setGpxParams(null);
        settings.FOLLOW_THE_GPX_ROUTE.set(null);
    } else {
        GPXRouteParams.GPXRouteParamsBuilder params = new GPXRouteParams.GPXRouteParamsBuilder(result, settings);
        params.setCalculateOsmAndRouteParts(settings.GPX_ROUTE_CALC_OSMAND_PARTS.get());
        params.setCalculateOsmAndRoute(settings.GPX_ROUTE_CALC.get());
        params.setSelectedSegment(settings.GPX_ROUTE_SEGMENT.get());
        List<Location> ps = params.getPoints(settings.getContext());
        app.getRoutingHelper().setGpxParams(params);
        settings.FOLLOW_THE_GPX_ROUTE.set(result.path);
        if (!ps.isEmpty()) {
            Location startLoc = ps.get(0);
            Location finishLoc = ps.get(ps.size() - 1);
            Location location = app.getLocationProvider().getLastKnownLocation();
            TargetPointsHelper pointsHelper = app.getTargetPointsHelper();
            pointsHelper.clearAllIntermediatePoints(false);
            if (location == null || MapUtils.getDistance(location, startLoc) <= START_TRACK_POINT_MY_LOCATION_RADIUS_METERS) {
                pointsHelper.clearStartPoint(false);
            } else {
                pointsHelper.setStartPoint(new LatLon(startLoc.getLatitude(), startLoc.getLongitude()), false, null);
            }
            pointsHelper.navigateToPoint(new LatLon(finishLoc.getLatitude(), finishLoc.getLongitude()), false, -1);
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) GPXRouteParams(net.osmand.plus.routing.GPXRouteParams) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) Location(net.osmand.Location)

Aggregations

TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)42 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)24 LatLon (net.osmand.data.LatLon)22 OsmandApplication (net.osmand.plus.OsmandApplication)19 MapActivity (net.osmand.plus.activities.MapActivity)14 View (android.view.View)11 RoutingHelper (net.osmand.plus.routing.RoutingHelper)11 TextView (android.widget.TextView)10 PointDescription (net.osmand.data.PointDescription)9 ImageView (android.widget.ImageView)8 ArrayList (java.util.ArrayList)8 Location (net.osmand.Location)8 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)7 Bundle (android.os.Bundle)4 OnClickListener (android.view.View.OnClickListener)4 FavouritePoint (net.osmand.data.FavouritePoint)4 DialogInterface (android.content.DialogInterface)3 HorizontalScrollView (android.widget.HorizontalScrollView)3 ImageButton (android.widget.ImageButton)3 LinearLayout (android.widget.LinearLayout)3