public class DataManager
extends android.database.sqlite.SQLiteOpenHelper
SQLiteOpenHelper
and allows data-driven map features creation. It acts
as a intermediate between a live data API (currently hard-coded under R.raw.
) and the
end-user interactions.Modifier and Type | Field and Description |
---|---|
private android.content.Context |
context_
Application's context background.
|
private static java.lang.String |
DATABASE_NAME |
private static int |
DATABASE_VERSION
Database constants
|
private android.database.sqlite.SQLiteDatabase[] |
dbs_
Readable & writable persistent databases' connections.
|
private static int |
JSON_BACKEND |
private static java.lang.String |
PLACE_AUTHOR |
private static java.lang.String[] |
PLACE_COLUMNS |
private static java.lang.String |
PLACE_ID
Places tables's fields.
|
private static java.lang.String |
PLACE_NAME |
private static java.lang.String |
PLACE_SHAPE |
private static java.lang.String |
PLACE_TABLE |
private static java.lang.String |
PLACE_THEME |
private static java.lang.String[] |
PLACE_TYPES |
private java.util.ArrayList<PlaceEntity> |
places_
Keeps an in-memory tracks of all places.
|
private static java.lang.String[] |
SOUND_COLUMNS |
private static java.lang.String |
SOUND_ID
Sounds tables's fields.
|
private static java.lang.String |
SOUND_PLACE |
private static java.lang.String |
SOUND_TABLE |
private static java.lang.String |
SOUND_TRACK |
private static java.lang.String[] |
SOUND_TYPES |
private static java.lang.String |
SOUND_WHERE |
Constructor and Description |
---|
DataManager(android.content.Context context)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.util.ArrayList<PlaceEntity> |
all_places()
Fetches all places stored in the
PLACE_TABLE table. |
java.util.ArrayList<SoundEntity> |
all_sounds(java.lang.String place_id)
Gets all sounds belonging to a specific
PlaceEntity . |
void |
close()
Closes the connection on both readable and writable databases.
|
private int |
count_places()
Returns the total amount of places.
|
private java.lang.String |
create_table_query(java.lang.String table,
java.lang.String[] columns,
java.lang.String[] types)
Utility function to generate a `CREATE TABLE` query where every column is of type `TEXT`, the
first one being a primary key.
|
private void |
drop(android.database.sqlite.SQLiteDatabase db)
Deletes table and recreates.
|
Area |
init()
Checks that we have actual data it the database; fills it with the (currently hard-coded)
JSON_BACKEND . |
private void |
insert_place(org.json.JSONObject place)
Mapping function that takes care of JSON -> `place` SQLITE injection.
|
private void |
insert_sound(java.lang.String place_id,
org.json.JSONObject sound)
Mapping function that takes care of JSON -> `sound` SQLITE injection.
|
SoundEntity |
inside_sound(java.lang.String place_id)
Returns all sounds of "inside" type.
|
static float |
min_distance_place(com.mapbox.mapboxsdk.geometry.LatLng reference,
java.util.ArrayList<PlaceEntity> places)
Returns the minimum distance between a reference point and a list of
PlaceEntity s. |
static java.util.ArrayList<PlaceEntity> |
nearest_place_list(com.mapbox.mapboxsdk.geometry.LatLng reference,
java.util.ArrayList<PlaceEntity> places,
short amount)
Returns a given amount list of
PlaceEntity s being the nearest of a given reference. |
private static PlaceEntity |
nearest_place(com.mapbox.mapboxsdk.geometry.LatLng reference,
java.util.ArrayList<PlaceEntity> places)
Given a list of locations, returns the nearest geographical coordinates of a reference point.
|
void |
onCreate(android.database.sqlite.SQLiteDatabase db)
Creates table structure after database creation.
|
void |
onDowngrade(android.database.sqlite.SQLiteDatabase db,
int oldVersion,
int newVersion)
Called on database version downgrade.
|
void |
onUpgrade(android.database.sqlite.SQLiteDatabase db,
int oldVersion,
int newVersion)
Called on database version upgrade.
|
static java.util.ArrayList<PlaceEntity> |
remove_farthest_place(PlaceEntity reference,
java.util.ArrayList<PlaceEntity> places)
Given a list of
PlaceEntity s and a reference point, returns the same list without its
farthest location. |
@RawRes private static final int JSON_BACKEND
private static final int DATABASE_VERSION
private static final java.lang.String DATABASE_NAME
private static final java.lang.String PLACE_ID
private static final java.lang.String PLACE_NAME
private static final java.lang.String PLACE_AUTHOR
private static final java.lang.String PLACE_THEME
private static final java.lang.String PLACE_SHAPE
private static final java.lang.String PLACE_TABLE
private static final java.lang.String[] PLACE_COLUMNS
private static final java.lang.String[] PLACE_TYPES
private static final java.lang.String SOUND_ID
private static final java.lang.String SOUND_TRACK
private static final java.lang.String SOUND_WHERE
private static final java.lang.String SOUND_PLACE
private static final java.lang.String SOUND_TABLE
private static final java.lang.String[] SOUND_COLUMNS
private static final java.lang.String[] SOUND_TYPES
private final android.content.Context context_
private final android.database.sqlite.SQLiteDatabase[] dbs_
@Nullable private java.util.ArrayList<PlaceEntity> places_
public DataManager(@NonNull android.content.Context context)
SQLiteOpenHelper
and a SoundPool
.context
- The base Context
of this app.public static java.util.ArrayList<PlaceEntity> remove_farthest_place(PlaceEntity reference, java.util.ArrayList<PlaceEntity> places)
PlaceEntity
s and a reference point, returns the same list without its
farthest location.reference
- The LatLng
reference's pointplaces
- A list of LatLng
to comparepublic static float min_distance_place(com.mapbox.mapboxsdk.geometry.LatLng reference, java.util.ArrayList<PlaceEntity> places)
PlaceEntity
s.reference
- The reference point to measure the distance fromplaces
- A list of PlaceEntity
public static java.util.ArrayList<PlaceEntity> nearest_place_list(@NonNull com.mapbox.mapboxsdk.geometry.LatLng reference, @NonNull java.util.ArrayList<PlaceEntity> places, short amount)
PlaceEntity
s being the nearest of a given reference.reference
- The location of the reference pointplaces
- A list of PlaceEntity
to compareamount
- The amount of locations to retrieve@Nullable private static PlaceEntity nearest_place(com.mapbox.mapboxsdk.geometry.LatLng reference, java.util.ArrayList<PlaceEntity> places)
reference
- The location of the reference pointplaces
- A list of LatLng
to comparepublic final Area init() throws org.json.JSONException
JSON_BACKEND
.Area
.org.json.JSONException
- in case of badly written JSON.private int count_places()
private void insert_place(org.json.JSONObject place)
place
- The JSONObject
to mapprivate void insert_sound(java.lang.String place_id, org.json.JSONObject sound)
place_id
- The id of the place this sound belongs tosound
- The JSONObject
to mappublic void close()
close
in class android.database.sqlite.SQLiteOpenHelper
dbs_
public void onCreate(android.database.sqlite.SQLiteDatabase db)
onCreate
in class android.database.sqlite.SQLiteOpenHelper
db
- The databasepublic void onUpgrade(android.database.sqlite.SQLiteDatabase db, int oldVersion, int newVersion)
onUpgrade
in class android.database.sqlite.SQLiteOpenHelper
db
- The databaseoldVersion
- The old database versionnewVersion
- The new database versionDATABASE_VERSION
public void onDowngrade(android.database.sqlite.SQLiteDatabase db, int oldVersion, int newVersion)
onDowngrade
in class android.database.sqlite.SQLiteOpenHelper
db
- The databaseoldVersion
- The old database versionnewVersion
- The new database versionDATABASE_VERSION
private void drop(android.database.sqlite.SQLiteDatabase db)
db
- A writable SQLite databaseprivate java.lang.String create_table_query(java.lang.String table, java.lang.String[] columns, java.lang.String[] types)
table
- The table namecolumns
- A list of columns that describes the tabletypes
- The corresponding sql types of columns@Nullable public java.util.ArrayList<PlaceEntity> all_places()
PLACE_TABLE
table.
The result of a first retrieval is cached inside places_
.PlaceEntity
or null
if there is no result.@Nullable public java.util.ArrayList<SoundEntity> all_sounds(java.lang.String place_id)
PlaceEntity
.place_id
- The id of the placeSoundEntity
or null
if there is no result.@Nullable public final SoundEntity inside_sound(@NonNull java.lang.String place_id)
place_id
- The place from where we're searching inside soundsSoundEntity
or null
if there is no result.