Hide context menu on map pan

This commit is contained in:
Alexey Kulish 2018-10-19 10:40:49 +03:00
parent 50643f3f85
commit 3cb6162e54
4 changed files with 57 additions and 11 deletions

View file

@ -862,9 +862,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
boolean night = app.getDaynightHelper().isNightModeForMapControls(); boolean night = app.getDaynightHelper().isNightModeForMapControls();
boolean quickSearchTopBar = getTopToolbarController(TopToolbarControllerType.QUICK_SEARCH) != null; boolean quickSearchTopBar = getTopToolbarController(TopToolbarControllerType.QUICK_SEARCH) != null;
boolean contextMenuTopBar = getTopToolbarController(TopToolbarControllerType.CONTEXT_MENU) != null; boolean contextMenuTopBar = getTopToolbarController(TopToolbarControllerType.CONTEXT_MENU) != null;
boolean contextTopBar = getTopToolbarController(TopToolbarControllerType.CONTEXT) != null;
boolean mapTopBar = findViewById(R.id.map_top_bar).getVisibility() == View.VISIBLE; boolean mapTopBar = findViewById(R.id.map_top_bar).getVisibility() == View.VISIBLE;
boolean markerTopBar = findViewById(R.id.map_markers_top_bar).getVisibility() == View.VISIBLE; boolean markerTopBar = findViewById(R.id.map_markers_top_bar).getVisibility() == View.VISIBLE;
if (((quickSearchTopBar || mapTopBar) && mapControlsVisible) || contextMenuTopBar) { if (((quickSearchTopBar || mapTopBar) && mapControlsVisible) || contextMenuTopBar || contextTopBar) {
colorId = night ? R.color.status_bar_route_dark : R.color.status_bar_route_light; colorId = night ? R.color.status_bar_route_dark : R.color.status_bar_route_light;
} else if (markerTopBar && mapControlsVisible) { } else if (markerTopBar && mapControlsVisible) {
colorId = R.color.status_bar_dark; colorId = R.color.status_bar_dark;

View file

@ -76,6 +76,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
private PointDescription pointDescription; private PointDescription pointDescription;
private Object object; private Object object;
private MenuController menuController; private MenuController menuController;
private ContextToolbarController toolbarController;
private LatLon mapCenter; private LatLon mapCenter;
private int mapPosition = 0; private int mapPosition = 0;
@ -125,6 +126,25 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
} }
public MapContextMenu() { public MapContextMenu() {
toolbarController = new ContextToolbarController();
toolbarController.setOnBackButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
show();
}
});
toolbarController.setOnTitleClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
show();
}
});
toolbarController.setOnCloseButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
close();
}
});
} }
@Nullable @Nullable
@ -444,6 +464,19 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
init(latLon, pointDescription, object); init(latLon, pointDescription, object);
} }
private void showToolbar() {
if (mapActivity != null) {
toolbarController.setTitle(getTitleStr());
mapActivity.showTopToolbar(toolbarController);
}
}
private void hideToolbar() {
if (mapActivity != null) {
mapActivity.hideTopToolbar(toolbarController);
}
}
public void onFragmentResume() { public void onFragmentResume() {
if (active && displayDistanceDirection()) { if (active && displayDistanceDirection()) {
updateLocation(false, true, false); updateLocation(false, true, false);
@ -478,6 +511,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
if (menuController != null) { if (menuController != null) {
menuController.setActive(false); menuController.setActive(false);
} }
hideToolbar();
mapActivity.refreshMap(); mapActivity.refreshMap();
} }
} }
@ -502,6 +536,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
fragmentRef.get().dismissMenu(); fragmentRef.get().dismissMenu();
result = true; result = true;
} }
if (active) {
showToolbar();
}
} }
return result; return result;
} }
@ -752,7 +789,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
if (fragmentRef != null) { if (fragmentRef != null) {
fragmentRef.get().refreshTitle(); fragmentRef.get().refreshTitle();
} }
if (searchDoneAction != null) { if (searchDoneAction != null) {
if (searchDoneAction.dlg != null) { if (searchDoneAction.dlg != null) {
try { try {
@ -766,6 +802,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
searchDoneAction.run(); searchDoneAction.run();
searchDoneAction = null; searchDoneAction = null;
} }
if (active) {
toolbarController.setTitle(getTitleStr());
if (mapActivity != null
&& mapActivity.getTopToolbarController(TopToolbarControllerType.CONTEXT) != null) {
mapActivity.refreshMap();
}
}
} }
@Nullable @Nullable
@ -1367,4 +1410,12 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
private abstract class MenuAction implements Runnable { private abstract class MenuAction implements Runnable {
protected ProgressDialog dlg; protected ProgressDialog dlg;
} }
public static class ContextToolbarController extends TopToolbarController {
public ContextToolbarController() {
super(TopToolbarControllerType.CONTEXT);
}
}
} }

View file

@ -1028,14 +1028,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
if (movementListener.onTouchEvent(event)) { if (movementListener.onTouchEvent(event)) {
if (menu.isVisible()) { menu.hide();
if (!menu.isClosable()) {
menu.hide();
} else {
menu.updateMapCenter(null);
menu.close();
}
}
if (multiSelectionMenu.isVisible()) { if (multiSelectionMenu.isVisible()) {
multiSelectionMenu.hide(); multiSelectionMenu.hide();
} }

View file

@ -51,7 +51,8 @@ public class MapInfoWidgetsFactory {
CONTEXT_MENU, CONTEXT_MENU,
TRACK_DETAILS, TRACK_DETAILS,
DISCOUNT, DISCOUNT,
MEASUREMENT_TOOL MEASUREMENT_TOOL,
CONTEXT
} }
public TextInfoWidget createAltitudeControl(final MapActivity map) { public TextInfoWidget createAltitudeControl(final MapActivity map) {