From 031c399ba23d8669761b701df2a59464eddbb1f2 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Mon, 17 Mar 2014 23:30:31 +0100 Subject: [PATCH] Add select on map --- .../osmand/plus/OsmAndLocationProvider.java | 2 ++ .../plus/activities/MapActivityActions.java | 6 ++-- .../osmand/plus/routing/RoutingHelper.java | 2 +- .../osmand/plus/views/MapControlsLayer.java | 14 ++++---- .../net/osmand/plus/views/OsmandMapLayer.java | 1 + .../osmand/plus/views/OsmandMapTileView.java | 23 +++++++----- .../views/controls/MapNavigateControl.java | 4 +-- .../views/controls/MapRouteInfoControl.java | 36 +++++++++++++------ 8 files changed, 58 insertions(+), 30 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index d690425d06..701531799a 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -748,6 +748,8 @@ public class OsmAndLocationProvider implements SensorEventListener { // Update routing position and get location for sticking mode updatedLocation = routingHelper.setCurrentLocation(location, settings.SNAP_TO_ROAD.get()); } + } else if(routingHelper.isRoutePlanningMode() && settings.getPointToStart() == null) { + routingHelper.setCurrentLocation(location, false); } this.location = updatedLocation; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 98e09d44a3..b74b42b59e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -369,8 +369,10 @@ public class MapActivityActions implements DialogProvider { public void contextMenuPoint(final double latitude, final double longitude, final ContextMenuAdapter iadapter, Object selectedObj) { final ContextMenuAdapter adapter = iadapter == null ? new ContextMenuAdapter(mapActivity) : iadapter; - adapter.item(R.string.context_menu_item_directions_to).icons( - R.drawable.ic_action_gdirections_dark, R.drawable.ic_action_gdirections_light).reg(); + if(!mapActivity.getRoutingHelper().isRoutePlanningMode()) { + adapter.item(R.string.context_menu_item_directions_to).icons( + R.drawable.ic_action_gdirections_dark, R.drawable.ic_action_gdirections_light).reg(); + } final TargetPointsHelper targets = getMyApplication().getTargetPointsHelper(); if(targets.getPointToNavigate() != null) { adapter.item(R.string.context_menu_item_destination_point).icons(R.drawable.ic_action_flag_dark, diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 9baf80fe62..cc84dc52d7 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -198,7 +198,7 @@ public class RoutingHelper { } public void updateLocation(Location currentLocation) { - if(isFollowingMode()) { + if(isFollowingMode() || (settings.getPointToStart() == null && isRoutePlanningMode)) { setCurrentLocation(currentLocation, false); } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index b4d17af42d..6c188d9a1b 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -1,5 +1,8 @@ package net.osmand.plus.views; +import java.util.ArrayList; +import java.util.List; + import net.osmand.data.RotatedTileBox; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; @@ -45,6 +48,7 @@ public class MapControlsLayer extends OsmandMapLayer { private MapNavigateControl mapNavigationControl; private MapRoutePlanControl mapRoutePlanControl; private MapRoutePreferencesControl mapAppModeControl; + private List allControls = new ArrayList(); private float scaleCoefficient; @@ -103,6 +107,7 @@ public class MapControlsLayer extends OsmandMapLayer { private T init(T c, FrameLayout parent, int gravity) { c.init(parent); c.setGravity(gravity); + allControls.add(c); return c; } @@ -188,14 +193,11 @@ public class MapControlsLayer extends OsmandMapLayer { mapMenuControls.showWithDelay((FrameLayout) mapActivity.getMapView().getParent(), TIMEOUT_TO_SHOW_BUTTONS); mapRoutePlanControl.showWithDelay((FrameLayout) mapActivity.getMapView().getParent(), TIMEOUT_TO_SHOW_BUTTONS); } - if(mapMenuControls.isVisible() && mapMenuControls.onSingleTap(point, tileBox)) { - return true; - } - if(zoomControls.isVisible() ) { - if(zoomControls.onSingleTap(point, tileBox)) { + for(MapControls m : allControls) { + if(m.isVisible() && m.onSingleTap(point, tileBox)){ return true; } - } + } return false; } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 22a1744fb3..fca62b78f5 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -63,6 +63,7 @@ public abstract class OsmandMapLayer { public boolean isUpdateVectorRendering() { return updateVectorRendering; } + public boolean isNightMode() { return nightMode; } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 556a78fa21..6e04ccd568 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -56,6 +56,7 @@ import android.widget.Toast; public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCallback, Callback { private static final int MAP_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 4; + private static final int MAP_FORCE_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 5; private static final int BASE_REFRESH_MESSAGE = OsmAndConstants.UI_HANDLER_MAP_VIEW + 3; protected final static int LOWEST_ZOOM_TO_ROTATE = 9; private boolean MEASURE_FPS = false; @@ -447,7 +448,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall } private void refreshMapInternal(DrawSettings drawSettings) { - handler.removeMessages(MAP_REFRESH_MESSAGE); SurfaceHolder holder = getHolder(); long ms = SystemClock.elapsedRealtime(); synchronized (holder) { @@ -530,10 +530,6 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall } } - public boolean mapIsRefreshing() { - return handler.hasMessages(MAP_REFRESH_MESSAGE); - } - private void refreshBufferImage(final DrawSettings drawSettings) { if (!baseHandler.hasMessages(BASE_REFRESH_MESSAGE) || drawSettings.isUpdateVectorRendering()) { Message msg = Message.obtain(baseHandler, new Runnable() { @@ -541,14 +537,21 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall public void run() { baseHandler.removeMessages(BASE_REFRESH_MESSAGE); try { - refreshBaseMapInternal(currentViewport.copy(), drawSettings); - sendRefreshMapMsg(drawSettings, 0); + DrawSettings param = drawSettings; + if (handler.hasMessages(MAP_FORCE_REFRESH_MESSAGE)) { + if (!param.isUpdateVectorRendering()) { + param = new DrawSettings(drawSettings.isNightMode(), true); + } + handler.removeMessages(MAP_FORCE_REFRESH_MESSAGE); + } + refreshBaseMapInternal(currentViewport.copy(), param); + sendRefreshMapMsg(param, 0); } catch(Exception e) { log.error(e.getMessage(), e); } } }); - msg.what = BASE_REFRESH_MESSAGE; + msg.what = drawSettings.isUpdateVectorRendering() ? MAP_FORCE_REFRESH_MESSAGE : BASE_REFRESH_MESSAGE; // baseHandler.sendMessageDelayed(msg, 0); baseHandler.sendMessage(msg); } @@ -574,8 +577,10 @@ public class OsmandMapTileView extends SurfaceView implements IMapDownloaderCall Message msg = Message.obtain(handler, new Runnable() { @Override public void run() { + DrawSettings param = drawSettings; handler.removeMessages(MAP_REFRESH_MESSAGE); - refreshMapInternal(drawSettings); + + refreshMapInternal(param); } }); msg.what = MAP_REFRESH_MESSAGE; diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java index 052d7be4a9..3aff6b1583 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java @@ -37,15 +37,15 @@ public class MapNavigateControl extends MapControls { mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); } else { OsmandApplication ctx = mapActivity.getMyApplication(); - if(!ctx.getTargetPointsHelper().checkPointToNavigate()) { + if(!ctx.getTargetPointsHelper().checkPointToNavigateShort()) { ri.showDialog(); } else { mapActivity.getMapViewTrackingUtilities().backToLocationImpl(); - app.getSettings().FOLLOW_THE_ROUTE.set(true); GPXRouteParams gpxRoute = null; // TODO gpx route if (gpxRoute == null) { app.getSettings().FOLLOW_THE_GPX_ROUTE.set(null); } + app.getSettings().FOLLOW_THE_ROUTE.set(true); routingHelper.setFollowingMode(true); routingHelper.setRoutePlanningMode(false); mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode(); diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java index 534d5c8da2..6c91639dc5 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java @@ -27,6 +27,7 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnDismissListener; import android.content.Intent; import android.graphics.Canvas; +import android.graphics.PointF; import android.graphics.drawable.Drawable; import android.os.Handler; import android.view.Gravity; @@ -52,6 +53,8 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio private OsmandMapTileView mapView; private Dialog dialog; private AlertDialog favoritesDialog; + private boolean selectFromMapTouch; + private boolean selectFromMapForTarget; public MapRouteInfoControl(ContextMenuLayer contextMenu, @@ -63,6 +66,22 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio routingHelper.addListener(this); } + @Override + public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { + if(selectFromMapTouch) { + LatLon latlon = tileBox.getLatLonFromPixel(point.x, point.y); + selectFromMapTouch = false; + if(selectFromMapForTarget) { + getTargets().navigateToPoint(latlon, true, -1); + } else { + getTargets().setStartPoint(latlon, true, null); + } + contextMenu.setLocation(latlon, null); + return true; + } + return super.onSingleTap(point, tileBox); + } + @Override public void showControls(FrameLayout parent) { infoButton = addButton(parent, R.string.route_info, R.drawable.map_btn_signpost); @@ -76,10 +95,10 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio showDialog(); } } - - - }); + if(getTargets().getPointToNavigate() == null) { + showDialog(); + } } private Dialog createDialog() { @@ -167,8 +186,9 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio } protected void selectOnScreen(View parentView, boolean target) { - // TODO Auto-generated method stub - + selectFromMapTouch = true; + selectFromMapForTarget = target; + hideDialog(); } protected void selectFavorite(final View parentView, final boolean target) { @@ -189,7 +209,6 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio } else { getTargets().setStartPoint(point, true, name); } - getTargets().updateRoutingHelper(); favoritesDialog.dismiss(); } }); @@ -311,7 +330,6 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio @Override public void newRouteIsCalculated(boolean newRoute) { directionInfo = -1; - mapView.refreshMap(); } public String generateViaDescription() { @@ -403,9 +421,7 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio @Override public void routeWasCancelled() { directionInfo = -1; - if(dialog != null) { - hideDialog(); - } + // do not hide dialog (needed for use case entering Planning mode without destination) }