diff --git a/OsmAnd/src/net/osmand/data/LocationPoint.java b/OsmAnd/src/net/osmand/data/LocationPoint.java index 72070fd649..2973ecbc12 100644 --- a/OsmAnd/src/net/osmand/data/LocationPoint.java +++ b/OsmAnd/src/net/osmand/data/LocationPoint.java @@ -2,10 +2,12 @@ package net.osmand.data; import android.content.Context; +import java.io.Serializable; + /** */ -public interface LocationPoint { +public interface LocationPoint extends Serializable { public double getLatitude(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java index 536a333198..12ba5a0d22 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java @@ -59,6 +59,11 @@ public abstract class BaseMenuController { } } + protected Drawable getIconOrig(int iconId) { + IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache(); + return iconsCache.getIcon(iconId, 0, 0f); + } + protected Drawable getIcon(int iconId) { return getIcon(iconId, R.color.icon_color, R.color.icon_color_light); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 1fda77762f..95b2118b4c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -10,14 +10,17 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; +import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.mapcontextmenu.details.AmenityMenuController; import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController; import net.osmand.plus.mapcontextmenu.details.HistoryMenuController; import net.osmand.plus.mapcontextmenu.details.MyLocationMenuController; -import net.osmand.plus.mapcontextmenu.details.ParkingPositionController; +import net.osmand.plus.mapcontextmenu.details.ParkingPositionMenuController; import net.osmand.plus.mapcontextmenu.details.PointDescriptionMenuController; +import net.osmand.plus.mapcontextmenu.details.TargetPointMenuController; public abstract class MenuController extends BaseMenuController { @@ -51,9 +54,11 @@ public abstract class MenuController extends BaseMenuController { menuController = new FavouritePointMenuController(app, mapActivity, (FavouritePoint) object); } else if (object instanceof SearchHistoryHelper.HistoryEntry) { menuController = new HistoryMenuController(app, mapActivity, (SearchHistoryHelper.HistoryEntry) object); + } else if (object instanceof TargetPoint) { + menuController = new TargetPointMenuController(app, mapActivity, (TargetPoint) object); } else if (object instanceof LatLon) { if (pointDescription.isParking()) { - menuController = new ParkingPositionController(app, mapActivity, pointDescription, (LatLon) object); + menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription, (LatLon) object); } else if (pointDescription.isMyLocation()) { menuController = new MyLocationMenuController(app, mapActivity, pointDescription, (LatLon) object); } @@ -162,6 +167,10 @@ public abstract class MenuController extends BaseMenuController { return false; } + public boolean displayStreetNameinTitle() { + return false; + } + public int getLeftIconId() { return 0; } public Drawable getLeftIcon() { return null; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java index b69d600f04..a47040fc69 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuTitleController.java @@ -9,6 +9,7 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.routing.RoutingHelper; import net.osmand.util.Algorithms; @@ -139,7 +140,8 @@ public abstract class MenuTitleController { object.getRef(), object.getDestinationName(settings.MAP_PREFERRED_LOCALE.get())); if (!Algorithms.isEmpty(streetStr)) { - if (getObject() == null) { + MenuController menuController = getMenuController(); + if (menuController == null || menuController.displayStreetNameinTitle()) { nameStr = streetStr; addressUnknown = false; streetStr = ""; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionMenuController.java similarity index 91% rename from OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionController.java rename to OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionMenuController.java index 8ef8e891e5..fc6845e386 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/ParkingPositionMenuController.java @@ -14,14 +14,14 @@ import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.util.Algorithms; -public class ParkingPositionController extends MenuController { +public class ParkingPositionMenuController extends MenuController { private PointDescription pointDescription; private LatLon latLon; ParkingPositionPlugin plugin; String parkingDescription = ""; - public ParkingPositionController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription, LatLon latLon) { + public ParkingPositionMenuController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription, LatLon latLon) { super(new MenuBuilder(app), mapActivity); this.pointDescription = pointDescription; this.latLon = latLon; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuController.java index 370625ebcb..f4d3114ed9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/PointDescriptionMenuController.java @@ -36,6 +36,11 @@ public class PointDescriptionMenuController extends MenuController { return (typeName != null && !typeName.isEmpty()); } + @Override + public boolean displayStreetNameinTitle() { + return true; + } + @Override public Drawable getLeftIcon() { return getIcon(SearchHistoryFragment.getItemIcon(pointDescription)); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/TargetPointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/TargetPointMenuController.java new file mode 100644 index 0000000000..ea8163db43 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/TargetPointMenuController.java @@ -0,0 +1,105 @@ +package net.osmand.plus.mapcontextmenu.details; + +import android.graphics.drawable.Drawable; +import android.os.Bundle; + +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; +import net.osmand.plus.TargetPointsHelper.TargetPoint; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.MenuController; +import net.osmand.plus.parkingpoint.ParkingPositionPlugin; +import net.osmand.util.Algorithms; + +public class TargetPointMenuController extends MenuController { + + private TargetPoint targetPoint; + + public TargetPointMenuController(OsmandApplication app, MapActivity mapActivity, final TargetPoint targetPoint) { + super(new MenuBuilder(app), mapActivity); + this.targetPoint = targetPoint; + } + + @Override + protected int getInitialMenuStatePortrait() { + return MenuState.HEADER_ONLY; + } + + @Override + protected int getSupportedMenuStatesPortrait() { + return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN; + } + + @Override + public boolean needTypeStr() { + return true; + } + + @Override + public Drawable getLeftIcon() { + if (!targetPoint.intermediate) { + if (isLight()) { + return getIconOrig(R.drawable.widget_target_day); + } else { + return getIconOrig(R.drawable.widget_target_night); + } + } else { + if (isLight()) { + return getIconOrig(R.drawable.widget_intermediate_day); + } else { + return getIconOrig(R.drawable.widget_intermediate_night); + } + } + } + + @Override + public String getNameStr() { + return targetPoint.getOriginalPointDescription().getSimpleName(getMapActivity(), false); + } + + @Override + public String getTypeStr() { + return targetPoint.getOnlyName(); + } + + @Override + public boolean displayStreetNameinTitle() { + return true; + } + + @Override + public boolean hasTitleButton() { + return true; + } + + @Override + public String getTitleButtonCaption() { + return getMapActivity().getString(R.string.delete_target_point); + } + + @Override + public void titleButtonPressed() { + TargetPointsHelper targetPointsHelper = getMapActivity().getMyApplication().getTargetPointsHelper(); + if(targetPoint.intermediate) { + targetPointsHelper.removeWayPoint(true, targetPoint.index); + } else { + targetPointsHelper.removeWayPoint(true, -1); + } + getMapActivity().getContextMenu().close(); + } + + @Override + public boolean needStreetName() { + return true; + } + + @Override + public void saveEntityState(Bundle bundle, String key) { + bundle.putSerializable(key, targetPoint); + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java index 5fc901a11c..060c1330ea 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java @@ -1,18 +1,5 @@ package net.osmand.plus.views; -import java.util.List; - -import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; -import net.osmand.data.QuadPoint; -import net.osmand.data.RotatedTileBox; -import net.osmand.plus.ContextMenuAdapter; -import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; -import net.osmand.plus.R; -import net.osmand.plus.TargetPointsHelper; -import net.osmand.plus.TargetPointsHelper.TargetPoint; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -21,7 +8,18 @@ import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.Paint.Style; import android.graphics.PointF; -import android.widget.ArrayAdapter; + +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.data.QuadPoint; +import net.osmand.data.RotatedTileBox; +import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; +import net.osmand.plus.TargetPointsHelper.TargetPoint; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; + +import java.util.List; public class PointNavigationLayer extends OsmandMapLayer implements IContextMenuProvider { protected final static int DIST_TO_SHOW = 80; @@ -216,32 +214,4 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu } return null; } - - @Override - public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) { - if(o instanceof TargetPoint) { - final TargetPoint a = (TargetPoint) o; - OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() { - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - if (itemId == R.string.delete_target_point) { - TargetPointsHelper targetPointsHelper = map.getMyApplication().getTargetPointsHelper(); - if(a.intermediate) { - targetPointsHelper.removeWayPoint(true, a.index); - } else { - targetPointsHelper.removeWayPoint(true, -1); - } - } - map.getContextMenu().close(); - return true; - } - }; - - - adapter.item(R.string.delete_target_point) - .iconColor( R.drawable.ic_action_remove_dark).listen(listener).reg(); - - } - } - }