From 8af5552a279a30d76674eec089c3286dc5852540 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 31 Jul 2014 02:25:29 +0200 Subject: [PATCH] Show view angle always and make show destination arrow configurable --- .../src/net/osmand/plus/OsmandSettings.java | 11 ++++---- .../plus/base/MapViewTrackingUtilities.java | 14 ++++++++-- .../plus/views/PointNavigationLayer.java | 27 ++++++++++--------- .../mapwidgets/AppearanceWidgetsFactory.java | 18 ++++++------- 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index b194091e8d..8f2369723a 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -3,7 +3,6 @@ package net.osmand.plus; import java.io.File; import java.io.IOException; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -316,6 +315,7 @@ public class OsmandSettings { protected abstract T getValue(Object prefs, T defaultValue); + protected abstract boolean setValue(Object prefs, T val); @Override @@ -361,6 +361,10 @@ public class OsmandSettings { } return false; } + + public boolean isSet() { + return settingsAPI.contains(getPreferences(), getId()); + } } @@ -947,10 +951,7 @@ public class OsmandSettings { public final CommonPreference MAP_ONLINE_DATA = new BooleanPreference("map_online_data", false).makeGlobal(); // this value string is synchronized with settings_pref.xml preference name -// public final CommonPreference SHOW_DESTINATION_ARROW = new BooleanPreference("show_destination_arrow", true).makeProfile(); -// { -// SHOW_DESTINATION_ARROW.setModeDefaultValue(ApplicationMode.CAR, false); -// } + public final CommonPreference SHOW_DESTINATION_ARROW = new BooleanPreference("show_destination_arrow", false).makeProfile(); // this value string is synchronized with settings_pref.xml preference name public final CommonPreference MAP_OVERLAY = new StringPreference("map_overlay", null).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index c9a7eaf7b4..f7fc508678 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -85,14 +85,16 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc public void updateLocation(Location location) { showViewAngle = false; if (mapView != null) { + RotatedTileBox tb = mapView.getCurrentRotatedTileBox(); if (isMapLinkedToLocation() && location != null) { if (settings.AUTO_ZOOM_MAP.get() != AutoZoomMap.NONE) { autozoom(location); } int currentMapRotation = settings.ROTATE_MAP.get(); - boolean smallSpeed = !location.hasSpeed() || location.getSpeed() < 0.5; + boolean smallSpeed = isSmallSpeedForCompass(location); // boolean virtualBearing = fMode && settings.SNAP_TO_ROAD.get(); - showViewAngle = (!location.hasBearing() || smallSpeed); + showViewAngle = (!location.hasBearing() || smallSpeed) && (tb != null && + tb.containsLatLon(location.getLatitude(), location.getLongitude())); if (currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) { if (location.hasBearing() && !smallSpeed) { // special case when bearing equals to zero (we don't change anything) @@ -105,6 +107,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc } registerUnregisterSensor(location); mapView.setLatLon(location.getLatitude(), location.getLongitude()); + } else if(location != null) { + showViewAngle = (!location.hasBearing() || isSmallSpeedForCompass(location)) && (tb != null && + tb.containsLatLon(location.getLatitude(), location.getLongitude())); + registerUnregisterSensor(location); } RoutingHelper routingHelper = app.getRoutingHelper(); followingMode = routingHelper.isFollowingMode(); @@ -115,6 +121,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc mapView.refreshMap(); } } + + private boolean isSmallSpeedForCompass(Location location) { + return !location.hasSpeed() || location.getSpeed() < 0.5; + } public boolean isShowViewAngle() { diff --git a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java index 354eea3d21..b7ee5acf77 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java @@ -11,7 +11,6 @@ import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; -import android.content.Context; import android.content.DialogInterface; import android.content.res.Resources; import android.graphics.Bitmap; @@ -21,8 +20,6 @@ import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Paint.Style; import android.graphics.PointF; -import android.util.DisplayMetrics; -import android.view.WindowManager; public class PointNavigationLayer extends OsmandMapLayer implements IContextMenuProvider { protected final static int DIST_TO_SHOW = 80; @@ -110,15 +107,21 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu int locationY = tb.getPixYFromLatNoRot(pointToNavigate.getLatitude()); canvas.rotate(-tb.getRotate(), locationX, locationY); canvas.drawBitmap(targetPoint, locationX - marginX, locationY - marginY, bitmapPaint); - } else if (pointToNavigate != null && !view.getApplication().getRoutingHelper().isRouteCalculated()) { - net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), - pointToNavigate.getLongitude(), calculations); - float bearing = calculations[1] - 90; - float radiusBearing = DIST_TO_SHOW * tb.getDensity(); - final QuadPoint cp = tb.getCenterPixelPoint(); - canvas.rotate(bearing, cp.x, cp.y); - canvas.translate(-24 * tb.getDensity() + radiusBearing, -22 * tb.getDensity()); - canvas.drawBitmap(arrowToDestination, cp.x, cp.y, bitmapPaint); + } else if (pointToNavigate != null) { + boolean show = !view.getApplication().getRoutingHelper().isRouteCalculated(); + if(view.getSettings().SHOW_DESTINATION_ARROW.isSet()) { + show = view.getSettings().SHOW_DESTINATION_ARROW.get(); + } + if (show) { + net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), + pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), calculations); + float bearing = calculations[1] - 90; + float radiusBearing = DIST_TO_SHOW * tb.getDensity(); + final QuadPoint cp = tb.getCenterPixelPoint(); + canvas.rotate(bearing, cp.x, cp.y); + canvas.translate(-24 * tb.getDensity() + radiusBearing, -22 * tb.getDensity()); + canvas.drawBitmap(arrowToDestination, cp.x, cp.y, bitmapPaint); + } } } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java index 8d14ad7462..2d6f8d9352 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/AppearanceWidgetsFactory.java @@ -54,15 +54,15 @@ public class AppearanceWidgetsFactory { } }); -// final MapWidgetRegistry.MapWidgetRegInfo showDestinationArrow = mapInfoControls.registerAppearanceWidget(R.drawable.widget_show_destination_arrow, R.string.map_widget_show_destination_arrow, -// "show_destination_arrow", view.getSettings().SHOW_DESTINATION_ARROW); -// showDestinationArrow.setStateChangeListener(new Runnable() { -// @Override -// public void run() { -// view.getSettings().SHOW_DESTINATION_ARROW.set(!view.getSettings().SHOW_DESTINATION_ARROW.get()); -// mapInfoLayer.recreateControls(); -// } -// }); + final MapWidgetRegistry.MapWidgetRegInfo showDestinationArrow = mapInfoControls.registerAppearanceWidget(R.drawable.widget_show_destination_arrow, R.string.map_widget_show_destination_arrow, + "show_destination_arrow", view.getSettings().SHOW_DESTINATION_ARROW); + showDestinationArrow.setStateChangeListener(new Runnable() { + @Override + public void run() { + view.getSettings().SHOW_DESTINATION_ARROW.set(!view.getSettings().SHOW_DESTINATION_ARROW.get()); + mapInfoLayer.recreateControls(); + } + }); final MapWidgetRegistry.MapWidgetRegInfo transparent = mapInfoControls.registerAppearanceWidget(R.drawable.widget_transparent_skin, R.string.map_widget_transparent, "transparent", view.getSettings().TRANSPARENT_MAP_THEME);