Added Transport stop's context menu

This commit is contained in:
Alexey Kulish 2016-02-29 10:47:14 +03:00
parent a9fc79463f
commit 3cc8bd5522
3 changed files with 81 additions and 30 deletions

View file

@ -9,6 +9,7 @@ import net.osmand.data.Amenity;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.MapMarkersHelper;
@ -30,6 +31,7 @@ import net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController;
import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController;
import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController;
import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController;
import net.osmand.plus.mapcontextmenu.other.ShareMenu;
import net.osmand.plus.osmedit.EditPOIMenuController;
@ -106,6 +108,8 @@ public abstract class MenuController extends BaseMenuController {
menuController = new GpxItemMenuController(app, mapActivity, pointDescription, (GpxDisplayItem) object);
} else if (object instanceof MapMarker) {
menuController = new MapMarkerMenuController(app, mapActivity, pointDescription, (MapMarker) object);
} else if (object instanceof TransportStop) {
menuController = new TransportStopController(app, mapActivity, pointDescription, (TransportStop) object);
} else if (object instanceof LatLon) {
if (pointDescription.isParking()) {
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription);

View file

@ -0,0 +1,77 @@
package net.osmand.plus.mapcontextmenu.controllers;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.resources.TransportIndexRepository;
import java.util.List;
public class TransportStopController extends MenuController {
private TransportStop transportStop;
public TransportStopController(OsmandApplication app, MapActivity mapActivity,
PointDescription pointDescription, TransportStop transportStop) {
super(new MenuBuilder(app), pointDescription, mapActivity);
this.transportStop = transportStop;
}
@Override
protected void setObject(Object object) {
if (object instanceof TransportStop) {
this.transportStop = (TransportStop) object;
}
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
}
@Override
public int getLeftIconId() {
return R.drawable.mx_public_transport_stop_position;
}
@Override
public boolean displayDistanceDirection() {
return true;
}
@Override
public String getTypeStr() {
return getPointDescription().getTypeName();
}
@Override
public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) {
List<TransportIndexRepository> reps = getMapActivity().getMyApplication()
.getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(),
transportStop.getLocation().getLongitude());
boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
for (TransportIndexRepository t : reps) {
if (t.acceptTransportStop(transportStop)) {
List<String> l;
if (useEnglishNames) {
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {3}");
} else {
l = t.getRouteDescriptionsForStop(transportStop, "{1} {0} - {2}");
}
if (l != null) {
for (String s : l) {
addPlainMenuItem(R.drawable.ic_action_polygom_dark, s, false, false);
}
}
}
}
}
}

View file

@ -4,18 +4,14 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.support.v7.app.AlertDialog;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.R;
import net.osmand.plus.resources.TransportIndexRepository;
@ -161,13 +157,6 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
return null;
}
private void showDescriptionDialog(TransportStop a) {
AlertDialog.Builder bs = new AlertDialog.Builder(view.getContext());
bs.setTitle(a.getName(view.getSettings().MAP_PREFERRED_LOCALE.get()));
bs.setMessage(getStopDescription(a, true));
bs.show();
}
@Override
public PointDescription getObjectName(Object o) {
if(o instanceof TransportStop){
@ -199,23 +188,4 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
}
return null;
}
@Override
public void populateObjectContextMenu(Object o, ContextMenuAdapter adapter) {
if(o instanceof TransportStop){
final TransportStop a = (TransportStop) o;
OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
showDescriptionDialog(a);
return true;
}
};
adapter.item(R.string.poi_context_menu_showdescription)
.iconColor( R.drawable.ic_action_note_dark).listen(listener).reg();
}
}
}