From d49648d39c9792fc5cc3fa7d022766df7c86095a Mon Sep 17 00:00:00 2001 From: frolovmo Date: Tue, 1 Jun 2010 14:44:58 +0000 Subject: [PATCH] improve history stack git-svn-id: https://osmand.googlecode.com/svn/trunk@109 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- OsmAnd/res/layout/searchpoi_list.xml | 2 +- .../com/osmand/AmenityIndexRepository.java | 2 +- OsmAnd/src/com/osmand/ResourceManager.java | 16 +++++----- .../osmand/activities/MainMenuActivity.java | 11 +++++++ .../com/osmand/activities/MapActivity.java | 20 +++++++++++-- .../activities/search/SearchPOIActivity.java | 29 ++++--------------- .../search/SearchPOIListActivity.java | 6 ++-- 7 files changed, 47 insertions(+), 39 deletions(-) diff --git a/OsmAnd/res/layout/searchpoi_list.xml b/OsmAnd/res/layout/searchpoi_list.xml index 67f3dd7bc7..0d6f4d3504 100644 --- a/OsmAnd/res/layout/searchpoi_list.xml +++ b/OsmAnd/res/layout/searchpoi_list.xml @@ -9,7 +9,7 @@ + android:textSize="25px" android:maxWidth="100px" android:minWidth="100px"/> diff --git a/OsmAnd/src/com/osmand/AmenityIndexRepository.java b/OsmAnd/src/com/osmand/AmenityIndexRepository.java index 4dc6d62d6b..9fc1c2a69a 100644 --- a/OsmAnd/src/com/osmand/AmenityIndexRepository.java +++ b/OsmAnd/src/com/osmand/AmenityIndexRepository.java @@ -42,7 +42,7 @@ public class AmenityIndexRepository { long now = System.currentTimeMillis(); String squery = "? < latitude AND latitude < ? AND ? < longitude AND longitude < ?"; if(type != null){ - squery += " AND type = " + AmenityType.valueToString(type); + squery += " AND type = " + "'" +AmenityType.valueToString(type)+ "'"; } Cursor query = db.query(IndexPoiTable.getTable(), columns, squery, new String[]{Double.toString(bottomLatitude), diff --git a/OsmAnd/src/com/osmand/ResourceManager.java b/OsmAnd/src/com/osmand/ResourceManager.java index bb9b30ec17..e53c5ed15e 100644 --- a/OsmAnd/src/com/osmand/ResourceManager.java +++ b/OsmAnd/src/com/osmand/ResourceManager.java @@ -16,6 +16,7 @@ import android.graphics.BitmapFactory; import android.os.Environment; import com.osmand.data.Amenity; +import com.osmand.data.Amenity.AmenityType; import com.osmand.data.index.IndexConstants; import com.osmand.data.preparation.MapTileDownloader; import com.osmand.data.preparation.MapTileDownloader.DownloadRequest; @@ -182,8 +183,9 @@ public class ResourceManager { } } - ////////////////////////////////////////////// Working with amenities //////////////////////////////////////////////// - public List searchAmenities(double latitude, double longitude, int zoom, int limit) { + // //////////////////////////////////////////// Working with amenities + // //////////////////////////////////////////////// + public List searchAmenities(AmenityType type, double latitude, double longitude, int zoom, int limit) { double tileNumberX = Math.floor(MapUtils.getTileNumberX(zoom, longitude)); double tileNumberY = Math.floor(MapUtils.getTileNumberY(zoom, latitude)); double topLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY); @@ -191,14 +193,14 @@ public class ResourceManager { double leftLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX); double rightLongitude = MapUtils.getLongitudeFromTile(zoom, tileNumberX + 1); List amenities = new ArrayList(); - for(AmenityIndexRepository index : amenityRepositories){ - if(index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)){ - if(!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, amenities)){ - index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, null, amenities); + for (AmenityIndexRepository index : amenityRepositories) { + if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) { + if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, amenities)) { + index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, type, amenities); } } } - + return amenities; } diff --git a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java index 8fe50658a6..2ffa0dbe9c 100644 --- a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java +++ b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java @@ -19,6 +19,7 @@ import android.os.Bundle; import android.os.Environment; import android.text.format.DateFormat; import android.util.Log; +import android.view.KeyEvent; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; @@ -144,6 +145,16 @@ public class MainMenuActivity extends Activity { startApplication(); } + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_SEARCH + && event.getRepeatCount() == 0) { + final Intent search = new Intent(MainMenuActivity.this, SearchActivity.class); + startActivity(search); + return true; + } + return super.onKeyDown(keyCode, event); + } private class DefaultExceptionHandler implements UncaughtExceptionHandler { diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 1047825926..8a20fe12f2 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -19,6 +19,7 @@ import android.os.Message; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.util.Log; +import android.view.KeyEvent; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -144,13 +145,26 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat backToMenu.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - Intent intent = new Intent(); - setResult(RESULT_OK, intent); - finish(); + Intent newIntent = new Intent(MapActivity.this, MainMenuActivity.class); + newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(newIntent); } }); } + + @Override + 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); + return true; + } + return super.onKeyDown(keyCode, event); + } + @Override protected void onDestroy() { super.onDestroy(); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java index 42d6d53de5..a842aeec1f 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java @@ -3,10 +3,8 @@ */ package com.osmand.activities.search; -import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.TreeMap; import android.app.ListActivity; import android.content.Intent; @@ -46,6 +44,7 @@ public class SearchPOIActivity extends ListActivity { private Button searchPOILevel; private int zoom = 12; + private int maxCount = 500; private AmenityType amenityType; @@ -65,9 +64,11 @@ public class SearchPOIActivity extends ListActivity { Bundle bundle = this.getIntent().getExtras(); String anemity = bundle.getString(ANENITY_TYPE); if (anemity != null) { + ResourceManager resourceManager = ResourceManager.getResourceManager(); + LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this); amenityType = findAmenityType(anemity); - createAmenityFilter(zoom); - amenityList = filter.get(amenityType); + amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(), + lastKnownMapLocation.getLongitude(), zoom, maxCount); if(amenityList != null) { amenityAdapter = new AmenityAdapter(amenityList); setListAdapter(amenityAdapter); @@ -76,30 +77,12 @@ public class SearchPOIActivity extends ListActivity { } - - private void createAmenityFilter(int zoom) { - ResourceManager resourceManager = ResourceManager.getResourceManager(); - filter = new TreeMap>(); - LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this); - List closestAmenities = resourceManager.searchAmenities(lastKnownMapLocation.getLatitude(), - lastKnownMapLocation.getLongitude(), zoom, 500); - MapUtils.sortListOfMapObject(closestAmenities, lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()); - for (Amenity n : closestAmenities) { - AmenityType type = n.getType(); - if (!filter.containsKey(type)) { - filter.put(type, new ArrayList()); - } - filter.get(type).add(n); - } - - } - public void onListItemClick(ListView parent, View v, int position, long id) { SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE); if(prefs != null ){ Amenity amenity = amenityList.get(position); OsmandSettings.setLastKnownMapLocation(this,amenity.getLocation().getLatitude(),amenity.getLocation().getLongitude()); - Intent newIntent = new Intent(this.getApplicationContext(), MapActivity.class); + Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class); startActivity(newIntent); } } diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java index 9a50594165..0df45f83ed 100644 --- a/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java @@ -5,7 +5,6 @@ package com.osmand.activities.search; import java.util.ArrayList; import java.util.List; -import java.util.Map; import android.app.ListActivity; import android.content.Intent; @@ -20,7 +19,6 @@ import android.widget.TextView; import com.osmand.Algoritms; import com.osmand.R; -import com.osmand.data.Amenity; import com.osmand.data.Amenity.AmenityType; /** @@ -31,7 +29,6 @@ public class SearchPOIListActivity extends ListActivity { List amenityList = new ArrayList(); - Map> filter; @Override public void onCreate(Bundle icicle) { @@ -55,8 +52,9 @@ public class SearchPOIListActivity extends ListActivity { if (amenityType != null) { Bundle bundle = new Bundle(); bundle.putString(SearchPOIActivity.ANENITY_TYPE, amenityList.get(position)); - Intent newIntent = new Intent(this.getApplicationContext(), SearchPOIActivity.class); + Intent newIntent = new Intent(SearchPOIListActivity.this, SearchPOIActivity.class); newIntent.putExtras(bundle); + newIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivityForResult(newIntent, 0); } }