add incremental search

git-svn-id: https://osmand.googlecode.com/svn/trunk@110 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
frolovmo 2010-06-01 18:40:10 +00:00
parent d49648d39c
commit fdcb7efefd
5 changed files with 36 additions and 24 deletions

View file

@ -3,7 +3,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/search_POI_level_btn" android:id="@+id/SearchPOILevelButton"></Button>
<Button android:layout_gravity="right" android:text="@string/search_POI_level_btn" android:id="@+id/SearchPOILevelButton" android:layout_height="wrap_content" android:layout_width="fill_parent"></Button>
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent"></ListView>

View file

@ -139,6 +139,7 @@ public class MainMenuActivity extends Activity {
public void onClick(View v) {
mNotificationManager.cancel(APP_NOTIFICATION_ID);
MainMenuActivity.this.finish();
System.exit(0);
}
});

View file

@ -157,9 +157,9 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
Intent newIntent = new Intent(MapActivity.this, MainMenuActivity.class);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(newIntent);
// Intent newIntent = new Intent(MapActivity.this, MainMenuActivity.class);
// newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(newIntent);
return true;
}
return super.onKeyDown(keyCode, event);

View file

@ -44,20 +44,31 @@ public class SearchPOIActivity extends ListActivity {
private Button searchPOILevel;
private int zoom = 12;
private int maxCount = 500;
private int maxCount = 100;
private AmenityType amenityType;
private AmenityAdapter amenityAdapter;
private LatLon lastKnownMapLocation;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.searchpoi);
searchPOILevel = (Button) findViewById(R.id.SearchPOILevelButton);
searchPOILevel = (Button) findViewById(R.id.SearchPOILevelButton);
searchPOILevel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ResourceManager resourceManager = ResourceManager.getResourceManager();
if ( zoom > 7) {
--zoom;
}
amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), lastKnownMapLocation
.getLongitude(), zoom, -1);
if (amenityList != null) {
amenityAdapter.setNewModel(amenityList);
}
}
});
@ -65,23 +76,22 @@ public class SearchPOIActivity extends ListActivity {
String anemity = bundle.getString(ANENITY_TYPE);
if (anemity != null) {
ResourceManager resourceManager = ResourceManager.getResourceManager();
LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this);
lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this);
amenityType = findAmenityType(anemity);
amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(),
lastKnownMapLocation.getLongitude(), zoom, maxCount);
if(amenityList != null) {
amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), lastKnownMapLocation
.getLongitude(), zoom, maxCount);
if (amenityList != null) {
amenityAdapter = new AmenityAdapter(amenityList);
setListAdapter(amenityAdapter);
}
}
}
}
public void onListItemClick(ListView parent, View v, int position, long id) {
SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE);
if(prefs != null ){
if (prefs != null) {
Amenity amenity = amenityList.get(position);
OsmandSettings.setLastKnownMapLocation(this,amenity.getLocation().getLatitude(),amenity.getLocation().getLongitude());
OsmandSettings.setLastKnownMapLocation(this, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude());
Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class);
startActivity(newIntent);
}
@ -101,15 +111,17 @@ public class SearchPOIActivity extends ListActivity {
class AmenityAdapter extends ArrayAdapter {
AmenityAdapter(Object list) {
super(SearchPOIActivity.this, R.layout.searchpoi_list, (List<?>) list);
this.setNotifyOnChange(false);
}
@Override
public int getCount() {
int c = super.getCount();
return c > 20 ? 20 : c;
public void setNewModel(List<?> amenityList) {
((AmenityAdapter) getListAdapter()).clear();
for(Object obj: amenityList){
this.add(obj);
}
this.notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
@ -130,12 +142,12 @@ public class SearchPOIActivity extends ListActivity {
String str = anemity.getStringWithoutType();
label.setText(str);
icon.setImageResource(R.drawable.poi);
distanceLabel.setText(" " +dist + " m ");
distanceLabel.setText(" " + dist + " m ");
}
}
return (row);
}
private Object getModel(int position) {
return (((AmenityAdapter) getListAdapter()).getItem(position));
}

View file

@ -54,7 +54,6 @@ public class SearchPOIListActivity extends ListActivity {
bundle.putString(SearchPOIActivity.ANENITY_TYPE, amenityList.get(position));
Intent newIntent = new Intent(SearchPOIListActivity.this, SearchPOIActivity.class);
newIntent.putExtras(bundle);
newIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivityForResult(newIntent, 0);
}
}