improve history stack
git-svn-id: https://osmand.googlecode.com/svn/trunk@109 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
bd4c191a23
commit
d49648d39c
7 changed files with 47 additions and 39 deletions
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
<TextView android:id="@+id/poidistance_label"
|
<TextView android:id="@+id/poidistance_label"
|
||||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
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"
|
<TextView android:id="@+id/poi_label" android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" android:textSize="25px" />
|
android:layout_height="wrap_content" android:textSize="25px" />
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class AmenityIndexRepository {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
String squery = "? < latitude AND latitude < ? AND ? < longitude AND longitude < ?";
|
String squery = "? < latitude AND latitude < ? AND ? < longitude AND longitude < ?";
|
||||||
if(type != null){
|
if(type != null){
|
||||||
squery += " AND type = " + AmenityType.valueToString(type);
|
squery += " AND type = " + "'" +AmenityType.valueToString(type)+ "'";
|
||||||
}
|
}
|
||||||
Cursor query = db.query(IndexPoiTable.getTable(), columns, squery,
|
Cursor query = db.query(IndexPoiTable.getTable(), columns, squery,
|
||||||
new String[]{Double.toString(bottomLatitude),
|
new String[]{Double.toString(bottomLatitude),
|
||||||
|
|
|
@ -16,6 +16,7 @@ import android.graphics.BitmapFactory;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import com.osmand.data.Amenity;
|
import com.osmand.data.Amenity;
|
||||||
|
import com.osmand.data.Amenity.AmenityType;
|
||||||
import com.osmand.data.index.IndexConstants;
|
import com.osmand.data.index.IndexConstants;
|
||||||
import com.osmand.data.preparation.MapTileDownloader;
|
import com.osmand.data.preparation.MapTileDownloader;
|
||||||
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
import com.osmand.data.preparation.MapTileDownloader.DownloadRequest;
|
||||||
|
@ -182,8 +183,9 @@ public class ResourceManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////// Working with amenities ////////////////////////////////////////////////
|
// //////////////////////////////////////////// Working with amenities
|
||||||
public List<Amenity> searchAmenities(double latitude, double longitude, int zoom, int limit) {
|
// ////////////////////////////////////////////////
|
||||||
|
public List<Amenity> searchAmenities(AmenityType type, double latitude, double longitude, int zoom, int limit) {
|
||||||
double tileNumberX = Math.floor(MapUtils.getTileNumberX(zoom, longitude));
|
double tileNumberX = Math.floor(MapUtils.getTileNumberX(zoom, longitude));
|
||||||
double tileNumberY = Math.floor(MapUtils.getTileNumberY(zoom, latitude));
|
double tileNumberY = Math.floor(MapUtils.getTileNumberY(zoom, latitude));
|
||||||
double topLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY);
|
double topLatitude = MapUtils.getLatitudeFromTile(zoom, tileNumberY);
|
||||||
|
@ -194,7 +196,7 @@ public class ResourceManager {
|
||||||
for (AmenityIndexRepository index : amenityRepositories) {
|
for (AmenityIndexRepository index : amenityRepositories) {
|
||||||
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
if (index.checkContains(topLatitude, leftLongitude, bottomLatitude, rightLongitude)) {
|
||||||
if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, amenities)) {
|
if (!index.checkCachedAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, amenities)) {
|
||||||
index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, null, amenities);
|
index.searchAmenities(topLatitude, leftLongitude, bottomLatitude, rightLongitude, limit, type, amenities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
@ -144,6 +145,16 @@ public class MainMenuActivity extends Activity {
|
||||||
startApplication();
|
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 {
|
private class DefaultExceptionHandler implements UncaughtExceptionHandler {
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import android.os.Message;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -144,13 +145,26 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat
|
||||||
backToMenu.setOnClickListener(new OnClickListener() {
|
backToMenu.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent();
|
Intent newIntent = new Intent(MapActivity.this, MainMenuActivity.class);
|
||||||
setResult(RESULT_OK, intent);
|
newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
finish();
|
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
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
*/
|
*/
|
||||||
package com.osmand.activities.search;
|
package com.osmand.activities.search;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -46,6 +44,7 @@ public class SearchPOIActivity extends ListActivity {
|
||||||
|
|
||||||
private Button searchPOILevel;
|
private Button searchPOILevel;
|
||||||
private int zoom = 12;
|
private int zoom = 12;
|
||||||
|
private int maxCount = 500;
|
||||||
|
|
||||||
private AmenityType amenityType;
|
private AmenityType amenityType;
|
||||||
|
|
||||||
|
@ -65,9 +64,11 @@ public class SearchPOIActivity extends ListActivity {
|
||||||
Bundle bundle = this.getIntent().getExtras();
|
Bundle bundle = this.getIntent().getExtras();
|
||||||
String anemity = bundle.getString(ANENITY_TYPE);
|
String anemity = bundle.getString(ANENITY_TYPE);
|
||||||
if (anemity != null) {
|
if (anemity != null) {
|
||||||
|
ResourceManager resourceManager = ResourceManager.getResourceManager();
|
||||||
|
LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this);
|
||||||
amenityType = findAmenityType(anemity);
|
amenityType = findAmenityType(anemity);
|
||||||
createAmenityFilter(zoom);
|
amenityList = resourceManager.searchAmenities(amenityType, lastKnownMapLocation.getLatitude(),
|
||||||
amenityList = filter.get(amenityType);
|
lastKnownMapLocation.getLongitude(), zoom, maxCount);
|
||||||
if(amenityList != null) {
|
if(amenityList != null) {
|
||||||
amenityAdapter = new AmenityAdapter(amenityList);
|
amenityAdapter = new AmenityAdapter(amenityList);
|
||||||
setListAdapter(amenityAdapter);
|
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) {
|
public void onListItemClick(ListView parent, View v, int position, long id) {
|
||||||
SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE);
|
SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE);
|
||||||
if(prefs != null ){
|
if(prefs != null ){
|
||||||
Amenity amenity = amenityList.get(position);
|
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(this.getApplicationContext(), MapActivity.class);
|
Intent newIntent = new Intent(SearchPOIActivity.this, MapActivity.class);
|
||||||
startActivity(newIntent);
|
startActivity(newIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ package com.osmand.activities.search;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -20,7 +19,6 @@ import android.widget.TextView;
|
||||||
|
|
||||||
import com.osmand.Algoritms;
|
import com.osmand.Algoritms;
|
||||||
import com.osmand.R;
|
import com.osmand.R;
|
||||||
import com.osmand.data.Amenity;
|
|
||||||
import com.osmand.data.Amenity.AmenityType;
|
import com.osmand.data.Amenity.AmenityType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +29,6 @@ public class SearchPOIListActivity extends ListActivity {
|
||||||
|
|
||||||
|
|
||||||
List<String> amenityList = new ArrayList<String>();
|
List<String> amenityList = new ArrayList<String>();
|
||||||
Map<AmenityType, List<Amenity>> filter;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
|
@ -55,8 +52,9 @@ public class SearchPOIListActivity extends ListActivity {
|
||||||
if (amenityType != null) {
|
if (amenityType != null) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(SearchPOIActivity.ANENITY_TYPE, amenityList.get(position));
|
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.putExtras(bundle);
|
||||||
|
newIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
|
||||||
startActivityForResult(newIntent, 0);
|
startActivityForResult(newIntent, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue