Enable setting to show view angle by default, when there is no speed

This commit is contained in:
vshcherb 2014-04-28 01:56:44 +02:00
parent b55a971f8a
commit 71625c67cc
7 changed files with 42 additions and 52 deletions

View file

@ -15,7 +15,5 @@
<CheckBoxPreference android:title="@string/snap_to_road" android:summary="@string/snap_to_road_descr" android:key="snap_to_road"></CheckBoxPreference> <CheckBoxPreference android:title="@string/snap_to_road" android:summary="@string/snap_to_road_descr" android:key="snap_to_road"></CheckBoxPreference>
<Preference android:title="@string/show_warnings_title" android:summary="@string/show_warnings_descr" android:key="show_routing_alarms"/> <Preference android:title="@string/show_warnings_title" android:summary="@string/show_warnings_descr" android:key="show_routing_alarms"/>
<Preference android:title="@string/speak_title" android:summary="@string/speak_descr" android:key="speak_routing_alarms"/> <Preference android:title="@string/speak_title" android:summary="@string/speak_descr" android:key="speak_routing_alarms"/>
<CheckBoxPreference android:summary="@string/use_compass_navigation_descr" android:title="@string/use_compass_navigation"
android:key="use_compass_navigation"></CheckBoxPreference>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View file

@ -831,12 +831,12 @@ public class OsmandSettings {
new IntPreference("map_screen_orientation", -1/*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/).makeGlobal(); new IntPreference("map_screen_orientation", -1/*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/).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_VIEW_ANGLE = new BooleanPreference("show_view_angle", false).makeProfile().cache(); // public final CommonPreference<Boolean> SHOW_VIEW_ANGLE = new BooleanPreference("show_view_angle", false).makeProfile().cache();
{ // {
SHOW_VIEW_ANGLE.setModeDefaultValue(ApplicationMode.CAR, false); // SHOW_VIEW_ANGLE.setModeDefaultValue(ApplicationMode.CAR, false);
SHOW_VIEW_ANGLE.setModeDefaultValue(ApplicationMode.BICYCLE, true); // SHOW_VIEW_ANGLE.setModeDefaultValue(ApplicationMode.BICYCLE, true);
SHOW_VIEW_ANGLE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, true); // SHOW_VIEW_ANGLE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, true);
} // }
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name
// seconds to auto_follow // seconds to auto_follow
@ -1544,12 +1544,6 @@ public class OsmandSettings {
}; };
}.makeGlobal(); }.makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
//public final OsmandPreference<Boolean> USE_COMPASS_IN_NAVIGATION = new BooleanPreference("use_compass_navigation", true).makeProfile().cache();
public final CommonPreference<Boolean> USE_COMPASS_IN_NAVIGATION = new BooleanPreference("use_compass_navigation", true).makeProfile().cache();
{
USE_COMPASS_IN_NAVIGATION.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> RENDERER = new StringPreference("renderer", RendererRegistry.DEFAULT_RENDER) { public final CommonPreference<String> RENDERER = new StringPreference("renderer", RendererRegistry.DEFAULT_RENDER) {

View file

@ -136,7 +136,7 @@ public class MapActivityLayers {
transportInfoLayer = new TransportInfoLayer(TransportRouteHelper.getInstance()); transportInfoLayer = new TransportInfoLayer(TransportRouteHelper.getInstance());
mapView.addLayer(transportInfoLayer, 5.5f); mapView.addLayer(transportInfoLayer, 5.5f);
// 6. point location layer // 6. point location layer
locationLayer = new PointLocationLayer(); locationLayer = new PointLocationLayer(activity.getMapViewTrackingUtilities());
mapView.addLayer(locationLayer, 6); mapView.addLayer(locationLayer, 6);
// 7. point navigation layer // 7. point navigation layer
navigationLayer = new PointNavigationLayer(activity); navigationLayer = new PointNavigationLayer(activity);

View file

@ -64,7 +64,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
registerBooleanPreference(settings.SNAP_TO_ROAD, screen); registerBooleanPreference(settings.SNAP_TO_ROAD, screen);
registerBooleanPreference(settings.USE_COMPASS_IN_NAVIGATION, screen);
Integer[] intValues = new Integer[] { 0, 5, 10, 15, 20, 25, 30, 45, 60, 90}; Integer[] intValues = new Integer[] { 0, 5, 10, 15, 20, 25, 30, 45, 60, 90};
entries = new String[intValues.length]; entries = new String[intValues.length];

View file

@ -27,7 +27,6 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
private static final int AUTO_FOLLOW_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 4; private static final int AUTO_FOLLOW_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 4;
private long lastTimeAutoZooming = 0; private long lastTimeAutoZooming = 0;
private long lastTimeSensorMapRotation = 0;
private boolean sensorRegistered = false; private boolean sensorRegistered = false;
private OsmandMapTileView mapView; private OsmandMapTileView mapView;
private OsmandSettings settings; private OsmandSettings settings;
@ -36,6 +35,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
private boolean isMapLinkedToLocation = false; private boolean isMapLinkedToLocation = false;
private boolean followingMode; private boolean followingMode;
private boolean routePlanningMode; private boolean routePlanningMode;
private boolean showViewAngle = false;
public MapViewTrackingUtilities(OsmandApplication app){ public MapViewTrackingUtilities(OsmandApplication app){
this.app = app; this.app = app;
@ -75,7 +75,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
if (Math.abs(MapUtils.degreesDiff(mapView.getRotate(), -val)) > 1) { if (Math.abs(MapUtils.degreesDiff(mapView.getRotate(), -val)) > 1) {
mapView.setRotate(-val); mapView.setRotate(-val);
} }
} else if (settings.SHOW_VIEW_ANGLE.get()) { } else if (showViewAngle) {
mapView.refreshMap(); mapView.refreshMap();
} }
} }
@ -83,37 +83,27 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
@Override @Override
public void updateLocation(Location location) { public void updateLocation(Location location) {
showViewAngle = false;
if (mapView != null) { if (mapView != null) {
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 enableCompass = false; boolean smallSpeed = !location.hasSpeed() || location.getSpeed() < 0.5;
// boolean virtualBearing = fMode && settings.SNAP_TO_ROAD.get();
showViewAngle = (!location.hasBearing() || smallSpeed);
if (currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) { if (currentMapRotation == OsmandSettings.ROTATE_MAP_BEARING) {
boolean smallSpeed = !location.hasSpeed() || location.getSpeed() < 0.5;
boolean fMode = app.getRoutingHelper().isFollowingMode();
// boolean virtualBearing = fMode && settings.SNAP_TO_ROAD.get();
enableCompass = (!location.hasBearing() || smallSpeed)
&& fMode && settings.USE_COMPASS_IN_NAVIGATION.get();
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)
if (location.getBearing() != 0f) { if (location.getBearing() != 0f) {
mapView.setRotate(-location.getBearing()); mapView.setRotate(-location.getBearing());
} }
} else if (enableCompass) {
long now = System.currentTimeMillis();
OsmAndLocationProvider provider = app.getLocationProvider();
Float lastSensorRotation = provider.getHeading();
if (lastSensorRotation != null && Math.abs(MapUtils.degreesDiff(mapView.getRotate(), -lastSensorRotation)) > 15) {
if (now - lastTimeSensorMapRotation > 3500) {
lastTimeSensorMapRotation = now;
mapView.setRotate(-lastSensorRotation);
}
}
} }
} else if(currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS) {
showViewAngle = routePlanningMode; // disable compass rotation in that mode
} }
registerUnregisterSensor(location, enableCompass); registerUnregisterSensor(location);
mapView.setLatLon(location.getLatitude(), location.getLongitude()); mapView.setLatLon(location.getLatitude(), location.getLongitude());
} }
RoutingHelper routingHelper = app.getRoutingHelper(); RoutingHelper routingHelper = app.getRoutingHelper();
@ -127,6 +117,11 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
} }
public boolean isShowViewAngle() {
return showViewAngle;
}
public void switchToRoutePlanningMode() { public void switchToRoutePlanningMode() {
RoutingHelper routingHelper = app.getRoutingHelper(); RoutingHelper routingHelper = app.getRoutingHelper();
@ -146,13 +141,12 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
mapView.setMapPosition(settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING && !routePlanningMode ? OsmandSettings.BOTTOM_CONSTANT mapView.setMapPosition(settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING && !routePlanningMode ? OsmandSettings.BOTTOM_CONSTANT
: OsmandSettings.CENTER_CONSTANT); : OsmandSettings.CENTER_CONSTANT);
} }
registerUnregisterSensor(app.getLocationProvider().getLastKnownLocation(), false); registerUnregisterSensor(app.getLocationProvider().getLastKnownLocation());
} }
private void registerUnregisterSensor(net.osmand.Location location, boolean overruleRegister) { private void registerUnregisterSensor(net.osmand.Location location) {
boolean currentShowingAngle = settings.SHOW_VIEW_ANGLE.get();
int currentMapRotation = settings.ROTATE_MAP.get(); int currentMapRotation = settings.ROTATE_MAP.get();
boolean registerCompassListener = overruleRegister || (currentShowingAngle && location != null) boolean registerCompassListener = (showViewAngle && location != null)
|| (currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS && !routePlanningMode); || (currentMapRotation == OsmandSettings.ROTATE_MAP_COMPASS && !routePlanningMode);
// show point view only if gps enabled // show point view only if gps enabled
if(sensorRegistered != registerCompassListener) { if(sensorRegistered != registerCompassListener) {
@ -313,4 +307,5 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
public void routeWasCancelled() { public void routeWasCancelled() {
} }
} }

View file

@ -6,6 +6,7 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.MapViewTrackingUtilities;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
@ -28,7 +29,12 @@ public class PointLocationLayer extends OsmandMapLayer {
private Bitmap bearingIcon; private Bitmap bearingIcon;
private Bitmap locationIcon; private Bitmap locationIcon;
private OsmAndLocationProvider locationProvider; private OsmAndLocationProvider locationProvider;
private MapViewTrackingUtilities mapViewTrackingUtilities;
private boolean nm; private boolean nm;
public PointLocationLayer(MapViewTrackingUtilities mv) {
this.mapViewTrackingUtilities = mv;
}
private void initUI() { private void initUI() {
locationPaint = new Paint(); locationPaint = new Paint();
@ -53,7 +59,6 @@ public class PointLocationLayer extends OsmandMapLayer {
checkAppMode(view.getSettings().getApplicationMode()); checkAppMode(view.getSettings().getApplicationMode());
locationProvider = view.getApplication().getLocationProvider(); locationProvider = view.getApplication().getLocationProvider();
} }
@Override @Override
@ -65,7 +70,7 @@ public class PointLocationLayer extends OsmandMapLayer {
private RectF getHeadingRect(int locationX, int locationY){ private RectF getHeadingRect(int locationX, int locationY){
int rad = Math.min(3 * view.getWidth() / 8, 3 * view.getHeight() / 8); int rad = (int) (view.getDensity() * 25);
return new RectF(locationX - rad, locationY - rad, locationX + rad, locationY + rad); return new RectF(locationX - rad, locationY - rad, locationX + rad, locationY + rad);
} }
@ -102,10 +107,9 @@ public class PointLocationLayer extends OsmandMapLayer {
locationPaint); locationPaint);
} }
Float heading = locationProvider.getHeading(); Float heading = locationProvider.getHeading();
if (heading != null && view.getSettings().SHOW_VIEW_ANGLE.get()) { if (heading != null && mapViewTrackingUtilities.isShowViewAngle()) {
canvas.drawArc(getHeadingRect(locationX, locationY), heading - HEADING_ANGLE / 2 - 90, HEADING_ANGLE, true, headingPaint); canvas.drawArc(getHeadingRect(locationX, locationY), heading - HEADING_ANGLE / 2 - 90, HEADING_ANGLE, true, headingPaint);
} }
if (isBearing) { if (isBearing) {
float bearing = lastKnownLocation.getBearing(); float bearing = lastKnownLocation.getBearing();
canvas.rotate(bearing - 90, locationX, locationY); canvas.rotate(bearing - 90, locationX, locationY);

View file

@ -32,15 +32,15 @@ public class AppearanceWidgetsFactory {
final OsmandMapTileView view = map.getMapView(); final OsmandMapTileView view = map.getMapView();
final MapWidgetRegistry.MapWidgetRegInfo displayViewDirections = mapInfoControls.registerAppearanceWidget(R.drawable.widget_viewing_direction, R.string.map_widget_view_direction, // final MapWidgetRegistry.MapWidgetRegInfo displayViewDirections = mapInfoControls.registerAppearanceWidget(R.drawable.widget_viewing_direction, R.string.map_widget_view_direction,
"viewDirection", view.getSettings().SHOW_VIEW_ANGLE); // "viewDirection", view.getSettings().SHOW_VIEW_ANGLE);
displayViewDirections.setStateChangeListener(new Runnable() { // displayViewDirections.setStateChangeListener(new Runnable() {
@Override // @Override
public void run() { // public void run() {
view.getSettings().SHOW_VIEW_ANGLE.set(!view.getSettings().SHOW_VIEW_ANGLE.get()); // view.getSettings().SHOW_VIEW_ANGLE.set(!view.getSettings().SHOW_VIEW_ANGLE.get());
map.getMapViewTrackingUtilities().updateSettings(); // map.getMapViewTrackingUtilities().updateSettings();
} // }
}); // });
if (EXTRA_SETTINGS) { if (EXTRA_SETTINGS) {
final MapWidgetRegistry.MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(R.drawable.widget_ruler, R.string.map_widget_show_ruler, final MapWidgetRegistry.MapWidgetRegInfo showRuler = mapInfoControls.registerAppearanceWidget(R.drawable.widget_ruler, R.string.map_widget_show_ruler,