Map widgets visibility refactoring, part 1

This commit is contained in:
nazar-kutz 2021-03-29 20:24:06 +03:00
parent 372e4e7f49
commit 40b5220caa
7 changed files with 258 additions and 150 deletions

View file

@ -140,6 +140,7 @@ import net.osmand.plus.views.layers.MapControlsLayer;
import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.layers.MapInfoLayer;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
import net.osmand.plus.views.mapwidgets.WidgetsVisibilityHelper;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -210,6 +211,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private MapActivityActions mapActions; private MapActivityActions mapActions;
private MapActivityLayers mapLayers; private MapActivityLayers mapLayers;
private WidgetsVisibilityHelper mapWidgetsVisibilityHelper;
// App variables // App variables
private OsmandApplication app; private OsmandApplication app;
@ -305,6 +307,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
mapActions = new MapActivityActions(this); mapActions = new MapActivityActions(this);
mapLayers = new MapActivityLayers(this); mapLayers = new MapActivityLayers(this);
mapWidgetsVisibilityHelper = new WidgetsVisibilityHelper(this);
dashboardOnMap.createDashboardView(); dashboardOnMap.createDashboardView();
checkAppInitialization(); checkAppInitialization();
@ -1597,6 +1600,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return mapLayers; return mapLayers;
} }
public WidgetsVisibilityHelper getWidgetsVisibilityHelper() {
return mapWidgetsVisibilityHelper;
}
public static void launchMapActivityMoveToTop(Context activity, Bundle prevIntentParams, Uri intentData, Bundle intentParams) { public static void launchMapActivityMoveToTop(Context activity, Bundle prevIntentParams, Uri intentData, Bundle intentParams) {
if (activity instanceof MapActivity) { if (activity instanceof MapActivity) {
if (((MapActivity) activity).getDashboard().isVisible()) { if (((MapActivity) activity).getDashboard().isVisible()) {

View file

@ -13,7 +13,6 @@ import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ContextThemeWrapper; import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.content.ContextCompat;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
@ -184,7 +183,7 @@ public class MapActivityLayers {
mapControlsLayer = new MapControlsLayer(activity); mapControlsLayer = new MapControlsLayer(activity);
mapView.addLayer(mapControlsLayer, 11); mapView.addLayer(mapControlsLayer, 11);
// 12. quick actions layer // 12. quick actions layer
mapQuickActionLayer = new MapQuickActionLayer(activity, contextMenuLayer); mapQuickActionLayer = new MapQuickActionLayer(activity);
mapView.addLayer(mapQuickActionLayer, 12); mapView.addLayer(mapQuickActionLayer, 12);
contextMenuLayer.setMapQuickActionLayer(mapQuickActionLayer); contextMenuLayer.setMapQuickActionLayer(mapQuickActionLayer);
mapControlsLayer.setMapQuickActionLayer(mapQuickActionLayer); mapControlsLayer.setMapQuickActionLayer(mapQuickActionLayer);

View file

@ -71,6 +71,7 @@ import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.corenative.NativeCoreContext; import net.osmand.plus.views.corenative.NativeCoreContext;
import net.osmand.plus.views.mapwidgets.WidgetsVisibilityHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -851,47 +852,36 @@ public class MapControlsLayer extends OsmandMapLayer {
// TODOnightMode // TODOnightMode
// updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls); // updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls);
// default buttons // default buttons
boolean routePlanningMode = false;
RoutingHelper rh = mapActivity.getRoutingHelper(); RoutingHelper rh = mapActivity.getRoutingHelper();
if (rh.isRoutePlanningMode()) { WidgetsVisibilityHelper vh = mapActivity.getWidgetsVisibilityHelper();
routePlanningMode = true;
} else if ((rh.isRouteCalculated() || rh.isRouteBeingCalculated()) && !rh.isFollowingMode()) { boolean routePlanningMode = isInRoutePlanningMode();
routePlanningMode = true;
}
boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode(); boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode();
boolean trackDialogOpened = mapActivity.getTrackDetailsMenu().isVisible(); boolean trackDialogOpened = mapActivity.getTrackDetailsMenu().isVisible();
boolean shouldHideTopControls = mapActivity.shouldHideTopControls(); boolean shouldHideTopControls = mapActivity.shouldHideTopControls();
boolean showRouteCalculationControls = routePlanningMode || boolean showRouteCalculationControls = routePlanningMode ||
((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode); ((app.accessibilityEnabled() || (System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS)) && routeFollowingMode);
boolean routeDialogOpened = mapRouteInfoMenu.isVisible() || (showRouteCalculationControls && mapRouteInfoMenu.needShowMenu()); boolean routeDialogOpened = mapRouteInfoMenu.isVisible() || (showRouteCalculationControls && mapRouteInfoMenu.needShowMenu());
updateMyLocationVisibility(backToLocationControl, rh, routeDialogOpened || shouldHideTopControls);
//routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_info_dark : R.drawable.ic_action_gdirections_dark);
boolean dialogOpened = routeDialogOpened || shouldHideTopControls;
boolean showBackToLocation = mapActivity.getWidgetsVisibilityHelper().shouldShowBackToLocationButton();
backToLocationControl.updateVisibility(!dialogOpened && showBackToLocation);
//routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_info_dark : R.drawable.ic_action_gdirections_dark);
updateRoutePlaningButton(rh, routePlanningMode); updateRoutePlaningButton(rh, routePlanningMode);
boolean showBottomMenuButtons = (showRouteCalculationControls || !routeFollowingMode) boolean showBottomMenuButtons =
&& !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode() (showRouteCalculationControls || !routeFollowingMode) && vh.shouldShowBottomMenuButtons();
&& !isInPlanRouteMode() && !shouldHideTopControls && !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode() && !isInFollowTrackMode() && !isInTrackAppearanceMode()
&& !isInRouteLineAppearanceMode();
routePlanningBtn.updateVisibility(showBottomMenuButtons); routePlanningBtn.updateVisibility(showBottomMenuButtons);
menuControl.updateVisibility(showBottomMenuButtons); menuControl.updateVisibility(showBottomMenuButtons);
boolean additionalDialogsHide = !isInGpxApproximationMode()
&& !isInTrackAppearanceMode() boolean showZoomButtons = !routeDialogOpened && !shouldHideTopControls && vh.shouldShowZoomButtons();
&& !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode()
&& !isInRouteLineAppearanceMode();
boolean showZoomButtons = !routeDialogOpened && !shouldHideTopControls
&& !isInFollowTrackMode()
&& (additionalDialogsHide || !portrait);
mapZoomIn.updateVisibility(showZoomButtons); mapZoomIn.updateVisibility(showZoomButtons);
mapZoomOut.updateVisibility(showZoomButtons); mapZoomOut.updateVisibility(showZoomButtons);
boolean forceHideCompass = routeDialogOpened || trackDialogOpened || isInMeasurementToolMode() boolean forceHideCompass = routeDialogOpened || trackDialogOpened || vh.shouldHideCompass();
|| isInPlanRouteMode() || shouldHideTopControls || isInChoosingRoutesMode()
|| isInTrackAppearanceMode() || isInWaypointsChoosingMode() || isInFollowTrackMode()
|| isInRouteLineAppearanceMode();
compassHud.forceHideCompass = forceHideCompass; compassHud.forceHideCompass = forceHideCompass;
compassHud.updateVisibility(!forceHideCompass && shouldShowCompass()); compassHud.updateVisibility(!forceHideCompass && shouldShowCompass());
@ -900,10 +890,8 @@ public class MapControlsLayer extends OsmandMapLayer {
if (layersHud.setIconResId(appMode.getIconRes())) { if (layersHud.setIconResId(appMode.getIconRes())) {
layersHud.update(app, isNight); layersHud.update(app, isNight);
} }
boolean showTopButtons = !routeDialogOpened && !trackDialogOpened && !shouldHideTopControls boolean showTopButtons = !routeDialogOpened && !trackDialogOpened
&& !isInMeasurementToolMode() && !isInPlanRouteMode() && !isInChoosingRoutesMode() && !shouldHideTopControls && vh.shouldShowTopButtons();
&& !isInTrackAppearanceMode() && !isInWaypointsChoosingMode() && !isInFollowTrackMode()
&& !isInRouteLineAppearanceMode();
layersHud.updateVisibility(showTopButtons); layersHud.updateVisibility(showTopButtons);
quickSearchHud.updateVisibility(showTopButtons); quickSearchHud.updateVisibility(showTopButtons);
@ -1026,19 +1014,6 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
} }
public void updateMyLocationVisibility(MapHudButton backToLocationControl, RoutingHelper rh, boolean dialogOpened) {
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
boolean visible = !(tracked && rh.isFollowingMode());
boolean additionalDialogsHide = !isInTrackAppearanceMode()
&& !isInGpxApproximationMode()
&& !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode()
&& !isInFollowTrackMode()
&& !isInRouteLineAppearanceMode();
backToLocationControl.updateVisibility(visible && !dialogOpened && !isInPlanRouteMode()
&& (additionalDialogsHide || !isPotrait()));
}
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
return mapRouteInfoMenu.onSingleTap(point, tileBox); return mapRouteInfoMenu.onSingleTap(point, tileBox);
} }
@ -1365,49 +1340,11 @@ public class MapControlsLayer extends OsmandMapLayer {
this.mapQuickActionLayer = mapQuickActionLayer; this.mapQuickActionLayer = mapQuickActionLayer;
} }
private boolean isInMovingMarkerMode() { private boolean isInRoutePlanningMode() {
return mapQuickActionLayer == null ? contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxPointMode() : RoutingHelper routingHelper = mapActivity.getRoutingHelper();
mapQuickActionLayer.isInMovingMarkerMode() || contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxPointMode(); return routingHelper.isRoutePlanningMode()
} || ((routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())
&& !routingHelper.isFollowingMode());
private boolean isInGpxDetailsMode() {
return contextMenuLayer.isInGpxDetailsMode();
}
private boolean isInMeasurementToolMode() {
return mapActivity.getMapLayers().getMeasurementToolLayer().isInMeasurementMode();
}
private boolean isInPlanRouteMode() {
return mapActivity.getMapLayers().getMapMarkersLayer().isInPlanRouteMode();
}
private boolean isInTrackAppearanceMode() {
return mapActivity.getMapLayers().getGpxLayer().isInTrackAppearanceMode();
}
private boolean isInGpxApproximationMode() {
return mapActivity.getMapLayers().getMeasurementToolLayer().isTapsDisabled();
}
public boolean isInTrackMenuMode() {
return mapActivity.getTrackMenuFragment() != null && mapActivity.getTrackMenuFragment().isVisible();
}
private boolean isInChoosingRoutesMode() {
return MapRouteInfoMenu.chooseRoutesVisible;
}
private boolean isInWaypointsChoosingMode() {
return MapRouteInfoMenu.waypointsVisible;
}
private boolean isInRouteLineAppearanceMode() {
return mapActivity.getMapLayers().getRouteLayer().isInRouteLineAppearanceMode();
}
private boolean isInFollowTrackMode() {
return MapRouteInfoMenu.followTrackVisible;
} }
public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) { public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) {

View file

@ -19,7 +19,6 @@ import android.widget.ImageView;
import androidx.annotation.DimenRes; import androidx.annotation.DimenRes;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.util.Pair; import androidx.core.util.Pair;
import androidx.fragment.app.Fragment;
import com.getkeepsafe.taptargetview.TapTarget; import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView; import com.getkeepsafe.taptargetview.TapTargetView;
@ -33,18 +32,13 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.MapContextMenuFragment;
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
import net.osmand.plus.measurementtool.MeasurementToolLayer;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.quickaction.QuickActionsWidget; import net.osmand.plus.quickaction.QuickActionsWidget;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -56,12 +50,6 @@ import static net.osmand.plus.views.layers.ContextMenuLayer.VIBRATE_SHORT;
public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRegistry.QuickActionUpdatesListener, QuickAction.QuickActionSelectionListener { public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRegistry.QuickActionUpdatesListener, QuickAction.QuickActionSelectionListener {
private final ContextMenuLayer contextMenuLayer;
private final MeasurementToolLayer measurementToolLayer;
private final MapMarkersLayer mapMarkersLayer;
private final MapControlsLayer mapControlsLayer;
private final GPXLayer gpxLayer;
private final RouteLayer routeLayer;
private ImageView contextMarker; private ImageView contextMarker;
private final MapActivity mapActivity; private final MapActivity mapActivity;
private final OsmandApplication app; private final OsmandApplication app;
@ -81,17 +69,11 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
private boolean nightMode; private boolean nightMode;
private Boolean currentWidgetState; private Boolean currentWidgetState;
public MapQuickActionLayer(MapActivity activity, ContextMenuLayer contextMenuLayer) { public MapQuickActionLayer(MapActivity activity) {
this.mapActivity = activity; this.mapActivity = activity;
this.contextMenuLayer = contextMenuLayer;
app = activity.getMyApplication(); app = activity.getMyApplication();
settings = activity.getMyApplication().getSettings(); settings = activity.getMyApplication().getSettings();
quickActionRegistry = app.getQuickActionRegistry(); quickActionRegistry = app.getQuickActionRegistry();
measurementToolLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
mapMarkersLayer = mapActivity.getMapLayers().getMapMarkersLayer();
gpxLayer = mapActivity.getMapLayers().getGpxLayer();
mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer();
routeLayer = mapActivity.getMapLayers().getRouteLayer();
} }
@Override @Override
@ -415,29 +397,8 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
} }
private void setupQuickActionBtnVisibility() { private void setupQuickActionBtnVisibility() {
MapContextMenu contextMenu = mapActivity.getContextMenu(); boolean visible = mapActivity.getWidgetsVisibilityHelper().shouldShowQuickActionButton();
MapRouteInfoMenu mapRouteInfoMenu = mapActivity.getMapRouteInfoMenu(); quickActionButton.setVisibility(visible ? View.VISIBLE : View.GONE);
MapMultiSelectionMenu multiSelectionMenu = contextMenu.getMultiSelectionMenu();
WeakReference<MapContextMenuFragment> contextMenuMenuFragmentRef = contextMenu.findMenuFragment();
MapContextMenuFragment contextMenuMenuFragment = contextMenuMenuFragmentRef != null ? contextMenuMenuFragmentRef.get() : null;
Fragment multiMenuFragment = multiSelectionMenu.getFragmentByTag();
boolean hideQuickButton = !isLayerOn ||
contextMenuLayer.isInChangeMarkerPositionMode() ||
contextMenuLayer.isInGpxDetailsMode() ||
measurementToolLayer.isInMeasurementMode() ||
mapMarkersLayer.isInPlanRouteMode() ||
gpxLayer.isInTrackAppearanceMode() ||
mapControlsLayer.isInTrackMenuMode() ||
routeLayer.isInRouteLineAppearanceMode() ||
mapRouteInfoMenu.isVisible() ||
MapRouteInfoMenu.chooseRoutesVisible ||
MapRouteInfoMenu.waypointsVisible ||
MapRouteInfoMenu.followTrackVisible ||
contextMenu.isVisible() && contextMenuMenuFragment != null && !contextMenuMenuFragment.isRemoving() ||
contextMenu.isVisible() && contextMenuMenuFragment != null && contextMenuMenuFragment.isAdded() ||
multiSelectionMenu.isVisible() && multiMenuFragment != null && multiMenuFragment.isAdded() ||
multiSelectionMenu.isVisible() && multiMenuFragment != null && !multiMenuFragment.isRemoving();
quickActionButton.setVisibility(hideQuickButton ? View.GONE : View.VISIBLE);
} }
@Override @Override

View file

@ -1204,13 +1204,7 @@ public class MapInfoWidgetsFactory {
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
public boolean updateInfo() { public boolean updateInfo() {
boolean visible = settings.SHOW_COORDINATES_WIDGET.get() && !map.shouldHideTopControls() boolean visible = map.getWidgetsVisibilityHelper().shouldShowTopCoordinatesWidget();
&& map.getMapRouteInfoMenu().shouldShowTopControls() && !map.isTopToolbarActive()
&& !map.getMapLayers().getGpxLayer().isInTrackAppearanceMode()
&& !map.getMapLayers().getRouteLayer().isInRouteLineAppearanceMode()
&& !MapRouteInfoMenu.chooseRoutesVisible && !MapRouteInfoMenu.waypointsVisible
&& !MapRouteInfoMenu.followTrackVisible;
updateVisibility(visible); updateVisibility(visible);
if (visible) { if (visible) {
lastKnownLocation = locationProvider.getLastKnownLocation(); lastKnownLocation = locationProvider.getLastKnownLocation();

View file

@ -36,7 +36,6 @@ public class MapMarkersWidgetsFactory {
private boolean portraitMode; private boolean portraitMode;
private View topBar; private View topBar;
private View addressTopBar;
private View topBar2nd; private View topBar2nd;
private View rowView; private View rowView;
private View rowView2nd; private View rowView2nd;
@ -60,7 +59,6 @@ public class MapMarkersWidgetsFactory {
helper = map.getMyApplication().getMapMarkersHelper(); helper = map.getMyApplication().getMapMarkersHelper();
portraitMode = AndroidUiHelper.isOrientationPortrait(map); portraitMode = AndroidUiHelper.isOrientationPortrait(map);
addressTopBar = map.findViewById(R.id.map_top_bar);
topBar = map.findViewById(R.id.map_markers_top_bar); topBar = map.findViewById(R.id.map_markers_top_bar);
topBar2nd = map.findViewById(R.id.map_markers_top_bar_2nd); topBar2nd = map.findViewById(R.id.map_markers_top_bar_2nd);
rowView = map.findViewById(R.id.map_marker_row); rowView = map.findViewById(R.id.map_marker_row);
@ -181,18 +179,8 @@ public class MapMarkersWidgetsFactory {
} }
List<MapMarker> markers = helper.getMapMarkers(); List<MapMarker> markers = helper.getMapMarkers();
if (zoom < 3 || markers.size() == 0 WidgetsVisibilityHelper vh = map.getWidgetsVisibilityHelper();
|| !map.getMyApplication().getSettings().MARKERS_DISTANCE_INDICATION_ENABLED.get() if (zoom < 3 || markers.size() == 0 || vh.shouldHideMapMarkersWidget()) {
|| !map.getMyApplication().getSettings().MAP_MARKERS_MODE.get().isToolbar()
|| map.getMyApplication().getRoutingHelper().isFollowingMode()
|| map.getMyApplication().getRoutingHelper().isRoutePlanningMode()
|| map.getMapRouteInfoMenu().isVisible()
|| addressTopBar.getVisibility() == View.VISIBLE
|| map.isTopToolbarActive()
|| map.shouldHideTopControls()
|| map.getMapLayers().getGpxLayer().isInTrackAppearanceMode()
|| map.getMapLayers().getMapMarkersLayer().isInPlanRouteMode()
|| map.getMapLayers().getRouteLayer().isInRouteLineAppearanceMode()) {
updateVisibility(false); updateVisibility(false);
return; return;
} }

View file

@ -0,0 +1,222 @@
package net.osmand.plus.views.mapwidgets;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.MapContextMenuFragment;
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.layers.MapQuickActionLayer;
import java.lang.ref.WeakReference;
public class WidgetsVisibilityHelper {
private MapActivity mapActivity;
private OsmandSettings settings;
private RoutingHelper routingHelper;
public WidgetsVisibilityHelper(@NonNull MapActivity mapActivity) {
this.mapActivity = mapActivity;
this.settings = mapActivity.getMyApplication().getSettings();
this.routingHelper = mapActivity.getRoutingHelper();
}
public boolean shouldShowQuickActionButton() {
return isQuickActionLayerOn()
&& !isInChangeMarkerPositionMode()
&& !isInGpxDetailsMode()
&& !isInMeasurementToolMode()
&& !isInPlanRouteMode()
&& !isInTrackAppearanceMode()
&& !isInTrackMenuMode()
&& !isInRouteLineAppearanceMode()
&& !isMapRouteInfoMenuVisible()
&& !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode()
&& !isInFollowTrackMode()
&& !isContextMenuFragmentVisible()
&& !isMultiSelectionMenuFragmentVisible();
}
public boolean shouldShowTopCoordinatesWidget() {
return settings.SHOW_COORDINATES_WIDGET.get()
&& !mapActivity.shouldHideTopControls()
&& mapActivity.getMapRouteInfoMenu().shouldShowTopControls()
&& !mapActivity.isTopToolbarActive()
&& !isInTrackAppearanceMode()
&& !isInRouteLineAppearanceMode()
&& !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode()
&& !isInFollowTrackMode();
}
public boolean shouldHideMapMarkersWidget() {
View addressTopBar = mapActivity.findViewById(R.id.map_top_bar);
return !settings.MARKERS_DISTANCE_INDICATION_ENABLED.get()
|| !settings.MAP_MARKERS_MODE.get().isToolbar()
|| addressTopBar != null && addressTopBar.getVisibility() == View.VISIBLE
|| routingHelper.isFollowingMode()
|| routingHelper.isRoutePlanningMode()
|| isMapRouteInfoMenuVisible()
|| mapActivity.isTopToolbarActive()
|| mapActivity.shouldHideTopControls()
|| isInTrackAppearanceMode()
|| isInPlanRouteMode()
|| isInRouteLineAppearanceMode();
}
public boolean shouldShowBottomMenuButtons() {
return !mapActivity.shouldHideTopControls()
&& !isInMovingMarkerMode()
&& !isInGpxDetailsMode()
&& !isInMeasurementToolMode()
&& !isInPlanRouteMode()
&& !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode()
&& !isInFollowTrackMode()
&& !isInTrackAppearanceMode()
&& !isInRouteLineAppearanceMode();
}
public boolean shouldShowZoomButtons() {
boolean additionalDialogsHide = !isInGpxApproximationMode()
&& !isInTrackAppearanceMode()
&& !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode()
&& !isInRouteLineAppearanceMode();
return !isInFollowTrackMode() && (additionalDialogsHide || !isPortrait());
}
public boolean shouldHideCompass() {
return mapActivity.shouldHideTopControls()
|| isInMeasurementToolMode()
|| isInPlanRouteMode()
|| isInChoosingRoutesMode()
|| isInTrackAppearanceMode()
|| isInWaypointsChoosingMode()
|| isInFollowTrackMode()
|| isInRouteLineAppearanceMode();
}
public boolean shouldShowTopButtons() {
return !isInMeasurementToolMode()
&& !isInPlanRouteMode()
&& !isInChoosingRoutesMode()
&& !isInTrackAppearanceMode()
&& !isInWaypointsChoosingMode()
&& !isInFollowTrackMode()
&& !isInRouteLineAppearanceMode();
}
public boolean shouldShowBackToLocationButton() {
boolean additionalDialogsHide = !isInTrackAppearanceMode()
&& !isInGpxApproximationMode()
&& !isInChoosingRoutesMode()
&& !isInWaypointsChoosingMode()
&& !isInFollowTrackMode()
&& !isInRouteLineAppearanceMode();
return !isInPlanRouteMode()
&& !(isMapLinkedToLocation() && routingHelper.isFollowingMode())
&& (additionalDialogsHide || !isPortrait());
}
private boolean isQuickActionLayerOn() {
return mapActivity.getMapLayers().getMapQuickActionLayer().isLayerOn();
}
private boolean isMapRouteInfoMenuVisible() {
return mapActivity.getMapRouteInfoMenu().isVisible();
}
private boolean isInMovingMarkerMode() {
MapQuickActionLayer quickActionLayer = mapActivity.getMapLayers().getMapQuickActionLayer();
boolean isInMovingMarkerMode = quickActionLayer != null && quickActionLayer.isInMovingMarkerMode();
return isInMovingMarkerMode || isInChangeMarkerPositionMode() || isInAddGpxPointMode();
}
private boolean isInGpxDetailsMode() {
return mapActivity.getMapLayers().getContextMenuLayer().isInGpxDetailsMode();
}
private boolean isInAddGpxPointMode() {
return mapActivity.getMapLayers().getContextMenuLayer().isInAddGpxPointMode();
}
private boolean isInChangeMarkerPositionMode() {
return mapActivity.getMapLayers().getContextMenuLayer().isInChangeMarkerPositionMode();
}
private boolean isInMeasurementToolMode() {
return mapActivity.getMapLayers().getMeasurementToolLayer().isInMeasurementMode();
}
private boolean isInPlanRouteMode() {
return mapActivity.getMapLayers().getMapMarkersLayer().isInPlanRouteMode();
}
private boolean isInTrackAppearanceMode() {
return mapActivity.getMapLayers().getGpxLayer().isInTrackAppearanceMode();
}
private boolean isInGpxApproximationMode() {
return mapActivity.getMapLayers().getMeasurementToolLayer().isTapsDisabled();
}
public boolean isInTrackMenuMode() {
return mapActivity.getTrackMenuFragment() != null && mapActivity.getTrackMenuFragment().isVisible();
}
private boolean isInChoosingRoutesMode() {
return MapRouteInfoMenu.chooseRoutesVisible;
}
private boolean isInWaypointsChoosingMode() {
return MapRouteInfoMenu.waypointsVisible;
}
private boolean isInRouteLineAppearanceMode() {
return mapActivity.getMapLayers().getRouteLayer().isInRouteLineAppearanceMode();
}
private boolean isInFollowTrackMode() {
return MapRouteInfoMenu.followTrackVisible;
}
private boolean isContextMenuFragmentVisible() {
MapContextMenu contextMenu = mapActivity.getContextMenu();
WeakReference<MapContextMenuFragment> contextMenuMenuFragmentRef = contextMenu.findMenuFragment();
MapContextMenuFragment contextMenuMenuFragment = contextMenuMenuFragmentRef != null ? contextMenuMenuFragmentRef.get() : null;
if (contextMenuMenuFragment != null && contextMenu.isVisible()) {
return !contextMenuMenuFragment.isRemoving() || contextMenuMenuFragment.isAdded();
}
return false;
}
private boolean isMultiSelectionMenuFragmentVisible() {
MapContextMenu contextMenu = mapActivity.getContextMenu();
MapMultiSelectionMenu multiSelectionMenu = contextMenu.getMultiSelectionMenu();
Fragment multiMenuFragment = multiSelectionMenu.getFragmentByTag();
if (multiMenuFragment != null && multiSelectionMenu.isVisible()) {
return multiMenuFragment.isAdded() || !multiMenuFragment.isRemoving();
}
return false;
}
private boolean isMapLinkedToLocation() {
return mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
}
private boolean isPortrait() {
return AndroidUiHelper.isOrientationPortrait(mapActivity);
}
}