fix small issues

git-svn-id: https://osmand.googlecode.com/svn/trunk@199 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-23 12:08:10 +00:00
parent bde5c301a1
commit 8a965e8380
6 changed files with 27 additions and 20 deletions

View file

@ -2,7 +2,6 @@ package com.osmand.data.index;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
@ -107,9 +106,9 @@ public class DownloaderIndexFromGoogleCode {
return files;
}
public static InputStream getInputStreamToLoadIndex(String indexName) throws IOException{
public static URL getInputStreamToLoadIndex(String indexName) throws IOException{
URL url = new URL("http://osmand.googlecode.com/files/"+indexName); //$NON-NLS-1$
return url.openStream();
return url;
}
}

View file

@ -9,7 +9,7 @@
<string name="downloading">Загрузка...</string>
<string name="downloading_list_indexes">Загружается список доступных индексов</string>
<string name="list_index_files_was_not_loaded">Не найдены доступные индекс файлы с osmand.googlecode.com</string>
<string name="select_index_file_to_download">Выберите файл индекса для загрузки из интернета. Если вы не можете найти регион, вы можете создать его самостоятельно.
<string name="select_index_file_to_download">Если вы не можете найти регион, вы можете создать его самостоятельно.
Читайте на osmand.googlecode.com .</string>
<string name="show_poi_on_map">Показать на карте</string>
<string name="fav_points_edited">Отредактирована избранная точка</string>

View file

@ -8,8 +8,9 @@
<string name="downloading_file">Downloading file</string>
<string name="downloading">Downloading...</string>
<string name="downloading_list_indexes">Downloading list of available indexes</string>
<string name="list_index_files_was_not_loaded">The index files are not loaded from osmand.googlecode.com. If you can't find your region, you can make it yourself. See osmand.googlecode.com.</string>
<string name="select_index_file_to_download">Select index file to download from internet</string>
<string name="list_index_files_was_not_loaded">The index files are not loaded from osmand.googlecode.com.</string>
<string name="select_index_file_to_download">If you can't find your region, you can make it by yourself.
See osmand.googlecode.com.</string>
<string name="show_poi_on_map">Show on map</string>
<string name="fav_points_edited">Favorite point was edited</string>
<string name="fav_points_not_exist">None of favorite points exist</string>

View file

@ -9,7 +9,7 @@ import android.os.Message;
public class ProgressDialogImplementation implements IProgress {
private static final float deltaToChange = 0.04f;
private static final float deltaToChange = 0.023f;
private String taskName;
private int progress;
private int work;
@ -60,8 +60,9 @@ public class ProgressDialogImplementation implements IProgress {
@Override
public void progress(int deltaWork) {
this.deltaWork += deltaWork;
if(change(progress + deltaWork)){
this.progress += deltaWork;
if(change(progress + this.deltaWork)){
this.progress += this.deltaWork;
this.deltaWork = 0;
updateMessage();
}
}

View file

@ -64,7 +64,7 @@ public class ResourceManager {
// Indexes
private Map<String, RegionAddressRepository> addressMap = new TreeMap<String, RegionAddressRepository>(Collator.getInstance());
protected List<AmenityIndexRepository> amenityRepositories = new ArrayList<AmenityIndexRepository>();
protected Map<String, AmenityIndexRepository> amenityRepositories = new LinkedHashMap<String, AmenityIndexRepository>();
public AsyncLoadingThread asyncLoadingTiles = new AsyncLoadingThread();
@ -253,7 +253,7 @@ public class ResourceManager {
progress.startTask(Messages.getMessage("indexing_poi") + f.getName(), -1); //$NON-NLS-1$
boolean initialized = repository.initialize(progress, f);
if (initialized) {
amenityRepositories.add(repository);
amenityRepositories.put(repository.getName(), repository);
}else {
warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_not_supported"), f.getName())); //$NON-NLS-1$
}
@ -289,7 +289,7 @@ public class ResourceManager {
// //////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
public List<AmenityIndexRepository> searchRepositories(double latitude, double longitude) {
List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();
for (AmenityIndexRepository index : amenityRepositories) {
for (AmenityIndexRepository index : amenityRepositories.values()) {
if (index.checkContains(latitude,longitude)) {
repos.add(index);
}
@ -304,7 +304,7 @@ public class ResourceManager {
double leftLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX - 0.5);
double rightLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX + 0.5);
List<Amenity> amenities = new ArrayList<Amenity>();
for (AmenityIndexRepository index : amenityRepositories) {
for (AmenityIndexRepository index : amenityRepositories.values()) {
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, filter.getFilterId(), amenities)) {
index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, filter, amenities);
@ -317,7 +317,7 @@ public class ResourceManager {
public void searchAmenitiesAsync(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, PoiFilter filter, List<Amenity> toFill){
String filterId = filter == null ? null : filter.getFilterId();
for(AmenityIndexRepository index : amenityRepositories){
for(AmenityIndexRepository index : amenityRepositories.values()){
if(index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)){
if(!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, filterId, toFill, true)){
asyncLoadingTiles.requestToLoadAmenities(
@ -340,7 +340,7 @@ public class ResourceManager {
////////////////////////////////////////////// Closing methods ////////////////////////////////////////////////
public void closeAmenities(){
for(AmenityIndexRepository r : amenityRepositories){
for(AmenityIndexRepository r : amenityRepositories.values()){
r.close();
}
amenityRepositories.clear();
@ -363,7 +363,7 @@ public class ResourceManager {
public void onLowMemory() {
log.info("On low memory : cleaning tiles - size = " + cacheOfImages.size()); //$NON-NLS-1$
clearTiles();
for(AmenityIndexRepository r : amenityRepositories){
for(AmenityIndexRepository r : amenityRepositories.values()){
r.clearCache();
}
for(RegionAddressRepository r : addressMap.values()){

View file

@ -4,6 +4,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@ -112,7 +114,7 @@ public class DownloadIndexActivity extends ListActivity {
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.ADDRESS_PATH);
regionName += IndexConstants.ADDRESS_INDEX_EXT;
} else if(key.endsWith(IndexConstants.POI_INDEX_EXT)){
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.ADDRESS_PATH);
parent = new File(Environment.getExternalStorageDirectory(), ResourceManager.POI_PATH);
regionName += IndexConstants.POI_INDEX_EXT;
}
if(parent != null){
@ -133,8 +135,10 @@ public class DownloadIndexActivity extends ListActivity {
try {
FileOutputStream out = new FileOutputStream(file);
try {
InputStream is = DownloaderIndexFromGoogleCode.getInputStreamToLoadIndex(key);
impl.startTask(getString(R.string.downloading_file), is.available());
URL url = DownloaderIndexFromGoogleCode.getInputStreamToLoadIndex(key);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream();
impl.startTask(getString(R.string.downloading_file), conn.getContentLength());
byte[] buffer = new byte[BUFFER_SIZE];
int read = 0;
while((read = is.read(buffer)) != -1){
@ -158,6 +162,8 @@ public class DownloadIndexActivity extends ListActivity {
} catch (IOException e) {
log.error("Exception ocurred", e); //$NON-NLS-1$
showWarning(getString(R.string.error_io_error));
// Possibly file is corrupted
file.delete();
} finally {
dlg.dismiss();
}
@ -170,7 +176,7 @@ public class DownloadIndexActivity extends ListActivity {
runOnUiThread(new Runnable(){
@Override
public void run() {
Toast.makeText(DownloadIndexActivity.this, messages, Toast.LENGTH_LONG);
Toast.makeText(DownloadIndexActivity.this, messages, Toast.LENGTH_LONG).show();
}
});