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