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);
}
}
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);
}
}
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();
}
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);
}
}
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();
}
Aggregations