diff --git a/OsmAnd/res/drawable-hdpi/av_download.png b/OsmAnd/res/drawable-hdpi/av_download.png new file mode 100644 index 0000000000..5bceafb1e3 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/av_download.png differ diff --git a/OsmAnd/res/drawable-hdpi/av_upload.png b/OsmAnd/res/drawable-hdpi/av_upload.png new file mode 100644 index 0000000000..d30ee8a830 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/av_upload.png differ diff --git a/OsmAnd/res/drawable-mdpi/av_download.png b/OsmAnd/res/drawable-mdpi/av_download.png new file mode 100644 index 0000000000..678ecfad45 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/av_download.png differ diff --git a/OsmAnd/res/drawable-mdpi/av_upload.png b/OsmAnd/res/drawable-mdpi/av_upload.png new file mode 100644 index 0000000000..9e3f74504f Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/av_upload.png differ diff --git a/OsmAnd/res/layout/change_order_item.xml b/OsmAnd/res/layout/change_order_item.xml new file mode 100644 index 0000000000..99100ed7b1 --- /dev/null +++ b/OsmAnd/res/layout/change_order_item.xml @@ -0,0 +1,25 @@ + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/layers_list_activity_item.xml b/OsmAnd/res/layout/layers_list_activity_item.xml index 7e6c734927..f87bf0f132 100644 --- a/OsmAnd/res/layout/layers_list_activity_item.xml +++ b/OsmAnd/res/layout/layers_list_activity_item.xml @@ -7,7 +7,7 @@ android:layout_marginTop="2dip" android:layout_marginLeft="5dip" android:layout_marginRight="5dip" - android:weightSum="1" > + android:weightSum="1" android:background="@color/color_white"> ps, List ds) { + public boolean saveIntermediatePoints(List ps, List ds) { StringBuilder sb = new StringBuilder(); for(int i=0; i 0){ diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java new file mode 100644 index 0000000000..fdcbc4fa8e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java @@ -0,0 +1,192 @@ +package net.osmand.plus; + +import java.util.ArrayList; +import java.util.List; + +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.Context; +import android.content.DialogInterface; +import android.location.Location; +import android.widget.Toast; + +import net.osmand.access.AccessibleToast; +import net.osmand.osm.LatLon; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.routing.RoutingHelper; + +public class TargetPointsHelper { + + private List intermediatePoints = new ArrayList(); + private List intermediatePointNames = new ArrayList(); + private LatLon pointToNavigate = null; + private OsmandSettings settings; + private RoutingHelper routingHelper; + + public TargetPointsHelper(OsmandSettings settings, RoutingHelper routingHelper){ + this.settings = settings; + this.routingHelper = routingHelper; + readFromSettings(settings); + } + + private void readFromSettings(OsmandSettings settings) { + pointToNavigate = settings.getPointToNavigate(); + intermediatePoints.clear(); + intermediatePointNames.clear(); + intermediatePoints.addAll(settings.getIntermediatePoints()); + intermediatePointNames.addAll(settings.getIntermediatePointDescriptions(intermediatePoints.size())); + } + + public LatLon getPointToNavigate() { + return pointToNavigate; + } + + public String getPointNavigateDescription(){ + return settings.getPointNavigateDescription(); + } + + public List getIntermediatePointNames() { + return intermediatePointNames; + } + + public List getIntermediatePoints() { + return intermediatePoints; + } + + public List getIntermediatePointsWithTarget() { + List res = new ArrayList(); + res.addAll(intermediatePoints); + if(pointToNavigate != null) { + res.add(pointToNavigate); + } + return res; + } + + public List getIntermediatePointNamesWithTarget() { + List res = new ArrayList(); + res.addAll(intermediatePointNames); + if(pointToNavigate != null) { + res.add(getPointNavigateDescription()); + } + return res; + } + + public LatLon getFirstIntermediatePoint(){ + if(intermediatePoints.size() > 0) { + return intermediatePoints.get(0); + } + return null; + } + + + public void removeWayPoint(MapActivity map, boolean updateRoute, int index){ + if(index < 0){ + settings.clearPointToNavigate(); + pointToNavigate = null; + if(intermediatePoints.size() > 0) { + settings.deleteIntermediatePoint(intermediatePoints.size() - 1); + pointToNavigate = intermediatePoints.remove(intermediatePoints.size() - 1); + settings.setPointToNavigate(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), + intermediatePointNames.remove(intermediatePoints.size() - 1)); + } + } else { + settings.deleteIntermediatePoint(index); + intermediatePoints.remove(index); + intermediatePointNames.remove(index); + } + updateRouteAndReferesh(map, updateRoute); + } + + private void updateRouteAndReferesh(MapActivity map, boolean updateRoute) { + if(updateRoute && ( routingHelper.isRouteBeingCalculated() || routingHelper.isRouteCalculated() || + routingHelper.isFollowingMode())) { + Location lastKnownLocation = map == null ? routingHelper.getLastProjection() : map.getLastKnownLocation(); + routingHelper.setFinalAndCurrentLocation(settings.getPointToNavigate(), + settings.getIntermediatePoints(), lastKnownLocation, routingHelper.getCurrentGPXRoute()); + } + if(map != null) { + map.getMapView().refreshMap(); + } + } + + + public void clearPointToNavigate(MapActivity map, boolean updateRoute) { + settings.clearPointToNavigate(); + settings.clearIntermediatePoints(); + readFromSettings(settings); + updateRouteAndReferesh(map, updateRoute); + } + + public void reorderAllTargetPoints(MapActivity map, List point, + List names, boolean updateRoute){ + settings.clearPointToNavigate(); + if (point.size() > 0) { + settings.saveIntermediatePoints(point.subList(0, point.size() - 1), names.subList(0, point.size() - 1)); + LatLon p = point.get(point.size() - 1); + String nm = names.get(point.size() - 1); + settings.setPointToNavigate(p.getLatitude(), p.getLongitude(), nm); + } else { + settings.clearIntermediatePoints(); + } + readFromSettings(settings); + updateRouteAndReferesh(map, updateRoute); + } + + public void navigateToPoint(MapActivity map, LatLon point, boolean updateRoute, int intermediate){ + if(point != null){ + if(intermediate < 0) { + settings.setPointToNavigate(point.getLatitude(), point.getLongitude(), null); + } else { + settings.insertIntermediatePoint(point.getLatitude(), point.getLongitude(), null, + intermediate, false); + } + } else { + settings.clearPointToNavigate(); + settings.clearIntermediatePoints(); + } + readFromSettings(settings); + updateRouteAndReferesh(map, updateRoute); + + } + + public boolean checkPointToNavigate(Context ctx ){ + if(pointToNavigate == null){ + AccessibleToast.makeText(ctx, R.string.mark_final_location_first, Toast.LENGTH_LONG).show(); + return false; + } + return true; + } + + public void navigatePointDialogAndLaunchMap(final Context ctx, final double lat, final double lon, final String name){ + if(pointToNavigate != null) { + Builder builder = new AlertDialog.Builder(ctx); + builder.setTitle(R.string.new_destination_point_dialog); + builder.setItems(new String[] { + ctx.getString(R.string.replace_destination_point), + ctx.getString(R.string.add_as_first_destination_point), + ctx.getString(R.string.add_as_last_destination_point) + }, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if(which == 0) { + settings.setPointToNavigate(lat, lon, true, name); + } else if(which == 2) { + int sz = intermediatePoints.size(); + LatLon pt = pointToNavigate; + settings.insertIntermediatePoint(pt.getLatitude(), pt.getLongitude(), + settings.getPointNavigateDescription(), sz, true); + settings.setPointToNavigate(lat, lon, true, name); + } else { + settings.insertIntermediatePoint(lat, lon, name, 0, true); + } + readFromSettings(settings); + MapActivity.launchMapActivityMoveToTop(ctx); + } + }); + builder.show(); + } else { + settings.setPointToNavigate(lat, lon, true, name); + MapActivity.launchMapActivityMoveToTop(ctx); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java b/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java new file mode 100644 index 0000000000..2b39397728 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java @@ -0,0 +1,189 @@ +package net.osmand.plus.activities; + +import java.util.ArrayList; +import java.util.List; + +import net.osmand.OsmAndFormatter; +import net.osmand.access.AccessibleAlertBuilder; +import net.osmand.osm.LatLon; +import net.osmand.osm.MapUtils; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; +import net.osmand.plus.views.AnimateDraggingMapThread; +import android.app.AlertDialog.Builder; +import android.content.DialogInterface; +import android.graphics.Color; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.CompoundButton; +import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.ImageButton; +import android.widget.ListView; +import android.widget.TextView; + +public class IntermediatePointsDialog { + + + public static void openIntermediatePointsDialog(MapActivity mapActivity, OsmandApplication app){ + openIntermediatePointsDialog(mapActivity, app, false); + } + + public static void openIntermediatePointsDialog(final MapActivity mapActivity, + final OsmandApplication app, final boolean changeOrder){ + TargetPointsHelper targets = app.getTargetPointsHelper(); + final List intermediates = targets.getIntermediatePointsWithTarget(); + final List names = targets.getIntermediatePointNamesWithTarget(); + final boolean[] checkedIntermediates = new boolean[intermediates.size()]; + final ArrayAdapter listadapter = new ArrayAdapter(app, + changeOrder? R.layout.change_order_item : R.layout.layers_list_activity_item, R.id.title, + intermediates) { + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + + // User super class to create the View + View v = super.getView(position, convertView, parent); + TextView tv = (TextView) v.findViewById(R.id.title); + String nm = (position + 1) + ". "; + String distString = ""; + if(mapActivity != null) { + double lat = mapActivity.getMapView().getLatitude(); + double lon = mapActivity.getMapView().getLongitude(); + double meters = MapUtils.getDistance(intermediates.get(position), lat, lon); + distString = OsmAndFormatter.getFormattedDistance((float) meters, mapActivity); + } + + nm += app.getString(R.string.target_point, distString); + String descr = names.get(position); + if(descr != null && descr.trim().length() > 0) { + nm += "\n" + descr; + } + tv.setText(nm); + checkedIntermediates[position] = true; + if (changeOrder) { + ((ImageButton) v.findViewById(R.id.up)).setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View v) { + if(position > 0) { + LatLon old = intermediates.remove(position - 1); + String oldN = names.remove(position - 1); + names.add(position, oldN); + intermediates.add(position, old); + notifyDataSetInvalidated(); + } + } + }); + ((ImageButton) v.findViewById(R.id.down)).setOnClickListener(new View.OnClickListener(){ + @Override + public void onClick(View v) { + if(position < intermediates.size() - 1) { + LatLon old = intermediates.remove(position + 1); + String oldN = names.remove(position + 1); + names.add(position, oldN); + intermediates.add(position, old); + notifyDataSetInvalidated(); + } + } + }); + } else if (position == intermediates.size() - 1) { + tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.list_view_set_destination, 0, 0, 0); + final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item)); + ch.setVisibility(View.GONE); + } else { + // list_view_set_intermediate + tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.list_view_set_intermediate, 0, 0, 0); + final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item)); + ch.setVisibility(View.VISIBLE); + ch.setChecked(true); + ch.setOnCheckedChangeListener(new OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + checkedIntermediates[position] = isChecked; + } + }); + } + return v; + } + }; + ListView lv = new ListView(app); + lv.setAdapter(listadapter); + lv.setBackgroundColor(Color.WHITE); + lv.setOnItemClickListener(new OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + if (mapActivity != null) { + // AnimateDraggingMapThread thread = mapActivity.getMapView().getAnimatedDraggingThread(); + LatLon pointToNavigate = intermediates.get(position); + float fZoom = mapActivity.getMapView().getFloatZoom() < 15 ? 15 : mapActivity.getMapView().getFloatZoom(); + // thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true); + mapActivity.getMapView().setZoom(fZoom); + mapActivity.getMapView().setLatLon(pointToNavigate.getLatitude(), pointToNavigate.getLongitude()); + listadapter.notifyDataSetInvalidated(); + } + } + }); + + Builder builder = new AccessibleAlertBuilder(app); + builder.setView(lv); + builder.setInverseBackgroundForced(true); + builder.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if(changeOrder) { + commitChangePointsOrder(app, mapActivity, intermediates, names); + } else { + commitPointsRemoval(app, mapActivity, checkedIntermediates); + } + + } + }); + if (!changeOrder) { + builder.setNeutralButton("Change order", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + openIntermediatePointsDialog(mapActivity, app, true); + } + }); + } + builder.show(); + } + + private static void commitPointsRemoval(OsmandApplication app, final MapActivity mapActivity, final boolean[] checkedIntermediates) { + int cnt = 0; + for (int i = checkedIntermediates.length - 1; i >= 0; i--) { + if (!checkedIntermediates[i]) { + cnt++; + } + } + if (cnt > 0) { + for (int i = checkedIntermediates.length - 1; i >= 0; i--) { + if (!checkedIntermediates[i]) { + cnt--; + app.getTargetPointsHelper().removeWayPoint(mapActivity, cnt == 0, i); + } + } + if(mapActivity != null) { + mapActivity.getMapLayers().getContextMenuLayer().setLocation(null, ""); + } + } + } + + private static void commitChangePointsOrder(OsmandApplication app, final MapActivity mapActivity, List target, List names) { + TargetPointsHelper targets = app.getTargetPointsHelper(); + List 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(mapActivity, target, names, true); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index e2ec769ab1..7ad2394f2b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -28,6 +28,7 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.ResourceManager; +import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.routing.RouteProvider.GPXRouteParams; import net.osmand.plus.routing.RoutingHelper; @@ -207,7 +208,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe // This situtation could be when navigation suddenly crashed and after restarting // it tries to continue the last route if(settings.FOLLOW_THE_ROUTE.get() && !routingHelper.isRouteCalculated()){ - restoreRoutingMode(settings.getPointToNavigate(), settings.getIntermediatePoints()); + restoreRoutingMode(); } mapView.setMapLocationListener(this); @@ -285,7 +286,6 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe setRequestedOrientation(settings.MAP_SCREEN_ORIENTATION.get()); // can't return from this method we are not sure if activity will be recreated or not } - mapLayers.getNavigationLayer().setPointToNavigate(settings.getPointToNavigate(), settings.getIntermediatePoints()); Location loc = getLastKnownLocation(); if (loc != null && (System.currentTimeMillis() - loc.getTime()) > 30 * 1000) { @@ -307,13 +307,14 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe mapLayers.getMapInfoLayer().getBackToLocation().setEnabled(false); - // if destination point was changed try to recalculate route + // if destination point was changed try to recalculate route + TargetPointsHelper targets = getTargetPoints(); if (routingHelper.isFollowingMode() && ( - !Algoritms.objectEquals(settings.getPointToNavigate(), routingHelper.getFinalLocation() )|| - !Algoritms.objectEquals(settings.getIntermediatePoints(), routingHelper.getIntermediatePoints()) + !Algoritms.objectEquals(targets.getPointToNavigate(), routingHelper.getFinalLocation() )|| + !Algoritms.objectEquals(targets.getIntermediatePoints(), routingHelper.getIntermediatePoints()) )) { - routingHelper.setFinalAndCurrentLocation(settings.getPointToNavigate(), - settings.getIntermediatePoints(), + routingHelper.setFinalAndCurrentLocation(targets.getPointToNavigate(), + targets.getIntermediatePoints(), getLastKnownLocation(), routingHelper.getCurrentGPXRoute()); } @@ -385,8 +386,10 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe mapView.refreshMap(changed); } - private void restoreRoutingMode(final LatLon pointToNavigate, final List intermediates) { + private void restoreRoutingMode() { final String gpxPath = settings.FOLLOW_THE_GPX_ROUTE.get(); + final TargetPointsHelper targetPoints = getTargetPoints(); + final LatLon pointToNavigate = targetPoints.getPointToNavigate(); if (pointToNavigate == null && gpxPath == null) { notRestoreRoutingMode(); } else { @@ -475,7 +478,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe if (endPoint == null) { notRestoreRoutingMode(); } else { - followRoute(settings.getApplicationMode(), endPoint, intermediates, startPoint, gpxRoute); + followRoute(settings.getApplicationMode(), endPoint, targetPoints.getIntermediatePoints(), startPoint, gpxRoute); } } }; @@ -674,7 +677,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe } private void emitNavigationHint() { - final LatLon point = settings.getPointToNavigate(); + final LatLon point = getTargetPoints().getPointToNavigate(); if (point != null) { if (routingHelper.isRouteCalculated()) { routingHelper.getVoiceRouter().announceCurrentDirection(getLastKnownLocation()); @@ -985,16 +988,6 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe return zoomDelta; } - public void removeIntermediatePoint(boolean updateRoute, int index){ - mapLayers.getNavigationLayer().getIntermediatePoints().remove(index); - settings.deleteIntermediatePoint(index); - if(updateRoute && ( routingHelper.isRouteBeingCalculated() || routingHelper.isRouteCalculated() || - routingHelper.isFollowingMode())) { - routingHelper.setFinalAndCurrentLocation(settings.getPointToNavigate(), - settings.getIntermediatePoints(), getLastKnownLocation(), routingHelper.getCurrentGPXRoute()); - } - mapView.refreshMap(); - } public void followRoute(ApplicationMode appMode, LatLon finalLocation, List intermediatePoints, Location currentLocation, GPXRouteParams gpxRoute){ // change global settings @@ -1016,25 +1009,6 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe getMyApplication().showDialogInitializingCommandPlayer(MapActivity.this); } - public void navigateToPoint(LatLon point, boolean updateRoute, int intermediate){ - if(point != null){ - if(intermediate < 0) { - settings.setPointToNavigate(point.getLatitude(), point.getLongitude(), null); - } else { - settings.insertIntermediatePoint(point.getLatitude(), point.getLongitude(), null, - intermediate, false); - } - } else { - settings.clearPointToNavigate(); - settings.clearIntermediatePoints(); - } - if(updateRoute && ( routingHelper.isRouteBeingCalculated() || routingHelper.isRouteCalculated() || - routingHelper.isFollowingMode())) { - routingHelper.setFinalAndCurrentLocation(settings.getPointToNavigate(), - settings.getIntermediatePoints(), getLastKnownLocation(), routingHelper.getCurrentGPXRoute()); - } - mapLayers.getNavigationLayer().setPointToNavigate(settings.getPointToNavigate(), settings.getIntermediatePoints()); - } public Location getLastKnownLocation(){ if(mapLayers.getLocationLayer() == null) { @@ -1047,21 +1021,12 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe return new LatLon(mapView.getLatitude(), mapView.getLongitude()); } + public TargetPointsHelper getTargetPoints(){ + return getMyApplication().getTargetPointsHelper(); + } + public LatLon getPointToNavigate(){ - return mapLayers.getNavigationLayer().getPointToNavigate(); - } - - public List getIntermediatePoints(){ - return mapLayers.getNavigationLayer().getIntermediatePoints(); - } - - - public LatLon getFirstIntermediatePoint(){ - List ip = mapLayers.getNavigationLayer().getIntermediatePoints(); - if(ip.size() > 0) { - return ip.get(0); - } - return null; + return getTargetPoints().getPointToNavigate(); } public RoutingHelper getRoutingHelper() { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 9d08910fdf..c2b88fb89a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -15,7 +15,6 @@ import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.FavouritePoint; import net.osmand.GPXUtilities; -import net.osmand.OsmAndFormatter; import net.osmand.GPXUtilities.GPXFile; import net.osmand.LogUtil; import net.osmand.Version; @@ -36,10 +35,10 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.ResourceManager; +import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.routing.RouteProvider.GPXRouteParams; import net.osmand.plus.routing.RoutingHelper; -import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.BaseMapLayer; import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.OsmandMapTileView; @@ -50,7 +49,6 @@ import android.app.Dialog; import android.app.ProgressDialog; import android.content.ActivityNotFoundException; import android.content.ComponentName; -import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnMultiChoiceClickListener; import android.content.Intent; @@ -77,7 +75,6 @@ import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; -import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ListAdapter; @@ -462,15 +459,6 @@ public class MapActivityActions implements DialogProvider { } - private boolean checkPointToNavigate(){ - MapActivityLayers mapLayers = mapActivity.getMapLayers(); - if(mapLayers.getNavigationLayer().getPointToNavigate() == null){ - AccessibleToast.makeText(mapActivity, R.string.mark_final_location_first, Toast.LENGTH_LONG).show(); - return false; - } - return true; - } - public String getRoutePointDescription(double lat, double lon) { return mapActivity.getString(R.string.route_descr_lat_lon, lat, lon); } @@ -491,22 +479,23 @@ public class MapActivityActions implements DialogProvider { from = getRoutePointDescription(fromOrCurrent.getLatitude(), fromOrCurrent.getLongitude()); } - + TargetPointsHelper targets = mapActivity.getTargetPoints(); String tos; if(to == null) { - tos = getRoutePointDescription(mapActivity.getPointToNavigate(), - settings.getPointNavigateDescription()); + tos = getRoutePointDescription(targets.getPointToNavigate(), + targets.getPointNavigateDescription()); } else { tos = getRoutePointDescription(to, ""); } - int sz = mapActivity.getIntermediatePoints().size(); + + int sz = targets.getIntermediatePoints().size(); if(sz == 0) { return mapActivity.getString(R.string.route_descr_from_to, from, tos); } else { String via = ""; - List names = settings.getIntermediatePointDescriptions(sz); + List names = targets.getIntermediatePointNames(); for (int i = 0; i < sz ; i++) { - via += "\n - " + getRoutePointDescription(mapActivity.getIntermediatePoints().get(i), + via += "\n - " + getRoutePointDescription(targets.getIntermediatePoints().get(i), names.get(i)); } return mapActivity.getString(R.string.route_descr_from_to_via, from, via, tos); @@ -516,9 +505,8 @@ public class MapActivityActions implements DialogProvider { public void getDirections(final Location fromOrCurrent, final LatLon to, boolean gpxRouteEnabled) { - final RoutingHelper routingHelper = mapActivity.getRoutingHelper(); - Builder builder = new AlertDialog.Builder(mapActivity); + final TargetPointsHelper targets = mapActivity.getTargetPoints(); View view = mapActivity.getLayoutInflater().inflate(R.layout.calculate_route, null); final CheckBox nonoptimal = (CheckBox) view.findViewById(R.id.OptimalCheckox); @@ -577,14 +565,14 @@ public class MapActivityActions implements DialogProvider { DialogInterface.OnClickListener onlyShowCall = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - if(to != null) { - mapActivity.navigateToPoint(to, false, -1); + if (to != null) { + targets.navigateToPoint(mapActivity, to, false, -1); } - if (!checkPointToNavigate()) { + if (!targets.checkPointToNavigate(mapActivity)) { return; } Location from = fromOrCurrent; - if(from == null) { + if (from == null) { from = mapActivity.getLastKnownLocation(); } if (from == null) { @@ -592,7 +580,8 @@ public class MapActivityActions implements DialogProvider { return; } - // PREV_APPLICATION_MODE also needs to be set here to overwrite possibly outdated value from prior follow-navigation in different profile + // PREV_APPLICATION_MODE also needs to be set here to overwrite possibly outdated value from prior follow-navigation in + // different profile // Do not overwrite PREV_APPLICATION_MODE if already navigating if (!routingHelper.isFollowingMode()) { settings.PREV_APPLICATION_MODE.set(settings.APPLICATION_MODE.get()); @@ -604,8 +593,7 @@ public class MapActivityActions implements DialogProvider { settings.FOLLOW_THE_ROUTE.set(false); settings.FOLLOW_THE_GPX_ROUTE.set(null); routingHelper.setFollowingMode(false); - routingHelper.setFinalAndCurrentLocation(mapActivity.getPointToNavigate(), - mapActivity.getIntermediatePoints(),from, null); + routingHelper.setFinalAndCurrentLocation(targets.getPointToNavigate(), targets.getIntermediatePoints(), from, null); } }; @@ -613,9 +601,9 @@ public class MapActivityActions implements DialogProvider { @Override public void onClick(DialogInterface dialog, int which) { if(to != null) { - mapActivity.navigateToPoint(to, false, -1); + targets.navigateToPoint(mapActivity, to, false, -1); } - if (!checkPointToNavigate()) { + if (!targets.checkPointToNavigate(mapActivity)) { return; } boolean msg = true; @@ -638,7 +626,7 @@ public class MapActivityActions implements DialogProvider { ApplicationMode mode = getAppMode(buttons, settings); settings.OPTIMAL_ROUTE_MODE.setModeValue(mode, !nonoptimal.isChecked()); dialog.dismiss(); - mapActivity.followRoute(mode, mapActivity.getPointToNavigate(), mapActivity.getIntermediatePoints(), + mapActivity.followRoute(mode, targets.getPointToNavigate(), targets.getIntermediatePoints(), current, null); } }; @@ -647,7 +635,7 @@ public class MapActivityActions implements DialogProvider { @Override public void onClick(DialogInterface dialog, int which) { if(to != null) { - mapActivity.navigateToPoint(to, false, -1); + targets.navigateToPoint(mapActivity, to, false, -1); } ApplicationMode mode = getAppMode(buttons, settings); navigateUsingGPX(mode); @@ -712,8 +700,8 @@ public class MapActivityActions implements DialogProvider { endPoint = point; } if(endPoint != null) { - settings.setPointToNavigate(point.getLatitude(), point.getLongitude(), null); - mapLayers.getNavigationLayer().setPointToNavigate(point, new ArrayList()); + mapActivity.getTargetPoints().navigateToPoint( + mapActivity, point, false, -1); } } if(endPoint != null){ @@ -820,8 +808,9 @@ public class MapActivityActions implements DialogProvider { adapter.registerItem(R.string.context_menu_item_navigate_point, R.drawable.list_view_set_destination); adapter.registerItem(R.string.context_menu_item_directions, R.drawable.list_activities_directions_to_here); - if(settings.getPointToNavigate() != null) { - if(mapActivity.getIntermediatePoints().size() == 0) { + final TargetPointsHelper targets = mapActivity.getTargetPoints(); + if(targets.getPointToNavigate() != null) { + if(targets.getIntermediatePoints().size() == 0) { adapter.registerItem(R.string.context_menu_item_intermediate_point, R.drawable.list_view_set_intermediate); } else { adapter.registerItem(R.string.context_menu_item_first_intermediate_point, R.drawable.list_view_set_intermediate); @@ -874,23 +863,27 @@ public class MapActivityActions implements DialogProvider { intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); mapActivity.startActivity(intent); } else if (standardId == R.string.context_menu_item_navigate_point) { - mapActivity.navigateToPoint(new LatLon(latitude, longitude), true, -1); + mapActivity.getTargetPoints().navigateToPoint(mapActivity, + new LatLon(latitude, longitude), true, -1); } else if (standardId == R.string.context_menu_item_directions) { // always enable and follow and let calculate it (GPS is not accessible in garage) getDirections(null, new LatLon(latitude, longitude), true); } else if (standardId == R.string.context_menu_item_show_route) { - if (checkPointToNavigate()) { + if (targets.checkPointToNavigate(mapActivity)) { Location loc = new Location("map"); loc.setLatitude(latitude); loc.setLongitude(longitude); getDirections(loc, null, true); } } else if (standardId == R.string.context_menu_item_intermediate_point) { - mapActivity.navigateToPoint(new LatLon(latitude, longitude), true, mapActivity.getIntermediatePoints().size()); + targets.navigateToPoint(mapActivity, + new LatLon(latitude, longitude), true, targets.getIntermediatePoints().size()); } else if (standardId == R.string.context_menu_item_first_intermediate_point) { - mapActivity.navigateToPoint(new LatLon(latitude, longitude), true, 0); + targets.navigateToPoint(mapActivity, + new LatLon(latitude, longitude), true, 0); } else if (standardId == R.string.context_menu_item_last_intermediate_point) { - mapActivity.navigateToPoint(new LatLon(latitude, longitude), true, mapActivity.getIntermediatePoints().size()); + targets.navigateToPoint(mapActivity, + new LatLon(latitude, longitude), true, targets.getIntermediatePoints().size()); } else if (standardId == R.string.context_menu_item_share_location) { shareLocation(latitude, longitude, mapActivity.getMapView().getZoom()); } else if (standardId == R.string.context_menu_item_add_favorite) { @@ -1038,7 +1031,7 @@ public class MapActivityActions implements DialogProvider { new OnOptionsMenuClick() { @Override public void prepareOptionsMenu(Menu menu, MenuItem navigateToPointMenu) { - if (settings.getPointToNavigate() != null) { + if (mapActivity.getPointToNavigate() != null) { navigateToPointMenu.setTitle((routingHelper.isRouteCalculated() || routingHelper.isFollowingMode() || routingHelper.isRouteBeingCalculated()) ? R.string.stop_routing : R.string.stop_navigation); navigateToPointMenu.setVisible(true); @@ -1056,7 +1049,7 @@ public class MapActivityActions implements DialogProvider { mapActivity.updateApplicationModeSettings(); mapView.refreshMap(changed); } else { - mapActivity.navigateToPoint(null, true, -1); + mapActivity.getTargetPoints().clearPointToNavigate(mapActivity, true); } mapView.refreshMap(); return true; @@ -1121,7 +1114,7 @@ public class MapActivityActions implements DialogProvider { optionsMenuHelper.registerOptionsMenuItem(R.string.target_points, R.string.target_points, new OnOptionsMenuClick() { @Override public void prepareOptionsMenu(Menu menu, MenuItem item) { - item.setVisible(mapActivity.getIntermediatePoints().size() > 0); + item.setVisible(mapActivity.getTargetPoints().getIntermediatePoints().size() > 0); } @Override public boolean onClick(MenuItem item) { @@ -1168,99 +1161,10 @@ public class MapActivityActions implements DialogProvider { } public void openIntermediatePointsDialog(){ - Builder builder = new AlertDialog.Builder(mapActivity); - final ArrayList intermediates = new ArrayList(mapActivity.getIntermediatePoints()); - final ArrayList names = new ArrayList(settings.getIntermediatePointDescriptions( - intermediates.size())); - final int targetPointInd = mapActivity.getPointToNavigate() == null ? -1 : intermediates.size(); - if(mapActivity.getPointToNavigate() != null) { - intermediates.add(mapActivity.getPointToNavigate()); - if(settings.getPointNavigateDescription() != null) { - names.add(settings.getPointNavigateDescription()); - } else { - names.add(""); - } - } - final List intermediateNames = new ArrayList(); - double lat = mapActivity.getMapView().getLatitude(); - double lon = mapActivity.getMapView().getLongitude(); - for (int i = 0; i < intermediates.size(); i++) { - double meters = MapUtils.getDistance(intermediates.get(i), lat, lon); - String distString = OsmAndFormatter.getFormattedDistance((float) meters, mapActivity); - String nm = (i+1)+". " + mapActivity.getString(R.string.target_point, distString); - String descr = names.get(i); - if(names.get(i) != null && descr.trim().length() > 0) { - nm += "\n" + descr; - } - intermediateNames.add(nm); - } - final boolean[] checkedIntermediates = new boolean[intermediateNames.size()]; - ListAdapter listadapter = new ArrayAdapter(mapActivity, R.layout.layers_list_activity_item, R.id.title, - intermediateNames) { - @Override - public View getView(final int position, View convertView, ViewGroup parent) { - // User super class to create the View - View v = super.getView(position, convertView, parent); - TextView tv = (TextView) v.findViewById(R.id.title); - tv.setText(intermediateNames.get(position)); - - checkedIntermediates[position] = true; - if(position == targetPointInd) { - tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.list_view_set_destination, 0, 0, 0); - final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item)); - ch.setVisibility(View.GONE); - } else { - tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.list_view_set_intermediate, 0, 0, 0); - final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item)); - ch.setVisibility(View.VISIBLE); - ch.setChecked(true); - ch.setOnCheckedChangeListener(new OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - checkedIntermediates[position] = isChecked; - } - }); - } - return v; - } - }; - builder.setAdapter(listadapter, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - AnimateDraggingMapThread thread = mapActivity.getMapView().getAnimatedDraggingThread(); - LatLon pointToNavigate = intermediates.get(which); - float fZoom = mapActivity.getMapView().getFloatZoom() < 15 ? 15 : mapActivity.getMapView().getFloatZoom(); - thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true); - } - }); - builder.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - int cnt = 0; - for (int i = checkedIntermediates.length - 1; i >= 0; i--) { - if (!checkedIntermediates[i]) { - cnt++; - } - } - if (cnt > 0) { - for (int i = checkedIntermediates.length - 1; i >= 0; i--) { - if (!checkedIntermediates[i]) { - cnt--; - mapActivity.removeIntermediatePoint(cnt == 0, i); - if (cnt == 0) { - mapActivity.getMapView().refreshMap(); - } - } - } - mapActivity.getMapLayers().getContextMenuLayer().setLocation(null, ""); - } - - } - }); - builder.show(); + IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity, mapActivity.getMyApplication()); } + + private void startGpsStatusIntent() { Intent intent = new Intent(); @@ -1306,7 +1210,7 @@ public class MapActivityActions implements DialogProvider { mapActivity.backToLocationImpl(); break; case 1: - mapActivity.getNavigationInfo().show(settings.getPointToNavigate(), + mapActivity.getNavigationInfo().show(mapActivity.getPointToNavigate(), mapActivity.getMapLayers().getLocationLayer().getHeading()); break; default: @@ -1345,9 +1249,8 @@ public class MapActivityActions implements DialogProvider { if(onShow != null) { onShow.onClick(v); } - navigateToPoint(activity, location.getLatitude(), location.getLongitude(), name); -// app.getSettings().setPointToNavigate(location.getLatitude(), location.getLongitude(), name); -// MapActivity.launchMapActivityMoveToTop(activity); + app.getTargetPointsHelper().navigatePointDialogAndLaunchMap(activity, + location.getLatitude(), location.getLongitude(), name); qa.dismiss(); } }); @@ -1369,38 +1272,4 @@ public class MapActivityActions implements DialogProvider { // qa.addActionItem(directionsTo); } - public static void navigateToPoint(final Context activity, final double lat, final double lon, final String name){ - final OsmandApplication app = ((OsmandApplication) activity.getApplicationContext()); - if(app.getSettings().getPointToNavigate() != null) { - Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.new_destination_point_dialog); - builder.setItems(new String[] { - activity.getString(R.string.replace_destination_point), - activity.getString(R.string.add_as_first_destination_point), - activity.getString(R.string.add_as_last_destination_point) - }, new DialogInterface.OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - if(which == 0) { - app.getSettings().setPointToNavigate(lat, lon, true, name); - } else if(which == 2) { - int sz = app.getSettings().getIntermediatePoints().size(); -// app.getSettings().insertIntermediatePoint(lat, lon, name, sz); - LatLon pt = app.getSettings().getPointToNavigate(); - app.getSettings().insertIntermediatePoint(pt.getLatitude(), pt.getLongitude(), - app.getSettings().getPointNavigateDescription(), sz, true); - app.getSettings().setPointToNavigate(lat, lon, true, name); - } else { - app.getSettings().insertIntermediatePoint(lat, lon, name, 0, true); - } - MapActivity.launchMapActivityMoveToTop(activity); - } - }); - builder.show(); - } else { - app.getSettings().setPointToNavigate(lat, lon, true, name); - MapActivity.launchMapActivityMoveToTop(activity); - } - } } diff --git a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java index fac6c2004f..2b56beb34b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java @@ -257,9 +257,11 @@ public class NavigatePointActivity extends Activity implements SearchActivityChi if(navigate){ if(activity != null) { - MapActivityActions.navigateToPoint(activity, lat, lon, getString(R.string.point_on_map, lat, lon)); + OsmandApplication app = (OsmandApplication) activity.getApplication(); + app.getTargetPointsHelper().navigatePointDialogAndLaunchMap(activity, lat, lon, getString(R.string.point_on_map, lat, lon)); } else { - MapActivityActions.navigateToPoint(this, lat, lon, getString(R.string.point_on_map, lat, lon)); + OsmandApplication app = (OsmandApplication) getApplication(); + app.getTargetPointsHelper().navigatePointDialogAndLaunchMap(this, lat, lon, getString(R.string.point_on_map, lat, lon)); } if(dlg != null){ dlg.dismiss(); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java index a9a96c94a2..01aa6bc256 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressActivity.java @@ -12,6 +12,7 @@ import net.osmand.plus.RegionAddressRepository; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityActions; import android.app.Activity; +import android.app.Application; import android.content.Intent; import android.os.Bundle; import android.view.View; @@ -236,7 +237,8 @@ public class SearchAddressActivity extends Activity { finish(); } else { if (navigateTo) { - MapActivityActions.navigateToPoint(SearchAddressActivity.this, searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); + OsmandApplication app = (OsmandApplication) getApplication(); + app.getTargetPointsHelper().navigatePointDialogAndLaunchMap(SearchAddressActivity.this, searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); } else { osmandSettings.setMapLocationToShow(searchPoint.getLatitude(), searchPoint.getLongitude(), zoom, historyName); MapActivity.launchMapActivityMoveToTop(SearchAddressActivity.this); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java index 16b4bc99ef..956be8aea0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java @@ -22,6 +22,7 @@ import net.osmand.plus.activities.TransportRouteHelper; import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; import android.app.AlertDialog; import android.app.AlertDialog.Builder; +import android.app.Application; import android.app.ListActivity; import android.content.DialogInterface; import android.content.Intent; @@ -142,8 +143,8 @@ public class SearchTransportActivity extends ListActivity implements SearchActiv if (startPoint == null) { startPoint = settings.getLastKnownMapLocation(); } - - LatLon pointToNavigate = settings.getPointToNavigate(); + OsmandApplication app = (OsmandApplication) getApplication(); + LatLon pointToNavigate = app.getTargetPointsHelper().getPointToNavigate(); if(!Algoritms.objectEquals(pointToNavigate, this.destinationLocation) || !Algoritms.objectEquals(startPoint, this.lastKnownMapLocation)){ destinationLocation = pointToNavigate; diff --git a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java index 97a542cb8e..b7c40fb2d4 100644 --- a/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java +++ b/OsmAnd/src/net/osmand/plus/development/OsmandDevelopmentPlugin.java @@ -63,7 +63,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin { @Override public void prepareOptionsMenu(Menu menu, MenuItem animateMenu) { animateMenu.setTitle(routeAnimation.isRouteAnimating() ? R.string.animate_route_off : R.string.animate_route); - animateMenu.setVisible(settings.getPointToNavigate() != null); + animateMenu.setVisible(app.getTargetPointsHelper().getPointToNavigate() != null); } @Override diff --git a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java index 0edf328eb4..c1b6bfdbef 100644 --- a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java +++ b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java @@ -174,8 +174,9 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { measurementPoints.add(l); view.refreshMap(); updateText(); + return true; } - return true; + return false; } @Override @@ -184,8 +185,9 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { measurementPoints.remove(measurementPoints.size() - 1); view.refreshMap(); updateText(); + return true; } - return true; + return false; } @Override diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 6192cd18a0..314eb593a4 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -15,6 +15,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.OsmandSettings.MetricsConstants; +import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.ApplicationMode; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RouteProvider.GPXRouteParams; @@ -362,9 +363,10 @@ public class RoutingHelper { showMessage(app.getString(R.string.arrived_at_intermediate_point)); voiceRouter.arrivedIntermediatePoint(); route.passIntermediatePoint(); - int toDel = settings.getIntermediatePoints().size() - route.getIntermediatePointsToPass(); + TargetPointsHelper targets = app.getTargetPointsHelper(); + int toDel = targets.getIntermediatePoints().size() - route.getIntermediatePointsToPass(); while(toDel > 0) { - settings.deleteIntermediatePoint(0); + targets.removeWayPoint(null, false, 0); toDel--; } while(intermediatePoints != null && route.getIntermediatePointsToPass() < intermediatePoints.size()) { @@ -378,6 +380,8 @@ public class RoutingHelper { showMessage(app.getString(R.string.arrived_at_destination)); voiceRouter.arrivedDestinationPoint(); clearCurrentRoute(null, null); + TargetPointsHelper targets = app.getTargetPointsHelper(); + targets.clearPointToNavigate(null, false); return true; } return false; diff --git a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java index 74547cec9e..db151e0cac 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java @@ -1,14 +1,13 @@ package net.osmand.plus.views; -import java.util.ArrayList; import java.util.List; import net.osmand.osm.LatLon; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.R; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; +import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import android.content.Context; import android.content.DialogInterface; @@ -31,8 +30,6 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu private Paint point; private Paint bitmapPaint; - protected LatLon pointToNavigate = null; - protected List intermediatePoints = new ArrayList(); private OsmandMapTileView view; private float[] calculations = new float[2]; @@ -43,8 +40,6 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu private Paint textPaint; - private RoutingHelper routingHelper; - private final MapActivity map; public PointNavigationLayer(MapActivity map) { @@ -88,7 +83,6 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu dm = new DisplayMetrics(); WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE); wmgr.getDefaultDisplay().getMetrics(dm); - routingHelper = view.getApplication().getRoutingHelper(); initUI(); } @@ -98,14 +92,8 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, DrawSettings nightMode) { int index = 0; - if(routingHelper != null && routingHelper.isFollowingMode() && routingHelper.isRouteCalculated()) { - List ip = routingHelper.getIntermediatePoints(); - int sz = ip == null ? 0 : ip.size(); - while(sz > intermediatePoints.size()) { - intermediatePoints.remove(0); - } - } - for (LatLon ip : intermediatePoints) { + TargetPointsHelper targetPoints = map.getTargetPoints(); + for (LatLon ip : targetPoints.getIntermediatePoints()) { index ++; if (isLocationVisible(ip)) { int marginX = intermediatePoint.getWidth() / 3; @@ -118,6 +106,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu canvas.rotate(view.getRotate(), locationX, locationY); } } + LatLon pointToNavigate = targetPoints.getPointToNavigate(); if (isLocationVisible(pointToNavigate)) { int marginX = targetPoint.getWidth() / 3; int marginY = 2 * targetPoint.getHeight() / 3; @@ -145,22 +134,6 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu } - public LatLon getPointToNavigate() { - return pointToNavigate; - } - - public void setPointToNavigate(LatLon pointToNavigate, List intermediatePoints) { - this.pointToNavigate = pointToNavigate; - this.intermediatePoints.clear(); - this.intermediatePoints.addAll(intermediatePoints); - view.refreshMap(); - } - - public List getIntermediatePoints() { - return intermediatePoints; - } - - @Override public void destroyLayer() { @@ -184,15 +157,11 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu @Override public void collectObjectsFromPoint(PointF point, List o) { - for(int i=0; i<=intermediatePoints.size(); i++) { - LatLon latLon; - boolean target = i == intermediatePoints.size(); - if(target){ - latLon = pointToNavigate; - } else { - latLon = intermediatePoints.get(i); - } - if(latLon != null) { + List intermediatePoints = map.getTargetPoints().getIntermediatePointsWithTarget(); + for (int i = 0; i < intermediatePoints.size(); i++) { + LatLon latLon = intermediatePoints.get(i); + boolean target = i == intermediatePoints.size() - 1; + if (latLon != null) { int ex = (int) point.x; int ey = (int) point.y; int x = view.getRotatedMapXForPoint(latLon.getLatitude(), latLon.getLongitude()); @@ -202,7 +171,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu TargetPoint tp = new TargetPoint(); tp.location = latLon; tp.intermediate = !target; - if(target) { + if (target) { tp.name = view.getContext().getString(R.string.target_point, ""); } else { tp.name = (i + 1) + ". " + view.getContext().getString(R.string.intermediate_point, ""); @@ -262,10 +231,11 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu @Override public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { if (itemId == R.string.delete_target_point) { + TargetPointsHelper targetPointsHelper = map.getMyApplication().getTargetPointsHelper(); if(a.intermediate) { - map.removeIntermediatePoint(true, a.index); + targetPointsHelper.removeWayPoint(map, true, a.index); } else { - map.navigateToPoint(null, true, -1); + targetPointsHelper.removeWayPoint(map, true, -1); } } map.getMapLayers().getContextMenuLayer().setLocation(null, ""); diff --git a/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java b/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java index e2b544200d..d6c28eec3f 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteInfoControls.java @@ -10,6 +10,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.routing.AlarmInfo; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; @@ -464,12 +465,13 @@ public class RouteInfoControls { protected TextInfoControl createIntermediateDistanceControl(final MapActivity map, Paint paintText, Paint paintSubText) { final OsmandMapTileView view = map.getMapView(); + final TargetPointsHelper targets = map.getTargetPoints(); DistanceToPointInfoControl distanceControl = new DistanceToPointInfoControl(map, 0, paintText, paintSubText, map.getResources() .getDrawable(R.drawable.info_intermediate), view) { @Override protected void click(OsmandMapTileView view) { - if(map.getIntermediatePoints().size() > 1) { + if(targets.getIntermediatePoints().size() > 1) { map.getMapActions().openIntermediatePointsDialog(); } else { super.click(view); @@ -478,7 +480,7 @@ public class RouteInfoControls { @Override public LatLon getPointToNavigate() { - return map.getFirstIntermediatePoint(); + return targets.getFirstIntermediatePoint(); } @Override