From e0799857cb929f73f15b00adda824af28e9eb916 Mon Sep 17 00:00:00 2001 From: Pavol Zibrita Date: Thu, 11 Aug 2011 01:41:07 +0200 Subject: [PATCH 1/3] Fixed 582,now the TTS uses application context, no need to reinitialize. --- OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java | 2 +- OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java b/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java index 32c6f29092..014a69acfd 100644 --- a/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java +++ b/OsmAnd/src/net/osmand/plus/voice/CommandPlayer.java @@ -15,4 +15,4 @@ public interface CommandPlayer { public abstract void clear(); public abstract List execute(List listStruct); -} \ No newline at end of file +} diff --git a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java index 83f8beaa1e..d060c290a3 100644 --- a/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java +++ b/OsmAnd/src/net/osmand/plus/voice/MediaCommandPlayerImpl.java @@ -118,4 +118,4 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer { public static boolean isMyData(File voiceDir) { return new File(voiceDir, CONFIG_FILE).exists(); } -} \ No newline at end of file +} From a2a1113791a3e313a83f0c8eb1392f9f0d4bb222 Mon Sep 17 00:00:00 2001 From: Pavol Zibrita Date: Tue, 16 Aug 2011 01:06:55 +0200 Subject: [PATCH 2/3] Added animation to follow a route. This way it is easier to test the voice navigation. Animation menu item is visible when 'Allow mock location' is set in debug menu of android settings. --- OsmAnd/res/menu/map_menu.xml | 1 + OsmAnd/res/values/strings.xml | 3 + OsmAnd/src/net/osmand/LatLonUtils.java | 34 ++++++++++ .../osmand/plus/activities/MapActivity.java | 25 +++++-- .../plus/activities/RouteAnimation.java | 65 +++++++++++++++++++ .../osmand/plus/activities/RoutingHelper.java | 7 +- 6 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 OsmAnd/src/net/osmand/LatLonUtils.java create mode 100644 OsmAnd/src/net/osmand/plus/activities/RouteAnimation.java diff --git a/OsmAnd/res/menu/map_menu.xml b/OsmAnd/res/menu/map_menu.xml index 898a6ede73..a5fe35f859 100644 --- a/OsmAnd/res/menu/map_menu.xml +++ b/OsmAnd/res/menu/map_menu.xml @@ -10,6 +10,7 @@ + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 19f0ffbace..2fd3cd2441 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,8 @@ + Animate off + Animate on + Upload GPX files to OSM community. They will be used to improve maps. %1$d of %2$d item(s) successfully uploaded. Contribute to OSM... diff --git a/OsmAnd/src/net/osmand/LatLonUtils.java b/OsmAnd/src/net/osmand/LatLonUtils.java new file mode 100644 index 0000000000..91153e9d8a --- /dev/null +++ b/OsmAnd/src/net/osmand/LatLonUtils.java @@ -0,0 +1,34 @@ +package net.osmand; + +import android.location.Location; + +public class LatLonUtils { + + public static Location middleLocation(Location start, Location end, + float meters) { + double lat1 = toRad(start.getLatitude()); + double lon1 = toRad(start.getLongitude()); + double R = 6371; // radius of earth in km + double d = meters / 1000; // in km + float brng = (float) (toRad(start.bearingTo(end))); + double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / R) + + Math.cos(lat1) * Math.sin(d / R) * Math.cos(brng)); + double lon2 = lon1 + + Math.atan2(Math.sin(brng) * Math.sin(d / R) * Math.cos(lat1), + Math.cos(d / R) - Math.sin(lat1) * Math.sin(lat2)); + Location nl = new Location(start); + nl.setLatitude(toDegree(lat2)); + nl.setLongitude(toDegree(lon2)); + nl.setBearing(brng); + return nl; + } + + private static double toDegree(double radians) { + return radians * 180 / Math.PI; + } + + private static double toRad(double degree) { + return degree * Math.PI / 180; + } + +} diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index a27c48828c..20ca65753e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -28,12 +28,12 @@ import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.PointLocationLayer; import android.app.Activity; import android.app.AlertDialog; +import android.app.AlertDialog.Builder; import android.app.Dialog; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.ProgressDialog; -import android.app.AlertDialog.Builder; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.DialogInterface; @@ -58,6 +58,7 @@ import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; +import android.provider.Settings.Secure; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; @@ -65,8 +66,8 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; -import android.view.Window; import android.view.View.OnClickListener; +import android.view.Window; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.view.animation.Transformation; @@ -121,6 +122,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso // Store previous map rotation settings for rotate button private Integer previousMapRotate = null; + private RouteAnimation routeAnimation = new RouteAnimation(); + private boolean isMapLinkedToLocation = false; private ProgressDialog startProgressDialog; @@ -436,6 +439,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso protected void onDestroy() { super.onDestroy(); savingTrackHelper.close(); + routeAnimation.close(); if(mNotificationManager != null){ mNotificationManager.cancel(APP_NOTIFICATION_ID); } @@ -948,6 +952,15 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso muteMenu.setVisible(false); } } + MenuItem animateMenu = menu.findItem(R.id.map_animate_route); + if (animateMenu != null) { + animateMenu.setTitle(routeAnimation.isRouteAnimating() ? R.string.animate_route_off + : R.string.animate_route); + animateMenu.setVisible("1".equals(Secure.getString( + getContentResolver(), Secure.ALLOW_MOCK_LOCATION)) + && settings.getPointToNavigate() != null + && routingHelper.isRouteCalculated()); + } return val; } @@ -1003,6 +1016,10 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso case R.id.map_show_point_options: contextMenuPoint(mapView.getLatitude(), mapView.getLongitude()); return true; + case R.id.map_animate_route: + //animate moving on route + routeAnimation.startStopRouteAnimation(routingHelper, this); + return true; default: return super.onOptionsItemSelected(item); } @@ -1104,9 +1121,7 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso @Override public void onClick(DialogInterface dialog, int which) { ApplicationMode mode = getAppMode(buttons); - Location location = new Location("map"); //$NON-NLS-1$ - location.setLatitude(lat); - location.setLongitude(lon); + Location location = getLocationToStartFrom(lat, lon); routingHelper.setAppMode(mode); settings.FOLLOW_TO_THE_ROUTE.set(false); routingHelper.setFollowingMode(false); diff --git a/OsmAnd/src/net/osmand/plus/activities/RouteAnimation.java b/OsmAnd/src/net/osmand/plus/activities/RouteAnimation.java new file mode 100644 index 0000000000..17dc8467a5 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/activities/RouteAnimation.java @@ -0,0 +1,65 @@ +package net.osmand.plus.activities; + +import java.util.ArrayList; +import java.util.List; + +import net.osmand.LatLonUtils; +import android.location.Location; + +public class RouteAnimation { + + private Thread routeAnimation; + + public boolean isRouteAnimating() { + return routeAnimation != null; + } + + public void startStopRouteAnimation(final RoutingHelper routingHelper, + final MapActivity ma) { + if (!isRouteAnimating()) { + routeAnimation = new Thread() { + public void run() { + final List directions = new ArrayList( + routingHelper.getCurrentRoute()); + Location current = null; + float meters = 20.0f; + while (!directions.isEmpty() && routeAnimation != null) { + if (current == null) { + current = new Location(directions.remove(0)); + } else { + if (current.distanceTo(directions.get(0)) > meters) { + current = LatLonUtils.middleLocation(current, + directions.get(0), meters); + } else { + current = new Location(directions.remove(0)); + } + } + current.setSpeed(meters); + current.setTime(System.currentTimeMillis()); + ma.setLocation(current); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // do nothing + } + } + RouteAnimation.this.stop(); + }; + }; + routeAnimation.start(); + } else { + // stop the animation + stop(); + } + } + + private void stop() { + routeAnimation = null; + } + + public void close() { + if (isRouteAnimating()) { + stop(); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java index 9d70a5059f..66dc487219 100644 --- a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java @@ -117,13 +117,18 @@ public class RoutingHelper { this.lastFixedLocation = null; this.isFollowingMode = false; } - } public List getCurrentGPXRoute() { return currentGPXRoute; } + public List getCurrentRoute() { + return currentGPXRoute == null || currentGPXRoute.isEmpty() ? Collections + .unmodifiableList(routeNodes) : Collections + .unmodifiableList(currentGPXRoute); + } + public void setAppMode(ApplicationMode mode){ this.mode = mode; voiceRouter.updateAppMode(); From f571c8f31784347de6f6330c86312e6a917fbd84 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 18 Sep 2011 12:01:12 +0200 Subject: [PATCH 3/3] Replace LF by CRLF --- DataExtractionOSM/.classpath | 28 ++-- DataExtractionOSM/OsmAndMapCreator.launch | 32 ++--- OsmAnd/src/net/osmand/LatLonUtils.java | 68 ++++----- .../plus/activities/RouteAnimation.java | 130 +++++++++--------- 4 files changed, 129 insertions(+), 129 deletions(-) diff --git a/DataExtractionOSM/.classpath b/DataExtractionOSM/.classpath index c9586f09ca..213c2a9a0c 100644 --- a/DataExtractionOSM/.classpath +++ b/DataExtractionOSM/.classpath @@ -1,14 +1,14 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/DataExtractionOSM/OsmAndMapCreator.launch b/DataExtractionOSM/OsmAndMapCreator.launch index c7a3cba55a..c2f01cfa4e 100644 --- a/DataExtractionOSM/OsmAndMapCreator.launch +++ b/DataExtractionOSM/OsmAndMapCreator.launch @@ -1,16 +1,16 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/LatLonUtils.java b/OsmAnd/src/net/osmand/LatLonUtils.java index 91153e9d8a..5b35bf718a 100644 --- a/OsmAnd/src/net/osmand/LatLonUtils.java +++ b/OsmAnd/src/net/osmand/LatLonUtils.java @@ -1,34 +1,34 @@ -package net.osmand; - -import android.location.Location; - -public class LatLonUtils { - - public static Location middleLocation(Location start, Location end, - float meters) { - double lat1 = toRad(start.getLatitude()); - double lon1 = toRad(start.getLongitude()); - double R = 6371; // radius of earth in km - double d = meters / 1000; // in km - float brng = (float) (toRad(start.bearingTo(end))); - double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / R) - + Math.cos(lat1) * Math.sin(d / R) * Math.cos(brng)); - double lon2 = lon1 - + Math.atan2(Math.sin(brng) * Math.sin(d / R) * Math.cos(lat1), - Math.cos(d / R) - Math.sin(lat1) * Math.sin(lat2)); - Location nl = new Location(start); - nl.setLatitude(toDegree(lat2)); - nl.setLongitude(toDegree(lon2)); - nl.setBearing(brng); - return nl; - } - - private static double toDegree(double radians) { - return radians * 180 / Math.PI; - } - - private static double toRad(double degree) { - return degree * Math.PI / 180; - } - -} +package net.osmand; + +import android.location.Location; + +public class LatLonUtils { + + public static Location middleLocation(Location start, Location end, + float meters) { + double lat1 = toRad(start.getLatitude()); + double lon1 = toRad(start.getLongitude()); + double R = 6371; // radius of earth in km + double d = meters / 1000; // in km + float brng = (float) (toRad(start.bearingTo(end))); + double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / R) + + Math.cos(lat1) * Math.sin(d / R) * Math.cos(brng)); + double lon2 = lon1 + + Math.atan2(Math.sin(brng) * Math.sin(d / R) * Math.cos(lat1), + Math.cos(d / R) - Math.sin(lat1) * Math.sin(lat2)); + Location nl = new Location(start); + nl.setLatitude(toDegree(lat2)); + nl.setLongitude(toDegree(lon2)); + nl.setBearing(brng); + return nl; + } + + private static double toDegree(double radians) { + return radians * 180 / Math.PI; + } + + private static double toRad(double degree) { + return degree * Math.PI / 180; + } + +} diff --git a/OsmAnd/src/net/osmand/plus/activities/RouteAnimation.java b/OsmAnd/src/net/osmand/plus/activities/RouteAnimation.java index 17dc8467a5..2ff4add488 100644 --- a/OsmAnd/src/net/osmand/plus/activities/RouteAnimation.java +++ b/OsmAnd/src/net/osmand/plus/activities/RouteAnimation.java @@ -1,65 +1,65 @@ -package net.osmand.plus.activities; - -import java.util.ArrayList; -import java.util.List; - -import net.osmand.LatLonUtils; -import android.location.Location; - -public class RouteAnimation { - - private Thread routeAnimation; - - public boolean isRouteAnimating() { - return routeAnimation != null; - } - - public void startStopRouteAnimation(final RoutingHelper routingHelper, - final MapActivity ma) { - if (!isRouteAnimating()) { - routeAnimation = new Thread() { - public void run() { - final List directions = new ArrayList( - routingHelper.getCurrentRoute()); - Location current = null; - float meters = 20.0f; - while (!directions.isEmpty() && routeAnimation != null) { - if (current == null) { - current = new Location(directions.remove(0)); - } else { - if (current.distanceTo(directions.get(0)) > meters) { - current = LatLonUtils.middleLocation(current, - directions.get(0), meters); - } else { - current = new Location(directions.remove(0)); - } - } - current.setSpeed(meters); - current.setTime(System.currentTimeMillis()); - ma.setLocation(current); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - // do nothing - } - } - RouteAnimation.this.stop(); - }; - }; - routeAnimation.start(); - } else { - // stop the animation - stop(); - } - } - - private void stop() { - routeAnimation = null; - } - - public void close() { - if (isRouteAnimating()) { - stop(); - } - } -} +package net.osmand.plus.activities; + +import java.util.ArrayList; +import java.util.List; + +import net.osmand.LatLonUtils; +import android.location.Location; + +public class RouteAnimation { + + private Thread routeAnimation; + + public boolean isRouteAnimating() { + return routeAnimation != null; + } + + public void startStopRouteAnimation(final RoutingHelper routingHelper, + final MapActivity ma) { + if (!isRouteAnimating()) { + routeAnimation = new Thread() { + public void run() { + final List directions = new ArrayList( + routingHelper.getCurrentRoute()); + Location current = null; + float meters = 20.0f; + while (!directions.isEmpty() && routeAnimation != null) { + if (current == null) { + current = new Location(directions.remove(0)); + } else { + if (current.distanceTo(directions.get(0)) > meters) { + current = LatLonUtils.middleLocation(current, + directions.get(0), meters); + } else { + current = new Location(directions.remove(0)); + } + } + current.setSpeed(meters); + current.setTime(System.currentTimeMillis()); + ma.setLocation(current); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // do nothing + } + } + RouteAnimation.this.stop(); + }; + }; + routeAnimation.start(); + } else { + // stop the animation + stop(); + } + } + + private void stop() { + routeAnimation = null; + } + + public void close() { + if (isRouteAnimating()) { + stop(); + } + } +}