Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2014-07-06 16:29:21 +02:00
commit 8ea84732db
6 changed files with 100 additions and 26 deletions

View file

@ -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) {

View file

@ -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);
}
}
}
}

View file

@ -532,7 +532,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override
protected void onPostExecute(List<GpxInfo> result) {
this.result = result;
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
if(getSherlockActivity() != null) {
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
}
}
private File[] listFilesSorted(File dir) {

View file

@ -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<IMapDownloaderCallback> 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;

View file

@ -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<BinaryMapDataObject> 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<BinaryMapDataObject> 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<BinaryMapDataObject> 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) {

View file

@ -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();
}
}
}