diff --git a/OsmAnd-java/src/net/osmand/data/RotatedTileBox.java b/OsmAnd-java/src/net/osmand/data/RotatedTileBox.java index 9f6270d7e0..bacc8b3024 100644 --- a/OsmAnd-java/src/net/osmand/data/RotatedTileBox.java +++ b/OsmAnd-java/src/net/osmand/data/RotatedTileBox.java @@ -456,6 +456,12 @@ public class RotatedTileBox { double ty = getPixYFromLatLon(lat, lon); return tx >= 0 && tx <= pixWidth && ty >= 0 && ty <= pixHeight; } + + public boolean containsLatLon(LatLon latLon) { + double tx = getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); + double ty = getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); + return tx >= 0 && tx <= pixWidth && ty >= 0 && ty <= pixHeight; + } public double getDistance(int pixX, int pixY, int pixX2, int pixY2) { diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 8e00ac5854..5eb81d303e 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -336,13 +336,23 @@ public class RouteResultPreparation { boolean tr = TurnType.TR.equals(t.getValue()); if(tl || tr) { TurnType tnext = getTurnInfo(result, i + 1, leftside); - if(tnext != null && result.get(i).getDistance() < 35) { - if(tl && TurnType.TL.equals(tnext.getValue()) ) { - next = i + 2; - t = TurnType.valueOf(TurnType.TU, false); - } else if(tr && TurnType.TR.equals(tnext.getValue()) ) { - next = i + 2; - t = TurnType.valueOf(TurnType.TU, true); + if (tnext != null && result.get(i).getDistance() < 35) { // + boolean ut = true; + if (i > 0) { + double uTurn = MapUtils.degreesDiff(result.get(i - 1).getBearingEnd(), result + .get(i + 1).getBearingBegin()); + if (Math.abs(uTurn) < 120) { + ut = false; + } + } + if (ut) { + if (tl && TurnType.TL.equals(tnext.getValue())) { + next = i + 2; + t = TurnType.valueOf(TurnType.TU, false); + } else if (tr && TurnType.TR.equals(tnext.getValue())) { + next = i + 2; + t = TurnType.valueOf(TurnType.TU, true); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/activities/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/activities/AvailableGPXFragment.java index 53a868759f..bfd3b6ecfd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/AvailableGPXFragment.java @@ -532,7 +532,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { @Override protected void onPostExecute(List result) { this.result = result; - getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false); + if(getSherlockActivity() != null) { + getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false); + } } private File[] listFilesSorted(File dir) { diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index bf82c80a39..2910e7fddd 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -95,7 +95,8 @@ public class MapRenderRepositories { // already rendered bitmap private Bitmap prevBmp; // to track necessity of map download (1 (if basemap) + 2 (if normal map) - private int previousRenderedState; + private int checkedRenderedState; + private RotatedTileBox checkedBox; // location of rendered bitmap private RotatedTileBox bmpLocation = null; @@ -555,15 +556,16 @@ public class MapRenderRepositories { } } - - - public boolean isLastMapRenderedEmpty(boolean checkBaseMap){ - if(checkBaseMap) { - return prevBmp != null && previousRenderedState == 0; - } else { - return prevBmp != null && previousRenderedState == 1; - } + public RotatedTileBox getCheckedBox() { + return checkedBox; } + + public int getCheckedRenderedState() { + // to track necessity of map download (1 (if basemap) + 2 (if normal map) + return checkedRenderedState; + } + + public synchronized void loadMap(RotatedTileBox tileRect, List notifyList) { interrupted = false; @@ -689,7 +691,6 @@ 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); @@ -731,6 +732,9 @@ public class MapRenderRepositories { } currentRenderingContext = null; return; + } else { + this.checkedRenderedState = renderedState; + this.checkedBox = this.bmpLocation; } currentRenderingContext = null; @@ -798,7 +802,6 @@ 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 ce8fab768f..5d091c475a 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -106,11 +106,36 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { ZOOM_THRESHOLD = 2; } + @Override + public void layerOnPostExecute() { + view.refreshMap(); + } + public boolean queriedBoxContains(final RotatedTileBox queriedData, final RotatedTileBox newBox) { + if (newBox.getZoom() < ZOOM_TO_SHOW_MAP_NAMES) { + if (queriedData != null && queriedData.getZoom() < ZOOM_TO_SHOW_MAP_NAMES) { + if (newBox.getZoom() >= ZOOM_TO_SHOW_BORDERS_ST && newBox.getZoom() < ZOOM_TO_SHOW_BORDERS) { + return queriedData != null && queriedData.containsTileBox(newBox); + } + return true; + } else { + return false; + } + } + List queriedResults = getResults(); + if(queriedData != null && queriedData.containsTileBox(newBox) && queriedData.getZoom() >= ZOOM_TO_SHOW_MAP_NAMES) { + if(queriedResults != null && ( queriedResults.isEmpty() || + Math.abs(queriedData.getZoom() - newBox.getZoom()) <= 1)) { + return true; + } + } + return false; + } + @Override protected List calculateResult(RotatedTileBox tileBox) { return queryData(tileBox); } - + }; } @@ -118,7 +143,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { private static int ZOOM_TO_SHOW_BORDERS_ST = 5; private static int ZOOM_TO_SHOW_BORDERS = 7; - private static int ZOOM_TO_SHOW_MAP_NAMES = 8; + private static int ZOOM_TO_SHOW_MAP_NAMES = 12; @Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { @@ -159,16 +184,39 @@ public class DownloadedRegionsLayer extends OsmandMapLayer { if (tileBox.getZoom() < ZOOM_TO_SHOW_MAP_NAMES) { basemapExists = rm.getRenderer().basemapExists(); } + // wait for image to be rendered + int count = 0; + RotatedTileBox cb = rm.getRenderer().getCheckedBox(); + while (cb == null || cb.getZoom() != tileBox.getZoom() || + !cb.containsLatLon(tileBox.getCenterLatLon())) { + if (count++ > 7) { + return null; + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + return null; + } + cb = rm.getRenderer().getCheckedBox(); + } + int cState = rm.getRenderer().getCheckedRenderedState(); + final boolean empty; + if (tileBox.getZoom() < ZOOM_TO_SHOW_MAP_NAMES) { + empty = cState == 0; + } else { + empty = cState <= 1; + } + noMapsPresent = empty; + if (!empty && tileBox.getZoom() >= ZOOM_TO_SHOW_MAP_NAMES) { + return Collections.emptyList(); + } + List result = null; int left = MapUtils.get31TileNumberX(tileBox.getLeftTopLatLon().getLongitude()); 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().isLastMapRenderedEmpty(tileBox.getZoom() < 12); - noMapsPresent = empty; - if (!empty && tileBox.getZoom() >= ZOOM_TO_SHOW_MAP_NAMES) { - return Collections.emptyList(); - } + try { result = osmandRegions.queryBbox(left, right, top, bottom); } catch (IOException e) { diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index fca62b78f5..b217642dff 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -106,6 +106,9 @@ public abstract class OsmandMapLayer { } } + public void layerOnPostExecute() { + } + public boolean isInterrupted() { return pendingTask != null; } @@ -152,6 +155,8 @@ public abstract class OsmandMapLayer { if (pendingTask != null) { executeTaskInBackground(pendingTask); pendingTask = null; + } else { + layerOnPostExecute(); } } }