use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class GridHelper method cursorToBusStopList.
/**
* Creates a List<BusStop> based on the Cursor information
*
* @param cursor
* @return A list of BusStops
*/
private List<BusStop> cursorToBusStopList(Cursor cursor) {
List<BusStop> busStopList = new ArrayList<>();
while (cursor.moveToNext()) {
String code = cursor.getString(1);
String name = cursor.getString(2);
Double lat = cursor.getDouble(3);
Double lon = cursor.getDouble(4);
String services = cursor.getString(5);
busStopList.add(new BusStop(code, name, lat, lon, services));
}
return busStopList;
}
use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class GridHelper method getNearBusStops.
/**
* return a list of BusStop that contains all the near bus stops in a square
*
* @param pLat The latitude from the point where we want to get near bus stops
* @param pLon The longitude from the point where we want to get near bus stops
* @return A list of BusStops containing the BusStops in the square
*/
public List<BusStop> getNearBusStops(double pLat, double pLon) {
Pair pair = getCellId(pLat, pLon);
final int AREA = 1;
String busStops = this.getColumnByName(pair, AREA, DataBaseContract.Grid.BUSSTOPS);
busStops = busStops.replace("/", "','");
busStops = "'" + busStops + "'";
// get bus stop list from code list given by grid
String query = "SELECT * FROM " + DataBaseContract.Stop.TABLE_NAME + " WHERE " + DataBaseContract.Stop.CODE + " IN (" + busStops + ") ";
String[] params = new String[] {};
Cursor cursor = this.getReadableDatabase().rawQuery(query, params);
List<BusStop> busStopList;
try {
// looping through all rows and adding to list
busStopList = this.cursorToBusStopList(cursor);
} finally {
cursor.close();
this.close();
}
return busStopList;
}
use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class BusStopAdapter method getView.
public View getView(final int position, View convertView, @NonNull final ViewGroup parent) {
final ViewHolder holder;
/* set view */
if (convertView == null) {
convertView = inflater.inflate(R.layout.row_search_bus_stop, parent, false);
holder = new ViewHolder();
/* initialize holder */
holder.title = convertView.findViewById(R.id.title);
holder.subtitle = convertView.findViewById(R.id.subtitle);
holder.topLine = convertView.findViewById(R.id.top_line);
holder.bottomLine = convertView.findViewById(R.id.bottom_line);
Typeface robotoBold = Typeface.createFromAsset(this.getContext().getAssets(), this.getContext().getString(R.string.roboto_bold_font));
holder.title.setTypeface(robotoBold);
holder.subtitle.setTypeface(robotoBold);
holder.row = convertView;
holder.topLine.setBackgroundColor(color);
holder.bottomLine.setBackgroundColor(color);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final BusStop busStop = items.get(position);
holder.title.setText(busStop.getId());
holder.subtitle.setText(busStop.getName());
holder.row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onItemClick(busStop);
}
});
if (position == 0) {
holder.topLine.setVisibility(View.INVISIBLE);
} else {
holder.topLine.setVisibility(View.VISIBLE);
}
if (position == items.size() - 1) {
holder.bottomLine.setVisibility(View.INVISIBLE);
} else {
holder.bottomLine.setVisibility(View.VISIBLE);
}
return convertView;
}
use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class BusStopPlugin method moveCenterInAndOpen.
public void moveCenterInAndOpen(String id) {
if (selectedBusStop != null) {
if (selectedBusStop.getStringProperty(Marker.PROPERTY_ID).equals(id)) {
MapboxUtil.animateCameraToSelection(selectedBusStop, animatorSet, mapboxMap);
return;
} else {
deselectSelectedBusStop();
}
}
Feature busStopFeature = getFeature(id, busStopFeatures, BusStopMarker.PROPERTY_ID);
BusStopClickHandler handler = new BusStopClickHandler(getContext().getResources(), periodicRequestHandler, BusStopPlugin.this);
if (busStopFeature == null) {
BusStopHelper helper = new BusStopHelper(getContext());
ArrayList<BusStop> busStops = new ArrayList<>();
busStops.add(helper.getBusStopById(id));
updateBusStopSource(busStops);
busStopFeature = busStopFeatures.getFeatures().get(0);
}
busStopFeatureClick(busStopFeature, handler);
}
use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class BusStopPlugin method onResponse.
private void onResponse(ArrayList<ServerSentBus> buses, ArrayList<ServerSentEvent> events, final BusStopLoadingLayerTask loaderTask, final Thread thread) {
buses = filterBuses(buses);
updateBusSource(buses);
for (ServerSentEvent event : events) {
event.finishInitialization();
}
((BusStopMarker) selectedBusStop).setEvents(events);
ArrayList<IconBuilder> buildingList = new ArrayList<>();
buildingList.add(new BusStopIconsBuilder(FeatureCollection.fromFeatures(new Feature[] { selectedBusStop })).toBuilder());
buildingList.add(new MapBusIconsBuilder(FeatureCollection.fromFeatures(busesFeatures.getFeatures())).toBuilder());
GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {
@Override
public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
if (selectedBusStop == null) {
return;
}
Log.d(BusStopPlugin.class.getSimpleName(), "onImageGenResult");
if (mapboxMap != null) {
mapboxMap.addImages(bitmapHashMap);
} else {
return;
}
selectedBusStop.addBooleanProperty(BusStopMarker.PROPERTY_LOADING, false);
if (loaderTask != null && thread != null) {
loaderTask.stop();
thread.interrupt();
}
refreshBusStopSource();
refreshBusSource();
if (!busesFeatures.getFeatures().isEmpty()) {
Collections.sort(busesFeatures.getFeatures(), new Comparator<Feature>() {
@Override
public int compare(Feature bus1, Feature bus2) {
BusMarker m1 = (BusMarker) bus1;
BusMarker m2 = (BusMarker) bus2;
return m1.getBus().getDistanceToBusStop() < m2.getBus().getDistanceToBusStop() ? -1 : (m1.getBus().getDistanceToBusStop() == m2.getBus().getDistanceToBusStop() ? 0 : 1);
}
});
Feature busFeature = busesFeatures.getFeatures().get(0);
LatLngBounds.Builder latLngBoundsBuilder = new LatLngBounds.Builder();
latLngBoundsBuilder.include(MapboxUtil.convertToLatLng(busFeature));
latLngBoundsBuilder.include(MapboxUtil.getRotatePoint(busFeature, selectedBusStop, busFeature.getNumberProperty(BusMarker.PROPERTY_BEARING).doubleValue()));
CameraUpdate update = CameraUpdateFactory.newLatLngBounds(latLngBoundsBuilder.build(), 100, 100, 100, 100);
if (loaderTask != null && thread != null) {
MapboxUtil.animateCameraToNewCameraPosition(update.getCameraPosition(mapboxMap), mapboxMap);
// mapboxMap.animateCamera(update, 1000);
periodicRequestHandler.startPeriodicRequest();
final BusStop busStop = ((BusStopMarker) selectedBusStop).getBusStop();
listener.onBusStopSelected(busStop);
}
}
}
}, viewMap, buildingList);
((BusStopMarker) selectedBusStop).getBusStop().setIncomingBuses(buses);
task.execute();
}
Aggregations