From d9286a9c7198b82f5eb4b24d2d0ea91dca34041b Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 15 Jun 2010 12:54:24 +0000 Subject: [PATCH] implement auto zoom presets git-svn-id: https://osmand.googlecode.com/svn/trunk@164 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8 --- .../src/com/osmand/ToDoConstants.java | 11 ++----- OsmAnd/res/values/strings.xml | 12 ++++--- OsmAnd/res/xml/settings_pref.xml | 21 ++++-------- .../com/osmand/activities/MapActivity.java | 25 ++++++++++++++ .../com/osmand/views/PointLocationLayer.java | 33 ++++++++++++------- 5 files changed, 64 insertions(+), 38 deletions(-) diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index 2dcd25b70c..542d4dcfb1 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -40,14 +40,6 @@ public class ToDoConstants { // GOT : Victor // DONE: Load transport routes in swing. // TODO: Create transport index, create transport activity - -// 44. Introduce settings presets (car/bicycle/pedestrian/default) - show different icons for car (bigger), possibly change fonts, position -// DONE : Introduce settings property in settings screen -// TODO : check if all is correct, change visible icon over map for car - -// 45. Autozoom feature (for car navigation) -// DONE : settings preferences done -// TODO : add to Map activity algorithm of auto zooming in setLocation method // 36. Postcode search @@ -69,7 +61,6 @@ public class ToDoConstants { // 5. Improvement : Implement caching files existing on FS, implement specific method in RM // Introducing cache of file names that are on disk (creating new File() consumes a lot of memory) - // TODO swing // 4. Fix issues with big files (such as netherlands) - save memory (!) @@ -79,6 +70,8 @@ public class ToDoConstants { // BUGS Swing // DONE ANDROID : + // 45. Autozoom feature (for car navigation) + // 44. Introduce settings presets (car/bicycle/pedestrian/default) - show different icons for car (bigger), possibly change fonts, position // 20. Implement save track/route to gpx // DONE SWING diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 197663f88d..eb79359680 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,7 +1,11 @@ - Search settings - Osm settings + Specify osm settings: show bugs, osm login + Specify monitor settings : save track + Specify search settings + Specify map settings : rotation, poi filter + Search + Osm Auto zoom map according to the speed Auto zoom map Additional settings @@ -12,7 +16,7 @@ Save current track Choose time interval to save track Save track interval - Monitoring settings + Monitoring Tracks will be saved to track directory grouped by days Save track to gpx Navigate to @@ -51,7 +55,7 @@ Map source Use internet Show location - Map settings + Map Settings Show gps coordinates on map Use internet to download missing tiles diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index 2ac55cf710..0b7e89e3c5 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -2,39 +2,32 @@ - - - - + - - - - + - + - + - + - + - - + diff --git a/OsmAnd/src/com/osmand/activities/MapActivity.java b/OsmAnd/src/com/osmand/activities/MapActivity.java index 1a3c8a01d7..fc6ce1fd63 100644 --- a/OsmAnd/src/com/osmand/activities/MapActivity.java +++ b/OsmAnd/src/com/osmand/activities/MapActivity.java @@ -101,6 +101,8 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat savingTrackHelper = new SavingTrackHelper(this); + locationLayer.setAppMode(OsmandSettings.getApplicationMode(this)); + LatLon pointToNavigate = OsmandSettings.getPointToNavigate(this); navigationLayer.setPointToNavigate(pointToNavigate); @@ -232,8 +234,19 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat } } Log.d(LogUtil.TAG, "Location changed"); + // TODO delete + if(locationLayer.getLastKnownLocation() != null){ + location.setSpeed(location.distanceTo(locationLayer.getLastKnownLocation())); + } locationLayer.setLastKnownLocation(location); if (location != null) { + if(OsmandSettings.isAutoZoomEnabled(this) && location.hasSpeed()){ + int z = defineZoomFromSpeed(location.getSpeed()); + if(mapView.getZoom() != z){ + mapView.setZoom(z); + } + + } if (isMapLinkedToLocation()) { if (location.hasBearing() && OsmandSettings.isRotateMapToBearing(this)) { mapView.setRotate(-location.getBearing()); @@ -250,6 +263,18 @@ public class MapActivity extends Activity implements LocationListener, IMapLocat } } } + + public int defineZoomFromSpeed(float speed){ + speed *= 3.6; + if(speed < 20){ + return 17; + } else if(speed < 60){ + return 16; + } else if(speed < 120){ + return 15; + } + return 14; + } public void navigateToPoint(LatLon point){ if(point != null){ diff --git a/OsmAnd/src/com/osmand/views/PointLocationLayer.java b/OsmAnd/src/com/osmand/views/PointLocationLayer.java index 4ddbfb9eb5..dc8330ad39 100644 --- a/OsmAnd/src/com/osmand/views/PointLocationLayer.java +++ b/OsmAnd/src/com/osmand/views/PointLocationLayer.java @@ -23,7 +23,7 @@ public class PointLocationLayer implements OsmandMapLayer { private Paint area; private Paint headingPaint; private Path pathForDirection; - private ApplicationMode preset = ApplicationMode.DEFAULT; + private ApplicationMode appMode = ApplicationMode.DEFAULT; protected Location lastKnownLocation = null; @@ -77,7 +77,13 @@ public class PointLocationLayer implements OsmandMapLayer { int radius = MapUtils.getLengthXFromMeters(view.getZoom(), view.getLatitude(), view.getLongitude(), lastKnownLocation .getAccuracy(), view.getTileSize(), view.getWidth()); - canvas.drawCircle(locationX, locationY, RADIUS, location); + if(appMode == ApplicationMode.CAR){ + if(!lastKnownLocation.hasBearing()){ + canvas.drawCircle(locationX, locationY, RADIUS * 2.5f, location); + } + } else { + canvas.drawCircle(locationX, locationY, RADIUS, location); + } if (radius > RADIUS) { canvas.drawCircle(locationX, locationY, radius, area); } @@ -103,8 +109,16 @@ public class PointLocationLayer implements OsmandMapLayer { pathForDirection.lineTo(0, 0); Matrix m = new Matrix(); m.reset(); - m.postScale(1, radiusBearing * 0.5f); - m.postTranslate(0, -radiusBearing); + if(appMode == ApplicationMode.CAR){ + m.postScale(2.5f, radiusBearing * 1.5f); + m.postTranslate(0, -radiusBearing/2); + } else if(appMode == ApplicationMode.BICYCLE){ + m.postScale(2f, radiusBearing); + m.postTranslate(0, -radiusBearing/2); + } else { + m.postScale(1, radiusBearing * 0.5f); + m.postTranslate(0, -radiusBearing); + } m.postTranslate(locationX, locationY); m.postRotate(bearing, locationX, locationY); @@ -150,15 +164,12 @@ public class PointLocationLayer implements OsmandMapLayer { public void destroyLayer() { } - - public ApplicationMode getPreset() { - return preset; + public ApplicationMode getAppMode() { + return appMode; } - - public void setSettingsPreset(ApplicationMode preset) { - this.preset = preset; + public void setAppMode(ApplicationMode appMode) { + this.appMode = appMode; } - @Override public boolean drawInScreenPixels() { return false;