From 09e4e6bba8b4fcc8407a04661b56b36e79e67975 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Thu, 1 Feb 2018 16:49:45 +0300 Subject: [PATCH] Fix context menu --- .../MapContextMenuFragment.java | 22 +++++++++++---- .../osmand/plus/views/MapControlsLayer.java | 28 +++++++++++-------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 3300b84cc5..92dc422c6a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -94,6 +94,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo private int menuTopShadowAllHeight; private int menuTitleHeight; private int menuBottomViewHeight; + private int menuButtonsHeight; private int menuFullHeight; private int menuFullHeightMax; private int menuTopViewHeightExcludingTitle; @@ -606,8 +607,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo private float getToolbarAlpha(int y) { float a = 0; if (menu != null && !menu.isLandscapeLayout()) { - if (y < minHalfY) { - a = 1f - (y - bottomToolbarPosY) * (1f / (minHalfY - bottomToolbarPosY)); + if (y < bottomToolbarPosY) { + a = 1f - (y - topScreenPosY) * (1f / (bottomToolbarPosY - topScreenPosY)); } if (a < 0) { a = 0; @@ -714,7 +715,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo int oldMenuState = menu.getCurrentMenuState(); if (!menu.isLandscapeLayout()) { - if (slidingDown && !skipScreenState && oldMenuState == MenuState.FULL_SCREEN && currentY < topScreenPosY) { + if (slidingDown && !skipScreenState && oldMenuState == MenuState.FULL_SCREEN + && currentY < (-menuTitleHeight + menuButtonsHeight)) { slidingDown = false; } if (menuBottomViewHeight > 0 && slidingUp) { @@ -1198,6 +1200,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo menuTopShadowAllHeight = newMenuTopShadowAllHeight; menuTitleHeight = menuTopShadowAllHeight + dy; menuBottomViewHeight = view.findViewById(R.id.context_menu_bottom_view).getHeight(); + menuButtonsHeight = view.findViewById(R.id.context_menu_bottom_buttons).getHeight() + view.findViewById(R.id.buttons_bottom_border).getHeight() + view.findViewById(R.id.context_menu_buttons).getHeight(); menuFullHeightMax = menuTitleHeight + menuBottomViewHeight; @@ -1416,7 +1419,12 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo case MenuState.FULL_SCREEN: if (currentY != CURRENT_Y_UNDEFINED) { int maxPosY = viewHeight - menuFullHeightMax; - int minPosY = topScreenPosY; + int minPosY; + if (menu.isLandscapeLayout()) { + minPosY = topScreenPosY; + } else { + minPosY = -menuTitleHeight + menuButtonsHeight + bottomToolbarPosY; + } if (maxPosY > minPosY) { maxPosY = minPosY; } @@ -1428,7 +1436,11 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo posY = currentY; } } else { - posY = topScreenPosY; + if (menu.isLandscapeLayout()) { + posY = topScreenPosY; + } else { + posY = -menuTitleHeight + menuButtonsHeight + bottomToolbarPosY; + } } break; default: diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 00fc954770..10ba7f3379 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -806,12 +806,12 @@ public class MapControlsLayer extends OsmandMapLayer { boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode(); boolean routeDialogOpened = MapRouteInfoMenu.isVisible(); boolean trackDialogOpened = TrackDetailsMenu.isVisible(); - boolean contextMenuOpened = mapActivity.getContextMenu().shouldShowTopControls(); + boolean contextMenuOpened = !mapActivity.getContextMenu().shouldShowTopControls(); boolean showRouteCalculationControls = routePlanningMode || ((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode); - updateMyLocation(rh, routeDialogOpened || trackDialogOpened || !contextMenuOpened); + updateMyLocation(rh, routeDialogOpened || trackDialogOpened || contextMenuOpened); boolean showButtons = (showRouteCalculationControls || !routeFollowingMode) - && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode() && contextMenuOpened; + && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() && !isInPlanRouteMode() && !contextMenuOpened; //routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_gabout_dark : R.drawable.map_directions); if (rh.isFollowingMode()) { routePlanningBtn.setIconResId(R.drawable.map_start_navigation); @@ -826,18 +826,20 @@ public class MapControlsLayer extends OsmandMapLayer { routePlanningBtn.updateVisibility(showButtons); menuControl.updateVisibility(showButtons); - mapZoomIn.updateVisibility(!routeDialogOpened && contextMenuOpened); - mapZoomOut.updateVisibility(!routeDialogOpened && contextMenuOpened); - compassHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && shouldShowCompass() - && !isInMeasurementToolMode() && !isInPlanRouteMode() && contextMenuOpened); + mapZoomIn.updateVisibility(!routeDialogOpened && !contextMenuOpened); + mapZoomOut.updateVisibility(!routeDialogOpened && !contextMenuOpened); + boolean forceHideCompass = routeDialogOpened || trackDialogOpened + || isInMeasurementToolMode() || isInPlanRouteMode() || contextMenuOpened; + compassHud.forceHideCompass = forceHideCompass; + compassHud.updateVisibility(!forceHideCompass && shouldShowCompass()); if (layersHud.setIconResId(settings.getApplicationMode().getMapIconId())) { layersHud.update(app, isNight); } layersHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode() && !isInPlanRouteMode() - && contextMenuOpened); + && !contextMenuOpened); quickSearchHud.updateVisibility(!routeDialogOpened && !trackDialogOpened && !isInMeasurementToolMode() && !isInPlanRouteMode() - && contextMenuOpened); + && !contextMenuOpened); if (!routePlanningMode && !routeFollowingMode) { if (mapView.isZooming()) { @@ -854,7 +856,9 @@ public class MapControlsLayer extends OsmandMapLayer { } mapRouteInfoMenu.setVisible(showRouteCalculationControls); - updateCompass(isNight); + if (!forceHideCompass) { + updateCompass(isNight); + } for (MapHudButton mc : controls) { mc.update(mapActivity.getMyApplication(), isNight); @@ -1027,6 +1031,7 @@ public class MapControlsLayer extends OsmandMapLayer { boolean f = true; boolean compass; boolean compassOutside; + boolean forceHideCompass; ViewPropertyAnimatorCompat hideAnimator; public MapHudButton setRoundTransparent() { @@ -1088,9 +1093,10 @@ public class MapControlsLayer extends OsmandMapLayer { iv.setVisibility(View.VISIBLE); iv.invalidate(); } else if (hideAnimator == null) { - if (compass) { + if (compass && !forceHideCompass) { hideDelayed(5000); } else { + forceHideCompass = false; iv.setVisibility(View.GONE); iv.invalidate(); }