diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 2900ada92d..24c677c158 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -97,7 +97,7 @@ import net.osmand.plus.views.OsmAndMapSurfaceView; 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.MapInfoWidgetsFactory.TopToolbarViewController; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.render.RenderingRulesStorage; import net.osmand.util.Algorithms; @@ -1407,13 +1407,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return mapInfoLayer.hasTopToolbar(); } - public void showTopToolbar(TopToolbarViewController viewController) { + public void showTopToolbar(TopToolbarController viewController) { MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer(); mapInfoLayer.addTopToolbarViewController(viewController); this.topToolbarActive = mapInfoLayer.hasTopToolbar(); } - public void hideTopToolbar(TopToolbarViewController viewController) { + public void hideTopToolbar(TopToolbarController viewController) { MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer(); mapInfoLayer.removeTopToolbarViewController(viewController); this.topToolbarActive = mapInfoLayer.hasTopToolbar(); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java index 51f7afa00b..120924c5cb 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteMenuController.java @@ -76,6 +76,11 @@ public class AudioVideoNoteMenuController extends MenuController { } } + @Override + protected Object getObject() { + return mRecording; + } + public Recording getRecording() { return mRecording; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 232b56027c..051435a1c7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -48,6 +48,7 @@ import net.osmand.plus.views.OsmandMapLayer; import net.osmand.util.MapUtils; import java.lang.ref.WeakReference; +import java.util.LinkedList; import java.util.List; public class MapContextMenu extends MenuTitleController implements StateChangedListener, @@ -82,6 +83,38 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL private MenuAction searchDoneAction; + private LinkedList historyStack = new LinkedList<>(); + + public static class MapContextMenuData { + private LatLon latLon; + private PointDescription pointDescription; + private Object object; + private boolean backAction; + + public MapContextMenuData(LatLon latLon, PointDescription pointDescription, Object object, boolean backAction) { + this.latLon = latLon; + this.pointDescription = pointDescription; + this.object = object; + this.backAction = backAction; + } + + public LatLon getLatLon() { + return latLon; + } + + public PointDescription getPointDescription() { + return pointDescription; + } + + public Object getObject() { + return object; + } + + public boolean hasBackAction() { + return backAction; + } + } + public MapContextMenu() { } @@ -112,7 +145,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } if (active) { - acquireMenuController(); + acquireMenuController(false); if (menuController != null) { menuController.addPlainMenuItems(typeStr, this.pointDescription, this.latLon); } @@ -222,13 +255,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public boolean init(@NonNull LatLon latLon, @Nullable PointDescription pointDescription, @Nullable Object object) { - return init(latLon, pointDescription, object, false); + return init(latLon, pointDescription, object, false, false); } public boolean init(@NonNull LatLon latLon, @Nullable PointDescription pointDescription, @Nullable Object object, - boolean update) { + boolean update, boolean restorePrevious) { if (myLocation == null) { myLocation = getMapActivity().getMyApplication().getSettings().getLastKnownMapLocation(); @@ -264,7 +297,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL appModeChanged = false; if (needAcquireMenuController) { - acquireMenuController(); + acquireMenuController(restorePrevious); } else { menuController.update(pointDescription, object); } @@ -311,21 +344,25 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL @Nullable PointDescription pointDescription, @Nullable Object object) { if (init(latLon, pointDescription, object)) { - if (!MapContextMenuFragment.showInstance(this, mapActivity, centerMarker)) { - active = false; - } else { - if (menuController != null) { - menuController.onShow(); - } - } - centerMarker = false; - autoHide = false; + showInternal(); } } + private void showInternal() { + if (!MapContextMenuFragment.showInstance(this, mapActivity, centerMarker)) { + active = false; + } else { + if (menuController != null) { + menuController.onShow(); + } + } + centerMarker = false; + autoHide = false; + } + public void update(LatLon latLon, PointDescription pointDescription, Object object) { WeakReference fragmentRef = findMenuFragment(); - init(latLon, pointDescription, object, true); + init(latLon, pointDescription, object, true, false); if (fragmentRef != null) { fragmentRef.get().rebuildMenu(); } @@ -350,12 +387,18 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL mapActivity.getMyApplication().getMapMarkersHelper().removeListener(this); } if (menuController != null) { + if (menuController.hasBackAction()) { + clearHistoryStack(); + } menuController.onClose(); } if (this.object != null) { clearSelectedObject(this.object); } hide(); + if (menuController != null) { + menuController.setActive(false); + } mapActivity.refreshMap(); } } @@ -457,16 +500,59 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } - private void acquireMenuController() { + private void acquireMenuController(boolean restorePrevious) { + MapContextMenuData menuData = null; if (menuController != null) { + if (menuController.isActive() && !restorePrevious) { + menuData = new MapContextMenuData( + menuController.getLatLon(), menuController.getPointDescription(), + menuController.getObject(), menuController.hasBackAction()); + } menuController.onAcquireNewController(pointDescription, object); } - menuController = MenuController.getMenuController(mapActivity, pointDescription, object, MenuType.STANDARD); + menuController = MenuController.getMenuController(mapActivity, latLon, pointDescription, object, MenuType.STANDARD); + menuController.setActive(true); + if (menuData != null && (object != menuData.getObject()) + && (menuController.hasBackAction() || menuData.hasBackAction())) { + historyStack.add(menuData); + } if (!(menuController instanceof MapDataMenuController)) { menuController.buildMapDownloadButton(latLon); } } + public boolean showPreviousMenu() { + MapContextMenuData menuData; + if (hasHistoryStackBackAction()) { + do { + menuData = historyStack.pollLast(); + } while (menuData != null && !menuData.hasBackAction()); + } else { + menuData = historyStack.pollLast(); + } + if (menuData != null) { + if (init(menuData.getLatLon(), menuData.getPointDescription(), menuData.getObject(), false, true)) { + showInternal(); + } + return active; + } else { + return false; + } + } + + public boolean hasHistoryStackBackAction() { + for (MapContextMenuData menuData : historyStack) { + if (menuData.hasBackAction()) { + return true; + } + } + return false; + } + + public void clearHistoryStack() { + historyStack.clear(); + } + public void onSingleTapOnMap() { if (menuController == null || !menuController.handleSingleTapOnMap()) { hide(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 453ed85d5e..f0c8010615 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -1,6 +1,7 @@ package net.osmand.plus.mapcontextmenu; import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; @@ -53,7 +54,7 @@ import net.osmand.plus.osmo.OsMoMenuController; import net.osmand.plus.parkingpoint.ParkingPositionMenuController; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject; -import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarViewController; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -79,6 +80,8 @@ public abstract class MenuController extends BaseMenuController { private int currentMenuState; private MenuType menuType = MenuType.STANDARD; private PointDescription pointDescription; + private LatLon latLon; + private boolean active; protected TitleButtonController leftTitleButtonController; protected TitleButtonController rightTitleButtonController; @@ -88,7 +91,7 @@ public abstract class MenuController extends BaseMenuController { protected TitleButtonController rightDownloadButtonController; protected TitleProgressController titleProgressController; - protected TopToolbarViewController toolbarController; + protected TopToolbarController toolbarController; protected IndexItem indexItem; protected boolean downloaded; @@ -109,7 +112,8 @@ public abstract class MenuController extends BaseMenuController { } public static MenuController getMenuController(MapActivity mapActivity, - PointDescription pointDescription, Object object, MenuType menuType) { + LatLon latLon, PointDescription pointDescription, Object object, + MenuType menuType) { OsmandApplication app = mapActivity.getMyApplication(); MenuController menuController = null; if (object != null) { @@ -156,6 +160,7 @@ public abstract class MenuController extends BaseMenuController { menuController = new PointDescriptionMenuController(app, mapActivity, pointDescription); } menuController.menuType = menuType; + menuController.setLatLon(latLon); return menuController; } @@ -170,6 +175,16 @@ public abstract class MenuController extends BaseMenuController { protected abstract void setObject(Object object); + protected abstract Object getObject(); + + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl, OnClickListener onClickListener) { builder.addPlainMenuItem(iconId, text, needLinks, isUrl, onClickListener); } @@ -275,10 +290,18 @@ public abstract class MenuController extends BaseMenuController { return titleProgressController; } - public TopToolbarViewController getToolbarController() { + public TopToolbarController getToolbarController() { return toolbarController; } + public boolean hasBackAction() { + return toolbarController != null; + } + + public LatLon getLatLon() { + return latLon; + } + public boolean supportZoomIn() { return true; } @@ -471,6 +494,10 @@ public abstract class MenuController extends BaseMenuController { return downloaded; } + public void setLatLon(@NonNull LatLon latLon) { + this.latLon = latLon; + } + public void buildMapDownloadButton(LatLon latLon) { int point31x = MapUtils.get31TileNumberX(latLon.getLongitude()); int point31y = MapUtils.get31TileNumberY(latLon.getLatitude()); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 36fce992df..3dab566229 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -29,6 +29,11 @@ public class AmenityMenuController extends MenuController { } } + @Override + protected Object getObject() { + return amenity; + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java index 1f62052339..476ec74d8b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java @@ -30,6 +30,11 @@ public class FavouritePointMenuController extends MenuController { } } + @Override + protected Object getObject() { + return fav; + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/GpxItemMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/GpxItemMenuController.java index b7d10fe088..dc932c6800 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/GpxItemMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/GpxItemMenuController.java @@ -25,6 +25,11 @@ public class GpxItemMenuController extends MenuController { } } + @Override + protected Object getObject() { + return item; + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java index fd72169a6f..d82a5c43ce 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/HistoryMenuController.java @@ -35,6 +35,11 @@ public class HistoryMenuController extends MenuController { } } + @Override + protected Object getObject() { + return entry; + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java index ec417eb929..611f4c499c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java @@ -41,6 +41,11 @@ public class ImpassibleRoadsMenuController extends MenuController { route = (RouteDataObject) object; } + @Override + protected Object getObject() { + return route; + } + @Override public String getTypeStr() { return getMapActivity().getString(R.string.road_blocked); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java index 2774a7a091..4c6a1fd2f2 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java @@ -182,6 +182,11 @@ public class MapDataMenuController extends MenuController { } } + @Override + protected Object getObject() { + return mapObject; + } + @Override public boolean needTypeStr() { return true; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java index a3a928688f..4d2a2ca7ea 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapMarkerMenuController.java @@ -40,6 +40,11 @@ public class MapMarkerMenuController extends MenuController { } } + @Override + protected Object getObject() { + return mapMarker; + } + public MapMarker getMapMarker() { return mapMarker; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java index dd03b12bc0..bbd7d70a8c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MyLocationMenuController.java @@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu.controllers; import android.graphics.drawable.Drawable; +import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; @@ -20,6 +21,11 @@ public class MyLocationMenuController extends MenuController { protected void setObject(Object object) { } + @Override + protected Object getObject() { + return getLatLon(); + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java index 9a63708b7d..23f1ebebcc 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/PointDescriptionMenuController.java @@ -29,6 +29,11 @@ public class PointDescriptionMenuController extends MenuController { initData(); } + @Override + protected Object getObject() { + return null; + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java index c97a4775dd..06c1bf60b2 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TargetPointMenuController.java @@ -58,6 +58,11 @@ public class TargetPointMenuController extends MenuController { } } + @Override + protected Object getObject() { + return targetPoint; + } + public TargetPoint getTargetPoint() { return targetPoint; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java index 2eed7301ae..1921823509 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java @@ -16,31 +16,65 @@ import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute; import net.osmand.plus.views.TransportStopsLayer; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController.TopToolbarViewControllerType; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView; -import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarViewController; import java.lang.ref.WeakReference; import java.util.List; public class TransportRouteController extends MenuController { - private TransportStopRoute transportStop; + private TransportStopRoute transportRoute; - public TransportRouteController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, - TransportStopRoute transportStop) { + public TransportRouteController(OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, + final TransportStopRoute transportRoute) { super(new MenuBuilder(app), pointDescription, mapActivity); - this.transportStop = transportStop; - toolbarController = new TransportRouteToolbarController(); + this.transportRoute = transportRoute; + toolbarController = new TopToolbarController(TopToolbarViewControllerType.CONTEXT_MENU) { + @Override + public void onBackPressed(TopToolbarView view) { + MapContextMenu menu = getMapActivity().getContextMenu(); + getMapActivity().hideTopToolbar(toolbarController); + resetRoute(); + if (!menu.showPreviousMenu() && menu.getMenuController() == TransportRouteController.this) { + menu.close(); + } + } + + @Override + public void onTitlePressed(TopToolbarView view) { + showMenuAndRoute(getLatLon(), true); + } + + @Override + public void onClosePressed(TopToolbarView view) { + MapContextMenu menu = getMapActivity().getContextMenu(); + if (menu.getMenuController() == TransportRouteController.this) { + menu.close(); + } else { + getMapActivity().hideTopToolbar(toolbarController); + menu.clearHistoryStack(); + resetRoute(); + getMapActivity().refreshMap(); + } + } + }; toolbarController.setTitle(getNameStr()); } @Override protected void setObject(Object object) { if (object instanceof TransportStopRoute) { - this.transportStop = (TransportStopRoute) object; + this.transportRoute = (TransportStopRoute) object; } } + @Override + protected Object getObject() { + return transportRoute; + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; @@ -48,9 +82,9 @@ public class TransportRouteController extends MenuController { @Override public int getLeftIconId() { - return this.transportStop.type == null ? + return this.transportRoute.type == null ? R.drawable.mx_public_transport : - this.transportStop.type.getTopResourceId(); + this.transportRoute.type.getTopResourceId(); } @Override @@ -84,36 +118,40 @@ public class TransportRouteController extends MenuController { return getPointDescription().getTypeName(); } + @Override + public void onShow() { + super.onShow(); + showRoute(); + } + @Override public void onClose() { super.onClose(); - TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); - stopsLayer.setRoute(null); + resetRoute(); } public void onAcquireNewController(PointDescription pointDescription, Object object) { if (object instanceof TransportRouteStop) { - TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); - stopsLayer.setRoute(null); + resetRoute(); } } @Override public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) { super.addPlainMenuItems(typeStr, pointDescription, latLon); - List stops = transportStop.route.getForwardStops(); + List stops = transportRoute.route.getForwardStops(); boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames(); int currentStop = -1; for (int i = 0; i < stops.size(); i++) { final TransportStop stop = stops.get(i); - if (stop.getName().equals(transportStop.stop.getName())) { + if (stop.getName().equals(transportRoute.stop.getName())) { currentStop = i; break; } } - int defaultIcon = transportStop.type == null ? R.drawable.mx_route_bus_ref : transportStop.type.getResourceId(); + int defaultIcon = transportRoute.type == null ? R.drawable.mx_route_bus_ref : transportRoute.type.getResourceId(); int startPosition = 0; - if (!transportStop.showWholeRoute) { + if (!transportRoute.showWholeRoute) { startPosition = (currentStop == -1 ? 0 : currentStop); if (currentStop > 0) { addPlainMenuItem(defaultIcon, getMapActivity().getString(R.string.route_stops_before, currentStop), @@ -121,13 +159,7 @@ public class TransportRouteController extends MenuController { @Override public void onClick(View arg0) { - MapContextMenu mm = getMapActivity().getContextMenu(); - transportStop.showWholeRoute = true; - mm.showOrUpdate(latLon, getPointDescription(), transportStop); - TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); - int cz = transportStop.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox()); - getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom()); - stopsLayer.setRoute(transportStop.route); + showMenuAndRoute(latLon, false); } }); } @@ -140,13 +172,12 @@ public class TransportRouteController extends MenuController { @Override public void onClick(View arg0) { - MapContextMenu mm = getMapActivity().getContextMenu(); + MapContextMenu menu = getMapActivity().getContextMenu(); PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_STOP, getMapActivity().getString(R.string.transport_Stop), name); - TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); - stopsLayer.setRoute(null); - mm.show(stop.getLocation(), pd, stop); - WeakReference rr = mm.findMenuFragment(); + resetRoute(); + menu.show(stop.getLocation(), pd, stop); + WeakReference rr = menu.findMenuFragment(); if (rr != null && rr.get() != null) { rr.get().centerMarkerLocation(); } @@ -155,25 +186,24 @@ public class TransportRouteController extends MenuController { } } - public static class TransportRouteToolbarController extends TopToolbarViewController { - - public TransportRouteToolbarController() { - super(TopToolbarViewControllerType.CONTEXT_MENU); + private void showMenuAndRoute(LatLon latLon, boolean centerMarker) { + MapContextMenu menu = getMapActivity().getContextMenu(); + if (centerMarker) { + menu.setCenterMarker(true); } + menu.show(latLon, getPointDescription(), transportRoute); + } - @Override - public void onBackPressed(TopToolbarView view) { - view.getMap().getContextMenu().close(); - } + private void showRoute() { + transportRoute.showWholeRoute = true; + TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); + int cz = transportRoute.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox()); + getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom()); + stopsLayer.setRoute(transportRoute.route); + } - @Override - public void onTitlePressed(TopToolbarView view) { - - } - - @Override - public void onClosePressed(TopToolbarView view) { - view.getMap().getContextMenu().close(); - } + private void resetRoute() { + TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); + stopsLayer.setRoute(null); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 382603a602..685388c1c1 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -1,11 +1,7 @@ package net.osmand.plus.mapcontextmenu.controllers; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; +import android.view.View; +import android.view.View.OnClickListener; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -24,8 +20,12 @@ import net.osmand.plus.resources.TransportIndexRepository; import net.osmand.plus.views.TransportStopsLayer; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; -import android.view.View; -import android.view.View.OnClickListener; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; public class TransportStopController extends MenuController { @@ -93,6 +93,11 @@ public class TransportStopController extends MenuController { } } + @Override + protected Object getObject() { + return transportStop; + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java index 1948b3f3f2..acec6cbd19 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java @@ -29,6 +29,11 @@ public class WptPtMenuController extends MenuController { } } + @Override + protected Object getObject() { + return wpt; + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java index 34beb26604..109665396f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java @@ -45,7 +45,8 @@ public class MapMultiSelectionMenu extends BaseMenuController { } protected void init() { - controller = MenuController.getMenuController(mapActivity, pointDescription, object, MenuType.MULTI_LINE); + controller = MenuController.getMenuController(mapActivity, latLon, pointDescription, object, MenuType.MULTI_LINE); + controller.setActive(true); initTitle(); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index cd7f48a8a2..cfbbf9fec2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -110,6 +110,11 @@ public class EditPOIMenuController extends MenuController { } } + @Override + protected Object getObject() { + return osmPoint; + } + public OsmPoint getOsmPoint() { return osmPoint; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java index 53815a1a2e..2b18ac6a1f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugMenuController.java @@ -64,6 +64,11 @@ public class OsmBugMenuController extends MenuController { } } + @Override + protected Object getObject() { + return bug; + } + public OpenStreetNote getBug() { return bug; } diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoMenuController.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoMenuController.java index 6689b2a4bb..dd661cb3e3 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoMenuController.java @@ -63,6 +63,11 @@ public class OsMoMenuController extends MenuController { } } + @Override + protected Object getObject() { + return device; + } + public OsMoDevice getDevice() { return device; } diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionMenuController.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionMenuController.java index 9f61a5f88a..04f7cc89b5 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionMenuController.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionMenuController.java @@ -51,6 +51,11 @@ public class ParkingPositionMenuController extends MenuController { } } + @Override + protected Object getObject() { + return getLatLon(); + } + @Override protected int getSupportedMenuStatesPortrait() { return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN; diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 869a3db7de..1d6bb63894 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -58,7 +58,7 @@ import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView; -import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarViewController; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.search.SearchUICore; import net.osmand.search.SearchUICore.SearchResultCollection; import net.osmand.search.core.ObjectType; @@ -1227,10 +1227,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } } - public static class QuickSearchToolbarController extends TopToolbarViewController { + public static class QuickSearchToolbarController extends TopToolbarController { public QuickSearchToolbarController() { - super(TopToolbarViewController.TopToolbarViewControllerType.QUICK_SEARCH); + super(TopToolbarController.TopToolbarViewControllerType.QUICK_SEARCH); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index d8142f6daa..02394c8ac5 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -19,7 +19,7 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; -import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarViewController; +import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry; import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo; @@ -101,11 +101,11 @@ public class MapInfoLayer extends OsmandMapLayer { mapInfoControls.removeSideWidgetInternal(widget); } - public void addTopToolbarViewController(TopToolbarViewController viewController) { + public void addTopToolbarViewController(TopToolbarController viewController) { topToolbarView.addViewController(viewController); } - public void removeTopToolbarViewController(TopToolbarViewController viewController) { + public void removeTopToolbarViewController(TopToolbarController viewController) { topToolbarView.removeViewController(viewController); } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index bb5e121505..6a5c29288e 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -37,6 +37,7 @@ import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable; import net.osmand.router.TurnType; +import java.util.Iterator; import java.util.LinkedList; public class MapInfoWidgetsFactory { @@ -162,7 +163,7 @@ public class MapInfoWidgetsFactory { return gpsInfoControl; } - public static abstract class TopToolbarViewController { + public static abstract class TopToolbarController { private TopToolbarViewControllerType type; private int backButtonIconId = R.drawable.abc_ic_ab_back_mtrl_am_alpha; private int closeButtonIconId = R.drawable.ic_action_remove_dark; @@ -173,7 +174,7 @@ public class MapInfoWidgetsFactory { CONTEXT_MENU } - public TopToolbarViewController(TopToolbarViewControllerType type) { + public TopToolbarController(TopToolbarViewControllerType type) { this.type = type; } @@ -210,7 +211,7 @@ public class MapInfoWidgetsFactory { public static class TopToolbarView { private final MapActivity map; - private LinkedList viewControllers = new LinkedList<>(); + private LinkedList viewControllers = new LinkedList<>(); private View topbar; private View topBarLayout; private ImageButton backButton; @@ -226,7 +227,7 @@ public class MapInfoWidgetsFactory { backButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - TopToolbarViewController viewController = getTopViewController(); + TopToolbarController viewController = getTopViewController(); if (viewController != null) { viewController.onBackPressed(TopToolbarView.this); } @@ -236,7 +237,7 @@ public class MapInfoWidgetsFactory { titleView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - TopToolbarViewController viewController = getTopViewController(); + TopToolbarController viewController = getTopViewController(); if (viewController != null) { viewController.onTitlePressed(TopToolbarView.this); } @@ -246,7 +247,7 @@ public class MapInfoWidgetsFactory { closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - TopToolbarViewController viewController = getTopViewController(); + TopToolbarController viewController = getTopViewController(); if (viewController != null) { viewController.onClosePressed(TopToolbarView.this); } @@ -279,7 +280,7 @@ public class MapInfoWidgetsFactory { return closeButton; } - public TopToolbarViewController getTopViewController() { + public TopToolbarController getTopViewController() { if (viewControllers.size() > 0) { return viewControllers.get(viewControllers.size() - 1); } else { @@ -287,14 +288,18 @@ public class MapInfoWidgetsFactory { } } - public void addViewController(TopToolbarViewController viewController) { - if (!viewControllers.contains(viewController)) { - viewControllers.add(viewController); + public void addViewController(TopToolbarController viewController) { + for (Iterator ctrlIter = viewControllers.iterator(); ctrlIter.hasNext(); ) { + TopToolbarController controller = (TopToolbarController) ctrlIter.next(); + if (controller.getType() == viewController.getType()) { + ctrlIter.remove(); + } } + viewControllers.add(viewController); updateInfo(); } - public void removeViewController(TopToolbarViewController viewController) { + public void removeViewController(TopToolbarController viewController) { viewControllers.remove(viewController); updateInfo(); } @@ -317,7 +322,7 @@ public class MapInfoWidgetsFactory { } public void updateInfo() { - TopToolbarViewController viewController = getTopViewController(); + TopToolbarController viewController = getTopViewController(); if (viewController != null) { viewController.updateToolbar(this); } @@ -327,7 +332,7 @@ public class MapInfoWidgetsFactory { public void updateTextColor(boolean nightMode, int textColor) { OsmandApplication app = map.getMyApplication(); titleView.setTextColor(textColor); - TopToolbarViewController viewController = getTopViewController(); + TopToolbarController viewController = getTopViewController(); if (viewController != null) { backButton.setImageDrawable(app.getIconsCache().getIcon(viewController.getBackButtonIconId(), !nightMode)); closeButton.setImageDrawable(app.getIconsCache().getIcon(viewController.getCloseButtonIconId(), !nightMode));