implement downloading indexes screen

git-svn-id: https://osmand.googlecode.com/svn/trunk@198 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-23 11:35:26 +00:00
parent 968b18cfc5
commit bde5c301a1
17 changed files with 349 additions and 42 deletions

View file

@ -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.

View file

@ -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<String, String> 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$

View file

@ -14,6 +14,7 @@
<activity android:name=".activities.SettingsActivity" android:label="@string/settings_activity"></activity>
<activity android:name=".activities.search.SearchActivity" android:label="@string/search_activity" ></activity>
<activity android:name=".activities.NavigatePointActivity"></activity>
<activity android:name=".activities.DownloadIndexActivity"></activity>
<activity android:name=".activities.FavouritesActivity" android:label="@string/favourites_activity"></activity>
<activity android:name=".activities.search.SearchPOIActivity" android:label="@string/searchpoi_activity"></activity>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/Label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="@string/select_index_file_to_download"></TextView>
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_marginLeft="3dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp"></ListView>
</LinearLayout>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/download_item"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" ></TextView>
<TextView android:id="@+id/download_descr" android:layout_marginLeft = "5dp"
android:layout_width="150dp" android:layout_height="wrap_content"></TextView>
</LinearLayout>

View file

@ -6,6 +6,7 @@
<TextView android:text="" android:id="@+id/Label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center"></TextView>
<LinearLayout android:id="@+id/LinearLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp">
<ProgressBar android:id="@+id/ProgressBar" android:layout_width="wrap_content" android:layout_height="wrap_content"></ProgressBar>
<EditText android:text="" android:id="@+id/SearchText" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="text|textFilter|textPhonetic"></EditText>
<Button android:id="@+id/ResetButton" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="0" android:text="@string/default_buttons_reset"></Button>

View file

@ -1,5 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="download_sd_dir_not_accessible">Директория на SD карточка не доступна для сохранения</string>
<string name="download_question">Вы хотите загрузить {0} - {1} ?</string>
<string name="address">Адрес</string>
<string name="download_index_success">Индекс успешно загружен</string>
<string name="error_io_error">Произошла ошибка ввода/вывода.</string>
<string name="downloading_file">Загрузка файла</string>
<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">Выберите файл индекса для загрузки из интернета. Если вы не можете найти регион, вы можете создать его самостоятельно.
Читайте на osmand.googlecode.com .</string>
<string name="show_poi_on_map">Показать на карте</string>
<string name="fav_points_edited">Отредактирована избранная точка</string>
<string name="fav_points_not_exist">Не существует избранных точек</string>
@ -42,6 +53,8 @@
<string name="finished_task">Окончен : </string>
<string name="reload_indexes_descr">Перезагрузить индексы с SD</string>
<string name="reload_indexes">Обновить индексы</string>
<string name="download_indexes_descr">Загрузить индекс файлы из интернета</string>
<string name="download_indexes">Загрузить индексы</string>
<string name="use_online_routing_descr">Использовать интернет для расчета маршрута</string>
<string name="use_online_routing">Online маршрутизация</string>
<string name="user_password_descr">Указать пароль для работы с OSM</string>
@ -153,7 +166,7 @@
<string name="search_address_building">Здание</string>
<string name="search_address_building_option">Здание</string>
<string name="search_address_street_option">Пересечение улиц</string>
<string name="search_tabs_address">Адрес</string>
<string name="search_tabs_location">Координаты</string>
<string name="context_menu_item_navigate_point">Идти к точке</string>
<string name="context_menu_item_add_favorite">Добавить к избранным</string>
@ -203,7 +216,6 @@
<string name="poi_action_succeded_template">Действие {0} успешно завершено.</string>
<string name="poi_error_unexpected_template">Неожиданная ошибка произошла при выполнении действия {0}.</string>
<string name="poi_error_io_error_template">Ошибка ввода/вывода произошла при выполнении действия {0}.</string>
<string name="poi_error_io_error">Произошла ошибка ввода/вывода.</string>
<string name="poi_error_info_not_loaded">Произошла ошибка при загрузке информации о POI</string>
<string name="poi_dialog_name">Имя</string>

View file

@ -1,5 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="download_sd_dir_not_accessible">Directory on SD card to save index is not accessible</string>
<string name="download_question">Do you want to download {0} - {1} ?</string>
<string name="address">Address</string>
<string name="download_index_success">Index downloaded successfully</string>
<string name="error_io_error">Input/output error occured.</string>
<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="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>
@ -42,6 +52,8 @@
<string name="finished_task">Finished : </string>
<string name="reload_indexes_descr">Reload data indexes from SD</string>
<string name="reload_indexes">Reload indexes</string>
<string name="download_indexes_descr">Download indexes from internet</string>
<string name="download_indexes">Download indexes</string>
<string name="use_online_routing_descr">Use internet to calculate route</string>
<string name="use_online_routing">Use online routing</string>
<string name="user_password_descr">Input osm password</string>
@ -154,7 +166,6 @@
<string name="search_address_building_option">Building</string>
<string name="search_address_street_option">Intersected street</string>
<string name="search_tabs_address">Address</string>
<string name="search_tabs_location">Location</string>
<string name="context_menu_item_navigate_point">Navigate to point</string>
@ -203,9 +214,9 @@
<string name="poi_action_add">Add</string>
<string name="poi_action_change">Change</string>
<string name="poi_action_succeded_template">Action {0} completed successfully.</string>
<string name="poi_error_unexpected_template">Unexpected error occured while preforming action {0}.</string>
<string name="poi_error_io_error_template">Input/output error occured while preforming action {0}.</string>
<string name="poi_error_io_error">Input/output error occured.</string>
<string name="poi_error_unexpected_template">Unexpected error occured while performing action {0}.</string>
<string name="poi_error_io_error_template">Input/output error occured while performing action {0}.</string>
<string name="poi_error_info_not_loaded">Info about node was not loaded</string>
<string name="poi_dialog_name">Name</string>

View file

@ -17,6 +17,7 @@
<PreferenceScreen android:title="@string/data_settings" android:summary="@string/data_settings_descr">
<CheckBoxPreference android:summary="@string/use_english_names_descr" android:title="@string/use_english_names" android:key="use_english_names"></CheckBoxPreference>
<Preference android:title="@string/reload_indexes" android:key="reload_indexes" android:summary="@string/reload_indexes_descr"></Preference>
<Preference android:title="@string/download_indexes" android:key="download_indexes" android:summary="@string/download_indexes_descr"></Preference>
</PreferenceScreen>
<PreferenceScreen android:title="@string/monitor_preferences" android:summary="@string/monitor_preferences_descr">

View file

@ -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$

View file

@ -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,8 +20,19 @@ 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) {
@ -29,6 +42,10 @@ public class ProgressDialogImplementation implements IProgress {
};
}
public ProgressDialogImplementation(final ProgressDialog dlg){
this(dlg, false);
}
public void setRunnable(String threadName, Runnable run){
this.run = new Thread(run, threadName);
}

View file

@ -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<String> 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<String> indexingAddresses(final IProgress progress){
File file = new File(Environment.getExternalStorageDirectory(), ADDRESS_PATH);
@ -263,21 +267,25 @@ 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<String> 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<AmenityIndexRepository> searchRepositories(double latitude, double longitude) {
List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();

View file

@ -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<String, String> indexFiles = downloadIndex();
dlg.dismiss();
runOnUiThread(new Runnable() {
@Override
public void run() {
if (indexFiles != null) {
setListAdapter(new DownloadIndexAdapter(new ArrayList<Entry<String,String>>(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<String, String> downloadIndex(){
try {
log.debug("Start loading list of index files"); //$NON-NLS-1$
Map<String, String> 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<String, String> 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<String> warnings = new ArrayList<String>();
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<Entry<String, String>> {
public DownloadIndexAdapter(List<Entry<String, String>> 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<String, String> 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;
}
}
}

View file

@ -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;
}

View file

@ -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){

View file

@ -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$
}

View file

@ -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<T> 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<T> 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<T> extends ListActivity {
}
});
progress.setVisibility(View.INVISIBLE);
findViewById(R.id.ResetButton).setOnClickListener(new View.OnClickListener(){
@Override
@ -74,6 +78,7 @@ public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
((NamesAdapter)getListAdapter()).add(o);
}
((NamesAdapter)getListAdapter()).notifyDataSetChanged();
progress.setVisibility(View.INVISIBLE);
}
});
}
@ -92,6 +97,7 @@ public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
Message msg = Message.obtain(handlerToLoop, new Runnable() {
@Override
public void run() {
showProgress(View.VISIBLE);
List<T> loadedObjects = getObjects(filter);
if(handlerToLoop != null && !handlerToLoop.hasMessages(1)){
updateUIList(loadedObjects);
@ -102,6 +108,18 @@ public abstract class SearchByNameAbstractActivity<T> extends ListActivity {
handlerToLoop.sendMessageDelayed(msg, 150);
}
private void showProgress(final int v){
runOnUiThread(new Runnable(){
@Override
public void run() {
progress.setVisibility(v);
}
});
}
public abstract List<T> getObjects(String filter);
public abstract void updateTextView(T obj, TextView txt);