diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 4961b279be..e676cd4ec3 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -243,6 +243,38 @@ public class AndroidUtils { return new PointF(centroidX, centroidY); } + public static void showSystemUI(Activity activity) { + if (Build.VERSION.SDK_INT >= 19 && !isSystemUiVisible(activity)) { + switchSystemUiVisibility(activity); + } + } + + public static void hideSystemUI(Activity activity) { + if (Build.VERSION.SDK_INT >= 19 && isSystemUiVisible(activity)) { + switchSystemUiVisibility(activity); + } + } + + public static boolean isSystemUiVisible(Activity activity) { + if (Build.VERSION.SDK_INT >= 19) { + int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility(); + return !((uiOptions | View.SYSTEM_UI_FLAG_FULLSCREEN) == uiOptions); + } + return true; + } + + public static void switchSystemUiVisibility(Activity activity) { + if (Build.VERSION.SDK_INT < 19) { + return; + } + View decorView = activity.getWindow().getDecorView(); + int uiOptions = decorView.getSystemUiVisibility(); + uiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; + uiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; + uiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + decorView.setSystemUiVisibility(uiOptions); + } + public static > Map sortByValue(Map map) { List> list = new LinkedList<>(map.entrySet()); Collections.sort(list, new Comparator>() { diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 8d7fcd75cc..972f862fb9 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -812,9 +812,7 @@ public class ContextMenuLayer extends OsmandMapLayer { boolean processed = hideVisibleMenues(); processed |= menu.onSingleTapOnMap(); if (!processed) { - MapControlsLayer controlsLayer = activity.getMapLayers().getMapControlsLayer(); - controlsLayer.switchMapControlsVisibility(); - controlsLayer.switchSystemUiVisibility(); + activity.getMapLayers().getMapControlsLayer().switchMapControlsVisibility(true); } return false; } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 14dabd4617..7ebfcfe16e 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -656,16 +656,9 @@ public class MapControlsLayer extends OsmandMapLayer { zoomOutButton.setOnLongClickListener(listener); } - private boolean isFullscreenModeAllowed() { - return !(app.getRoutingHelper().isFollowingMode() || app.getRoutingHelper().isPauseNavigation() - || mapActivity.getMeasurementToolFragment() != null - || mapActivity.getPlanRouteFragment() != null - || mapActivity.getMapLayers().getRulerControlLayer().rulerModeOn()); - } - public void showMapControls() { mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.VISIBLE); - showSystemUI(); + AndroidUtils.showSystemUI(mapActivity); } public void hideMapControls() { @@ -681,49 +674,23 @@ public class MapControlsLayer extends OsmandMapLayer { return mapActivity.findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE; } - public void switchMapControlsVisibility() { - if (!isFullscreenModeAllowed()) { + public void switchMapControlsVisibility(boolean switchSystemUiVisibility) { + if (app.getRoutingHelper().isFollowingMode() || app.getRoutingHelper().isPauseNavigation() + || mapActivity.getMeasurementToolFragment() != null + || mapActivity.getPlanRouteFragment() != null + || mapActivity.getMapLayers().getRulerControlLayer().rulerModeOn()) { return; } if (isMapControlsVisible()) { - hideMapControls(); + AndroidUtils.hideSystemUI(mapActivity); + if (switchSystemUiVisibility) { + hideMapControls(); + } } else { showMapControls(); } } - public void showSystemUI() { - if (Build.VERSION.SDK_INT >= 19 && !isSystemUiVisible()) { - switchSystemUiVisibility(); - } - } - - public void hideSystemUI() { - if (Build.VERSION.SDK_INT >= 19 && isSystemUiVisible()) { - switchSystemUiVisibility(); - } - } - - public boolean isSystemUiVisible() { - if (Build.VERSION.SDK_INT >= 19) { - int uiOptions = mapActivity.getWindow().getDecorView().getSystemUiVisibility(); - return !((uiOptions | View.SYSTEM_UI_FLAG_FULLSCREEN) == uiOptions); - } - return true; - } - - public void switchSystemUiVisibility() { - if (!isFullscreenModeAllowed() || Build.VERSION.SDK_INT < 19) { - return; - } - View decorView = mapActivity.getWindow().getDecorView(); - int uiOptions = decorView.getSystemUiVisibility(); - uiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; - uiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN; - uiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; - decorView.setSystemUiVisibility(uiOptions); - } - public void startNavigation() { OsmandApplication app = mapActivity.getMyApplication(); RoutingHelper routingHelper = app.getRoutingHelper();