Search in sources :

Example 6 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class BusStopHelper method getBusStopById.

/**
 * Open the database, does a query, close the database and returns the BusStop that matches the
 * given id.
 *
 * @param pId code of the desired BusStop
 * @return BusStop that matches the given id, or null if the BusStop does not exists in the
 * database
 */
public BusStop getBusStopById(String pId) {
    Log.d("pID", pId);
    Cursor cursor = getBusStopCursorById(pId);
    List<BusStop> busStopList = this.cursorToBusStopList(cursor);
    this.close();
    if (busStopList.size() > 0)
        return busStopList.get(0);
    else
        return null;
}
Also used : Cursor(android.database.Cursor) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Example 7 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class FavouritesManger method getFavouriteBusStops.

static List<BusStop> getFavouriteBusStops(Context context) {
    FavoriteHelper helper = new FavoriteHelper(context);
    BusStopHelper busStopHelper = new BusStopHelper(context);
    List<String> busStops = helper.getFavoriteBusStops();
    List<BusStop> favouriteBusStops = new ArrayList<>();
    if (!busStops.isEmpty()) {
        List<BusStop> favourites = busStopHelper.getAllBusStopsIn(busStops.toArray(new String[busStops.size()]));
        favouriteBusStops.addAll(favourites);
    }
    return favouriteBusStops;
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) FavoriteHelper(cl.smartcities.isci.transportinspector.database.FavoriteHelper) ArrayList(java.util.ArrayList) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Example 8 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class DetectionServiceTest method testManualGetOutOfBus.

@Test
public void testManualGetOutOfBus() throws TimeoutException {
    DetectionService spyService = spy(service);
    BusStop mockBusStop = mock(BusStop.class);
    when(mockBusStop.getIncomingBuses()).thenReturn(new ArrayList<Bus>());
    Bus bus = new Bus("506", "GGWP00", "");
    spyService.setCurrentState(new VehicleState(new IdleState(spyService), bus, mock(StateLocationSender.class)));
    spyService.onBusDetected(bus);
    assertTrue(spyService.isRunningInForeground());
    spyService.outOfBus();
    assertFalse(spyService.isRunningInForeground());
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Test(org.junit.Test)

Example 9 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class DetectionServiceTest method testGetOutOfBus.

@Test
public void testGetOutOfBus() throws TimeoutException {
    DetectionService spyService = spy(service);
    BusStop mockBusStop = mock(BusStop.class);
    when(mockBusStop.getIncomingBuses()).thenReturn(new ArrayList<Bus>());
    Bus bus = new Bus("506", "GGWP00", "");
    spyService.setCurrentState(new VehicleState(new IdleState(spyService), bus, mock(StateLocationSender.class)));
    spyService.onBusDetected(bus);
    assertTrue(spyService.isRunningInForeground());
    spyService.onActivityChanged(new DetectedActivity(DetectedActivity.WALKING, 100));
    spyService.onActivityChanged(new DetectedActivity(DetectedActivity.IN_VEHICLE, 100));
    spyService.onActivityChanged(new DetectedActivity(DetectedActivity.WALKING, 100));
    spyService.fakeOnTimePassed();
    assertFalse(spyService.isRunningInForeground());
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) DetectedActivity(com.google.android.gms.location.DetectedActivity) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Test(org.junit.Test)

Example 10 with BusStop

use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.

the class DetectionServiceTest method testBusDetectedNotificationIsSent.

@Test
public void testBusDetectedNotificationIsSent() throws TimeoutException {
    DetectionService spyService = spy(service);
    BusStop mockBusStop = mock(BusStop.class);
    when(mockBusStop.getIncomingBuses()).thenReturn(new ArrayList<Bus>());
    // IdleState is set
    spyService.setCurrentState(new IdleState(spyService));
    // BusStop is selected
    spyService.busStopSelected(mockBusStop);
    // New IN_VEHICLE Detected Activity
    spyService.onActivityChanged(new DetectedActivity(DetectedActivity.IN_VEHICLE, 100));
// TODO(aantoine): REDO this test
// verify(spyService).sendNotification(anyInt(), any(NotificationCompat.Builder.class));
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) DetectedActivity(com.google.android.gms.location.DetectedActivity) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Test(org.junit.Test)

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