From bbb35bc385a8e380c58c3aed1c1bf6b36a45a915 Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Tue, 3 Jan 2017 13:13:11 +0200 Subject: [PATCH] quick action fab proper visibility with context menu; center map shift in quick action mode --- .../plus/mapcontextmenu/MapContextMenu.java | 2 ++ .../other/MapMultiSelectionMenu.java | 8 +++++-- .../plus/views/MapQuickActionLayer.java | 21 ++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 0985f6f676..06bbf65e92 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -587,6 +587,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public void onSingleTapOnMap() { if (menuController == null || !menuController.handleSingleTapOnMap()) { hide(); + if (mapActivity.getMapLayers().getMapQuickActionLayer().isLayerOn()) + mapActivity.getMapLayers().getMapQuickActionLayer().refreshLayer(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java index 109665396f..6fd4ffbf63 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java @@ -170,13 +170,17 @@ public class MapMultiSelectionMenu extends BaseMenuController { } public boolean isVisible() { - Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(MapMultiSelectionMenuFragment.TAG); + Fragment fragment = getFragmentByTag(); return fragment != null; } + public Fragment getFragmentByTag() { + return getMapActivity().getSupportFragmentManager().findFragmentByTag(MapMultiSelectionMenuFragment.TAG); + } + public void hide() { clearMenu(); - Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(MapMultiSelectionMenuFragment.TAG); + Fragment fragment = getFragmentByTag(); if (fragment != null) { MapMultiSelectionMenuFragment menuFragment = (MapMultiSelectionMenuFragment) fragment; menuFragment.dismissMenu(); diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index 35f4a9a72c..1bc5276646 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -46,6 +46,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe private OsmandMapTileView view; private boolean wasCollapseButtonVisible; + private int previousMapPosition; private boolean inChangeMarkerPositionMode; @@ -102,6 +103,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe public void refreshLayer() { setLayerState(true); isLayerOn = quickActionRegistry.isQuickActionOn(); + setUpQuickActionBtnVisibility(); } private void setQuickActionButtonMargin() { @@ -160,6 +162,8 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe } private void enterMovingMode(RotatedTileBox tileBox) { + previousMapPosition = view.getMapPosition(); + view.setMapPosition( OsmandSettings.BOTTOM_CONSTANT); MapContextMenu menu = mapActivity.getContextMenu(); LatLon ll = menu.isActive() && tileBox.containsLatLon(menu.getLatLon()) ? menu.getLatLon() : tileBox.getCenterLatLon(); @@ -167,7 +171,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe menu.close(); RotatedTileBox rb = new RotatedTileBox(tileBox); -// rb.setCenterLocation(0.5f, 0.5f); +// tileBox.setCenterLocation(0.5f, 0.75f); rb.setLatLonCenter(ll.getLatitude(), ll.getLongitude()); double lat = rb.getLatFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); double lon = rb.getLonFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); @@ -189,6 +193,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe } private void quitMovingMarker() { + view.setMapPosition(previousMapPosition); inChangeMarkerPositionMode = false; mark(View.VISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); @@ -228,10 +233,16 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe canvas.translate(box.getCenterPixelX() - contextMarker.getWidth() / 2, box.getCenterPixelY() - contextMarker.getHeight()); contextMarker.draw(canvas); } + setUpQuickActionBtnVisibility(); + } + + private void setUpQuickActionBtnVisibility() { boolean hideQuickButton = !isLayerOn || contextMenuLayer.isInChangeMarkerPositionMode() || - mapActivity.getContextMenu().isVisible() || - mapActivity.getContextMenu().getMultiSelectionMenu().isVisible(); + mapActivity.getContextMenu().isVisible() && !mapActivity.getContextMenu().findMenuFragment().get().isRemoving() || + mapActivity.getContextMenu().isVisible() && mapActivity.getContextMenu().findMenuFragment().get().isAdded() || + mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() && mapActivity.getContextMenu().getMultiSelectionMenu().getFragmentByTag().isAdded() || + mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() && !mapActivity.getContextMenu().getMultiSelectionMenu().getFragmentByTag().isRemoving(); quickActionButton.setVisibility(hideQuickButton ? View.GONE : View.VISIBLE); } @@ -265,6 +276,10 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe return isLayerOn && inChangeMarkerPositionMode; } + public boolean isLayerOn() { + return isLayerOn; + } + public boolean onBackPressed() { return setLayerState(true); }