Merge pull request #11283 from osmandapp/MapWidgetsRefactoring
Map widgets visibility refactoring
This commit is contained in:
commit
bc249018e3
7 changed files with 273 additions and 158 deletions
|
@ -140,6 +140,7 @@ import net.osmand.plus.views.layers.MapControlsLayer;
|
|||
import net.osmand.plus.views.layers.MapInfoLayer;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
|
||||
import net.osmand.plus.views.mapwidgets.WidgetsVisibilityHelper;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -210,6 +211,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
|
||||
private MapActivityActions mapActions;
|
||||
private MapActivityLayers mapLayers;
|
||||
private WidgetsVisibilityHelper mapWidgetsVisibilityHelper;
|
||||
|
||||
// App variables
|
||||
private OsmandApplication app;
|
||||
|
@ -305,6 +307,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
mapActions = new MapActivityActions(this);
|
||||
mapLayers = new MapActivityLayers(this);
|
||||
mapWidgetsVisibilityHelper = new WidgetsVisibilityHelper(this);
|
||||
dashboardOnMap.createDashboardView();
|
||||
checkAppInitialization();
|
||||
|
||||
|
@ -1597,6 +1600,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
return mapLayers;
|
||||
}
|
||||
|
||||
public WidgetsVisibilityHelper getWidgetsVisibilityHelper() {
|
||||
return mapWidgetsVisibilityHelper;
|
||||
}
|
||||
|
||||
public static void launchMapActivityMoveToTop(Context activity, Bundle prevIntentParams, Uri intentData, Bundle intentParams) {
|
||||
if (activity instanceof MapActivity) {
|
||||
if (((MapActivity) activity).getDashboard().isVisible()) {
|
||||
|
|
|
@ -13,7 +13,6 @@ import android.widget.Toast;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
|
@ -184,7 +183,7 @@ public class MapActivityLayers {
|
|||
mapControlsLayer = new MapControlsLayer(activity);
|
||||
mapView.addLayer(mapControlsLayer, 11);
|
||||
// 12. quick actions layer
|
||||
mapQuickActionLayer = new MapQuickActionLayer(activity, contextMenuLayer);
|
||||
mapQuickActionLayer = new MapQuickActionLayer(activity);
|
||||
mapView.addLayer(mapQuickActionLayer, 12);
|
||||
contextMenuLayer.setMapQuickActionLayer(mapQuickActionLayer);
|
||||
mapControlsLayer.setMapQuickActionLayer(mapQuickActionLayer);
|
||||
|
|
|
@ -71,6 +71,7 @@ import net.osmand.plus.settings.backend.OsmandSettings;
|
|||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.corenative.NativeCoreContext;
|
||||
import net.osmand.plus.views.mapwidgets.WidgetsVisibilityHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
@ -851,47 +852,31 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
// TODOnightMode
|
||||
// updatextColor(textColor, shadw, rulerControl, zoomControls, mapMenuControls);
|
||||
// default buttons
|
||||
boolean routePlanningMode = false;
|
||||
|
||||
RoutingHelper rh = mapActivity.getRoutingHelper();
|
||||
if (rh.isRoutePlanningMode()) {
|
||||
routePlanningMode = true;
|
||||
} else if ((rh.isRouteCalculated() || rh.isRouteBeingCalculated()) && !rh.isFollowingMode()) {
|
||||
routePlanningMode = true;
|
||||
}
|
||||
boolean routeFollowingMode = !routePlanningMode && rh.isFollowingMode();
|
||||
boolean trackDialogOpened = mapActivity.getTrackDetailsMenu().isVisible();
|
||||
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 || shouldHideTopControls);
|
||||
//routePlanningBtn.setIconResId(routeFollowingMode ? R.drawable.ic_action_info_dark : R.drawable.ic_action_gdirections_dark);
|
||||
WidgetsVisibilityHelper vh = mapActivity.getWidgetsVisibilityHelper();
|
||||
|
||||
updateRoutePlaningButton(rh, routePlanningMode);
|
||||
boolean isRoutePlanningMode = isInRoutePlanningMode();
|
||||
boolean isRouteFollowingMode = !isRoutePlanningMode && rh.isFollowingMode();
|
||||
boolean isTimeToShowButtons = System.currentTimeMillis() - touchEvent < TIMEOUT_TO_SHOW_BUTTONS;
|
||||
boolean shouldShowRouteCalculationControls = isRoutePlanningMode || ((app.accessibilityEnabled() || isTimeToShowButtons) && isRouteFollowingMode);
|
||||
boolean isRouteDialogOpened = mapRouteInfoMenu.isVisible() || (shouldShowRouteCalculationControls && mapRouteInfoMenu.needShowMenu());
|
||||
|
||||
boolean showBottomMenuButtons = (showRouteCalculationControls || !routeFollowingMode)
|
||||
&& !isInMovingMarkerMode() && !isInGpxDetailsMode() && !isInMeasurementToolMode()
|
||||
&& !isInPlanRouteMode() && !shouldHideTopControls && !isInChoosingRoutesMode()
|
||||
&& !isInWaypointsChoosingMode() && !isInFollowTrackMode() && !isInTrackAppearanceMode()
|
||||
&& !isInRouteLineAppearanceMode();
|
||||
boolean showBackToLocation = !isRouteDialogOpened && vh.shouldShowBackToLocationButton();
|
||||
backToLocationControl.updateVisibility(showBackToLocation);
|
||||
|
||||
//routePlanningBtn.setIconResId(isRouteFollowingMode ? R.drawable.ic_action_info_dark : R.drawable.ic_action_gdirections_dark);
|
||||
updateRoutePlaningButton(rh, isRoutePlanningMode);
|
||||
|
||||
boolean showBottomMenuButtons = (shouldShowRouteCalculationControls || !isRouteFollowingMode) && vh.shouldShowBottomMenuButtons();
|
||||
routePlanningBtn.updateVisibility(showBottomMenuButtons);
|
||||
menuControl.updateVisibility(showBottomMenuButtons);
|
||||
|
||||
boolean additionalDialogsHide = !isInGpxApproximationMode()
|
||||
&& !isInTrackAppearanceMode()
|
||||
&& !isInChoosingRoutesMode()
|
||||
&& !isInWaypointsChoosingMode()
|
||||
&& !isInRouteLineAppearanceMode();
|
||||
boolean showZoomButtons = !routeDialogOpened && !shouldHideTopControls
|
||||
&& !isInFollowTrackMode()
|
||||
&& (additionalDialogsHide || !portrait);
|
||||
boolean showZoomButtons = !isRouteDialogOpened && vh.shouldShowZoomButtons();
|
||||
mapZoomIn.updateVisibility(showZoomButtons);
|
||||
mapZoomOut.updateVisibility(showZoomButtons);
|
||||
|
||||
boolean forceHideCompass = routeDialogOpened || trackDialogOpened || isInMeasurementToolMode()
|
||||
|| isInPlanRouteMode() || shouldHideTopControls || isInChoosingRoutesMode()
|
||||
|| isInTrackAppearanceMode() || isInWaypointsChoosingMode() || isInFollowTrackMode()
|
||||
|| isInRouteLineAppearanceMode();
|
||||
boolean forceHideCompass = isRouteDialogOpened || vh.shouldHideCompass();
|
||||
compassHud.forceHideCompass = forceHideCompass;
|
||||
compassHud.updateVisibility(!forceHideCompass && shouldShowCompass());
|
||||
|
||||
|
@ -900,10 +885,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
if (layersHud.setIconResId(appMode.getIconRes())) {
|
||||
layersHud.update(app, isNight);
|
||||
}
|
||||
boolean showTopButtons = !routeDialogOpened && !trackDialogOpened && !shouldHideTopControls
|
||||
&& !isInMeasurementToolMode() && !isInPlanRouteMode() && !isInChoosingRoutesMode()
|
||||
&& !isInTrackAppearanceMode() && !isInWaypointsChoosingMode() && !isInFollowTrackMode()
|
||||
&& !isInRouteLineAppearanceMode();
|
||||
boolean showTopButtons = !isRouteDialogOpened && vh.shouldShowTopButtons();
|
||||
layersHud.updateVisibility(showTopButtons);
|
||||
quickSearchHud.updateVisibility(showTopButtons);
|
||||
|
||||
|
@ -918,7 +900,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
zoomText.setText(getZoomLevel(tileBox));
|
||||
}
|
||||
|
||||
mapRouteInfoMenu.setVisible(showRouteCalculationControls);
|
||||
mapRouteInfoMenu.setVisible(shouldShowRouteCalculationControls);
|
||||
if (!forceHideCompass) {
|
||||
updateCompass(isNight);
|
||||
}
|
||||
|
@ -1026,19 +1008,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) {
|
||||
return mapRouteInfoMenu.onSingleTap(point, tileBox);
|
||||
}
|
||||
|
@ -1365,49 +1334,11 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
this.mapQuickActionLayer = mapQuickActionLayer;
|
||||
}
|
||||
|
||||
private boolean isInMovingMarkerMode() {
|
||||
return mapQuickActionLayer == null ? contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxPointMode() :
|
||||
mapQuickActionLayer.isInMovingMarkerMode() || contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxPointMode();
|
||||
}
|
||||
|
||||
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;
|
||||
private boolean isInRoutePlanningMode() {
|
||||
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
|
||||
return routingHelper.isRoutePlanningMode()
|
||||
|| ((routingHelper.isRouteCalculated() || routingHelper.isRouteBeingCalculated())
|
||||
&& !routingHelper.isFollowingMode());
|
||||
}
|
||||
|
||||
public static View.OnLongClickListener getOnClickMagnifierListener(final OsmandMapTileView view) {
|
||||
|
|
|
@ -19,7 +19,6 @@ import android.widget.ImageView;
|
|||
import androidx.annotation.DimenRes;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
import androidx.core.util.Pair;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.getkeepsafe.taptargetview.TapTarget;
|
||||
import com.getkeepsafe.taptargetview.TapTargetView;
|
||||
|
@ -33,18 +32,13 @@ 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.measurementtool.MeasurementToolLayer;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.quickaction.QuickActionRegistry;
|
||||
import net.osmand.plus.quickaction.QuickActionsWidget;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
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 {
|
||||
|
||||
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 final MapActivity mapActivity;
|
||||
private final OsmandApplication app;
|
||||
|
@ -81,17 +69,11 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
private boolean nightMode;
|
||||
private Boolean currentWidgetState;
|
||||
|
||||
public MapQuickActionLayer(MapActivity activity, ContextMenuLayer contextMenuLayer) {
|
||||
public MapQuickActionLayer(MapActivity activity) {
|
||||
this.mapActivity = activity;
|
||||
this.contextMenuLayer = contextMenuLayer;
|
||||
app = activity.getMyApplication();
|
||||
settings = activity.getMyApplication().getSettings();
|
||||
quickActionRegistry = app.getQuickActionRegistry();
|
||||
measurementToolLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
|
||||
mapMarkersLayer = mapActivity.getMapLayers().getMapMarkersLayer();
|
||||
gpxLayer = mapActivity.getMapLayers().getGpxLayer();
|
||||
mapControlsLayer = mapActivity.getMapLayers().getMapControlsLayer();
|
||||
routeLayer = mapActivity.getMapLayers().getRouteLayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -415,29 +397,8 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
}
|
||||
|
||||
private void setupQuickActionBtnVisibility() {
|
||||
MapContextMenu contextMenu = mapActivity.getContextMenu();
|
||||
MapRouteInfoMenu mapRouteInfoMenu = mapActivity.getMapRouteInfoMenu();
|
||||
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);
|
||||
boolean visible = mapActivity.getWidgetsVisibilityHelper().shouldShowQuickActionButton();
|
||||
quickActionButton.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1204,13 +1204,7 @@ public class MapInfoWidgetsFactory {
|
|||
|
||||
@SuppressLint("SetTextI18n")
|
||||
public boolean updateInfo() {
|
||||
boolean visible = settings.SHOW_COORDINATES_WIDGET.get() && !map.shouldHideTopControls()
|
||||
&& map.getMapRouteInfoMenu().shouldShowTopControls() && !map.isTopToolbarActive()
|
||||
&& !map.getMapLayers().getGpxLayer().isInTrackAppearanceMode()
|
||||
&& !map.getMapLayers().getRouteLayer().isInRouteLineAppearanceMode()
|
||||
&& !MapRouteInfoMenu.chooseRoutesVisible && !MapRouteInfoMenu.waypointsVisible
|
||||
&& !MapRouteInfoMenu.followTrackVisible;
|
||||
|
||||
boolean visible = map.getWidgetsVisibilityHelper().shouldShowTopCoordinatesWidget();
|
||||
updateVisibility(visible);
|
||||
if (visible) {
|
||||
lastKnownLocation = locationProvider.getLastKnownLocation();
|
||||
|
|
|
@ -36,7 +36,6 @@ public class MapMarkersWidgetsFactory {
|
|||
private boolean portraitMode;
|
||||
|
||||
private View topBar;
|
||||
private View addressTopBar;
|
||||
private View topBar2nd;
|
||||
private View rowView;
|
||||
private View rowView2nd;
|
||||
|
@ -60,7 +59,6 @@ public class MapMarkersWidgetsFactory {
|
|||
helper = map.getMyApplication().getMapMarkersHelper();
|
||||
portraitMode = AndroidUiHelper.isOrientationPortrait(map);
|
||||
|
||||
addressTopBar = map.findViewById(R.id.map_top_bar);
|
||||
topBar = map.findViewById(R.id.map_markers_top_bar);
|
||||
topBar2nd = map.findViewById(R.id.map_markers_top_bar_2nd);
|
||||
rowView = map.findViewById(R.id.map_marker_row);
|
||||
|
@ -181,18 +179,8 @@ public class MapMarkersWidgetsFactory {
|
|||
}
|
||||
|
||||
List<MapMarker> markers = helper.getMapMarkers();
|
||||
if (zoom < 3 || markers.size() == 0
|
||||
|| !map.getMyApplication().getSettings().MARKERS_DISTANCE_INDICATION_ENABLED.get()
|
||||
|| !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()) {
|
||||
WidgetsVisibilityHelper vh = map.getWidgetsVisibilityHelper();
|
||||
if (zoom < 3 || markers.size() == 0 || vh.shouldHideMapMarkersWidget()) {
|
||||
updateVisibility(false);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,235 @@
|
|||
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.activities.MapActivityLayers;
|
||||
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;
|
||||
private MapActivityLayers mapLayers;
|
||||
|
||||
public WidgetsVisibilityHelper(@NonNull MapActivity mapActivity) {
|
||||
this.mapActivity = mapActivity;
|
||||
this.settings = mapActivity.getMyApplication().getSettings();
|
||||
this.routingHelper = mapActivity.getRoutingHelper();
|
||||
this.mapLayers = mapActivity.getMapLayers();
|
||||
}
|
||||
|
||||
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 !mapActivity.shouldHideTopControls()
|
||||
&& !isInFollowTrackMode()
|
||||
&& (additionalDialogsHide || !isPortrait());
|
||||
}
|
||||
|
||||
public boolean shouldHideCompass() {
|
||||
return mapActivity.shouldHideTopControls()
|
||||
|| isTrackDetailsMenuOpened()
|
||||
|| isInMeasurementToolMode()
|
||||
|| isInPlanRouteMode()
|
||||
|| isInChoosingRoutesMode()
|
||||
|| isInTrackAppearanceMode()
|
||||
|| isInWaypointsChoosingMode()
|
||||
|| isInFollowTrackMode()
|
||||
|| isInRouteLineAppearanceMode();
|
||||
}
|
||||
|
||||
public boolean shouldShowTopButtons() {
|
||||
return !mapActivity.shouldHideTopControls()
|
||||
&& !isTrackDetailsMenuOpened()
|
||||
&& !isInMeasurementToolMode()
|
||||
&& !isInPlanRouteMode()
|
||||
&& !isInChoosingRoutesMode()
|
||||
&& !isInTrackAppearanceMode()
|
||||
&& !isInWaypointsChoosingMode()
|
||||
&& !isInFollowTrackMode()
|
||||
&& !isInRouteLineAppearanceMode();
|
||||
}
|
||||
|
||||
public boolean shouldShowBackToLocationButton() {
|
||||
boolean additionalDialogsHide = !isInTrackAppearanceMode()
|
||||
&& !isInGpxApproximationMode()
|
||||
&& !isInChoosingRoutesMode()
|
||||
&& !isInWaypointsChoosingMode()
|
||||
&& !isInFollowTrackMode()
|
||||
&& !isInRouteLineAppearanceMode();
|
||||
return !mapActivity.shouldHideTopControls()
|
||||
&& !isInPlanRouteMode()
|
||||
&& !(isMapLinkedToLocation() && routingHelper.isFollowingMode())
|
||||
&& (additionalDialogsHide || !isPortrait());
|
||||
}
|
||||
|
||||
private boolean isQuickActionLayerOn() {
|
||||
return mapLayers.getMapQuickActionLayer().isLayerOn();
|
||||
}
|
||||
|
||||
private boolean isMapRouteInfoMenuVisible() {
|
||||
return mapActivity.getMapRouteInfoMenu().isVisible();
|
||||
}
|
||||
|
||||
private boolean isInMovingMarkerMode() {
|
||||
MapQuickActionLayer quickActionLayer = mapLayers.getMapQuickActionLayer();
|
||||
boolean isInMovingMarkerMode = quickActionLayer != null && quickActionLayer.isInMovingMarkerMode();
|
||||
return isInMovingMarkerMode || isInChangeMarkerPositionMode() || isInAddGpxPointMode();
|
||||
}
|
||||
|
||||
private boolean isInGpxDetailsMode() {
|
||||
return mapLayers.getContextMenuLayer().isInGpxDetailsMode();
|
||||
}
|
||||
|
||||
private boolean isInAddGpxPointMode() {
|
||||
return mapLayers.getContextMenuLayer().isInAddGpxPointMode();
|
||||
}
|
||||
|
||||
private boolean isInChangeMarkerPositionMode() {
|
||||
return mapLayers.getContextMenuLayer().isInChangeMarkerPositionMode();
|
||||
}
|
||||
|
||||
private boolean isInMeasurementToolMode() {
|
||||
return mapLayers.getMeasurementToolLayer().isInMeasurementMode();
|
||||
}
|
||||
|
||||
private boolean isInPlanRouteMode() {
|
||||
return mapLayers.getMapMarkersLayer().isInPlanRouteMode();
|
||||
}
|
||||
|
||||
private boolean isInTrackAppearanceMode() {
|
||||
return mapLayers.getGpxLayer().isInTrackAppearanceMode();
|
||||
}
|
||||
|
||||
private boolean isInGpxApproximationMode() {
|
||||
return mapLayers.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 mapLayers.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 isTrackDetailsMenuOpened() {
|
||||
return mapActivity.getTrackDetailsMenu().isVisible();
|
||||
}
|
||||
|
||||
private boolean isPortrait() {
|
||||
return AndroidUiHelper.isOrientationPortrait(mapActivity);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue