From 85ace59fd88b304019d20d1261f1513e021433ee Mon Sep 17 00:00:00 2001 From: vshcherb Date: Fri, 28 Feb 2014 23:00:56 +0200 Subject: [PATCH 01/17] Fix voice issue --- .../net/osmand/plus/activities/SettingsNavigationActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 7bf386dc86..01a3272788 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -233,7 +233,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { if (MORE_VALUE.equals(newValue)) { // listPref.set(oldValue); // revert the change.. final Intent intent = new Intent(this, DownloadIndexActivity.class); - intent.putExtra(DownloadIndexActivity.FILTER_KEY, "voice"); + intent.putExtra(DownloadIndexActivity.FILTER_KEY, getString(R.string.voice)); startActivity(intent); } else { super.onPreferenceChange(preference, newValue); From d140b673adc283cc9eb8ff08d89571dd88e3d784 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Fri, 28 Feb 2014 23:20:15 +0200 Subject: [PATCH 02/17] Fix left side turn issue --- OsmAnd/src/net/osmand/plus/routing/RouteProvider.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index a2f092f69e..6e9073435c 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -435,6 +435,7 @@ public class RouteProvider { complexCtx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, RouteCalculationMode.COMPLEX); complexCtx.calculationProgress = params.calculationProgress; + complexCtx.leftSideNavigation = params.leftSide; } ctx.leftSideNavigation = params.leftSide; ctx.calculationProgress = params.calculationProgress; From 8ad5280fb0a60d0ed9bd91db50d43d60f6f764b4 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 1 Mar 2014 00:32:55 +0200 Subject: [PATCH 03/17] Add truck --- .../res/drawable-hdpi/ic_action_truck_dark.png | Bin 0 -> 859 bytes .../res/drawable-hdpi/ic_action_truck_light.png | Bin 0 -> 998 bytes OsmAnd/res/drawable-hdpi/ic_truck.png | Bin 0 -> 1971 bytes .../res/drawable-mdpi/ic_action_truck_dark.png | Bin 0 -> 528 bytes .../res/drawable-mdpi/ic_action_truck_light.png | Bin 0 -> 649 bytes OsmAnd/res/drawable-mdpi/ic_truck.png | Bin 0 -> 1285 bytes .../res/drawable-xhdpi/ic_action_truck_dark.png | Bin 0 -> 1098 bytes .../res/drawable-xhdpi/ic_action_truck_light.png | Bin 0 -> 1332 bytes OsmAnd/res/drawable-xhdpi/ic_truck.png | Bin 0 -> 2817 bytes OsmAnd/res/values/strings.xml | 1 + OsmAnd/src/net/osmand/plus/ApplicationMode.java | 4 ++++ 11 files changed, 5 insertions(+) create mode 100644 OsmAnd/res/drawable-hdpi/ic_action_truck_dark.png create mode 100644 OsmAnd/res/drawable-hdpi/ic_action_truck_light.png create mode 100644 OsmAnd/res/drawable-hdpi/ic_truck.png create mode 100644 OsmAnd/res/drawable-mdpi/ic_action_truck_dark.png create mode 100644 OsmAnd/res/drawable-mdpi/ic_action_truck_light.png create mode 100644 OsmAnd/res/drawable-mdpi/ic_truck.png create mode 100644 OsmAnd/res/drawable-xhdpi/ic_action_truck_dark.png create mode 100644 OsmAnd/res/drawable-xhdpi/ic_action_truck_light.png create mode 100644 OsmAnd/res/drawable-xhdpi/ic_truck.png diff --git a/OsmAnd/res/drawable-hdpi/ic_action_truck_dark.png b/OsmAnd/res/drawable-hdpi/ic_action_truck_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..04733336b0b412977c79d26bc6ebb213315d4cc1 GIT binary patch literal 859 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 literal 0 HcmV?d00001 diff --git a/OsmAnd/res/drawable-mdpi/ic_truck.png b/OsmAnd/res/drawable-mdpi/ic_truck.png new file mode 100644 index 0000000000000000000000000000000000000000..e068a61c2d62e4045f0fbd13e869bf3c34b22b6e GIT binary patch literal 1285 zcmV+g1^W7lP)+-rMG!U-#oZ z?|I+nJkNX1xffWSH>mUcnF2sDpw1Cc5~yV9Q8i0V7_>Fuw8T4<)YIpNQ zs17x2VNbEFct}XrH)hPqEWld}cz&}~On^u|E4JCyT zTbFjh0oERvV7=rG#nKL{{&u+RB1SJ4KIs?3x5xEz?kF<^z`foUVW`$!(!?Og$Q}m4g z=hr#_V8{ug<3z|eObNF-0Pmn(31^V)(?e^9HXc3KoONVBCmys_0%0Zq#G-xikoT32 zK6Fk@rnUj3dAyEgTy9t=(gwB!@C{9QT-Sp@(955+_7o?tYwn|S{gC3#go(J4ye zaZ2KC`ka0{&E}Vtk1b*4g&*8`$GGQ3D~7a+~;XK+)EGdyzt_G z0YFR0t*6v=q5YtTJZ-mXqt^+@epi%y;eCcXc%Z+_Js8vy{ZtczWms@#d86mX@yWzy zK#($ekTx|R`nBXiDkqQ5>{HnL2V=wc659^t-|N(;od1%;8Y)i3Jp;XG-Ap)lq2Np8 zbMDBUj(4}jXn*iDQT)|XqtGDx3`X)fCntQ7m0J2h#r;|P8a9eRW6y4Y3kna2`v_3PJF!QIqqtv(fUu2fj zz9$~>8u@ryaoCyxAV=94JAZYKP3}kJI~kQ}+PL%*O`os!cNeW7J2>Dow8GrL1pAq! z_Oc%F$s=&pt)>7}9gPJJ6aW^0ZmS^`18g-N76hXhU;*g18d5R9R?}fYFp2>dfNrZH v6$5NF9To(m7+?YDwi;3~z*f^?K`{RUau^t239RL900000NkvXXu0mjfR>oiv literal 0 HcmV?d00001 diff --git a/OsmAnd/res/drawable-xhdpi/ic_action_truck_dark.png b/OsmAnd/res/drawable-xhdpi/ic_action_truck_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..bc743e3929a31c4d03fc03537e859b05cc066dba GIT binary patch literal 1098 zcmV-Q1hxB#P)O899)7Z(IgkqgFyus zJS4b81rLHbh>Ezz1s9APQ4+`R4>i!XneLv+ES+=}JbJpjs@{8Fy?RyENvuc2ODy94 z_pktL1Vo&GodOXL0GkBu6tGhu;sopzhg04Cqun^|qt~A*=va;Lz%T&L^tX0N`+nZNfPP zh=7$ivMNPq+Ni%C2)9#d7uEe01pCPEeYBPNRdF!r-07qlAy;}w?FM4MFSj${?Jg- z>leW}0icb>IiwDGZUBtpIty8f3`}9vya4Eca~5ep-Xgt`aYzBO5J{~4PIXxa@EC1d z88tcnUtuJN^H5vV@c|(u18|M@`_S_>iJnP3-;HPq%o%`pXez;|4>+pP&^}y-DEuEF zS9#aMJ8e;QS{oezLPr3!pVz*=mA({BixC}ve<2M#zoCA4r)QOj^KTegjet!kuQv{s z8|R%qKIEp%0MZuq7~(f)-2hr>Q$!!Hje`fdcmI{@63=!SK<+O|839m@0(S^MHHKkV z+<6Lf5ArPxTW3b7it7ZQC^$v^3i_N!z5OPNwsGH&-`dkFw{%oa(C)Yy3<1%H5|xZ> zg-6m+DKf~R`5p?-pl~S9E+ZW!pmx8JLh8Pv?h<~_@Br|Pca>(^C{l`$Chl+2R@>PF z9&JDJu7J92)D>`nYDTK0+oPRtNP4x^yi;UUdsgD(CPv)#spF?-ITgx$`k0TNPpRth zo0EQqX+EAuy!t7|ut%vH=By9sMcnW7=tE2K+@PPqoc(kPfI7lBW!}k2jC;a!0no-J z?ShUWG_FOG{g1*$ba(+usyh<^wER>c$_LJ(HG3_FHKy&kqoGNRa z5s)|ZAyI52AS45kH#2MmyJ?Lmv{wHUdI25P37>FV}_PP|gqY Qg8%>k07*qoM6N<$f){(~@c;k- literal 0 HcmV?d00001 diff --git a/OsmAnd/res/drawable-xhdpi/ic_action_truck_light.png b/OsmAnd/res/drawable-xhdpi/ic_action_truck_light.png new file mode 100644 index 0000000000000000000000000000000000000000..2ebc8bcd47e369964c46b72a8e97cd749f618c2c GIT binary patch literal 1332 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 + Truck Navigation preferences Routing preferences Specify speech rate for TTS diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index 7aecd11413..53946b29c2 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -45,6 +45,10 @@ public class ApplicationMode { carLocation().parent(CAR). icon(R.drawable.ic_motorcycle, R.drawable.ic_action_motorcycle_light, R.drawable.ic_action_motorcycle_dark).reg(); + public static final ApplicationMode TRUCK = create(R.string.app_mode_truck, "truck").speed(15.3f, 40). + carLocation().parent(CAR). + icon(R.drawable.ic_truck, R.drawable.ic_action_truck_light, R.drawable.ic_action_truck_dark).reg(); + static { ApplicationMode[] exceptPedestrian = new ApplicationMode[] { DEFAULT, CAR, BICYCLE, BOAT, AIRCRAFT }; ApplicationMode[] exceptAirBoat = new ApplicationMode[] { DEFAULT, CAR, BICYCLE}; From 92dad044ec88bf5a503742076d1e240f8d1766d2 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 1 Mar 2014 00:51:39 +0200 Subject: [PATCH 04/17] Zoom should not change sync with map --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 670bac731d..9e51cac594 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -367,10 +367,10 @@ public class MapActivity extends AccessibleActivity { public void changeZoom(int stp){ // delta = Math.round(delta * OsmandMapTileView.ZOOM_DELTA) * OsmandMapTileView.ZOOM_DELTA_1; - boolean changeLocation = true; - if (settings.AUTO_ZOOM_MAP.get() == AutoZoomMap.NONE) { - changeLocation = false; - } + boolean changeLocation = false; +// if (settings.AUTO_ZOOM_MAP.get() == AutoZoomMap.NONE) { +// changeLocation = false; +// } final int newZoom = mapView.getZoom() + stp; mapView.getAnimatedDraggingThread().startZooming(newZoom, changeLocation); if (app.accessibilityEnabled()) From 2cc540904441b089202487a3792f21b2089284d9 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 1 Mar 2014 13:30:25 +0200 Subject: [PATCH 05/17] Add rendering route data objects from java/ change download button behavior --- .../osmand/binary/BinaryMapDataObject.java | 1 + .../osmand/binary/BinaryMapIndexReader.java | 10 +- .../binary/BinaryMapRouteReaderAdapter.java | 4 +- .../net/osmand/binary/RouteDataObject.java | 4 + .../osmand/router/RouteResultPreparation.java | 20 ++ .../plus/render/MapRenderRepositories.java | 319 +++++++++++------- .../plus/views/DownloadedRegionsLayer.java | 2 +- 7 files changed, 231 insertions(+), 129 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java index 6032ee1e89..20c90394c0 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapDataObject.java @@ -33,6 +33,7 @@ public class BinaryMapDataObject { this.coordinates = coordinates; } + public String getName(){ if(objectNames == null){ return ""; diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java index 5c3a277efa..b48ee00f61 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapIndexReader.java @@ -1541,6 +1541,10 @@ public class BinaryMapIndexReader { return top; } + public int getZoom() { + return zoom; + } + public void clearSearchResults(){ // recreate whole list to allow GC collect old data searchResults = new ArrayList(); @@ -1598,6 +1602,10 @@ public class BinaryMapIndexReader { } } + public boolean isRegisteredRule(int id) { + return decodingRules.containsKey(id); + } + public void initMapEncodingRule(int type, int id, String tag, String val) { if(!encodingRules.containsKey(tag)){ encodingRules.put(tag, new HashMap()); @@ -2070,7 +2078,7 @@ public class BinaryMapIndexReader { } - public List searchRouteIndexTree(SearchRequest req, List list) throws IOException { + public List searchRouteIndexTree(SearchRequest req, List list) throws IOException { req.numberOfVisitedObjects = 0; req.numberOfAcceptedObjects = 0; req.numberOfAcceptedSubtrees = 0; diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java index 697eaa75e2..943000fb81 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryMapRouteReaderAdapter.java @@ -674,7 +674,7 @@ public class BinaryMapRouteReaderAdapter { } } - public void initRouteTypesIfNeeded(SearchRequest req, List list) throws IOException { + public void initRouteTypesIfNeeded(SearchRequest req, List list) throws IOException { for (RouteSubregion rs : list) { if (req.intersects(rs.left, rs.top, rs.right, rs.bottom)) { initRouteRegion(rs.routeReg); @@ -736,7 +736,7 @@ public class BinaryMapRouteReaderAdapter { } } - public List searchRouteRegionTree(SearchRequest req, List list, + public List searchRouteRegionTree(SearchRequest req, List list, List toLoad) throws IOException { for (RouteSubregion rs : list) { if (req.intersects(rs.left, rs.top, rs.right, rs.bottom)) { diff --git a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java index b2db055789..4359cf506d 100644 --- a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java @@ -61,6 +61,10 @@ public class RouteDataObject { return null; } + public TIntObjectHashMap getNames() { + return names; + } + public String getRef(){ if(names != null ) { return names.get(region.refTypeRule); diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 64531097e1..8e00ac5854 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -9,6 +9,7 @@ import java.util.Iterator; import java.util.List; import net.osmand.binary.BinaryMapIndexReader; +import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; import net.osmand.router.BinaryRoutePlanner.FinalRouteSegment; @@ -295,11 +296,30 @@ public class RouteResultPreparation { additional.append("description = \"").append(res.getDescription()).append("\" "); println(MessageFormat.format("\t", (res.getObject().getId()) + "", res.getStartPointIndex() + "", res.getEndPointIndex() + "", additional.toString())); + printAdditionalPointInfo(res); } } println(""); } + private void printAdditionalPointInfo(RouteSegmentResult res) { + boolean plus = res.getStartPointIndex() < res.getEndPointIndex(); + for(int k = res.getStartPointIndex(); k != res.getEndPointIndex(); ) { + int[] tp = res.getObject().getPointTypes(k); + if(tp != null) { + for(int t = 0; t < tp.length; t++) { + RouteTypeRule rr = res.getObject().region.quickGetEncodingRule(tp[t]); + println("\t"); + } + } + if(plus) { + k++; + } else { + k--; + } + } + } + private void addTurnInfo(boolean leftside, List result) { int prevSegment = -1; diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 7f3a049a82..18d4f3e7ae 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -1,9 +1,11 @@ package net.osmand.plus.render; +import gnu.trove.iterator.TIntObjectIterator; import gnu.trove.list.TLongList; import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TLongArrayList; +import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.set.TLongSet; import gnu.trove.set.hash.TLongHashSet; @@ -20,18 +22,19 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import net.osmand.IProgress; +import net.osmand.ResultMatcher; import net.osmand.NativeLibrary.NativeSearchResult; import net.osmand.PlatformUtil; -import net.osmand.ResultMatcher; import net.osmand.access.AccessibleToast; import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapIndexReader; +import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; +import net.osmand.binary.RouteDataObject; import net.osmand.binary.BinaryMapIndexReader.MapIndex; import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.TagValuePair; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion; -import net.osmand.binary.RouteDataObject; import net.osmand.data.QuadPointDouble; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; @@ -66,10 +69,10 @@ public class MapRenderRepositories { // It is needed to not draw object twice if user have map index that intersects by boundaries public static boolean checkForDuplicateObjectIds = true; - private final static Log log = PlatformUtil.getLog(MapRenderRepositories.class); private final OsmandApplication context; private final static int BASEMAP_ZOOM = 11; + static int zoomForBaseRouteRendering = 14; private Handler handler; private Map files = new ConcurrentHashMap(); private Set nativeFiles = new HashSet(); @@ -91,6 +94,8 @@ public class MapRenderRepositories { private RotatedTileBox prevBmpLocation = null; // already rendered bitmap private Bitmap prevBmp; + // to track necessity of map download (1 (if basemap) + 2 (if normal map) + private int previousRenderedState; // location of rendered bitmap private RotatedTileBox bmpLocation = null; @@ -98,6 +103,7 @@ public class MapRenderRepositories { private Bitmap bmp; // Field used in C++ private boolean interrupted = false; + private int renderedState = 0; // (1 (if basemap) + 2 (if normal map) private RenderingContext currentRenderingContext; private SearchRequest searchRequest; private OsmandSettings prefs; @@ -252,7 +258,7 @@ public class MapRenderRepositories { } NativeSearchResult resultHandler = library.searchObjectsForRendering(leftX, rightX, topY, bottomY, zoom, renderingReq, - checkForDuplicateObjectIds, this, /*context.getString(R.string.switch_to_raster_map_to_see)*/ ""); + checkForDuplicateObjectIds, this, ""); if (checkWhetherInterrupted()) { resultHandler.deleteNativeResult(); return false; @@ -267,6 +273,77 @@ public class MapRenderRepositories { log.info(String.format("Native search: %s ms ", System.currentTimeMillis() - now)); //$NON-NLS-1$ return true; } + + private void readRouteDataAsMapObjects(SearchRequest sr, BinaryMapIndexReader c, + final ArrayList tempResult, final TLongSet ids) { + final boolean basemap = c.isBasemap(); + try { + for (RouteRegion reg : c.getRoutingIndexes()) { + List parent = sr.getZoom() < 15 ? reg.getBaseSubregions() : reg.getSubregions(); + List searchRouteIndexTree = c.searchRouteIndexTree(sr, parent); + final MapIndex nmi = new MapIndex(); + c.loadRouteIndexData(searchRouteIndexTree, new ResultMatcher() { + + @Override + public boolean publish(RouteDataObject r) { + if (basemap) { + renderedState |= 1; + } else { + renderedState |= 2; + } + if (checkForDuplicateObjectIds && !basemap) { + if (ids.contains(r.getId()) && r.getId() > 0) { + // do not add object twice + return false; + } + ids.add(r.getId()); + } + int[] coordinantes = new int[r.getPointsLength() * 2]; + int[] roTypes = r.getTypes(); + for(int k = 0; k < roTypes.length; k++) { + int type = roTypes[k]; + registerMissingType(nmi, r, type); + } + for(int k = 0; k < coordinantes.length/2; k++ ) { + coordinantes[2 * k] = r.getPoint31XTile(k); + coordinantes[2 * k + 1] = r.getPoint31YTile(k); + } + BinaryMapDataObject mo = new BinaryMapDataObject(coordinantes, roTypes, new int[0][], r.getId()); + TIntObjectHashMap names = r.getNames(); + if(names != null) { + TIntObjectIterator it = names.iterator(); + while(it.hasNext()) { + it.advance(); + registerMissingType(nmi, r, it.key()); + mo.putObjectName(it.key(), it.value()); + } + } + mo.setMapIndex(nmi); + tempResult.add(mo); + return false; + } + + private void registerMissingType(final MapIndex nmi, RouteDataObject r, int type) { + if (!nmi.isRegisteredRule(type)) { + RouteTypeRule rr = r.region.quickGetEncodingRule(type); + String tag = rr.getTag(); + int additional = ("highway".equals(tag) || "route".equals(tag) || "railway".equals(tag) + || "aeroway".equals(tag) || "aerialway".equals(tag)) ? 0 : 1; + nmi.initMapEncodingRule(additional, type, rr.getTag(), rr.getValue()); + } + } + + @Override + public boolean isCancelled() { + return !interrupted; + } + }); + } + } catch (IOException e) { + log.debug("Search failed " + c.getRegionNames(), e); //$NON-NLS-1$ + } + } + private boolean loadVectorData(QuadRect dataBox, final int zoom, final RenderingRuleSearchRequest renderingReq) { double cBottomLatitude = dataBox.bottom; @@ -277,18 +354,102 @@ public class MapRenderRepositories { long now = System.currentTimeMillis(); System.gc(); // to clear previous objects - int count = 0; ArrayList tempResult = new ArrayList(); ArrayList basemapResult = new ArrayList(); - TLongSet ids = new TLongHashSet(); + + int[] count = new int[]{0}; + boolean[] ocean = new boolean[]{false}; + boolean[] land = new boolean[]{false}; List coastLines = new ArrayList(); List basemapCoastLines = new ArrayList(); int leftX = MapUtils.get31TileNumberX(cLeftLongitude); int rightX = MapUtils.get31TileNumberX(cRightLongitude); int bottomY = MapUtils.get31TileNumberY(cBottomLatitude); int topY = MapUtils.get31TileNumberY(cTopLatitude); - BinaryMapIndexReader.SearchFilter searchFilter = new BinaryMapIndexReader.SearchFilter() { + TLongSet ids = new TLongHashSet(); + MapIndex mi = readMapObjectsForRendering(zoom, renderingReq, tempResult, basemapResult, ids, count, ocean, + land, coastLines, basemapCoastLines, leftX, rightX, bottomY, topY); + int renderRouteDataFile = 0; + if (renderingReq.searchRenderingAttribute("showRoadMapsAttribute")) { + renderRouteDataFile = renderingReq.getIntPropertyValue(renderingReq.ALL.R_ATTR_INT_VALUE); + } + if (checkWhetherInterrupted()) { + return false; + } + if (renderRouteDataFile >= 0 && zoom >= BASEMAP_ZOOM ) { + searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, null); + for (BinaryMapIndexReader c : files.values()) { + // false positive case when we have 2 sep maps Country-roads & Country + if(c.getMapIndexes().size() == 0 || renderRouteDataFile == 1) { + readRouteDataAsMapObjects(searchRequest, c, tempResult, ids); + } + } + log.info(String.format("Route objects %s", tempResult.size() +"")); + } + String coastlineTime = ""; + boolean addBasemapCoastlines = true; + boolean emptyData = zoom > BASEMAP_ZOOM && tempResult.isEmpty() && coastLines.isEmpty(); + boolean basemapMissing = zoom <= BASEMAP_ZOOM && basemapCoastLines.isEmpty() && mi == null; + boolean detailedLandData = zoom >= zoomForBaseRouteRendering && tempResult.size() > 0 && renderRouteDataFile < 0; + if (!coastLines.isEmpty()) { + long ms = System.currentTimeMillis(); + boolean coastlinesWereAdded = processCoastlines(coastLines, leftX, rightX, bottomY, topY, zoom, + basemapCoastLines.isEmpty(), true, tempResult); + addBasemapCoastlines = (!coastlinesWereAdded && !detailedLandData) || zoom <= BASEMAP_ZOOM; + coastlineTime = "(coastline " + (System.currentTimeMillis() - ms) + " ms )"; + } else { + addBasemapCoastlines = !detailedLandData; + } + if (addBasemapCoastlines) { + long ms = System.currentTimeMillis(); + boolean coastlinesWereAdded = processCoastlines(basemapCoastLines, leftX, rightX, bottomY, topY, zoom, + true, true, tempResult); + addBasemapCoastlines = !coastlinesWereAdded; + coastlineTime = "(coastline " + (System.currentTimeMillis() - ms) + " ms )"; + } + if (addBasemapCoastlines && mi != null) { + BinaryMapDataObject o = new BinaryMapDataObject(new int[]{leftX, topY, rightX, topY, rightX, bottomY, leftX, bottomY, leftX, + topY}, new int[]{ocean[0] && !land[0] ? mi.coastlineEncodingType : (mi.landEncodingType)}, null, -1); + o.setMapIndex(mi); + tempResult.add(o); + } + if (emptyData || basemapMissing) { + // message + MapIndex mapIndex; + if (!tempResult.isEmpty()) { + mapIndex = tempResult.get(0).getMapIndex(); + } else { + mapIndex = new MapIndex(); + mapIndex.initMapEncodingRule(0, 1, "natural", "coastline"); + mapIndex.initMapEncodingRule(0, 2, "name", ""); + } + } + if (zoom <= BASEMAP_ZOOM || emptyData) { + tempResult.addAll(basemapResult); + } + + + if (count[0] > 0) { + log.info(String.format("BLat=%s, TLat=%s, LLong=%s, RLong=%s, zoom=%s", //$NON-NLS-1$ + cBottomLatitude, cTopLatitude, cLeftLongitude, cRightLongitude, zoom)); + log.info(String.format("Searching: %s ms %s (%s results found)", System.currentTimeMillis() - now, coastlineTime, count[0])); //$NON-NLS-1$ + } + + + cObjects = tempResult; + cObjectsBox = dataBox; + + return true; + } + + + + private MapIndex readMapObjectsForRendering(final int zoom, final RenderingRuleSearchRequest renderingReq, + ArrayList tempResult, ArrayList basemapResult, + TLongSet ids, int[] count, boolean[] ocean, boolean[] land, List coastLines, + List basemapCoastLines, int leftX, int rightX, int bottomY, int topY) { + BinaryMapIndexReader.SearchFilter searchFilter = new BinaryMapIndexReader.SearchFilter() { @Override public boolean accept(TIntArrayList types, BinaryMapIndexReader.MapIndex root) { for (int j = 0; j < types.size(); j++) { @@ -318,11 +479,10 @@ public class MapRenderRepositories { if (zoom > 16) { searchFilter = null; } - boolean ocean = false; - boolean land = false; MapIndex mi = null; searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, searchFilter); for (BinaryMapIndexReader c : files.values()) { + boolean basemap = c.isBasemap(); searchRequest.clearSearchResults(); List res; try { @@ -331,99 +491,52 @@ public class MapRenderRepositories { res = new ArrayList(); log.debug("Search failed " + c.getRegionNames(), e); //$NON-NLS-1$ } + if(res.size() > 0) { + if(basemap) { + renderedState |= 1; + } else { + renderedState |= 2; + } + } for (BinaryMapDataObject r : res) { - if (checkForDuplicateObjectIds) { + if (checkForDuplicateObjectIds && !basemap) { if (ids.contains(r.getId()) && r.getId() > 0) { // do not add object twice continue; } ids.add(r.getId()); } - count++; + count[0]++; if (r.containsType(r.getMapIndex().coastlineEncodingType)) { - if (c.isBasemap()) { + if (basemap) { basemapCoastLines.add(r); } else { coastLines.add(r); } } else { // do not mess coastline and other types - if (c.isBasemap()) { + if (basemap) { basemapResult.add(r); } else { tempResult.add(r); } } if (checkWhetherInterrupted()) { - return false; + return null; } } if (searchRequest.isOcean()) { mi = c.getMapIndexes().get(0); - ocean = true; + ocean[0] = true; } if (searchRequest.isLand()) { mi = c.getMapIndexes().get(0); - land = true; + land[0] = true; } } - - String coastlineTime = ""; - boolean addBasemapCoastlines = true; - boolean emptyData = zoom > BASEMAP_ZOOM && tempResult.isEmpty() && coastLines.isEmpty(); - boolean basemapMissing = zoom <= BASEMAP_ZOOM && basemapCoastLines.isEmpty() && mi == null; - boolean detailedLandData = zoom >= 14 && tempResult.size() > 0; - if (!coastLines.isEmpty()) { - long ms = System.currentTimeMillis(); - boolean coastlinesWereAdded = processCoastlines(coastLines, leftX, rightX, bottomY, topY, zoom, - basemapCoastLines.isEmpty(), true, tempResult); - addBasemapCoastlines = (!coastlinesWereAdded && !detailedLandData) || zoom <= BASEMAP_ZOOM; - coastlineTime = "(coastline " + (System.currentTimeMillis() - ms) + " ms )"; - } else { - addBasemapCoastlines = !detailedLandData; - } - if (addBasemapCoastlines) { - long ms = System.currentTimeMillis(); - boolean coastlinesWereAdded = processCoastlines(basemapCoastLines, leftX, rightX, bottomY, topY, zoom, - true, true, tempResult); - addBasemapCoastlines = !coastlinesWereAdded; - coastlineTime = "(coastline " + (System.currentTimeMillis() - ms) + " ms )"; - } - if (addBasemapCoastlines && mi != null) { - BinaryMapDataObject o = new BinaryMapDataObject(new int[]{leftX, topY, rightX, topY, rightX, bottomY, leftX, bottomY, leftX, - topY}, new int[]{ocean && !land ? mi.coastlineEncodingType : (mi.landEncodingType)}, null, -1); - o.setMapIndex(mi); - tempResult.add(o); - } - if (emptyData || basemapMissing) { - // message - MapIndex mapIndex; - if (!tempResult.isEmpty()) { - mapIndex = tempResult.get(0).getMapIndex(); - } else { - mapIndex = new MapIndex(); - mapIndex.initMapEncodingRule(0, 1, "natural", "coastline"); - mapIndex.initMapEncodingRule(0, 2, "name", ""); - } - } - if (zoom <= BASEMAP_ZOOM || emptyData) { - tempResult.addAll(basemapResult); - } - - - if (count > 0) { - log.info(String.format("BLat=%s, TLat=%s, LLong=%s, RLong=%s, zoom=%s", //$NON-NLS-1$ - cBottomLatitude, cTopLatitude, cLeftLongitude, cRightLongitude, zoom)); - log.info(String.format("Searching: %s ms %s (%s results found)", System.currentTimeMillis() - now, coastlineTime, count)); //$NON-NLS-1$ - } - - - cObjects = tempResult; - cObjectsBox = dataBox; - - return true; + return mi; } private void validateLatLonBox(QuadRect box) { @@ -441,61 +554,14 @@ public class MapRenderRepositories { } } + - // only single thread to read ! - public synchronized boolean checkIfMapIsEmpty(int leftX, int rightX, int topY, int bottomY, int zoom){ - final boolean[] empty = new boolean[] {true}; - SearchRequest searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, - null, new ResultMatcher() { - @Override - public boolean publish(BinaryMapDataObject object) { - empty[0] = false; - return false; - } - - @Override - public boolean isCancelled() { - return !empty[0]; - } - }); - SearchRequest searchRouteRequest = BinaryMapIndexReader.buildSearchRouteRequest(leftX, rightX, topY, bottomY, - new ResultMatcher() { - @Override - public boolean publish(RouteDataObject object) { - empty[0] = false; - return false; - } - - @Override - public boolean isCancelled() { - return !empty[0]; - } - }); - for (BinaryMapIndexReader c : files.values()) { - if (!c.isBasemap()) { - try { - c.searchMapIndex(searchRequest); - } catch (IOException e) { - // lots of FalsePositive cases - return false; - } - if (!empty[0]) { - return false; - } - for (RouteRegion r : c.getRoutingIndexes()) { - try { - List regs = c.searchRouteIndexTree(searchRouteRequest, r.getSubregions()); - if(!regs.isEmpty()) { - return false; - } - } catch (IOException e) { - // lots of FalsePositive cases - return false; - } - } - } + public boolean isLastMapRenderedEmpty(boolean checkBaseMap){ + if(checkBaseMap) { + return prevBmp != null && previousRenderedState == 0; + } else { + return prevBmp != null && previousRenderedState == 1; } - return empty[0]; } public synchronized void loadMap(RotatedTileBox tileRect, List notifyList) { @@ -538,11 +604,11 @@ public class MapRenderRepositories { // prevent editing requestedBox = new RotatedTileBox(tileRect); + // calculate data box QuadRect dataBox = requestedBox.getLatLonBounds(); long now = System.currentTimeMillis(); - if (cObjectsBox.left > dataBox.left || cObjectsBox.top > dataBox.top || cObjectsBox.right < dataBox.right || cObjectsBox.bottom < dataBox.bottom || (nativeLib != null) == (cNativeObjects == null)) { // increase data box in order for rotate @@ -556,6 +622,7 @@ public class MapRenderRepositories { dataBox.bottom -= hi; } validateLatLonBox(dataBox); + renderedState = 0; boolean loaded; if(nativeLib != null) { cObjects = new LinkedList(); @@ -618,6 +685,7 @@ public class MapRenderRepositories { Bitmap reuse = prevBmp; this.prevBmp = this.bmp; this.prevBmpLocation = this.bmpLocation; + this.previousRenderedState = renderedState; if (reuse != null && reuse.getWidth() == currentRenderingContext.width && reuse.getHeight() == currentRenderingContext.height) { bmp = reuse; bmp.eraseColor(currentRenderingContext.defaultColor); @@ -726,6 +794,7 @@ public class MapRenderRepositories { cObjectsBox = new QuadRect(); requestedBox = prevBmpLocation = null; + previousRenderedState = 0; // Do not clear main bitmap to not cause a screen refresh // prevBmp = null; // bmp = null; diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index b86cade006..99bc961d9a 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -165,7 +165,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { int right = MapUtils.get31TileNumberX(tileBox.getRightBottomLatLon().getLongitude()); int top = MapUtils.get31TileNumberY(tileBox.getLeftTopLatLon().getLatitude()); int bottom = MapUtils.get31TileNumberY(tileBox.getRightBottomLatLon().getLatitude()); - final boolean empty = rm.getRenderer().checkIfMapIsEmpty(left, right, top, bottom, tileBox.getZoom()); + final boolean empty = rm.getRenderer().isLastMapRenderedEmpty(false); noMapsPresent = empty; if (!empty && tileBox.getZoom() >= ZOOM_TO_SHOW_MAP_NAMES) { return Collections.emptyList(); From 82137dc66bc9aa589eadbb59302097546e50653e Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 1 Mar 2014 16:49:21 +0200 Subject: [PATCH 06/17] Fix roundabout issue --- .../net/osmand/router/BinaryRoutePlanner.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java index 26e77216e3..b798c78fca 100644 --- a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java +++ b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java @@ -98,7 +98,7 @@ public class BinaryRoutePlanner { graphReverseSegments.size()) * STANDARD_ROAD_IN_QUEUE_OVERHEAD; if(TRACE_ROUTING){ - printRoad(">", segment); + printRoad(">", segment, !forwardSearch); } if(segment instanceof FinalRouteSegment) { if(RoutingContext.SHOW_GC_SIZE){ @@ -136,9 +136,9 @@ public class BinaryRoutePlanner { } if (ctx.planRouteIn2Directions()) { forwardSearch = (nonHeuristicSegmentsComparator.compare(graphDirectSegments.peek(), graphReverseSegments.peek()) < 0); - if (graphDirectSegments.size() * 1.3 > graphReverseSegments.size()) { + if (graphDirectSegments.size() * 2 > graphReverseSegments.size()) { forwardSearch = false; - } else if (graphDirectSegments.size() < 1.3 * graphReverseSegments.size()) { + } else if (graphDirectSegments.size() < 2 * graphReverseSegments.size()) { forwardSearch = true; } } else { @@ -236,14 +236,18 @@ public class BinaryRoutePlanner { } - private void printRoad(String prefix, RouteSegment segment) { + private void printRoad(String prefix, RouteSegment segment, Boolean reverseWaySearch) { String pr; if(segment.parentRoute != null){ pr = " pend="+segment.parentSegmentEnd +" parent=" + segment.parentRoute.road; } else { pr = ""; } - println(prefix +"" + segment.road + " dir="+segment.getDirectionAssigned()+" ind=" + segment.getSegmentStart() + + String p = ""; + if(reverseWaySearch != null) { + p = (reverseWaySearch?"B" : "F"); + } + println(p+prefix +"" + segment.road + " dir="+segment.getDirectionAssigned()+" ind=" + segment.getSegmentStart() + " ds=" + ((float)segment.distanceFromStart) + " es="+((float)segment.distanceToEnd) + pr); } @@ -304,7 +308,7 @@ public class BinaryRoutePlanner { final RouteDataObject road = segment.road; boolean initDirectionAllowed = checkIfInitialMovementAllowedOnSegment(ctx, reverseWaySearch, visitedSegments, segment, road); if(TEST_SPECIFIC && road.getId() == TEST_ID ) { - printRoad(" ! " + +segment.distanceFromStart + " ", segment); + printRoad(" ! " + +segment.distanceFromStart + " ", segment, reverseWaySearch); } boolean directionAllowed = initDirectionAllowed; if(!directionAllowed) { @@ -433,7 +437,7 @@ public class BinaryRoutePlanner { frs.opposite = opposite; graphSegments.add(frs); if(TRACE_ROUTING){ - printRoad(" >> Final segment : ", frs); + printRoad(" >> Final segment : ", frs, reverseWaySearch); } return true; } @@ -634,7 +638,7 @@ public class BinaryRoutePlanner { printRoad(" !? distFromStart=" + +distFromStart + " from " + segment.getRoad().getId() + " dir=" + segment.getDirectionAssigned() + " distToEnd=" + distanceToEnd + - " segmentPoint="+ segmentPoint + " -- ", next); + " segmentPoint="+ segmentPoint + " -- ", next, true); } if (!visitedSegments.containsKey(calculateRoutePointId(next, next.isPositive()))) { if (next.getParentRoute() == null @@ -643,7 +647,7 @@ public class BinaryRoutePlanner { next.distanceFromStart = distFromStart; next.distanceToEnd = distanceToEnd; if (TRACE_ROUTING) { - printRoad(" >>", next); + printRoad(" >>", next, null); } // put additional information to recover whole route after next.setParentRoute(segment); From 4279cf6150472d11608ae1dbe9b06f5334beb2e0 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sat, 1 Mar 2014 19:02:50 +0200 Subject: [PATCH 07/17] Add field for java pc rendering --- OsmAnd-java/src/net/osmand/RenderingContext.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd-java/src/net/osmand/RenderingContext.java b/OsmAnd-java/src/net/osmand/RenderingContext.java index d6536b3a90..2aac0a56ee 100644 --- a/OsmAnd-java/src/net/osmand/RenderingContext.java +++ b/OsmAnd-java/src/net/osmand/RenderingContext.java @@ -18,6 +18,7 @@ public class RenderingContext { } } + public int renderedState = 0; // FIELDS OF THAT CLASS ARE USED IN C++ public boolean interrupted = false; public boolean nightMode = false; From 1f7f7f54da1b537f5bef97f92e955a8f87a89c63 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sun, 2 Mar 2014 18:24:02 +0200 Subject: [PATCH 08/17] Add osmand route calculation following gpx track --- .../router/PrecalculatedRouteDirection.java | 23 ++ OsmAnd/res/values/strings.xml | 1 + .../osmand/plus/OsmAndLocationSimulation.java | 9 +- .../src/net/osmand/plus/OsmandSettings.java | 1 + .../activities/actions/NavigateAction.java | 21 +- .../osmand/plus/base/FailSafeFuntions.java | 19 +- .../osmand/plus/routing/RouteProvider.java | 225 +++++++++++++----- 7 files changed, 226 insertions(+), 73 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java b/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java index bdce12e940..68bcc8195e 100644 --- a/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java +++ b/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; import net.osmand.binary.RouteDataObject; +import net.osmand.data.LatLon; import net.osmand.data.QuadPoint; import net.osmand.data.QuadRect; import net.osmand.data.QuadTree; @@ -42,6 +43,11 @@ public class PrecalculatedRouteDirection { init(ls); } + private PrecalculatedRouteDirection(LatLon[] ls, float maxSpeed) { + this.maxSpeed = maxSpeed; + init(ls); + } + private PrecalculatedRouteDirection(PrecalculatedRouteDirection parent, int s1, int s2) { this.minSpeed = parent.minSpeed; this.maxSpeed = parent.maxSpeed; @@ -81,6 +87,10 @@ public class PrecalculatedRouteDirection { return null; } + public static PrecalculatedRouteDirection build(LatLon[] ls, float maxSpeed){ + return new PrecalculatedRouteDirection(ls, maxSpeed); + } + private void init(List ls) { TIntArrayList px = new TIntArrayList(); @@ -104,6 +114,19 @@ public class PrecalculatedRouteDirection { } init(px, py, speedSegments); } + + private void init(LatLon[] ls) { + TIntArrayList px = new TIntArrayList(); + TIntArrayList py = new TIntArrayList(); + List speedSegments = new ArrayList(); + for (LatLon s : ls) { + float routeSpd = maxSpeed; // (s.getDistance() / s.getRoutingTime()) + px.add(MapUtils.get31TileNumberX(s.getLongitude())); + py.add(MapUtils.get31TileNumberY(s.getLatitude())); + speedSegments.add(routeSpd); + } + init(px, py, speedSegments); + } private void init(TIntArrayList px, TIntArrayList py, List speedSegments) { float totaltm = 0; diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 06c3bab9c0..b686fc5d54 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Calculate OsmAnd offline route Truck Navigation preferences Routing preferences diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java index 9387bdafbc..0c0795c83f 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java @@ -8,8 +8,8 @@ import net.osmand.CallbackWithObject; import net.osmand.Location; import net.osmand.access.AccessibleToast; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider.GPXRouteParams; +import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder; import net.osmand.plus.routing.RoutingHelper; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -72,8 +72,11 @@ public class OsmAndLocationSimulation { new CallbackWithObject() { @Override public boolean processResult(GPXUtilities.GPXFile result) { - GPXRouteParams prms = new RouteProvider.GPXRouteParams(result, false, ch - .isChecked(), app.getSettings()); + GPXRouteParamsBuilder builder = GPXRouteParams.GPXRouteParamsBuilder.newBuilder(result, app.getSettings()); + if(ch.isChecked()){ + builder.announceWaypoints(); + } + GPXRouteParams prms = builder.build(); startAnimationThread(app.getRoutingHelper(), ma, prms.getPoints(), true, speedup.getProgress() + 1); return true; diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 13e3a77263..d7f3161e39 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -739,6 +739,7 @@ public class OsmandSettings { public final OsmandPreference SPEAK_SPEED_LIMIT = new BooleanPreference("speak_speed_limit", true).makeProfile().cache(); public final OsmandPreference SPEAK_GPX_WPT = new BooleanPreference("speak_gpx_wpt", true).makeGlobal().cache(); + public final OsmandPreference CALC_GPX_ROUTE = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache(); diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java b/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java index f6712b5f91..a2f401f3e3 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/NavigateAction.java @@ -19,6 +19,7 @@ import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.routing.RouteProvider.GPXRouteParams; import net.osmand.plus.routing.RouteProvider.RouteService; +import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -66,10 +67,11 @@ public class NavigateAction { public boolean navigateUsingGPX(final ApplicationMode appMode, final LatLon endForRouting, final GPXFile result) { Builder builder = new AlertDialog.Builder(mapActivity); - final boolean[] props = new boolean[]{false, false, false, settings.SPEAK_GPX_WPT.get()}; + final boolean[] props = new boolean[]{false, false, false, settings.SPEAK_GPX_WPT.get(), settings.CALC_GPX_ROUTE.get()}; builder.setMultiChoiceItems(new String[] { getString(R.string.gpx_option_reverse_route), getString(R.string.gpx_option_destination_point), getString(R.string.gpx_option_from_start_point), - getString(R.string.announce_gpx_waypoints) }, props, + getString(R.string.announce_gpx_waypoints), + getString(R.string.calculate_osmand_route_gpx)}, props, new OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { @@ -83,9 +85,20 @@ public class NavigateAction { boolean passWholeWay = props[2]; boolean useDestination = props[1]; boolean announceGpxWpt = props[3]; + boolean calculateOsmAndRoute = props[4]; settings.SPEAK_GPX_WPT.set(announceGpxWpt); - GPXRouteParams gpxRoute = new GPXRouteParams(result, reverse, announceGpxWpt, settings); - + settings.CALC_GPX_ROUTE.set(calculateOsmAndRoute); + GPXRouteParamsBuilder bld = GPXRouteParamsBuilder.newBuilder(result, settings); + if(reverse) { + bld.reverse(); + } + if(announceGpxWpt) { + bld.announceWaypoints(); + } + if(calculateOsmAndRoute) { + bld.calculateOsmAndRoute(); + } + GPXRouteParams gpxRoute = bld.build(); Location loc = getLastKnownLocation(); if(passWholeWay && loc != null){ gpxRoute.setStartPoint(loc); diff --git a/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java b/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java index 0ed3c6d6cd..e66a6781d3 100644 --- a/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java +++ b/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java @@ -16,6 +16,7 @@ import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.routing.RouteProvider.GPXRouteParams; +import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.DialogInterface; @@ -123,14 +124,26 @@ public class FailSafeFuntions { @Override protected void onPostExecute(GPXFile result) { - final GPXRouteParams gpxRoute = result == null ? null : new GPXRouteParams(result, false, - settings.SPEAK_GPX_WPT.get(), settings); + final GPXRouteParams gpxRoute; + if (result != null) { + GPXRouteParamsBuilder builder = GPXRouteParamsBuilder.newBuilder(result, settings); + if (settings.SPEAK_GPX_WPT.get()) { + builder.announceWaypoints(); + } + if(settings.CALC_GPX_ROUTE.get()) { + builder.calculateOsmAndRoute(); + } + gpxRoute = builder.build(); + } else { + gpxRoute = null; + } LatLon endPoint = pointToNavigate != null ? pointToNavigate : gpxRoute.getLastPoint(); net.osmand.Location startPoint = gpxRoute == null ? null : gpxRoute.getStartPointForRoute(); if (endPoint == null) { notRestoreRoutingMode(ma, app); } else { - ma.followRoute(settings.getApplicationMode(), endPoint, targetPoints.getIntermediatePoints(), startPoint, gpxRoute); + ma.followRoute(settings.getApplicationMode(), endPoint, + targetPoints.getIntermediatePoints(), startPoint, gpxRoute); } } }; diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 6e9073435c..e8cbf61d0e 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -3,6 +3,7 @@ package net.osmand.plus.routing; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; @@ -48,6 +49,7 @@ import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter.GeneralRouterProfile; import net.osmand.router.GeneralRouter.RoutingParameter; import net.osmand.router.GeneralRouter.RoutingParameterType; +import net.osmand.router.PrecalculatedRouteDirection; import net.osmand.router.RoutePlannerFrontEnd; import net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode; import net.osmand.router.RouteSegmentResult; @@ -115,9 +117,9 @@ public class RouteProvider { List points = new ArrayList(); List directions; DataTileManager wpt; + boolean calculateOsmAndRoute = false; - public GPXRouteParams(GPXFile file, boolean reverse, boolean announceWaypoints, OsmandSettings settings){ - prepareEverything(file, reverse, announceWaypoints, settings.DRIVING_REGION.get().leftHandDriving); + private GPXRouteParams(){ } public void setStartPoint(Location startPoint) { @@ -144,6 +146,45 @@ public class RouteProvider { return null; } + public static class GPXRouteParamsBuilder { + + private GPXRouteParams obj = new GPXRouteParams(); + private GPXFile file; + private boolean leftHandDriving; + private boolean reverse; + private boolean announceWaypoints; + private GPXRouteParamsBuilder(GPXFile f, OsmandSettings settings) { + this.file = f; + leftHandDriving = settings.DRIVING_REGION.get().leftHandDriving; +// obj = new GPXRouteParams(file, reverse, announceWaypoints, settings) + // TODO Auto-generated constructor stub + } + + public GPXRouteParamsBuilder reverse() { + this.reverse = true; + return this; + } + + public GPXRouteParamsBuilder announceWaypoints() { + this.announceWaypoints = true; + return this; + } + + public GPXRouteParamsBuilder calculateOsmAndRoute() { + obj.calculateOsmAndRoute = true; + return this; + } + + public static GPXRouteParamsBuilder newBuilder(GPXFile f, OsmandSettings settings) { + return new GPXRouteParamsBuilder(f, settings); + } + + public GPXRouteParams build(){ + obj.prepareEverything(file, reverse, announceWaypoints, leftHandDriving); + return obj; + } + } + private void prepareEverything(GPXFile file, boolean reverse, boolean announceWaypoints, boolean leftSide){ if(file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)){ directions = parseCloudmadeRoute(points, file, OSMAND_ROUTER.equals(file.author), leftSide, 10); @@ -210,7 +251,10 @@ public class RouteProvider { } try { RouteCalculationResult res; - if(params.gpxRoute != null && !params.gpxRoute.points.isEmpty()){ + boolean calcGPXRoute = params.gpxRoute != null && !params.gpxRoute.points.isEmpty(); + if (params.type == RouteService.OSMAND || (calcGPXRoute && params.gpxRoute.calculateOsmAndRoute)) { + res = findVectorMapsRoute(params, calcGPXRoute); + } else if(calcGPXRoute){ res = calculateGpxRoute(params); } else if (params.type == RouteService.YOURS) { res = findYOURSRoute(params); @@ -218,8 +262,6 @@ public class RouteProvider { res = findORSRoute(params); } else if (params.type == RouteService.OSRM) { res = findOSRMRoute(params); - } else if (params.type == RouteService.OSMAND) { - res = findVectorMapsRoute(params); } else if (params.type == RouteService.BROUTER) { res = findBROUTERRoute(params); } else { @@ -246,45 +288,20 @@ public class RouteProvider { private RouteCalculationResult calculateGpxRoute(RouteCalculationParams pars) { RouteCalculationResult res; // get the closest point to start and to end - float minDist = Integer.MAX_VALUE; - int startI = 0; GPXRouteParams params = pars.gpxRoute; List gpxRoute = params.points; - int endI = gpxRoute.size(); - if (pars.start != null) { - for (int i = 0; i < gpxRoute.size(); i++) { - float d = gpxRoute.get(i).distanceTo(pars.start); - if (d < minDist) { - startI = i; - minDist = d; - } - } - } else { - pars.start = gpxRoute.get(0); - } - Location l = new Location("temp"); //$NON-NLS-1$ - l.setLatitude(pars.end.getLatitude()); - l.setLongitude(pars.end.getLongitude()); - minDist = Integer.MAX_VALUE; - // get in reverse order taking into account ways with cycle - for (int i = gpxRoute.size() - 1; i >= startI; i--) { - float d = gpxRoute.get(i).distanceTo(l); - if (d < minDist) { - endI = i + 1; - // slightly modify to allow last point to be added - minDist = d - 40; - } - } - ArrayList sublist = new ArrayList(gpxRoute.subList(startI, endI)); + int[] startI = new int[]{0}; + int[] endI = new int[]{gpxRoute.size()}; + ArrayList sublist = findGpxLocations(pars, startI, endI); pars.intermediates = null; if(params.directions == null){ res = new RouteCalculationResult(sublist, null, pars, params.wpt); } else { List subdirections = new ArrayList(); for (RouteDirectionInfo info : params.directions) { - if(info.routePointOffset >= startI && info.routePointOffset < endI){ + if(info.routePointOffset >= startI[0] && info.routePointOffset < endI[0]){ RouteDirectionInfo ch = new RouteDirectionInfo(info.getAverageSpeed(), info.getTurnType()); - ch.routePointOffset = info.routePointOffset - startI; + ch.routePointOffset = info.routePointOffset - startI[0]; ch.setDescriptionRoute(info.getDescriptionRoute()); // recalculate @@ -297,6 +314,49 @@ public class RouteProvider { } return res; } + + + + + private ArrayList findGpxLocations(RouteCalculationParams pars, int[] startI, int[] endI) { + GPXRouteParams params = pars.gpxRoute; + List gpxRoute = params.points; + float minDist = Integer.MAX_VALUE; + int start = 0; + int end = gpxRoute.size(); + if (pars.start != null) { + for (int i = 0; i < gpxRoute.size(); i++) { + float d = gpxRoute.get(i).distanceTo(pars.start); + if (d < minDist) { + start = i; + minDist = d; + } + } + } else { + pars.start = gpxRoute.get(0); + } + Location l = new Location("temp"); //$NON-NLS-1$ + l.setLatitude(pars.end.getLatitude()); + l.setLongitude(pars.end.getLongitude()); + minDist = Integer.MAX_VALUE; + // get in reverse order taking into account ways with cycle + for (int i = gpxRoute.size() - 1; i >= start; i--) { + float d = gpxRoute.get(i).distanceTo(l); + if (d < minDist) { + end = i + 1; + // slightly modify to allow last point to be added + minDist = d - 40; + } + } + ArrayList sublist = new ArrayList(gpxRoute.subList(start, end)); + if(startI != null) { + startI[0] = start; + } + if(endI != null) { + endI[0] = end; + } + return sublist; + } protected String getString(ClientContext ctx, int resId){ if(ctx == null){ @@ -370,10 +430,65 @@ public class RouteProvider { return new RouteCalculationResult(res, null, params, null); } - protected RouteCalculationResult findVectorMapsRoute(final RouteCalculationParams params) throws IOException { + protected RouteCalculationResult findVectorMapsRoute(final RouteCalculationParams params, boolean calcGPXRoute) throws IOException { BinaryMapIndexReader[] files = params.ctx.getTodoAPI().getRoutingMapFiles(); RoutePlannerFrontEnd router = new RoutePlannerFrontEnd(false); OsmandSettings settings = params.ctx.getSettings(); + + GeneralRouter generalRouter = SettingsNavigationActivity.getRouter(params.mode); + if(generalRouter == null) { + return applicationModeNotSupported(params); + } + RoutingConfiguration cf = initOsmAndRoutingConfig(params, settings, generalRouter); + if(cf == null){ + return applicationModeNotSupported(params); + } + PrecalculatedRouteDirection precalculated = null; + if(calcGPXRoute) { + ArrayList sublist = findGpxLocations(params, null, null); + LatLon[] latLon = new LatLon[sublist.size()]; + for(int k = 0; k < latLon.length; k ++) { + latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude()); + } + precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxDefaultSpeed()); + cf.planRoadDirection = 1; + } + // BUILD context + RoutingContext ctx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, + RouteCalculationMode.NORMAL); + + RoutingContext complexCtx = null; + boolean complex = params.mode.isDerivedRoutingFrom(ApplicationMode.CAR) && !settings.DISABLE_COMPLEX_ROUTING.get() + && precalculated == null; + if(complex) { + complexCtx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, + RouteCalculationMode.COMPLEX); + complexCtx.calculationProgress = params.calculationProgress; + complexCtx.leftSideNavigation = params.leftSide; + } + if(precalculated != null) { + ctx.precalculatedRouteDirection = precalculated.adopt(ctx); + } + ctx.leftSideNavigation = params.leftSide; + ctx.calculationProgress = params.calculationProgress; + if(params.previousToRecalculate != null) { + // not used any more + // ctx.previouslyCalculatedRoute = params.previousToRecalculate.getOriginalRoute(); + } + LatLon st = new LatLon(params.start.getLatitude(), params.start.getLongitude()); + LatLon en = new LatLon(params.end.getLatitude(), params.end.getLongitude()); + List inters = new ArrayList(); + if (params.intermediates != null) { + inters = new ArrayList(params.intermediates); + } + return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters); + } + + + + + private RoutingConfiguration initOsmAndRoutingConfig(final RouteCalculationParams params, OsmandSettings settings, + GeneralRouter generalRouter) throws IOException, FileNotFoundException { File routingXml = params.ctx.getAppPath(IndexConstants.ROUTING_XML_FILE); RoutingConfiguration.Builder config ; if (routingXml.exists() && routingXml.canRead()) { @@ -393,12 +508,9 @@ public class RouteProvider { } else if(params.mode.isDerivedRoutingFrom(ApplicationMode.CAR)){ p = GeneralRouterProfile.CAR; } else { - return applicationModeNotSupported(params); - } - GeneralRouter generalRouter = SettingsNavigationActivity.getRouter(params.mode); - if(generalRouter == null) { - return applicationModeNotSupported(params); + return null; } + Map paramsR = new LinkedHashMap(); for(Map.Entry e : generalRouter.getParameters().entrySet()){ String key = e.getKey(); @@ -427,28 +539,15 @@ public class RouteProvider { RoutingConfiguration cf = config.build(p.name().toLowerCase(), params.start.hasBearing() ? params.start.getBearing() / 180d * Math.PI : null, memoryLimit, paramsR); - boolean complex = params.mode.isDerivedRoutingFrom(ApplicationMode.CAR) && !settings.DISABLE_COMPLEX_ROUTING.get(); - RoutingContext ctx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, - RouteCalculationMode.NORMAL); - RoutingContext complexCtx = null; - if(complex) { - complexCtx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, - RouteCalculationMode.COMPLEX); - complexCtx.calculationProgress = params.calculationProgress; - complexCtx.leftSideNavigation = params.leftSide; - } - ctx.leftSideNavigation = params.leftSide; - ctx.calculationProgress = params.calculationProgress; - if(params.previousToRecalculate != null) { - // not used any more - // ctx.previouslyCalculatedRoute = params.previousToRecalculate.getOriginalRoute(); - } - LatLon st = new LatLon(params.start.getLatitude(), params.start.getLongitude()); - LatLon en = new LatLon(params.end.getLatitude(), params.end.getLongitude()); - List inters = new ArrayList(); - if (params.intermediates != null) { - inters = new ArrayList(params.intermediates); - } + return cf; + } + + + + + private RouteCalculationResult calcOfflineRouteImpl(final RouteCalculationParams params, + RoutePlannerFrontEnd router, RoutingContext ctx, RoutingContext complexCtx, LatLon st, LatLon en, + List inters) throws IOException { try { List result ; if(complexCtx != null) { From a16882f672934529fea1a39e415d344338af805d Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sun, 2 Mar 2014 20:35:20 +0200 Subject: [PATCH 09/17] Try to move the data when user change directory --- OsmAnd/res/values/strings.xml | 6 +- .../activities/SettingsGeneralActivity.java | 144 ++++++++++++++++-- .../base/SuggestExternalDirectoryDialog.java | 12 +- 3 files changed, 144 insertions(+), 18 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index b686fc5d54..befabb803f 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,10 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + OsmAnd could try to move the data to new destination. Do you want it? + Copying file (%s) to new destination... + Copying OsmAnd files to new destination (%s) + Copying OsmAnd files Calculate OsmAnd offline route Truck Navigation preferences @@ -1252,7 +1256,7 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A OsmAnd offline navigation is an experimental feature and it does not work for distances of more than about 20 km.\n\nNavigation service is temporarily switched to online CloudMade. Can not find specified directory. Storage directory - Changing the storage directory will not move or delete the data. This must be performed separately and outside OsmAnd. Continue anyway? + A previous OsmAnd version is installed. All offline data will be supported by the new application. But Favorite points should be exported in the old application and later imported by the new one. Build {0} successfully installed ({1}). Downloading build… diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 4ea463088f..177b009082 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -2,23 +2,32 @@ package net.osmand.plus.activities; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.List; +import net.osmand.CallbackWithObject; import net.osmand.IProgress; +import net.osmand.IndexConstants; import net.osmand.access.AccessibleToast; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ClientContext; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.DrivingRegion; import net.osmand.plus.OsmandSettings.MetricsConstants; +import net.osmand.plus.ProgressDialogImplementation; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.base.SuggestExternalDirectoryDialog; import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.voice.CommandPlayer; import net.osmand.render.RenderingRulesStorage; +import net.osmand.util.Algorithms; import android.app.AlertDialog; import android.app.AlertDialog.Builder; +import android.app.ProgressDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; @@ -101,12 +110,12 @@ public class SettingsGeneralActivity extends SettingsBaseActivity { dialog.dismiss(); showOtherDialog(); } - }, new Runnable() { + }, new CallbackWithObject() { + @Override - public void run() { - Toast.makeText(SettingsGeneralActivity.this, getString(R.string.application_dir_change_warning), - Toast.LENGTH_LONG).show(); - reloadIndexes(); + public boolean processResult(String result) { + warnAboutChangingStorage(result); + return true; } }); return false; @@ -264,6 +273,97 @@ public class SettingsGeneralActivity extends SettingsBaseActivity { } return true; } + + public static class MoveFilesToDifferentDirectory extends AsyncTask { + + private File to; + private Context ctx; + private File from; + private ProgressDialogImplementation progress; + private Runnable runOnSuccess; + + public MoveFilesToDifferentDirectory(Context ctx, File from, File to) { + this.ctx = ctx; + this.from = from; + this.to = to; + } + + public void setRunOnSuccess(Runnable runOnSuccess) { + this.runOnSuccess = runOnSuccess; + } + + @Override + protected void onPreExecute() { + progress = ProgressDialogImplementation.createProgressDialog( + ctx, ctx.getString(R.string.copying_osmand_files), + ctx.getString(R.string.copying_osmand_files_descr, to.getPath()), + ProgressDialog.STYLE_HORIZONTAL); + } + + @Override + protected void onPostExecute(Boolean result) { + if(result != null && result.booleanValue() && runOnSuccess != null) { + runOnSuccess.run(); + } + if(progress.getDialog().isShowing()) { + progress.getDialog().dismiss(); + } + } + + private void movingFiles(File f, File t, int depth) throws IOException { + if(depth <= 2) { + progress.startTask(ctx.getString(R.string.copying_osmand_one_file_descr, t.getName()), -1); + } + if(t.exists()) { + Algorithms.removeAllFiles(t); + } + if (f.isFile()) { + boolean rnm = false; + try { + rnm = f.renameTo(t); + } catch(RuntimeException e) { + } + if (!rnm) { + FileInputStream fin = new FileInputStream(f); + FileOutputStream fout = new FileOutputStream(t); + try { + Algorithms.streamCopy(fin, fout); + } finally { + fin.close(); + fout.close(); + } + f.delete(); + } + } else if (f.isDirectory()) { + t.mkdirs(); + File[] lf = f.listFiles(); + if (lf != null) { + for (int i = 0; i < lf.length; i++) { + if (lf[i] != null) { + movingFiles(lf[i], new File(t, lf[i].getName()), depth + 1); + } + } + } + f.delete(); + } + if(depth <= 2) { + progress.finishTask(); + } + } + + @Override + protected Boolean doInBackground(Void... params) { + to.mkdirs(); + try { + movingFiles(from, to, 0); + } catch (IOException e) { + Toast.makeText(ctx, R.string.input_output_error, Toast.LENGTH_LONG); + return false; + } + return true; + } + + } private void warnAboutChangingStorage(final String newValue) { final String newDir = newValue != null ? newValue.trim() : newValue; @@ -273,22 +373,42 @@ public class SettingsGeneralActivity extends SettingsBaseActivity { AccessibleToast.makeText(this, R.string.specified_dir_doesnt_exist, Toast.LENGTH_LONG).show(); return; } - Builder builder = new AlertDialog.Builder(this); - builder.setMessage(getString(R.string.application_dir_change_warning)); + builder.setMessage(getString(R.string.application_dir_change_warning2)); builder.setPositiveButton(R.string.default_buttons_yes, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - // edit the preference - settings.setExternalStorageDirectory(newDir); - getMyApplication().getResourceManager().resetStoreDirectory(); - reloadIndexes(); - updateApplicationDirTextAndSummary(); + MoveFilesToDifferentDirectory task = + new MoveFilesToDifferentDirectory(SettingsGeneralActivity.this, + new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR), new File(newDir, + IndexConstants.APP_DIR)); + task.setRunOnSuccess(new Runnable() { + @Override + public void run() { + updateSettingsToNewDir(newDir); + } + }); + task.execute(); + } + }); + builder.setNeutralButton(R.string.default_buttons_no, new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + updateSettingsToNewDir(newDir); } }); builder.setNegativeButton(R.string.default_buttons_cancel, null); builder.show(); } + + private void updateSettingsToNewDir(final String newDir) { + // edit the preference + settings.setExternalStorageDirectory(newDir); + getMyApplication().getResourceManager().resetStoreDirectory(); + reloadIndexes(); + updateApplicationDirTextAndSummary(); + } public void reloadIndexes() { setSupportProgressBarIndeterminateVisibility(true); diff --git a/OsmAnd/src/net/osmand/plus/base/SuggestExternalDirectoryDialog.java b/OsmAnd/src/net/osmand/plus/base/SuggestExternalDirectoryDialog.java index 0888e636b7..3ed84f451f 100644 --- a/OsmAnd/src/net/osmand/plus/base/SuggestExternalDirectoryDialog.java +++ b/OsmAnd/src/net/osmand/plus/base/SuggestExternalDirectoryDialog.java @@ -4,6 +4,7 @@ import java.io.InputStream; import java.util.HashSet; import java.util.Locale; +import net.osmand.CallbackWithObject; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -17,7 +18,7 @@ public class SuggestExternalDirectoryDialog { public static boolean showDialog(Activity a, final DialogInterface.OnClickListener otherListener, - final Runnable reloadListener){ + final CallbackWithObject selector){ final boolean showOther = otherListener != null; final OsmandApplication app = (OsmandApplication) a.getApplication(); Builder bld = new AlertDialog.Builder(a); @@ -46,10 +47,11 @@ public class SuggestExternalDirectoryDialog { otherListener.onClick(dialog, which); } else { dialog.dismiss(); - app.getSettings().setExternalStorageDirectory(extMounts[which]); - app.getResourceManager().resetStoreDirectory(); - if(reloadListener != null) { - reloadListener.run(); + if(selector != null) { + selector.processResult(extMounts[which]); + } else { + app.getSettings().setExternalStorageDirectory(extMounts[which]); + app.getResourceManager().resetStoreDirectory(); } } } From 2f7a78e6fc93e71915c1fb1be1237b0c80fc845d Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sun, 2 Mar 2014 21:13:11 +0200 Subject: [PATCH 10/17] Change director for Google android 19 --- OsmAnd/res/values/strings.xml | 3 ++ .../src/net/osmand/plus/OsmandSettings.java | 13 ++++++- .../activities/DownloadIndexActivity.java | 39 ++++++++++++++++++- .../activities/SettingsGeneralActivity.java | 2 +- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index befabb803f..948ea46153 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,9 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Since KitKat release Android, you can\'t download and update map in previous storage location (%s). Do you want to change to allowed one and copy all files? + \n Note : old files will stay untouched. + \n Note : it will not be possible to share files between OsmAnd and OsmAnd+. OsmAnd could try to move the data to new destination. Do you want it? Copying file (%s) to new destination... Copying OsmAnd files to new destination (%s) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index d7f3161e39..c6e37edced 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -993,8 +993,17 @@ public class OsmandSettings { public static final String EXTERNAL_STORAGE_DIR = "external_storage_dir"; //$NON-NLS-1$ public File getExternalStorageDirectory() { - return new File(settingsAPI.getString(globalPreferences,EXTERNAL_STORAGE_DIR, - ctx.getExternalServiceAPI().getExternalStorageDirectory())); + String defaultLocation = getDefaultExternalStorageLocation(); + return new File(settingsAPI.getString(globalPreferences, EXTERNAL_STORAGE_DIR, + defaultLocation)); + } + + public String getDefaultExternalStorageLocation() { + String defaultLocation = ctx.getExternalServiceAPI().getExternalStorageDirectory(); + if(Build.VERSION.SDK_INT >= 19) { + defaultLocation += "/Android/data/" + ctx.getPackageName(); + } + return defaultLocation; } public boolean setExternalStorageDirectory(String externalStorageDir) { diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index 599635833e..9fd011e253 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.TimeZone; +import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleToast; import net.osmand.plus.ClientContext; import net.osmand.plus.OsmandApplication; @@ -18,6 +19,7 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.Version; +import net.osmand.plus.activities.SettingsGeneralActivity.MoveFilesToDifferentDirectory; import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.base.SuggestExternalDirectoryDialog; import net.osmand.plus.download.DownloadActivityType; @@ -36,6 +38,7 @@ import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.net.Uri; import android.os.AsyncTask.Status; +import android.os.Build; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; @@ -162,7 +165,10 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { DownloadIndexAdapter adapter = new DownloadIndexAdapter(this, list); setListAdapter(adapter); if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) { - boolean showedDialog = SuggestExternalDirectoryDialog.showDialog(this, null, null); + boolean showedDialog = false; + if(Build.VERSION.SDK_INT < 19) { + SuggestExternalDirectoryDialog.showDialog(this, null, null); + } if(!showedDialog) { showDialogOfFreeDownloadsIfNeeded(); } @@ -182,7 +188,36 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { return true; } }); - + if(Build.VERSION.SDK_INT >= 19) { + if(!settings.getExternalStorageDirectory().equals(settings.getDefaultExternalStorageLocation())) { + AccessibleAlertBuilder ab = new AccessibleAlertBuilder(this); + ab.setMessage(getString(R.string.android_19_location_disabled, settings.getExternalStorageDirectory())); + ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + copyFilesForAndroid19(); + } + }); + ab.setNegativeButton(R.string.default_buttons_cancel, null); + } + } + } + + private void copyFilesForAndroid19() { + File newLoc = new File(settings.getDefaultExternalStorageLocation()); + MoveFilesToDifferentDirectory task = + new MoveFilesToDifferentDirectory(DownloadIndexActivity.this, settings.getExternalStorageDirectory(), newLoc) { + protected Boolean doInBackground(Void[] params) { + Boolean result = super.doInBackground(params); + if(result) { + settings.setExternalStorageDirectory(settings.getDefaultExternalStorageLocation()); + getMyApplication().getResourceManager().resetStoreDirectory(); + getMyApplication().getResourceManager().reloadIndexes(progress) ; + } + return result; + }; + }; + task.execute(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 177b009082..c4db41f38e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -279,7 +279,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity { private File to; private Context ctx; private File from; - private ProgressDialogImplementation progress; + protected ProgressDialogImplementation progress; private Runnable runOnSuccess; public MoveFilesToDifferentDirectory(Context ctx, File from, File to) { From cbb5ad26723972f8ad5b9ceec89e557531bdff53 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sun, 2 Mar 2014 21:43:36 +0200 Subject: [PATCH 11/17] Add special kitkat version --- OsmAnd/res/values/strings.xml | 2 +- .../src/net/osmand/plus/OsmandSettings.java | 4 ++- .../activities/DownloadIndexActivity.java | 17 +++++++---- .../activities/SettingsGeneralActivity.java | 30 +++++++++---------- 4 files changed, 30 insertions(+), 23 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 948ea46153..00c7e4ce60 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,7 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> - Since KitKat release Android, you can\'t download and update map in previous storage location (%s). Do you want to change to allowed one and copy all files? + Since KitKat version you can\'t download and update map in previous storage location (%s). Do you want to change to allowed one and copy all files there? \n Note : old files will stay untouched. \n Note : it will not be possible to share files between OsmAnd and OsmAnd+. OsmAnd could try to move the data to new destination. Do you want it? diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index c6e37edced..25199c5869 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -997,10 +997,12 @@ public class OsmandSettings { return new File(settingsAPI.getString(globalPreferences, EXTERNAL_STORAGE_DIR, defaultLocation)); } + + public static final int VERSION_DEFAULTLOCATION_CHANGED = 19; public String getDefaultExternalStorageLocation() { String defaultLocation = ctx.getExternalServiceAPI().getExternalStorageDirectory(); - if(Build.VERSION.SDK_INT >= 19) { + if(Build.VERSION.SDK_INT >= VERSION_DEFAULTLOCATION_CHANGED) { defaultLocation += "/Android/data/" + ctx.getPackageName(); } return defaultLocation; diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index 9fd011e253..662814d009 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Map; import java.util.TimeZone; +import net.osmand.IndexConstants; import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleToast; import net.osmand.plus.ClientContext; @@ -92,6 +93,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { private TextView progressPercent; private ImageView cancel; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -166,7 +168,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { setListAdapter(adapter); if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) { boolean showedDialog = false; - if(Build.VERSION.SDK_INT < 19) { + if(Build.VERSION.SDK_INT < OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) { SuggestExternalDirectoryDialog.showDialog(this, null, null); } if(!showedDialog) { @@ -188,8 +190,8 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { return true; } }); - if(Build.VERSION.SDK_INT >= 19) { - if(!settings.getExternalStorageDirectory().equals(settings.getDefaultExternalStorageLocation())) { + if(Build.VERSION.SDK_INT >= OsmandSettings.VERSION_DEFAULTLOCATION_CHANGED) { + if(!settings.getExternalStorageDirectory().getAbsolutePath().equals(settings.getDefaultExternalStorageLocation())) { AccessibleAlertBuilder ab = new AccessibleAlertBuilder(this); ab.setMessage(getString(R.string.android_19_location_disabled, settings.getExternalStorageDirectory())); ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() { @@ -199,18 +201,21 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity { } }); ab.setNegativeButton(R.string.default_buttons_cancel, null); + ab.show(); } } } private void copyFilesForAndroid19() { - File newLoc = new File(settings.getDefaultExternalStorageLocation()); + final String newLoc = settings.getDefaultExternalStorageLocation(); MoveFilesToDifferentDirectory task = - new MoveFilesToDifferentDirectory(DownloadIndexActivity.this, settings.getExternalStorageDirectory(), newLoc) { + new MoveFilesToDifferentDirectory(DownloadIndexActivity.this, + new File(settings.getExternalStorageDirectory(), IndexConstants.APP_DIR), + new File(newLoc, IndexConstants.APP_DIR)) { protected Boolean doInBackground(Void[] params) { Boolean result = super.doInBackground(params); if(result) { - settings.setExternalStorageDirectory(settings.getDefaultExternalStorageLocation()); + settings.setExternalStorageDirectory(newLoc); getMyApplication().getResourceManager().resetStoreDirectory(); getMyApplication().getResourceManager().reloadIndexes(progress) ; } diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index c4db41f38e..45797559af 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -314,10 +314,21 @@ public class SettingsGeneralActivity extends SettingsBaseActivity { if(depth <= 2) { progress.startTask(ctx.getString(R.string.copying_osmand_one_file_descr, t.getName()), -1); } - if(t.exists()) { - Algorithms.removeAllFiles(t); - } - if (f.isFile()) { + if (f.isDirectory()) { + t.mkdirs(); + File[] lf = f.listFiles(); + if (lf != null) { + for (int i = 0; i < lf.length; i++) { + if (lf[i] != null) { + movingFiles(lf[i], new File(t, lf[i].getName()), depth + 1); + } + } + } + f.delete(); + } else if (f.isFile()) { + if(t.exists()) { + Algorithms.removeAllFiles(t); + } boolean rnm = false; try { rnm = f.renameTo(t); @@ -334,17 +345,6 @@ public class SettingsGeneralActivity extends SettingsBaseActivity { } f.delete(); } - } else if (f.isDirectory()) { - t.mkdirs(); - File[] lf = f.listFiles(); - if (lf != null) { - for (int i = 0; i < lf.length; i++) { - if (lf[i] != null) { - movingFiles(lf[i], new File(t, lf[i].getName()), depth + 1); - } - } - } - f.delete(); } if(depth <= 2) { progress.finishTask(); From 35fa1c863806061fef9f6ddde4fda3c4b15eb63b Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sun, 2 Mar 2014 22:11:22 +0200 Subject: [PATCH 12/17] Fix download date --- .../osmand/plus/download/DownloadOsmandIndexesHelper.java | 3 ++- OsmAnd/src/net/osmand/plus/download/IndexItem.java | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index afb1762ca4..e09194e415 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -10,6 +10,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TimeZone; import java.util.zip.GZIPInputStream; import net.osmand.AndroidUtils; @@ -182,7 +183,7 @@ public class DownloadOsmandIndexesHelper { } } - private static String reparseDate(Context ctx, String date) { + protected static String reparseDate(Context ctx, String date) { try { Date d = simpleDateFormat.parse(date); return AndroidUtils.formatDate(ctx, d.getTime()); diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java index 941105a01f..94d951cc2a 100644 --- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; +import java.util.TimeZone; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -218,7 +219,9 @@ public class IndexItem implements Comparable { entry.zipStream = zipStream; entry.unzipFolder = unzipDir; try { - Date d = DateFormat.getDateFormat((Context) ctx).parse(date); + final java.text.DateFormat format = DateFormat.getDateFormat((Context) ctx); + format.setTimeZone(TimeZone.getTimeZone("GMT+01:00")); + Date d = format.parse(date); entry.dateModified = d.getTime(); } catch (ParseException e1) { log.error("ParseException", e1); From ca446092081ef8424632cced35b0b1442a44badc Mon Sep 17 00:00:00 2001 From: vshcherb Date: Sun, 2 Mar 2014 23:34:06 +0200 Subject: [PATCH 13/17] Merge osm tags while uploading --- .../net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java index b8b4a97e87..fa199e2f23 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java @@ -301,7 +301,13 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { OsmBaseStorage st = new OsmBaseStorage(); st.parseOSM(new ByteArrayInputStream(res.getBytes("UTF-8")), null, null, true); //$NON-NLS-1$ EntityId id = new Entity.EntityId(EntityType.NODE, nodeId); -// Node entity = (Node) st.getRegisteredEntities().get(id); + Node entity = (Node) st.getRegisteredEntities().get(id); + // merge non existing tags + for(String rtag : entity.getTagKeySet()) { + if(!n.getTagKeySet().contains(rtag)) { + n.putTag(rtag, entity.getTag(rtag)); + } + } entityInfo = st.getRegisteredEntityInfo().get(id); return entityInfo; } From 159dc51197dbec48768f4fc563601c78d73a4292 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 3 Mar 2014 15:01:29 +0200 Subject: [PATCH 14/17] Consolidate rendering with native --- .../osmand/plus/render/MapRenderRepositories.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 18d4f3e7ae..e7e9bc1b6d 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -71,7 +71,7 @@ public class MapRenderRepositories { private final static Log log = PlatformUtil.getLog(MapRenderRepositories.class); private final OsmandApplication context; - private final static int BASEMAP_ZOOM = 11; + private final static int zoomOnlyForBasemaps = 11; static int zoomForBaseRouteRendering = 14; private Handler handler; private Map files = new ConcurrentHashMap(); @@ -376,7 +376,7 @@ public class MapRenderRepositories { if (checkWhetherInterrupted()) { return false; } - if (renderRouteDataFile >= 0 && zoom >= BASEMAP_ZOOM ) { + if (renderRouteDataFile >= 0 && zoom >= zoomOnlyForBasemaps ) { searchRequest = BinaryMapIndexReader.buildSearchRequest(leftX, rightX, topY, bottomY, zoom, null); for (BinaryMapIndexReader c : files.values()) { // false positive case when we have 2 sep maps Country-roads & Country @@ -389,14 +389,14 @@ public class MapRenderRepositories { String coastlineTime = ""; boolean addBasemapCoastlines = true; - boolean emptyData = zoom > BASEMAP_ZOOM && tempResult.isEmpty() && coastLines.isEmpty(); - boolean basemapMissing = zoom <= BASEMAP_ZOOM && basemapCoastLines.isEmpty() && mi == null; + boolean emptyData = zoom > zoomOnlyForBasemaps && tempResult.isEmpty() && coastLines.isEmpty(); + boolean basemapMissing = zoom <= zoomOnlyForBasemaps && basemapCoastLines.isEmpty() && mi == null; boolean detailedLandData = zoom >= zoomForBaseRouteRendering && tempResult.size() > 0 && renderRouteDataFile < 0; if (!coastLines.isEmpty()) { long ms = System.currentTimeMillis(); boolean coastlinesWereAdded = processCoastlines(coastLines, leftX, rightX, bottomY, topY, zoom, basemapCoastLines.isEmpty(), true, tempResult); - addBasemapCoastlines = (!coastlinesWereAdded && !detailedLandData) || zoom <= BASEMAP_ZOOM; + addBasemapCoastlines = (!coastlinesWereAdded && !detailedLandData) || zoom <= zoomOnlyForBasemaps; coastlineTime = "(coastline " + (System.currentTimeMillis() - ms) + " ms )"; } else { addBasemapCoastlines = !detailedLandData; @@ -425,7 +425,7 @@ public class MapRenderRepositories { mapIndex.initMapEncodingRule(0, 2, "name", ""); } } - if (zoom <= BASEMAP_ZOOM || emptyData) { + if (zoom <= zoomOnlyForBasemaps || emptyData) { tempResult.addAll(basemapResult); } From 05e763f60c791e79e8111134fea48c8f054bd2c3 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 3 Mar 2014 15:55:32 +0200 Subject: [PATCH 15/17] Improve gpx route calculation --- .../src/net/osmand/router/BinaryRoutePlanner.java | 12 ++++++++++-- .../osmand/router/PrecalculatedRouteDirection.java | 11 +++++++++++ .../src/net/osmand/router/RoutePlannerFrontEnd.java | 11 ++++++++--- .../src/net/osmand/plus/routing/RouteProvider.java | 12 +++++------- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java index b798c78fca..4a222c8acb 100644 --- a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java +++ b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java @@ -371,15 +371,23 @@ public class BinaryRoutePlanner { // long nt = System.nanoTime(); // float devDistance = ctx.precalculatedRouteDirection.getDeviationDistance(x, y); // // 1. linear method -// // segmentDist = segmentDist * (1 + ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.config.DEVIATION_RADIUS); +// segmentDist = segmentDist * (1 + devDistance / ctx.config.DEVIATION_RADIUS); // // 2. exponential method // segmentDist = segmentDist * (float) Math.pow(1.5, devDistance / 500); + // 3. next by method +// segmentDist = devDistance ; // ctx.timeNanoToCalcDeviation += (System.nanoTime() - nt); } // could be expensive calculation // 3. get intersected ways final RouteSegment roadNext = ctx.loadRouteSegment(x, y, ctx.config.memoryLimitation - ctx.memoryOverhead); float distStartObstacles = segment.distanceFromStart + calculateTimeWithObstacles(ctx, road, segmentDist , obstaclesTime); + if(ctx.precalculatedRouteDirection != null && ctx.precalculatedRouteDirection.isFollowNext()) { + // reset to f + distStartObstacles = 0; + // more precise but slower + //distStartObstacles = ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.getRouter().getMinDefaultSpeed(); + } // We don't check if there are outgoing connections previous = processIntersections(ctx, graphSegments, visitedSegments, distStartObstacles, @@ -557,7 +565,7 @@ public class BinaryRoutePlanner { private RouteSegment processIntersections(RoutingContext ctx, PriorityQueue graphSegments, - TLongObjectHashMap visitedSegments, float distFromStart, RouteSegment segment, + TLongObjectHashMap visitedSegments, float distFromStart, RouteSegment segment, short segmentPoint, RouteSegment inputNext, boolean reverseWaySearch, boolean doNotAddIntersections, boolean[] processFurther) { boolean thereAreRestrictions ; diff --git a/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java b/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java index 68bcc8195e..17a5eb5314 100644 --- a/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java +++ b/OsmAnd-java/src/net/osmand/router/PrecalculatedRouteDirection.java @@ -19,6 +19,7 @@ public class PrecalculatedRouteDirection { private float minSpeed; private float maxSpeed; private float[] tms; + private boolean followNext; private static final int SHIFT = (1 << (31 - 17)); private static final int[] SHIFTS = new int[]{1 << (31 - 15), 1 << (31 - 13), 1 << (31 - 12), 1 << (31 - 11), 1 << (31 - 7)}; @@ -240,6 +241,15 @@ public class PrecalculatedRouteDirection { return ((long) x31) << 32l + ((long)y31); } + public void setFollowNext(boolean followNext) { + this.followNext = followNext; + } + + public boolean isFollowNext() { + return followNext; + } + + public PrecalculatedRouteDirection adopt(RoutingContext ctx) { int ind1 = getIndex(ctx.startX, ctx.startY); int ind2 = getIndex(ctx.targetX, ctx.targetY); @@ -258,6 +268,7 @@ public class PrecalculatedRouteDirection { // routeDirection.startY31 = ctx.startY; routeDirection.endPoint = calc(ctx.targetX, ctx.targetX); routeDirection.endFinishTime = (float) BinaryRoutePlanner.squareRootDist(pointsX[ind2], pointsY[ind2], ctx.targetX, ctx.targetY) / maxSpeed; + routeDirection.followNext = followNext; // routeDirection.endX31 = ctx.targetX; // routeDirection.endY31 = ctx.targetY; diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index b466cb0dcf..8d7f61e3ae 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -84,13 +84,17 @@ public class RoutePlannerFrontEnd { } - public List searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List intermediates) throws IOException, InterruptedException { + return searchRoute(ctx, start, end, intermediates, null); + } + + + public List searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List intermediates, + PrecalculatedRouteDirection routeDirection) throws IOException, InterruptedException { if(ctx.calculationProgress == null) { ctx.calculationProgress = new RouteCalculationProgress(); } boolean intermediatesEmpty = intermediates == null || intermediates.isEmpty(); - PrecalculatedRouteDirection routeDirection = null; double maxDistance = MapUtils.getDistance(start, end); if(!intermediatesEmpty) { LatLon b = start; @@ -99,7 +103,8 @@ public class RoutePlannerFrontEnd { b = l; } } - if(ctx.calculationMode == RouteCalculationMode.COMPLEX && maxDistance > Math.max(ctx.config.DEVIATION_RADIUS * 4, 30000)) { + if(ctx.calculationMode == RouteCalculationMode.COMPLEX && routeDirection == null + && maxDistance > Math.max(ctx.config.DEVIATION_RADIUS * 4, 30000)) { RoutingContext nctx = buildRoutingContext(ctx.config, ctx.nativeLib, ctx.getMaps(), RouteCalculationMode.BASE); nctx.calculationProgress = ctx.calculationProgress ; List ls = searchRoute(nctx, start, end, intermediates); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index e8cbf61d0e..61cc068e36 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -451,7 +451,8 @@ public class RouteProvider { latLon[k] = new LatLon(sublist.get(k).getLatitude(), sublist.get(k).getLongitude()); } precalculated = PrecalculatedRouteDirection.build(latLon, generalRouter.getMaxDefaultSpeed()); - cf.planRoadDirection = 1; + precalculated.setFollowNext(true); + //cf.planRoadDirection = 1; } // BUILD context RoutingContext ctx = router.buildRoutingContext(cf, params.ctx.getInternalAPI().getNativeLibrary(), files, @@ -466,9 +467,6 @@ public class RouteProvider { complexCtx.calculationProgress = params.calculationProgress; complexCtx.leftSideNavigation = params.leftSide; } - if(precalculated != null) { - ctx.precalculatedRouteDirection = precalculated.adopt(ctx); - } ctx.leftSideNavigation = params.leftSide; ctx.calculationProgress = params.calculationProgress; if(params.previousToRecalculate != null) { @@ -481,7 +479,7 @@ public class RouteProvider { if (params.intermediates != null) { inters = new ArrayList(params.intermediates); } - return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters); + return calcOfflineRouteImpl(params, router, ctx, complexCtx, st, en, inters, precalculated); } @@ -547,12 +545,12 @@ public class RouteProvider { private RouteCalculationResult calcOfflineRouteImpl(final RouteCalculationParams params, RoutePlannerFrontEnd router, RoutingContext ctx, RoutingContext complexCtx, LatLon st, LatLon en, - List inters) throws IOException { + List inters, PrecalculatedRouteDirection precalculated) throws IOException { try { List result ; if(complexCtx != null) { try { - result = router.searchRoute(complexCtx, st, en, inters); + result = router.searchRoute(complexCtx, st, en, inters, precalculated); // discard ctx and replace with calculated ctx = complexCtx; } catch(final RuntimeException e) { From 3c1104b1d0c431925f04765355fa852fe3509578 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 3 Mar 2014 18:44:17 +0100 Subject: [PATCH 16/17] Improve gpx route calculation --- OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java | 4 ++-- OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java index 4a222c8acb..e8091b06a4 100644 --- a/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java +++ b/OsmAnd-java/src/net/osmand/router/BinaryRoutePlanner.java @@ -384,9 +384,9 @@ public class BinaryRoutePlanner { float distStartObstacles = segment.distanceFromStart + calculateTimeWithObstacles(ctx, road, segmentDist , obstaclesTime); if(ctx.precalculatedRouteDirection != null && ctx.precalculatedRouteDirection.isFollowNext()) { // reset to f - distStartObstacles = 0; +// distStartObstacles = 0; // more precise but slower - //distStartObstacles = ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.getRouter().getMinDefaultSpeed(); + distStartObstacles = ctx.precalculatedRouteDirection.getDeviationDistance(x, y) / ctx.getRouter().getMaxDefaultSpeed(); } // We don't check if there are outgoing connections diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index 8d7f61e3ae..1e2bfd5ac9 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -122,7 +122,7 @@ public class RoutePlannerFrontEnd { if(res != null) { new RouteResultPreparation().printResults(ctx, start, end, res); } - return res; + return res; } int indexNotFound = 0; List points = new ArrayList(); From 8f69f6f55d7e34fbeef5baf5a8bd3468e958107a Mon Sep 17 00:00:00 2001 From: vshcherb Date: Tue, 4 Mar 2014 01:45:56 +0100 Subject: [PATCH 17/17] Fix for xxhdpi devices with density>=3, zoom magnifier didn't work as expected --- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 7 +++++-- .../src/net/osmand/plus/activities/SettingsActivity.java | 7 ++----- OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 25199c5869..85e5e5751d 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -651,7 +651,7 @@ public class OsmandSettings { public float getSettingsZoomScale(float density){ // by default scale between [0, 1[ density (because of lots map complains) - return MAP_ZOOM_SCALE_BY_DENSITY.get() + (float)Math.min(Math.sqrt(Math.max(0, density - 1)), 1); + return MAP_ZOOM_SCALE_BY_DENSITY.get() + (float)Math.sqrt(Math.max(0, density - 1)); } @@ -993,7 +993,10 @@ public class OsmandSettings { public static final String EXTERNAL_STORAGE_DIR = "external_storage_dir"; //$NON-NLS-1$ public File getExternalStorageDirectory() { - String defaultLocation = getDefaultExternalStorageLocation(); + String defaultLocation = ctx.getExternalServiceAPI().getExternalStorageDirectory(); + if(Build.VERSION.SDK_INT >= VERSION_DEFAULTLOCATION_CHANGED && !new File(defaultLocation, IndexConstants.APP_DIR).exists()) { + defaultLocation += "/Android/data/" + ctx.getPackageName(); + } return new File(settingsAPI.getString(globalPreferences, EXTERNAL_STORAGE_DIR, defaultLocation)); } diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java index 5ba6ebedea..b1d7a00c04 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java @@ -4,30 +4,27 @@ package net.osmand.plus.activities; import java.io.File; import java.util.Date; -import android.content.SharedPreferences; -import android.widget.ScrollView; import net.osmand.IndexConstants; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.Version; -import net.osmand.plus.rastermaps.SettingsRasterMapsActivity; -import net.osmand.util.Algorithms; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceScreen; -import android.preference.Preference.OnPreferenceClickListener; import android.text.SpannableString; import android.text.format.DateFormat; import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.util.TypedValue; import android.view.View; +import android.widget.ScrollView; import android.widget.TextView; public class SettingsActivity extends SettingsBaseActivity { diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 24b91505ef..37bcd63de7 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -393,7 +393,7 @@ public class MapControlsLayer extends OsmandMapLayer { final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext()); float scale = view.getZoomScale(); int p = (int) ((scale > 0 ? 1 : -1) * Math.round(scale * scale * 100)) + 100; - final TIntArrayList tlist = new TIntArrayList(new int[] { 75, 100, 150, 200, 300, 400 }); + final TIntArrayList tlist = new TIntArrayList(new int[] { 75, 100, 150, 200, 300, 400, 500 }); final List values = new ArrayList(); int i = -1; for (int k = 0; k <= tlist.size(); k++) {