use of net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder in project Osmand by osmandapp.
the class ChooseRouteFragment method buildMenuButtons.
private void buildMenuButtons(@NonNull View view) {
OsmandApplication app = getMyApplication();
AppCompatImageView backButton = (AppCompatImageView) view.findViewById(R.id.back_button);
AppCompatImageButton backButtonFlow = (AppCompatImageButton) view.findViewById(R.id.back_button_flow);
OnClickListener backOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
dismiss(true);
}
};
backButton.setOnClickListener(backOnClick);
backButtonFlow.setOnClickListener(backOnClick);
int navigationIconResId = AndroidUtils.getNavigationIconResId(getContext());
backButton.setImageResource(navigationIconResId);
backButtonFlow.setImageResource(navigationIconResId);
OnClickListener printOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
print();
}
};
View printRoute = view.findViewById(R.id.print_route);
View printRouteFlow = view.findViewById(R.id.print_route_flow);
printRoute.setOnClickListener(printOnClick);
printRouteFlow.setOnClickListener(printOnClick);
View saveRoute = view.findViewById(R.id.save_as_gpx);
View saveRouteFlow = view.findViewById(R.id.save_as_gpx_flow);
OnClickListener saveOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
String fileName = null;
if (paramsBuilder != null && paramsBuilder.getFile() != null) {
GPXFile gpxFile = paramsBuilder.getFile();
if (!Algorithms.isEmpty(gpxFile.path)) {
fileName = Algorithms.getFileNameWithoutExtension(new File(gpxFile.path).getName());
} else if (!Algorithms.isEmpty(gpxFile.tracks)) {
fileName = gpxFile.tracks.get(0).name;
}
}
if (Algorithms.isEmpty(fileName)) {
String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date());
fileName = FileUtils.createUniqueFileName(app, suggestedName, IndexConstants.GPX_INDEX_DIR, GPX_FILE_EXT);
}
SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), ChooseRouteFragment.this, null, fileName, null, false, true);
}
}
};
saveRoute.setOnClickListener(saveOnClick);
saveRouteFlow.setOnClickListener(saveOnClick);
ImageView shareRoute = (ImageView) view.findViewById(R.id.share_as_gpx);
ImageView shareRouteFlow = (ImageView) view.findViewById(R.id.share_as_gpx_flow);
Drawable shareIcon = getIcon(R.drawable.ic_action_gshare_dark, ColorUtilities.getSecondaryTextColorId(nightMode));
shareIcon = AndroidUtils.getDrawableForDirection(app, shareIcon);
shareRoute.setImageDrawable(shareIcon);
shareRouteFlow.setImageDrawable(shareIcon);
OnClickListener shareOnClick = new OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity activity = getActivity();
if (activity != null) {
OsmandApplication app = (OsmandApplication) activity.getApplication();
RoutingHelper routingHelper = app.getRoutingHelper();
final String trackName = new SimpleDateFormat("yyyy-MM-dd_HH-mm_EEE", Locale.US).format(new Date());
final GPXUtilities.GPXFile gpx = routingHelper.generateGPXFileWithRoute(trackName);
final Uri fileUri = AndroidUtils.getUriForFile(app, new File(gpx.path));
File dir = new File(app.getCacheDir(), "share");
if (!dir.exists()) {
dir.mkdir();
}
File dst = new File(dir, "route.gpx");
try {
FileWriter fw = new FileWriter(dst);
GPXUtilities.writeGpx(fw, gpx, null);
fw.close();
final Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtml(routingHelper.getRouteDirections(), routingHelper.getGeneralRouteInformation()).toString()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_route_subject));
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
sendIntent.putExtra(Intent.EXTRA_STREAM, AndroidUtils.getUriForFile(app, dst));
sendIntent.setType("text/plain");
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
AndroidUtils.startActivityIfSafe(activity, sendIntent);
} catch (IOException e) {
}
}
}
};
shareRoute.setOnClickListener(shareOnClick);
shareRouteFlow.setOnClickListener(shareOnClick);
OsmAndAppCustomization customization = app.getAppCustomization();
boolean featureEnabled = customization.isFeatureEnabled(NAVIGATION_ROUTE_DETAILS_OPTIONS_ID);
if (publicTransportMode || !featureEnabled) {
view.findViewById(R.id.toolbar_options).setVisibility(View.GONE);
}
if (publicTransportMode || !portrait || !featureEnabled) {
view.findViewById(R.id.toolbar_options_flow).setVisibility(View.GONE);
view.findViewById(R.id.toolbar_options_flow_bg).setVisibility(View.GONE);
}
}
use of net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder in project Osmand by osmandapp.
the class MapRouteInfoMenu method updateStartPointView.
private void updateStartPointView() {
MapActivity mapActivity = getMapActivity();
final View mainView = getMainView();
if (mapActivity == null || mainView == null) {
return;
}
setupFromText(mainView);
View fromLayout = mainView.findViewById(R.id.FromLayout);
fromLayout.setOnClickListener(v -> {
MapActivity mapActv = getMapActivity();
if (mapActv != null) {
AddPointBottomSheetDialog.showInstance(mapActv, PointType.START);
}
});
FrameLayout fromButton = mainView.findViewById(R.id.from_button);
boolean isFollowTrack = mapActivity.getMyApplication().getRoutingHelper().getCurrentGPXRoute() != null;
if (isFollowTrack) {
fromButton.setVisibility(View.GONE);
} else {
fromButton.setVisibility(View.VISIBLE);
}
LinearLayout fromButtonContainer = mainView.findViewById(R.id.from_button_container);
setupButtonBackground(fromButton, fromButtonContainer);
ImageView swapDirectionView = mainView.findViewById(R.id.from_button_image_view);
setupButtonIcon(swapDirectionView, R.drawable.ic_action_change_navigation_points);
fromButton.setOnClickListener(view -> {
MapActivity mapActv = getMapActivity();
if (mapActv != null) {
OsmandApplication app = mapActv.getMyApplication();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
TargetPoint startPoint = targetPointsHelper.getPointToStart();
TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
Location loc = app.getLocationProvider().getLastKnownLocation();
if (loc == null && startPoint == null && endPoint == null) {
app.showShortToastMessage(R.string.add_start_and_end_points);
} else if (endPoint == null) {
app.showShortToastMessage(R.string.mark_final_location_first);
} else {
GPXRouteParamsBuilder gpxParams = app.getRoutingHelper().getCurrentGPXRoute();
if (gpxParams != null) {
boolean reverse = !gpxParams.isReverse();
LocalRoutingParameter parameter = new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route, app.getString(R.string.gpx_option_reverse_route), reverse);
app.getRoutingOptionsHelper().applyRoutingParameter(parameter, reverse);
} else {
if (startPoint == null && loc != null) {
startPoint = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActv.getString(R.string.shared_string_my_location)));
}
if (startPoint != null) {
int intermediateSize = targetPointsHelper.getIntermediatePoints().size();
if (intermediateSize > 1) {
WaypointDialogHelper.reverseAllPoints(app, mapActv, mapActv.getDashboard().getWaypointDialogHelper());
} else {
WaypointDialogHelper.switchStartAndFinish(mapActv.getMyApplication(), mapActv, mapActv.getDashboard().getWaypointDialogHelper(), true);
}
} else {
app.showShortToastMessage(R.string.route_add_start_point);
}
}
}
}
});
updateFromIcon(mainView);
final View textView = mainView.findViewById(R.id.from_button_description);
if (!swapButtonCollapsing && !swapButtonCollapsed && fromButton.getVisibility() == View.VISIBLE && textView.getVisibility() == View.VISIBLE) {
swapButtonCollapsing = true;
collapseButtonAnimated(R.id.from_button, R.id.from_button_description, success -> {
swapButtonCollapsing = false;
swapButtonCollapsed = success;
});
} else if (swapButtonCollapsed) {
textView.setVisibility(View.GONE);
}
}
use of net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder in project Osmand by osmandapp.
the class GpxNavigationHelper method startNavigationForSegment.
public static void startNavigationForSegment(@NonNull GPXFile gpxFile, int selectedSegment, @NonNull MapActivity mapActivity) {
OsmandApplication app = mapActivity.getMyApplication();
app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
startNavigationForGpx(gpxFile, mapActivity);
GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
if (paramsBuilder != null) {
paramsBuilder.setSelectedSegment(selectedSegment);
app.getRoutingHelper().onSettingsChanged(true);
}
}
use of net.osmand.plus.routing.GPXRouteParams.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(new File(gpxPath));
if (f.error != 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_ROUTE_CALC.get()) {
gpxRoute.setCalculateOsmAndRoute(true);
}
if (settings.GPX_ROUTE_SEGMENT.get() != -1) {
gpxRoute.setSelectedSegment(settings.GPX_ROUTE_SEGMENT.get());
}
} 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.GPXRouteParams.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(@Nullable Activity activity, boolean useGpx, final Runnable runnable) {
if (!isRouteAnimating()) {
if (useGpx) {
if (activity == null) {
stop();
if (runnable != null) {
runnable.run();
}
return;
}
boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
ApplicationMode appMode = app.getSettings().getApplicationMode();
int selectedModeColor = appMode.getProfileColor(nightMode);
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity, themeRes));
builder.setTitle(R.string.animate_route);
final View view = activity.getLayoutInflater().inflate(R.layout.animate_route, null);
// $NON-NLS-1$
((TextView) view.findViewById(R.id.MinSpeedup)).setText("1");
// $NON-NLS-1$
((TextView) view.findViewById(R.id.MaxSpeedup)).setText("4");
final Slider speedup = view.findViewById(R.id.Speedup);
speedup.setValueTo(3);
UiUtilities.setupSlider(speedup, nightMode, selectedModeColor, true);
builder.setView(view);
builder.setPositiveButton(R.string.shared_string_ok, (dialog, which) -> {
boolean nightMode1 = activity instanceof MapActivity ? app.getDaynightHelper().isNightModeForMapControls() : !app.getSettings().isLightContent();
GpxUiHelper.selectGPXFile(activity, false, false, result -> {
GPXRouteParamsBuilder gpxParamsBuilder = new GPXRouteParamsBuilder(result[0], app.getSettings());
startAnimationThread(app, gpxParamsBuilder.getPoints(app), true, speedup.getValue() + 1);
if (runnable != null) {
runnable.run();
}
return true;
}, nightMode1);
});
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.show();
} 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();
}
}
}
} else {
stop();
if (runnable != null) {
runnable.run();
}
}
}
Aggregations