From 9e87ec17e9ceb3a59afe64403040d1ef96c76bd4 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 26 Oct 2014 23:08:24 +0100 Subject: [PATCH 1/2] FIx issue 2384 --- .../osmand/router/BinaryRoutePlannerOld.java | 2 +- .../osmand/router/RoutePlannerFrontEnd.java | 3 ++- .../osmand/plus/dialogs/ConfigureMapMenu.java | 3 ++- .../plus/download/DownloadIndexAdapter.java | 7 ++++-- .../plus/download/LocalIndexesFragment.java | 22 +++++++++++++++++-- .../plus/routing/RouteCalculationParams.java | 2 ++ .../osmand/plus/routing/RouteProvider.java | 6 ++--- .../osmand/plus/routing/RoutingHelper.java | 21 ++++++++++-------- 8 files changed, 47 insertions(+), 19 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlannerOld.java b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlannerOld.java index a0a56f555f..1fff0dfaba 100644 --- a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlannerOld.java +++ b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlannerOld.java @@ -81,7 +81,7 @@ public class BinaryRoutePlannerOld { TLongObjectHashMap visitedDirectSegments = new TLongObjectHashMap(); TLongObjectHashMap visitedOppositeSegments = new TLongObjectHashMap(); - boolean runRecalculation = ctx.previouslyCalculatedRoute != null && ctx.previouslyCalculatedRoute.size() > 0 + boolean runRecalculation = ctx.previouslyCalculatedRoute != null && ctx.previouslyCalculatedRoute.size() > 0 && ctx.config.recalculateDistance != 0; if (runRecalculation) { RouteSegment previous = null; diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index e61ad49676..57888d1c71 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.Log; public class RoutePlannerFrontEnd { private boolean useOldVersion; - protected static final Log log = PlatformUtil.getLog(BinaryRoutePlannerOld.class); + protected static final Log log = PlatformUtil.getLog(RoutePlannerFrontEnd.class); public RoutePlannerFrontEnd(boolean useOldVersion) { this.useOldVersion = useOldVersion; @@ -348,6 +348,7 @@ public class RoutePlannerFrontEnd { restPartRecalculatedRoute.add(prev.get(k)); } } + System.out.println("Recalculate only first part of the route"); break; } } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 027300da48..f23abe9bc2 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -224,7 +224,7 @@ public class ConfigureMapMenu { final String[] txtNames = new String[txtValues.length]; for (int i = 0; i < txtNames.length; i++) { txtNames[i] = (int) (txtValues[i] * 100) + " %"; - if (view.getSettings().TEXT_SCALE.get() == txtValues[i]) { + if (Math.abs(view.getSettings().TEXT_SCALE.get() - txtValues[i]) < 0.1f) { selected = i; } } @@ -235,6 +235,7 @@ public class ConfigureMapMenu { refreshMapComplete(activity); adapter.setItemDescription(pos, getScale(activity)); ad.notifyDataSetInvalidated(); + dialog.dismiss(); } }); b.show(); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java index ae7ef61480..f5749ada81 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java @@ -36,11 +36,14 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem private int updateColor; private OsmandRegions osmandRegions; private java.text.DateFormat format; + private OsmandApplication app; public DownloadIndexAdapter(DownloadIndexFragment downloadFragment, List indexFiles) { this.downloadFragment = downloadFragment; + this.indexFiles = new ArrayList(indexFiles); - List cats = IndexItemCategory.categorizeIndexItems(downloadFragment.getMyApplication(), indexFiles); + app = downloadFragment.getMyApplication(); + List cats = IndexItemCategory.categorizeIndexItems(app, indexFiles); synchronized (this) { list.clear(); list.addAll(cats); @@ -165,7 +168,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem list.clear(); Collection items = (Collection) results.values; if (items != null && !items.isEmpty()) { - list.addAll(IndexItemCategory.categorizeIndexItems(downloadFragment.getMyApplication(), items)); + list.addAll(IndexItemCategory.categorizeIndexItems(app, items)); } else if(DownloadIndexAdapter.this.indexFiles.isEmpty()){ list.add(new IndexItemCategory(downloadFragment.getResources().getString(R.string.no_index_file_to_download), 1)); } else { diff --git a/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java index ac6a6589c4..fd3549998d 100644 --- a/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java @@ -1,8 +1,11 @@ package net.osmand.plus.download; import java.io.File; +import java.text.Collator; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; @@ -264,6 +267,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment { @Override protected void onPostExecute(List result) { this.result = result; + listAdapter.sortData(); + getDownloadActivity().setSupportProgressBarIndeterminateVisibility(false); getDownloadActivity().setLocalIndexInfos(result); } @@ -759,6 +764,19 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment { filterCategory = null; notifyDataSetChanged(); } + + public void sortData() { + final Collator cl = Collator.getInstance(); + for(List i : data.values()) { + Collections.sort(i, new Comparator() { + + @Override + public int compare(LocalIndexInfo lhs, LocalIndexInfo rhs) { + return cl.compare(lhs.getName(), rhs.getName()); + } + }); + } + } public LocalIndexInfo findCategory(LocalIndexInfo val, boolean backuped){ for(LocalIndexInfo i : category){ @@ -1017,8 +1035,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment { name = fileName.substring(0, ls); } - if (name.endsWith("-roads")){ - return ctx.getString(R.string.download_roads_only_item); + if (name.endsWith("-roads")) { + return ctx.getString(R.string.download_roads_only_item); } return ""; diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java index ed95bc19ba..88e5038851 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java @@ -16,11 +16,13 @@ public class RouteCalculationParams { public LatLon end; public List intermediates; + public OsmandApplication ctx; public ApplicationMode mode; public RouteService type; public GPXRouteParams gpxRoute; public RouteCalculationResult previousToRecalculate; + public boolean onlyStartPointChanged; public boolean fast; public boolean leftSide; public RouteCalculationProgress calculationProgress; diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 057bb2fcfc..af8942005d 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -394,7 +394,8 @@ public class RouteProvider { rp.leftSide = routeParams.leftSide; rp.type = routeParams.type; rp.fast = routeParams.fast; - rp.previousToRecalculate = routeParams.previousToRecalculate; + rp.onlyStartPointChanged = routeParams.onlyStartPointChanged; + rp.previousToRecalculate = routeParams.previousToRecalculate; rp.intermediates = new ArrayList(); for(Location w : intermediates) { rp.intermediates.add(new LatLon(w.getLatitude(), w.getLongitude())); @@ -656,8 +657,7 @@ public class RouteProvider { } ctx.leftSideNavigation = params.leftSide; ctx.calculationProgress = params.calculationProgress; - if(params.previousToRecalculate != null) { - // not used any more + if(params.previousToRecalculate != null && params.onlyStartPointChanged) { ctx.previouslyCalculatedRoute = params.previousToRecalculate.getOriginalRoute(); } LatLon st = new LatLon(params.start.getLatitude(), params.start.getLongitude()); diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 4a91d14962..d12429b588 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -138,7 +138,7 @@ public class RoutingHelper { RouteCalculationResult previousRoute = route; clearCurrentRoute(finalLocation, intermediatePoints); // to update route - setCurrentLocation(currentLocation, false, previousRoute); + setCurrentLocation(currentLocation, false, previousRoute, true); } public synchronized void clearCurrentRoute(LatLon newFinalLocation, List newIntermediatePoints) { @@ -227,7 +227,7 @@ public class RoutingHelper { } public Location setCurrentLocation(Location currentLocation, boolean returnUpdatedLocation) { - return setCurrentLocation(currentLocation, returnUpdatedLocation, route); + return setCurrentLocation(currentLocation, returnUpdatedLocation, route, false); } public double getRouteDeviation(){ @@ -240,7 +240,8 @@ public class RoutingHelper { return getOrthogonalDistance(lastFixedLocation, routeNodes.get(route.currentRoute -1), routeNodes.get(route.currentRoute)); } - private Location setCurrentLocation(Location currentLocation, boolean returnUpdatedLocation, RouteCalculationResult previousRoute) { + private Location setCurrentLocation(Location currentLocation, boolean returnUpdatedLocation, + RouteCalculationResult previousRoute, boolean targetPointsChanged) { Location locationProjection = currentLocation; if (finalLocation == null || currentLocation == null) { isDeviatedFromRoute = false; @@ -316,7 +317,7 @@ public class RoutingHelper { if (calculateRoute) { recalculateRouteInBackground(false, currentLocation, finalLocation, intermediatePoints, currentGPXRoute, - previousRoute.isCalculated() ? previousRoute : null, false); + previousRoute.isCalculated() ? previousRoute : null, false, !targetPointsChanged); } else { Thread job = currentRunningJob; if(job instanceof RouteRecalculationThread) { @@ -772,29 +773,31 @@ public class RoutingHelper { } public void recalculateRouteDueToSettingsChange() { - recalculateRouteInBackground(true, lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, true); + recalculateRouteInBackground(true, lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, + true, false); } private void recalculateRouteInBackground(boolean force, final Location start, final LatLon end, final List intermediates, - final GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute, boolean paramsChanged){ + final GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute, boolean paramsChanged, boolean onlyStartPointChanged){ if (start == null || end == null) { return; } - if(currentRunningJob == null){ + if (currentRunningJob == null) { // do not evaluate very often if (force || System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval) { RouteCalculationParams params = new RouteCalculationParams(); params.start = start; params.end = end; params.intermediates = intermediates; - params.gpxRoute = gpxRoute == null? null : gpxRoute.build(start, settings); + params.gpxRoute = gpxRoute == null ? null : gpxRoute.build(start, settings); + params.onlyStartPointChanged = onlyStartPointChanged; params.previousToRecalculate = previousRoute; params.leftSide = settings.DRIVING_REGION.get().leftHandDriving; params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode); params.type = settings.ROUTER_SERVICE.getModeValue(mode); params.mode = mode; params.ctx = app; - if(previousRoute == null && params.type == RouteService.OSMAND) { + if (previousRoute == null && params.type == RouteService.OSMAND) { params.calculationProgress = new RouteCalculationProgress(); updateProgress(params.calculationProgress); } From a410e2b56597c152ac2ac9074ee87f8449035e19 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 26 Oct 2014 23:48:47 +0100 Subject: [PATCH 2/2] Fix be attentive with route recalculation --- .../osmand/router/RoutePlannerFrontEnd.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index 57888d1c71..d8e1117edc 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -336,20 +336,25 @@ public class RoutePlannerFrontEnd { List prev = ctx.previouslyCalculatedRoute; long id = points.get(1).getRoad().id; int ss = points.get(1).getSegmentStart(); + int px = points.get(1).getRoad().getPoint31XTile(ss); + int py = points.get(1).getRoad().getPoint31YTile(ss); for (int i = 0; i < prev.size(); i++) { RouteSegmentResult rsr = prev.get(i); - if (id == rsr.getObject().getId() && ss == rsr.getEndPointIndex()) { - firstPartRecalculatedRoute = new ArrayList(i + 1); - restPartRecalculatedRoute = new ArrayList(prev.size() - i); - for (int k = 0; k < prev.size(); k++) { - if (k <= i) { - firstPartRecalculatedRoute.add(prev.get(k)); - } else { - restPartRecalculatedRoute.add(prev.get(k)); + if (id == rsr.getObject().getId()) { + if (MapUtils.getDistance(rsr.getPoint(rsr.getEndPointIndex()), MapUtils.get31LatitudeY(py), + MapUtils.get31LongitudeX(px)) < 50) { + firstPartRecalculatedRoute = new ArrayList(i + 1); + restPartRecalculatedRoute = new ArrayList(prev.size() - i); + for (int k = 0; k < prev.size(); k++) { + if (k <= i) { + firstPartRecalculatedRoute.add(prev.get(k)); + } else { + restPartRecalculatedRoute.add(prev.get(k)); + } } + System.out.println("Recalculate only first part of the route"); + break; } - System.out.println("Recalculate only first part of the route"); - break; } } }