private static void commitPointsRemoval( OsmandApplication app, final boolean[] checkedIntermediates) { int cnt = 0; for (int i = checkedIntermediates.length - 1; i >= 0; i--) { if (!checkedIntermediates[i]) { cnt++; } } if (cnt > 0) { boolean changeDestinationFlag = !checkedIntermediates[checkedIntermediates.length - 1]; if (cnt == checkedIntermediates .length) { // there is no alternative destination if all points are to be removed? app.getTargetPointsHelper().removeAllWayPoints(true); } else { for (int i = checkedIntermediates.length - 2; i >= 0; i--) { // skip the destination until a retained waypoint is found if (checkedIntermediates[i] && changeDestinationFlag) { // Find a valid replacement for the destination app.getTargetPointsHelper().makeWayPointDestination(cnt == 0, i); changeDestinationFlag = false; } else if (!checkedIntermediates[i]) { cnt--; app.getTargetPointsHelper().removeWayPoint(cnt == 0, i); } } // FIXME delete location when point is removed // if(mapActivity instanceof MapActivity) { // ((MapActivity) mapActivity).getMapLayers().getContextMenuLayer().setLocation(null, // ""); // } } } }
@Override protected void onResume() { super.onResume(); Intent intent = getIntent(); LatLon startPoint = null; if (intent != null) { double lat = intent.getDoubleExtra(SEARCH_LAT, 0); double lon = intent.getDoubleExtra(SEARCH_LON, 0); if (lat != 0 || lon != 0) { startPoint = new LatLon(lat, lon); } } if (startPoint == null && getParent() instanceof SearchActivity) { startPoint = ((SearchActivity) getParent()).getSearchPoint(); } if (startPoint == null) { startPoint = settings.getLastKnownMapLocation(); } OsmandApplication app = (OsmandApplication) getApplication(); LatLon pointToNavigate = app.getTargetPointsHelper().getPointToNavigate(); if (!Algorithms.objectEquals(pointToNavigate, this.destinationLocation) || !Algorithms.objectEquals(startPoint, this.lastKnownMapLocation)) { destinationLocation = pointToNavigate; selectedDestinationLocation = destinationLocation; lastKnownMapLocation = startPoint; searchTransport(); } }
public void showOnMap(boolean navigateTo) { if (searchPoint == null) { return; } String historyName = null; String objectName = ""; int zoom = 12; if (!Algoritms.isEmpty(street2) && !Algoritms.isEmpty(street)) { String cityName = !Algoritms.isEmpty(postcode) ? postcode : city; objectName = street; historyName = MessageFormat.format( getString(R.string.search_history_int_streets), street, street2, cityName); zoom = 16; } else if (!Algoritms.isEmpty(building)) { String cityName = !Algoritms.isEmpty(postcode) ? postcode : city; objectName = street + " " + building; historyName = MessageFormat.format( getString(R.string.search_history_building), building, street, cityName); zoom = 16; } else if (!Algoritms.isEmpty(street)) { String cityName = postcode != null ? postcode : city; objectName = street; historyName = MessageFormat.format(getString(R.string.search_history_street), street, cityName); zoom = 15; } else if (!Algoritms.isEmpty(city)) { historyName = MessageFormat.format(getString(R.string.search_history_city), city); objectName = city; zoom = 13; } if (selectAddressMode) { Intent intent = getIntent(); intent.putExtra(SELECT_ADDRESS_POINT_INTENT_KEY, objectName); intent.putExtra(SELECT_ADDRESS_POINT_LAT, searchPoint.getLatitude()); intent.putExtra(SELECT_ADDRESS_POINT_LON, searchPoint.getLongitude()); setResult(SELECT_ADDRESS_POINT_RESULT_OK, intent); finish(); } else { if (navigateTo) { OsmandApplication app = (OsmandApplication) getApplication(); app.getTargetPointsHelper() .navigatePointDialogAndLaunchMap( SearchAddressActivity.this, searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); } else { osmandSettings.setMapLocationToShow( searchPoint.getLatitude(), searchPoint.getLongitude(), zoom, historyName); MapActivity.launchMapActivityMoveToTop(SearchAddressActivity.this); } } }
private static void commitChangePointsOrder( OsmandApplication app, List<LatLon> target, List<String> names) { TargetPointsHelper targets = app.getTargetPointsHelper(); List<LatLon> cur = targets.getIntermediatePointsWithTarget(); boolean eq = true; for (int j = 0; j < cur.size() && j < target.size(); j++) { if (cur.get(j) != target.get(j)) { eq = false; break; } } if (!eq) { targets.reorderAllTargetPoints(target, names, true); } }
protected List<LocationPointWrapper> getTargets(List<LocationPointWrapper> points) { List<TargetPoint> wts = app.getTargetPointsHelper().getIntermediatePointsWithTarget(); for (int k = 0; k < wts.size(); k++) { final int index = wts.size() - k - 1; TargetPoint tp = wts.get(index); int routeIndex; if (route == null) { routeIndex = k == 0 ? Integer.MAX_VALUE : index; } else { routeIndex = k == 0 ? route.getImmutableAllLocations().size() - 1 : route.getIndexOfIntermediate(k - 1); } points.add(new LocationPointWrapper(route, TARGETS, tp, 0, routeIndex)); } Collections.reverse(points); return points; }
public void startNavigation() { stopCounter(); OsmandApplication app = mapActivity.getMyApplication(); RoutingHelper routingHelper = app.getRoutingHelper(); if (routingHelper.isFollowingMode()) { switchToRouteFollowingLayout(); } else { if (!app.getTargetPointsHelper().checkPointToNavigateShort()) { mapRouteInfoControlDialog.showDialog(); } else { touchEvent = 0; mapActivity.getMapViewTrackingUtilities().backToLocationImpl(); app.getSettings().FOLLOW_THE_ROUTE.set(true); routingHelper.setFollowingMode(true); routingHelper.setRoutePlanningMode(false); mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); app.getRoutingHelper().notifyIfRouteIsCalculated(); routingHelper.setCurrentLocation(app.getLocationProvider().getLastKnownLocation(), false); } } }
public void removeVisibleLocationPoint(List<LocationPointWrapper> points) { List<TargetPoint> ps = app.getTargetPointsHelper().getIntermediatePointsWithTarget(); boolean[] checkedIntermediates = null; for (LocationPointWrapper lp : points) { if (lp.type == TARGETS) { if (checkedIntermediates == null) { checkedIntermediates = new boolean[ps.size()]; Arrays.fill(checkedIntermediates, true); } if (((TargetPoint) lp.point).intermediate) { checkedIntermediates[((TargetPoint) lp.point).index] = false; } else { checkedIntermediates[ps.size() - 1] = false; } } else if (lp.type < locationPoints.size()) { locationPoints.get(lp.type).remove(lp); } } if (checkedIntermediates != null) { IntermediatePointsDialog.commitPointsRemoval(app, checkedIntermediates); } }
public void reRouteTo(LatLon loc) { final OsmandApplication app = activity.getMyApplication(); final TargetPointsHelper targets = app.getTargetPointsHelper(); // If we are in following mode then just update target point targets.navigateToPoint(loc, true, -1); if (!app.getRoutingHelper().isFollowingMode()) { // If we are not in following mode then request new route to calculate // Use default application mode activity.runOnUiThread( new Runnable() { @Override public void run() { activity.followRoute( app.getSettings().getApplicationMode(), targets.getPointToNavigate(), targets.getIntermediatePoints(), app.getLastKnownLocation(), null); } }); } }
public static void openIntermediatePointsDialog( final Activity activity, final OsmandApplication app, final boolean changeOrder) { TargetPointsHelper targets = app.getTargetPointsHelper(); final List<LatLon> intermediates = targets.getIntermediatePointsWithTarget(); final TIntArrayList originalPositions = new TIntArrayList(intermediates.size()); for (int j = 1; j <= intermediates.size(); j++) { originalPositions.add(j); } final List<String> names = targets.getIntermediatePointNamesWithTarget(); final boolean[] checkedIntermediates = new boolean[intermediates.size()]; Arrays.fill(checkedIntermediates, true); final ArrayAdapter<LatLon> listadapter = getListAdapter( app, activity, changeOrder, intermediates, originalPositions, names, checkedIntermediates); ListView lv = new ListView(activity); View contentView = lv; final ProgressBar pb = new ProgressBar(activity); pb.setVisibility(View.GONE); final TextView textInfo = new TextView(activity); textInfo.setText(R.string.intermediate_items_sort_return); textInfo.setVisibility(View.GONE); if (changeOrder) { LinearLayout ll = new LinearLayout(activity); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(lv); ll.addView(pb); ll.addView(textInfo); contentView = ll; // lv.addFooterView(pb); // lv.addFooterView(textInfo); } lv.setAdapter(listadapter); lv.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (activity instanceof MapActivity) { // AnimateDraggingMapThread thread = // mapActivity.getMapView().getAnimatedDraggingThread(); LatLon pointToNavigate = intermediates.get(position); int fZoom = ((MapActivity) activity).getMapView().getZoom() < 15 ? 15 : ((MapActivity) activity).getMapView().getZoom(); // thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), // fZoom, true); ((MapActivity) activity).getMapView().setIntZoom(fZoom); ((MapActivity) activity) .getMapView() .setLatLon(pointToNavigate.getLatitude(), pointToNavigate.getLongitude()); listadapter.notifyDataSetInvalidated(); } } }); Builder builder = new AccessibleAlertBuilder(activity); builder.setView(contentView); builder.setInverseBackgroundForced(true); lv.setBackgroundColor(Color.WHITE); builder.setPositiveButton( R.string.default_buttons_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (changeOrder) { commitChangePointsOrder(app, intermediates, names); } else { commitPointsRemoval(app, checkedIntermediates); } } }); if (!changeOrder && intermediates.size() > 1) { builder.setNeutralButton( R.string.intermediate_points_change_order, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { openIntermediatePointsDialog(activity, app, true); } }); } else if (intermediates.size() > 1) { builder.setNeutralButton( R.string.intermediate_items_sort_by_distance, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface d, int which) { // Do nothing here. We override the onclick } }); } AlertDialog dlg = builder.create(); if (changeOrder) { applySortTargets( dlg, activity, intermediates, originalPositions, names, listadapter, pb, textInfo); } dlg.show(); }
// Duplicate methods to OsmAndApplication public LatLon getPointToNavigate() { return app.getTargetPointsHelper().getPointToNavigate(); }
@Override protected void onResume() { super.onResume(); cancelNotification(); if (settings.MAP_SCREEN_ORIENTATION.get() != getRequestedOrientation()) { setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get()); // can't return from this method we are not sure if activity will be recreated or not } app.getLocationProvider().checkIfLastKnownLocationIsValid(); // for voice navigation if (settings.AUDIO_STREAM_GUIDANCE.get() != null) { setVolumeControlStream(settings.AUDIO_STREAM_GUIDANCE.get()); } else { setVolumeControlStream(AudioManager.STREAM_MUSIC); } applicationModeListener = new StateChangedListener<ApplicationMode>() { @Override public void stateChanged(ApplicationMode change) { updateApplicationModeSettings(); } }; settings.APPLICATION_MODE.addListener(applicationModeListener); updateApplicationModeSettings(); String filterId = settings.getPoiFilterForMap(); PoiFilter poiFilter = app.getPoiFilters().getFilterById(filterId); if (poiFilter == null) { poiFilter = new PoiFilter(null, app); } mapLayers.getPoiMapLayer().setFilter(poiFilter); // if destination point was changed try to recalculate route TargetPointsHelper targets = app.getTargetPointsHelper(); RoutingHelper routingHelper = app.getRoutingHelper(); if (routingHelper.isFollowingMode() && (!Algorithms.objectEquals(targets.getPointToNavigate(), routingHelper.getFinalLocation()) || !Algorithms.objectEquals( targets.getIntermediatePoints(), routingHelper.getIntermediatePoints()))) { routingHelper.setFinalAndCurrentLocation( targets.getPointToNavigate(), targets.getIntermediatePoints(), app.getLocationProvider().getLastKnownLocation(), routingHelper.getCurrentGPXRoute()); } app.getLocationProvider().resumeAllUpdates(); if (settings != null && settings.isLastKnownMapLocation()) { LatLon l = settings.getLastKnownMapLocation(); mapView.setLatLon(l.getLatitude(), l.getLongitude()); mapView.setZoom(settings.getLastKnownMapZoom()); } settings.MAP_ACTIVITY_ENABLED.set(true); checkExternalStorage(); showAndHideMapPosition(); LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude()); LatLon latLonToShow = settings.getAndClearMapLocationToShow(); String mapLabelToShow = settings.getAndClearMapLabelToShow(); Object toShow = settings.getAndClearObjectToShow(); if (settings.isRouteToPointNavigateAndClear()) { // always enable and follow and let calculate it (GPS is not accessible in garage) mapActions.getDirections(null, null, false); } if (mapLabelToShow != null && latLonToShow != null) { mapLayers.getContextMenuLayer().setSelectedObject(toShow); mapLayers.getContextMenuLayer().setLocation(latLonToShow, mapLabelToShow); } if (latLonToShow != null && !latLonToShow.equals(cur)) { mapView .getAnimatedDraggingThread() .startMoving( latLonToShow.getLatitude(), latLonToShow.getLongitude(), settings.getMapZoomToShow(), true); } if (latLonToShow != null) { // remember if map should come back to isMapLinkedToLocation=true mapViewTrackingUtilities.setMapLinkedToLocation(false); } View progress = mapLayers.getMapInfoLayer().getProgressBar(); if (progress != null) { app.getResourceManager().setBusyIndicator(new BusyIndicator(this, progress)); } OsmandPlugin.onMapActivityResume(this); mapView.refreshMap(true); }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { OsmandApplication app = (OsmandApplication) getActivity().getApplication(); boolean light = app.getSettings().isLightActionBar(); com.actionbarsherlock.view.MenuItem menuItem = menu.add(0, NAVIGATE_TO, 0, R.string.get_directions) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon( light ? R.drawable.ic_action_gdirections_light : R.drawable.ic_action_gdirections_dark); menuItem.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { select(NAVIGATE_TO); return true; } }); TargetPointsHelper targets = app.getTargetPointsHelper(); if (targets.getPointToNavigate() != null) { menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_intermediate_point) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon( light ? R.drawable.ic_action_flage_light : R.drawable.ic_action_flage_dark); } else { menuItem = menu.add(0, ADD_WAYPOINT, 0, R.string.context_menu_item_destination_point) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon( light ? R.drawable.ic_action_flag_light : R.drawable.ic_action_flag_dark); } menuItem.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { select(ADD_WAYPOINT); return true; } }); // } menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.search_shown_on_map) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon( light ? R.drawable.ic_action_marker_light : R.drawable.ic_action_marker_dark); menuItem.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { select(SHOW_ON_MAP); return true; } }); menuItem = menu.add(0, ADD_TO_FAVORITE, 0, R.string.add_to_favourite) .setShowAsActionFlags( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); menuItem = menuItem.setIcon(light ? R.drawable.ic_action_fav_light : R.drawable.ic_action_fav_dark); menuItem.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(com.actionbarsherlock.view.MenuItem item) { select(ADD_TO_FAVORITE); return true; } }); }
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()) { log.debug( "Processed by distance : (new) " + newDist + " (old) " + dist); //$NON-NLS-1$//$NON-NLS-2$ } processed = true; } } else if (newDist < dist || newDist < 10) { // newDist < 10 (avoid distance 0 till next turn) if (dist > posTolerance) { processed = true; if (log.isDebugEnabled()) { log.debug( "Processed by distance : " + newDist + " " + dist); // $NON-NLS-1$//$NON-NLS-2$ } } else { // case if you are getting close to the next point after turn // 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; } else { break; } } // 2. check if intermediate found if (route.getIntermediatePointsToPass() > 0 && route.getDistanceToNextIntermediate(lastFixedLocation) < POSITION_TOLERANCE * 2) { showMessage(app.getString(R.string.arrived_at_intermediate_point)); route.passIntermediatePoint(); TargetPointsHelper targets = app.getTargetPointsHelper(); List<String> ns = targets.getIntermediatePointNames(); int toDel = targets.getIntermediatePoints().size() - route.getIntermediatePointsToPass(); int currentIndex = toDel - 1; String name = currentIndex < 0 || currentIndex >= ns.size() || ns.get(currentIndex) == null ? "" : ns.get(currentIndex); if (isFollowingMode) { voiceRouter.arrivedIntermediatePoint(name); } while (toDel > 0) { targets.removeWayPoint(false, 0); toDel--; } 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) < (((float) settings.getApplicationMode().getArrivalDistance()) * settings.ARRIVAL_DISTANCE_FACTOR.get())) { showMessage(app.getString(R.string.arrived_at_destination)); TargetPointsHelper targets = app.getTargetPointsHelper(); String description = targets.getPointNavigateDescription(); if (isFollowingMode) { voiceRouter.arrivedDestinationPoint(description); } if (OsmandPlugin.onDestinationReached()) { clearCurrentRoute(null, null); setRoutePlanningMode(false); app.runInUIThread( new Runnable() { @Override public void run() { settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get()); } }); // targets.clearPointToNavigate(false); return true; } } return false; }