Search in sources :

Example 16 with GPXRouteParamsBuilder

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

the class RoutingOptionsHelper method getRoutingParametersInner.

public List<LocalRoutingParameter> getRoutingParametersInner(ApplicationMode am) {
    boolean osmandRouter = am.getRouteService() == RouteService.OSMAND;
    if (!osmandRouter) {
        return getOsmandRouterParameters(am);
    }
    GPXRouteParamsBuilder rparams = app.getRoutingHelper().getCurrentGPXRoute();
    List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>(getGpxRouterParameters(am));
    GeneralRouter rm = app.getRouter(am);
    if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
        return list;
    }
    for (GeneralRouter.RoutingParameter r : rm.getParameters().values()) {
        if (r.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) {
            if ("relief_smoothness_factor".equals(r.getGroup())) {
                continue;
            }
            if (!Algorithms.isEmpty(r.getGroup())) {
                LocalRoutingParameterGroup rpg = getLocalRoutingParameterGroup(list, r.getGroup());
                if (rpg == null) {
                    rpg = new LocalRoutingParameterGroup(am, r.getGroup());
                    list.add(rpg);
                }
                rpg.addRoutingParameter(r);
            } else {
                LocalRoutingParameter rp = new LocalRoutingParameter(am);
                rp.routingParameter = r;
                updateRoutingParameterIcons(rp);
                list.add(rp);
            }
        }
    }
    return list;
}
Also used : GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) ArrayList(java.util.ArrayList) GeneralRouter(net.osmand.router.GeneralRouter) RoutingParameter(net.osmand.router.GeneralRouter.RoutingParameter)

Example 17 with GPXRouteParamsBuilder

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

the class TrackEditCard method updateContent.

@Override
protected void updateContent() {
    String fileName = null;
    File file = null;
    if (!Algorithms.isEmpty(gpxFile.path)) {
        file = new File(gpxFile.path);
        fileName = gpxFile.path;
    } else if (!Algorithms.isEmpty(gpxFile.tracks)) {
        fileName = gpxFile.tracks.get(0).name;
    }
    if (Algorithms.isEmpty(fileName)) {
        fileName = app.getString(R.string.shared_string_gpx_track);
    }
    GPXInfo gpxInfo = new GPXInfo(fileName, file != null ? file.lastModified() : 0, file != null ? file.length() : 0);
    GPXTrackAnalysis analysis = null;
    if (file != null) {
        GpxDataItem dataItem = getDataItem(gpxInfo);
        if (dataItem != null) {
            analysis = dataItem.getAnalysis();
        }
    } else {
        analysis = gpxFile.getAnalysis(0);
    }
    String title = GpxUiHelper.getGpxTitle(Algorithms.getFileWithoutDirs(fileName));
    GPXRouteParamsBuilder routeParams = app.getRoutingHelper().getCurrentGPXRoute();
    if (gpxFile.getNonEmptySegmentsCount() > 1 && routeParams != null && routeParams.getSelectedSegment() != -1) {
        int selectedSegmentCount = routeParams.getSelectedSegment() + 1;
        int totalSegmentCount = routeParams.getFile().getNonEmptyTrkSegments(false).size();
        title = app.getString(R.string.of, selectedSegmentCount, totalSegmentCount) + ", " + title;
    }
    GpxUiHelper.updateGpxInfoView(view, title, gpxInfo, analysis, app);
    if (gpxFile.getNonEmptySegmentsCount() > 1 && routeParams != null && routeParams.getSelectedSegment() != -1 && gpxFile.getNonEmptySegmentsCount() > routeParams.getSelectedSegment()) {
        TextView distanceView = view.findViewById(R.id.distance);
        TextView timeView = view.findViewById(R.id.time);
        ImageView timeIcon = view.findViewById(R.id.time_icon);
        AndroidUiHelper.updateVisibility(view.findViewById(R.id.points_icon), false);
        AndroidUiHelper.updateVisibility(view.findViewById(R.id.points_count), false);
        List<GPXUtilities.TrkSegment> segments = gpxFile.getNonEmptyTrkSegments(false);
        GPXUtilities.TrkSegment segment = segments.get(routeParams.getSelectedSegment());
        double distance = TrackSelectSegmentAdapter.getDistance(segment);
        long time = TrackSelectSegmentAdapter.getSegmentTime(segment);
        boolean timeAvailable = time != 1;
        if (timeAvailable) {
            timeView.setText(Algorithms.formatDuration((int) (time / 1000), app.accessibilityEnabled()));
        }
        AndroidUiHelper.updateVisibility(timeView, timeAvailable);
        AndroidUiHelper.updateVisibility(timeIcon, timeAvailable);
        distanceView.setText(OsmAndFormatter.getFormattedDistance((float) distance, app));
    }
    ImageButton editButton = view.findViewById(R.id.show_on_map);
    editButton.setVisibility(View.VISIBLE);
    editButton.setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark));
    editButton.setOnClickListener(v -> notifyCardPressed());
    int minCardHeight = getDimen(R.dimen.setting_list_item_large_height);
    int listContentPadding = getDimen(R.dimen.list_content_padding);
    LinearLayout container = view.findViewById(R.id.container);
    container.setMinimumHeight(minCardHeight);
    AndroidUtils.setPadding(container, listContentPadding, 0, 0, 0);
    int activeColor = getActiveColor();
    int bgColor = ColorUtilities.getColorWithAlpha(activeColor, 0.1f);
    view.setBackgroundDrawable(new ColorDrawable(bgColor));
}
Also used : GPXInfo(net.osmand.plus.helpers.GpxUiHelper.GPXInfo) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) GPXUtilities(net.osmand.GPXUtilities) ImageButton(android.widget.ImageButton) ColorDrawable(android.graphics.drawable.ColorDrawable) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) TextView(android.widget.TextView) ImageView(android.widget.ImageView) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) LinearLayout(android.widget.LinearLayout)

Example 18 with GPXRouteParamsBuilder

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

the class SelectedTrackToFollowCard method updateContent.

@Override
protected void updateContent() {
    view.getViewTreeObserver().addOnScrollChangedListener(() -> {
        boolean bottomScrollAvailable = view.canScrollVertically(1);
        if (bottomScrollAvailable) {
            target.showShadowButton();
        } else {
            target.hideShadowButton();
        }
    });
    ViewGroup cardsContainer = ((ViewGroup) view.findViewById(R.id.cards_container));
    cardsContainer.removeAllViews();
    TrackEditCard importTrackCard = new TrackEditCard(mapActivity, gpxFile);
    importTrackCard.setListener(target);
    cardsContainer.addView(importTrackCard.build(mapActivity));
    SelectTrackCard selectTrackCard = new SelectTrackCard(mapActivity);
    selectTrackCard.setListener(target);
    cardsContainer.addView(selectTrackCard.build(mapActivity));
    ApplicationMode mode = app.getRoutingHelper().getAppMode();
    RoutingHelper routingHelper = app.getRoutingHelper();
    GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
    boolean osmandRouter = mode.getRouteService() == RouteService.OSMAND;
    if (rparams != null && osmandRouter) {
        cardsContainer.addView(buildDividerView(cardsContainer, false));
        ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, rparams.isReverse());
        reverseTrackCard.setListener(target);
        cardsContainer.addView(reverseTrackCard.build(mapActivity));
        if (!gpxFile.hasRtePt() && !gpxFile.hasRoute()) {
            cardsContainer.addView(buildDividerView(cardsContainer, true));
            AttachTrackToRoadsCard attachTrackCard = new AttachTrackToRoadsCard(mapActivity);
            attachTrackCard.setListener(target);
            cardsContainer.addView(attachTrackCard.build(mapActivity));
        }
        setupNavigateOptionsCard(cardsContainer, rparams);
    }
}
Also used : ViewGroup(android.view.ViewGroup) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) RoutingHelper(net.osmand.plus.routing.RoutingHelper)

Example 19 with GPXRouteParamsBuilder

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

the class MapActivityActions method createSaveDirections.

public static Dialog createSaveDirections(Activity activity, RoutingHelper routingHelper) {
    final OsmandApplication app = ((OsmandApplication) activity.getApplication());
    final File fileDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    final Dialog dlg = new Dialog(activity);
    dlg.setTitle(R.string.shared_string_save_as_gpx);
    dlg.setContentView(R.layout.save_directions_dialog);
    final EditText edit = (EditText) dlg.findViewById(R.id.FileNameEdit);
    final GPXRouteParamsBuilder rp = routingHelper.getCurrentGPXRoute();
    final String editText;
    if (rp == null || rp.getFile() == null || rp.getFile().path == null) {
        editText = "_" + MessageFormat.format("{0,date,yyyy-MM-dd}", new Date()) + "_";
    } else {
        editText = new File(rp.getFile().path).getName();
    }
    edit.setText(editText);
    dlg.findViewById(R.id.Save).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String name = edit.getText().toString();
            // noinspection ResultOfMethodCallIgnored
            fileDir.mkdirs();
            File toSave = fileDir;
            if (name.length() > 0) {
                if (!name.endsWith(GPX_FILE_EXT)) {
                    name += GPX_FILE_EXT;
                }
                toSave = new File(fileDir, name);
            }
            if (toSave.exists()) {
                dlg.findViewById(R.id.DuplicateFileName).setVisibility(View.VISIBLE);
            } else {
                dlg.dismiss();
                new SaveDirectionsAsyncTask(app, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, toSave);
            }
        }
    });
    dlg.findViewById(R.id.Cancel).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dlg.dismiss();
        }
    });
    return dlg;
}
Also used : EditText(android.widget.EditText) OsmandApplication(net.osmand.plus.OsmandApplication) Dialog(android.app.Dialog) AlertDialog(androidx.appcompat.app.AlertDialog) GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Date(java.util.Date)

Example 20 with GPXRouteParamsBuilder

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

the class FollowTrackFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    app = requireMyApplication();
    MapActivity mapActivity = requireMapActivity();
    importHelper = new ImportHelper(mapActivity, getMyApplication());
    GPXRouteParamsBuilder routeParamsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
    if (routeParamsBuilder != null) {
        gpxFile = routeParamsBuilder.getFile();
    }
    if (savedInstanceState != null) {
        selectingTrack = savedInstanceState.getBoolean(SELECTING_TRACK, gpxFile == null);
    } else {
        selectingTrack = gpxFile == null;
    }
}
Also used : GPXRouteParamsBuilder(net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder) ImportHelper(net.osmand.plus.importfiles.ImportHelper) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

GPXRouteParamsBuilder (net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder)22 OsmandApplication (net.osmand.plus.OsmandApplication)10 File (java.io.File)8 ImageView (android.widget.ImageView)7 TextView (android.widget.TextView)7 MapActivity (net.osmand.plus.activities.MapActivity)7 View (android.view.View)6 GPXFile (net.osmand.GPXUtilities.GPXFile)6 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)6 Location (net.osmand.Location)5 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)4 LinearLayout (android.widget.LinearLayout)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 LatLon (net.osmand.data.LatLon)3 TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)3 RoutingHelper (net.osmand.plus.routing.RoutingHelper)3 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)3 FrameLayout (android.widget.FrameLayout)2 HorizontalScrollView (android.widget.HorizontalScrollView)2 ArrayList (java.util.ArrayList)2