use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class DashWaypointsFragment method selectTargetModel.
private void selectTargetModel(final TargetPoint point, final View view) {
final PopupMenu optionsMenu = new PopupMenu(getActivity(), view);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
MenuItem item;
// item = optionsMenu.getMenu().add(
// R.string.shared_string_add_to_favorites).setIcon(getMyApplication().getIconsCache().
// getIcon(R.drawable.ic_action_fav_dark));
// item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
// @Override
// public boolean onMenuItemClick(MenuItem item) {
// Bundle args = new Bundle();
// Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), args);
// dlg.show();
// FavoriteDialogs.prepareAddFavouriteDialog(getActivity(), dlg, args, model.getLatitude(), model.getLongitude(),
// model.getOriginalPointDescription());
// return true;
// }
// });
final boolean target = point == getMyApplication().getTargetPointsHelper().getPointToNavigate();
if (SHOW_ALL && getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0) {
final List<TargetPoint> allTargets = getMyApplication().getTargetPointsHelper().getIntermediatePointsWithTarget();
if (point.index > 0 || target) {
final int ind = target ? allTargets.size() - 1 : point.index;
item = optionsMenu.getMenu().add(R.string.waypoint_visit_before).setIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_up_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
TargetPoint remove = allTargets.remove(ind - 1);
allTargets.add(ind, remove);
getMyApplication().getTargetPointsHelper().reorderAllTargetPoints(allTargets, true);
setupView();
return true;
}
});
}
if (!target) {
item = optionsMenu.getMenu().add(R.string.waypoint_visit_after).setIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_down_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
TargetPoint remove = allTargets.remove(point.index + 1);
allTargets.add(point.index, remove);
getMyApplication().getTargetPointsHelper().reorderAllTargetPoints(allTargets, true);
setupView();
return true;
}
});
}
}
item = optionsMenu.getMenu().add(R.string.shared_string_remove).setIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
deletePointConfirm(point, view);
return true;
}
});
optionsMenu.show();
}
use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class FailSafeFuntions method restoreRoutingMode.
public static void restoreRoutingMode(final MapActivity ma) {
final OsmandApplication app = ma.getMyApplication();
final OsmandSettings settings = app.getSettings();
final Handler uiHandler = new Handler();
final String gpxPath = settings.FOLLOW_THE_GPX_ROUTE.get();
final TargetPointsHelper targetPoints = app.getTargetPointsHelper();
final TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
if (pointToNavigate == null && gpxPath == null) {
notRestoreRoutingMode(ma, app);
} else {
quitRouteRestoreDialog = false;
Runnable encapsulate = new Runnable() {
int delay = 7;
Runnable delayDisplay = null;
@Override
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(ma);
final TextView tv = new TextView(ma);
tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
tv.setPadding(7, 5, 7, 5);
builder.setView(tv);
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
quitRouteRestoreDialog = true;
restoreRoutingModeInner();
}
});
builder.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
quitRouteRestoreDialog = true;
notRestoreRoutingMode(ma, app);
}
});
final AlertDialog dlg = builder.show();
dlg.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
quitRouteRestoreDialog = true;
}
});
dlg.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
quitRouteRestoreDialog = true;
}
});
delayDisplay = new Runnable() {
@Override
public void run() {
if (!quitRouteRestoreDialog) {
delay--;
tv.setText(ma.getString(R.string.continue_follow_previous_route_auto, delay + ""));
if (delay <= 0) {
try {
if (dlg.isShowing() && !quitRouteRestoreDialog) {
dlg.dismiss();
}
quitRouteRestoreDialog = true;
restoreRoutingModeInner();
} catch (Exception e) {
// swalow view not attached exception
log.error(e.getMessage() + "", e);
}
} else {
uiHandler.postDelayed(delayDisplay, 1000);
}
}
}
};
delayDisplay.run();
}
private void restoreRoutingModeInner() {
AsyncTask<String, Void, GPXFile> task = new AsyncTask<String, Void, GPXFile>() {
@Override
protected GPXFile doInBackground(String... params) {
if (gpxPath != null) {
// Reverse also should be stored ?
GPXFile f = GPXUtilities.loadGPXFile(app, new File(gpxPath));
if (f.warning != null) {
return null;
}
return f;
} else {
return null;
}
}
@Override
protected void onPostExecute(GPXFile result) {
final GPXRouteParamsBuilder gpxRoute;
if (result != null) {
gpxRoute = new GPXRouteParamsBuilder(result, settings);
if (settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()) {
gpxRoute.setCalculateOsmAndRouteParts(true);
}
if (settings.GPX_CALCULATE_RTEPT.get()) {
gpxRoute.setUseIntermediatePointsRTE(true);
}
if (settings.GPX_ROUTE_CALC.get()) {
gpxRoute.setCalculateOsmAndRoute(true);
}
} else {
gpxRoute = null;
}
TargetPoint endPoint = pointToNavigate;
if (endPoint == null) {
notRestoreRoutingMode(ma, app);
} else {
enterRoutingMode(ma, gpxRoute);
}
}
};
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxPath);
}
};
encapsulate.run();
}
}
use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class RoutingHelper method updateCurrentRouteStatus.
private boolean updateCurrentRouteStatus(Location currentLocation, float posTolerance) {
List<Location> routeNodes = route.getImmutableAllLocations();
int currentRoute = route.currentRoute;
// 1. Try to proceed to next point using orthogonal distance (finding minimum orthogonal dist)
while (currentRoute + 1 < routeNodes.size()) {
double dist = currentLocation.distanceTo(routeNodes.get(currentRoute));
if (currentRoute > 0) {
dist = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
}
boolean processed = false;
// if we are still too far try to proceed many points
// if not then look ahead only 3 in order to catch sharp turns
boolean longDistance = dist >= 250;
int newCurrentRoute = lookAheadFindMinOrthogonalDistance(currentLocation, routeNodes, currentRoute, longDistance ? 15 : 8);
double newDist = getOrthogonalDistance(currentLocation, routeNodes.get(newCurrentRoute), routeNodes.get(newCurrentRoute + 1));
if (longDistance) {
if (newDist < dist) {
if (log.isDebugEnabled()) {
// $NON-NLS-1$//$NON-NLS-2$
log.debug("Processed by distance : (new) " + newDist + " (old) " + dist);
}
processed = true;
}
} else if (newDist < dist || newDist < 10) {
// newDist < 10 (avoid distance 0 till next turn)
if (dist > posTolerance) {
processed = true;
if (log.isDebugEnabled()) {
// $NON-NLS-1$//$NON-NLS-2$
log.debug("Processed by distance : " + newDist + " " + dist);
}
} else {
// but you have not yet turned (could be checked bearing)
if (currentLocation.hasBearing() || lastFixedLocation != null) {
float bearingToRoute = currentLocation.bearingTo(routeNodes.get(currentRoute));
float bearingRouteNext = routeNodes.get(newCurrentRoute).bearingTo(routeNodes.get(newCurrentRoute + 1));
float bearingMotion = currentLocation.hasBearing() ? currentLocation.getBearing() : lastFixedLocation.bearingTo(currentLocation);
double diff = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingToRoute));
double diffToNext = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingRouteNext));
if (diff > diffToNext) {
if (log.isDebugEnabled()) {
log.debug("Processed point bearing deltas : " + diff + " " + diffToNext);
}
processed = true;
}
}
}
}
if (processed) {
// that node already passed
route.updateCurrentRoute(newCurrentRoute + 1);
currentRoute = newCurrentRoute + 1;
app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION);
} else {
break;
}
}
// 2. check if intermediate found
if (route.getIntermediatePointsToPass() > 0 && route.getDistanceToNextIntermediate(lastFixedLocation) < getArrivalDistance() * 2f && !isRoutePlanningMode) {
showMessage(app.getString(R.string.arrived_at_intermediate_point));
route.passIntermediatePoint();
TargetPointsHelper targets = app.getTargetPointsHelper();
String name = "";
if (intermediatePoints != null && !intermediatePoints.isEmpty()) {
LatLon rm = intermediatePoints.remove(0);
List<TargetPoint> ll = targets.getIntermediatePointsNavigation();
int ind = -1;
for (int i = 0; i < ll.size(); i++) {
if (ll.get(i).point != null && MapUtils.getDistance(ll.get(i).point, rm) < 5) {
name = ll.get(i).getOnlyName();
ind = i;
break;
}
}
if (ind >= 0) {
targets.removeWayPoint(false, ind);
}
}
if (isFollowingMode) {
voiceRouter.arrivedIntermediatePoint(name);
}
// double check
while (intermediatePoints != null && route.getIntermediatePointsToPass() < intermediatePoints.size()) {
intermediatePoints.remove(0);
}
}
// 3. check if destination found
Location lastPoint = routeNodes.get(routeNodes.size() - 1);
if (currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < getArrivalDistance() && !isRoutePlanningMode) {
// showMessage(app.getString(R.string.arrived_at_destination));
TargetPointsHelper targets = app.getTargetPointsHelper();
TargetPoint tp = targets.getPointToNavigate();
String description = tp == null ? "" : tp.getOnlyName();
if (isFollowingMode) {
voiceRouter.arrivedDestinationPoint(description);
}
boolean onDestinationReached = OsmandPlugin.onDestinationReached();
onDestinationReached &= app.getAppCustomization().onDestinationReached();
if (onDestinationReached) {
clearCurrentRoute(null, null);
setRoutePlanningMode(false);
app.runInUIThread(new Runnable() {
@Override
public void run() {
settings.LAST_ROUTING_APPLICATION_MODE = settings.APPLICATION_MODE.get();
// settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
}
});
finishCurrentRoute();
// targets.clearPointToNavigate(false);
return true;
}
}
return false;
}
use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class MapActivity method newRouteIsCalculated.
@Override
public void newRouteIsCalculated(boolean newRoute, ValueHolder<Boolean> showToast) {
RoutingHelper rh = app.getRoutingHelper();
if (newRoute && rh.isRoutePlanningMode() && mapView != null) {
Location lt = rh.getLastProjection();
if (lt == null) {
lt = app.getTargetPointsHelper().getPointToStartLocation();
}
if (lt != null) {
double left = lt.getLongitude(), right = lt.getLongitude();
double top = lt.getLatitude(), bottom = lt.getLatitude();
List<Location> list = rh.getCurrentCalculatedRoute();
for (Location l : list) {
left = Math.min(left, l.getLongitude());
right = Math.max(right, l.getLongitude());
top = Math.max(top, l.getLatitude());
bottom = Math.min(bottom, l.getLatitude());
}
List<TargetPoint> targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
for (TargetPoint l : targetPoints) {
left = Math.min(left, l.getLongitude());
right = Math.max(right, l.getLongitude());
top = Math.max(top, l.getLatitude());
bottom = Math.min(bottom, l.getLatitude());
}
RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
int tileBoxWidthPx = 0;
int tileBoxHeightPx = 0;
MapRouteInfoMenu routeInfoMenu = mapLayers.getMapControlsLayer().getMapRouteInfoMenu();
WeakReference<MapRouteInfoMenuFragment> fragmentRef = routeInfoMenu.findMenuFragment();
if (fragmentRef != null) {
MapRouteInfoMenuFragment f = fragmentRef.get();
if (landscapeLayout) {
tileBoxWidthPx = tb.getPixWidth() - f.getWidth();
} else {
tileBoxHeightPx = tb.getPixHeight() - f.getHeight();
}
}
mapView.fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0);
}
}
}
use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.
the class PointNavigationLayer method collectObjectsFromPoint.
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (tileBox.getZoom() >= 3) {
TargetPointsHelper tg = map.getMyApplication().getTargetPointsHelper();
List<TargetPoint> intermediatePoints = tg.getAllPoints();
int r = getDefaultRadiusPoi(tileBox);
for (int i = 0; i < intermediatePoints.size(); i++) {
TargetPoint tp = intermediatePoints.get(i);
LatLon latLon = tp.point;
if (latLon != null) {
int ex = (int) point.x;
int ey = (int) point.y;
int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
if (calculateBelongs(ex, ey, x, y, r)) {
o.add(tp);
}
}
}
}
}
Aggregations