Search in sources :

Example 6 with TransportStopRoute

use of net.osmand.plus.transport.TransportStopRoute in project Osmand by osmandapp.

the class TransportStopController method addRoutes.

private void addRoutes(List<TransportStopRoute> routes, boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) {
    Collection<TransportRoute> rts = t.getRouteForStop(s);
    if (rts != null) {
        for (TransportRoute rs : rts) {
            TransportStopType type = TransportStopType.findType(rs.getType());
            if (topType == null && type != null && type.isTopType()) {
                topType = type;
            }
            if (!containsRef(routes, rs)) {
                TransportStopRoute r = new TransportStopRoute();
                r.type = type;
                r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
                r.route = rs;
                r.refStop = refStop;
                r.stop = s;
                r.distance = dist;
                routes.add(r);
            }
        }
    }
}
Also used : TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) TransportStopType(net.osmand.plus.transport.TransportStopType) TransportRoute(net.osmand.data.TransportRoute)

Example 7 with TransportStopRoute

use of net.osmand.plus.transport.TransportStopRoute in project Osmand by osmandapp.

the class AmenityMenuController method addRoutes.

private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, int dist, boolean isSubwayEntrance) {
    Collection<TransportRoute> rts = t.getRouteForStop(s);
    if (rts != null) {
        for (TransportRoute rs : rts) {
            if (!containsRef(rs)) {
                TransportStopType type = TransportStopType.findType(rs.getType());
                if (isSubwayEntrance && type != TransportStopType.SUBWAY && dist > 150) {
                    continue;
                }
                TransportStopRoute r = new TransportStopRoute();
                r.type = type;
                r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
                r.route = rs;
                r.stop = s;
                r.distance = dist;
                this.routes.add(r);
            }
        }
    }
}
Also used : TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) TransportStopType(net.osmand.plus.transport.TransportStopType) TransportRoute(net.osmand.data.TransportRoute)

Example 8 with TransportStopRoute

use of net.osmand.plus.transport.TransportStopRoute in project Osmand by osmandapp.

the class AmenityMenuController method processTransportStop.

private void processTransportStop() {
    routes = new ArrayList<>();
    List<TransportIndexRepository> reps = getMapActivity().getMyApplication().getResourceManager().searchTransportRepositories(amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude());
    boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
    boolean isSubwayEntrance = amenity.getSubType().equals("subway_entrance");
    for (TransportIndexRepository t : reps) {
        ArrayList<TransportStop> ls = new ArrayList<>();
        QuadRect ll = MapUtils.calculateLatLonBbox(amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), isSubwayEntrance ? 400 : 150);
        t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
        for (TransportStop tstop : ls) {
            addRoutes(useEnglishNames, t, tstop, (int) MapUtils.getDistance(tstop.getLocation(), amenity.getLocation()), isSubwayEntrance);
        }
    }
    Collections.sort(routes, new Comparator<TransportStopRoute>() {

        @Override
        public int compare(TransportStopRoute o1, TransportStopRoute o2) {
            if (o1.distance != o2.distance) {
                return Algorithms.compare(o1.distance, o2.distance);
            }
            int i1 = Algorithms.extractFirstIntegerNumber(o1.desc);
            int i2 = Algorithms.extractFirstIntegerNumber(o2.desc);
            if (i1 != i2) {
                return Algorithms.compare(i1, i2);
            }
            return o1.desc.compareTo(o2.desc);
        }
    });
    builder.setRoutes(routes);
}
Also used : TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) ArrayList(java.util.ArrayList) TransportIndexRepository(net.osmand.plus.resources.TransportIndexRepository) TransportStop(net.osmand.data.TransportStop) QuadRect(net.osmand.data.QuadRect)

Example 9 with TransportStopRoute

use of net.osmand.plus.transport.TransportStopRoute in project Osmand by osmandapp.

the class TransportStopController method processTransportStop.

public List<TransportStopRoute> processTransportStop() {
    ArrayList<TransportStopRoute> routes = new ArrayList<>();
    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)) {
            boolean empty = transportStop.getReferencesToRoutes() == null || transportStop.getReferencesToRoutes().length == 0;
            if (!empty) {
                addRoutes(routes, useEnglishNames, t, transportStop, transportStop, 0);
            }
            ArrayList<TransportStop> ls = new ArrayList<>();
            QuadRect ll = MapUtils.calculateLatLonBbox(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude(), SHOW_STOPS_RADIUS_METERS);
            t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
            for (TransportStop tstop : ls) {
                if (tstop.getId().longValue() != transportStop.getId().longValue() || empty) {
                    addRoutes(routes, useEnglishNames, t, tstop, transportStop, (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation()));
                }
            }
        }
    }
    Collections.sort(routes, new Comparator<TransportStopRoute>() {

        @Override
        public int compare(TransportStopRoute o1, TransportStopRoute o2) {
            if (o1.distance != o2.distance) {
                return Algorithms.compare(o1.distance, o2.distance);
            }
            int i1 = Algorithms.extractFirstIntegerNumber(o1.desc);
            int i2 = Algorithms.extractFirstIntegerNumber(o2.desc);
            if (i1 != i2) {
                return Algorithms.compare(i1, i2);
            }
            return o1.desc.compareTo(o2.desc);
        }
    });
    return routes;
}
Also used : TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) ArrayList(java.util.ArrayList) TransportIndexRepository(net.osmand.plus.resources.TransportIndexRepository) TransportStop(net.osmand.data.TransportStop) QuadRect(net.osmand.data.QuadRect)

Example 10 with TransportStopRoute

use of net.osmand.plus.transport.TransportStopRoute in project Osmand by osmandapp.

the class MapContextMenuFragment method createTransportStopRouteAdapter.

private TransportStopRouteAdapter createTransportStopRouteAdapter(List<TransportStopRoute> routes) {
    final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getMyApplication(), routes, nightMode);
    adapter.setListener(new TransportStopRouteAdapter.OnClickListener() {

        @Override
        public void onClick(int position) {
            TransportStopRoute route = adapter.getItem(position);
            if (route != null) {
                PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, route.getDescription(getMapActivity().getMyApplication(), false));
                menu.show(menu.getLatLon(), pd, route);
                TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
                stopsLayer.setRoute(route);
                int cz = route.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
                getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
            }
        }
    });
    return adapter;
}
Also used : TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) PointDescription(net.osmand.data.PointDescription) QuadPoint(net.osmand.data.QuadPoint) TransportStopsLayer(net.osmand.plus.views.TransportStopsLayer)

Aggregations

TransportStopRoute (net.osmand.plus.transport.TransportStopRoute)10 TransportStop (net.osmand.data.TransportStop)3 View (android.view.View)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 QuadPoint (net.osmand.data.QuadPoint)2 QuadRect (net.osmand.data.QuadRect)2 TransportRoute (net.osmand.data.TransportRoute)2 TransportStopType (net.osmand.plus.transport.TransportStopType)2 Drawable (android.graphics.drawable.Drawable)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 NonNull (android.support.annotation.NonNull)1 TypedValue (android.util.TypedValue)1 GestureDetector (android.view.GestureDetector)1 MotionEvent (android.view.MotionEvent)1 VelocityTracker (android.view.VelocityTracker)1 OnLayoutChangeListener (android.view.View.OnLayoutChangeListener)1 ViewConfiguration (android.view.ViewConfiguration)1 ViewGroup (android.view.ViewGroup)1