From bd4c191a23334267057508cc48a84eb2b5a67489 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 1 Jun 2010 09:10:26 +0000 Subject: [PATCH] Finalizing search functionality git-svn-id: https://osmand.googlecode.com/svn/trunk@108 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 22 +++--- OsmAnd/res/layout/search_address.xml | 19 +++-- .../search/SearchAddressActivity.java | 2 +- .../search/SearchByNameAbstractActivity.java | 71 +++++++++++++++++-- 4 files changed, 93 insertions(+), 21 deletions(-) diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 165f65417b..0adc40cd02 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -16,25 +16,21 @@ public class ToDoConstants { // TODO ANDROID // 25. POI search near to map location (show categories & type). Second cut. (implement incremental search) - -// 3. Revise osmand UI. Preparing new icons (revise UI 18, 2, ). Main application icon, back to location icon. // 13. Save point as favorite & introduce favorite points dialog + +// 3. Revise osmand UI. Preparing new icons (revise UI 18, 2, ). Main application icon, back to location icon. // 14. Show zoom level on map // 24. Implement ResourceManager, load cities/streets/buildings on Low memory (clear previous all addresses cities). -// 5. Search for city/streets/buildings - + +// 25. Show opened/closed amenities. +// 27. Search intersection of streets. +// 26. Show the whole street on map (when it is chosen in search activity). Possibly extend that story to show layer with streets. + // 8. Enable change POI directly on map (requires OSM login) // 16. Support open street bugs api. // 20. Implement save track/route to gpx (?) -// 24. Show the whole street on map (when it is chosen in search activity). Possibly extend that story to show layer with streets. -// 25. Show opened/closed amenities. - - // TODO search story : - // 2) Find intersection of streets - // 9) Loading cities (data) in another thread - // 10) fix bug with landscape layout (search address) - + // FIXME Bugs Android : // 1. When firstly run osmand navigation (from notification bar) show map & go to menu shows desktop. @@ -44,6 +40,7 @@ public class ToDoConstants { // Call ResourceManager.close when it is needed. // 8. Introduce activity search by location (unify with existing dialog) // 9. When all features will be ready we can remove show location from context menu + // 10. Notification is gone after clear all notifications // Performance improvements Android : // 1. Introducing one place where refreshMap will be called using postMessage mechanism (delay more than > 50 ? ms) @@ -60,6 +57,7 @@ public class ToDoConstants { // DONE ANDROID : +// 5. Search for city/streets/buildings // 15. Investigate interruption of any long running operation & implement where it is needed. // ProgressDialogImplementation should support setOnCancelListener or obtain CANCEL message & // throw InterruptedException in all methods (remaining, progress, startTask, ...) when call it. diff --git a/OsmAnd/res/layout/search_address.xml b/OsmAnd/res/layout/search_address.xml index 7143dc160a..00d2396ef1 100644 --- a/OsmAnd/res/layout/search_address.xml +++ b/OsmAnd/res/layout/search_address.xml @@ -42,12 +42,23 @@ - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java index c25521eeaf..8168d10ec9 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchAddressActivity.java @@ -188,7 +188,7 @@ public class SearchAddressActivity extends Activity { region = ResourceManager.getResourceManager().getRegionRepository(lastSearchedRegion); String progressMsg = null; // try to determine whether progress dialog & new thread needed - if(region.areCitiesPreloaded()){ + if(!region.areCitiesPreloaded()){ progressMsg = "Loading cities..."; } else if(city == null || city.getId() != OsmandSettings.getLastSearchedCity(this)){ progressMsg = "Loading streets/buildings..."; diff --git a/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java index dc2a89d823..64d60af6e6 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchByNameAbstractActivity.java @@ -4,6 +4,9 @@ import java.util.List; import android.app.ListActivity; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; @@ -20,6 +23,7 @@ import com.osmand.R; public abstract class SearchByNameAbstractActivity extends ListActivity { private EditText searchText; + private Handler handlerToLoop; @Override protected void onCreate(Bundle savedInstanceState) { @@ -56,11 +60,36 @@ public abstract class SearchByNameAbstractActivity extends ListActivity { public Editable getFilter(){ return searchText.getText(); } - public void setText(String filter){ - ((NamesAdapter)getListAdapter()).clear(); - for(T o : getObjects(filter)){ - ((NamesAdapter)getListAdapter()).add(o); + + protected void updateUIList(final List objects){ + runOnUiThread(new Runnable(){ + @Override + public void run() { + for(T o : objects){ + ((NamesAdapter)getListAdapter()).add(o); + } + } + }); + } + + public void setText(final String filter) { + ((NamesAdapter) getListAdapter()).clear(); + + if(handlerToLoop == null){ + return; } + handlerToLoop.removeMessages(1); + Message msg = Message.obtain(handlerToLoop, new Runnable() { + @Override + public void run() { + List loadedObjects = getObjects(filter); + if(!handlerToLoop.hasMessages(1)){ + updateUIList(loadedObjects); + } + } + }); + msg.what = 1; + handlerToLoop.sendMessageDelayed(msg, 150); } public abstract List getObjects(String filter); @@ -76,6 +105,40 @@ public abstract class SearchByNameAbstractActivity extends ListActivity { itemSelected(repo); } + @Override + protected void onResume() { + synchronized (this) { + if (handlerToLoop == null) { + new Thread("Filter data") { + @Override + public void run() { + Looper.prepare(); + handlerToLoop = new Handler(); + Looper.loop(); + } + }.start(); + } + + } + super.onResume(); + } + + @Override + protected void onPause() { + super.onPause(); + synchronized (this) { + if(handlerToLoop != null){ + handlerToLoop.post(new Runnable(){ + @Override + public void run() { + Looper.myLooper().quit(); + } + }); + handlerToLoop = null; + } + } + } + class NamesAdapter extends ArrayAdapter { NamesAdapter(List list) {