Context menu: added Destination and Intermediate points

This commit is contained in:
Alexey Kulish 2015-10-29 11:46:46 +03:00
parent dc9c29fc52
commit fa8bff7d36
8 changed files with 146 additions and 48 deletions

View file

@ -2,10 +2,12 @@ package net.osmand.data;
import android.content.Context; import android.content.Context;
import java.io.Serializable;
/** /**
*/ */
public interface LocationPoint { public interface LocationPoint extends Serializable {
public double getLatitude(); public double getLatitude();

View file

@ -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) { protected Drawable getIcon(int iconId) {
return getIcon(iconId, R.color.icon_color, R.color.icon_color_light); return getIcon(iconId, R.color.icon_color, R.color.icon_color_light);
} }

View file

@ -10,14 +10,17 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; 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.activities.MapActivity;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.mapcontextmenu.details.AmenityMenuController; import net.osmand.plus.mapcontextmenu.details.AmenityMenuController;
import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController; import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController;
import net.osmand.plus.mapcontextmenu.details.HistoryMenuController; import net.osmand.plus.mapcontextmenu.details.HistoryMenuController;
import net.osmand.plus.mapcontextmenu.details.MyLocationMenuController; 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.PointDescriptionMenuController;
import net.osmand.plus.mapcontextmenu.details.TargetPointMenuController;
public abstract class MenuController extends BaseMenuController { public abstract class MenuController extends BaseMenuController {
@ -51,9 +54,11 @@ public abstract class MenuController extends BaseMenuController {
menuController = new FavouritePointMenuController(app, mapActivity, (FavouritePoint) object); menuController = new FavouritePointMenuController(app, mapActivity, (FavouritePoint) object);
} else if (object instanceof SearchHistoryHelper.HistoryEntry) { } else if (object instanceof SearchHistoryHelper.HistoryEntry) {
menuController = new HistoryMenuController(app, mapActivity, (SearchHistoryHelper.HistoryEntry) object); 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) { } else if (object instanceof LatLon) {
if (pointDescription.isParking()) { if (pointDescription.isParking()) {
menuController = new ParkingPositionController(app, mapActivity, pointDescription, (LatLon) object); menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription, (LatLon) object);
} else if (pointDescription.isMyLocation()) { } else if (pointDescription.isMyLocation()) {
menuController = new MyLocationMenuController(app, mapActivity, pointDescription, (LatLon) object); menuController = new MyLocationMenuController(app, mapActivity, pointDescription, (LatLon) object);
} }
@ -162,6 +167,10 @@ public abstract class MenuController extends BaseMenuController {
return false; return false;
} }
public boolean displayStreetNameinTitle() {
return false;
}
public int getLeftIconId() { return 0; } public int getLeftIconId() { return 0; }
public Drawable getLeftIcon() { return null; } public Drawable getLeftIcon() { return null; }

View file

@ -9,6 +9,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -139,7 +140,8 @@ public abstract class MenuTitleController {
object.getRef(), object.getDestinationName(settings.MAP_PREFERRED_LOCALE.get())); object.getRef(), object.getDestinationName(settings.MAP_PREFERRED_LOCALE.get()));
if (!Algorithms.isEmpty(streetStr)) { if (!Algorithms.isEmpty(streetStr)) {
if (getObject() == null) { MenuController menuController = getMenuController();
if (menuController == null || menuController.displayStreetNameinTitle()) {
nameStr = streetStr; nameStr = streetStr;
addressUnknown = false; addressUnknown = false;
streetStr = ""; streetStr = "";

View file

@ -14,14 +14,14 @@ import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
public class ParkingPositionController extends MenuController { public class ParkingPositionMenuController extends MenuController {
private PointDescription pointDescription; private PointDescription pointDescription;
private LatLon latLon; private LatLon latLon;
ParkingPositionPlugin plugin; ParkingPositionPlugin plugin;
String parkingDescription = ""; 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); super(new MenuBuilder(app), mapActivity);
this.pointDescription = pointDescription; this.pointDescription = pointDescription;
this.latLon = latLon; this.latLon = latLon;

View file

@ -36,6 +36,11 @@ public class PointDescriptionMenuController extends MenuController {
return (typeName != null && !typeName.isEmpty()); return (typeName != null && !typeName.isEmpty());
} }
@Override
public boolean displayStreetNameinTitle() {
return true;
}
@Override @Override
public Drawable getLeftIcon() { public Drawable getLeftIcon() {
return getIcon(SearchHistoryFragment.getItemIcon(pointDescription)); return getIcon(SearchHistoryFragment.getItemIcon(pointDescription));

View file

@ -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);
}
}

View file

@ -1,18 +1,5 @@
package net.osmand.plus.views; 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.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
@ -21,7 +8,18 @@ import android.graphics.Paint;
import android.graphics.Paint.Align; import android.graphics.Paint.Align;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.PointF; 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 { public class PointNavigationLayer extends OsmandMapLayer implements IContextMenuProvider {
protected final static int DIST_TO_SHOW = 80; protected final static int DIST_TO_SHOW = 80;
@ -216,32 +214,4 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
} }
return null; 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();
}
}
} }