Refactor waypoints
This commit is contained in:
parent
021b493a56
commit
34a99dbb1f
6 changed files with 115 additions and 56 deletions
|
@ -518,12 +518,8 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
}
|
||||
|
||||
|
||||
private void updateLocation(net.osmand.Location loc ) {
|
||||
if (app.getSettings().ANNOUNCE_NEARBY_FAVORITES.get() && app.getRoutingHelper().isFollowingMode()){
|
||||
app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper().updateDialog();
|
||||
app.getWaypointHelper().locationChanged(getLastKnownLocation());
|
||||
}
|
||||
for(OsmAndLocationListener l : locationListeners){
|
||||
private void updateLocation(net.osmand.Location loc) {
|
||||
for (OsmAndLocationListener l : locationListeners) {
|
||||
l.updateLocation(loc);
|
||||
}
|
||||
}
|
||||
|
@ -716,8 +712,8 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
OsmandPlugin.updateLocationPlugins(location);
|
||||
// 2. accessibility routing
|
||||
navigationInfo.setLocation(location);
|
||||
|
||||
app.getRoutingHelper().updateLocation(location);
|
||||
app.getWaypointHelper().locationChanged(location);
|
||||
}
|
||||
|
||||
public void setLocationFromSimulation(net.osmand.Location location) {
|
||||
|
@ -761,6 +757,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
} else if(getLocationSimulation().isRouteAnimating()) {
|
||||
routingHelper.setCurrentLocation(location, false);
|
||||
}
|
||||
app.getWaypointHelper().locationChanged(location);
|
||||
this.location = updatedLocation;
|
||||
|
||||
// Update information
|
||||
|
|
|
@ -266,7 +266,7 @@ public class IntermediatePointsDialog {
|
|||
return listadapter;
|
||||
}
|
||||
|
||||
private static void commitPointsRemoval(OsmandApplication app, final boolean[] checkedIntermediates) {
|
||||
public static void commitPointsRemoval(OsmandApplication app, final boolean[] checkedIntermediates) {
|
||||
int cnt = 0;
|
||||
for (int i = checkedIntermediates.length - 1; i >= 0; i--) {
|
||||
if (!checkedIntermediates[i]) {
|
||||
|
@ -274,23 +274,26 @@ public class IntermediatePointsDialog {
|
|||
}
|
||||
}
|
||||
if (cnt > 0) {
|
||||
boolean changeDestinationFlag =!checkedIntermediates [checkedIntermediates.length - 1];
|
||||
if(cnt == checkedIntermediates.length){ //there is no alternative destination if all points are to be removed?
|
||||
app.getTargetPointsHelper().removeAllWayPoints(true);
|
||||
}else{
|
||||
for (int i = checkedIntermediates.length - 2; i >= 0; i--) { //skip the destination until a retained waypoint is found
|
||||
if (checkedIntermediates[i] && changeDestinationFlag) { //Find a valid replacement for the destination
|
||||
app.getTargetPointsHelper().makeWayPointDestination(cnt == 0, i);
|
||||
boolean changeDestinationFlag = !checkedIntermediates[checkedIntermediates.length - 1];
|
||||
if (cnt == checkedIntermediates.length) { // there is no alternative destination if all points are to be
|
||||
// removed?
|
||||
app.getTargetPointsHelper().removeAllWayPoints(true);
|
||||
} else {
|
||||
for (int i = checkedIntermediates.length - 2; i >= 0; i--) { // skip the destination until a retained
|
||||
// waypoint is found
|
||||
if (checkedIntermediates[i] && changeDestinationFlag) { // Find a valid replacement for the
|
||||
// destination
|
||||
app.getTargetPointsHelper().makeWayPointDestination(cnt == 0, i);
|
||||
changeDestinationFlag = false;
|
||||
}else if(!checkedIntermediates[i]){
|
||||
} else if (!checkedIntermediates[i]) {
|
||||
cnt--;
|
||||
app.getTargetPointsHelper().removeWayPoint(cnt == 0, i);
|
||||
}
|
||||
}
|
||||
// FIXME delete location when point is removed
|
||||
// if(mapActivity instanceof MapActivity) {
|
||||
// ((MapActivity) mapActivity).getMapLayers().getContextMenuLayer().setLocation(null, "");
|
||||
// }
|
||||
// if(mapActivity instanceof MapActivity) {
|
||||
// ((MapActivity) mapActivity).getMapLayers().getContextMenuLayer().setLocation(null, "");
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
|||
import net.osmand.Location;
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -34,7 +35,7 @@ import android.widget.TextView;
|
|||
|
||||
/**
|
||||
*/
|
||||
public class WaypointDialogHelper {
|
||||
public class WaypointDialogHelper implements OsmAndLocationListener {
|
||||
private MapActivity mapActivity;
|
||||
private OsmandApplication app;
|
||||
private FrameLayout mainLayout;
|
||||
|
@ -51,6 +52,23 @@ public class WaypointDialogHelper {
|
|||
this.mapActivity = mapActivity;
|
||||
this.mainLayout = (FrameLayout) ((FrameLayout) mapActivity.getLayout()).getChildAt(0);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
app.getLocationProvider().addLocationListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocation(Location location) {
|
||||
if(mapActivity != null) {
|
||||
updateDialog();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeListener() {
|
||||
app.getLocationProvider().removeLocationListener(this);
|
||||
mapActivity = null;
|
||||
}
|
||||
|
||||
|
||||
public void updateDialog() {
|
||||
final LocationPointWrapper point = waypointHelper.getMostImportantLocationPoint(many);
|
||||
|
@ -216,9 +234,7 @@ public class WaypointDialogHelper {
|
|||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
for(LocationPointWrapper wr : deletedPoints) {
|
||||
waypointHelper.removeVisibleLocationPoint(wr);
|
||||
}
|
||||
waypointHelper.removeVisibleLocationPoint(deletedPoints);
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(ctx.getString(R.string.default_buttons_cancel), null);
|
||||
|
@ -232,4 +248,8 @@ public class WaypointDialogHelper {
|
|||
// ctx.getMapView().setIntZoom(fZoom);
|
||||
// ctx.getMapView().setLatLon(point.getLatitude(), point.getLongitude());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.helpers;
|
|||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
|
@ -23,6 +24,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.PoiFilter;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
import net.osmand.plus.activities.IntermediatePointsDialog;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.routing.AlarmInfo;
|
||||
|
@ -54,8 +56,8 @@ public class WaypointHelper {
|
|||
private List<List<LocationPointWrapper>> locationPoints = new ArrayList<List<LocationPointWrapper>>();
|
||||
private ConcurrentHashMap<LocationPoint, Integer> locationPointsStates = new ConcurrentHashMap<LocationPoint, Integer>();
|
||||
private TIntArrayList pointsProgress = new TIntArrayList();
|
||||
private Location lastKnownLocation;
|
||||
private RouteCalculationResult route;
|
||||
|
||||
private long announcedAlarmTime;
|
||||
|
||||
|
||||
|
@ -75,7 +77,6 @@ public class WaypointHelper {
|
|||
|
||||
public void locationChanged(Location location) {
|
||||
app.getAppCustomization();
|
||||
lastKnownLocation = location;
|
||||
announceVisibleLocations();
|
||||
}
|
||||
|
||||
|
@ -89,6 +90,30 @@ public class WaypointHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void removeVisibleLocationPoint(List<LocationPointWrapper> points) {
|
||||
List<TargetPoint> ps = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
|
||||
boolean[] checkedIntermediates = null;
|
||||
for (LocationPointWrapper lp : points) {
|
||||
if (lp.type == TARGETS) {
|
||||
if(checkedIntermediates == null) {
|
||||
checkedIntermediates = new boolean[ps.size()];
|
||||
Arrays.fill(checkedIntermediates, true);
|
||||
}
|
||||
if(((TargetPoint) lp.point).intermediate) {
|
||||
checkedIntermediates[((TargetPoint) lp.point).index] = false;
|
||||
} else {
|
||||
checkedIntermediates[ps.size() - 1] = false;
|
||||
}
|
||||
} else if (lp.type < locationPoints.size()) {
|
||||
locationPoints.get(lp.type).remove(lp);
|
||||
}
|
||||
}
|
||||
if(checkedIntermediates != null) {
|
||||
IntermediatePointsDialog.commitPointsRemoval(app, checkedIntermediates);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public LocationPointWrapper getMostImportantLocationPoint(List<LocationPointWrapper> list ) {
|
||||
//Location lastProjection = app.getRoutingHelper().getLastProjection();
|
||||
if(list != null) {
|
||||
|
@ -212,6 +237,7 @@ public class WaypointHelper {
|
|||
|
||||
|
||||
public void announceVisibleLocations() {
|
||||
Location lastKnownLocation = app.getRoutingHelper().getLastProjection();
|
||||
if (lastKnownLocation != null && app.getRoutingHelper().isFollowingMode()) {
|
||||
for (int type = 0; type < locationPoints.size(); type++) {
|
||||
String nameToAnnounce = null;
|
||||
|
@ -239,15 +265,11 @@ public class WaypointHelper {
|
|||
.isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS)) {
|
||||
nameToAnnounce = (nameToAnnounce == null ? "" : ", ") + point.getName();
|
||||
locationPointsStates.remove(point);
|
||||
app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper()
|
||||
.updateDialog();
|
||||
announcePoints.add(point);
|
||||
} else if ((state == null || state == NOT_ANNOUNCED)
|
||||
&& getVoiceRouter()
|
||||
.isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS)) {
|
||||
locationPointsStates.put(point, ANNOUNCED_ONCE);
|
||||
app.getMapActivity().getMapLayers().getMapControlsLayer().getWaypointDialogHelper()
|
||||
.updateDialog();
|
||||
approachPoints.add(point);
|
||||
}
|
||||
kIterator++;
|
||||
|
@ -300,6 +322,12 @@ public class WaypointHelper {
|
|||
points.addAll(loc.subList(ps.get(i), loc.size()));
|
||||
}
|
||||
}
|
||||
List<TargetPoint> wts = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
|
||||
for(int k = 0; k < wts.size() ; k++) {
|
||||
TargetPoint tp = wts.get(wts.size() - k - 1);
|
||||
int routeIndex = k == 0 ? Integer.MAX_VALUE : route.getIndexOfIntermediate(k);
|
||||
points.add(new LocationPointWrapper(route, TARGETS, new TargetPointHelper(tp), 0, routeIndex));
|
||||
}
|
||||
sortList(points);
|
||||
return points;
|
||||
}
|
||||
|
@ -310,9 +338,28 @@ public class WaypointHelper {
|
|||
}
|
||||
|
||||
|
||||
public void setNewRoute(RouteCalculationResult res) {
|
||||
this.route = res;
|
||||
recalculateAllPoints();
|
||||
public void setNewRoute(RouteCalculationResult route) {
|
||||
ArrayList<List<LocationPointWrapper>> locationPoints = new ArrayList<List<LocationPointWrapper>>();
|
||||
if (route != null && !route.isEmpty()) {
|
||||
if (showFavorites()) {
|
||||
findLocationPoints(route, FAVORITES, getArray(locationPoints, FAVORITES), app.getFavorites()
|
||||
.getFavouritePoints(), announceFavorites());
|
||||
}
|
||||
calculateAlarms(route, getArray(locationPoints, ALARMS));
|
||||
if (showGPXWaypoints()) {
|
||||
findLocationPoints(route, WAYPOINTS, getArray(locationPoints, WAYPOINTS), app.getAppCustomization()
|
||||
.getWaypoints(), announceGPXWaypoints());
|
||||
findLocationPoints(route, WAYPOINTS, getArray(locationPoints, WAYPOINTS), route.getLocationPoints(),
|
||||
announceGPXWaypoints());
|
||||
}
|
||||
if(showPOI()) {
|
||||
calculatePoi(route, locationPoints);
|
||||
}
|
||||
}
|
||||
for (List<LocationPointWrapper> list : locationPoints) {
|
||||
sortList(list);
|
||||
}
|
||||
setLocationPoints(locationPoints, route);
|
||||
}
|
||||
|
||||
private float dist(LocationPoint l, List<Location> locations, int[] ind) {
|
||||
|
@ -333,33 +380,13 @@ public class WaypointHelper {
|
|||
return dist;
|
||||
}
|
||||
|
||||
private void recalculateAllPoints() {
|
||||
ArrayList<List<LocationPointWrapper>> locationPoints = new ArrayList<List<LocationPointWrapper>>();
|
||||
if (route != null && !route.isEmpty()) {
|
||||
if (showFavorites()) {
|
||||
findLocationPoints(route, FAVORITES, getArray(locationPoints, FAVORITES), app.getFavorites()
|
||||
.getFavouritePoints(), announceFavorites());
|
||||
}
|
||||
calculateAlarms(getArray(locationPoints, ALARMS));
|
||||
if (showGPXWaypoints()) {
|
||||
findLocationPoints(route, WAYPOINTS, getArray(locationPoints, WAYPOINTS), app.getAppCustomization()
|
||||
.getWaypoints(), announceGPXWaypoints());
|
||||
findLocationPoints(route, WAYPOINTS, getArray(locationPoints, WAYPOINTS), route.getLocationPoints(),
|
||||
announceGPXWaypoints());
|
||||
}
|
||||
if(showPOI()) {
|
||||
calculatePoi(locationPoints);
|
||||
}
|
||||
}
|
||||
for (List<LocationPointWrapper> list : locationPoints) {
|
||||
sortList(list);
|
||||
}
|
||||
protected synchronized void setLocationPoints(ArrayList<List<LocationPointWrapper>> locationPoints, RouteCalculationResult route) {
|
||||
this.locationPoints = locationPoints;
|
||||
this.locationPointsStates.clear();
|
||||
TIntArrayList list = new TIntArrayList(locationPoints.size());
|
||||
list.fill(0, locationPoints.size(), 0);
|
||||
this.pointsProgress = list;
|
||||
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
|
||||
|
@ -375,7 +402,7 @@ public class WaypointHelper {
|
|||
}
|
||||
|
||||
|
||||
protected void calculatePoi(ArrayList<List<LocationPointWrapper>> locationPoints) {
|
||||
protected void calculatePoi(RouteCalculationResult route, ArrayList<List<LocationPointWrapper>> locationPoints) {
|
||||
PoiFilter pf = getPoiFilter();
|
||||
if (pf != null) {
|
||||
final List<Location> locs = route.getImmutableAllLocations();
|
||||
|
@ -408,7 +435,7 @@ public class WaypointHelper {
|
|||
|
||||
|
||||
|
||||
private void calculateAlarms(List<LocationPointWrapper> array) {
|
||||
private void calculateAlarms(RouteCalculationResult route, List<LocationPointWrapper> array) {
|
||||
for(AlarmInfo i : route.getAlarmInfo()) {
|
||||
if(i.getType() == AlarmInfoType.SPEED_CAMERA) {
|
||||
if(app.getSettings().SHOW_CAMERAS.get()){
|
||||
|
|
|
@ -868,6 +868,15 @@ public class RouteCalculationResult {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public int getIndexOfIntermediate(int countFromLast) {
|
||||
final int j = intermediatePoints.length - countFromLast - 1;
|
||||
if(j < intermediatePoints.length) {
|
||||
int i = intermediatePoints[j];
|
||||
return directions.get(i).routePointOffset;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getIntermediatePointsToPass(){
|
||||
if(nextIntermediate >= intermediatePoints.length) {
|
||||
return 0;
|
||||
|
|
|
@ -68,6 +68,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
waypointDialogHelper = new WaypointDialogHelper(activity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean drawInScreenPixels() {
|
||||
return true;
|
||||
|
@ -111,6 +112,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
mapInfoNavigationControl.setMargin(mapSmallMenuControls.getWidth() + mapCancelNavigationControl.getWidth());
|
||||
mapAppModeControl.setMargin(mapNavigationControl.getWidth());
|
||||
|
||||
waypointDialogHelper.init();
|
||||
initTransparencyBar(view, parent);
|
||||
}
|
||||
|
||||
|
@ -137,6 +139,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
waypointDialogHelper.removeListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue