Search in sources :

Example 11 with TargetPointsHelper

use of net.osmand.plus.TargetPointsHelper 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 12 with TargetPointsHelper

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

the class ExternalApiHelper method startNavigation.

private void startNavigation(GPXFile gpx, LatLon from, PointDescription fromDesc, LatLon to, PointDescription toDesc, ApplicationMode mode) {
    OsmandApplication app = mapActivity.getMyApplication();
    RoutingHelper routingHelper = app.getRoutingHelper();
    if (gpx == null) {
        app.getSettings().APPLICATION_MODE.set(mode);
        final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
        targets.removeAllWayPoints(false, true);
        targets.navigateToPoint(to, true, -1, toDesc);
    }
    mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpx, from, fromDesc, true, false);
    if (!app.getTargetPointsHelper().checkPointToNavigateShort()) {
        mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().show();
    } else {
        if (app.getSettings().APPLICATION_MODE.get() != routingHelper.getAppMode()) {
            app.getSettings().APPLICATION_MODE.set(routingHelper.getAppMode());
        }
        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);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 13 with TargetPointsHelper

use of net.osmand.plus.TargetPointsHelper 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 14 with TargetPointsHelper

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

Example 15 with TargetPointsHelper

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

Aggregations

TargetPointsHelper (net.osmand.plus.TargetPointsHelper)36 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)19 LatLon (net.osmand.data.LatLon)18 PointDescription (net.osmand.data.PointDescription)11 TextView (android.widget.TextView)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 RoutingHelper (net.osmand.plus.routing.RoutingHelper)8 View (android.view.View)7 Location (net.osmand.Location)7 ImageView (android.widget.ImageView)5 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 AdapterView (android.widget.AdapterView)4 ArrayList (java.util.ArrayList)4 ApplicationMode (net.osmand.plus.ApplicationMode)4 Paint (android.graphics.Paint)3 Bundle (android.os.Bundle)3 ImageButton (android.widget.ImageButton)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2