fix some search issues

git-svn-id: https://osmand.googlecode.com/svn/trunk@107 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-06-01 07:25:29 +00:00
parent 8c2ae5e8c2
commit 03b52f348f
11 changed files with 116 additions and 20 deletions

View file

@ -11,6 +11,9 @@ public class ToDoConstants {
*/
public int DESCRIBE_ABOUT_AUTHORS = 8;
// TODO team :
// 1. write letters (UI/strings)
// TODO ANDROID
// 25. POI search near to map location (show categories & type). Second cut. (implement incremental search)
@ -24,14 +27,13 @@ public class ToDoConstants {
// 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
// 3) Shows progress dialog (?)
// 6) Show street on map
// 8) Show message (that user should input more than 2 symbols to get all)
// 9) Loading cities in another thread
// 10. fix bug with landscape layout (search address)
// 9) Loading cities (data) in another thread
// 10) fix bug with landscape layout (search address)
// FIXME Bugs Android :
@ -53,6 +55,7 @@ public class ToDoConstants {
// 6. Implement renaming/deleting street/building/city
// 8. Implement basic transliteration version
// 7. Implement saving bundle of tiles in different folder
// 9. Using Collator in all TreeSet/TreeMap/Comparators
// 1. Download tiles without using dir tiles

View file

@ -3,6 +3,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<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">
<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:text="Reset" android:id="@+id/ResetButton" android:layout_width="wrap_content" android:layout_height="wrap_content"
@ -12,4 +14,5 @@
<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

@ -40,4 +40,8 @@
<color name="color_red">#FF0000</color>
<string name="searchpoi_activity">searchpoi_activity</string>
<string name="search_POI_level_btn">Find more</string>
<string name="incremental_search_city">Search city incrementally. In order to find villages input more than 3 first symbols.</string>
<string name="incremental_search_street">Search street incrementally</string>
<string name="incremental_search_building">Search building incrementally</string>
<string name="choose_available_region">Choose region</string>
</resources>

View file

@ -122,6 +122,7 @@ public class OsmandSettings {
public static final String LAST_SEARCHED_CITY = "last_searched_city";
public static final String LAST_SEARCHED_STREET = "last_searched_street";
public static final String LAST_SEARCHED_BUILDING = "last_searched_building";
public static final String LAST_SEARCHED_INTERSECTED_STREET = "last_searched_intersected_street";
public static String getLastSearchedRegion(Context ctx){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
@ -140,7 +141,9 @@ public class OsmandSettings {
public static boolean setLastSearchedCity(Context ctx, Long cityId){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.edit().putLong(LAST_SEARCHED_CITY, cityId).commit();
return prefs.edit().
putLong(LAST_SEARCHED_CITY, cityId).putString(LAST_SEARCHED_STREET, "").putString(LAST_SEARCHED_BUILDING, "").
commit();
}
public static String getLastSearchedStreet(Context ctx){
@ -150,7 +153,7 @@ public class OsmandSettings {
public static boolean setLastSearchedStreet(Context ctx, String street){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.edit().putString(LAST_SEARCHED_STREET, street).commit();
return prefs.edit().putString(LAST_SEARCHED_STREET, street).putString(LAST_SEARCHED_BUILDING, "").commit();
}
public static String getLastSearchedBuilding(Context ctx){
@ -160,7 +163,21 @@ public class OsmandSettings {
public static boolean setLastSearchedBuilding(Context ctx, String building){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.edit().putString(LAST_SEARCHED_BUILDING, building).commit();
return prefs.edit().putString(LAST_SEARCHED_BUILDING, building).remove(LAST_SEARCHED_INTERSECTED_STREET).commit();
}
public static String getLastSearchedIntersectedStreet(Context ctx){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
if(!prefs.contains(LAST_SEARCHED_INTERSECTED_STREET)){
return null;
}
return prefs.getString(LAST_SEARCHED_INTERSECTED_STREET, "");
}
public static boolean setLastSearchedIntersectedStreet(Context ctx, String street){
SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE);
return prefs.edit().putString(LAST_SEARCHED_INTERSECTED_STREET, street).commit();
}

View file

@ -58,6 +58,10 @@ public class RegionAddressRepository {
cityTypes.clear();
}
public boolean areCitiesPreloaded(){
return !cities.isEmpty();
}
public City getCityById(Long id){
if(id == -1){
// do not preload cities for that case

View file

@ -22,7 +22,7 @@ public class SearchActivity extends TabActivity {
super.onCreate(savedInstanceState);
TabHost host = getTabHost();
host.addTab(host.newTabSpec("Search_POI").setIndicator("Search POI").setContent(new Intent(this, SearchPOIListActivity.class)));
host.addTab(host.newTabSpec("Search_Adress").setIndicator("Search Address").setContent(new Intent(this, SearchAddressActivity.class)));
host.addTab(host.newTabSpec("Search_Address").setIndicator("Search Address").setContent(new Intent(this, SearchAddressActivity.class)));
}
}

View file

@ -2,6 +2,7 @@ package com.osmand.activities.search;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@ -30,6 +31,7 @@ public class SearchAddressActivity extends Activity {
private City city = null;
private Street street = null;
private Building building = null;
private ProgressDialog dlg;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -163,27 +165,76 @@ public class SearchAddressActivity extends Activity {
showOnMap.setEnabled(building != null || city != null || street != null);
}
@Override
protected void onResume() {
super.onResume();
region = null;
city = null;
street = null;
building = null;
String lastSearchedRegion = OsmandSettings.getLastSearchedRegion(this);
region = ResourceManager.getResourceManager().getRegionRepository(lastSearchedRegion);
if(region != null){
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
if(city != null){
street = region.getStreetByName(city, OsmandSettings.getLastSearchedStreet(this));
if(street != null){
building = region.getBuildingByName(street, OsmandSettings.getLastSearchedBuilding(this));
public void loadData(){
if (region != null) {
city = region.getCityById(OsmandSettings.getLastSearchedCity(SearchAddressActivity.this));
if (city != null) {
street = region.getStreetByName(city, OsmandSettings.getLastSearchedStreet(SearchAddressActivity.this));
if (street != null) {
building = region.getBuildingByName(street, OsmandSettings
.getLastSearchedBuilding(SearchAddressActivity.this));
}
}
}
}
@Override
protected void onResume() {
super.onResume();
region = null;
String lastSearchedRegion = OsmandSettings.getLastSearchedRegion(SearchAddressActivity.this);
region = ResourceManager.getResourceManager().getRegionRepository(lastSearchedRegion);
String progressMsg = null;
// try to determine whether progress dialog & new thread needed
if(region.areCitiesPreloaded()){
progressMsg = "Loading cities...";
} else if(city == null || city.getId() != OsmandSettings.getLastSearchedCity(this)){
progressMsg = "Loading streets/buildings...";
}
city = null;
street = null;
building = null;
if (progressMsg != null) {
dlg = ProgressDialog.show(this, "Loading", progressMsg, true);
new Thread("Loader search data") {
@Override
public void run() {
try {
loadData();
} finally {
dlg.dismiss();
runOnUiThread(new Runnable() {
@Override
public void run() {
updateUI();
}
});
}
}
}.start();
} else {
loadData();
updateUI();
}
}
@Override
protected void onPause() {
if(building == null && OsmandSettings.getLastSearchedBuilding(this).length() > 0){
OsmandSettings.setLastSearchedBuilding(this, "");
}
if(street == null && OsmandSettings.getLastSearchedStreet(this).length() > 0){
OsmandSettings.setLastSearchedStreet(this, "");
}
if(city == null && OsmandSettings.getLastSearchedCity(this) != -1){
OsmandSettings.setLastSearchedCity(this, -1l);
}
super.onPause();
}
}

View file

@ -7,6 +7,7 @@ import android.os.Bundle;
import android.widget.TextView;
import com.osmand.OsmandSettings;
import com.osmand.R;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.Building;
@ -27,6 +28,7 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
}
}
super.onCreate(savedInstanceState);
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_building);
}
@Override

View file

@ -7,6 +7,7 @@ import android.os.Bundle;
import android.widget.TextView;
import com.osmand.OsmandSettings;
import com.osmand.R;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.City;
@ -22,6 +23,7 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
region = ResourceManager.getResourceManager().getRegionRepository(OsmandSettings.getLastSearchedRegion(this));
location = OsmandSettings.getLastKnownMapLocation(this);
super.onCreate(savedInstanceState);
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_city);
}
@Override

View file

@ -3,14 +3,22 @@ package com.osmand.activities.search;
import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.widget.TextView;
import com.osmand.OsmandSettings;
import com.osmand.R;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<RegionAddressRepository> {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((TextView)findViewById(R.id.Label)).setText(R.string.choose_available_region);
}
@Override
public List<RegionAddressRepository> getObjects(String filter) {
return new ArrayList<RegionAddressRepository>(ResourceManager.getResourceManager().getAddressRepositories());

View file

@ -7,6 +7,7 @@ import android.os.Bundle;
import android.widget.TextView;
import com.osmand.OsmandSettings;
import com.osmand.R;
import com.osmand.RegionAddressRepository;
import com.osmand.ResourceManager;
import com.osmand.data.City;
@ -22,6 +23,7 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
city = region.getCityById(OsmandSettings.getLastSearchedCity(this));
}
super.onCreate(savedInstanceState);
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_street);
}
@Override