use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class PlanRouteFragment method createOptionsFragmentListener.
private PlanRouteOptionsFragmentListener createOptionsFragmentListener() {
return new PlanRouteOptionsFragmentListener() {
private MapActivity mapActivity = getMapActivity();
@Override
public void selectOnClick() {
selectAllOnClick();
}
@Override
public void navigateOnClick() {
if (mapActivity != null) {
boolean hasTargets = false;
TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
List<MapMarker> markers = markersHelper.getSelectedMarkers();
if (markers.size() > 0) {
int i = 0;
if (markersHelper.isStartFromMyLocation()) {
targetPointsHelper.clearStartPoint(false);
} else {
MapMarker m = markers.get(i++);
targetPointsHelper.setStartPoint(new LatLon(m.getLatitude(), m.getLongitude()), false, m.getPointDescription(mapActivity));
}
List<TargetPoint> targetPoints = new ArrayList<>();
for (int k = i; k < markers.size(); k++) {
MapMarker m = markers.get(k);
TargetPoint t = new TargetPoint(new LatLon(m.getLatitude(), m.getLongitude()), m.getPointDescription(mapActivity));
targetPoints.add(t);
}
if (mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get()) {
TargetPoint end = targetPointsHelper.getPointToStart();
if (end == null) {
Location loc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
if (loc != null) {
end = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location)));
}
}
if (end != null) {
targetPoints.add(end);
}
}
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
boolean updateRoute = routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode();
targetPointsHelper.reorderAllTargetPoints(targetPoints, updateRoute);
hasTargets = true;
} else {
targetPointsHelper.clearStartPoint(false);
targetPointsHelper.clearPointToNavigate(false);
}
planRouteContext.setNavigationFromMarkers(true);
dismiss();
mapActivity.getMapLayers().getMapControlsLayer().doRoute(hasTargets);
}
}
@Override
public void makeRoundTripOnClick() {
roundTripOnClick();
}
@Override
public void doorToDoorOnClick() {
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
Location myLoc = app.getLocationProvider().getLastStaleKnownLocation();
boolean startFromLocation = app.getMapMarkersHelper().isStartFromMyLocation() && myLoc != null;
if (selectedCount > (startFromLocation ? 0 : 1)) {
sortSelectedMarkersDoorToDoor(mapActivity, startFromLocation, myLoc);
}
}
}
@Override
public void reverseOrderOnClick() {
if (mapActivity != null) {
markersHelper.reverseActiveMarkersOrder();
adapter.reloadData();
adapter.notifyDataSetChanged();
planRouteContext.recreateSnapTrkSegment(false);
}
}
};
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint 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.helpers.TargetPointsHelper.TargetPoint 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.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class DashWaypointsFragment method selectTargetModel.
private void selectTargetModel(final TargetPoint point, final View view) {
final OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
final UiUtilities iconsCache = app.getUIUtilities();
final PopupMenu optionsMenu = new PopupMenu(requireActivity(), view);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
MenuItem item;
final boolean target = point == app.getTargetPointsHelper().getPointToNavigate();
if (SHOW_ALL && app.getTargetPointsHelper().getIntermediatePoints().size() > 0) {
final List<TargetPoint> allTargets = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
if (point.index > 0 || target) {
final int ind = target ? allTargets.size() - 1 : point.index;
item = optionsMenu.getMenu().add(R.string.waypoint_visit_before).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_up_dark));
item.setOnMenuItemClickListener(menuItem -> {
TargetPoint remove = allTargets.remove(ind - 1);
allTargets.add(ind, remove);
app.getTargetPointsHelper().reorderAllTargetPoints(allTargets, true);
setupView();
return true;
});
}
if (!target) {
item = optionsMenu.getMenu().add(R.string.waypoint_visit_after).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_down_dark));
item.setOnMenuItemClickListener(menuItem -> {
TargetPoint remove = allTargets.remove(point.index + 1);
allTargets.add(point.index, remove);
app.getTargetPointsHelper().reorderAllTargetPoints(allTargets, true);
setupView();
return true;
});
}
}
item = optionsMenu.getMenu().add(R.string.shared_string_remove).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
item.setOnMenuItemClickListener(menuItem -> {
deletePointConfirm(point, view);
return true;
});
optionsMenu.show();
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class MenuController method getMenuController.
public static MenuController getMenuController(@NonNull MapActivity mapActivity, @NonNull LatLon latLon, @NonNull PointDescription pointDescription, @Nullable Object object, @NonNull MenuType menuType) {
MenuController menuController = null;
if (object != null) {
if (object instanceof Amenity) {
menuController = new AmenityMenuController(mapActivity, pointDescription, (Amenity) object);
} else if (object instanceof FavouritePoint) {
if (pointDescription.isParking() || (FavouritePoint.SpecialPointType.PARKING.equals(((FavouritePoint) object).getSpecialPointType()))) {
menuController = new ParkingPositionMenuController(mapActivity, pointDescription, (FavouritePoint) object);
} else {
menuController = new FavouritePointMenuController(mapActivity, pointDescription, (FavouritePoint) object);
}
} else if (object instanceof SearchHistoryHelper.HistoryEntry) {
menuController = new HistoryMenuController(mapActivity, pointDescription, (SearchHistoryHelper.HistoryEntry) object);
} else if (object instanceof TargetPoint) {
menuController = new TargetPointMenuController(mapActivity, pointDescription, (TargetPoint) object);
} else if (object instanceof Recording) {
menuController = new AudioVideoNoteMenuController(mapActivity, pointDescription, (Recording) object);
} else if (object instanceof OsmPoint) {
menuController = new EditPOIMenuController(mapActivity, pointDescription, (OsmPoint) object);
} else if (object instanceof WptPt) {
menuController = WptPtMenuController.getInstance(mapActivity, pointDescription, (WptPt) object);
} else if (object instanceof DownloadMapObject) {
menuController = new MapDataMenuController(mapActivity, pointDescription, (DownloadMapObject) object);
} else if (object instanceof OpenStreetNote) {
menuController = new OsmBugMenuController(mapActivity, pointDescription, (OpenStreetNote) object);
} else if (object instanceof GpxDisplayItem) {
menuController = new GpxItemMenuController(mapActivity, pointDescription, (GpxDisplayItem) object);
} else if (object instanceof MapMarker) {
menuController = new MapMarkerMenuController(mapActivity, pointDescription, (MapMarker) object);
} else if (object instanceof TransportStopRoute) {
menuController = new TransportRouteController(mapActivity, pointDescription, (TransportStopRoute) object);
} else if (object instanceof TransportStop) {
menuController = new TransportStopController(mapActivity, pointDescription, (TransportStop) object);
} else if (object instanceof AidlMapPointWrapper) {
menuController = new AMapPointMenuController(mapActivity, pointDescription, (AidlMapPointWrapper) object);
} else if (object instanceof LatLon) {
if (pointDescription.isMyLocation()) {
menuController = new MyLocationMenuController(mapActivity, pointDescription);
}
} else if (object instanceof AvoidSpecificRoads.AvoidRoadInfo) {
menuController = new ImpassibleRoadsMenuController(mapActivity, pointDescription, (AvoidSpecificRoads.AvoidRoadInfo) object);
} else if (object instanceof RenderedObject) {
menuController = new RenderedObjectMenuController(mapActivity, pointDescription, (RenderedObject) object);
} else if (object instanceof MapillaryImage) {
menuController = new MapillaryMenuController(mapActivity, pointDescription, (MapillaryImage) object);
} else if (object instanceof SelectedGpxPoint) {
menuController = new SelectedGpxMenuController(mapActivity, pointDescription, (SelectedGpxPoint) object);
} else if (object instanceof Pair && ((Pair<?, ?>) object).second instanceof SelectedGpxPoint) {
menuController = new SelectedGpxMenuController(mapActivity, pointDescription, (SelectedGpxPoint) ((Pair<?, ?>) object).second);
}
}
if (menuController == null) {
menuController = new PointDescriptionMenuController(mapActivity, pointDescription);
}
menuController.menuType = menuType;
menuController.setLatLon(latLon);
menuController.onCreated();
return menuController;
}
Aggregations