Search in sources :

Example 21 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class BusStopPlugin method updateBusStopSource.

private void updateBusStopSource(List<BusStop> busStops) {
    List<Feature> markerCoordinates = new ArrayList<>();
    boolean added = false;
    for (BusStop busStop : busStops) {
        if (selectedBusStop != null && selectedBusStop.getStringProperty(BusStopMarker.PROPERTY_ID).equals(busStop.getId())) {
            markerCoordinates.add(selectedBusStop);
            added = true;
        } else {
            markerCoordinates.add(new BusStopMarker(busStop));
        }
    }
    if (selectedBusStop != null && !added)
        markerCoordinates.add(selectedBusStop);
    busStopFeatures = FeatureCollection.fromFeatures(markerCoordinates);
    refreshBusStopSource();
}
Also used : ArrayList(java.util.ArrayList) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Feature(com.mapbox.services.commons.geojson.Feature)

Example 22 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class StepJsonBuilder method getRoute.

private Route getRoute(JSONObject route, Context context) throws JSONException {
    List<IStep> steps = new ArrayList<>();
    List<GoogleStep> googleSteps = new ArrayList<>();
    List<InnerPolyline> polyline = new ArrayList<>();
    List<BusStop> busStops = new ArrayList<>();
    String title = null;
    String firstTitle = null;
    JSONObject leg = route.getJSONArray("legs").getJSONObject(0);
    JSONObject northeast = route.getJSONObject("bounds").getJSONObject("northeast");
    JSONObject southwest = route.getJSONObject("bounds").getJSONObject("southwest");
    Location northeastPoint = new ComparableLocation(northeast.getDouble("lat"), northeast.getDouble("lng"));
    Location southwestPoint = new ComparableLocation(southwest.getDouble("lat"), southwest.getDouble("lng"));
    String start = leg.getString("start_address");
    String end = leg.getString("end_address");
    String departureTime = leg.getJSONObject("departure_time").getString("text");
    String arrivalTime = leg.getJSONObject("arrival_time").getString("text");
    String duration = leg.getJSONObject("duration").getString("text");
    GoogleStep prevState = new NullStep("Tu UbicaciĆ³n", start, departureTime);
    GoogleStep currentState;
    JSONArray rawSteps = leg.getJSONArray("steps");
    for (int i = 0; i < rawSteps.length(); i++) {
        JSONObject step = rawSteps.getJSONObject(i);
        Location startPoint = new ComparableLocation(step.getJSONObject("start_location").getDouble("lat"), step.getJSONObject("start_location").getDouble("lng"));
        Location endPoint = new ComparableLocation(step.getJSONObject("end_location").getDouble("lat"), step.getJSONObject("end_location").getDouble("lng"));
        String travel_mode = step.getString("travel_mode");
        String stepDuration = step.getJSONObject("duration").getString("text");
        String actualRoute = step.getJSONObject("polyline").getString("points");
        if (travel_mode.equals("TRANSIT")) {
            JSONObject details = step.getJSONObject("transit_details");
            String mode = details.getJSONObject("line").getJSONObject("vehicle").getString("type");
            String line = details.getJSONObject("line").getString("short_name");
            String departure = details.getJSONObject("departure_stop").getString("name");
            String arrival = details.getJSONObject("arrival_stop").getString("name");
            if (mode.equals("BUS")) {
                try {
                    currentState = new BusStep(departure, arrival, stepDuration, line, actualRoute, startPoint, endPoint);
                } catch (IllegalStateException exception) {
                    return null;
                }
                BusStop arrivalStop = getBusStop(arrival, context, endPoint);
                if (arrivalStop == null) {
                    return null;
                }
                busStops.add(arrivalStop);
                if (!prevState.isBusStep()) {
                    BusStop departureStop = getBusStop(departure, context, startPoint);
                    if (departureStop == null) {
                        return null;
                    }
                    busStops.add(departureStop);
                }
            } else {
                String color = details.getJSONObject("line").getString("color");
                currentState = new SubwayStep(departure, arrival, stepDuration, line, color, actualRoute, startPoint, endPoint);
            }
            if (title == null) {
                title = currentState.getTitle();
            }
        } else {
            int rawStepDuration = step.getJSONObject("duration").getInt("value");
            currentState = new WalkingStep(stepDuration, rawStepDuration, actualRoute, startPoint, endPoint);
        }
        if (firstTitle == null) {
            firstTitle = currentState.getTitle();
        }
        polyline.add(currentState.getPolyline());
        googleSteps.add(currentState);
        steps.add(prevState.dispatch(currentState, new StepBuilder(context)));
        prevState = currentState;
    }
    currentState = new NullStep("Tu destino", end, arrivalTime);
    steps.add(prevState.dispatch(currentState, new StepBuilder(context)));
    title = title == null ? firstTitle : title;
    return new Route(steps, googleSteps, duration, northeastPoint, southwestPoint, polyline, busStops, title);
}
Also used : StepBuilder(cl.smartcities.isci.transportinspector.router.transappStep.StepBuilder) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) NullStep(cl.smartcities.isci.transportinspector.router.googleStep.NullStep) BusStep(cl.smartcities.isci.transportinspector.router.googleStep.BusStep) JSONObject(org.json.JSONObject) GoogleStep(cl.smartcities.isci.transportinspector.router.googleStep.GoogleStep) IStep(cl.smartcities.isci.transportinspector.router.transappStep.IStep) WalkingStep(cl.smartcities.isci.transportinspector.router.googleStep.WalkingStep) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) ComparableLocation(cl.smartcities.isci.transportinspector.map.model.ComparableLocation) SubwayStep(cl.smartcities.isci.transportinspector.router.googleStep.SubwayStep) Route(cl.smartcities.isci.transportinspector.router.route.Route) ComparableLocation(cl.smartcities.isci.transportinspector.map.model.ComparableLocation) Location(android.location.Location)

Example 23 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class BusStep method getNearestBusStop.

@Nullable
private BusStop getNearestBusStop(Location point) {
    BusStopHelper helper = new BusStopHelper(TranSappApplication.getAppContext());
    List<BusStop> buses = helper.getNearestBusStops(point.getLatitude(), point.getLongitude(), 1);
    if (buses.isEmpty()) {
        return null;
    }
    return buses.get(0);
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Nullable(android.support.annotation.Nullable)

Example 24 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class BusStopIconsBuilder method setIconsAndViews.

public void setIconsAndViews(LayoutInflater inflater, HashMap<String, Bitmap> imagesMap, HashMap<String, View> viewMap) {
    for (Feature feature : featureCollection.getFeatures()) {
        String id = feature.getStringProperty(Marker.PROPERTY_ID);
        BusStopMarker marker = (BusStopMarker) feature;
        BusStop busStop = marker.getBusStop();
        View view = inflater.inflate(R.layout.bus_stop_bubble, null);
        TextView code = view.findViewById(R.id.bubble_bus_stop_code);
        TextView name = view.findViewById(R.id.bubble_bus_stop_name);
        code.setText(id);
        name.setText(busStop.getName());
        AppCompatImageView favIcon = view.findViewById(R.id.fav_icon);
        final FavoriteHelper helper = new FavoriteHelper(view.getContext());
        boolean isFavorite = helper.isFavorite(busStop.getId());
        if (isFavorite) {
            favIcon.setColorFilter(ContextCompat.getColor(view.getContext(), R.color.yellow_fav));
        }
        List<ServerSentBus> buses = Bus.filterDummyPlates(busStop.getIncomingBuses());
        buses = ServerSentBus.orderBusesByDistance(buses);
        if (!buses.isEmpty()) {
            view.findViewById(R.id.bus_layout).setVisibility(View.VISIBLE);
            view.findViewById(R.id.bus_empty_layout).setVisibility(View.GONE);
            setupNearBusLayout(view, getNearestVisibleBus(buses, busStop));
        } else {
            view.findViewById(R.id.bus_layout).setVisibility(View.GONE);
            view.findViewById(R.id.bus_empty_layout).setVisibility(View.VISIBLE);
        }
        setEventLayout(view, marker.getEvents());
        Bitmap bitmap = GenerateViewIconTask.SymbolGenerator.generate(view);
        imagesMap.put(id + "-max", bitmap);
        viewMap.put("busStop-max", view);
        View viewMin = inflater.inflate(R.layout.bus_stop_minimize_bubble, null);
        TextView nameMin = viewMin.findViewById(R.id.bubble_bus_stop_code);
        nameMin.setText(id);
        ((ImageView) viewMin.findViewById(R.id.maximize)).setImageDrawable(new GreenButtonUp(viewMin.getContext()));
        imagesMap.put(id + "-min", GenerateViewIconTask.SymbolGenerator.generate(viewMin));
        viewMap.put("busStop-min", viewMin);
    }
}
Also used : Feature(com.mapbox.services.commons.geojson.Feature) AppCompatImageView(android.support.v7.widget.AppCompatImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AppCompatImageView(android.support.v7.widget.AppCompatImageView) GreenButtonUp(cl.smartcities.isci.transportinspector.drawables.greenButton.GreenButtonUp) ServerSentBus(cl.smartcities.isci.transportinspector.model.gson.ServerSentBus) FavoriteHelper(cl.smartcities.isci.transportinspector.database.FavoriteHelper) Bitmap(android.graphics.Bitmap) TextView(android.widget.TextView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) ImageView(android.widget.ImageView) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Example 25 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class SearchBusStopEngine method updateBusStopSource.

public void updateBusStopSource(List<BusStop> busStops) {
    List<Feature> markerCoordinates = new ArrayList<>();
    for (BusStop busStop : busStops) {
        markerCoordinates.add(new BusStopMarker(busStop));
    }
    busStopFeatures = FeatureCollection.fromFeatures(markerCoordinates);
    refreshSourceWithFeatures(busStopSource, busStopFeatures);
}
Also used : ArrayList(java.util.ArrayList) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Feature(com.mapbox.services.commons.geojson.Feature)

Aggregations

BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)27 ArrayList (java.util.ArrayList)13 Feature (com.mapbox.services.commons.geojson.Feature)8 BusStopMarker (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker)6 BusStopHelper (cl.smartcities.isci.transportinspector.database.BusStopHelper)5 Cursor (android.database.Cursor)4 View (android.view.View)3 Bus (cl.smartcities.isci.transportinspector.backend.Bus)3 Test (org.junit.Test)3 Bitmap (android.graphics.Bitmap)2 Nullable (android.support.annotation.Nullable)2 TextView (android.widget.TextView)2 FavoriteHelper (cl.smartcities.isci.transportinspector.database.FavoriteHelper)2 GridHelper (cl.smartcities.isci.transportinspector.database.GridHelper)2 DetectedActivity (com.google.android.gms.location.DetectedActivity)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Typeface (android.graphics.Typeface)1 Location (android.location.Location)1 Pair (android.support.v4.util.Pair)1