fix issue 179
git-svn-id: https://osmand.googlecode.com/svn/trunk@679 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
dd06e60bc1
commit
5825b5fe92
4 changed files with 103 additions and 20 deletions
BIN
OsmAnd/res/drawable/ic_menu_refresh.png
Normal file
BIN
OsmAnd/res/drawable/ic_menu_refresh.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="reload">Перезагрузить</string>
|
||||
<string name="poi_context_menu_website">Просмотреть вебсайт POI</string>
|
||||
<string name="poi_context_menu_call">Показать телефон POI</string>
|
||||
<string name="website">веб сайт</string>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||
<resources>
|
||||
<string name="reload">reload</string>
|
||||
<string name="poi_context_menu_website">See POI website</string>
|
||||
<string name="poi_context_menu_call">Show POI phone</string>
|
||||
<string name="website">web site</string>
|
||||
|
@ -406,4 +407,5 @@
|
|||
<string name="edit_filter_delete_message">Filter {0} has been deleted</string>
|
||||
<string name="edit_filter_create_message">Filter {0} has been created</string>
|
||||
<string name="default_buttons_selectall">Select All</string>
|
||||
|
||||
</resources>
|
|
@ -1,19 +1,19 @@
|
|||
package net.osmand.activities;
|
||||
|
||||
import static net.osmand.data.index.IndexConstants.ADDRESS_TABLE_VERSION;
|
||||
import static net.osmand.data.index.IndexConstants.ADDRESS_INDEX_EXT;
|
||||
import static net.osmand.data.index.IndexConstants.POI_TABLE_VERSION;
|
||||
import static net.osmand.data.index.IndexConstants.POI_INDEX_EXT;
|
||||
import static net.osmand.data.index.IndexConstants.TRANSPORT_TABLE_VERSION;
|
||||
import static net.osmand.data.index.IndexConstants.TRANSPORT_INDEX_EXT;
|
||||
import static net.osmand.data.index.IndexConstants.ADDRESS_INDEX_EXT_ZIP;
|
||||
import static net.osmand.data.index.IndexConstants.POI_INDEX_EXT_ZIP;
|
||||
import static net.osmand.data.index.IndexConstants.TRANSPORT_INDEX_EXT_ZIP;
|
||||
import static net.osmand.data.index.IndexConstants.BINARY_MAP_VERSION;
|
||||
import static net.osmand.data.index.IndexConstants.ADDRESS_TABLE_VERSION;
|
||||
import static net.osmand.data.index.IndexConstants.BINARY_MAP_INDEX_EXT;
|
||||
import static net.osmand.data.index.IndexConstants.BINARY_MAP_INDEX_EXT_ZIP;
|
||||
import static net.osmand.data.index.IndexConstants.VOICE_VERSION;
|
||||
import static net.osmand.data.index.IndexConstants.BINARY_MAP_VERSION;
|
||||
import static net.osmand.data.index.IndexConstants.POI_INDEX_EXT;
|
||||
import static net.osmand.data.index.IndexConstants.POI_INDEX_EXT_ZIP;
|
||||
import static net.osmand.data.index.IndexConstants.POI_TABLE_VERSION;
|
||||
import static net.osmand.data.index.IndexConstants.TRANSPORT_INDEX_EXT;
|
||||
import static net.osmand.data.index.IndexConstants.TRANSPORT_INDEX_EXT_ZIP;
|
||||
import static net.osmand.data.index.IndexConstants.TRANSPORT_TABLE_VERSION;
|
||||
import static net.osmand.data.index.IndexConstants.VOICE_INDEX_EXT_ZIP;
|
||||
import static net.osmand.data.index.IndexConstants.VOICE_VERSION;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -56,11 +56,14 @@ import android.os.Environment;
|
|||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
@ -69,6 +72,7 @@ import android.widget.Toast;
|
|||
public class DownloadIndexActivity extends ListActivity {
|
||||
|
||||
private final static Log log = LogUtil.getLog(DownloadIndexActivity.class);
|
||||
private static final int RELOAD_ID = 0;
|
||||
private static DownloadIndexListThread downloadListIndexThread = new DownloadIndexListThread();
|
||||
|
||||
private ProgressDialog progressFileDlg = null;
|
||||
|
@ -114,18 +118,41 @@ public class DownloadIndexActivity extends ListActivity {
|
|||
if(downloadListIndexThread.getCachedIndexFiles() != null){
|
||||
setListAdapter(new DownloadIndexAdapter(new ArrayList<Entry<String,String>>(downloadListIndexThread.getCachedIndexFiles().entrySet())));
|
||||
} else {
|
||||
progressListDlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_list_indexes));
|
||||
progressListDlg.setCancelable(true);
|
||||
downloadListIndexThread.uiActivity = this;
|
||||
if(downloadListIndexThread.getState() == Thread.State.NEW){
|
||||
downloadListIndexThread.start();
|
||||
} else if(downloadListIndexThread.getState() == Thread.State.TERMINATED){
|
||||
// possibly exception occurred we don't have cache of files
|
||||
downloadListIndexThread = new DownloadIndexListThread();
|
||||
downloadListIndexThread.uiActivity = this;
|
||||
}
|
||||
downloadIndexList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void downloadIndexList() {
|
||||
progressListDlg = ProgressDialog.show(this, getString(R.string.downloading), getString(R.string.downloading_list_indexes));
|
||||
progressListDlg.setCancelable(true);
|
||||
downloadListIndexThread.uiActivity = this;
|
||||
if(downloadListIndexThread.getState() == Thread.State.NEW){
|
||||
downloadListIndexThread.start();
|
||||
} else if(downloadListIndexThread.getState() == Thread.State.TERMINATED){
|
||||
// possibly exception occurred we don't have cache of files
|
||||
downloadListIndexThread = new DownloadIndexListThread();
|
||||
downloadListIndexThread.uiActivity = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
MenuItem item = menu.add(0, RELOAD_ID, 0, R.string.reload);
|
||||
item.setIcon(R.drawable.ic_menu_refresh);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if(item.getItemId() == RELOAD_ID){
|
||||
//re-create the thread
|
||||
downloadListIndexThread = new DownloadIndexListThread();
|
||||
downloadIndexList();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class DownloadIndexListThread extends Thread {
|
||||
|
@ -569,8 +596,14 @@ public class DownloadIndexActivity extends ListActivity {
|
|||
|
||||
protected class DownloadIndexAdapter extends ArrayAdapter<Entry<String, String>> implements Filterable {
|
||||
|
||||
List<Entry<String, String>> origArray;
|
||||
private List<Entry<String, String>> origReference;
|
||||
private DownloadIndexFilter myFilter;
|
||||
|
||||
public DownloadIndexAdapter(List<Entry<String, String>> array) {
|
||||
super(DownloadIndexActivity.this, net.osmand.R.layout.download_index_list_item, array);
|
||||
this.origArray = new ArrayList<Entry<String,String>>(array);
|
||||
this.origReference = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -615,6 +648,53 @@ public class DownloadIndexActivity extends ListActivity {
|
|||
description.setText(e.getValue().replace(':', '\n').trim());
|
||||
return row;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter getFilter() {
|
||||
if (myFilter == null) {
|
||||
myFilter = new DownloadIndexFilter();
|
||||
}
|
||||
return myFilter;
|
||||
}
|
||||
|
||||
private final class DownloadIndexFilter extends Filter {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
FilterResults results = new FilterResults();
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
results.values = origArray;
|
||||
results.count = origArray.size();
|
||||
} else {
|
||||
CharSequence lowerCase = constraint.toString()
|
||||
.toLowerCase();
|
||||
List<Entry<String, String>> filter = new ArrayList<Entry<String, String>>();
|
||||
for (Entry<String, String> item : origArray) {
|
||||
if (item.getKey().toLowerCase().contains(lowerCase)) {
|
||||
filter.add(item);
|
||||
}
|
||||
}
|
||||
results.values = filter;
|
||||
results.count = filter.size();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint,
|
||||
FilterResults results) {
|
||||
synchronized (origReference) {
|
||||
origReference.clear();
|
||||
origReference.addAll((List<Entry<String, String>>) results.values);
|
||||
}
|
||||
if (results.count > 0) {
|
||||
notifyDataSetChanged();
|
||||
} else {
|
||||
notifyDataSetInvalidated();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue