Fix download button
This commit is contained in:
parent
157b5b0209
commit
2749b01454
4 changed files with 75 additions and 19 deletions
|
@ -530,8 +530,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(List<GpxInfo> result) {
|
protected void onPostExecute(List<GpxInfo> result) {
|
||||||
this.result = result;
|
this.result = result;
|
||||||
|
if(getSherlockActivity() != null) {
|
||||||
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
|
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private File[] listFilesSorted(File dir) {
|
private File[] listFilesSorted(File dir) {
|
||||||
File[] listFiles = dir.listFiles();
|
File[] listFiles = dir.listFiles();
|
||||||
|
|
|
@ -95,7 +95,8 @@ public class MapRenderRepositories {
|
||||||
// already rendered bitmap
|
// already rendered bitmap
|
||||||
private Bitmap prevBmp;
|
private Bitmap prevBmp;
|
||||||
// to track necessity of map download (1 (if basemap) + 2 (if normal map)
|
// 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
|
// location of rendered bitmap
|
||||||
private RotatedTileBox bmpLocation = null;
|
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) {
|
public synchronized void loadMap(RotatedTileBox tileRect, List<IMapDownloaderCallback> notifyList) {
|
||||||
interrupted = false;
|
interrupted = false;
|
||||||
|
@ -689,7 +691,8 @@ public class MapRenderRepositories {
|
||||||
Bitmap reuse = prevBmp;
|
Bitmap reuse = prevBmp;
|
||||||
this.prevBmp = this.bmp;
|
this.prevBmp = this.bmp;
|
||||||
this.prevBmpLocation = this.bmpLocation;
|
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) {
|
if (reuse != null && reuse.getWidth() == currentRenderingContext.width && reuse.getHeight() == currentRenderingContext.height) {
|
||||||
bmp = reuse;
|
bmp = reuse;
|
||||||
bmp.eraseColor(currentRenderingContext.defaultColor);
|
bmp.eraseColor(currentRenderingContext.defaultColor);
|
||||||
|
@ -798,7 +801,6 @@ public class MapRenderRepositories {
|
||||||
cObjectsBox = new QuadRect();
|
cObjectsBox = new QuadRect();
|
||||||
|
|
||||||
requestedBox = prevBmpLocation = null;
|
requestedBox = prevBmpLocation = null;
|
||||||
previousRenderedState = 0;
|
|
||||||
// Do not clear main bitmap to not cause a screen refresh
|
// Do not clear main bitmap to not cause a screen refresh
|
||||||
// prevBmp = null;
|
// prevBmp = null;
|
||||||
// bmp = null;
|
// bmp = null;
|
||||||
|
|
|
@ -106,6 +106,31 @@ public class DownloadedRegionsLayer extends OsmandMapLayer {
|
||||||
ZOOM_THRESHOLD = 2;
|
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
|
@Override
|
||||||
protected List<BinaryMapDataObject> calculateResult(RotatedTileBox tileBox) {
|
protected List<BinaryMapDataObject> calculateResult(RotatedTileBox tileBox) {
|
||||||
return queryData(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_ST = 5;
|
||||||
private static int ZOOM_TO_SHOW_BORDERS = 7;
|
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
|
@Override
|
||||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
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) {
|
if (tileBox.getZoom() < ZOOM_TO_SHOW_MAP_NAMES) {
|
||||||
basemapExists = rm.getRenderer().basemapExists();
|
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;
|
List<BinaryMapDataObject> result = null;
|
||||||
int left = MapUtils.get31TileNumberX(tileBox.getLeftTopLatLon().getLongitude());
|
int left = MapUtils.get31TileNumberX(tileBox.getLeftTopLatLon().getLongitude());
|
||||||
int right = MapUtils.get31TileNumberX(tileBox.getRightBottomLatLon().getLongitude());
|
int right = MapUtils.get31TileNumberX(tileBox.getRightBottomLatLon().getLongitude());
|
||||||
int top = MapUtils.get31TileNumberY(tileBox.getLeftTopLatLon().getLatitude());
|
int top = MapUtils.get31TileNumberY(tileBox.getLeftTopLatLon().getLatitude());
|
||||||
int bottom = MapUtils.get31TileNumberY(tileBox.getRightBottomLatLon().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 {
|
try {
|
||||||
result = osmandRegions.queryBbox(left, right, top, bottom);
|
result = osmandRegions.queryBbox(left, right, top, bottom);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -106,6 +106,9 @@ public abstract class OsmandMapLayer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void layerOnPostExecute() {
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isInterrupted() {
|
public boolean isInterrupted() {
|
||||||
return pendingTask != null;
|
return pendingTask != null;
|
||||||
}
|
}
|
||||||
|
@ -152,6 +155,8 @@ public abstract class OsmandMapLayer {
|
||||||
if (pendingTask != null) {
|
if (pendingTask != null) {
|
||||||
executeTaskInBackground(pendingTask);
|
executeTaskInBackground(pendingTask);
|
||||||
pendingTask = null;
|
pendingTask = null;
|
||||||
|
} else {
|
||||||
|
layerOnPostExecute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue