diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index dd66da49d6..dc56b94118 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -1,5 +1,7 @@ + Наибыстрейший маршрут + Включите опцию для расчета наибыстрейшего маршрута или отключите для расчета кратчайшего. На масштабе {0} загрузить {1} тайлов ({2} Mb ) Загрузить карту Выберите максимальный масштаб для загрузки видимой области diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 8ec97b1373..1f89b41efb 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,8 @@ + Fastest route + Enable for calculate fastest route or disable for shortest route + At zoom {0} download {1} tiles ({2} Mb ) Download map Select max zoom to preload visible area @@ -243,7 +246,7 @@ Your OSM password User password Specify OSM settings: OSM login - Specify monitoring settings: save track + Specify monitoring settings Specify language, download/reload data Specify map settings: map source, rotation, center position, screen orientation Data diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index aa81724b72..2d965ab7eb 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -32,6 +32,8 @@ + + diff --git a/OsmAnd/src/net/osmand/OsmandSettings.java b/OsmAnd/src/net/osmand/OsmandSettings.java index 1d1d7953a8..cef0333b80 100644 --- a/OsmAnd/src/net/osmand/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/OsmandSettings.java @@ -229,6 +229,15 @@ public class OsmandSettings { SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); return prefs.getBoolean(SAVE_TRACK_TO_GPX, SAVE_TRACK_TO_GPX_DEF); } + + // this value string is synchronized with settings_pref.xml preference name + public static final String FAST_ROUTE_MODE = "fast_route_mode"; //$NON-NLS-1$ + public static final boolean FAST_ROUTE_MODE_DEF = true; + + public static boolean isFastRouteMode(Context ctx) { + SharedPreferences prefs = ctx.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_WORLD_READABLE); + return prefs.getBoolean(FAST_ROUTE_MODE, FAST_ROUTE_MODE_DEF); + } // this value string is synchronized with settings_pref.xml preference name public static final String SAVE_TRACK_INTERVAL = "save_track_interval"; //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/activities/RouteProvider.java b/OsmAnd/src/net/osmand/activities/RouteProvider.java index 7a2246bd7e..55344e5a3f 100644 --- a/OsmAnd/src/net/osmand/activities/RouteProvider.java +++ b/OsmAnd/src/net/osmand/activities/RouteProvider.java @@ -161,7 +161,7 @@ public class RouteProvider { } public RouteCalculationResult calculateRouteImpl(Location start, LatLon end, ApplicationMode mode, RouteService type, Context ctx, - List gpxRoute){ + List gpxRoute, boolean fast){ long time = System.currentTimeMillis(); if (start != null && end != null) { if(log.isInfoEnabled()){ @@ -199,10 +199,10 @@ public class RouteProvider { res = new RouteCalculationResult(new ArrayList(gpxRoute.subList(startI, endI)), null, start, end, null); addMissingTurnsToRoute(res, start, end, mode, ctx); } else if (type == RouteService.YOURS) { - res = findYOURSRoute(start, end, mode); + res = findYOURSRoute(start, end, mode, fast); addMissingTurnsToRoute(res, start, end, mode, ctx); } else { - res = findCloudMadeRoute(start, end, mode, ctx); + res = findCloudMadeRoute(start, end, mode, ctx, fast); // for test purpose addMissingTurnsToRoute(res, start, end, mode, ctx); } @@ -422,7 +422,7 @@ public class RouteProvider { } - protected RouteCalculationResult findYOURSRoute(Location start, LatLon end, ApplicationMode mode) throws MalformedURLException, IOException, + protected RouteCalculationResult findYOURSRoute(Location start, LatLon end, ApplicationMode mode, boolean fast) throws MalformedURLException, IOException, ParserConfigurationException, FactoryConfigurationError, SAXException { List res = new ArrayList(); StringBuilder uri = new StringBuilder(); @@ -438,7 +438,7 @@ public class RouteProvider { } else { uri.append("&v=motorcar"); //$NON-NLS-1$ } - uri.append("&fast=1").append("&layer=mapnik"); //$NON-NLS-1$ //$NON-NLS-2$ + uri.append("&fast=").append(fast ? "1" : "0").append("&layer=mapnik"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ URL url = new URL(uri.toString()); URLConnection connection = url.openConnection(); @@ -481,7 +481,7 @@ public class RouteProvider { } - protected RouteCalculationResult findCloudMadeRoute(Location start, LatLon end, ApplicationMode mode, Context ctx) throws MalformedURLException, IOException, + protected RouteCalculationResult findCloudMadeRoute(Location start, LatLon end, ApplicationMode mode, Context ctx, boolean fast) throws MalformedURLException, IOException, ParserConfigurationException, FactoryConfigurationError, SAXException { List res = new ArrayList(); List directions = null; @@ -498,7 +498,11 @@ public class RouteProvider { } else if (ApplicationMode.BICYCLE == mode) { uri.append("bicycle.gpx"); //$NON-NLS-1$ } else { - uri.append("car.gpx"); //$NON-NLS-1$ + if(fast){ + uri.append("car.gpx"); //$NON-NLS-1$ + } else { + uri.append("car/shortest.gpx"); //$NON-NLS-1$ + } } uri.append("?lang=").append(Locale.getDefault().getLanguage()); //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/activities/RoutingHelper.java b/OsmAnd/src/net/osmand/activities/RoutingHelper.java index cca64c4eda..506ad9189d 100644 --- a/OsmAnd/src/net/osmand/activities/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/activities/RoutingHelper.java @@ -439,11 +439,12 @@ public class RoutingHelper { if(currentRunningJob == null){ // do not evaluate very often if (System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval) { + final boolean fastRouteMode = OsmandSettings.isFastRouteMode(context); synchronized (this) { currentRunningJob = new Thread(new Runnable() { @Override public void run() { - RouteCalculationResult res = provider.calculateRouteImpl(start, end, mode, service, context, currentGPXRoute); + RouteCalculationResult res = provider.calculateRouteImpl(start, end, mode, service, context, currentGPXRoute, fastRouteMode); synchronized (RoutingHelper.this) { if (res.isCalculated()) { setNewRoute(res); diff --git a/OsmAnd/src/net/osmand/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/activities/SettingsActivity.java index 9b38b029c5..0ade155451 100644 --- a/OsmAnd/src/net/osmand/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/activities/SettingsActivity.java @@ -110,6 +110,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference new BooleanPreference(OsmandSettings.SAVE_TRACK_TO_GPX, OsmandSettings.SAVE_TRACK_TO_GPX_DEF), new BooleanPreference(OsmandSettings.DEBUG_RENDERING_INFO, OsmandSettings.DEBUG_RENDERING_INFO_DEF), new BooleanPreference(OsmandSettings.USE_STEP_BY_STEP_RENDERING, OsmandSettings.USE_STEP_BY_STEP_RENDERING_DEF), + new BooleanPreference(OsmandSettings.FAST_ROUTE_MODE, OsmandSettings.FAST_ROUTE_MODE_DEF), }; private BroadcastReceiver broadcastReceiver; diff --git a/OsmAnd/src/net/osmand/render/OsmandRenderer.java b/OsmAnd/src/net/osmand/render/OsmandRenderer.java index f0973f204b..f584b1ca9c 100644 --- a/OsmAnd/src/net/osmand/render/OsmandRenderer.java +++ b/OsmAnd/src/net/osmand/render/OsmandRenderer.java @@ -362,11 +362,7 @@ public class OsmandRenderer { for(IconDrawInfo icon : rc.iconsToDraw){ if (icon.resId != 0) { if (cachedIcons.get(icon.resId) == null) { - Options options = new BitmapFactory.Options(); - options.inScaled = false; - options.inTargetDensity = dm.densityDpi; - options.inDensity = dm.densityDpi; - cachedIcons.put(icon.resId, BitmapFactory.decodeResource(context.getResources(), icon.resId, options)); + cachedIcons.put(icon.resId, UnscaledBitmapLoader.loadFromResource(context.getResources(), icon.resId, null, dm)); } Bitmap ico = cachedIcons.get(icon.resId); if (ico != null) { diff --git a/OsmAnd/src/net/osmand/render/UnscaledBitmapLoader.java b/OsmAnd/src/net/osmand/render/UnscaledBitmapLoader.java new file mode 100644 index 0000000000..9c1fe552f7 --- /dev/null +++ b/OsmAnd/src/net/osmand/render/UnscaledBitmapLoader.java @@ -0,0 +1,45 @@ +package net.osmand.render; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.BitmapFactory.Options; +import android.os.Build; +import android.util.DisplayMetrics; + +public abstract class UnscaledBitmapLoader { + + public static final UnscaledBitmapLoader instance; + + static { + instance = Integer.parseInt(Build.VERSION.SDK) < 4 ? new Old() : new New(); + } + + public static Bitmap loadFromResource(Resources resources, int resId, BitmapFactory.Options options, DisplayMetrics densityDpi) { + return instance.load(resources, resId, options, densityDpi); + } + + private static class Old extends UnscaledBitmapLoader { + + @Override + Bitmap load(Resources resources, int resId, Options options, DisplayMetrics densityDpi) { + return BitmapFactory.decodeResource(resources, resId, options); + } + + } + + private static class New extends UnscaledBitmapLoader { + + @Override + Bitmap load(Resources resources, int resId, Options options, DisplayMetrics dm) { + options = new BitmapFactory.Options(); + options.inScaled = false; + options.inTargetDensity = dm.densityDpi; + options.inDensity = dm.densityDpi; + return BitmapFactory.decodeResource(resources, resId, options); + } + + } + + abstract Bitmap load(Resources resources, int resId, BitmapFactory.Options options, DisplayMetrics densityDpi); + +} \ No newline at end of file