From 2cd82950b5d3319334e25c9018a9027cf2fb4fc9 Mon Sep 17 00:00:00 2001 From: fanfan Date: Tue, 12 Jul 2011 13:35:41 +0200 Subject: [PATCH] Improve search online UI : - When search is pressed, the hide the virtual keyboard - Cache last search, so that if you go back again or switch the phone, it still display the result (Desire Z, other device with keyboard) - Add a button to clear search (!! Add a new text properties !!) --- OsmAnd/res/layout/search_address_online.xml | 3 +- OsmAnd/res/values/strings.xml | 1 + .../activities/search/SearchActivity.java | 21 ++++++++++++-- .../search/SearchAddressOnlineActivity.java | 28 +++++++++++++++++-- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/OsmAnd/res/layout/search_address_online.xml b/OsmAnd/res/layout/search_address_online.xml index 632b546bcf..aad63bae2c 100644 --- a/OsmAnd/res/layout/search_address_online.xml +++ b/OsmAnd/res/layout/search_address_online.xml @@ -15,7 +15,8 @@ - + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0c0bc8afe6..884dc103f6 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -417,6 +417,7 @@ Search address using OSM Nominatim House number, street, city Offline + Clear Search Internet Max. online zoom Choose maximum zoom level to download for online map tiles diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java index 4f084b4421..878ec2e8a6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java @@ -22,12 +22,17 @@ public class SearchActivity extends TabActivity { Button searchPOIButton; private TabSpec addressSpec; + private static boolean searchOnLine = false; + @Override protected void onCreate(Bundle savedInstanceState) { 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$ - addressSpec = host.newTabSpec("Search_Address").setIndicator(getString(R.string.address)).setContent(new Intent(this, SearchAddressActivity.class));//$NON-NLS-1$ + + addressSpec = host.newTabSpec("Search_Address").setIndicator(getString(R.string.address)); + setAddressSpecContent(); + host.addTab(addressSpec); host.addTab(host.newTabSpec("Search_Location").setIndicator(getString(R.string.search_tabs_location)).setContent(new Intent(this, NavigatePointActivity.class))); //$NON-NLS-1$ // host.addTab(host.newTabSpec("Search_Transport").setIndicator(getString(R.string.transport)).setContent(new Intent(this, SearchTransportActivity.class))); //$NON-NLS-1$ @@ -35,15 +40,25 @@ public class SearchActivity extends TabActivity { } public void startSearchAddressOffline(){ + searchOnLine = false; getTabHost().setCurrentTab(0); - addressSpec.setContent(new Intent(this, SearchAddressActivity.class)); + setAddressSpecContent(); getTabHost().setCurrentTab(1); } public void startSearchAddressOnline(){ + searchOnLine = true; getTabHost().setCurrentTab(0); - addressSpec.setContent(new Intent(this, SearchAddressOnlineActivity.class)); + setAddressSpecContent(); getTabHost().setCurrentTab(1); } + + public void setAddressSpecContent() { + if (searchOnLine) { + addressSpec.setContent(new Intent(this, SearchAddressOnlineActivity.class)); + } else { + addressSpec.setContent(new Intent(this, SearchAddressActivity.class)); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java index bf12fb84ed..c719654f16 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressOnlineActivity.java @@ -23,12 +23,12 @@ import org.xmlpull.v1.XmlPullParser; import android.app.ListActivity; import android.app.ProgressDialog; -import android.content.Intent; import android.os.Bundle; import android.util.Xml; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; @@ -42,6 +42,8 @@ public class SearchAddressOnlineActivity extends ListActivity { private ProgressDialog progressDlg; private final static Log log = LogUtil.getLog(SearchAddressOnlineActivity.class); + private static PlacesAdapter lastResult = null; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -58,14 +60,33 @@ public class SearchAddressOnlineActivity extends ListActivity { searchOffline.setVisibility(View.INVISIBLE); } + final EditText searchText = (EditText) findViewById(R.id.SearchText); + + Button clearSearch = (Button) findViewById(R.id.ClearSearch); + clearSearch.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + searchText.setText(""); + lastResult = null; + setListAdapter(null); + } + }); + Button searchButton = (Button) findViewById(R.id.SearchButton); searchButton.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { - searchPlaces(((EditText) findViewById(R.id.SearchText)).getText().toString()); + InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); + inputMethodManager.hideSoftInputFromWindow(searchText.getWindowToken(), 0); // Remove keyboard + + searchPlaces(searchText.getText().toString()); } }); location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); + + if (lastResult != null) { + setListAdapter(lastResult); + } } protected void searchPlaces(final String search) { @@ -138,7 +159,8 @@ public class SearchAddressOnlineActivity extends ListActivity { if(places == null){ Toast.makeText(SearchAddressOnlineActivity.this, getString(warning), Toast.LENGTH_LONG).show(); } else { - setListAdapter(new PlacesAdapter(places)); + lastResult = new PlacesAdapter(places); + setListAdapter(lastResult); } } });