Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/data/NextGenDB.java
Show First 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | public class NextGenDB extends SQLiteOpenHelper{ | ||||
* | * | ||||
* You can obtain the coordinates from OSMDroid using something like this: | * You can obtain the coordinates from OSMDroid using something like this: | ||||
* BoundingBoxE6 bb = mMapView.getBoundingBox(); | * BoundingBoxE6 bb = mMapView.getBoundingBox(); | ||||
* double latFrom = bb.getLatSouthE6() / 1E6; | * double latFrom = bb.getLatSouthE6() / 1E6; | ||||
* double latTo = bb.getLatNorthE6() / 1E6; | * double latTo = bb.getLatNorthE6() / 1E6; | ||||
* double lngFrom = bb.getLonWestE6() / 1E6; | * double lngFrom = bb.getLonWestE6() / 1E6; | ||||
* double lngTo = bb.getLonEastE6() / 1E6; | * double lngTo = bb.getLonEastE6() / 1E6; | ||||
*/ | */ | ||||
public synchronized Stop[] queryAllInsideMapView(double minLat, double maxLat, double minLng, double maxLng) { | public synchronized ArrayList<Stop> queryAllInsideMapView(double minLat, double maxLat, double minLng, double maxLng) { | ||||
Stop[] stops = new Stop[0]; | ArrayList<Stop> stops = new ArrayList<>(); | ||||
SQLiteDatabase db = this.getReadableDatabase(); | SQLiteDatabase db = this.getReadableDatabase(); | ||||
//Cursor result=null; | |||||
int count; | |||||
// coordinates must be strings in the where condition | // coordinates must be strings in the where condition | ||||
String minLatRaw = String.valueOf(minLat); | String minLatRaw = String.valueOf(minLat); | ||||
String maxLatRaw = String.valueOf(maxLat); | String maxLatRaw = String.valueOf(maxLat); | ||||
String minLngRaw = String.valueOf(minLng); | String minLngRaw = String.valueOf(minLng); | ||||
String maxLngRaw = String.valueOf(maxLng); | String maxLngRaw = String.valueOf(maxLng); | ||||
if(db == null) { | if(db == null) { | ||||
Show All 17 Lines | public synchronized ArrayList<Stop> queryAllInsideMapView(double minLat, double maxLat, double minLng, double maxLng) { | ||||
return stops; | return stops; | ||||
} | } | ||||
/** | /** | ||||
* Get the list of stop in the query, with all the possible fields {NextGenDB.QUERY_COLUMN_stops_all} | * Get the list of stop in the query, with all the possible fields {NextGenDB.QUERY_COLUMN_stops_all} | ||||
* @param result cursor from query | * @param result cursor from query | ||||
* @return an Array of the stops found in the query | * @return an Array of the stops found in the query | ||||
*/ | */ | ||||
public static Stop[] getStopsFromCursorAllFields(Cursor result){ | public static ArrayList<Stop> getStopsFromCursorAllFields(Cursor result){ | ||||
int colID = result.getColumnIndex(StopsTable.COL_ID); | final int colID = result.getColumnIndex(StopsTable.COL_ID); | ||||
int colName = result.getColumnIndex(StopsTable.COL_NAME); | final int colName = result.getColumnIndex(StopsTable.COL_NAME); | ||||
int colLocation = result.getColumnIndex(StopsTable.COL_LOCATION); | final int colLocation = result.getColumnIndex(StopsTable.COL_LOCATION); | ||||
int colType = result.getColumnIndex(StopsTable.COL_TYPE); | final int colType = result.getColumnIndex(StopsTable.COL_TYPE); | ||||
int colLat = result.getColumnIndex(StopsTable.COL_LAT); | final int colLat = result.getColumnIndex(StopsTable.COL_LAT); | ||||
int colLon = result.getColumnIndex(StopsTable.COL_LONG); | final int colLon = result.getColumnIndex(StopsTable.COL_LONG); | ||||
int colLines = result.getColumnIndex(StopsTable.COL_LINES_STOPPING); | final int colLines = result.getColumnIndex(StopsTable.COL_LINES_STOPPING); | ||||
int count = result.getCount(); | int count = result.getCount(); | ||||
Stop[] stops = new Stop[count]; | ArrayList<Stop> stops = new ArrayList<>(count); | ||||
int i = 0; | int i = 0; | ||||
while(result.moveToNext()) { | while(result.moveToNext()) { | ||||
final String stopID = result.getString(colID).trim(); | final String stopID = result.getString(colID).trim(); | ||||
final Route.Type type; | final Route.Type type; | ||||
if(result.getString(colType) == null) type = Route.Type.BUS; | if(result.getString(colType) == null) type = Route.Type.BUS; | ||||
else type = Route.getTypeFromSymbol(result.getString(colType)); | else type = Route.getTypeFromSymbol(result.getString(colType)); | ||||
String lines = result.getString(colLines).trim(); | String lines = result.getString(colLines).trim(); | ||||
String locationSometimesEmpty = result.getString(colLocation); | String locationSometimesEmpty = result.getString(colLocation); | ||||
if (locationSometimesEmpty!= null && locationSometimesEmpty.length() <= 0) { | if (locationSometimesEmpty!= null && locationSometimesEmpty.length() <= 0) { | ||||
locationSometimesEmpty = null; | locationSometimesEmpty = null; | ||||
} | } | ||||
stops[i++] = new Stop(stopID, result.getString(colName), null, | stops.add(new Stop(stopID, result.getString(colName), null, | ||||
locationSometimesEmpty, type, splitLinesString(lines), | locationSometimesEmpty, type, splitLinesString(lines), | ||||
result.getDouble(colLat), result.getDouble(colLon)); | result.getDouble(colLat), result.getDouble(colLon)) | ||||
); | |||||
} | } | ||||
return stops; | return stops; | ||||
} | } | ||||
/** | /** | ||||
* Insert batch content, already prepared as | * Insert batch content, already prepared as | ||||
* @param content ContentValues array | * @param content ContentValues array | ||||
* @return number of lines inserted | * @return number of lines inserted | ||||
▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register