use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class RouteDetailsFragment method buildStartItem.
private void buildStartItem(@NonNull View view, final TargetPoint start, int[] startTime, final TransportRouteResultSegment segment, double walkSpeed) {
OsmandApplication app = requireMyApplication();
FrameLayout baseItemView = new FrameLayout(view.getContext());
LinearLayout imagesContainer = (LinearLayout) createImagesContainer(view.getContext());
baseItemView.addView(imagesContainer);
LinearLayout infoContainer = (LinearLayout) createInfoContainer(view.getContext());
baseItemView.addView(infoContainer);
String name;
if (start != null) {
name = start.getOnlyName().length() > 0 ? start.getOnlyName() : (getString(R.string.route_descr_map_location) + " " + getRoutePointDescription(start.getLatitude(), start.getLongitude()));
} else {
name = getString(R.string.shared_string_my_location);
}
Spannable startTitle = new SpannableString(name);
String text = OsmAndFormatter.getFormattedDurationShortMinutes(startTime[0]);
int drawableId = start == null ? R.drawable.ic_action_location_color : R.drawable.list_startpoint;
Drawable icon = app.getUIUtilities().getIcon(drawableId);
buildStartRow(infoContainer, icon, text, startTitle, imagesContainer, new OnClickListener() {
@Override
public void onClick(View v) {
showLocationOnMap(start != null ? start.point : null);
}
});
addWalkRouteIcon(imagesContainer);
buildRowDivider(infoContainer, true);
double walkDist = (long) getWalkDistance(null, segment, segment.walkDist);
int walkTime = (int) getWalkTime(null, segment, walkDist, walkSpeed);
if (walkTime < 60) {
walkTime = 60;
}
startTime[0] += walkTime;
SpannableStringBuilder title = new SpannableStringBuilder(Algorithms.capitalizeFirstLetter(getString(R.string.shared_string_walk)));
title.setSpan(new ForegroundColorSpan(getSecondaryColor()), 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int startIndex = title.length();
title.append(" ").append(OsmAndFormatter.getFormattedDuration(walkTime, app));
title.setSpan(new CustomTypefaceSpan(FontCache.getRobotoMedium(app)), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
startIndex = title.length();
title.append(", ").append(OsmAndFormatter.getFormattedDistance((float) walkDist, app));
title.setSpan(new ForegroundColorSpan(getSecondaryColor()), startIndex, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
buildWalkRow(infoContainer, title, imagesContainer, new OnClickListener() {
@Override
public void onClick(View v) {
showWalkingRouteOnMap(null, segment);
}
});
buildRowDivider(infoContainer, true);
((ViewGroup) view).addView(baseItemView);
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class RouteInfoWidgetsFactory method createIntermediateDistanceControl.
public TextInfoWidget createIntermediateDistanceControl(final MapActivity map) {
final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper();
DistanceToPointWidget distanceControl = new DistanceToPointWidget(map, R.drawable.widget_intermediate_day, R.drawable.widget_intermediate_night) {
@Override
protected void click(OsmandMapTileView view) {
if (targets.getIntermediatePoints().size() > 1) {
map.getMapActions().openIntermediatePointsDialog();
} else {
super.click(view);
}
}
@Override
public LatLon getPointToNavigate() {
TargetPoint p = targets.getFirstIntermediatePoint();
return p == null ? null : p.point;
}
@Override
public int getDistance() {
if (getPointToNavigate() != null && map.getRoutingHelper().isRouteCalculated()) {
return map.getRoutingHelper().getLeftDistanceNextIntermediate();
}
return super.getDistance();
}
};
return distanceControl;
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class SearchScreen method reloadHistoryInternal.
private void reloadHistoryInternal() {
if (!destroyed) {
OsmandApplication app = getApp();
try {
List<SearchResult> recentResults = new ArrayList<>();
// Home / work
/* Disable since points exists at favorites screen
FavouritesDbHelper favorites = app.getFavorites();
FavouritePoint homePoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.HOME);
FavouritePoint workPoint = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.WORK);
if (homePoint != null) {
SearchResult result = new SearchResult();
result.location = new LatLon(homePoint.getLatitude(), homePoint.getLongitude());
result.objectType = ObjectType.FAVORITE;
result.object = homePoint;
result.localeName = homePoint.getAddress();
recentResults.add(result);
}
if (workPoint != null) {
SearchResult result = new SearchResult();
result.location = new LatLon(workPoint.getLatitude(), workPoint.getLongitude());
result.objectType = ObjectType.FAVORITE;
result.object = workPoint;
result.localeName = workPoint.getAddress();
recentResults.add(result);
}
*/
// Previous route card
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
TargetPoint startPoint = targetPointsHelper.getPointToStartBackup();
boolean myLocation = false;
if (startPoint == null) {
myLocation = true;
startPoint = targetPointsHelper.getMyLocationToStart();
}
TargetPoint destinationPoint = targetPointsHelper.getPointToNavigateBackup();
if (startPoint != null && destinationPoint != null) {
StringBuilder startText = new StringBuilder(myLocation ? app.getText(R.string.my_location) : "");
String startDescr = getPointName(startPoint);
if (!Algorithms.isEmpty(startDescr)) {
if (startText.length() > 0) {
startText.append(" — ");
}
startText.append(startDescr);
}
String destDescr = getPointName(destinationPoint);
SearchResult result = new SearchResult();
result.location = new LatLon(destinationPoint.getLatitude(), destinationPoint.getLongitude());
result.objectType = ObjectType.ROUTE;
result.object = destinationPoint;
result.localeName = destDescr;
result.relatedObject = startPoint;
result.localeRelatedObjectName = startText.toString();
recentResults.add(result);
}
// Map markers
List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
int mapMarkersCount = 0;
for (MapMarker marker : mapMarkers) {
SearchResult result = new SearchResult();
result.location = new LatLon(marker.getLatitude(), marker.getLongitude());
result.objectType = ObjectType.MAP_MARKER;
result.object = marker;
result.localeName = marker.getName(app);
recentResults.add(result);
mapMarkersCount++;
if (mapMarkersCount >= MAP_MARKERS_LIMIT) {
break;
}
}
// History
SearchResultCollection res = getSearchUICore().shallowSearch(SearchHistoryAPI.class, "", null, false, false);
if (res != null) {
recentResults.addAll(res.getCurrentSearchResults());
}
this.recentResults = recentResults;
if (!searchHelper.isSearching() && Algorithms.isEmpty(searchHelper.getSearchQuery())) {
showRecents();
invalidate();
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
app.showToastMessage(e.getMessage());
}
}
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class DestinationReachedMenuFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
MapActivity mapActivity = getMapActivity();
if (mapActivity == null || menu == null) {
return null;
}
ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, menu.isLight() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
LayoutInflater inf = LayoutInflater.from(ctx);
View view = inf.inflate(R.layout.dest_reached_menu_fragment, container, false);
AndroidUtils.addStatusBarPadding21v(ctx, view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finishNavigation();
}
});
UiUtilities iconsCache = mapActivity.getMyApplication().getUIUtilities();
ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight()));
closeImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finishNavigation();
}
});
Button removeDestButton = (Button) view.findViewById(R.id.removeDestButton);
removeDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_done, menu.isLight()), null, null, null);
removeDestButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finishNavigation();
}
});
Button recalcDestButton = (Button) view.findViewById(R.id.recalcDestButton);
recalcDestButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_gdirections_dark, menu.isLight()), null, null, null);
recalcDestButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
TargetPointsHelper helper = mapActivity.getMyApplication().getTargetPointsHelper();
TargetPoint target = helper.getPointToNavigate();
dismissMenu();
if (target != null) {
helper.navigateToPoint(new LatLon(target.getLatitude(), target.getLongitude()), true, -1, target.getOriginalPointDescription());
mapActivity.getMapActions().recalculateRoute(false);
mapActivity.getMapLayers().getMapControlsLayer().startNavigation();
}
}
}
});
Button findParkingButton = (Button) view.findViewById(R.id.findParkingButton);
ApplicationMode appMode = mapActivity.getMyApplication().getRoutingHelper().getAppMode();
if (!appMode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
findParkingButton.setVisibility(View.GONE);
}
findParkingButton.setCompoundDrawablesWithIntrinsicBounds(iconsCache.getIcon(R.drawable.ic_action_parking_dark, menu.isLight()), null, null, null);
findParkingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
PoiFiltersHelper helper = mapActivity.getMyApplication().getPoiFilters();
PoiUIFilter parkingFilter = helper.getFilterById(PoiUIFilter.STD_PREFIX + "parking");
mapActivity.showQuickSearch(parkingFilter);
}
dismissMenu();
}
});
View mainView = view.findViewById(R.id.main_view);
if (menu.isLandscapeLayout()) {
AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_left_menu_light, R.drawable.bg_left_menu_dark);
} else {
AndroidUtils.setBackground(view.getContext(), mainView, !menu.isLight(), R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
}
return view;
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class DestinationReachedMenuFragment method finishNavigation.
private void finishNavigation() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMyApplication().getTargetPointsHelper().removeWayPoint(true, -1);
Object contextMenuObj = mapActivity.getContextMenu().getObject();
if (mapActivity.getContextMenu().isActive() && contextMenuObj instanceof TargetPoint) {
TargetPoint targetPoint = (TargetPoint) contextMenuObj;
if (!targetPoint.start && !targetPoint.intermediate) {
mapActivity.getContextMenu().close();
}
}
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
settings.setApplicationMode(settings.DEFAULT_APPLICATION_MODE.get());
mapActivity.getMapActions().stopNavigationWithoutConfirm();
dismissMenu();
}
}
Aggregations