Search in sources :

Example 1 with GPXRouteParamsBuilder

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

the class FailSafeFuntions method restoreRoutingMode.

public static void restoreRoutingMode(final MapActivity ma) {
    final OsmandApplication app = ma.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final Handler uiHandler = new Handler();
    final String gpxPath = settings.FOLLOW_THE_GPX_ROUTE.get();
    final TargetPointsHelper targetPoints = app.getTargetPointsHelper();
    final TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
    if (pointToNavigate == null && gpxPath == null) {
        notRestoreRoutingMode(ma, app);
    } else {
        quitRouteRestoreDialog = false;
        Runnable encapsulate = new Runnable() {

            int delay = 7;

            Runnable delayDisplay = null;

            @Override
            public void run() {
                AlertDialog.Builder builder = new AlertDialog.Builder(ma);
                final TextView tv = new TextView(ma);
                tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                tv.setPadding(7, 5, 7, 5);
                builder.setView(tv);
                builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        restoreRoutingModeInner();
                    }
                });
                builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        quitRouteRestoreDialog = true;
                        notRestoreRoutingMode(ma, app);
                    }
                });
                final AlertDialog dlg = builder.show();
                dlg.setOnDismissListener(new OnDismissListener() {

                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                dlg.setOnCancelListener(new OnCancelListener() {

                    @Override
                    public void onCancel(DialogInterface dialog) {
                        quitRouteRestoreDialog = true;
                    }
                });
                delayDisplay = new Runnable() {

                    @Override
                    public void run() {
                        if (!quitRouteRestoreDialog) {
                            delay--;
                            tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
                            if (delay <= 0) {
                                try {
                                    if (dlg.isShowing() && !quitRouteRestoreDialog) {
                                        dlg.dismiss();
                                    }
                                    quitRouteRestoreDialog = true;
                                    restoreRoutingModeInner();
                                } catch (Exception e) {
                                    // swalow view not attached exception
                                    log.error(e.getMessage() + "", e);
                                }
                            } else {
                                uiHandler.postDelayed(delayDisplay, 1000);
                            }
                        }
                    }
                };
                delayDisplay.run();
            }

            private void restoreRoutingModeInner() {
                AsyncTask<String, Void, GPXFile> task = new AsyncTask<String, Void, GPXFile>() {

                    @Override
                    protected GPXFile doInBackground(String... params) {
                        if (gpxPath != null) {
                            // Reverse also should be stored ?
                            GPXFile f = GPXUtilities.loadGPXFile(app, new File(gpxPath));
                            if (f.warning != null) {
                                return null;
                            }
                            return f;
                        } else {
                            return null;
                        }
                    }

                    @Override
                    protected void onPostExecute(GPXFile result) {
                        final GPXRouteParamsBuilder gpxRoute;
                        if (result != null) {
                            gpxRoute = new GPXRouteParamsBuilder(result, settings);
                            if (settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
                                gpxRoute.setCalculateOsmAndRouteParts(true);
                            }
                            if (settings.GPX_CALCULATE_RTEPT.get()) {
                                gpxRoute.setUseIntermediatePointsRTE(true);
                            }
                            if (settings.GPX_ROUTE_CALC.get()) {
                                gpxRoute.setCalculateOsmAndRoute(true);
                            }
                        } else {
                            gpxRoute = null;
                        }
                        TargetPoint endPoint = pointToNavigate;
                        if (endPoint == null) {
                            notRestoreRoutingMode(ma, app);
                        } else {
                            enterRoutingMode(ma, gpxRoute);
                        }
                    }
                };
                task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxPath);
            }
        };
        encapsulate.run();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) OnDismissListener(android.content.DialogInterface.OnDismissListener) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) OsmandSettings(net.osmand.plus.OsmandSettings) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TextView(android.widget.TextView) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 2 with GPXRouteParamsBuilder

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

the class MapActivityActions method setGPXRouteParams.

public void setGPXRouteParams(GPXFile result) {
    if (result == null) {
        mapActivity.getRoutingHelper().setGpxParams(null);
        settings.FOLLOW_THE_GPX_ROUTE.set(null);
    } else {
        GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication().getSettings());
        if (result.hasRtePt() && !result.hasTrkPt()) {
            settings.GPX_CALCULATE_RTEPT.set(true);
        } else {
            settings.GPX_CALCULATE_RTEPT.set(false);
        }
        params.setCalculateOsmAndRouteParts(settings.GPX_ROUTE_CALC_OSMAND_PARTS.get());
        params.setUseIntermediatePointsRTE(settings.GPX_CALCULATE_RTEPT.get());
        params.setCalculateOsmAndRoute(settings.GPX_ROUTE_CALC.get());
        List<Location> ps = params.getPoints();
        mapActivity.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);
            TargetPointsHelper tg = mapActivity.getMyApplication().getTargetPointsHelper();
            tg.navigateToPoint(new LatLon(finishLoc.getLatitude(), finishLoc.getLongitude()), false, -1);
            if (startLoc != finishLoc) {
                tg.setStartPoint(new LatLon(startLoc.getLatitude(), startLoc.getLongitude()), false, null);
            } else {
                tg.clearStartPoint(false);
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Location(net.osmand.Location)

Example 3 with GPXRouteParamsBuilder

use of net.osmand.plus.routing.RouteProvider.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")) {
                    name += ".gpx";
                }
                toSave = new File(fileDir, name);
            }
            if (toSave.exists()) {
                dlg.findViewById(R.id.DuplicateFileName).setVisibility(View.VISIBLE);
            } else {
                dlg.dismiss();
                new SaveDirectionsAsyncTask(app).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(android.support.v7.app.AlertDialog) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) Date(java.util.Date)

Example 4 with GPXRouteParamsBuilder

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

the class OsmAndLocationSimulation method startStopRouteAnimation.

// public void startStopRouteAnimationRoute(final MapActivity ma) {
// if (!isRouteAnimating()) {
// List<Location> currentRoute = app.getRoutingHelper().getCurrentRoute();
// if (currentRoute.isEmpty()) {
// Toast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
// } else {
// startAnimationThread(app.getRoutingHelper(), ma, new ArrayList<Location>(currentRoute), false, 1);
// }
// } else {
// stop();
// }
// }
public void startStopRouteAnimation(final Activity ma, final Runnable runnable) {
    if (!isRouteAnimating()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(ma);
        builder.setTitle(R.string.animate_route);
        final View view = ma.getLayoutInflater().inflate(R.layout.animate_route, null);
        final View gpxView = ((LinearLayout) view.findViewById(R.id.layout_animate_gpx));
        final RadioButton radioGPX = (RadioButton) view.findViewById(R.id.radio_gpx);
        radioGPX.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                gpxView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            }
        });
        // $NON-NLS-1$
        ((TextView) view.findViewById(R.id.MinSpeedup)).setText("1");
        // $NON-NLS-1$
        ((TextView) view.findViewById(R.id.MaxSpeedup)).setText("4");
        final SeekBar speedup = (SeekBar) view.findViewById(R.id.Speedup);
        speedup.setMax(3);
        builder.setView(view);
        builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean gpxNavigation = radioGPX.isChecked();
                if (gpxNavigation) {
                    GpxUiHelper.selectGPXFile(ma, false, false, new CallbackWithObject<GPXUtilities.GPXFile[]>() {

                        @Override
                        public boolean processResult(GPXUtilities.GPXFile[] result) {
                            GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(result[0], app.getSettings());
                            startAnimationThread(app, builder.getPoints(), true, speedup.getProgress() + 1);
                            if (runnable != null) {
                                runnable.run();
                            }
                            return true;
                        }
                    });
                } else {
                    List<Location> currentRoute = app.getRoutingHelper().getCurrentCalculatedRoute();
                    if (currentRoute.isEmpty()) {
                        Toast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
                    } else {
                        startAnimationThread(app, new ArrayList<Location>(currentRoute), false, 1);
                        if (runnable != null) {
                            runnable.run();
                        }
                    }
                }
            }
        });
        builder.setNegativeButton(R.string.shared_string_cancel, null);
        builder.show();
    } else {
        stop();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) SeekBar(android.widget.SeekBar) DialogInterface(android.content.DialogInterface) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) ArrayList(java.util.ArrayList) RadioButton(android.widget.RadioButton) TextView(android.widget.TextView) View(android.view.View) CallbackWithObject(net.osmand.CallbackWithObject) TextView(android.widget.TextView) ArrayList(java.util.ArrayList) List(java.util.List) CompoundButton(android.widget.CompoundButton)

Aggregations

GPXRouteParamsBuilder (net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder)4 AlertDialog (android.support.v7.app.AlertDialog)3 TextView (android.widget.TextView)3 DialogInterface (android.content.DialogInterface)2 View (android.view.View)2 File (java.io.File)2 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)2 Dialog (android.app.Dialog)1 OnCancelListener (android.content.DialogInterface.OnCancelListener)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 AsyncTask (android.os.AsyncTask)1 Handler (android.os.Handler)1 AdapterView (android.widget.AdapterView)1 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 EditText (android.widget.EditText)1 ListView (android.widget.ListView)1 RadioButton (android.widget.RadioButton)1