From e917d8c55a9a247aeac2d992a0bb1b5e3c8898fc Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 30 Mar 2015 23:09:38 +0200 Subject: [PATCH] Update and add address for select section --- OsmAnd/res/values/strings.xml | 1 + .../src/net/osmand/plus/OsmandSettings.java | 3 +++ .../osmand/plus/activities/MapActivity.java | 6 +++++ .../osmand/plus/dashboard/DashboardOnMap.java | 22 +++++++-------- .../osmand/plus/helpers/WaypointHelper.java | 2 +- .../osmand/plus/views/MapControlsLayer.java | 18 +++++++++++++ .../plus/views/PointNavigationLayer.java | 4 ++- .../views/controls/MapRouteInfoControl.java | 27 +++++++++++++++++++ .../mapwidgets/MapInfoWidgetsFactory.java | 8 ------ .../views/mapwidgets/MapWidgetRegistry.java | 4 ++- 10 files changed, 73 insertions(+), 22 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0b04a9475e..28ca7c7e6c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -108,6 +108,7 @@ Map Favorite Favorites + Address Add Add to Favorites My Location diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index c330e3de2e..52448732f5 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -992,6 +992,9 @@ public class OsmandSettings { // this value string is synchronized with settings_pref.xml preference name public final CommonPreference SHOW_DESTINATION_ARROW = new BooleanPreference("show_destination_arrow", false).makeProfile(); + { + SHOW_DESTINATION_ARROW.setModeDefaultValue(ApplicationMode.PEDESTRIAN, true); + } // this value string is synchronized with settings_pref.xml preference name public final CommonPreference MAP_OVERLAY = new StringPreference("map_overlay", null).makeGlobal().cache(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 0924232f2d..a622f96c17 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -35,6 +35,7 @@ import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.Version; import net.osmand.plus.activities.search.SearchActivity; +import net.osmand.plus.activities.search.SearchAddressFragment; import net.osmand.plus.base.FailSafeFuntions; import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.dashboard.DashboardOnMap; @@ -46,6 +47,7 @@ import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback; import net.osmand.plus.views.AnimateDraggingMapThread; +import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.OsmAndMapLayersView; import net.osmand.plus.views.OsmAndMapSurfaceView; import net.osmand.plus.views.OsmandMapLayer; @@ -890,6 +892,10 @@ public class MapActivity extends AccessibleActivity { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { OsmandPlugin.onMapActivityResult(requestCode, resultCode, data); + MapControlsLayer mcl = mapView.getLayerByClass(MapControlsLayer.class); + if(mcl != null) { + mcl.onActivityResult(requestCode, resultCode, data); + } } public void refreshMap() { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index ce86b58de4..8ebc6959a2 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -223,6 +223,17 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { }); if (waypointsVisible && getMyApplication().getWaypointHelper().getAllPoints().size() > 0) { + if (mapActivity.getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0) { + sort.setVisibility(View.VISIBLE); + sort.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + hideDashboard(); + IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity, getMyApplication(), true); + } + }); + } edit.setVisibility(View.VISIBLE); edit.setOnClickListener(new View.OnClickListener() { @@ -256,17 +267,6 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks { hideDashboard(); } }); - if (mapActivity.getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0) { - sort.setVisibility(View.VISIBLE); - sort.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - hideDashboard(); - IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity, getMyApplication(), true); - } - }); - } } if (visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.LIST_MENU) { settings.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index cfe307b2cc..9382c75597 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -689,7 +689,7 @@ public class WaypointHelper { return null; } else if(type == TARGETS) { int i = !((TargetPoint)point).intermediate? R.drawable.list_destination : - R.drawable.list_destination; + R.drawable.list_intermediate; return uiCtx.getResources().getDrawable(i); } else if(type == FAVORITES || type == WAYPOINTS) { return FavoriteImageDrawable.getOrCreate(uiCtx, point.getColor()); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 32eb93c839..38004852af 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -8,6 +8,7 @@ import java.util.List; import net.londatiga.android.ActionItem; import net.londatiga.android.QuickAction; import net.osmand.core.android.MapRendererContext; +import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; @@ -16,6 +17,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.search.SearchAddressFragment; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.controls.MapRouteInfoControl; @@ -23,6 +25,7 @@ import net.osmand.plus.views.controls.MapRoutePreferencesControl; import net.osmand.plus.views.corenative.NativeCoreContext; import android.app.AlertDialog; import android.content.DialogInterface; +import android.content.Intent; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; @@ -41,6 +44,7 @@ import android.widget.TextView; public class MapControlsLayer extends OsmandMapLayer { private static final int TIMEOUT_TO_SHOW_BUTTONS = 7000; + public static final int REQUEST_ADDRESS_SELECT = 2; public MapHudButton createHudButton(View iv, int resId) { MapHudButton mc = new MapHudButton(); @@ -810,4 +814,18 @@ public class MapControlsLayer extends OsmandMapLayer { }; return listener; } + + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if(requestCode == REQUEST_ADDRESS_SELECT && resultCode == SearchAddressFragment.SELECT_ADDRESS_POINT_RESULT_OK){ + String name = data.getStringExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_INTENT_KEY); + LatLon latLon = new LatLon( + data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LAT, 0), + data.getDoubleExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_LON, 0)); + if(name != null){ + mapRouteInfoControlDialog.selectAddress(name, latLon, false); + } else { + mapRouteInfoControlDialog.selectAddress("", latLon, true); + } + } + } } diff --git a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java index 00f54b230e..ce3449262b 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java @@ -78,8 +78,10 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu @Override public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) { + if(tb.getZoom() < 3) { + return; + } int index = 0; - TargetPointsHelper targetPoints = map.getMyApplication().getTargetPointsHelper(); for (TargetPoint ip : targetPoints.getIntermediatePoints()) { index ++; diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java index 3ba2641917..c579d3968c 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java @@ -5,6 +5,7 @@ import java.util.List; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; @@ -13,6 +14,9 @@ import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.FavoritesListFragment.FavouritesAdapter; +import net.osmand.plus.activities.search.SearchActivity; +import net.osmand.plus.activities.search.SearchAddressActivity; +import net.osmand.plus.activities.search.SearchAddressFragment; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.ShowRouteInfoActivity; import net.osmand.plus.development.OsmandDevelopmentPlugin; @@ -20,6 +24,7 @@ import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; import net.osmand.plus.views.ContextMenuLayer; +import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.OsmandMapTileView; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -172,6 +177,11 @@ public class MapRouteInfoControl implements IRouteInformationListener { selectFavorite(parentView, false); } else if(position == 2) { selectOnScreen(parentView, false); + } else if(position == 3) { + Intent intent = new Intent(mapActivity, SearchAddressActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + intent.putExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_INTENT_KEY, (String) null); + mapActivity.startActivityForResult(intent, MapControlsLayer.REQUEST_ADDRESS_SELECT); } } @@ -186,6 +196,11 @@ public class MapRouteInfoControl implements IRouteInformationListener { selectFavorite(parentView, true); } else if(position == 2) { selectOnScreen(parentView, true); + } else if(position == 3) { + Intent intent = new Intent(mapActivity, SearchAddressActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + intent.putExtra(SearchAddressFragment.SELECT_ADDRESS_POINT_INTENT_KEY, (String) null); + mapActivity.startActivityForResult(intent, MapControlsLayer.REQUEST_ADDRESS_SELECT); } } @@ -201,6 +216,16 @@ public class MapRouteInfoControl implements IRouteInformationListener { selectFromMapForTarget = target; hideDialog(); } + + public void selectAddress(String name, LatLon l, final boolean target) { + PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, name); + if(target) { + getTargets().navigateToPoint(l, true, -1, pd); + } else { + getTargets().setStartPoint(l, true, pd); + } + showDialog(); + } protected void selectFavorite(final View parentView, final boolean target) { Builder bld = new AlertDialog.Builder(mapActivity); @@ -361,6 +386,7 @@ public class MapRouteInfoControl implements IRouteInformationListener { fromActions.add(mapActivity.getString(R.string.route_descr_current_location)); fromActions.add(mapActivity.getString(R.string.shared_string_favorite) + mapActivity.getString(R.string.shared_string_ellipsis)); fromActions.add(mapActivity.getString(R.string.shared_string_select_on_map)); + fromActions.add(mapActivity.getString(R.string.shared_string_address) + mapActivity.getString(R.string.shared_string_ellipsis)); TargetPoint start = getTargets().getPointToStart(); if (start != null) { @@ -400,6 +426,7 @@ public class MapRouteInfoControl implements IRouteInformationListener { } toActions.add(mapActivity.getString(R.string.shared_string_favorite) + mapActivity.getString(R.string.shared_string_ellipsis)); toActions.add(mapActivity.getString(R.string.shared_string_select_on_map)); + toActions.add(mapActivity.getString(R.string.shared_string_address) + mapActivity.getString(R.string.shared_string_ellipsis)); ArrayAdapter toAdapter = new ArrayAdapter(view.getContext(), android.R.layout.simple_spinner_item, diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index 96e0efd905..082a3e6952 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -1,7 +1,6 @@ package net.osmand.plus.views.mapwidgets; import net.osmand.Location; -import net.osmand.access.AccessibleToast; import net.osmand.binary.RouteDataObject; import net.osmand.plus.ApplicationMode; import net.osmand.plus.NavigationService; @@ -23,7 +22,6 @@ import net.osmand.plus.monitoring.ValueHolder; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; -import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.controls.MapRouteInfoControl; import net.osmand.plus.views.mapwidgets.NextTurnInfoWidget.TurnDrawable; import net.osmand.router.TurnType; @@ -33,18 +31,12 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Typeface; -import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; -import android.view.Gravity; -import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; -import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.LinearLayout.LayoutParams; import android.widget.TextView; -import android.widget.Toast; public class MapInfoWidgetsFactory { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index 1a82c65c8f..ce1e3d0274 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -220,7 +220,9 @@ public class MapWidgetRegistry { addControlId(mil, cm, R.string.map_widget_show_destination_arrow, settings.SHOW_DESTINATION_ARROW); addControlId(mil, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME); addControlId(mil, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP); - addControlId(mil, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME); + if(mode != ApplicationMode.DEFAULT) { + addControlId(mil, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME); + } }