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();
}
}
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);
}
}
}
}
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;
}
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();
}
}
Aggregations