Search in sources :

Example 1 with LoadFarePoint

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

the class FareLoadPointHelper method cursorToFareLoadPointList.

/**
 * Creates a List<LoadFarePoint> based on the Cursor information
 *
 * @param cursor
 * @return
 */
private List<LoadFarePoint> cursorToFareLoadPointList(Cursor cursor) {
    List<LoadFarePoint> loadFarePointList = new ArrayList<>();
    while (cursor.moveToNext()) {
        // String id = cursor.getString(1);
        String name = cursor.getString(2);
        Double lat = cursor.getDouble(3);
        Double lon = cursor.getDouble(4);
        loadFarePointList.add(new LoadFarePoint(name, lat, lon));
    }
    return loadFarePointList;
}
Also used : LoadFarePoint(cl.smartcities.isci.transportinspector.backend.LoadFarePoint) ArrayList(java.util.ArrayList)

Example 2 with LoadFarePoint

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

the class FareLoadPointHelper method getLoadFarePointById.

/**
 * @param pId id of the desired load fare point
 * @return LoadFarePoint that matches the given id, or null if the load fare point does not
 * exists in the database
 */
public LoadFarePoint getLoadFarePointById(String pId) {
    Log.d("pID", pId);
    String query = "SELECT * FROM " + DataBaseContract.FareLoadPoint.TABLE_NAME + " WHERE " + DataBaseContract.FareLoadPoint.ID + " = ?";
    String[] params = new String[] { pId };
    Cursor cursor = this.getReadableDatabase().rawQuery(query, params);
    List<LoadFarePoint> loadFarePointList = this.cursorToFareLoadPointList(cursor);
    this.close();
    if (loadFarePointList.size() > 0)
        return loadFarePointList.get(0);
    else
        return null;
}
Also used : LoadFarePoint(cl.smartcities.isci.transportinspector.backend.LoadFarePoint) Cursor(android.database.Cursor)

Example 3 with LoadFarePoint

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

the class GridHelper method getNearLoadFarePoints.

/**
 * return a list of LoadFarePoints that contains all the load fare points in a square
 *
 * @param pLat    The latitude from the point where we want to get load fare points
 * @param pLon    The longitude from the point where we want to get near load fare points
 * @return A list of LoadFarePoints containing the LoadFarePoints in the square
 */
public List<LoadFarePoint> getNearLoadFarePoints(double pLat, double pLon) {
    Pair pair = getCellId(pLat, pLon);
    final int AREA = 1;
    String loadFarePoints = this.getLoadFarePoints(pair, AREA);
    loadFarePoints = loadFarePoints.replace("/", ",");
    // get bus stop list from code list given by grid
    String query = "SELECT * FROM " + DataBaseContract.FareLoadPoint.TABLE_NAME + " WHERE " + DataBaseContract.FareLoadPoint.ID + " IN (" + loadFarePoints + ") ";
    String[] params = new String[] {};
    Cursor cursor = this.getReadableDatabase().rawQuery(query, params);
    List<LoadFarePoint> loadFarePointList = this.cursorToLoadFarePointList(cursor);
    cursor.close();
    this.close();
    return loadFarePointList;
}
Also used : LoadFarePoint(cl.smartcities.isci.transportinspector.backend.LoadFarePoint) Cursor(android.database.Cursor) LoadFarePoint(cl.smartcities.isci.transportinspector.backend.LoadFarePoint) Pair(android.support.v4.util.Pair)

Example 4 with LoadFarePoint

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

the class GridHelper method cursorToLoadFarePointList.

/**
 * Creates a List<LoadFarePoint> based on the Cursor information
 *
 * @param cursor
 * @return A list of load fare point
 */
private List<LoadFarePoint> cursorToLoadFarePointList(Cursor cursor) {
    List<LoadFarePoint> loadFarePointList = new ArrayList<>();
    while (cursor.moveToNext()) {
        String name = cursor.getString(2);
        Double lat = cursor.getDouble(3);
        Double lon = cursor.getDouble(4);
        loadFarePointList.add(new LoadFarePoint(name, lat, lon));
    }
    return loadFarePointList;
}
Also used : LoadFarePoint(cl.smartcities.isci.transportinspector.backend.LoadFarePoint) ArrayList(java.util.ArrayList)

Aggregations

LoadFarePoint (cl.smartcities.isci.transportinspector.backend.LoadFarePoint)4 Cursor (android.database.Cursor)2 ArrayList (java.util.ArrayList)2 Pair (android.support.v4.util.Pair)1