Add transport route
This commit is contained in:
parent
99c3d9ca18
commit
6dd56084fe
6 changed files with 48 additions and 256 deletions
|
@ -174,7 +174,7 @@
|
||||||
|
|
||||||
<color name="nav_track">#CCaa0088</color>
|
<color name="nav_track">#CCaa0088</color>
|
||||||
<color name="nav_track_fluorescent">#CC00ddff</color>
|
<color name="nav_track_fluorescent">#CC00ddff</color>
|
||||||
<color name="transport_route_line">#CCaa0088</color>
|
<color name="transport_route_line">#CC2f7af5</color>
|
||||||
|
|
||||||
|
|
||||||
<color name="nav_arrow_distant">#C0C0C0</color>
|
<color name="nav_arrow_distant">#C0C0C0</color>
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
package net.osmand.plus.activities;
|
package net.osmand.plus.activities;
|
||||||
|
|
||||||
|
|
||||||
import android.content.DialogInterface;
|
import java.util.ArrayList;
|
||||||
import android.content.Intent;
|
import java.util.LinkedHashMap;
|
||||||
import android.graphics.drawable.Drawable;
|
import java.util.List;
|
||||||
import android.support.v7.app.AlertDialog;
|
import java.util.Map.Entry;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import net.osmand.CallbackWithObject;
|
import net.osmand.CallbackWithObject;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
|
@ -50,14 +44,18 @@ import net.osmand.plus.views.POIMapLayer;
|
||||||
import net.osmand.plus.views.PointLocationLayer;
|
import net.osmand.plus.views.PointLocationLayer;
|
||||||
import net.osmand.plus.views.PointNavigationLayer;
|
import net.osmand.plus.views.PointNavigationLayer;
|
||||||
import net.osmand.plus.views.RouteLayer;
|
import net.osmand.plus.views.RouteLayer;
|
||||||
import net.osmand.plus.views.TransportInfoLayer;
|
|
||||||
import net.osmand.plus.views.TransportStopsLayer;
|
import net.osmand.plus.views.TransportStopsLayer;
|
||||||
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
|
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import java.util.ArrayList;
|
import android.content.Intent;
|
||||||
import java.util.LinkedHashMap;
|
import android.graphics.drawable.Drawable;
|
||||||
import java.util.List;
|
import android.support.v7.app.AlertDialog;
|
||||||
import java.util.Map.Entry;
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Object is responsible to maintain layers using by map activity
|
* Object is responsible to maintain layers using by map activity
|
||||||
|
@ -74,7 +72,6 @@ public class MapActivityLayers {
|
||||||
private POIMapLayer poiMapLayer;
|
private POIMapLayer poiMapLayer;
|
||||||
private FavouritesLayer mFavouritesLayer;
|
private FavouritesLayer mFavouritesLayer;
|
||||||
private TransportStopsLayer transportStopsLayer;
|
private TransportStopsLayer transportStopsLayer;
|
||||||
private TransportInfoLayer transportInfoLayer;
|
|
||||||
private PointLocationLayer locationLayer;
|
private PointLocationLayer locationLayer;
|
||||||
private PointNavigationLayer navigationLayer;
|
private PointNavigationLayer navigationLayer;
|
||||||
private MapMarkersLayer mapMarkersLayer;
|
private MapMarkersLayer mapMarkersLayer;
|
||||||
|
@ -142,9 +139,6 @@ public class MapActivityLayers {
|
||||||
mapView.addLayer(mFavouritesLayer, 4);
|
mapView.addLayer(mFavouritesLayer, 4);
|
||||||
// 5. transport layer
|
// 5. transport layer
|
||||||
transportStopsLayer = new TransportStopsLayer();
|
transportStopsLayer = new TransportStopsLayer();
|
||||||
// 5.5 transport info layer
|
|
||||||
transportInfoLayer = new TransportInfoLayer(TransportRouteHelper.getInstance());
|
|
||||||
mapView.addLayer(transportInfoLayer, 5.5f);
|
|
||||||
// 5.95 all text labels
|
// 5.95 all text labels
|
||||||
// 6. point location layer
|
// 6. point location layer
|
||||||
locationLayer = new PointLocationLayer(activity.getMapViewTrackingUtilities());
|
locationLayer = new PointLocationLayer(activity.getMapViewTrackingUtilities());
|
||||||
|
@ -600,11 +594,12 @@ public class MapActivityLayers {
|
||||||
public POIMapLayer getPoiMapLayer() {
|
public POIMapLayer getPoiMapLayer() {
|
||||||
return poiMapLayer;
|
return poiMapLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TransportInfoLayer getTransportInfoLayer() {
|
public TransportStopsLayer getTransportStopsLayer() {
|
||||||
return transportInfoLayer;
|
return transportStopsLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public DownloadedRegionsLayer getDownloadedRegionsLayer() {
|
public DownloadedRegionsLayer getDownloadedRegionsLayer() {
|
||||||
return downloadedRegionsLayer;
|
return downloadedRegionsLayer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
package net.osmand.plus.activities;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.osmand.plus.resources.TransportIndexRepository.RouteInfoLocation;
|
|
||||||
|
|
||||||
|
|
||||||
public class TransportRouteHelper {
|
|
||||||
private static TransportRouteHelper inst = new TransportRouteHelper();
|
|
||||||
public static TransportRouteHelper getInstance(){
|
|
||||||
return inst;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<RouteInfoLocation> route = new ArrayList<RouteInfoLocation>();
|
|
||||||
|
|
||||||
public List<RouteInfoLocation> getRoute() {
|
|
||||||
return route;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean routeIsCalculated(){
|
|
||||||
if(route.isEmpty()){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(route.size() == 1 && route.get(0) == null){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRoute(List<RouteInfoLocation> route) {
|
|
||||||
this.route = route;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,16 +1,17 @@
|
||||||
package net.osmand.plus.dialogs;
|
package net.osmand.plus.dialogs;
|
||||||
|
|
||||||
import android.content.Context;
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.DialogInterface.OnMultiChoiceClickListener;
|
import java.util.ArrayList;
|
||||||
import android.content.Intent;
|
import java.util.Arrays;
|
||||||
import android.support.annotation.DrawableRes;
|
import java.util.Collection;
|
||||||
import android.support.annotation.StringRes;
|
import java.util.Collections;
|
||||||
import android.support.v7.app.AlertDialog;
|
import java.util.Comparator;
|
||||||
import android.view.View;
|
import java.util.HashMap;
|
||||||
import android.widget.ArrayAdapter;
|
import java.util.Iterator;
|
||||||
import android.widget.CompoundButton;
|
import java.util.List;
|
||||||
import android.widget.Toast;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.core.android.MapRendererContext;
|
import net.osmand.core.android.MapRendererContext;
|
||||||
|
@ -28,7 +29,6 @@ import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.MapActivityLayers;
|
import net.osmand.plus.activities.MapActivityLayers;
|
||||||
import net.osmand.plus.activities.PluginActivity;
|
import net.osmand.plus.activities.PluginActivity;
|
||||||
import net.osmand.plus.activities.SettingsActivity;
|
import net.osmand.plus.activities.SettingsActivity;
|
||||||
import net.osmand.plus.activities.TransportRouteHelper;
|
|
||||||
import net.osmand.plus.poi.PoiFiltersHelper;
|
import net.osmand.plus.poi.PoiFiltersHelper;
|
||||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
|
@ -43,18 +43,17 @@ import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import android.content.Context;
|
||||||
import java.util.Arrays;
|
import android.content.DialogInterface;
|
||||||
import java.util.Collection;
|
import android.content.DialogInterface.OnMultiChoiceClickListener;
|
||||||
import java.util.Collections;
|
import android.content.Intent;
|
||||||
import java.util.Comparator;
|
import android.support.annotation.DrawableRes;
|
||||||
import java.util.HashMap;
|
import android.support.annotation.StringRes;
|
||||||
import java.util.Iterator;
|
import android.support.v7.app.AlertDialog;
|
||||||
import java.util.List;
|
import android.view.View;
|
||||||
import java.util.Locale;
|
import android.widget.ArrayAdapter;
|
||||||
import java.util.Map;
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.Toast;
|
||||||
import gnu.trove.list.array.TIntArrayList;
|
|
||||||
|
|
||||||
public class ConfigureMapMenu {
|
public class ConfigureMapMenu {
|
||||||
private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class);
|
private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class);
|
||||||
|
@ -158,8 +157,6 @@ public class ConfigureMapMenu {
|
||||||
} else {
|
} else {
|
||||||
ma.getMapLayers().selectMapLayer(ma.getMapView());
|
ma.getMapLayers().selectMapLayer(ma.getMapView());
|
||||||
}
|
}
|
||||||
} else if (itemId == R.string.layer_transport_route) {
|
|
||||||
ma.getMapLayers().getTransportInfoLayer().setVisible(isChecked);
|
|
||||||
}
|
}
|
||||||
ma.getMapLayers().updateLayers(ma.getMapView());
|
ma.getMapLayers().updateLayers(ma.getMapView());
|
||||||
ma.getMapView().refreshMap();
|
ma.getMapView().refreshMap();
|
||||||
|
@ -252,14 +249,6 @@ public class ConfigureMapMenu {
|
||||||
.setTitleId(R.string.layer_map, activity)
|
.setTitleId(R.string.layer_map, activity)
|
||||||
.setIcon(R.drawable.ic_world_globe_dark)
|
.setIcon(R.drawable.ic_world_globe_dark)
|
||||||
.setListener(l).createItem());
|
.setListener(l).createItem());
|
||||||
if (TransportRouteHelper.getInstance().routeIsCalculated()) {
|
|
||||||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
|
||||||
.setTitleId(R.string.layer_transport_route, activity)
|
|
||||||
.setSelected(true)
|
|
||||||
.setColor(R.color.osmand_orange)
|
|
||||||
.setIcon(R.drawable.ic_action_bus_dark)
|
|
||||||
.setListener(l).createItem());
|
|
||||||
}
|
|
||||||
|
|
||||||
OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
|
OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
|
||||||
app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
|
app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package net.osmand.plus.mapcontextmenu.controllers;
|
package net.osmand.plus.mapcontextmenu.controllers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.TransportRoute;
|
import net.osmand.data.TransportRoute;
|
||||||
|
@ -11,12 +14,8 @@ import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||||
import net.osmand.plus.resources.TransportIndexRepository;
|
import net.osmand.plus.resources.TransportIndexRepository;
|
||||||
import net.osmand.plus.views.TransportInfoLayer;
|
import net.osmand.plus.views.TransportStopsLayer;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
|
||||||
|
@ -123,8 +122,8 @@ public class TransportStopController extends MenuController {
|
||||||
public void onClick(View arg0) {
|
public void onClick(View arg0) {
|
||||||
MapContextMenu mm = getMapActivity().getContextMenu();
|
MapContextMenu mm = getMapActivity().getContextMenu();
|
||||||
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, r.desc);
|
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, r.desc);
|
||||||
TransportInfoLayer tif = getMapActivity().getMapLayers().getTransportInfoLayer();
|
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
||||||
tif.
|
stopsLayer.setRoute(r.route);
|
||||||
mm.show(latLon, pd, r);
|
mm.show(latLon, pd, r);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,157 +0,0 @@
|
||||||
package net.osmand.plus.views;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.osmand.data.LatLon;
|
|
||||||
import net.osmand.data.RotatedTileBox;
|
|
||||||
import net.osmand.data.TransportRoute;
|
|
||||||
import net.osmand.data.TransportStop;
|
|
||||||
import net.osmand.plus.R;
|
|
||||||
import net.osmand.plus.activities.TransportRouteHelper;
|
|
||||||
import net.osmand.plus.resources.TransportIndexRepository.RouteInfoLocation;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.PointF;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
public class TransportInfoLayer extends OsmandMapLayer {
|
|
||||||
|
|
||||||
private final TransportRouteHelper routeHelper;
|
|
||||||
private OsmandMapTileView view;
|
|
||||||
private Paint paintInt;
|
|
||||||
private Paint paintEnd;
|
|
||||||
private boolean visible = true;
|
|
||||||
|
|
||||||
public TransportInfoLayer(TransportRouteHelper routeHelper){
|
|
||||||
this.routeHelper = routeHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initLayer(OsmandMapTileView view) {
|
|
||||||
this.view = view;
|
|
||||||
|
|
||||||
paintInt = new Paint();
|
|
||||||
paintInt.setColor(view.getResources().getColor(R.color.transport_int));
|
|
||||||
paintInt.setAntiAlias(true);
|
|
||||||
paintEnd = new Paint();
|
|
||||||
paintEnd.setColor(view.getResources().getColor(R.color.transport_end));
|
|
||||||
paintEnd.setAntiAlias(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isVisible() {
|
|
||||||
return visible;
|
|
||||||
}
|
|
||||||
public void setVisible(boolean visible) {
|
|
||||||
this.visible = visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getRadius(RotatedTileBox tb){
|
|
||||||
final double zoom = tb.getZoom();
|
|
||||||
if(zoom <= 16) {
|
|
||||||
return (int) (tb.getDensity() * 8);
|
|
||||||
}
|
|
||||||
return (int) (tb.getDensity() * 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
|
||||||
if (routeHelper.routeIsCalculated() && visible) {
|
|
||||||
List<RouteInfoLocation> list = routeHelper.getRoute();
|
|
||||||
for (RouteInfoLocation l : list) {
|
|
||||||
if (l == null) {
|
|
||||||
// once l is null in list
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TransportRoute route = l.getRoute();
|
|
||||||
boolean start = false;
|
|
||||||
boolean end = false;
|
|
||||||
List<TransportStop> stops = l.getDirection() ? route.getForwardStops() : route.getBackwardStops();
|
|
||||||
for (int i = 0; i < stops.size() && !end; i++) {
|
|
||||||
Paint toShow = paintInt;
|
|
||||||
TransportStop st = stops.get(i);
|
|
||||||
if (!start) {
|
|
||||||
if (st == l.getStart()) {
|
|
||||||
start = true;
|
|
||||||
toShow = paintEnd;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (st == l.getStop()) {
|
|
||||||
end = true;
|
|
||||||
toShow = paintEnd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (start) {
|
|
||||||
LatLon location = st.getLocation();
|
|
||||||
if (tileBox.containsLatLon(location.getLatitude(), location.getLongitude())) {
|
|
||||||
int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
|
||||||
int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
|
||||||
canvas.drawRect(x - getRadius(tileBox), y - getRadius(tileBox), x + getRadius(tileBox), y
|
|
||||||
+ getRadius(tileBox), toShow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void destroyLayer() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean drawInScreenPixels() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
|
||||||
int ex = (int) point.x;
|
|
||||||
int ey = (int) point.y;
|
|
||||||
if (visible && !routeHelper.getRoute().isEmpty()) {
|
|
||||||
for (RouteInfoLocation l : routeHelper.getRoute()) {
|
|
||||||
if(l == null){
|
|
||||||
// once l is null in list
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TransportRoute route = l.getRoute();
|
|
||||||
boolean start = false;
|
|
||||||
boolean end = false;
|
|
||||||
List<TransportStop> stops = l.getDirection() ? route.getForwardStops() : route.getBackwardStops();
|
|
||||||
for (int i = 0; i < stops.size() && !end; i++) {
|
|
||||||
TransportStop st = stops.get(i);
|
|
||||||
if (!start) {
|
|
||||||
if (st == l.getStart()) {
|
|
||||||
start = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (st == l.getStop()) {
|
|
||||||
end = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (start) {
|
|
||||||
LatLon location = st.getLocation();
|
|
||||||
int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
|
|
||||||
int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
|
|
||||||
if (Math.abs(x - ex) < getRadius(tileBox) * 3 /2 && Math.abs(y - ey) < getRadius(tileBox) * 3 /2) {
|
|
||||||
Toast.makeText(view.getContext(), st.getName(view.getSettings().MAP_PREFERRED_LOCALE.get()) + " : " + //$NON-NLS-1$
|
|
||||||
route.getType() + " " + route.getRef() //$NON-NLS-1$
|
|
||||||
, Toast.LENGTH_LONG).show();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue