Search in sources :

Example 26 with TargetPointsHelper

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

the class DirectionsDialogs method directionsToDialogAndLaunchMap.

public static void directionsToDialogAndLaunchMap(final Activity act, final double lat, final double lon, final PointDescription name) {
    final OsmandApplication ctx = (OsmandApplication) act.getApplication();
    final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
    if (targetPointsHelper.getIntermediatePoints().size() > 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(act);
        builder.setTitle(R.string.new_directions_point_dialog);
        builder.setItems(new String[] { act.getString(R.string.keep_intermediate_points), act.getString(R.string.clear_intermediate_points) }, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (which == 1) {
                    targetPointsHelper.clearPointToNavigate(false);
                }
                ctx.getSettings().navigateDialog();
                targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
                MapActivity.launchMapActivityMoveToTop(act);
            }
        });
        builder.show();
    } else {
        ctx.getSettings().navigateDialog();
        targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1, name);
        MapActivity.launchMapActivityMoveToTop(act);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) LatLon(net.osmand.data.LatLon) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 27 with TargetPointsHelper

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

the class IntermediatePointsDialog method commitChangePointsOrder.

private static void commitChangePointsOrder(OsmandApplication app, List<TargetPoint> target) {
    TargetPointsHelper targets = app.getTargetPointsHelper();
    List<TargetPoint> 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, true);
    }
}
Also used : TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint)

Example 28 with TargetPointsHelper

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

the class IntermediatePointsDialog method openIntermediatePointsDialog.

public static void openIntermediatePointsDialog(final Activity activity, final OsmandApplication app, final boolean changeOrder) {
    TargetPointsHelper targets = app.getTargetPointsHelper();
    final List<TargetPoint> intermediates = targets.getIntermediatePointsWithTarget();
    final TIntArrayList originalPositions = new TIntArrayList(intermediates.size());
    for (int j = 1; j <= intermediates.size(); j++) {
        originalPositions.add(j);
    }
    final boolean[] checkedIntermediates = new boolean[intermediates.size()];
    Arrays.fill(checkedIntermediates, true);
    final ArrayAdapter<TargetPoint> listadapter = getListAdapter(app, activity, changeOrder, intermediates, originalPositions, 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();
                TargetPoint 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();
            }
        }
    });
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setView(contentView);
    builder.setInverseBackgroundForced(true);
    lv.setBackgroundColor(Color.WHITE);
    builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (changeOrder) {
                commitChangePointsOrder(app, intermediates);
            } 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, listadapter, pb, textInfo);
    }
    dlg.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) DialogInterface(android.content.DialogInterface) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) TIntArrayList(gnu.trove.list.array.TIntArrayList) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ListView(android.widget.ListView) TextView(android.widget.TextView) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) ProgressBar(android.widget.ProgressBar) LinearLayout(android.widget.LinearLayout)

Example 29 with TargetPointsHelper

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

the class MapActivityActions method enterRoutePlanningModeGivenGpx.

public void enterRoutePlanningModeGivenGpx(GPXFile gpxFile, LatLon from, PointDescription fromName, boolean useIntermediatePointsByDefault, boolean showDialog) {
    settings.USE_INTERMEDIATE_POINTS_NAVIGATION.set(useIntermediatePointsByDefault);
    OsmandApplication app = mapActivity.getMyApplication();
    TargetPointsHelper targets = app.getTargetPointsHelper();
    ApplicationMode mode = getRouteMode(from);
    // app.getSettings().APPLICATION_MODE.set(mode);
    app.getRoutingHelper().setAppMode(mode);
    app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false);
    // save application mode controls
    settings.FOLLOW_THE_ROUTE.set(false);
    app.getRoutingHelper().setFollowingMode(false);
    app.getRoutingHelper().setRoutePlanningMode(true);
    // reset start point
    targets.setStartPoint(from, false, fromName);
    // then set gpx
    setGPXRouteParams(gpxFile);
    // then update start and destination point
    targets.updateRouteAndRefresh(true);
    mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
    mapActivity.getMapView().refreshMap(true);
    if (showDialog) {
        mapActivity.getMapLayers().getMapControlsLayer().showDialog();
    }
    if (targets.hasTooLongDistanceToNavigate()) {
        app.showToastMessage(R.string.route_is_too_long_v2);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ApplicationMode(net.osmand.plus.ApplicationMode) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

Example 30 with TargetPointsHelper

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

the class MapActivityActions method addAsTarget.

public void addAsTarget(double latitude, double longitude, PointDescription pd) {
    TargetPointsHelper targets = getMyApplication().getTargetPointsHelper();
    targets.navigateToPoint(new LatLon(latitude, longitude), true, targets.getIntermediatePoints().size() + 1, pd);
    openIntermediatePointsDialog();
}
Also used : LatLon(net.osmand.data.LatLon) TargetPointsHelper(net.osmand.plus.TargetPointsHelper)

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