Improve poi search and other search
This commit is contained in:
parent
4131349ab2
commit
320d1d93de
9 changed files with 121 additions and 86 deletions
|
@ -4,8 +4,12 @@
|
|||
android:orientation="vertical" android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
|
||||
<Button android:text="@string/show_poi_on_map" android:id="@+id/ShowOnMap" android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>
|
||||
<Button android:text="@string/search_POI_level_btn" android:id="@+id/SearchPOILevelButton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"></Button>
|
||||
<ImageButton android:src="@android:drawable/ic_input_get" android:text="@string/show_poi_on_map" android:id="@+id/ShowFilter"
|
||||
android:layout_height="wrap_content" android:layout_width="wrap_content" />
|
||||
<ImageButton android:src="@android:drawable/ic_dialog_map"
|
||||
android:id="@+id/ShowOnMap" android:layout_height="wrap_content" android:layout_width="wrap_content"/>
|
||||
<Button android:text="@string/search_POI_level_btn"
|
||||
android:id="@+id/SearchPOILevelButton" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1"/>
|
||||
<TextView android:layout_width="wrap_content" android:text="" android:id="@+id/SearchAreaText" android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.PoiFilter;
|
||||
import net.osmand.plus.PoiFiltersHelper;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.search.SearchActivity;
|
||||
import net.osmand.plus.activities.search.SearchPOIActivity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
|
@ -47,8 +48,8 @@ public class EditPOIFilterActivity extends ListActivity {
|
|||
private Button filterLevel;
|
||||
private PoiFilter filter;
|
||||
private PoiFiltersHelper helper;
|
||||
public static final String SEARCH_LAT = "SEARCH_LAT"; //$NON-NLS-1$
|
||||
public static final String SEARCH_LON = "SEARCH_LON"; //$NON-NLS-1$
|
||||
public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; //$NON-NLS-1$
|
||||
public static final String SEARCH_LON = SearchActivity.SEARCH_LON; //$NON-NLS-1$
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -72,7 +72,7 @@ public class NavigatePointActivity extends Activity implements SearchActivityChi
|
|||
loc = new LatLon(lat, lon);
|
||||
}
|
||||
}
|
||||
if (loc == null) {
|
||||
if (loc == null && getParent() instanceof SearchActivity) {
|
||||
loc = ((SearchActivity) getParent()).getSearchPoint();
|
||||
}
|
||||
if (loc == null) {
|
||||
|
|
|
@ -49,6 +49,7 @@ public class SearchActivity extends TabActivity {
|
|||
Button searchPOIButton;
|
||||
private TabSpec addressSpec;
|
||||
private LatLon searchPoint = null;
|
||||
private boolean searchAroundCurrentLocation = false;
|
||||
|
||||
private static boolean searchOnLine = false;
|
||||
private LocationListener locationListener = null;
|
||||
|
@ -104,7 +105,9 @@ public class SearchActivity extends TabActivity {
|
|||
if (position != 0) {
|
||||
if (position == POSITION_CURRENT_LOCATION) {
|
||||
startSearchCurrentLocation();
|
||||
searchAroundCurrentLocation = true;
|
||||
} else {
|
||||
searchAroundCurrentLocation = false;
|
||||
endSearchCurrentLocation();
|
||||
if (position == POSITION_LAST_MAP_VIEW) {
|
||||
OsmandSettings settings = OsmandSettings.getOsmandSettings(SearchActivity.this);
|
||||
|
@ -207,6 +210,10 @@ public class SearchActivity extends TabActivity {
|
|||
return searchPoint;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSearchAroundCurrentLocation() {
|
||||
return searchAroundCurrentLocation;
|
||||
}
|
||||
|
||||
private Intent createIntent(Class<? extends Activity> cl){
|
||||
Intent intent = new Intent(this, cl);
|
||||
|
|
|
@ -25,7 +25,7 @@ import android.widget.RadioButton;
|
|||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SearchAddressActivity extends Activity {
|
||||
public class SearchAddressActivity extends Activity {
|
||||
|
||||
private Button showOnMap;
|
||||
private Button streetButton;
|
||||
|
|
|
@ -17,12 +17,14 @@ import net.osmand.osm.MapUtils;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
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;
|
||||
|
@ -36,7 +38,7 @@ import android.widget.ListView;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class SearchAddressOnlineActivity extends ListActivity {
|
||||
public class SearchAddressOnlineActivity extends ListActivity implements SearchActivityChild {
|
||||
|
||||
private LatLon location;
|
||||
private ProgressDialog progressDlg;
|
||||
|
@ -88,6 +90,33 @@ public class SearchAddressOnlineActivity extends ListActivity {
|
|||
setListAdapter(lastResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Intent intent = getIntent();
|
||||
if(intent != null){
|
||||
double lat = intent.getDoubleExtra(SearchActivity.SEARCH_LAT, 0);
|
||||
double lon = intent.getDoubleExtra(SearchActivity.SEARCH_LON, 0);
|
||||
if(lat != 0 || lon != 0){
|
||||
location = new LatLon(lat, lon);
|
||||
}
|
||||
}
|
||||
if (location == null && getParent() instanceof SearchActivity) {
|
||||
location = ((SearchActivity) getParent()).getSearchPoint();
|
||||
}
|
||||
if (location == null) {
|
||||
location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void locationUpdate(LatLon l) {
|
||||
location = l;
|
||||
if(lastResult != null){
|
||||
lastResult.notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
|
||||
protected void searchPlaces(final String search) {
|
||||
if(Algoritms.isEmpty(search)){
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.osmand.osm.MapUtils;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
||||
import net.osmand.plus.activities.search.SearchHistoryHelper.HistoryEntry;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ListActivity;
|
||||
|
@ -25,7 +26,7 @@ import android.widget.ImageButton;
|
|||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SearchHistoryActivity extends ListActivity {
|
||||
public class SearchHistoryActivity extends ListActivity implements SearchActivityChild {
|
||||
private LatLon location;
|
||||
private SearchHistoryHelper helper;
|
||||
private Button clearButton;
|
||||
|
@ -39,17 +40,7 @@ public class SearchHistoryActivity extends ListActivity {
|
|||
lv.setId(android.R.id.list);
|
||||
|
||||
setContentView(lv);
|
||||
Intent intent = getIntent();
|
||||
if(intent != null){
|
||||
float lat = intent.getFloatExtra(SEARCH_LAT, 0);
|
||||
float lon = intent.getFloatExtra(SEARCH_LON, 0);
|
||||
if(lat != 0 || lon != 0){
|
||||
location = new LatLon(lat, lon);
|
||||
}
|
||||
}
|
||||
if (location == null) {
|
||||
location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation();
|
||||
}
|
||||
|
||||
helper = SearchHistoryHelper.getInstance();
|
||||
|
||||
|
||||
|
@ -73,6 +64,21 @@ public class SearchHistoryActivity extends ListActivity {
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
Intent intent = getIntent();
|
||||
if(intent != null){
|
||||
double lat = intent.getDoubleExtra(SEARCH_LAT, 0);
|
||||
double lon = intent.getDoubleExtra(SEARCH_LON, 0);
|
||||
if(lat != 0 || lon != 0){
|
||||
location = new LatLon(lat, lon);
|
||||
}
|
||||
}
|
||||
if(location == null && getParent() instanceof SearchActivity){
|
||||
location = ((SearchActivity) getParent()).getSearchPoint();
|
||||
}
|
||||
if (location == null) {
|
||||
location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation();
|
||||
}
|
||||
|
||||
List<HistoryEntry> historyEntries = helper.getHistoryEntries(this);
|
||||
|
||||
getListView().removeFooterView(clearButton);
|
||||
|
@ -82,6 +88,12 @@ public class SearchHistoryActivity extends ListActivity {
|
|||
setListAdapter(new HistoryAdapter(historyEntries));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void locationUpdate(LatLon l) {
|
||||
location = l;
|
||||
((HistoryAdapter) getListAdapter()).notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private boolean onItemLongClick(int pos) {
|
||||
final HistoryEntry entry = ((HistoryAdapter) getListAdapter()).getItem(pos);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(SearchHistoryActivity.this);
|
||||
|
|
|
@ -58,6 +58,7 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Filter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
@ -79,7 +80,8 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
|
|||
|
||||
|
||||
private Button searchPOILevel;
|
||||
private Button showOnMap;
|
||||
private ImageButton showOnMap;
|
||||
private ImageButton showFilter;
|
||||
private PoiFilter filter;
|
||||
private AmenityAdapter amenityAdapter;
|
||||
private TextView searchArea;
|
||||
|
@ -112,7 +114,8 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
|
|||
searchArea = (TextView) findViewById(R.id.SearchAreaText);
|
||||
searchFilter = (EditText) findViewById(R.id.SearchFilter);
|
||||
searchFilterLayout = findViewById(R.id.SearchFilterLayout);
|
||||
showOnMap = (Button) findViewById(R.id.ShowOnMap);
|
||||
showOnMap = (ImageButton) findViewById(R.id.ShowOnMap);
|
||||
showFilter = (ImageButton) findViewById(R.id.ShowFilter);
|
||||
|
||||
settings = OsmandSettings.getOsmandSettings(this);
|
||||
|
||||
|
@ -141,6 +144,19 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
|
|||
|
||||
}
|
||||
});
|
||||
showFilter.setVisibility(isNameFinderFilter() ? View.GONE : View.VISIBLE);
|
||||
showFilter.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (searchFilterLayout.getVisibility() == View.GONE) {
|
||||
searchFilterLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
searchFilter.setText(""); //$NON-NLS-1$
|
||||
searchFilterLayout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(isNameFinderFilter()){
|
||||
searchFilterLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -297,30 +313,6 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen
|
|||
return filter instanceof NameFinderPoiFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
boolean m = super.onCreateOptionsMenu(menu);
|
||||
if (!isNameFinderFilter()) {
|
||||
final MenuItem me = menu.add(R.string.show_poi_filter);
|
||||
me.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
if (searchFilterLayout.getVisibility() == View.GONE) {
|
||||
searchFilterLayout.setVisibility(View.VISIBLE);
|
||||
me.setTitle(R.string.hide_poi_filter);
|
||||
} else {
|
||||
searchFilter.setText(""); //$NON-NLS-1$
|
||||
searchFilterLayout.setVisibility(View.GONE);
|
||||
me.setTitle(R.string.show_poi_filter);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
// Working with location listeners
|
||||
private LocationListener networkListener = new LocationListener(){
|
||||
|
|
|
@ -39,9 +39,6 @@ public class SearchPoiFilterActivity extends ListActivity {
|
|||
public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT;
|
||||
public static final String SEARCH_LON = SearchActivity.SEARCH_LON;
|
||||
|
||||
private boolean searchNearBy = true;
|
||||
private double latitude = 0;
|
||||
private double longitude = 0;
|
||||
|
||||
|
||||
|
||||
|
@ -49,17 +46,6 @@ public class SearchPoiFilterActivity extends ListActivity {
|
|||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
setContentView(R.layout.searchpoilist);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if(extras != null && extras.containsKey(SEARCH_LAT) && extras.containsKey(SEARCH_LON)){
|
||||
searchNearBy = false;
|
||||
latitude = extras.getDouble(SEARCH_LAT);
|
||||
longitude = extras.getDouble(SEARCH_LON);
|
||||
} else {
|
||||
LatLon loc = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation();
|
||||
latitude = loc.getLatitude();
|
||||
longitude = loc.getLongitude();
|
||||
}
|
||||
|
||||
typeFace = Typeface.create((String)null, Typeface.ITALIC);
|
||||
|
||||
// ListActivity has a ListView, which you can get with:
|
||||
|
@ -84,49 +70,53 @@ public class SearchPoiFilterActivity extends ListActivity {
|
|||
filters.add(poiFilters.getNameFinderPOIFilter());
|
||||
setListAdapter(new AmenityAdapter(filters));
|
||||
}
|
||||
|
||||
|
||||
private void updateIntentToLaunch(Intent intentToLaunch){
|
||||
LatLon loc = null;
|
||||
boolean searchAround = false;
|
||||
Intent intent = getIntent();
|
||||
if(intent != null){
|
||||
double lat = intent.getDoubleExtra(SEARCH_LAT, 0);
|
||||
double lon = intent.getDoubleExtra(SEARCH_LON, 0);
|
||||
if(lat != 0 || lon != 0){
|
||||
loc = new LatLon(lat, lon);
|
||||
}
|
||||
}
|
||||
|
||||
if (loc == null && getParent() instanceof SearchActivity) {
|
||||
loc = ((SearchActivity) getParent()).getSearchPoint();
|
||||
searchAround = ((SearchActivity) getParent()).isSearchAroundCurrentLocation();
|
||||
}
|
||||
if (loc == null && !searchAround) {
|
||||
loc = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation();
|
||||
}
|
||||
if(loc != null && !searchAround) {
|
||||
intentToLaunch.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude());
|
||||
intentToLaunch.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude());
|
||||
}
|
||||
}
|
||||
|
||||
private void showEditActivity(PoiFilter poi) {
|
||||
if(!poi.isStandardFilter()) {
|
||||
Intent newIntent = new Intent(SearchPoiFilterActivity.this, EditPOIFilterActivity.class);
|
||||
// folder selected
|
||||
newIntent.putExtra(EditPOIFilterActivity.AMENITY_FILTER, poi.getFilterId());
|
||||
if(!searchNearBy){
|
||||
newIntent.putExtra(EditPOIFilterActivity.SEARCH_LAT, latitude);
|
||||
newIntent.putExtra(EditPOIFilterActivity.SEARCH_LON, longitude);
|
||||
}
|
||||
updateIntentToLaunch(newIntent);
|
||||
startActivityForResult(newIntent, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void onListItemClick(ListView parent, View v, int position, long id) {
|
||||
final PoiFilter filter = ((AmenityAdapter) getListAdapter()).getItem(position);
|
||||
if(filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)){
|
||||
if (filter.getFilterId().equals(PoiFilter.CUSTOM_FILTER_ID)) {
|
||||
showEditActivity(filter);
|
||||
return;
|
||||
}
|
||||
final Intent newIntent = new Intent(SearchPoiFilterActivity.this, SearchPOIActivity.class);
|
||||
newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
|
||||
if (searchNearBy) {
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(this);
|
||||
b.setItems(new String[] { getString(R.string.search_nearby), getString(R.string.search_near_map) },
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == 1) {
|
||||
newIntent.putExtra(SearchPOIActivity.SEARCH_LAT, latitude);
|
||||
newIntent.putExtra(SearchPOIActivity.SEARCH_LON, longitude);
|
||||
}
|
||||
startActivityForResult(newIntent, 0);
|
||||
}
|
||||
});
|
||||
b.show();
|
||||
} else {
|
||||
newIntent.putExtra(SearchPOIActivity.SEARCH_LAT, latitude);
|
||||
newIntent.putExtra(SearchPOIActivity.SEARCH_LON, longitude);
|
||||
startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
updateIntentToLaunch(newIntent);
|
||||
startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue