Search in sources :

Example 16 with TargetPoint

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

the class PointNavigationLayer method applyNewObjectPosition.

@Override
public void applyNewObjectPosition(@NonNull Object o, @NonNull LatLon position, @Nullable ContextMenuLayer.ApplyMovedObjectCallback callback) {
    boolean result = false;
    TargetPoint newTargetPoint = null;
    if (o instanceof TargetPoint) {
        TargetPointsHelper targetPointsHelper = getApplication().getTargetPointsHelper();
        TargetPoint oldPoint = (TargetPoint) o;
        if (oldPoint.start) {
            targetPointsHelper.setStartPoint(position, true, null);
            newTargetPoint = targetPointsHelper.getPointToStart();
        } else if (oldPoint == targetPointsHelper.getPointToNavigate()) {
            targetPointsHelper.navigateToPoint(position, true, -1, null);
            newTargetPoint = targetPointsHelper.getPointToNavigate();
        } else if (oldPoint.intermediate) {
            List<TargetPoint> points = targetPointsHelper.getIntermediatePointsWithTarget();
            int i = points.indexOf(oldPoint);
            if (i != -1) {
                newTargetPoint = new TargetPoint(position, new PointDescription(PointDescription.POINT_TYPE_LOCATION, ""));
                points.set(i, newTargetPoint);
                targetPointsHelper.reorderAllTargetPoints(points, true);
            }
        }
        result = true;
    }
    if (callback != null) {
        callback.onApplyMovedObject(result, newTargetPoint == null ? o : newTargetPoint);
    }
}
Also used : PointDescription(net.osmand.data.PointDescription) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint)

Example 17 with TargetPoint

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

the class PointNavigationLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
    if (tb.getZoom() < 3) {
        return;
    }
    updateBitmaps(false);
    OsmandApplication app = getApplication();
    TargetPointsHelper targetPoints = app.getTargetPointsHelper();
    TargetPoint pointToStart = targetPoints.getPointToStart();
    if (pointToStart != null) {
        if (isLocationVisible(tb, pointToStart)) {
            int marginX = mStartPoint.getWidth() / 6;
            int marginY = mStartPoint.getHeight();
            float locationX = getPointX(tb, pointToStart);
            float locationY = getPointY(tb, pointToStart);
            canvas.rotate(-tb.getRotate(), locationX, locationY);
            canvas.drawBitmap(mStartPoint, locationX - marginX, locationY - marginY, mBitmapPaint);
            canvas.rotate(tb.getRotate(), locationX, locationY);
        }
    }
    int index = 0;
    for (TargetPoint ip : targetPoints.getIntermediatePoints()) {
        index++;
        if (isLocationVisible(tb, ip)) {
            int marginX = mIntermediatePoint.getWidth() / 6;
            int marginY = mIntermediatePoint.getHeight();
            float locationX = getPointX(tb, ip);
            float locationY = getPointY(tb, ip);
            canvas.rotate(-tb.getRotate(), locationX, locationY);
            canvas.drawBitmap(mIntermediatePoint, locationX - marginX, locationY - marginY, mBitmapPaint);
            marginX = mIntermediatePoint.getWidth() / 3;
            canvas.drawText(index + "", locationX + marginX, locationY - 3 * marginY / 5, mTextPaint);
            canvas.rotate(tb.getRotate(), locationX, locationY);
        }
    }
    TargetPoint pointToNavigate = targetPoints.getPointToNavigate();
    if (isLocationVisible(tb, pointToNavigate)) {
        int marginX = mTargetPoint.getWidth() / 6;
        int marginY = mTargetPoint.getHeight();
        float locationX = getPointX(tb, pointToNavigate);
        float locationY = getPointY(tb, pointToNavigate);
        canvas.rotate(-tb.getRotate(), locationX, locationY);
        canvas.drawBitmap(mTargetPoint, locationX - marginX, locationY - marginY, mBitmapPaint);
        canvas.rotate(tb.getRotate(), locationX, locationY);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) Paint(android.graphics.Paint)

Example 18 with TargetPoint

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

the class MapControlsLayer method startRoutePlanningWithDestination.

private void startRoutePlanningWithDestination(LatLon latLon, PointDescription pointDescription, TargetPointsHelper targets) {
    MapActivity mapActivity = getMapActivity();
    MapActions mapActions = mapActivity != null ? mapActivity.getMapActions() : app.getOsmandMap().getMapActions();
    boolean hasPointToStart = settings.restorePointToStart();
    targets.navigateToPoint(latLon, true, -1, pointDescription);
    if (!hasPointToStart) {
        mapActions.enterRoutePlanningModeGivenGpx(null, null, null, true, true, MenuState.HEADER_ONLY);
    } else {
        TargetPoint start = targets.getPointToStart();
        if (start != null) {
            mapActions.enterRoutePlanningModeGivenGpx(null, start.point, start.getOriginalPointDescription(), true, true, MenuState.HEADER_ONLY);
        } else {
            mapActions.enterRoutePlanningModeGivenGpx(null, null, null, true, true, MenuState.HEADER_ONLY);
        }
    }
}
Also used : MapActions(net.osmand.plus.views.MapActions) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) MapActivity(net.osmand.plus.activities.MapActivity)

Example 19 with TargetPoint

use of net.osmand.plus.helpers.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.helpers.TargetPointsHelper.TargetPoint)

Example 20 with TargetPoint

use of net.osmand.plus.helpers.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.helpers.TargetPointsHelper.TargetPoint) Location(net.osmand.Location)

Aggregations

TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)49 TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)23 OsmandApplication (net.osmand.plus.OsmandApplication)20 LatLon (net.osmand.data.LatLon)19 MapActivity (net.osmand.plus.activities.MapActivity)15 View (android.view.View)13 TextView (android.widget.TextView)13 Location (net.osmand.Location)13 ArrayList (java.util.ArrayList)12 ImageView (android.widget.ImageView)11 FavouritePoint (net.osmand.data.FavouritePoint)10 PointDescription (net.osmand.data.PointDescription)10 MapMarker (net.osmand.plus.mapmarkers.MapMarker)8 List (java.util.List)7 RoutingHelper (net.osmand.plus.routing.RoutingHelper)7 SuppressLint (android.annotation.SuppressLint)6 FrameLayout (android.widget.FrameLayout)6 LinearLayout (android.widget.LinearLayout)6 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)6 OnClickListener (android.view.View.OnClickListener)5