This commit is contained in:
nazar-kutz 2021-04-01 19:34:03 +03:00
parent 432f0e6abd
commit b42a69e53f
3 changed files with 22 additions and 18 deletions

View file

@ -92,6 +92,8 @@ public class MapActivityKeyListener implements KeyEvent.Callback {
return true; return true;
} else if (keyCode == KeyEvent.KEYCODE_C) { } else if (keyCode == KeyEvent.KEYCODE_C) {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl(); mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
} else if (keyCode == KeyEvent.KEYCODE_D) {
mapActivity.getMapViewTrackingUtilities().switchRotateMapMode();
} else if (settings.EXTERNAL_INPUT_DEVICE.get() == PARROT_EXTERNAL_DEVICE) { } else if (settings.EXTERNAL_INPUT_DEVICE.get() == PARROT_EXTERNAL_DEVICE) {
// Parrot device has only dpad left and right // Parrot device has only dpad left and right
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {

View file

@ -39,6 +39,8 @@ import java.util.Map;
public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLocationListener, public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLocationListener,
OsmAndCompassListener, MapMarkerChangedListener { OsmAndCompassListener, MapMarkerChangedListener {
private static final int COMPASS_REQUEST_TIME_INTERVAL_MS = 5000;
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;
@ -59,6 +61,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
private Float heading; private Float heading;
private boolean drivingRegionUpdated = false; private boolean drivingRegionUpdated = false;
private boolean movingToMyLocation = false; private boolean movingToMyLocation = false;
private long compassRequest;
public MapViewTrackingUtilities(OsmandApplication app){ public MapViewTrackingUtilities(OsmandApplication app){
this.app = app; this.app = app;
@ -424,7 +427,22 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
setMapLinkedToLocation(false); setMapLinkedToLocation(false);
} }
public void switchRotateMapMode(){ public void switchRotateMapMode() {
if (app.getRoutingHelper().isFollowingMode()) {
if (compassRequest + COMPASS_REQUEST_TIME_INTERVAL_MS > System.currentTimeMillis()) {
compassRequest = 0;
switchRotateMapModeImpl();
} else {
compassRequest = System.currentTimeMillis();
app.showShortToastMessage(app.getString(R.string.press_again_to_change_the_map_orientation));
}
} else {
compassRequest = 0;
switchRotateMapModeImpl();
}
}
private void switchRotateMapModeImpl(){
if (mapView != null) { if (mapView != null) {
String rotMode = app.getString(R.string.rotate_map_none_opt); String rotMode = app.getString(R.string.rotate_map_none_opt);
if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE && mapView.getRotate() != 0) { if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE && mapView.getRotate() != 0) {

View file

@ -97,8 +97,6 @@ public class MapControlsLayer extends OsmandMapLayer {
private static final int REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION = 201; private static final int REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION = 201;
private static final int REQUEST_LOCATION_FOR_ADD_DESTINATION_PERMISSION = 202; private static final int REQUEST_LOCATION_FOR_ADD_DESTINATION_PERMISSION = 202;
private static final int COMPASS_PRESSED_TIME_INTERVAL_MS = 5000;
public MapHudButton createHudButton(View iv, int resId, String id) { public MapHudButton createHudButton(View iv, int resId, String id) {
MapHudButton mc = new MapHudButton(); MapHudButton mc = new MapHudButton();
mc.iv = iv; mc.iv = iv;
@ -139,7 +137,6 @@ public class MapControlsLayer extends OsmandMapLayer {
private MapQuickActionLayer mapQuickActionLayer; private MapQuickActionLayer mapQuickActionLayer;
private boolean forceShowCompass; private boolean forceShowCompass;
private LatLon requestedLatLon; private LatLon requestedLatLon;
private long compassPressed;
private Set<String> themeInfoProviderTags = new HashSet<>(); private Set<String> themeInfoProviderTags = new HashSet<>();
public MapControlsLayer(MapActivity activity) { public MapControlsLayer(MapActivity activity) {
@ -292,20 +289,7 @@ public class MapControlsLayer extends OsmandMapLayer {
compass.setOnClickListener(new View.OnClickListener() { compass.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
boolean followingMode = app.getRoutingHelper().isFollowingMode();
if (followingMode) {
if (compassPressed + COMPASS_PRESSED_TIME_INTERVAL_MS > System.currentTimeMillis()) {
compassPressed = 0;
mapActivity.getMapViewTrackingUtilities().switchRotateMapMode(); mapActivity.getMapViewTrackingUtilities().switchRotateMapMode();
} else {
compassPressed = System.currentTimeMillis();
app.showShortToastMessage(app.getString(R.string.press_again_to_change_the_map_orientation));
}
} else {
compassPressed = 0;
mapActivity.getMapViewTrackingUtilities().switchRotateMapMode();
}
} }
}); });