use of cl.smartcities.isci.transportinspector.router.transappStep.IStep in project androidApp by InspectorIncognito.
the class StepAdapter method getView.
@NonNull
public View getView(final int position, View convertView, @NonNull final ViewGroup parent) {
final StepViewHolder holder;
/* set view */
if (convertView == null) {
convertView = inflater.inflate(R.layout.router_step, parent, false);
holder = new StepViewHolder();
/* initialize holder */
holder.icon = convertView.findViewById(R.id.image_icon);
holder.title = convertView.findViewById(R.id.title);
holder.subtitle = convertView.findViewById(R.id.subtitle);
holder.time = convertView.findViewById(R.id.remaining_time);
holder.topLine = convertView.findViewById(R.id.top_line);
holder.bottomLine = convertView.findViewById(R.id.bottom_line);
holder.busIcon = convertView.findViewById(R.id.bus_icon);
holder.busService = convertView.findViewById(R.id.bus_service);
holder.stepTimeWalking = convertView.findViewById(R.id.walking_step_time);
holder.stepTimeBus = convertView.findViewById(R.id.bus_step_time);
holder.stepTimeMetro = convertView.findViewById(R.id.metro_step_time);
holder.walkingLayout = convertView.findViewById(R.id.layout_walking);
holder.busLayout = convertView.findViewById(R.id.layout_bus);
holder.metroLayout = convertView.findViewById(R.id.layout_metro);
holder.title.setTypeface(robotoBold);
holder.subtitle.setTypeface(robotoBold);
holder.time.setTypeface(robotoBold);
holder.busService.setTypeface(robotoBold);
holder.stepTimeWalking.setTypeface(robotoRegular);
holder.stepTimeBus.setTypeface(robotoRegular);
holder.stepTimeMetro.setTypeface(robotoRegular);
holder.row = convertView;
convertView.setTag(holder);
} else {
holder = (StepViewHolder) convertView.getTag();
}
final IStep step = items.get(position);
holder.busLayout.setVisibility(View.GONE);
holder.walkingLayout.setVisibility(View.GONE);
holder.metroLayout.setVisibility(View.GONE);
step.setHolder(convertView.getContext(), holder);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onItemClick(step);
}
});
holder.row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onItemClick(step);
}
});
return convertView;
}
use of cl.smartcities.isci.transportinspector.router.transappStep.IStep 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);
}
Aggregations