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 !!)
This commit is contained in:
fanfan 2011-07-12 13:35:41 +02:00
parent a4374d7eb9
commit 2cd82950b5
4 changed files with 46 additions and 7 deletions

View file

@ -15,7 +15,8 @@
<LinearLayout android:id="@+id/LinearLayout" android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop = "5dp" android:gravity="left|bottom">
<Button android:text="@string/search_offline_address" android:id="@+id/SearchOffline" android:minWidth="120dp" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="@string/search_offline_address" android:id="@+id/SearchOffline" android:minWidth="120dp" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
<Button android:text="@string/search_offline_clear_search" android:id="@+id/ClearSearch" android:minWidth="150dp" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
</LinearLayout>

View file

@ -417,6 +417,7 @@
<string name="search_osm_nominatim">Search address using OSM Nominatim</string>
<string name="hint_search_online">House number, street, city</string>
<string name="search_offline_address">Offline</string>
<string name="search_offline_clear_search">Clear Search</string>
<string name="search_online_address">Internet</string>
<string name="max_level_download_tile">Max. online zoom</string>
<string name="max_level_download_tile_descr">Choose maximum zoom level to download for online map tiles</string>

View file

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

View file

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