Add transport route

This commit is contained in:
Victor Shcherb 2016-07-29 18:11:24 +02:00
parent 99c3d9ca18
commit 6dd56084fe
6 changed files with 48 additions and 256 deletions

View file

@ -174,7 +174,7 @@
<color name="nav_track">#CCaa0088</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>

View file

@ -1,16 +1,10 @@
package net.osmand.plus.activities;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AlertDialog;
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 java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import net.osmand.CallbackWithObject;
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.PointNavigationLayer;
import net.osmand.plus.views.RouteLayer;
import net.osmand.plus.views.TransportInfoLayer;
import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AlertDialog;
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
@ -74,7 +72,6 @@ public class MapActivityLayers {
private POIMapLayer poiMapLayer;
private FavouritesLayer mFavouritesLayer;
private TransportStopsLayer transportStopsLayer;
private TransportInfoLayer transportInfoLayer;
private PointLocationLayer locationLayer;
private PointNavigationLayer navigationLayer;
private MapMarkersLayer mapMarkersLayer;
@ -142,9 +139,6 @@ public class MapActivityLayers {
mapView.addLayer(mFavouritesLayer, 4);
// 5. transport layer
transportStopsLayer = new TransportStopsLayer();
// 5.5 transport info layer
transportInfoLayer = new TransportInfoLayer(TransportRouteHelper.getInstance());
mapView.addLayer(transportInfoLayer, 5.5f);
// 5.95 all text labels
// 6. point location layer
locationLayer = new PointLocationLayer(activity.getMapViewTrackingUtilities());
@ -601,10 +595,11 @@ public class MapActivityLayers {
return poiMapLayer;
}
public TransportInfoLayer getTransportInfoLayer() {
return transportInfoLayer;
public TransportStopsLayer getTransportStopsLayer() {
return transportStopsLayer;
}
public DownloadedRegionsLayer getDownloadedRegionsLayer() {
return downloadedRegionsLayer;
}

View file

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

View file

@ -1,16 +1,17 @@
package net.osmand.plus.dialogs;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.Toast;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import net.osmand.PlatformUtil;
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.PluginActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.activities.TransportRouteHelper;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.render.RendererRegistry;
@ -43,18 +43,17 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import gnu.trove.list.array.TIntArrayList;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.Toast;
public class ConfigureMapMenu {
private static final Log LOG = PlatformUtil.getLog(ConfigureMapMenu.class);
@ -158,8 +157,6 @@ public class ConfigureMapMenu {
} else {
ma.getMapLayers().selectMapLayer(ma.getMapView());
}
} else if (itemId == R.string.layer_transport_route) {
ma.getMapLayers().getTransportInfoLayer().setVisible(isChecked);
}
ma.getMapLayers().updateLayers(ma.getMapView());
ma.getMapView().refreshMap();
@ -252,14 +249,6 @@ public class ConfigureMapMenu {
.setTitleId(R.string.layer_map, activity)
.setIcon(R.drawable.ic_world_globe_dark)
.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);
app.getAppCustomization().prepareLayerContextMenu(activity, adapter);

View file

@ -1,5 +1,8 @@
package net.osmand.plus.mapcontextmenu.controllers;
import java.util.ArrayList;
import java.util.List;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
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.MenuController;
import net.osmand.plus.resources.TransportIndexRepository;
import net.osmand.plus.views.TransportInfoLayer;
import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
import android.view.View;
import android.view.View.OnClickListener;
@ -123,8 +122,8 @@ public class TransportStopController extends MenuController {
public void onClick(View arg0) {
MapContextMenu mm = getMapActivity().getContextMenu();
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, r.desc);
TransportInfoLayer tif = getMapActivity().getMapLayers().getTransportInfoLayer();
tif.
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
stopsLayer.setRoute(r.route);
mm.show(latLon, pd, r);
}
};

View file

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