fix issue 252

fix issue 157

git-svn-id: https://osmand.googlecode.com/svn/trunk@781 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-12-08 15:47:40 +00:00
parent 355c44b955
commit f40eca5bed
9 changed files with 77 additions and 14 deletions

View file

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="fast_route_mode">Наибыстрейший маршрут</string>
<string name="fast_route_mode_descr">Включите опцию для расчета наибыстрейшего маршрута или отключите для расчета кратчайшего.</string>
<string name="tiles_to_download_estimated_size">На масштабе {0} загрузить {1} тайлов ({2} Mb )</string>
<string name="context_menu_item_download_map">Загрузить карту</string>
<string name="select_max_zoom_preload_area">Выберите максимальный масштаб для загрузки видимой области</string>

View file

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="fast_route_mode">Fastest route</string>
<string name="fast_route_mode_descr">Enable for calculate fastest route or disable for shortest route </string>
<string name="tiles_to_download_estimated_size">At zoom {0} download {1} tiles ({2} Mb )</string>
<string name="context_menu_item_download_map">Download map</string>
<string name="select_max_zoom_preload_area">Select max zoom to preload visible area</string>
@ -243,7 +246,7 @@
<string name="user_password_descr">Your OSM password</string>
<string name="user_password">User password</string>
<string name="osm_settings_descr">Specify OSM settings: OSM login</string>
<string name="monitor_preferences_descr">Specify monitoring settings: save track</string>
<string name="monitor_preferences_descr">Specify monitoring settings</string>
<string name="data_settings_descr">Specify language, download/reload data</string>
<string name="map_preferences_descr">Specify map settings: map source, rotation, center position, screen orientation</string>
<string name="data_settings">Data</string>

View file

@ -32,6 +32,8 @@
<PreferenceScreen android:title="@string/routing_settings" android:summary="@string/routing_settings_descr">
<ListPreference android:title="@string/router_service" android:key="router_service" android:summary="@string/router_service_descr"></ListPreference>
<CheckBoxPreference android:summary="@string/fast_route_mode_descr" android:title="@string/fast_route_mode" android:key="fast_route_mode"></CheckBoxPreference>
<CheckBoxPreference android:summary="@string/background_router_service_descr" android:title="@string/background_router_service" android:key="service_off_enabled"></CheckBoxPreference>
<ListPreference android:key="service_off_provider" android:title="@string/background_service_provider" android:summary="@string/background_service_provider_descr"></ListPreference>
<ListPreference android:key="service_off_interval" android:title="@string/background_service_int" android:summary="@string/background_service_int_descr"></ListPreference>

View file

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

View file

@ -161,7 +161,7 @@ public class RouteProvider {
}
public RouteCalculationResult calculateRouteImpl(Location start, LatLon end, ApplicationMode mode, RouteService type, Context ctx,
List<Location> gpxRoute){
List<Location> 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<Location>(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<Location> res = new ArrayList<Location>();
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<Location> res = new ArrayList<Location>();
List<RouteDirectionInfo> 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$

View file

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

View file

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

View file

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

View file

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