use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class MapRouteInfoMenu method setupFromText.
private void setupFromText(View view) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
TargetPoint start = mapActivity.getMyApplication().getTargetPointsHelper().getPointToStart();
String name = null;
if (start != null) {
name = start.getOnlyName().length() > 0 ? start.getOnlyName() : (mapActivity.getString(R.string.route_descr_map_location) + " " + getRoutePointDescription(start.getLatitude(), start.getLongitude()));
final LatLon latLon = start.point;
final PointDescription pointDescription = start.getOriginalPointDescription();
boolean needAddress = pointDescription != null && pointDescription.isSearchingAddress(mapActivity);
cancelStartPointAddressRequest();
if (needAddress) {
startPointRequest = new AddressLookupRequest(latLon, address -> {
startPointRequest = null;
updateMenu();
}, null);
mapActivity.getMyApplication().getGeocodingLookupService().lookupAddress(startPointRequest);
}
}
final TextView fromText = view.findViewById(R.id.fromText);
if (start != null) {
fromText.setText(name);
} else {
if (OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
fromText.setText(R.string.shared_string_my_location);
} else {
fromText.setText(R.string.route_descr_select_start_point);
}
}
}
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class MapRouteInfoMenu method isFinishPointFromTrack.
private boolean isFinishPointFromTrack() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
GPXRouteParamsBuilder routeParams = app.getRoutingHelper().getCurrentGPXRoute();
if (routeParams != null) {
TargetPoint target = app.getTargetPointsHelper().getPointToNavigate();
if (target != null) {
List<Location> points = routeParams.getPoints(app);
if (!Algorithms.isEmpty(points)) {
Location loc = points.get(points.size() - 1);
LatLon latLon = new LatLon(loc.getLatitude(), loc.getLongitude());
LatLon targetLatLon = new LatLon(target.getLatitude(), target.getLongitude());
return latLon.equals(targetLatLon);
}
}
}
}
return false;
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class WaypointsFragment method updatePointInfoView.
private static void updatePointInfoView(final MapActivity mapActivity, View localView, final LocationPointWrapper ps, final boolean mapCenter, final boolean nightMode, final boolean edit, final boolean topBar) {
final OsmandApplication app = mapActivity.getMyApplication();
WaypointHelper wh = mapActivity.getMyApplication().getWaypointHelper();
final LocationPoint point = ps.getPoint();
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
if (!topBar) {
text.setTextColor(ColorUtilities.getPrimaryTextColor(mapActivity, nightMode));
}
TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
if (!edit) {
localView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showOnMap(app, mapActivity, point, mapCenter);
}
});
}
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
textDist.setTextColor(ColorUtilities.getActiveColor(mapActivity, nightMode));
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(mapActivity, app, nightMode));
int dist = -1;
boolean startPoint = ps.type == WaypointHelper.TARGETS && ((TargetPoint) ps.point).start;
if (!startPoint) {
if (!wh.isRouteCalculated()) {
dist = (int) MapUtils.getDistance(mapActivity.getMapView().getLatitude(), mapActivity.getMapView().getLongitude(), point.getLatitude(), point.getLongitude());
} else {
dist = wh.getRouteDistance(ps);
}
}
if (dist > 0) {
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
} else {
textDist.setText("");
}
TextView textDeviation = (TextView) localView.findViewById(R.id.waypoint_deviation);
if (textDeviation != null) {
if (dist > 0 && ps.deviationDistance > 0) {
String devStr = "+" + OsmAndFormatter.getFormattedDistance(ps.deviationDistance, app);
textDeviation.setText(devStr);
if (!topBar) {
int colorId = R.color.description_font_and_bottom_sheet_icons;
textDeviation.setTextColor(ContextCompat.getColor(app, R.color.description_font_and_bottom_sheet_icons));
if (ps.deviationDirectionRight) {
textDeviation.setCompoundDrawablesWithIntrinsicBounds(app.getUIUtilities().getIcon(R.drawable.ic_small_turn_right, colorId), null, null, null);
} else {
textDeviation.setCompoundDrawablesWithIntrinsicBounds(app.getUIUtilities().getIcon(R.drawable.ic_small_turn_left, colorId), null, null, null);
}
}
textDeviation.setVisibility(View.VISIBLE);
} else {
textDeviation.setText("");
textDeviation.setVisibility(View.GONE);
}
}
String descr;
PointDescription pd = point.getPointDescription(app);
if (Algorithms.isEmpty(pd.getName())) {
descr = pd.getTypeName();
} else {
descr = pd.getName();
}
if (textShadow != null) {
textShadow.setText(descr);
}
text.setText(descr);
String pointDescription = "";
TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
if (descText != null) {
descText.setTextColor(ContextCompat.getColor(app, R.color.description_font_and_bottom_sheet_icons));
switch(ps.type) {
case WaypointHelper.TARGETS:
TargetPoint targetPoint = (TargetPoint) ps.point;
if (targetPoint.start) {
pointDescription = mapActivity.getResources().getString(R.string.starting_point);
} else {
pointDescription = getPointDescription(mapActivity, targetPoint).getTypeName();
}
break;
case WaypointHelper.FAVORITES:
FavouritePoint favPoint = (FavouritePoint) ps.point;
pointDescription = Algorithms.isEmpty(favPoint.getCategory()) ? mapActivity.getResources().getString(R.string.shared_string_favorites) : favPoint.getCategory();
break;
}
}
if (Algorithms.objectEquals(descr, pointDescription)) {
pointDescription = "";
}
if (dist > 0 && !Algorithms.isEmpty(pointDescription)) {
pointDescription = " • " + pointDescription;
}
if (descText != null) {
descText.setText(pointDescription);
}
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class WaypointsFragment method getWaypointsDrawerAdapter.
public StableArrayAdapter getWaypointsDrawerAdapter(final boolean edit, final List<LocationPointWrapper> deletedPoints, final MapActivity ctx, final int[] running, final boolean flat, final boolean nightMode) {
final WaypointDialogHelper waypointDialogHelper = ctx.getDashboard().getWaypointDialogHelper();
List<Object> points = waypointDialogHelper.getTargetPoints();
List<Object> activePoints = waypointDialogHelper.getActivePoints(points);
final StableArrayAdapter listAdapter = new StableArrayAdapter(ctx, R.layout.route_waypoint_item, R.id.waypoint_text, points, activePoints) {
@NonNull
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
View v = convertView;
Object obj = getItem(position);
if (obj instanceof LocationPointWrapper) {
LocationPointWrapper point = (LocationPointWrapper) obj;
v = updateWaypointItemView(edit, deletedPoints, ctx, v, point, this, nightMode, flat, position);
}
return v;
}
};
for (Object p : points) {
if (p instanceof LocationPointWrapper) {
LocationPointWrapper w = (LocationPointWrapper) p;
if (w.type == WaypointHelper.TARGETS) {
final TargetPoint t = (TargetPoint) w.point;
if (t.getOriginalPointDescription() != null && t.getOriginalPointDescription().isSearchingAddress(ctx)) {
GeocodingLookupService.AddressLookupRequest lookupRequest = new GeocodingLookupService.AddressLookupRequest(t.point, new GeocodingLookupService.OnAddressLookupResult() {
@Override
public void geocodingDone(String address) {
reloadListAdapter(listAdapter);
// updateRouteInfoMenu(ctx);
}
}, null);
ctx.getMyApplication().getGeocodingLookupService().lookupAddress(lookupRequest);
}
}
}
}
return listAdapter;
}
use of net.osmand.plus.helpers.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class RouteDetailsFragment method buildTransportRouteRow.
private void buildTransportRouteRow(@NonNull ViewGroup parent, TransportRouteResult routeResult, boolean showDivider) {
OsmandApplication app = requireMyApplication();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
TargetPoint startPoint = targetPointsHelper.getPointToStart();
TargetPoint endPoint = targetPointsHelper.getPointToNavigate();
int[] startTime = { 0 };
List<TransportRouteResultSegment> segments = routeResult.getSegments();
for (int i = 0; i < segments.size(); i++) {
boolean first = i == 0;
boolean last = i == segments.size() - 1;
final TransportRouteResultSegment segment = segments.get(i);
if (first) {
buildStartItem(parent, startPoint, startTime, segment, routeResult.getWalkSpeed());
}
buildSegmentItem(parent, segment, !last ? segments.get(i + 1) : null, startTime, routeResult.getWalkSpeed(), routeResult.getBoardingTime());
if (last) {
buildDestinationItem(parent, endPoint, startTime, segment, routeResult.getWalkSpeed());
}
if (showDivider && !last) {
buildRowDivider(parent, true);
}
}
}
Aggregations