From 840dae932faf9c158c1a4fe86ce4586a783e9a3c Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 1 Nov 2017 17:08:46 +0200 Subject: [PATCH] Improve fullscreen mode entering --- .../osmand/plus/activities/MapActivity.java | 1 + .../osmand/plus/dashboard/DashboardOnMap.java | 5 +- .../MapContextMenuFragment.java | 5 +- .../other/MapRouteInfoMenuFragment.java | 6 ++- .../plus/mapmarkers/PlanRouteFragment.java | 9 ++-- .../MeasurementToolFragment.java | 5 +- .../osmand/plus/views/ContextMenuLayer.java | 2 +- .../osmand/plus/views/MapControlsLayer.java | 50 ++++++++++++++----- 8 files changed, 61 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index df74bc3d06..90edd74513 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -930,6 +930,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven public void readLocationToShow() { mapLayers.getMapControlsLayer().showMapControls(); + mapLayers.getMapControlsLayer().showSystemUI(); LatLon cur = new LatLon(mapView.getLatitude(), mapView.getLongitude()); LatLon latLonToShow = settings.getAndClearMapLocationToShow(); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 8438311687..36ebf169e2 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -85,6 +85,7 @@ import net.osmand.plus.srtmplugin.ContourLinesMenu; import net.osmand.plus.srtmplugin.HillshadeMenu; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.DownloadedRegionsLayer; +import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.controls.DynamicListView; @@ -875,7 +876,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis mapActivity.getMapView().refreshMap(); } - mapActivity.getMapLayers().getMapControlsLayer().showMapControls(); + MapControlsLayer controlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); + controlsLayer.showMapControls(); + controlsLayer.showSystemUI(); hideActionButton(); for (WeakReference df : fragList) { if (df.get() != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 3d3a0a3658..362876f104 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -46,6 +46,7 @@ import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.views.AnimateDraggingMapThread; +import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.views.controls.SingleTapConfirm; @@ -904,7 +905,9 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { ((View) parent).addOnLayoutChangeListener(containerLayoutListener); } menu.updateControlsVisibility(true); - getMapActivity().getMapLayers().getMapControlsLayer().showMapControls(); + MapControlsLayer controlsLayer = getMapActivity().getMapLayers().getMapControlsLayer(); + controlsLayer.showMapControls(); + controlsLayer.showSystemUI(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenuFragment.java index 1ceedaa33c..93a81e72a7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenuFragment.java @@ -4,7 +4,6 @@ import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -14,6 +13,7 @@ import net.osmand.AndroidUtils; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.views.MapControlsLayer; public class MapRouteInfoMenuFragment extends Fragment { public static final String TAG = "MapRouteInfoMenuFragment"; @@ -55,7 +55,9 @@ public class MapRouteInfoMenuFragment extends Fragment { if (menu == null) { dismiss(); } - getMapActivity().getMapLayers().getMapControlsLayer().showMapControls(); + MapControlsLayer controlsLayer = getMapActivity().getMapLayers().getMapControlsLayer(); + controlsLayer.showMapControls(); + controlsLayer.showSystemUI(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index 4911ec30d9..ce477804f7 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -53,6 +53,7 @@ import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadFragmentListener; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapMarkersLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; @@ -362,10 +363,10 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene public void onResume() { super.onResume(); MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.getMyApplication().getLocationProvider().addLocationListener(this); - } - getMapActivity().getMapLayers().getMapControlsLayer().showMapControls(); + mapActivity.getMyApplication().getLocationProvider().addLocationListener(this); + MapControlsLayer controlsLayer = mapActivity.getMapLayers().getMapControlsLayer(); + controlsLayer.showMapControls(); + controlsLayer.showSystemUI(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 9008611dd9..37cac1bcf6 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -61,6 +61,7 @@ import net.osmand.plus.measurementtool.command.ClearPointsCommand; import net.osmand.plus.measurementtool.command.MovePointCommand; import net.osmand.plus.measurementtool.command.RemovePointCommand; import net.osmand.plus.measurementtool.command.ReorderPointCommand; +import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -461,7 +462,9 @@ public class MeasurementToolFragment extends Fragment { @Override public void onResume() { super.onResume(); - getMapActivity().getMapLayers().getMapControlsLayer().showMapControls(); + MapControlsLayer controlsLayer = getMapActivity().getMapLayers().getMapControlsLayer(); + controlsLayer.showMapControls(); + controlsLayer.showSystemUI(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 7f18a1aca0..8d7fcd75cc 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -814,7 +814,7 @@ public class ContextMenuLayer extends OsmandMapLayer { if (!processed) { MapControlsLayer controlsLayer = activity.getMapLayers().getMapControlsLayer(); controlsLayer.switchMapControlsVisibility(); - controlsLayer.switchStatusbarAndNavbarVisibility(); + controlsLayer.switchSystemUiVisibility(); } return false; } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 8b9724a4a1..7ae2934282 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -656,9 +656,17 @@ public class MapControlsLayer extends OsmandMapLayer { zoomOutButton.setOnLongClickListener(listener); } + private boolean switchMapControlsAndSystemUiVisibilityNotAllowed() { + 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); } + public void hideMapControls() { mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.INVISIBLE); } @@ -673,10 +681,7 @@ public class MapControlsLayer extends OsmandMapLayer { } public void switchMapControlsVisibility() { - if (app.getRoutingHelper().isFollowingMode() || app.getRoutingHelper().isPauseNavigation() - || mapActivity.getMeasurementToolFragment() != null - || mapActivity.getPlanRouteFragment() != null - || mapActivity.getMapLayers().getRulerControlLayer().rulerModeOn()) { + if (switchMapControlsAndSystemUiVisibilityNotAllowed()) { return; } if (isMapControlsVisible()) { @@ -686,17 +691,38 @@ public class MapControlsLayer extends OsmandMapLayer { } } - public void switchStatusbarAndNavbarVisibility() { - if (Build.VERSION.SDK_INT >= 19) { - 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 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 (switchMapControlsAndSystemUiVisibilityNotAllowed() || 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();