Search in sources :

Example 16 with BusStop

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;
}
Also used : ArrayList(java.util.ArrayList) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Example 17 with BusStop

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;
}
Also used : Cursor(android.database.Cursor) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) LoadFarePoint(cl.smartcities.isci.transportinspector.backend.LoadFarePoint) Pair(android.support.v4.util.Pair)

Example 18 with BusStop

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;
}
Also used : Typeface(android.graphics.Typeface) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) TextView(android.widget.TextView) View(android.view.View)

Example 19 with BusStop

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);
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) ArrayList(java.util.ArrayList) BusStopClickHandler(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopClickHandler) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Feature(com.mapbox.services.commons.geojson.Feature)

Example 20 with BusStop

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();
}
Also used : GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder) MapBusIconsBuilder(cl.smartcities.isci.transportinspector.map.model.bus.MapBusIconsBuilder) ServerSentEvent(cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) ArrayList(java.util.ArrayList) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) Feature(com.mapbox.services.commons.geojson.Feature) View(android.view.View) Comparator(java.util.Comparator) Bitmap(android.graphics.Bitmap) MapBusIconsBuilder(cl.smartcities.isci.transportinspector.map.model.bus.MapBusIconsBuilder) BusMarker(cl.smartcities.isci.transportinspector.map.model.bus.BusMarker) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder) CameraUpdate(com.mapbox.mapboxsdk.camera.CameraUpdate) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

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