Fixed issue 494.

Do not draw new map when it is already drawing and there is only
rotation change.
This commit is contained in:
Pavol Zibrita 2011-10-13 00:25:50 +02:00
parent 734888f238
commit b3c6fede74
4 changed files with 84 additions and 15 deletions

View file

@ -4,22 +4,21 @@ import java.io.File;
import java.util.List;
import java.util.Stack;
import org.apache.commons.logging.Log;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import net.osmand.Algoritms;
import net.osmand.LogUtil;
import net.osmand.ResultMatcher;
import net.osmand.data.Amenity;
import net.osmand.data.MapTileDownloader;
import net.osmand.data.TransportStop;
import net.osmand.data.MapTileDownloader.DownloadRequest;
import net.osmand.data.MapTileDownloader.IMapDownloaderCallback;
import net.osmand.data.TransportStop;
import net.osmand.map.ITileSource;
import org.apache.commons.logging.Log;
import android.os.Handler;
import android.os.HandlerThread;
/**
* Thread to load map objects (POI, transport stops )async
*/

View file

@ -13,6 +13,9 @@ public class RotatedTileBox {
private int zoom;
private float rotateCos;
private float rotateSin;
private RectF latLon;
private boolean rendering;
private RotatedTileBox parent;
public RotatedTileBox(float leftTileX, float topTileY, float tileWidth, float tileHeight, float rotate, int zoom) {
set(leftTileX, topTileY, tileWidth, tileHeight, rotate, zoom);
@ -20,6 +23,9 @@ public class RotatedTileBox {
public RotatedTileBox(RotatedTileBox r){
set(r.leftTileX, r.topTileY, r.tileWidth, r.tileHeight, r.rotate, r.zoom);
this.latLon = r.latLon;
this.rendering = r.rendering;
this.parent = r;
}
private void init() {
@ -166,6 +172,61 @@ public class RotatedTileBox {
return calcPointTileY(tileWidth, tileHeight);
}
/**
* the lat lon bounds
* @param latLonBounds
*/
public void setLatLon(RectF latLonBounds) {
//on new latLonBounds reset rendering info and latLonBounds....
if (!latLonBounds.equals(this.latLon)) {
this.rendering = false;
this.latLon = latLonBounds;
}
}
/**
* @return true if rendering is in progress
*/
public boolean isRendering() {
return rendering;
}
/**
* Say we are rendering this box
*/
public void rendering() {
rendering = true;
if (parent != null) {
parent.rendering(latLon);
}
}
/**
* Say we are rendering this box for this coordinates
*
* @param aLatLon
*/
private void rendering(RectF aLatLon) {
if (aLatLon.equals(latLon)) {
rendering = true;
}
}
/**
* all if rendering was interrupted
*/
public void renderingInterrupted() {
rendered();
}
/**
* Call if rendering is finished
*/
public void rendered() {
rendering = false;
if (parent != null) {
parent.rendered();
}
}
}

View file

@ -196,6 +196,9 @@ public class MapRenderRepositories {
}
public void interruptLoadingMap(){
if (requestedBox != null) {
requestedBox.renderingInterrupted();
}
interrupted = true;
if(currentRenderingContext != null){
currentRenderingContext.interrupted = true;
@ -207,6 +210,9 @@ public class MapRenderRepositories {
private boolean checkWhetherInterrupted(){
if(interrupted || (currentRenderingContext != null && currentRenderingContext.interrupted)){
if (requestedBox != null) {
requestedBox.renderingInterrupted();
}
requestedBox = bmpLocation;
return true;
}
@ -356,6 +362,10 @@ public class MapRenderRepositories {
currentRenderingContext = null;
}
try {
// prevent editing
requestedBox = new RotatedTileBox(tileRect);
requestedBox.rendering();
// find selected rendering type
OsmandApplication app = ((OsmandApplication)context.getApplicationContext());
Boolean renderDay = app.getDaynightHelper().getDayNightRenderer();
@ -363,9 +373,6 @@ public class MapRenderRepositories {
// boolean moreDetail = prefs.SHOW_MORE_MAP_DETAIL.get();
BaseOsmandRender renderingType = app.getRendererRegistry().getCurrentSelectedRenderer();
// prevent editing
requestedBox = new RotatedTileBox(tileRect);
// calculate data box
RectF dataBox = requestedBox.calculateLatLonBox(new RectF());
long now = System.currentTimeMillis();
@ -419,7 +426,6 @@ public class MapRenderRepositories {
}
renderer.generateNewBitmap(currentRenderingContext, cObjects, bmp,
prefs.USE_ENGLISH_NAMES.get(), renderingType, stepByStep ? notifyList : null);
String renderingDebugInfo = currentRenderingContext.renderingDebugInfo;
@ -468,9 +474,11 @@ public class MapRenderRepositories {
Toast.makeText(context, R.string.rendering_out_of_memory, Toast.LENGTH_SHORT).show();
}
});
} finally {
if (requestedBox != null) {
requestedBox.rendered();
}
}
}
public Bitmap getBitmap() {

View file

@ -93,10 +93,11 @@ public class MapVectorLayer extends BaseMapLayer {
tileLayer.drawTileMap(canvas, tilesRect);
resourceManager.getRenderer().interruptLoadingMap();
} else {
rotatedTileBox.setLatLon(latLonBounds);
if (!view.isZooming()) {
pixRect.set(0, 0, view.getWidth(), view.getHeight());
updateRotatedTileBox();
if (resourceManager.updateRenderedMapNeeded(rotatedTileBox)) {
if (!rotatedTileBox.isRendering() && resourceManager.updateRenderedMapNeeded(rotatedTileBox)) {
// pixRect.set(-view.getWidth(), -view.getHeight() / 2, 2 * view.getWidth(), 3 * view.getHeight() / 2);
pixRect.set(-view.getWidth() / 3, -view.getHeight() / 4, 4 * view.getWidth() / 3, 5 * view.getHeight() / 4);
updateRotatedTileBox();