use of net.osmand.data.LocationPoint in project Osmand by osmandapp.
the class WaypointDialogHelper method getCustomDividers.
private List<Drawable> getCustomDividers(Context ctx, List<Object> points, boolean nightMode) {
int color = ContextCompat.getColor(ctx, nightMode ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light);
Shape fullDividerShape = new ListDividerShape(color, 0);
Shape halfDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(ctx, 56f));
Shape headerDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(ctx, 16f));
final ShapeDrawable fullDivider = new ShapeDrawable(fullDividerShape);
final ShapeDrawable halfDivider = new ShapeDrawable(halfDividerShape);
final ShapeDrawable headerDivider = new ShapeDrawable(headerDividerShape);
int divHeight = AndroidUtils.dpToPx(ctx, 1f);
fullDivider.setIntrinsicHeight(divHeight);
halfDivider.setIntrinsicHeight(divHeight);
headerDivider.setIntrinsicHeight(divHeight);
List<Drawable> res = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {
Object obj = points.get(i);
Object objNext = i + 1 < points.size() ? points.get(i + 1) : null;
if (objNext == null) {
break;
}
boolean labelView = (obj instanceof Integer);
boolean bottomDividerViewNext = (objNext instanceof Boolean) && !((Boolean) objNext);
boolean locationPoint = (obj instanceof LocationPointWrapper);
boolean locationPointNext = (objNext instanceof LocationPointWrapper);
Drawable d = null;
if (locationPointNext) {
d = locationPoint ? halfDivider : fullDivider;
} else if (objNext instanceof RadiusItem && labelView) {
d = headerDivider;
} else if (locationPoint && !bottomDividerViewNext) {
d = fullDivider;
}
res.add(d);
}
return res;
}
use of net.osmand.data.LocationPoint in project Osmand by osmandapp.
the class WaypointDialogHelper method updatePointInfoView.
public static void updatePointInfoView(final OsmandApplication app, final Activity activity, View localView, final LocationPointWrapper ps, final boolean mapCenter, final boolean nightMode, final boolean edit, final boolean topBar) {
WaypointHelper wh = app.getWaypointHelper();
final LocationPoint point = ps.getPoint();
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
if (!topBar) {
AndroidUtils.setTextPrimaryColor(activity, text, 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, activity, point, mapCenter);
}
});
}
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(activity, app, nightMode));
int dist = -1;
boolean startPoint = ps.type == WaypointHelper.TARGETS && ((TargetPoint) ps.point).start;
if (!startPoint) {
if (!wh.isRouteCalculated()) {
if (activity instanceof MapActivity) {
dist = (int) MapUtils.getDistance(((MapActivity) activity).getMapView().getLatitude(), ((MapActivity) activity).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 = nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light;
AndroidUtils.setTextSecondaryColor(activity, textDeviation, nightMode);
if (ps.deviationDirectionRight) {
textDeviation.setCompoundDrawablesWithIntrinsicBounds(app.getIconsCache().getIcon(R.drawable.ic_small_turn_right, colorId), null, null, null);
} else {
textDeviation.setCompoundDrawablesWithIntrinsicBounds(app.getIconsCache().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) {
AndroidUtils.setTextSecondaryColor(activity, descText, nightMode);
switch(ps.type) {
case WaypointHelper.TARGETS:
TargetPoint targetPoint = (TargetPoint) ps.point;
if (targetPoint.start) {
pointDescription = activity.getResources().getString(R.string.starting_point);
} else {
pointDescription = targetPoint.getPointDescription(activity).getTypeName();
}
break;
case WaypointHelper.FAVORITES:
FavouritePoint favPoint = (FavouritePoint) ps.point;
pointDescription = Algorithms.isEmpty(favPoint.getCategory()) ? activity.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.data.LocationPoint in project Osmand by osmandapp.
the class WaypointHelper method announceVisibleLocations.
public void announceVisibleLocations() {
Location lastKnownLocation = app.getRoutingHelper().getLastProjection();
if (lastKnownLocation != null && app.getRoutingHelper().isFollowingMode()) {
for (int type = 0; type < locationPoints.size(); type++) {
int currentRoute = route.getCurrentRoute();
List<LocationPointWrapper> approachPoints = new ArrayList<LocationPointWrapper>();
List<LocationPointWrapper> announcePoints = new ArrayList<LocationPointWrapper>();
List<LocationPointWrapper> lp = locationPoints.get(type);
if (lp != null) {
int kIterator = pointsProgress.get(type);
while (kIterator < lp.size() && lp.get(kIterator).routeIndex < currentRoute) {
if (type == ALARMS) {
AlarmInfo alarm = (AlarmInfo) lp.get(kIterator).getPoint();
if (alarm.getLastLocationIndex() >= currentRoute) {
break;
}
}
kIterator++;
}
pointsProgress.set(type, kIterator);
while (kIterator < lp.size()) {
LocationPointWrapper lwp = lp.get(kIterator);
if (type == ALARMS && lwp.routeIndex < currentRoute) {
kIterator++;
continue;
}
if (lwp.announce) {
if (route.getDistanceToPoint(lwp.routeIndex) > LONG_ANNOUNCE_RADIUS * 2) {
break;
}
LocationPoint point = lwp.point;
double d1 = Math.max(0.0, MapUtils.getDistance(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), point.getLatitude(), point.getLongitude()) - lwp.getDeviationDistance());
Integer state = locationPointsStates.get(point);
if (state != null && state.intValue() == ANNOUNCED_ONCE && getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS, 0f)) {
locationPointsStates.put(point, ANNOUNCED_DONE);
announcePoints.add(lwp);
} else if (type != ALARMS && (state == null || state == NOT_ANNOUNCED) && getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS, 0f)) {
locationPointsStates.put(point, ANNOUNCED_ONCE);
approachPoints.add(lwp);
} else if (type == ALARMS && (state == null || state == NOT_ANNOUNCED) && getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, ALARMS_ANNOUNCE_RADIUS, 0f)) {
locationPointsStates.put(point, ANNOUNCED_ONCE);
approachPoints.add(lwp);
}
}
kIterator++;
}
if (!announcePoints.isEmpty()) {
if (announcePoints.size() > ANNOUNCE_POI_LIMIT) {
announcePoints = announcePoints.subList(0, ANNOUNCE_POI_LIMIT);
}
if (type == WAYPOINTS) {
getVoiceRouter().announceWaypoint(announcePoints);
} else if (type == POI) {
getVoiceRouter().announcePoi(announcePoints);
} else if (type == ALARMS) {
// nothing to announce
} else if (type == FAVORITES) {
getVoiceRouter().announceFavorite(announcePoints);
}
}
if (!approachPoints.isEmpty()) {
if (approachPoints.size() > APPROACH_POI_LIMIT) {
approachPoints = approachPoints.subList(0, APPROACH_POI_LIMIT);
}
if (type == WAYPOINTS) {
getVoiceRouter().approachWaypoint(lastKnownLocation, approachPoints);
} else if (type == POI) {
getVoiceRouter().approachPoi(lastKnownLocation, approachPoints);
} else if (type == ALARMS) {
EnumSet<AlarmInfoType> ait = EnumSet.noneOf(AlarmInfoType.class);
for (LocationPointWrapper pw : approachPoints) {
ait.add(((AlarmInfo) pw.point).getType());
}
for (AlarmInfoType t : ait) {
app.getRoutingHelper().getVoiceRouter().announceAlarm(new AlarmInfo(t, -1), lastKnownLocation.getSpeed());
}
} else if (type == FAVORITES) {
getVoiceRouter().approachFavorite(lastKnownLocation, approachPoints);
}
}
}
}
}
}
use of net.osmand.data.LocationPoint in project Osmand by osmandapp.
the class WaypointHelper method findLocationPoints.
private void findLocationPoints(RouteCalculationResult rt, int type, List<LocationPointWrapper> locationPoints, List<? extends LocationPoint> points, boolean announce) {
List<Location> immutableAllLocations = rt.getImmutableAllLocations();
int[] ind = new int[1];
boolean[] devDirRight = new boolean[1];
for (LocationPoint p : points) {
float dist = dist(p, immutableAllLocations, ind, devDirRight);
int rad = getSearchDeviationRadius(type);
if (dist <= rad) {
LocationPointWrapper lpw = new LocationPointWrapper(rt, type, p, dist, ind[0]);
lpw.deviationDirectionRight = devDirRight[0];
lpw.setAnnounce(announce);
locationPoints.add(lpw);
}
}
}
use of net.osmand.data.LocationPoint in project Osmand by osmandapp.
the class WaypointHelper method dist.
private float dist(LocationPoint l, List<Location> locations, int[] ind, boolean[] devDirRight) {
float dist = Float.POSITIVE_INFINITY;
// Special iterations because points stored by pairs!
for (int i = 1; i < locations.size(); i++) {
final double ld = MapUtils.getOrthogonalDistance(l.getLatitude(), l.getLongitude(), locations.get(i - 1).getLatitude(), locations.get(i - 1).getLongitude(), locations.get(i).getLatitude(), locations.get(i).getLongitude());
if (ld < dist) {
if (ind != null) {
ind[0] = i;
}
dist = (float) ld;
}
}
if (ind != null && dist < Float.POSITIVE_INFINITY) {
int i = ind[0];
devDirRight[0] = MapUtils.rightSide(l.getLatitude(), l.getLongitude(), locations.get(i - 1).getLatitude(), locations.get(i - 1).getLongitude(), locations.get(i).getLatitude(), locations.get(i).getLongitude());
}
return dist;
}
Aggregations