Issue 520

This commit is contained in:
Victor Shcherb 2011-07-17 14:53:27 +02:00
parent 247169a7c7
commit fa7f4c96c6
11 changed files with 45 additions and 25 deletions

View file

@ -28,6 +28,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
@ -37,18 +38,18 @@ import net.osmand.IProgress;
import net.osmand.LogUtil; import net.osmand.LogUtil;
import net.osmand.data.IndexConstants; import net.osmand.data.IndexConstants;
import net.osmand.plus.DownloadOsmandIndexesHelper; import net.osmand.plus.DownloadOsmandIndexesHelper;
import net.osmand.plus.DownloadOsmandIndexesHelper.IndexItem;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.ProgressDialogImplementation; import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.ResourceManager; import net.osmand.plus.ResourceManager;
import net.osmand.plus.DownloadOsmandIndexesHelper.IndexItem;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ListActivity; import android.app.ListActivity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
@ -82,7 +83,7 @@ public class DownloadIndexActivity extends ListActivity {
private ProgressDialog progressFileDlg = null; private ProgressDialog progressFileDlg = null;
private ProgressDialog progressListDlg = null; private ProgressDialog progressListDlg = null;
private Map<String, String> indexFileNames = null; private Map<String, String> indexFileNames = null;
private LinkedHashMap<String, DownloadEntry> entriesToDownload = new LinkedHashMap<String, DownloadEntry>(); private TreeMap<String, DownloadEntry> entriesToDownload = new TreeMap<String, DownloadEntry>();
private TextWatcher textWatcher = new TextWatcher() { private TextWatcher textWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
@ -436,12 +437,16 @@ public class DownloadIndexActivity extends ListActivity {
@Override @Override
public void run() { public void run() {
try { try {
for (String s : new ArrayList<String>(entriesToDownload.keySet())) { List<File> filesToReindex = new ArrayList<File>();
DownloadEntry entry = entriesToDownload.get(s); ArrayList<String> filesToDownload = new ArrayList<String>(entriesToDownload.keySet());
for(int i=0;i<filesToDownload.size(); i++) {
String filename = filesToDownload.get(i);
DownloadEntry entry = entriesToDownload.get(filename);
if (entry != null) { if (entry != null) {
if (downloadFile(s, entry.fileToSave, entry.fileToUnzip, entry.unzip, impl, entry.dateModified, String indexOfAllFiles = filesToDownload.size() < 1 ? "" : (" ["+(i+1)+"/"+filesToDownload.size()+"]");
entry.parts)) { if (downloadFile(filename, entry.fileToSave, entry.fileToUnzip, entry.unzip, impl, entry.dateModified,
entriesToDownload.remove(s); entry.parts, filesToReindex, indexOfAllFiles)) {
entriesToDownload.remove(filename);
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -452,6 +457,26 @@ public class DownloadIndexActivity extends ListActivity {
} }
} }
} }
boolean vectorMapsToReindex = false;
for(File f : filesToReindex){
if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
vectorMapsToReindex = true;
break;
}
}
// reindex vector maps all at one time
if (vectorMapsToReindex) {
ResourceManager manager = ((OsmandApplication) getApplication()).getResourceManager();
List<String> warnings = manager.indexingMaps(impl);
if(warnings.isEmpty() && !OsmandSettings.getOsmandSettings(getApplicationContext()).MAP_VECTOR_DATA.get()){
warnings.add(getString(R.string.binary_map_download_success));
// Is it proper way to switch every tome to vector data?
OsmandSettings.getOsmandSettings(getApplicationContext()).MAP_VECTOR_DATA.set(true);
}
if (!warnings.isEmpty()) {
showWarning(warnings.get(0));
}
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
// do not dismiss dialog // do not dismiss dialog
progressFileDlg = null; progressFileDlg = null;
@ -487,7 +512,8 @@ public class DownloadIndexActivity extends ListActivity {
protected final long TIMEOUT_BETWEEN_DOWNLOADS = 8000; protected final long TIMEOUT_BETWEEN_DOWNLOADS = 8000;
private boolean interruptDownloading = false; private boolean interruptDownloading = false;
protected void downloadFile(String fileName, FileOutputStream out, URL url, String part, IProgress progress) throws IOException, InterruptedException { protected void downloadFile(String fileName, FileOutputStream out, URL url, String part, String indexOfAllFiles,
IProgress progress) throws IOException, InterruptedException {
InputStream is = null; InputStream is = null;
byte[] buffer = new byte[BUFFER_SIZE]; byte[] buffer = new byte[BUFFER_SIZE];
@ -527,7 +553,7 @@ public class DownloadIndexActivity extends ListActivity {
// } // }
if (first) { if (first) {
length = conn.getContentLength(); length = conn.getContentLength();
String taskName = getString(R.string.downloading_file) + " " + fileName; String taskName = getString(R.string.downloading_file) + indexOfAllFiles +" " + fileName;
if(part != null){ if(part != null){
taskName += part; taskName += part;
} }
@ -578,8 +604,8 @@ public class DownloadIndexActivity extends ListActivity {
progressFileDlg = null; progressFileDlg = null;
} }
protected boolean downloadFile(final String key, final File fileToDownload, final File fileToUnZip, final boolean unzipToDir, protected boolean downloadFile(final String fileName, final File fileToDownload, final File fileToUnZip, final boolean unzipToDir,
IProgress progress, Long dateModified, int parts) throws InterruptedException { IProgress progress, Long dateModified, int parts, List<File> toReIndex, String indexOfAllFiles) throws InterruptedException {
FileOutputStream out = null; FileOutputStream out = null;
try { try {
@ -587,12 +613,12 @@ public class DownloadIndexActivity extends ListActivity {
try { try {
if(parts == 1){ if(parts == 1){
URL url = new URL("http://download.osmand.net/download?file="+key); //$NON-NLS-1$ URL url = new URL("http://download.osmand.net/download?file="+fileName); //$NON-NLS-1$
downloadFile(key, out, url, null, progress); downloadFile(fileName, out, url, null, indexOfAllFiles, progress);
} else { } else {
for(int i=1; i<=parts; i++){ for(int i=1; i<=parts; i++){
URL url = new URL("http://download.osmand.net/download?file="+key+"-"+i); //$NON-NLS-1$ URL url = new URL("http://download.osmand.net/download?file="+fileName+"-"+i); //$NON-NLS-1$
downloadFile(key, out, url, " ["+i+"/"+parts+"]", progress); downloadFile(fileName, out, url, " ["+i+"/"+parts+"]", indexOfAllFiles, progress);
} }
} }
} finally { } finally {
@ -652,20 +678,14 @@ public class DownloadIndexActivity extends ListActivity {
toIndex.setLastModified(dateModified); toIndex.setLastModified(dateModified);
} }
if (toIndex.getName().endsWith(IndexConstants.POI_INDEX_EXT)) { if (toIndex.getName().endsWith(IndexConstants.POI_INDEX_EXT)) {
// update poi index immediately
manager.indexingPoi(progress, warnings, toIndex); manager.indexingPoi(progress, warnings, toIndex);
} else if (toIndex.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
warnings.addAll(manager.indexingMaps(progress));
if(warnings.isEmpty() && !OsmandSettings.getOsmandSettings(getApplicationContext()).MAP_VECTOR_DATA.get()){
warnings.add(getString(R.string.binary_map_download_success));
// Is it proper way to switch every tome to vector data?
OsmandSettings.getOsmandSettings(getApplicationContext()).MAP_VECTOR_DATA.set(true);
}
} else if (toIndex.getName().endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
} }
if(dateModified != null){ if(dateModified != null){
toIndex.setLastModified(dateModified); toIndex.setLastModified(dateModified);
manager.updateIndexLastDateModified(toIndex); manager.updateIndexLastDateModified(toIndex);
} }
toReIndex.add(toIndex);
if (warnings.isEmpty()) { if (warnings.isEmpty()) {
showWarning(getString(R.string.download_index_success)); showWarning(getString(R.string.download_index_success));
} else { } else {

View file

@ -255,7 +255,7 @@ public class MapRenderRepositories {
} }
// search lower level zooms only in basemap for now :) before it was intersection of maps on zooms 5-7 // search lower level zooms only in basemap for now :) before it was intersection of maps on zooms 5-7
boolean basemapSearch = false; boolean basemapSearch = false;
if (zoom < 7) { if (zoom <= 7) {
for (String f : files.keySet()) { for (String f : files.keySet()) {
if (f.toLowerCase().contains(BASEMAP_NAME)) { if (f.toLowerCase().contains(BASEMAP_NAME)) {
basemapSearch = true; basemapSearch = true;

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB