Fix download button

This commit is contained in:
Victor Shcherb 2014-07-06 15:55:10 +02:00
parent 157b5b0209
commit 2749b01454
4 changed files with 75 additions and 19 deletions

View file

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

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 RotatedTileBox getCheckedBox() {
return checkedBox;
}
public int getCheckedRenderedState() {
// to track necessity of map download (1 (if basemap) + 2 (if normal map)
return checkedRenderedState;
}
public boolean isLastMapRenderedEmpty(boolean checkBaseMap){
if(checkBaseMap) {
return prevBmp != null && previousRenderedState == 0;
} else {
return prevBmp != null && previousRenderedState == 1;
}
}
public synchronized void loadMap(RotatedTileBox tileRect, List<IMapDownloaderCallback> notifyList) {
interrupted = false;
@ -689,7 +691,8 @@ public class MapRenderRepositories {
Bitmap reuse = prevBmp;
this.prevBmp = this.bmp;
this.prevBmpLocation = this.bmpLocation;
this.previousRenderedState = renderedState;
this.checkedRenderedState = renderedState;
this.checkedBox = this.bmpLocation;
if (reuse != null && reuse.getWidth() == currentRenderingContext.width && reuse.getHeight() == currentRenderingContext.height) {
bmp = reuse;
bmp.eraseColor(currentRenderingContext.defaultColor);
@ -798,7 +801,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,6 +106,31 @@ 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,38 @@ 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()) {
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();
}
}
}