From bde5c301a1c72c0d6e157a083a48e11529643e04 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 23 Jun 2010 11:35:26 +0000 Subject: [PATCH] implement downloading indexes screen git-svn-id: https://osmand.googlecode.com/svn/trunk@198 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 5 +- .../index/DownloaderIndexFromGoogleCode.java | 7 +- OsmAnd/AndroidManifest.xml | 1 + OsmAnd/res/layout/download_index.xml | 11 + .../res/layout/download_index_list_item.xml | 13 ++ OsmAnd/res/layout/search_by_name.xml | 1 + OsmAnd/res/values-ru-rRU/strings.xml | 16 +- OsmAnd/res/values/strings.xml | 19 +- OsmAnd/res/xml/settings_pref.xml | 1 + OsmAnd/src/com/osmand/OsmandSettings.java | 2 +- .../osmand/ProgressDialogImplementation.java | 21 +- OsmAnd/src/com/osmand/ResourceManager.java | 56 +++-- .../activities/DownloadIndexActivity.java | 205 ++++++++++++++++++ .../osmand/activities/EditingPOIActivity.java | 4 +- .../osmand/activities/SettingsActivity.java | 9 +- .../activities/search/SearchActivity.java | 2 +- .../search/SearchByNameAbstractActivity.java | 18 ++ 17 files changed, 349 insertions(+), 42 deletions(-) create mode 100644 OsmAnd/res/layout/download_index.xml create mode 100644 OsmAnd/res/layout/download_index_list_item.xml create mode 100644 OsmAnd/src/com/osmand/activities/DownloadIndexActivity.java diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index b1cbce7b34..2ab4f4bf4a 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -19,12 +19,10 @@ public class ToDoConstants { // FUTURE RELEASES - // 54. Invent screen to update index from internet (from osmand.googlecode.com) // 46. Implement downloading strategy for tiles : select max zoom to download [16,15,14,...] // That means you can save internet because from [16 -> zoom -> 18], [14 -> zoom -> 16 - suitable for speed > 40], ... // 50. Invent opening hours editor in order to edit POI hours better on device - // 53. Add progress bars (for search adresses activity - show that something is loaded in background), - // to internet communication activities [editing/commiting/deleting poi], do not hide edit poi dialog if operation failed + // 53. Add progress bars : to internet communication activities [editing/commiting/deleting poi], do not hide edit poi dialog if operation failed // [move close buttons from alertdialog to own view] // 55. Update POI data from internet for selected area [suggest to create new POI index or extend exising of none exist] // 43. Enable poi filter by name @@ -53,6 +51,7 @@ public class ToDoConstants { // BUGS Swing // DONE ANDROID : + // 54. Invent screen to update index from internet (from osmand.googlecode.com) // 32. Introduce POI predefined filters (car filter(other-fuel, transportation-car_wash, show-car) and others) // 48. Enable change favorite point : (for example fav - "car") means last point you left car. It is not static point, // you can always use the same name for different locations. diff --git a/DataExtractionOSM/src/com/osmand/data/index/DownloaderIndexFromGoogleCode.java b/DataExtractionOSM/src/com/osmand/data/index/DownloaderIndexFromGoogleCode.java index da58d10758..5d51daf9b0 100644 --- a/DataExtractionOSM/src/com/osmand/data/index/DownloaderIndexFromGoogleCode.java +++ b/DataExtractionOSM/src/com/osmand/data/index/DownloaderIndexFromGoogleCode.java @@ -23,7 +23,10 @@ public class DownloaderIndexFromGoogleCode { * @throws IOException */ public static void main(String[] args) throws URISyntaxException, IOException { - System.out.println(getIndexFiles(new String[] {".addr.odb",".poi.odb"}, new String[] {"0", "0"})); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + Map indexFiles = DownloaderIndexFromGoogleCode.getIndexFiles(new String[] { IndexConstants.ADDRESS_INDEX_EXT, + IndexConstants.POI_INDEX_EXT }, new String[] { + IndexConstants.ADDRESS_TABLE_VERSION + "", IndexConstants.POI_TABLE_VERSION + "" }); //$NON-NLS-1$//$NON-NLS-2$ + System.out.println(indexFiles); } private static StringBuilder getContent() { @@ -57,7 +60,7 @@ public class DownloaderIndexFromGoogleCode { prevI = i; } int j = i - 1; - while (content.charAt(j) == '_' || Character.isLetterOrDigit(content.charAt(j))) { + while (content.charAt(j) == '_' || Character.isLetterOrDigit(content.charAt(j)) || content.charAt(j) == '-') { j--; } if(!content.substring(j + 1, i).endsWith("_"+version)){ //$NON-NLS-1$ diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 0129b3fe77..2a6bd17132 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -14,6 +14,7 @@ + diff --git a/OsmAnd/res/layout/download_index.xml b/OsmAnd/res/layout/download_index.xml new file mode 100644 index 0000000000..fee37170ba --- /dev/null +++ b/OsmAnd/res/layout/download_index.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/OsmAnd/res/layout/download_index_list_item.xml b/OsmAnd/res/layout/download_index_list_item.xml new file mode 100644 index 0000000000..74182963f2 --- /dev/null +++ b/OsmAnd/res/layout/download_index_list_item.xml @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/OsmAnd/res/layout/search_by_name.xml b/OsmAnd/res/layout/search_by_name.xml index 5822328e89..e7a8d67328 100644 --- a/OsmAnd/res/layout/search_by_name.xml +++ b/OsmAnd/res/layout/search_by_name.xml @@ -6,6 +6,7 @@ + diff --git a/OsmAnd/res/values-ru-rRU/strings.xml b/OsmAnd/res/values-ru-rRU/strings.xml index 1b5fd60045..21ad4cd774 100644 --- a/OsmAnd/res/values-ru-rRU/strings.xml +++ b/OsmAnd/res/values-ru-rRU/strings.xml @@ -1,5 +1,16 @@ + Директория на SD карточка не доступна для сохранения + Вы хотите загрузить {0} - {1} ? + Адрес + Индекс успешно загружен + Произошла ошибка ввода/вывода. + Загрузка файла + Загрузка... + Загружается список доступных индексов + Не найдены доступные индекс файлы с osmand.googlecode.com + Выберите файл индекса для загрузки из интернета. Если вы не можете найти регион, вы можете создать его самостоятельно. +Читайте на osmand.googlecode.com . Показать на карте Отредактирована избранная точка Не существует избранных точек @@ -42,6 +53,8 @@ Окончен : Перезагрузить индексы с SD Обновить индексы + Загрузить индекс файлы из интернета + Загрузить индексы Использовать интернет для расчета маршрута Online маршрутизация Указать пароль для работы с OSM @@ -153,7 +166,7 @@ Здание Здание Пересечение улиц -Адрес + Координаты Идти к точке Добавить к избранным @@ -203,7 +216,6 @@ Действие {0} успешно завершено. Неожиданная ошибка произошла при выполнении действия {0}. Ошибка ввода/вывода произошла при выполнении действия {0}. -Произошла ошибка ввода/вывода. Произошла ошибка при загрузке информации о POI Имя diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 9c2addc117..f52d425603 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,15 @@ + Directory on SD card to save index is not accessible + Do you want to download {0} - {1} ? + Address + Index downloaded successfully + Input/output error occured. + Downloading file + Downloading... + Downloading list of available indexes + 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. + Select index file to download from internet Show on map Favorite point was edited None of favorite points exist @@ -42,6 +52,8 @@ Finished : Reload data indexes from SD Reload indexes + Download indexes from internet + Download indexes Use internet to calculate route Use online routing Input osm password @@ -154,7 +166,6 @@ Building Intersected street -Address Location Navigate to point @@ -203,9 +214,9 @@ Add Change Action {0} completed successfully. -Unexpected error occured while preforming action {0}. -Input/output error occured while preforming action {0}. -Input/output error occured. +Unexpected error occured while performing action {0}. +Input/output error occured while performing action {0}. + Info about node was not loaded Name diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index c996980a92..71fd7f2aed 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -17,6 +17,7 @@ + diff --git a/OsmAnd/src/com/osmand/OsmandSettings.java b/OsmAnd/src/com/osmand/OsmandSettings.java index 58d44f05ca..b36d6a12b5 100644 --- a/OsmAnd/src/com/osmand/OsmandSettings.java +++ b/OsmAnd/src/com/osmand/OsmandSettings.java @@ -113,8 +113,8 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public static final String SAVE_CURRENT_TRACK = "save_current_track"; //$NON-NLS-1$ - public static final String RELOAD_INDEXES = "reload_indexes"; //$NON-NLS-1$ + public static final String DOWNLOAD_INDEXES = "download_indexes"; //$NON-NLS-1$ // this value string is synchronized with settings_pref.xml preference name public static final String SAVE_TRACK_TO_GPX = "save_track_to_gpx"; //$NON-NLS-1$ diff --git a/OsmAnd/src/com/osmand/ProgressDialogImplementation.java b/OsmAnd/src/com/osmand/ProgressDialogImplementation.java index 28f8572aeb..7091229f66 100644 --- a/OsmAnd/src/com/osmand/ProgressDialogImplementation.java +++ b/OsmAnd/src/com/osmand/ProgressDialogImplementation.java @@ -2,6 +2,8 @@ package com.osmand; import android.app.ProgressDialog; import android.content.Context; +import android.content.DialogInterface; +import android.content.DialogInterface.OnCancelListener; import android.os.Handler; import android.os.Message; @@ -18,15 +20,30 @@ public class ProgressDialogImplementation implements IProgress { private Thread run; private Context context; - public ProgressDialogImplementation(final ProgressDialog dlg){ + public ProgressDialogImplementation(final ProgressDialog dlg, boolean cancelable){ context = dlg.getContext(); + if(cancelable){ + dlg.setOnCancelListener(new OnCancelListener(){ + @Override + public void onCancel(DialogInterface dialog) { + if(run != null){ + run.stop(); + } + + } + }); + } mViewUpdateHandler = new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); dlg.setMessage(message); } - }; + }; + } + + public ProgressDialogImplementation(final ProgressDialog dlg){ + this(dlg, false); } public void setRunnable(String threadName, Runnable run){ diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index 2fbbbcf3ca..b39ba4cac6 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -36,9 +36,9 @@ import com.osmand.views.POIMapLayer; */ public class ResourceManager { - private static final String POI_PATH = "osmand/" + IndexConstants.POI_INDEX_DIR; //$NON-NLS-1$ - private static final String ADDRESS_PATH = "osmand/" + IndexConstants.ADDRESS_INDEX_DIR; //$NON-NLS-1$ - private static final String TILES_PATH = "osmand/tiles/"; //$NON-NLS-1$ + public static final String POI_PATH = "osmand/" + IndexConstants.POI_INDEX_DIR; //$NON-NLS-1$ + public static final String ADDRESS_PATH = "osmand/" + IndexConstants.ADDRESS_INDEX_DIR; //$NON-NLS-1$ + public static final String TILES_PATH = "osmand/tiles/"; //$NON-NLS-1$ private static final Log log = LogUtil.getLog(ResourceManager.class); @@ -240,22 +240,26 @@ public class ResourceManager { closeAmenities(); if (file.exists() && file.canRead()) { for (File f : file.listFiles()) { - if (f.getName().endsWith(IndexConstants.POI_INDEX_EXT)) { - AmenityIndexRepository repository = new AmenityIndexRepository(); - - progress.startTask(Messages.getMessage("indexing_poi") + f.getName(), -1); //$NON-NLS-1$ - boolean initialized = repository.initialize(progress, f); - if (initialized) { - amenityRepositories.add(repository); - }else { - warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_not_supported"), f.getName())); //$NON-NLS-1$ - } - } + indexingPoi(progress, warnings, f); } } return warnings; } + public void indexingPoi(final IProgress progress, List warnings, File f) { + if (f.getName().endsWith(IndexConstants.POI_INDEX_EXT)) { + AmenityIndexRepository repository = new AmenityIndexRepository(); + + progress.startTask(Messages.getMessage("indexing_poi") + f.getName(), -1); //$NON-NLS-1$ + boolean initialized = repository.initialize(progress, f); + if (initialized) { + amenityRepositories.add(repository); + }else { + warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_not_supported"), f.getName())); //$NON-NLS-1$ + } + } + } + public List indexingAddresses(final IProgress progress){ File file = new File(Environment.getExternalStorageDirectory(), ADDRESS_PATH); @@ -263,20 +267,24 @@ public class ResourceManager { closeAddresses(); if (file.exists() && file.canRead()) { for (File f : file.listFiles()) { - if (f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)) { - RegionAddressRepository repository = new RegionAddressRepository(); - progress.startTask(Messages.getMessage("indexing_address") + f.getName(), -1); //$NON-NLS-1$ - boolean initialized = repository.initialize(progress, f); - if (initialized) { - addressMap.put(repository.getName(), repository); - } else { - warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_not_supported"), f.getName())); //$NON-NLS-1$ - } - } + indexingAddress(progress, warnings, f); } } return warnings; } + + public void indexingAddress(final IProgress progress, List warnings, File f) { + if (f.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)) { + RegionAddressRepository repository = new RegionAddressRepository(); + progress.startTask(Messages.getMessage("indexing_address") + f.getName(), -1); //$NON-NLS-1$ + boolean initialized = repository.initialize(progress, f); + if (initialized) { + addressMap.put(repository.getName(), repository); + } else { + warnings.add(MessageFormat.format(Messages.getMessage("version_index_is_not_supported"), f.getName())); //$NON-NLS-1$ + } + } + } // //////////////////////////////////////////// Working with amenities //////////////////////////////////////////////// public List searchRepositories(double latitude, double longitude) { diff --git a/OsmAnd/src/com/osmand/activities/DownloadIndexActivity.java b/OsmAnd/src/com/osmand/activities/DownloadIndexActivity.java new file mode 100644 index 0000000000..002efadd06 --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/DownloadIndexActivity.java @@ -0,0 +1,205 @@ +package com.osmand.activities; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.logging.Log; + +import android.app.AlertDialog; +import android.app.ListActivity; +import android.app.ProgressDialog; +import android.app.AlertDialog.Builder; +import android.content.DialogInterface; +import android.os.Bundle; +import android.os.Environment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; + +import com.osmand.LogUtil; +import com.osmand.ProgressDialogImplementation; +import com.osmand.R; +import com.osmand.ResourceManager; +import com.osmand.data.index.DownloaderIndexFromGoogleCode; +import com.osmand.data.index.IndexConstants; + +public class DownloadIndexActivity extends ListActivity { + + private final static Log log = LogUtil.getLog(DownloadIndexActivity.class); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.download_index); + + final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_list_indexes)); + dlg.setCancelable(true); + + new Thread(new Runnable(){ + @Override + public void run() { + final Map indexFiles = downloadIndex(); + dlg.dismiss(); + runOnUiThread(new Runnable() { + @Override + public void run() { + if (indexFiles != null) { + setListAdapter(new DownloadIndexAdapter(new ArrayList>(indexFiles.entrySet()))); + } else { + Toast.makeText(DownloadIndexActivity.this, R.string.list_index_files_was_not_loaded, Toast.LENGTH_LONG).show(); + } + } + }); + + } + }, "DownloadIndexes").start(); //$NON-NLS-1$ + + } + + protected Map downloadIndex(){ + try { + log.debug("Start loading list of index files"); //$NON-NLS-1$ + Map indexFiles = DownloaderIndexFromGoogleCode.getIndexFiles(new String[] { IndexConstants.ADDRESS_INDEX_EXT, + IndexConstants.POI_INDEX_EXT }, new String[] { + IndexConstants.ADDRESS_TABLE_VERSION + "", IndexConstants.POI_TABLE_VERSION + "" }); //$NON-NLS-1$//$NON-NLS-2$ + if (indexFiles != null && !indexFiles.isEmpty()) { + return indexFiles; + } else { + return null; + } + } catch (RuntimeException e) { + log.error("Error while loading indexes from repository", e); //$NON-NLS-1$ + return null; + } + } + + + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + super.onListItemClick(l, v, position, id); + final Entry e = ((DownloadIndexAdapter)getListAdapter()).getItem(position); + Builder builder = new AlertDialog.Builder(this); + int ls = e.getKey().lastIndexOf('_'); + final String regionName = e.getKey().substring(0, ls); + builder.setMessage(MessageFormat.format(getString(R.string.download_question), regionName, e.getValue())); + builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener(){ + @Override + public void onClick(DialogInterface dialog, int which) { + downloadFile(e.getKey(), regionName); + } + }); + builder.setNegativeButton(R.string.default_buttons_no, null); + builder.show(); + } + + private static final int BUFFER_SIZE = 32256; + + protected void downloadFile(final String key, String regionName) { + File parent = null; + if(key.endsWith(IndexConstants.ADDRESS_INDEX_EXT)){ + 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); + regionName += IndexConstants.POI_INDEX_EXT; + } + if(parent != null){ + parent.mkdirs(); + } + if(parent == null || !parent.exists()){ + Toast.makeText(DownloadIndexActivity.this, getString(R.string.download_sd_dir_not_accessible), Toast.LENGTH_LONG); + return; + } + final File file = new File(parent, regionName); + final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_file), true, true); + dlg.show(); + final ProgressDialogImplementation impl = new ProgressDialogImplementation(dlg, true); + impl.setRunnable("DownloadIndex", new Runnable(){ //$NON-NLS-1$ + + @Override + public void run() { + try { + FileOutputStream out = new FileOutputStream(file); + try { + InputStream is = DownloaderIndexFromGoogleCode.getInputStreamToLoadIndex(key); + impl.startTask(getString(R.string.downloading_file), is.available()); + byte[] buffer = new byte[BUFFER_SIZE]; + int read = 0; + while((read = is.read(buffer)) != -1){ + out.write(buffer, 0, read); + impl.progress(read); + } + ArrayList warnings = new ArrayList(); + if(file.getName().endsWith(IndexConstants.ADDRESS_INDEX_EXT)){ + ResourceManager.getResourceManager().indexingAddress(impl, warnings, file); + } else if(file.getName().endsWith(IndexConstants.POI_INDEX_EXT)){ + ResourceManager.getResourceManager().indexingPoi(impl, warnings, file); + } + if(warnings.isEmpty()){ + showWarning(getString(R.string.download_index_success)); + } else { + showWarning(warnings.get(0)); + } + } finally { + out.close(); + } + } catch (IOException e) { + log.error("Exception ocurred", e); //$NON-NLS-1$ + showWarning(getString(R.string.error_io_error)); + } finally { + dlg.dismiss(); + } + } + }); + impl.run(); + } + + public void showWarning(final String messages){ + runOnUiThread(new Runnable(){ + @Override + public void run() { + Toast.makeText(DownloadIndexActivity.this, messages, Toast.LENGTH_LONG); + } + + }); + } + + + private class DownloadIndexAdapter extends ArrayAdapter> { + + public DownloadIndexAdapter(List> array) { + super(DownloadIndexActivity.this, com.osmand.R.layout.download_index_list_item, array); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View row = convertView; + if (row == null) { + LayoutInflater inflater = getLayoutInflater(); + row = inflater.inflate(com.osmand.R.layout.download_index_list_item, parent, false); + } + TextView item = (TextView) row.findViewById(R.id.download_item); + TextView description = (TextView) row.findViewById(R.id.download_descr); + Entry e = getItem(position); + int l = e.getKey().lastIndexOf('_'); + String s = e.getKey().endsWith(IndexConstants.POI_INDEX_EXT) ? getString(R.string.poi) : getString(R.string.address); + item.setText(s + "\n " + e.getKey().substring(0, l)); //$NON-NLS-1$ + description.setText(e.getValue().replace(':', '\n')); + return row; + } + } + + +} diff --git a/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java b/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java index c879c4b9e9..abe3c72775 100644 --- a/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java +++ b/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java @@ -524,10 +524,10 @@ public class EditingPOIActivity { } catch (IOException e) { log.error("Loading node failed" + id, e); //$NON-NLS-1$ - Toast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_io_error), Toast.LENGTH_LONG).show(); + Toast.makeText(ctx, ctx.getResources().getString(R.string.error_io_error), Toast.LENGTH_LONG).show(); } catch (SAXException e) { log.error("Loading node failed" + id, e); //$NON-NLS-1$ - Toast.makeText(ctx, ctx.getResources().getString(R.string.poi_error_io_error), Toast.LENGTH_LONG).show(); + Toast.makeText(ctx, ctx.getResources().getString(R.string.error_io_error), Toast.LENGTH_LONG).show(); } return null; } diff --git a/OsmAnd/src/com/osmand/activities/SettingsActivity.java b/OsmAnd/src/com/osmand/activities/SettingsActivity.java index f42f5da18c..9d5cd7a71f 100644 --- a/OsmAnd/src/com/osmand/activities/SettingsActivity.java +++ b/OsmAnd/src/com/osmand/activities/SettingsActivity.java @@ -4,6 +4,7 @@ import java.util.List; import android.app.ProgressDialog; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Resources; @@ -44,6 +45,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference private CheckBoxPreference autoZoom; private EditTextPreference userPassword; private Preference reloadIndexes; + private Preference downloadIndexes; @Override public void onCreate(Bundle savedInstanceState) { @@ -71,6 +73,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference useEnglishNames.setOnPreferenceChangeListener(this); reloadIndexes =(Preference) screen.findPreference(OsmandSettings.RELOAD_INDEXES); reloadIndexes.setOnPreferenceClickListener(this); + downloadIndexes =(Preference) screen.findPreference(OsmandSettings.DOWNLOAD_INDEXES); + downloadIndexes.setOnPreferenceClickListener(this); userName = (EditTextPreference) screen.findPreference(OsmandSettings.USER_NAME); userName.setOnPreferenceChangeListener(this); @@ -318,7 +322,10 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference @Override public boolean onPreferenceClick(Preference preference) { - if(preference == reloadIndexes){ + if(preference == downloadIndexes){ + startActivity(new Intent(this, DownloadIndexActivity.class)); + return true; + } else if(preference == reloadIndexes){ reloadIndexes(); return true; } else if(preference == saveCurrentTrack){ diff --git a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java index 6054a9f6e5..b3faa4cff6 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java @@ -25,7 +25,7 @@ public class SearchActivity extends TabActivity { super.onCreate(savedInstanceState); TabHost host = getTabHost(); host.addTab(host.newTabSpec("Search_POI").setIndicator(getString(R.string.poi)).setContent(new Intent(this, SearchPoiFilterActivity.class))); //$NON-NLS-1$ - host.addTab(host.newTabSpec("Search_Address").setIndicator(getString(R.string.search_tabs_address)).setContent(new Intent(this, SearchAddressActivity.class))); //$NON-NLS-1$ + host.addTab(host.newTabSpec("Search_Address").setIndicator(getString(R.string.address)).setContent(new Intent(this, SearchAddressActivity.class))); //$NON-NLS-1$ host.addTab(host.newTabSpec("Search_Location").setIndicator(getString(R.string.search_tabs_location)).setContent(new Intent(this, NavigatePointActivity.class))); //$NON-NLS-1$ } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java index 54e34e99d7..8cd43011d5 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java @@ -16,6 +16,7 @@ import android.view.Window; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ListView; +import android.widget.ProgressBar; import android.widget.TextView; import com.osmand.R; @@ -24,6 +25,7 @@ public abstract class SearchByNameAbstractActivity extends ListActivity { private EditText searchText; private Handler handlerToLoop; + private ProgressBar progress; @Override protected void onCreate(Bundle savedInstanceState) { @@ -32,6 +34,7 @@ public abstract class SearchByNameAbstractActivity extends ListActivity { setContentView(R.layout.search_by_name); NamesAdapter namesAdapter = new NamesAdapter(getObjects("")); //$NON-NLS-1$ setListAdapter(namesAdapter); + progress = (ProgressBar) findViewById(R.id.ProgressBar); searchText = (EditText) findViewById(R.id.SearchText); searchText.addTextChangedListener(new TextWatcher(){ @@ -47,6 +50,7 @@ public abstract class SearchByNameAbstractActivity extends ListActivity { } }); + progress.setVisibility(View.INVISIBLE); findViewById(R.id.ResetButton).setOnClickListener(new View.OnClickListener(){ @Override @@ -74,6 +78,7 @@ public abstract class SearchByNameAbstractActivity extends ListActivity { ((NamesAdapter)getListAdapter()).add(o); } ((NamesAdapter)getListAdapter()).notifyDataSetChanged(); + progress.setVisibility(View.INVISIBLE); } }); } @@ -92,6 +97,7 @@ public abstract class SearchByNameAbstractActivity extends ListActivity { Message msg = Message.obtain(handlerToLoop, new Runnable() { @Override public void run() { + showProgress(View.VISIBLE); List loadedObjects = getObjects(filter); if(handlerToLoop != null && !handlerToLoop.hasMessages(1)){ updateUIList(loadedObjects); @@ -101,6 +107,18 @@ public abstract class SearchByNameAbstractActivity extends ListActivity { msg.what = 1; handlerToLoop.sendMessageDelayed(msg, 150); } + + private void showProgress(final int v){ + runOnUiThread(new Runnable(){ + + @Override + public void run() { + progress.setVisibility(v); + + } + + }); + } public abstract List getObjects(String filter);