Search in sources :

Example 1 with Route

use of cl.smartcities.isci.transportinspector.router.route.Route in project androidApp by InspectorIncognito.

the class RouterOptionAdapter method getView.

public View getView(final int position, View convertView, @NonNull final ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        if (defaultView == null) {
            convertView = inflater.inflate(R.layout.row_router_option, parent, false);
        } else {
            convertView = defaultView;
        }
        holder = new ViewHolder();
        /* initialize holder */
        holder.textView = convertView.findViewById(R.id.time_text);
        holder.layout1 = (LinearLayout) inflater.inflate(R.layout.row_router_option_icons, (LinearLayout) convertView, false);
        holder.layout2 = (LinearLayout) inflater.inflate(R.layout.row_router_option_icons, (LinearLayout) convertView, false);
        holder.innerHolder1 = new InnerHolder();
        holder.innerHolder2 = new InnerHolder();
        createInnerHolder(holder.innerHolder1, holder.layout1);
        createInnerHolder(holder.innerHolder2, holder.layout2);
        ((LinearLayout) convertView).addView(holder.layout1);
        ((LinearLayout) convertView).addView(holder.layout2);
        holder.layout1.setVisibility(View.GONE);
        holder.layout2.setVisibility(View.GONE);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    final Route route = items.get(position);
    holder.textView.setText(route.totalTime);
    setView(route, holder);
    convertView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (innerListener != null) {
                innerListener.onItemClick(position);
            }
        }
    });
    return convertView;
}
Also used : AppCompatImageView(android.support.v7.widget.AppCompatImageView) TextView(android.widget.TextView) View(android.view.View) LinearLayout(android.widget.LinearLayout) Route(cl.smartcities.isci.transportinspector.router.route.Route)

Example 2 with Route

use of cl.smartcities.isci.transportinspector.router.route.Route in project androidApp by InspectorIncognito.

the class RouterVectorMapFragment method innerSetRoute.

private void innerSetRoute(Route route) {
    adapter.changeItems(route.steps);
    List<Route> routeList = new ArrayList<>();
    routeList.add(route);
    routerOptionAdapter.changeItems(routeList);
    convertView = routerOptionAdapter.getView(0, convertView, viewGroup);
    title.setText(route.title);
    routerPlugin.changeRoute(route);
    zoomBound(new LatLng(route.northEastPoint.getLatitude(), route.northEastPoint.getLongitude()), new LatLng(route.southWestPoint.getLatitude(), route.southWestPoint.getLongitude()));
}
Also used : ArrayList(java.util.ArrayList) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) Route(cl.smartcities.isci.transportinspector.router.route.Route)

Example 3 with Route

use of cl.smartcities.isci.transportinspector.router.route.Route in project androidApp by InspectorIncognito.

the class StepJsonBuilder method build.

public List<Route> build(Context context, String raw) throws JSONException {
    List<Route> routes = new ArrayList<>();
    JSONArray array = new JSONArray(raw);
    for (int i = 0; i < array.length(); i++) {
        Route route = getRoute(array.getJSONObject(i), context);
        if (route != null) {
            routes.add(route);
        }
    }
    return routes;
}
Also used : ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Route(cl.smartcities.isci.transportinspector.router.route.Route)

Example 4 with Route

use of cl.smartcities.isci.transportinspector.router.route.Route 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)

Aggregations

Route (cl.smartcities.isci.transportinspector.router.route.Route)4 ArrayList (java.util.ArrayList)3 JSONArray (org.json.JSONArray)2 Location (android.location.Location)1 AppCompatImageView (android.support.v7.widget.AppCompatImageView)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)1 ComparableLocation (cl.smartcities.isci.transportinspector.map.model.ComparableLocation)1 BusStep (cl.smartcities.isci.transportinspector.router.googleStep.BusStep)1 GoogleStep (cl.smartcities.isci.transportinspector.router.googleStep.GoogleStep)1 NullStep (cl.smartcities.isci.transportinspector.router.googleStep.NullStep)1 SubwayStep (cl.smartcities.isci.transportinspector.router.googleStep.SubwayStep)1 WalkingStep (cl.smartcities.isci.transportinspector.router.googleStep.WalkingStep)1 IStep (cl.smartcities.isci.transportinspector.router.transappStep.IStep)1 StepBuilder (cl.smartcities.isci.transportinspector.router.transappStep.StepBuilder)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 JSONObject (org.json.JSONObject)1