Search in sources :

Example 6 with TargetPoint

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

the class RouteInfoWidgetsFactory method createIntermediateDistanceControl.

public TextInfoWidget createIntermediateDistanceControl(final MapActivity map) {
    final TargetPointsHelper targets = map.getMyApplication().getTargetPointsHelper();
    DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, R.drawable.widget_intermediate_day, R.drawable.widget_intermediate_night) {

        @Override
        protected void click(OsmandMapTileView view) {
            if (targets.getIntermediatePoints().size() > 1) {
                map.getMapActions().openIntermediatePointsDialog();
            } else {
                super.click(view);
            }
        }

        @Override
        public LatLon getPointToNavigate() {
            TargetPoint p = targets.getFirstIntermediatePoint();
            return p == null ? null : p.point;
        }

        @Override
        public int getDistance() {
            if (getPointToNavigate() != null && map.getRoutingHelper().isRouteCalculated()) {
                return map.getRoutingHelper().getLeftDistanceNextIntermediate();
            }
            return super.getDistance();
        }
    };
    return distanceControl;
}
Also used : OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 7 with TargetPoint

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

the class MapContextMenu method init.

public boolean init(@NonNull LatLon latLon, @Nullable PointDescription pointDescription, @Nullable Object object, boolean update, boolean restorePrevious) {
    OsmandApplication app = mapActivity.getMyApplication();
    if (myLocation == null) {
        updateMyLocation(app.getLocationProvider().getLastKnownLocation(), false);
    }
    if (!update && isVisible()) {
        if (this.object == null || !this.object.equals(object)) {
            hide();
        } else {
            return false;
        }
    }
    setSelectedObject(object);
    if (pointDescription == null) {
        this.pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
    } else {
        this.pointDescription = pointDescription;
    }
    boolean needAcquireMenuController = menuController == null || appModeChanged || !update || this.object == null && object != null || this.object != null && object == null || (this.object != null && object != null && !this.object.getClass().equals(object.getClass()));
    this.latLon = latLon;
    this.object = object;
    active = true;
    appModeChanged = false;
    if (needAcquireMenuController) {
        if (menuController != null) {
            menuController.setMapContextMenu(null);
        }
        if (!acquireMenuController(restorePrevious)) {
            active = false;
            clearSelectedObject(object);
            return false;
        }
    } else {
        menuController.update(pointDescription, object);
    }
    initTitle();
    if (menuController != null) {
        menuController.clearPlainMenuItems();
        menuController.addPlainMenuItems(typeStr, this.pointDescription, this.latLon);
    }
    if (mapPosition != 0) {
        mapActivity.getMapView().setMapPosition(0);
    }
    mapActivity.refreshMap();
    if (object instanceof MapMarker) {
        app.getMapMarkersHelper().addListener(this);
    } else if (object instanceof TargetPoint) {
        app.getTargetPointsHelper().addPointListener(this);
    }
    return true;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) PointDescription(net.osmand.data.PointDescription) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Example 8 with TargetPoint

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

the class MenuController method getMenuController.

public static MenuController getMenuController(MapActivity mapActivity, LatLon latLon, PointDescription pointDescription, Object object, MenuType menuType) {
    MenuController menuController = null;
    if (object != null) {
        if (object instanceof Amenity) {
            menuController = new AmenityMenuController(mapActivity, pointDescription, (Amenity) object);
        } else if (object instanceof FavouritePoint) {
            menuController = new FavouritePointMenuController(mapActivity, pointDescription, (FavouritePoint) object);
        } else if (object instanceof SearchHistoryHelper.HistoryEntry) {
            menuController = new HistoryMenuController(mapActivity, pointDescription, (SearchHistoryHelper.HistoryEntry) object);
        } else if (object instanceof TargetPoint) {
            menuController = new TargetPointMenuController(mapActivity, pointDescription, (TargetPoint) object);
        } else if (object instanceof Recording) {
            menuController = new AudioVideoNoteMenuController(mapActivity, pointDescription, (Recording) object);
        } else if (object instanceof OsmPoint) {
            menuController = new EditPOIMenuController(mapActivity, pointDescription, (OsmPoint) object);
        } else if (object instanceof WptPt) {
            menuController = new WptPtMenuController(mapActivity, pointDescription, (WptPt) object);
        } else if (object instanceof DownloadMapObject) {
            menuController = new MapDataMenuController(mapActivity, pointDescription, (DownloadMapObject) object);
        } else if (object instanceof OpenStreetNote) {
            menuController = new OsmBugMenuController(mapActivity, pointDescription, (OpenStreetNote) object);
        } else if (object instanceof GpxDisplayItem) {
            menuController = new GpxItemMenuController(mapActivity, pointDescription, (GpxDisplayItem) object);
        } else if (object instanceof MapMarker) {
            menuController = new MapMarkerMenuController(mapActivity, pointDescription, (MapMarker) object);
        } else if (object instanceof TransportStopRoute) {
            menuController = new TransportRouteController(mapActivity, pointDescription, (TransportStopRoute) object);
        } else if (object instanceof TransportStop) {
            menuController = new TransportStopController(mapActivity, pointDescription, (TransportStop) object);
        } else if (object instanceof AMapPoint) {
            menuController = new AMapPointMenuController(mapActivity, pointDescription, (AMapPoint) object);
        } else if (object instanceof LatLon) {
            if (pointDescription.isParking()) {
                menuController = new ParkingPositionMenuController(mapActivity, pointDescription);
            } else if (pointDescription.isMyLocation()) {
                menuController = new MyLocationMenuController(mapActivity, pointDescription);
            }
        } else if (object instanceof RouteDataObject) {
            menuController = new ImpassibleRoadsMenuController(mapActivity, pointDescription, (RouteDataObject) object);
        } else if (object instanceof RenderedObject) {
            menuController = new RenderedObjectMenuController(mapActivity, pointDescription, (RenderedObject) object);
        } else if (object instanceof MapillaryImage) {
            menuController = new MapillaryMenuController(mapActivity, pointDescription, (MapillaryImage) object);
        }
    }
    if (menuController == null) {
        menuController = new PointDescriptionMenuController(mapActivity, pointDescription);
    }
    menuController.menuType = menuType;
    menuController.setLatLon(latLon);
    menuController.onCreated();
    return menuController;
}
Also used : TargetPointMenuController(net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController) WptPt(net.osmand.plus.GPXUtilities.WptPt) HistoryMenuController(net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController) TransportStopController(net.osmand.plus.mapcontextmenu.controllers.TransportStopController) FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) MapillaryImage(net.osmand.plus.mapillary.MapillaryImage) ParkingPositionMenuController(net.osmand.plus.parkingpoint.ParkingPositionMenuController) GpxDisplayItem(net.osmand.plus.GpxSelectionHelper.GpxDisplayItem) GpxItemMenuController(net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) RenderedObjectMenuController(net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController) ImpassibleRoadsMenuController(net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController) EditPOIMenuController(net.osmand.plus.osmedit.EditPOIMenuController) TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) MapMarkerMenuController(net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController) PointDescriptionMenuController(net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController) AMapPointMenuController(net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController) TransportStop(net.osmand.data.TransportStop) Amenity(net.osmand.data.Amenity) FavouritePointMenuController(net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController) AudioVideoNoteMenuController(net.osmand.plus.audionotes.AudioVideoNoteMenuController) OsmBugMenuController(net.osmand.plus.osmedit.OsmBugMenuController) OsmPoint(net.osmand.plus.osmedit.OsmPoint) TransportRouteController(net.osmand.plus.mapcontextmenu.controllers.TransportRouteController) AMapPoint(net.osmand.aidl.maplayer.point.AMapPoint) AmenityMenuController(net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController) DownloadMapObject(net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject) MyLocationMenuController(net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController) RenderedObjectMenuController(net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController) PointDescriptionMenuController(net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController) MapMarkerMenuController(net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController) AMapPointMenuController(net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController) OsmBugMenuController(net.osmand.plus.osmedit.OsmBugMenuController) WptPtMenuController(net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController) MapillaryMenuController(net.osmand.plus.mapillary.MapillaryMenuController) GpxItemMenuController(net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController) HistoryMenuController(net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController) ParkingPositionMenuController(net.osmand.plus.parkingpoint.ParkingPositionMenuController) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) TargetPointMenuController(net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController) AudioVideoNoteMenuController(net.osmand.plus.audionotes.AudioVideoNoteMenuController) AmenityMenuController(net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController) ImpassibleRoadsMenuController(net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController) EditPOIMenuController(net.osmand.plus.osmedit.EditPOIMenuController) FavouritePointMenuController(net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController) MyLocationMenuController(net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController) LatLon(net.osmand.data.LatLon) RenderedObject(net.osmand.NativeLibrary.RenderedObject) OpenStreetNote(net.osmand.plus.osmedit.OsmBugsLayer.OpenStreetNote) RouteDataObject(net.osmand.binary.RouteDataObject) Recording(net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording) WptPtMenuController(net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController) MapillaryMenuController(net.osmand.plus.mapillary.MapillaryMenuController)

Example 9 with TargetPoint

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

the class WaypointDialogHelper method sortAllTargets.

@SuppressLint("StaticFieldLeak")
public static void sortAllTargets(final OsmandApplication app, final Activity activity, final WaypointDialogHelper helper) {
    new AsyncTask<Void, Void, int[]>() {

        ProgressDialog dlg = null;

        long startDialogTime = 0;

        List<TargetPoint> intermediates;

        protected void onPreExecute() {
            startDialogTime = System.currentTimeMillis();
            dlg = new ProgressDialog(activity);
            dlg.setTitle("");
            dlg.setMessage(activity.getResources().getString(R.string.intermediate_items_sort_by_distance));
            dlg.show();
        }

        protected int[] doInBackground(Void[] params) {
            TargetPointsHelper targets = app.getTargetPointsHelper();
            intermediates = targets.getIntermediatePointsWithTarget();
            Location cll = app.getLocationProvider().getLastKnownLocation();
            ArrayList<TargetPoint> lt = new ArrayList<>(intermediates);
            TargetPoint start;
            if (cll != null) {
                LatLon ll = new LatLon(cll.getLatitude(), cll.getLongitude());
                start = TargetPoint.create(ll, null);
            } else if (app.getTargetPointsHelper().getPointToStart() != null) {
                TargetPoint ps = app.getTargetPointsHelper().getPointToStart();
                LatLon ll = new LatLon(ps.getLatitude(), ps.getLongitude());
                start = TargetPoint.create(ll, null);
            } else {
                start = lt.get(0);
            }
            TargetPoint end = lt.remove(lt.size() - 1);
            ArrayList<LatLon> al = new ArrayList<>();
            for (TargetPoint p : lt) {
                al.add(p.point);
            }
            return new TspAnt().readGraph(al, start.point, end.point).solve();
        }

        protected void onPostExecute(int[] result) {
            if (dlg != null) {
                long t = System.currentTimeMillis();
                if (t - startDialogTime < 500) {
                    app.runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            dlg.dismiss();
                        }
                    }, 500 - (t - startDialogTime));
                } else {
                    dlg.dismiss();
                }
            }
            List<TargetPoint> alocs = new ArrayList<>();
            for (int i : result) {
                if (i > 0) {
                    TargetPoint loc = intermediates.get(i - 1);
                    alocs.add(loc);
                }
            }
            intermediates.clear();
            intermediates.addAll(alocs);
            TargetPointsHelper targets = app.getTargetPointsHelper();
            List<TargetPoint> cur = targets.getIntermediatePointsWithTarget();
            boolean eq = true;
            for (int j = 0; j < cur.size() && j < intermediates.size(); j++) {
                if (cur.get(j) != intermediates.get(j)) {
                    eq = false;
                    break;
                }
            }
            if (!eq) {
                targets.reorderAllTargetPoints(intermediates, true);
            }
            if (helper.helperCallbacks != null) {
                helper.helperCallbacks.reloadAdapter();
            }
            updateRouteInfoMenu(activity);
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : ArrayList(java.util.ArrayList) TspAnt(net.osmand.TspAnt) ProgressDialog(android.app.ProgressDialog) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) List(java.util.List) ArrayList(java.util.ArrayList) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Location(net.osmand.Location) SuppressLint(android.annotation.SuppressLint)

Example 10 with TargetPoint

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

the class WaypointDialogHelper method updateWaypointItemView.

public static View updateWaypointItemView(final boolean edit, final List<LocationPointWrapper> deletedPoints, final OsmandApplication app, final Activity ctx, final WaypointDialogHelper helper, View v, final LocationPointWrapper point, final ArrayAdapter adapter, final boolean nightMode, final boolean flat) {
    if (v == null || v.findViewById(R.id.info_close) == null) {
        v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
    }
    updatePointInfoView(app, ctx, v, point, true, nightMode, edit, false);
    v.findViewById(R.id.all_points).setVisibility(View.GONE);
    final ImageView move = (ImageView) v.findViewById(R.id.info_move);
    final ImageButton remove = (ImageButton) v.findViewById(R.id.info_close);
    if (!edit) {
        remove.setVisibility(View.GONE);
        move.setVisibility(View.GONE);
    } else {
        boolean targets = point.type == WaypointHelper.TARGETS;
        boolean notFlatTargets = targets && !flat;
        boolean startPoint = notFlatTargets && ((TargetPoint) point.point).start;
        final TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
        boolean canRemove = !targets || !targetPointsHelper.getIntermediatePoints().isEmpty();
        int iconResId = nightMode ? R.color.marker_circle_button_color_dark : R.color.ctx_menu_title_color_dark;
        remove.setVisibility(View.VISIBLE);
        remove.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark, iconResId));
        remove.setEnabled(canRemove);
        remove.setAlpha(canRemove ? 1 : .5f);
        if (canRemove) {
            if (notFlatTargets && startPoint) {
                remove.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (targetPointsHelper.getPointToStart() == null) {
                            if (!targetPointsHelper.getIntermediatePoints().isEmpty()) {
                                replaceStartWithFirstIntermediate(targetPointsHelper, ctx, helper);
                            }
                        } else {
                            targetPointsHelper.setStartPoint(null, true, null);
                            updateControls(ctx, helper);
                        }
                    }
                });
            } else {
                remove.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        deletePoint(app, ctx, adapter, helper, point, deletedPoints, true);
                    }
                });
            }
        }
        move.setVisibility(notFlatTargets ? View.VISIBLE : View.GONE);
        if (notFlatTargets) {
            move.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_reorder, iconResId));
            move.setTag(new DragIcon() {

                @Override
                public void onClick() {
                // do nothing
                }
            });
        }
    }
    return v;
}
Also used : ImageButton(android.widget.ImageButton) DragIcon(net.osmand.plus.views.controls.DynamicListView.DragIcon) ImageView(android.widget.ImageView) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) SuppressLint(android.annotation.SuppressLint) FavouritePoint(net.osmand.data.FavouritePoint)

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