use of net.osmand.plus.TargetPointsHelper 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, 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.TargetPointsHelper in project Osmand by osmandapp.
the class MapRouteInfoMenu method generateViaDescription.
public String generateViaDescription() {
TargetPointsHelper targets = getTargets();
List<TargetPoint> points = targets.getIntermediatePointsNavigation();
if (points.size() == 0) {
return "";
}
StringBuilder via = new StringBuilder();
for (int i = 0; i < points.size(); i++) {
if (i > 0) {
via.append(" ");
}
TargetPoint p = points.get(i);
String description = p.getOnlyName();
via.append(getRoutePointDescription(p.point, description));
boolean needAddress = new PointDescription(PointDescription.POINT_TYPE_LOCATION, description).isSearchingAddress(mapActivity) && !intermediateRequestsLatLon.contains(p.point);
if (needAddress) {
AddressLookupRequest lookupRequest = new AddressLookupRequest(p.point, new GeocodingLookupService.OnAddressLookupResult() {
@Override
public void geocodingDone(String address) {
updateMenu();
}
}, null);
intermediateRequestsLatLon.add(p.point);
geocodingLookupService.lookupAddress(lookupRequest);
}
}
return via.toString();
}
use of net.osmand.plus.TargetPointsHelper in project Osmand by osmandapp.
the class MapRouteInfoMenu method updateViaView.
private void updateViaView(final View parentView) {
String via = generateViaDescription();
View viaLayout = parentView.findViewById(R.id.ViaLayout);
View viaLayoutDivider = parentView.findViewById(R.id.viaLayoutDivider);
ImageView swapDirectionView = (ImageView) parentView.findViewById(R.id.swap_direction_image_view);
if (via.length() == 0) {
viaLayout.setVisibility(View.GONE);
viaLayoutDivider.setVisibility(View.GONE);
swapDirectionView.setVisibility(View.VISIBLE);
} else {
swapDirectionView.setVisibility(View.GONE);
viaLayout.setVisibility(View.VISIBLE);
viaLayoutDivider.setVisibility(View.VISIBLE);
((TextView) parentView.findViewById(R.id.ViaView)).setText(via);
}
viaLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getTargets().checkPointToNavigateShort()) {
mapActivity.getMapActions().openIntermediatePointsDialog();
}
}
});
ImageView viaIcon = (ImageView) parentView.findViewById(R.id.viaIcon);
viaIcon.setImageDrawable(getIconOrig(R.drawable.list_intermediate));
swapDirectionView.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_change_navigation_points, isLight() ? R.color.route_info_control_icon_color_light : R.color.route_info_control_icon_color_dark));
swapDirectionView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TargetPointsHelper targetPointsHelper = getTargets();
TargetPoint startPoint = targetPointsHelper.getPointToStart();
TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
if (startPoint == null) {
Location loc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
if (loc != null) {
startPoint = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location)));
}
}
if (startPoint != null && endPoint != null) {
targetPointsHelper.navigateToPoint(startPoint.point, false, -1, startPoint.getPointDescription(mapActivity));
targetPointsHelper.setStartPoint(endPoint.point, false, endPoint.getPointDescription(mapActivity));
targetPointsHelper.updateRouteAndRefresh(true);
updateFromIcon();
updateToIcon(parentView);
}
}
});
}
use of net.osmand.plus.TargetPointsHelper in project Osmand by osmandapp.
the class MapRouteInfoMenu method updateRouteCalcProgress.
private void updateRouteCalcProgress(final View main) {
TargetPointsHelper targets = getTargets();
if (targets.hasTooLongDistanceToNavigate()) {
main.findViewById(R.id.dividerToDropDown).setVisibility(View.VISIBLE);
main.findViewById(R.id.RouteInfoControls).setVisibility(View.VISIBLE);
TextView textView = (TextView) main.findViewById(R.id.InfoTextView);
ImageView iconView = (ImageView) main.findViewById(R.id.InfoIcon);
main.findViewById(R.id.Prev).setVisibility(View.GONE);
main.findViewById(R.id.Next).setVisibility(View.GONE);
main.findViewById(R.id.InfoIcon).setVisibility(View.GONE);
main.findViewById(R.id.DurationIcon).setVisibility(View.GONE);
main.findViewById(R.id.InfoDistance).setVisibility(View.GONE);
main.findViewById(R.id.InfoDuration).setVisibility(View.GONE);
textView.setText(R.string.route_is_too_long_v2);
textView.setVisibility(View.VISIBLE);
iconView.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_warning, isLight()));
} else {
main.findViewById(R.id.dividerToDropDown).setVisibility(View.GONE);
main.findViewById(R.id.RouteInfoControls).setVisibility(View.GONE);
}
}
use of net.osmand.plus.TargetPointsHelper in project Osmand by osmandapp.
the class MapRouteInfoMenu method updateFromSpinner.
private void updateFromSpinner(final View parentView) {
final TargetPointsHelper targets = getTargets();
final Spinner fromSpinner = setupFromSpinner(parentView);
fromSpinner.setClickable(false);
final View fromLayout = parentView.findViewById(R.id.FromLayout);
fromSpinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
event.offsetLocation(AndroidUtils.dpToPx(mapActivity, 48f), 0);
fromLayout.onTouchEvent(event);
return true;
}
});
fromSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, final long id) {
parentView.post(new Runnable() {
@Override
public void run() {
if (id == SPINNER_MY_LOCATION_ID) {
if (targets.getPointToStart() != null) {
targets.clearStartPoint(true);
mapActivity.getMyApplication().getSettings().backupPointToStart();
}
updateFromIcon(parentView);
} else if (id == SPINNER_FAV_ID) {
selectFavorite(parentView, false, false);
} else if (id == SPINNER_MAP_ID) {
selectOnScreen(false, false);
} else if (id == SPINNER_ADDRESS_ID) {
mapActivity.showQuickSearch(MapActivity.ShowQuickSearchMode.START_POINT_SELECTION, false);
setupFromSpinner(parentView);
} else if (id == SPINNER_MAP_MARKER_MORE_ID) {
selectMapMarker(-1, false, false);
setupFromSpinner(parentView);
} else if (id == SPINNER_MAP_MARKER_1_ID) {
selectMapMarker(0, false, false);
} else if (id == SPINNER_MAP_MARKER_2_ID) {
selectMapMarker(1, false, false);
} else if (id == SPINNER_MAP_MARKER_3_ID) {
selectMapMarker(2, false, false);
}
}
});
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
fromLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fromSpinner.performClick();
}
});
updateFromIcon(parentView);
ImageView fromDropDownIcon = (ImageView) parentView.findViewById(R.id.fromDropDownIcon);
fromDropDownIcon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, isLight()));
}
Aggregations