Show view angle always and make show destination arrow configurable

This commit is contained in:
Victor Shcherb 2014-07-31 02:25:29 +02:00
parent 182834f93b
commit 3bb57cb560
4 changed files with 42 additions and 28 deletions

View file

@ -3,7 +3,6 @@ package net.osmand.plus;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -316,6 +315,7 @@ public class OsmandSettings {
protected abstract T getValue(Object prefs, T defaultValue); protected abstract T getValue(Object prefs, T defaultValue);
protected abstract boolean setValue(Object prefs, T val); protected abstract boolean setValue(Object prefs, T val);
@Override @Override
@ -361,6 +361,10 @@ public class OsmandSettings {
} }
return false; return false;
} }
public boolean isSet() {
return settingsAPI.contains(getPreferences(), getId());
}
} }
@ -947,10 +951,7 @@ public class OsmandSettings {
public final CommonPreference<Boolean> MAP_ONLINE_DATA = new BooleanPreference("map_online_data", false).makeGlobal(); public final CommonPreference<Boolean> MAP_ONLINE_DATA = new BooleanPreference("map_online_data", false).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
// public final CommonPreference<Boolean> SHOW_DESTINATION_ARROW = new BooleanPreference("show_destination_arrow", true).makeProfile(); public final CommonPreference<Boolean> SHOW_DESTINATION_ARROW = new BooleanPreference("show_destination_arrow", false).makeProfile();
// {
// SHOW_DESTINATION_ARROW.setModeDefaultValue(ApplicationMode.CAR, false);
// }
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<String> MAP_OVERLAY = new StringPreference("map_overlay", null).makeGlobal(); public final CommonPreference<String> MAP_OVERLAY = new StringPreference("map_overlay", null).makeGlobal();

View file

@ -85,14 +85,16 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
public void updateLocation(Location location) { public void updateLocation(Location location) {
showViewAngle = false; showViewAngle = false;
if (mapView != null) { if (mapView != null) {
RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
if (isMapLinkedToLocation() && location != null) { if (isMapLinkedToLocation() && location != null) {
if (settings.AUTO_ZOOM_MAP.get() != AutoZoomMap.NONE) { if (settings.AUTO_ZOOM_MAP.get() != AutoZoomMap.NONE) {
autozoom(location); autozoom(location);
} }
int currentMapRotation = settings.ROTATE_MAP.get(); 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(); // 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 (currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) {
if (location.hasBearing() && !smallSpeed) { if (location.hasBearing() && !smallSpeed) {
// special case when bearing equals to zero (we don't change anything) // special case when bearing equals to zero (we don't change anything)
@ -105,6 +107,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
} }
registerUnregisterSensor(location); registerUnregisterSensor(location);
mapView.setLatLon(location.getLatitude(), location.getLongitude()); 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(); RoutingHelper routingHelper = app.getRoutingHelper();
followingMode = routingHelper.isFollowingMode(); followingMode = routingHelper.isFollowingMode();
@ -115,6 +121,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
mapView.refreshMap(); mapView.refreshMap();
} }
} }
private boolean isSmallSpeedForCompass(Location location) {
return !location.hasSpeed() || location.getSpeed() < 0.5;
}
public boolean isShowViewAngle() { public boolean isShowViewAngle() {

View file

@ -11,7 +11,6 @@ import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -21,8 +20,6 @@ import android.graphics.Paint;
import android.graphics.Paint.Align; import android.graphics.Paint.Align;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.PointF; import android.graphics.PointF;
import android.util.DisplayMetrics;
import android.view.WindowManager;
public class PointNavigationLayer extends OsmandMapLayer implements IContextMenuProvider { public class PointNavigationLayer extends OsmandMapLayer implements IContextMenuProvider {
protected final static int DIST_TO_SHOW = 80; 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()); int locationY = tb.getPixYFromLatNoRot(pointToNavigate.getLatitude());
canvas.rotate(-tb.getRotate(), locationX, locationY); canvas.rotate(-tb.getRotate(), locationX, locationY);
canvas.drawBitmap(targetPoint, locationX - marginX, locationY - marginY, bitmapPaint); canvas.drawBitmap(targetPoint, locationX - marginX, locationY - marginY, bitmapPaint);
} else if (pointToNavigate != null && !view.getApplication().getRoutingHelper().isRouteCalculated()) { } else if (pointToNavigate != null) {
net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), pointToNavigate.getLatitude(), boolean show = !view.getApplication().getRoutingHelper().isRouteCalculated();
pointToNavigate.getLongitude(), calculations); if(view.getSettings().SHOW_DESTINATION_ARROW.isSet()) {
float bearing = calculations[1] - 90; show = view.getSettings().SHOW_DESTINATION_ARROW.get();
float radiusBearing = DIST_TO_SHOW * tb.getDensity(); }
final QuadPoint cp = tb.getCenterPixelPoint(); if (show) {
canvas.rotate(bearing, cp.x, cp.y); net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(),
canvas.translate(-24 * tb.getDensity() + radiusBearing, -22 * tb.getDensity()); pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), calculations);
canvas.drawBitmap(arrowToDestination, cp.x, cp.y, bitmapPaint); 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);
}
} }
} }

View file

@ -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, 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); "show_destination_arrow", view.getSettings().SHOW_DESTINATION_ARROW);
// showDestinationArrow.setStateChangeListener(new Runnable() { showDestinationArrow.setStateChangeListener(new Runnable() {
// @Override @Override
// public void run() { public void run() {
// view.getSettings().SHOW_DESTINATION_ARROW.set(!view.getSettings().SHOW_DESTINATION_ARROW.get()); view.getSettings().SHOW_DESTINATION_ARROW.set(!view.getSettings().SHOW_DESTINATION_ARROW.get());
// mapInfoLayer.recreateControls(); mapInfoLayer.recreateControls();
// } }
// }); });
final MapWidgetRegistry.MapWidgetRegInfo transparent = mapInfoControls.registerAppearanceWidget(R.drawable.widget_transparent_skin, R.string.map_widget_transparent, final MapWidgetRegistry.MapWidgetRegInfo transparent = mapInfoControls.registerAppearanceWidget(R.drawable.widget_transparent_skin, R.string.map_widget_transparent,
"transparent", view.getSettings().TRANSPARENT_MAP_THEME); "transparent", view.getSettings().TRANSPARENT_MAP_THEME);