From effe5c96e3123b39713a658685e49d45250a9676 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 26 Jan 2021 18:47:33 +0200 Subject: [PATCH] Make widgets visibility in gpx menu same as in context menu --- .../osmand/plus/activities/MapActivity.java | 12 +++++- .../plus/mapcontextmenu/MapContextMenu.java | 32 ++++++++------- .../osmand/plus/track/TrackMenuFragment.java | 40 ++++++++++--------- .../plus/views/layers/MapControlsLayer.java | 12 +++--- .../mapwidgets/MapInfoWidgetsFactory.java | 4 +- .../mapwidgets/MapMarkersWidgetsFactory.java | 2 +- 6 files changed, 60 insertions(+), 42 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 316d5c36b2..0de562fa2b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -70,7 +70,6 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OnDismissDialogFragmentListener; import net.osmand.plus.OsmAndConstants; -import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmandApplication; @@ -1568,6 +1567,17 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } } + public boolean shouldHideTopControls() { + boolean hideTopControls = !mapContextMenu.shouldShowTopControls(); + + TrackMenuFragment fragment = getTrackMenuFragment(); + if (fragment != null) { + hideTopControls = hideTopControls || !fragment.shouldShowTopControls(); + } + + return hideTopControls; + } + public OsmandMapTileView getMapView() { return mapView; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index c1a6a6cc0a..cd035da4bb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -22,18 +22,17 @@ import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.TransportStop; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.mapmarkers.MapMarker; -import net.osmand.plus.mapmarkers.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPointChangedListener; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper; +import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener; import net.osmand.plus.mapcontextmenu.MenuController.ContextMenuToolbarController; import net.osmand.plus.mapcontextmenu.MenuController.MenuState; import net.osmand.plus.mapcontextmenu.MenuController.MenuType; @@ -47,12 +46,14 @@ import net.osmand.plus.mapcontextmenu.editors.RtePtEditor; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.mapcontextmenu.other.ShareMenu; -import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener; +import net.osmand.plus.mapmarkers.MapMarker; +import net.osmand.plus.mapmarkers.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.transport.TransportStopRoute; -import net.osmand.plus.views.layers.ContextMenuLayer; import net.osmand.plus.views.OsmandMapLayer; +import net.osmand.plus.views.layers.ContextMenuLayer; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.util.Algorithms; @@ -570,18 +571,21 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public void updateControlsVisibility(boolean menuVisible) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - int topControlsVisibility = shouldShowTopControls(menuVisible) ? View.VISIBLE : View.GONE; - mapActivity.findViewById(R.id.map_center_info).setVisibility(topControlsVisibility); - mapActivity.findViewById(R.id.map_left_widgets_panel).setVisibility(topControlsVisibility); - mapActivity.findViewById(R.id.map_right_widgets_panel).setVisibility(topControlsVisibility); - - int bottomControlsVisibility = shouldShowBottomControls(menuVisible) ? View.VISIBLE : View.GONE; - mapActivity.findViewById(R.id.bottom_controls_container).setVisibility(bottomControlsVisibility); - - mapActivity.refreshMap(); + boolean topControlsVisible = shouldShowTopControls(menuVisible); + boolean bottomControlsVisible = shouldShowBottomControls(menuVisible); + updateControlsVisibility(mapActivity, topControlsVisible, bottomControlsVisible); } } + public static void updateControlsVisibility(@NonNull MapActivity mapActivity, boolean topControlsVisible, boolean bottomControlsVisible) { + AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_center_info), topControlsVisible); + AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_left_widgets_panel), topControlsVisible); + AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_right_widgets_panel), topControlsVisible); + AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.bottom_controls_container), bottomControlsVisible); + + mapActivity.refreshMap(); + } + public boolean shouldShowTopControls() { return shouldShowTopControls(isVisible()); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 0e21879f85..ff7a55180d 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -270,7 +270,6 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card setupToolbar(); updateHeader(); setupButtons(view); - enterTrackAppearanceMode(); runLayoutListener(); } return view; @@ -458,7 +457,12 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override public void onContextMenuStateChanged(@NonNull ContextMenuFragment fragment, int currentMenuState, int previousMenuState) { super.onContextMenuStateChanged(fragment, currentMenuState, previousMenuState); - if (currentMenuState != MenuState.FULL_SCREEN && (currentMenuState != previousMenuState || !mapPositionAdjusted)) { + + boolean changed = currentMenuState != previousMenuState; + if (changed) { + updateControlsVisibility(true); + } + if (currentMenuState != MenuState.FULL_SCREEN && (changed || !mapPositionAdjusted)) { adjustMapPosition(getViewY()); } } @@ -466,7 +470,6 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override public void onDestroyView() { super.onDestroyView(); - exitTrackAppearanceMode(); updateStatusBarColor(); } @@ -477,6 +480,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null && trackChartPoints != null) { mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints); } + updateControlsVisibility(true); startLocationUpdate(); } @@ -487,6 +491,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null) { mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(null); } + updateControlsVisibility(false); stopLocationUpdate(); } @@ -572,26 +577,25 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card updateContent(); } - private void enterTrackAppearanceMode() { + public void updateControlsVisibility(boolean menuVisible) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); - AndroidUiHelper.setVisibility(mapActivity, portrait ? View.INVISIBLE : View.GONE, - R.id.map_left_widgets_panel, - R.id.map_right_widgets_panel, - R.id.map_center_info); + boolean topControlsVisible = shouldShowTopControls(menuVisible); + boolean bottomControlsVisible = shouldShowBottomControls(menuVisible); + MapContextMenu.updateControlsVisibility(mapActivity, topControlsVisible, bottomControlsVisible); } } - private void exitTrackAppearanceMode() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - AndroidUiHelper.setVisibility(mapActivity, View.VISIBLE, - R.id.map_left_widgets_panel, - R.id.map_right_widgets_panel, - R.id.map_center_info, - R.id.map_search_button); - } + public boolean shouldShowTopControls() { + return shouldShowTopControls(isVisible()); + } + + public boolean shouldShowTopControls(boolean menuVisible) { + return !menuVisible || !isPortrait() || getCurrentMenuState() == MenuState.HEADER_ONLY; + } + + public boolean shouldShowBottomControls(boolean menuVisible) { + return !menuVisible || !isPortrait(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java index e4fe3a484c..22eb448670 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java @@ -859,30 +859,30 @@ public class MapControlsLayer extends OsmandMapLayer { } boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode(); boolean trackDialogOpened = mapActivity.getTrackDetailsMenu().isVisible(); - boolean contextMenuOpened = !mapActivity.getContextMenu().shouldShowTopControls(); + boolean shouldHideTopControls = mapActivity.shouldHideTopControls(); boolean showRouteCalculationControls = routePlanningMode || ((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode); boolean routeDialogOpened = mapRouteInfoMenu.isVisible() || (showRouteCalculationControls && mapRouteInfoMenu.needShowMenu()); - updateMyLocationVisibility(backToLocationControl, rh, routeDialogOpened || contextMenuOpened); + updateMyLocationVisibility(backToLocationControl, rh, routeDialogOpened || shouldHideTopControls); //routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_info_dark : R.drawable.ic_action_gdirections_dark); updateRoutePlaningButton(rh, routePlanningMode); boolean showBottomMenuButtons = (showRouteCalculationControls || !routeFollowingMode) && !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() - && !isInPlanRouteMode() && !contextMenuOpened && !isInChoosingRoutesMode() + && !isInPlanRouteMode() && !shouldHideTopControls && !isInChoosingRoutesMode() && !isInWaypointsChoosingMode() && !isInFollowTrackMode() && !isInTrackAppearanceMode(); routePlanningBtn.updateVisibility(showBottomMenuButtons); menuControl.updateVisibility(showBottomMenuButtons); - boolean showZoomButtons = !routeDialogOpened && !contextMenuOpened && !isInTrackAppearanceMode() + boolean showZoomButtons = !routeDialogOpened && !shouldHideTopControls && !isInTrackAppearanceMode() && (!isInGpxApproximationMode() || !isPotrait()) && !isInFollowTrackMode() && (!isInChoosingRoutesMode() || !isInWaypointsChoosingMode() || !portrait); mapZoomIn.updateVisibility(showZoomButtons); mapZoomOut.updateVisibility(showZoomButtons); boolean forceHideCompass = routeDialogOpened || trackDialogOpened || isInMeasurementToolMode() - || isInPlanRouteMode() || contextMenuOpened || isInChoosingRoutesMode() + || isInPlanRouteMode() || shouldHideTopControls || isInChoosingRoutesMode() || isInTrackAppearanceMode() || isInWaypointsChoosingMode() || isInFollowTrackMode(); compassHud.forceHideCompass = forceHideCompass; compassHud.updateVisibility(!forceHideCompass && shouldShowCompass()); @@ -892,7 +892,7 @@ public class MapControlsLayer extends OsmandMapLayer { if (layersHud.setIconResId(appMode.getIconRes())) { layersHud.update(app, isNight); } - boolean showTopButtons = !routeDialogOpened && !trackDialogOpened && !contextMenuOpened + boolean showTopButtons = !routeDialogOpened && !trackDialogOpened && !shouldHideTopControls && !isInMeasurementToolMode() && !isInPlanRouteMode() && !isInChoosingRoutesMode() && !isInTrackAppearanceMode() && !isInWaypointsChoosingMode() && !isInFollowTrackMode(); layersHud.updateVisibility(showTopButtons); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index fca0ae429e..63c4c93ab9 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -974,7 +974,7 @@ public class MapInfoWidgetsFactory { } } } - if (map.isTopToolbarActive() || !map.getContextMenu().shouldShowTopControls() || MapRouteInfoMenu.chooseRoutesVisible || MapRouteInfoMenu.waypointsVisible) { + if (map.isTopToolbarActive() || map.shouldHideTopControls() || MapRouteInfoMenu.chooseRoutesVisible || MapRouteInfoMenu.waypointsVisible) { updateVisibility(false); } else if (showClosestWaypointFirstInAddress && updateWaypoint()) { updateVisibility(true); @@ -1232,7 +1232,7 @@ public class MapInfoWidgetsFactory { @SuppressLint("SetTextI18n") public boolean updateInfo() { - boolean visible = settings.SHOW_COORDINATES_WIDGET.get() && map.getContextMenu().shouldShowTopControls() + boolean visible = settings.SHOW_COORDINATES_WIDGET.get() && !map.shouldHideTopControls() && map.getMapRouteInfoMenu().shouldShowTopControls() && !map.isTopToolbarActive() && !map.getMapLayers().getGpxLayer().isInTrackAppearanceMode() && !MapRouteInfoMenu.chooseRoutesVisible && !MapRouteInfoMenu.waypointsVisible diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index f47c0f8bd6..ac0765cee5 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -191,7 +191,7 @@ public class MapMarkersWidgetsFactory { || map.getMapRouteInfoMenu().isVisible() || addressTopBar.getVisibility() == View.VISIBLE || map.isTopToolbarActive() - || !map.getContextMenu().shouldShowTopControls() + || map.shouldHideTopControls() || map.getMapLayers().getGpxLayer().isInTrackAppearanceMode() || map.getMapLayers().getMapMarkersLayer().isInPlanRouteMode()) { updateVisibility(false);