Search in sources :

Example 1 with GenerateViewIconTask

use of cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask in project androidApp by InspectorIncognito.

the class BusUserPlugin method setOnBus.

private void setOnBus() {
    final GeoJsonSource locationGeoJsonSource = mapboxMap.getSourceAs(LocationLayerConstants.LOCATION_SOURCE);
    if (locationGeoJsonSource == null) {
        return;
    }
    this.directionDetectionEngine = new DirectionEngine(10, currentUserBus.getService());
    ArrayList<IconBuilder> buildingList = new ArrayList<>();
    buildingList.add(new UserBusIconsBuilder(currentUserBus).toBuilder());
    GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {

        @Override
        public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
            if (mapboxMap != null) {
                mapboxMap.addImages(bitmapHashMap);
            } else {
                return;
            }
            BearingEngine.Orientation orientation;
            if (currentUserBus.isFlipped()) {
                userLocationFeature.addStringProperty(LocationLayerConstants.PROPERTY_ORIENTATION, "LEFT");
                orientation = BearingEngine.Orientation.Left;
            } else {
                userLocationFeature.addStringProperty(LocationLayerConstants.PROPERTY_ORIENTATION, "RIGHT");
                orientation = BearingEngine.Orientation.Right;
            }
            userLocationFeature.addBooleanProperty(LocationLayerConstants.PROPERTY_ON_BUS, true);
            bearingEngine = new BearingEngine(mapboxMap, previousPoint, orientation);
            if (currentUserBus.getDirection() != null && !currentUserBus.getDirection().isEmpty()) {
                onBusEngine.setOnBus(currentUserBus);
            }
            locationGeoJsonSource.setGeoJson(userLocationFeature);
            mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(MapboxUtil.convertToLatLng(userLocationFeature)));
        }
    }, viewMap, buildingList);
    task.execute();
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) DirectionEngine(cl.smartcities.isci.transportinspector.map.engine.DirectionEngine) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) ArrayList(java.util.ArrayList) UserBusIconsBuilder(cl.smartcities.isci.transportinspector.map.model.bus.UserBusIconsBuilder) MapView(com.mapbox.mapboxsdk.maps.MapView) View(android.view.View) Bitmap(android.graphics.Bitmap) BearingEngine(cl.smartcities.isci.transportinspector.map.engine.BearingEngine)

Example 2 with GenerateViewIconTask

use of cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask in project androidApp by InspectorIncognito.

the class BusUserPlugin method setBusAvatarId.

public void setBusAvatarId(int busAvatarId) {
    if (currentUserBus == null) {
        return;
    }
    currentUserBus.setAvatarId(busAvatarId);
    ArrayList<IconBuilder> buildingList = new ArrayList<>();
    buildingList.add(new UserBusIconsBuilder(currentUserBus).toBuilder());
    GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {

        @Override
        public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
            if (mapboxMap != null) {
                mapboxMap.addImages(bitmapHashMap);
            } else {
                return;
            }
            GeoJsonSource locationGeoJsonSource = mapboxMap.getSourceAs(LocationLayerConstants.LOCATION_SOURCE);
            if (locationGeoJsonSource != null) {
                locationGeoJsonSource.setGeoJson(userLocationFeature);
            }
        }
    }, viewMap, buildingList);
    task.execute();
}
Also used : GeoJsonSource(com.mapbox.mapboxsdk.style.sources.GeoJsonSource) GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) ArrayList(java.util.ArrayList) UserBusIconsBuilder(cl.smartcities.isci.transportinspector.map.model.bus.UserBusIconsBuilder) MapView(com.mapbox.mapboxsdk.maps.MapView) View(android.view.View) Bitmap(android.graphics.Bitmap)

Example 3 with GenerateViewIconTask

use of cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask in project androidApp by InspectorIncognito.

the class BusStopPlugin method onFavIconClick.

@Override
public void onFavIconClick(final String busStopId) {
    final FavoriteHelper helper = new FavoriteHelper(getContext());
    final boolean isFavorite = helper.isFavorite(busStopId);
    ArrayList<IconBuilder> buildingList = new ArrayList<>();
    buildingList.add(new BusStopIconsBuilder(FeatureCollection.fromFeatures(new Feature[] { selectedBusStop })).toBuilder());
    final GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {

        @Override
        public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
            if (mapboxMap != null) {
                mapboxMap.addImages(bitmapHashMap);
            }
            refreshBusStopSource();
        }
    }, viewMap, buildingList);
    new Thread(new Runnable() {

        @Override
        public void run() {
            if (isFavorite) {
                helper.removeFavoriteBusStop(busStopId);
            } else {
                helper.addFavoriteBusStop(busStopId);
            }
            task.execute();
        }
    }).start();
}
Also used : GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) ArrayList(java.util.ArrayList) Feature(com.mapbox.services.commons.geojson.Feature) View(android.view.View) FavoriteHelper(cl.smartcities.isci.transportinspector.database.FavoriteHelper) Bitmap(android.graphics.Bitmap) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder)

Example 4 with GenerateViewIconTask

use of cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask 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)

Example 5 with GenerateViewIconTask

use of cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask in project androidApp by InspectorIncognito.

the class BusStopPlugin method updateSelectedBusStopIcons.

private void updateSelectedBusStopIcons() {
    ArrayList<IconBuilder> buildingList = new ArrayList<>();
    buildingList.add(new BusStopIconsBuilder(FeatureCollection.fromFeatures(new Feature[] { selectedBusStop })).toBuilder());
    final GenerateViewIconTask task = new GenerateViewIconTask(new GenerateViewIconTask.ImageLoaderListener() {

        @Override
        public void onImageGenResult(HashMap<String, View> viewMap, HashMap<String, Bitmap> bitmapHashMap) {
            if (mapboxMap != null) {
                mapboxMap.addImages(bitmapHashMap);
            }
            refreshBusStopSource();
        }
    }, viewMap, buildingList);
    task.execute();
}
Also used : GenerateViewIconTask(cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask) IconBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder) ArrayList(java.util.ArrayList) Feature(com.mapbox.services.commons.geojson.Feature) View(android.view.View) Bitmap(android.graphics.Bitmap) BusStopIconsBuilder(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder)

Aggregations

Bitmap (android.graphics.Bitmap)6 View (android.view.View)6 IconBuilder (cl.smartcities.isci.transportinspector.map.model.busStop.IconBuilder)6 GenerateViewIconTask (cl.smartcities.isci.transportinspector.map.tasks.GenerateViewIconTask)6 ArrayList (java.util.ArrayList)6 UserBusIconsBuilder (cl.smartcities.isci.transportinspector.map.model.bus.UserBusIconsBuilder)3 BusStopIconsBuilder (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopIconsBuilder)3 MapView (com.mapbox.mapboxsdk.maps.MapView)3 GeoJsonSource (com.mapbox.mapboxsdk.style.sources.GeoJsonSource)3 Feature (com.mapbox.services.commons.geojson.Feature)3 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)1 FavoriteHelper (cl.smartcities.isci.transportinspector.database.FavoriteHelper)1 BearingEngine (cl.smartcities.isci.transportinspector.map.engine.BearingEngine)1 DirectionEngine (cl.smartcities.isci.transportinspector.map.engine.DirectionEngine)1 BusMarker (cl.smartcities.isci.transportinspector.map.model.bus.BusMarker)1 MapBusIconsBuilder (cl.smartcities.isci.transportinspector.map.model.bus.MapBusIconsBuilder)1 BusStopMarker (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker)1 ServerSentEvent (cl.smartcities.isci.transportinspector.model.gson.ServerSentEvent)1 CameraUpdate (com.mapbox.mapboxsdk.camera.CameraUpdate)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1