add incremental search
git-svn-id: https://osmand.googlecode.com/svn/trunk@110 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
d49648d39c
commit
fdcb7efefd
5 changed files with 36 additions and 24 deletions
|
@ -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>
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -44,12 +44,14 @@ 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);
|
||||
|
@ -58,6 +60,15 @@ public class SearchPOIActivity extends ListActivity {
|
|||
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,10 +76,10 @@ 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);
|
||||
amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), lastKnownMapLocation
|
||||
.getLongitude(), zoom, maxCount);
|
||||
if (amenityList != null) {
|
||||
amenityAdapter = new AmenityAdapter(amenityList);
|
||||
setListAdapter(amenityAdapter);
|
||||
|
@ -76,7 +87,6 @@ public class SearchPOIActivity extends ListActivity {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void onListItemClick(ListView parent, View v, int position, long id) {
|
||||
SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE);
|
||||
if (prefs != null) {
|
||||
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue