improve history stack

git-svn-id: https://osmand.googlecode.com/svn/trunk@109 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
frolovmo 2010-06-01 14:44:58 +00:00
parent bd4c191a23
commit d49648d39c
7 changed files with 47 additions and 39 deletions

View file

@ -9,7 +9,7 @@
<TextView android:id="@+id/poidistance_label"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="25px" />
android:textSize="25px" android:maxWidth="100px" android:minWidth="100px"/>
<TextView android:id="@+id/poi_label" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="25px" />

View file

@ -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),

View file

@ -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<Amenity> searchAmenities(double latitude, double longitude, int zoom, int limit) {
// //////////////////////////////////////////// Working with amenities
// ////////////////////////////////////////////////
public List<Amenity> 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<Amenity> amenities = new ArrayList<Amenity>();
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;
}

View file

@ -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 {

View file

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

View file

@ -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<AmenityType, List<Amenity>>();
LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this);
List<Amenity> 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<Amenity>());
}
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);
}
}

View file

@ -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<String> amenityList = new ArrayList<String>();
Map<AmenityType, List<Amenity>> 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);
}
}