use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class MapRouteInfoMenu method updateCards.
private void updateCards() {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
OsmandApplication app = mapActivity.getMyApplication();
nightMode = app.getDaynightHelper().isNightModeForMapControls();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
RoutingHelper routingHelper = app.getRoutingHelper();
boolean hasPrecalculatedMissingMaps = hasPrecalculatedMissingMaps();
boolean hasCalculatedMissingMaps = hasCalculatedMissingMaps(app);
List<BaseCard> menuCards = new ArrayList<>();
boolean bottomShadowVisible = true;
if (isBasicRouteCalculated()) {
GPXFile gpx = GpxUiHelper.makeGpxFromRoute(routingHelper.getRoute(), app);
SimpleRouteCard simpleRouteCard = new SimpleRouteCard(mapActivity, gpx);
simpleRouteCard.setListener(this);
menuCards.add(simpleRouteCard);
bottomShadowVisible = false;
} else if (isTransportRouteCalculated()) {
TransportRoutingHelper transportRoutingHelper = app.getTransportRoutingHelper();
List<TransportRouteResult> routes = transportRoutingHelper.getRoutes();
if (routes != null && routes.size() > 0) {
TransportRouteResult route = routes.get(0);
int walkTimeReal = transportRoutingHelper.getWalkingTime(route.getSegments());
int walkTimePT = (int) route.getWalkTime();
int walkTime = walkTimeReal > 0 ? walkTimeReal : walkTimePT;
int travelTime = (int) route.getTravelTime() + walkTime;
LatLon startLocation = transportRoutingHelper.getStartLocation();
LatLon endLocation = transportRoutingHelper.getEndLocation();
int approxPedestrianTime = (int) MapUtils.getDistance(startLocation, endLocation);
boolean showPedestrianCard = approxPedestrianTime < travelTime + 60 && approxPedestrianTime < MAX_PEDESTRIAN_ROUTE_DURATION;
boolean hasTopCard = false;
if (routes.size() > 1 && routeSelected) {
int currentRoute = app.getTransportRoutingHelper().getCurrentRoute();
if (currentRoute >= 0 && currentRoute < routes.size()) {
route = routes.get(currentRoute);
PublicTransportCard card = new PublicTransportCard(mapActivity, startLocation, endLocation, route, currentRoute);
card.setRouteInfoVisible(false);
card.setRouteButtonsVisible(false);
card.setShowBottomShadow(false);
card.setShowTopShadow(false);
card.setListener(this);
menuCards.add(card);
hasTopCard = true;
}
}
for (int i = 0; i < routes.size(); i++) {
route = routes.get(i);
PublicTransportCard card = new PublicTransportCard(mapActivity, startLocation, endLocation, route, i);
card.setShowButtonCustomTitle(mapActivity.getString(R.string.shared_string_show_on_map));
card.setShowBottomShadow(i == routes.size() - 1 && !showPedestrianCard);
card.setShowTopShadow(i != 0 || hasTopCard);
card.setListener(this);
menuCards.add(card);
}
if (showPedestrianCard) {
PedestrianRouteCard pedestrianRouteCard = new PedestrianRouteCard(mapActivity, approxPedestrianTime);
pedestrianRouteCard.setListener(this);
menuCards.add(pedestrianRouteCard);
}
bottomShadowVisible = routes.size() == 0;
} else {
RouteMenuAppModes mode = app.getRoutingOptionsHelper().getRouteMenuAppMode(routingHelper.getAppMode());
boolean avoidPTTypesCustomized = false;
for (LocalRoutingParameter parameter : mode.parameters) {
if (parameter instanceof AvoidPTTypesRoutingParameter) {
avoidPTTypesCustomized = true;
break;
}
}
if (avoidPTTypesCustomized) {
PublicTransportNotFoundSettingsWarningCard warningCard = new PublicTransportNotFoundSettingsWarningCard(mapActivity);
warningCard.setListener(this);
menuCards.add(warningCard);
} else {
PublicTransportNotFoundWarningCard warningCard = new PublicTransportNotFoundWarningCard(mapActivity);
warningCard.setListener(this);
menuCards.add(warningCard);
}
}
} else if (routeCalculationInProgress) {
if (app.getRoutingHelper().isPublicTransportMode()) {
menuCards.add(new PublicTransportBetaWarningCard(mapActivity));
} else if (app.getRoutingHelper().isBoatMode()) {
menuCards.add(new NauticalBridgeHeightWarningCard(mapActivity));
} else if (hasPrecalculatedMissingMaps || suggestedMapsOnlineSearch) {
menuCards.add(new SuggestionsMapsDownloadWarningCard(mapActivity));
} else if (app.getTargetPointsHelper().hasTooLongDistanceToNavigate() && !hasCalculatedMissingMaps) {
menuCards.add(new LongDistanceWarningCard(mapActivity));
}
} else {
if (hasCalculatedMissingMaps) {
menuCards.add(new SuggestionsMapsDownloadWarningCard(mapActivity));
} else {
// Home/work card
HomeWorkCard homeWorkCard = new HomeWorkCard(mapActivity);
menuCards.add(homeWorkCard);
// Previous route card
boolean historyEnabled = app.getSettings().NAVIGATION_HISTORY.get();
if (historyEnabled) {
TargetPoint startBackup = targetPointsHelper.getPointToStartBackup();
if (startBackup == null) {
startBackup = targetPointsHelper.getMyLocationToStart();
}
TargetPoint destinationBackup = targetPointsHelper.getPointToNavigateBackup();
if (startBackup != null && destinationBackup != null) {
PreviousRouteCard previousRouteCard = new PreviousRouteCard(mapActivity);
previousRouteCard.setListener(this);
menuCards.add(previousRouteCard);
}
}
// Gpx card
List<SelectedGpxFile> selectedGPXFiles = app.getSelectedGpxHelper().getSelectedGPXFiles();
final List<GPXFile> gpxFiles = new ArrayList<>();
for (SelectedGpxFile gs : selectedGPXFiles) {
if (!gs.isShowCurrentTrack()) {
if (gs.getGpxFile().hasRtePt() || gs.getGpxFile().hasTrkPt()) {
gpxFiles.add(gs.getGpxFile());
}
}
}
if (gpxFiles.size() > 0) {
TracksCard tracksCard = new TracksCard(mapActivity, gpxFiles);
tracksCard.setListener(this);
menuCards.add(tracksCard);
}
// Map markers card
List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
if (mapMarkers.size() > 0) {
MapMarkersCard mapMarkersCard = new MapMarkersCard(mapActivity, mapMarkers);
menuCards.add(mapMarkersCard);
}
// History card
if (historyEnabled) {
try {
SearchResultCollection res = app.getSearchUICore().getCore().shallowSearch(SearchHistoryAPI.class, "", null, false, false);
if (res != null) {
List<SearchResult> results = res.getCurrentSearchResults();
if (results.size() > 0) {
HistoryCard historyCard = new HistoryCard(mapActivity, results);
historyCard.setListener(this);
menuCards.add(historyCard);
}
}
} catch (IOException e) {
LOG.error(e);
}
}
}
}
applyCardsState(menuCards, this.menuCards);
this.menuCards = menuCards;
setBottomShadowVisible(bottomShadowVisible);
setupCards();
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class MapRouteInfoMenu method generateViaDescription.
public String generateViaDescription() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
TargetPointsHelper targets = app.getTargetPointsHelper();
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, address -> updateMenu(), null);
intermediateRequestsLatLon.add(p.point);
app.getGeocodingLookupService().lookupAddress(lookupRequest);
}
}
return via.toString();
}
return "";
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class RouteDetailsFragment method buildDestinationItem.
private void buildDestinationItem(@NonNull View view, final TargetPoint destination, int[] startTime, final TransportRouteResultSegment segment, double walkSpeed) {
OsmandApplication app = requireMyApplication();
Typeface typeface = FontCache.getRobotoMedium(app);
FrameLayout baseItemView = new FrameLayout(view.getContext());
LinearLayout imagesContainer = (LinearLayout) createImagesContainer(view.getContext());
baseItemView.addView(imagesContainer);
LinearLayout infoContainer = (LinearLayout) createInfoContainer(view.getContext());
baseItemView.addView(infoContainer);
buildRowDivider(infoContainer, true);
double walkDist = (long) getWalkDistance(segment, null, segment.walkDist);
int walkTime = (int) getWalkTime(segment, null, walkDist, walkSpeed);
if (walkTime < 60) {
walkTime = 60;
}
SpannableStringBuilder spannable = new SpannableStringBuilder(getString(R.string.shared_string_walk)).append(" ");
spannable.setSpan(new ForegroundColorSpan(getSecondaryColor()), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int startIndex = spannable.length();
spannable.append("~").append(OsmAndFormatter.getFormattedDuration(walkTime, app));
spannable.setSpan(new CustomTypefaceSpan(typeface), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
startIndex = spannable.length();
spannable.append(", ").append(OsmAndFormatter.getFormattedDistance((float) walkDist, app));
spannable.setSpan(new ForegroundColorSpan(getSecondaryColor()), startIndex, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
buildWalkRow(infoContainer, spannable, imagesContainer, new OnClickListener() {
@Override
public void onClick(View v) {
showWalkingRouteOnMap(segment, null);
}
});
buildRowDivider(infoContainer, true);
addWalkRouteIcon(imagesContainer);
String timeStr = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0] + walkTime);
String name = getRoutePointDescription(destination.point, destination.getOnlyName());
SpannableString title = new SpannableString(name);
title.setSpan(new CustomTypefaceSpan(typeface), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
title.setSpan(new ForegroundColorSpan(getActiveColor()), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableString secondaryText = new SpannableString(getString(R.string.route_descr_destination));
secondaryText.setSpan(new CustomTypefaceSpan(typeface), 0, secondaryText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
secondaryText.setSpan(new ForegroundColorSpan(getMainFontColor()), 0, secondaryText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
buildDestinationRow(infoContainer, timeStr, title, secondaryText, destination.point, imagesContainer, new OnClickListener() {
@Override
public void onClick(View v) {
showLocationOnMap(destination.point);
}
});
((ViewGroup) view).addView(baseItemView);
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class AddPointBottomSheetDialog method createSwitchStartAndEndItem.
private void createSwitchStartAndEndItem() {
final View switchStartAndEndView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_simple_56dp, null);
TextView title = (TextView) switchStartAndEndView.findViewById(R.id.title);
String start = getString(R.string.route_start_point);
String destination = getString(R.string.route_descr_destination);
String titleS = getString(R.string.swap_two_places, start, destination);
SpannableString titleSpan = new SpannableString(titleS);
int startIndex = titleS.indexOf(start);
int destinationIndex = titleS.indexOf(destination);
if (startIndex != -1 && destinationIndex != -1) {
Typeface typeface = FontCache.getRobotoMedium(getContext());
titleSpan.setSpan(new CustomTypefaceSpan(typeface), startIndex, startIndex + start.length(), 0);
titleSpan.setSpan(new CustomTypefaceSpan(typeface), destinationIndex, destinationIndex + destination.length(), 0);
}
title.setText(titleSpan);
BaseBottomSheetItem switchStartAndEndItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_change_navigation_points)).setCustomView(switchStartAndEndView).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
TargetPointsHelper targetsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
TargetPoint startPoint = targetsHelper.getPointToStart();
if (startPoint == null) {
mapActivity.getMyApplication().showShortToastMessage(R.string.route_add_start_point);
return;
}
WaypointDialogHelper.switchStartAndFinish(mapActivity.getMyApplication(), mapActivity, mapActivity.getDashboard().getWaypointDialogHelper(), true);
}
dismiss();
}
}).create();
items.add(switchStartAndEndItem);
}
Aggregations