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.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<Boolean> MAP_ONLINE_DATA = new BooleanPreference("map_online_data", false).makeGlobal();
// 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();
// {
// SHOW_DESTINATION_ARROW.setModeDefaultValue(ApplicationMode.CAR, false);
// }
public final CommonPreference<Boolean> SHOW_DESTINATION_ARROW = new BooleanPreference("show_destination_arrow", false).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
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) {
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() {

View file

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

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,
// "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);