Search in sources :

Example 16 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class MapRouteInfoMenu method setupToSpinner.

private Spinner setupToSpinner(View view) {
    final Spinner toSpinner = ((Spinner) view.findViewById(R.id.ToSpinner));
    final TargetPointsHelper targets = getTargets();
    List<RouteSpinnerRow> toActions = new ArrayList<>();
    TargetPoint finish = getTargets().getPointToNavigate();
    if (finish != null) {
        toActions.add(new RouteSpinnerRow(SPINNER_FINISH_ID, R.drawable.ic_action_get_my_location, getRoutePointDescription(targets.getPointToNavigate().point, targets.getPointToNavigate().getOnlyName())));
        final LatLon latLon = finish.point;
        final PointDescription pointDescription = finish.getOriginalPointDescription();
        boolean needAddress = pointDescription != null && pointDescription.isSearchingAddress(mapActivity);
        cancelTargetPointAddressRequest();
        if (needAddress) {
            targetPointRequest = new AddressLookupRequest(latLon, new GeocodingLookupService.OnAddressLookupResult() {

                @Override
                public void geocodingDone(String address) {
                    targetPointRequest = null;
                    updateMenu();
                }
            }, null);
            geocodingLookupService.lookupAddress(targetPointRequest);
        }
    } else {
        toSpinner.setPromptId(R.string.route_descr_select_destination);
        toActions.add(new RouteSpinnerRow(SPINNER_HINT_ID, R.drawable.ic_action_get_my_location, mapActivity.getString(R.string.route_descr_select_destination)));
    }
    toActions.add(new RouteSpinnerRow(SPINNER_FAV_ID, R.drawable.ic_action_fav_dark, mapActivity.getString(R.string.shared_string_favorite) + mapActivity.getString(R.string.shared_string_ellipsis)));
    toActions.add(new RouteSpinnerRow(SPINNER_MAP_ID, R.drawable.ic_action_marker_dark, mapActivity.getString(R.string.shared_string_select_on_map)));
    toActions.add(new RouteSpinnerRow(SPINNER_ADDRESS_ID, R.drawable.ic_action_home_dark, mapActivity.getString(R.string.shared_string_address) + mapActivity.getString(R.string.shared_string_ellipsis)));
    addMarkersToSpinner(toActions);
    RouteSpinnerArrayAdapter toAdapter = new RouteSpinnerArrayAdapter(view.getContext());
    for (RouteSpinnerRow row : toActions) {
        toAdapter.add(row);
    }
    toSpinner.setAdapter(toAdapter);
    return toSpinner;
}
Also used : Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) AddressLookupRequest(net.osmand.plus.GeocodingLookupService.AddressLookupRequest)

Example 17 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class MapRouteInfoMenu method setupFromSpinner.

private Spinner setupFromSpinner(View view) {
    List<RouteSpinnerRow> fromActions = new ArrayList<>();
    fromActions.add(new RouteSpinnerRow(SPINNER_MY_LOCATION_ID, R.drawable.ic_action_get_my_location, mapActivity.getString(R.string.shared_string_my_location)));
    fromActions.add(new RouteSpinnerRow(SPINNER_FAV_ID, R.drawable.ic_action_fav_dark, mapActivity.getString(R.string.shared_string_favorite) + mapActivity.getString(R.string.shared_string_ellipsis)));
    fromActions.add(new RouteSpinnerRow(SPINNER_MAP_ID, R.drawable.ic_action_marker_dark, mapActivity.getString(R.string.shared_string_select_on_map)));
    fromActions.add(new RouteSpinnerRow(SPINNER_ADDRESS_ID, R.drawable.ic_action_home_dark, mapActivity.getString(R.string.shared_string_address) + mapActivity.getString(R.string.shared_string_ellipsis)));
    TargetPoint start = getTargets().getPointToStart();
    int startPos = -1;
    if (start != null) {
        String oname = start.getOnlyName().length() > 0 ? start.getOnlyName() : (mapActivity.getString(R.string.route_descr_map_location) + " " + getRoutePointDescription(start.getLatitude(), start.getLongitude()));
        startPos = fromActions.size();
        fromActions.add(new RouteSpinnerRow(SPINNER_START_ID, R.drawable.ic_action_get_my_location, oname));
        final LatLon latLon = start.point;
        final PointDescription pointDescription = start.getOriginalPointDescription();
        boolean needAddress = pointDescription != null && pointDescription.isSearchingAddress(mapActivity);
        cancelStartPointAddressRequest();
        if (needAddress) {
            startPointRequest = new AddressLookupRequest(latLon, new GeocodingLookupService.OnAddressLookupResult() {

                @Override
                public void geocodingDone(String address) {
                    startPointRequest = null;
                    updateMenu();
                }
            }, null);
            geocodingLookupService.lookupAddress(startPointRequest);
        }
    }
    addMarkersToSpinner(fromActions);
    final Spinner fromSpinner = ((Spinner) view.findViewById(R.id.FromSpinner));
    RouteSpinnerArrayAdapter fromAdapter = new RouteSpinnerArrayAdapter(view.getContext());
    for (RouteSpinnerRow row : fromActions) {
        fromAdapter.add(row);
    }
    fromSpinner.setAdapter(fromAdapter);
    if (start != null) {
        fromSpinner.setSelection(startPos);
    } else {
        if (mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() == null) {
            fromSpinner.setPromptId(R.string.search_poi_location);
        }
    // fromSpinner.setSelection(0);
    }
    return fromSpinner;
}
Also used : Spinner(android.widget.Spinner) ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) AddressLookupRequest(net.osmand.plus.GeocodingLookupService.AddressLookupRequest)

Example 18 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class PlanRouteFragment method createOptionsFragmentListener.

private PlanRouteOptionsFragmentListener createOptionsFragmentListener() {
    return new PlanRouteOptionsFragmentListener() {

        private MapActivity mapActivity = getMapActivity();

        @Override
        public void selectOnClick() {
            selectAllOnClick();
        }

        @Override
        public void navigateOnClick() {
            if (mapActivity != null) {
                boolean hasTargets = false;
                TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
                List<MapMarker> markers = markersHelper.getSelectedMarkers();
                if (markers.size() > 0) {
                    int i = 0;
                    if (markersHelper.isStartFromMyLocation()) {
                        targetPointsHelper.clearStartPoint(false);
                    } else {
                        MapMarker m = markers.get(i++);
                        targetPointsHelper.setStartPoint(new LatLon(m.getLatitude(), m.getLongitude()), false, m.getPointDescription(mapActivity));
                    }
                    List<TargetPoint> targetPoints = new ArrayList<>();
                    for (int k = i; k < markers.size(); k++) {
                        MapMarker m = markers.get(k);
                        TargetPoint t = new TargetPoint(new LatLon(m.getLatitude(), m.getLongitude()), m.getPointDescription(mapActivity));
                        targetPoints.add(t);
                    }
                    if (mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get()) {
                        TargetPoint end = targetPointsHelper.getPointToStart();
                        if (end == null) {
                            Location loc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
                            if (loc != null) {
                                end = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, getString(R.string.shared_string_my_location)));
                            }
                        }
                        if (end != null) {
                            targetPoints.add(end);
                        }
                    }
                    RoutingHelper routingHelper = mapActivity.getRoutingHelper();
                    boolean updateRoute = routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode();
                    targetPointsHelper.reorderAllTargetPoints(targetPoints, updateRoute);
                    hasTargets = true;
                } else {
                    targetPointsHelper.clearStartPoint(false);
                    targetPointsHelper.clearPointToNavigate(false);
                }
                planRouteContext.setNavigationFromMarkers(true);
                dismiss();
                mapActivity.getMapLayers().getMapControlsLayer().doRoute(hasTargets);
            }
        }

        @Override
        public void makeRoundTripOnClick() {
            roundTripOnClick();
        }

        @Override
        public void doorToDoorOnClick() {
            if (mapActivity != null) {
                OsmandApplication app = mapActivity.getMyApplication();
                Location myLoc = app.getLocationProvider().getLastStaleKnownLocation();
                boolean startFromLocation = app.getMapMarkersHelper().isStartFromMyLocation() && myLoc != null;
                if (selectedCount > (startFromLocation ? 0 : 1)) {
                    sortSelectedMarkersDoorToDoor(mapActivity, startFromLocation, myLoc);
                }
            }
        }

        @Override
        public void reverseOrderOnClick() {
            if (mapActivity != null) {
                markersHelper.reverseActiveMarkersOrder();
                adapter.reloadData();
                adapter.notifyDataSetChanged();
                planRouteContext.recreateSnapTrkSegment(false);
            }
        }
    };
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PlanRouteOptionsFragmentListener(net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener) PointDescription(net.osmand.data.PointDescription) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location)

Example 19 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class NavigationInfo method updateCompassValue.

@Override
public synchronized void updateCompassValue(float heading) {
    RoutingHelper router = app.getRoutingHelper();
    if (router.isFollowingMode() && router.isRouteCalculated()) {
        synchronized (router) {
            NextDirectionInfo nextDirection = router.getNextRouteDirectionInfo(new NextDirectionInfo(), true);
            if (nextDirection != null) {
                updateTargetDirection(router.getLocationFromRouteDirection(nextDirection.directionInfo), heading);
            }
        }
    } else {
        TargetPoint target = app.getTargetPointsHelper().getPointToNavigate();
        updateTargetDirection((target != null) ? target.point : null, heading);
    }
}
Also used : NextDirectionInfo(net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Example 20 with TargetPoint

use of net.osmand.plus.TargetPointsHelper.TargetPoint in project Osmand by osmandapp.

the class NavigationInfo method updateLocation.

@Override
public synchronized void updateLocation(Location location) {
    currentLocation = location;
    if (autoAnnounce && app.accessibilityEnabled()) {
        final TargetPoint point = app.getTargetPointsHelper().getPointToNavigate();
        if (point != null) {
            if ((currentLocation != null) && currentLocation.hasBearing() && !MapViewTrackingUtilities.isSmallSpeedForCompass(currentLocation)) {
                final long now = SystemClock.uptimeMillis();
                if ((now - lastNotificationTime) >= settings.ACCESSIBILITY_AUTOANNOUNCE_PERIOD.get()) {
                    // $NON-NLS-1$
                    Location destination = new Location("map");
                    destination.setLatitude(point.getLatitude());
                    destination.setLongitude(point.getLongitude());
                    if (lastDirection.update(destination) || !settings.ACCESSIBILITY_SMART_AUTOANNOUNCE.get()) {
                        // $NON-NLS-1$
                        final String notification = distanceString(destination) + " " + lastDirection.getString();
                        lastNotificationTime = now;
                        app.runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                app.showToastMessage(notification);
                            }
                        });
                    }
                }
            } else {
                lastDirection.clear();
            }
        }
    }
}
Also used : TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Location(net.osmand.Location)

Aggregations

TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)39 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)18 LatLon (net.osmand.data.LatLon)17 View (android.view.View)13 TextView (android.widget.TextView)13 Location (net.osmand.Location)10 PointDescription (net.osmand.data.PointDescription)10 AdapterView (android.widget.AdapterView)9 ArrayList (java.util.ArrayList)9 ImageView (android.widget.ImageView)8 SuppressLint (android.annotation.SuppressLint)6 LocationPoint (net.osmand.data.LocationPoint)6 FavouritePoint (net.osmand.data.FavouritePoint)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 Paint (android.graphics.Paint)4 ImageButton (android.widget.ImageButton)4 ListView (android.widget.ListView)4 List (java.util.List)4 RoutingHelper (net.osmand.plus.routing.RoutingHelper)4 DialogInterface (android.content.DialogInterface)3