Permalink
Browse files

POI: SQLite Android Bindings, fix #1079

  • Loading branch information...
devemux86 committed Aug 12, 2018
1 parent d3c25e6 commit 59d06f3c7e5bffd5ed0ba008d7cf97228858c915
Showing with 11,392 additions and 4,694 deletions.
  1. +4 −4 build.gradle
  2. +1 −0 docs/Changelog.md
  3. +2 −2 docs/Getting-Started-Developers.md
  4. +5 −4 docs/Integration.md
  5. +3 −3 docs/POI.md
  6. +1 −1 mapsforge-poi-android/build.gradle
  7. +20 −13 mapsforge-poi-android/src/main/java/org/mapsforge/poi/android/storage/AndroidPoiCategoryManager.java
  8. +133 −269 ...rge-poi-android/src/main/java/org/mapsforge/poi/android/storage/AndroidPoiPersistenceManager.java
  9. +1 −1 mapsforge-samples-android/build.gradle
  10. +3 −3 settings.gradle
  11. +0 −6 spatialite-android/build.gradle
  12. BIN spatialite-android/natives/armeabi-v7a/lib/armeabi-v7a/libjsqlite.so
  13. BIN spatialite-android/natives/armeabi/lib/armeabi/libjsqlite.so
  14. BIN spatialite-android/natives/x86/lib/x86/libjsqlite.so
  15. +0 −25 spatialite-android/src/main/java/jsqlite/Authorizer.java
  16. +0 −99 spatialite-android/src/main/java/jsqlite/Backup.java
  17. +0 −786 spatialite-android/src/main/java/jsqlite/Benchmark.java
  18. +0 −337 spatialite-android/src/main/java/jsqlite/Blob.java
  19. +0 −20 spatialite-android/src/main/java/jsqlite/BusyHandler.java
  20. +0 −68 spatialite-android/src/main/java/jsqlite/Callback.java
  21. +0 −145 spatialite-android/src/main/java/jsqlite/Constants.java
  22. +0 −970 spatialite-android/src/main/java/jsqlite/Database.java
  23. +0 −18 spatialite-android/src/main/java/jsqlite/Exception.java
  24. +0 −59 spatialite-android/src/main/java/jsqlite/Function.java
  25. +0 −82 spatialite-android/src/main/java/jsqlite/FunctionContext.java
  26. +0 −19 spatialite-android/src/main/java/jsqlite/Profile.java
  27. +0 −17 spatialite-android/src/main/java/jsqlite/ProgressHandler.java
  28. +0 −96 spatialite-android/src/main/java/jsqlite/SQLDump.java
  29. +0 −49 spatialite-android/src/main/java/jsqlite/SQLRestore.java
  30. +0 −698 spatialite-android/src/main/java/jsqlite/Shell.java
  31. +0 −330 spatialite-android/src/main/java/jsqlite/Stmt.java
  32. +0 −315 spatialite-android/src/main/java/jsqlite/StringEncoder.java
  33. +0 −159 spatialite-android/src/main/java/jsqlite/TableResult.java
  34. +0 −17 spatialite-android/src/main/java/jsqlite/Trace.java
  35. +0 −79 spatialite-android/src/main/java/jsqlite/Vm.java
  36. +2 −0 sqlite-android/AndroidManifest.xml
  37. +202 −0 sqlite-android/LICENSE
  38. +11 −0 sqlite-android/build.gradle
  39. BIN sqlite-android/natives/arm64-v8a/lib/arm64-v8a/libsqliteX.so
  40. BIN sqlite-android/natives/armeabi-v7a/lib/armeabi-v7a/libsqliteX.so
  41. BIN sqlite-android/natives/x86/lib/x86/libsqliteX.so
  42. BIN sqlite-android/natives/x86_64/lib/x86_64/libsqliteX.so
  43. +37 −0 sqlite-android/src/main/java/org/sqlite/database/DatabaseErrorHandler.java
  44. +1,461 −0 sqlite-android/src/main/java/org/sqlite/database/DatabaseUtils.java
  45. +117 −0 sqlite-android/src/main/java/org/sqlite/database/DefaultDatabaseErrorHandler.java
  46. +37 −0 sqlite-android/src/main/java/org/sqlite/database/SQLException.java
  47. +235 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/CloseGuard.java
  48. +35 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/DatabaseObjectNotClosedException.java
  49. +34 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteAbortException.java
  50. +33 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteAccessPermException.java
  51. +32 −0 ...-android/src/main/java/org/sqlite/database/sqlite/SQLiteBindOrColumnIndexOutOfRangeException.java
  52. +29 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteBlobTooBigException.java
  53. +29 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteCantOpenDatabaseException.java
  54. +112 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteClosable.java
  55. +1,525 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteConnection.java
  56. +1,086 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteConnectionPool.java
  57. +32 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteConstraintException.java
  58. +284 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteCursor.java
  59. +60 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteCursorDriver.java
  60. +57 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteCustomFunction.java
  61. +2,223 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteDatabase.java
  62. +177 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteDatabaseConfiguration.java
  63. +32 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteDatabaseCorruptException.java
  64. +37 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteDatabaseLockedException.java
  65. +29 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteDatatypeMismatchException.java
  66. +178 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteDebug.java
  67. +87 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteDirectCursorDriver.java
  68. +33 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteDiskIOException.java
  69. +35 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteDoneException.java
  70. +39 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteException.java
  71. +32 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteFullException.java
  72. +118 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteGlobal.java
  73. +41 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteMisuseException.java
  74. +441 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteOpenHelper.java
  75. +29 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteOutOfMemoryException.java
  76. +222 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteProgram.java
  77. +88 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteQuery.java
  78. +652 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteQueryBuilder.java
  79. +29 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteReadOnlyDatabaseException.java
  80. +967 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteSession.java
  81. +167 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteStatement.java
  82. +43 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteStatementInfo.java
  83. +29 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteTableLockedException.java
  84. +41 −0 sqlite-android/src/main/java/org/sqlite/database/sqlite/SQLiteTransactionListener.java
View
@@ -31,8 +31,8 @@ allprojects {
static def androidCompileSdk() { return 28 }
// Minimum API Level by Support Library
static def androidMinSdk() { return 14 }
// 14 for Support Library, 16 for sqlite-android
static def androidMinSdk() { return 16 }
static def androidTargetSdk() { return 22 }
@@ -56,7 +56,7 @@ subprojects {
}
// Configuration for all plain Java projects
project.ext.javalibraryprojects = ["mapsforge-core", "mapsforge-map", "mapsforge-themes", "mapsforge-map-reader", "mapsforge-map-awt", "mapsforge-map-writer", "mapsforge-poi", "mapsforge-poi-awt", "mapsforge-poi-writer", "spatialite-android"]
project.ext.javalibraryprojects = ["mapsforge-core", "mapsforge-map", "mapsforge-map-awt", "mapsforge-map-reader", "mapsforge-map-writer", "mapsforge-poi", "mapsforge-poi-awt", "mapsforge-poi-writer", "mapsforge-themes"]
project.ext.javaprojects = project.javalibraryprojects + ["mapsforge-samples-awt"]
configure(filterProjects(project.javalibraryprojects)) {
@@ -89,7 +89,7 @@ configure(filterProjects(project.javaprojects)) {
}
// Configuration for Android projects
project.ext.androidlibraryprojects = ["mapsforge-map-android", "mapsforge-poi-android"]
project.ext.androidlibraryprojects = ["mapsforge-map-android", "mapsforge-poi-android", "sqlite-android"]
project.ext.androidapkprojects = ["mapsforge-samples-android"]
project.ext.androidprojects = project.androidlibraryprojects + project.androidapkprojects
View
@@ -5,6 +5,7 @@
- Mapsforge maps **v5**: custom tag keys [#1041](https://github.com/mapsforge/mapsforge/issues/1041)
- Read & render polygon label/symbol position [#1064](https://github.com/mapsforge/mapsforge/issues/1064)
- Map writer: polygon label/symbol centroid [#1061](https://github.com/mapsforge/mapsforge/issues/1061)
- POI: SQLite Android Bindings [#1079](https://github.com/mapsforge/mapsforge/issues/1079)
- POI: offline address search [#1063](https://github.com/mapsforge/mapsforge/issues/1063)
- POI writer: tag keys as categories [#1062](https://github.com/mapsforge/mapsforge/pull/1062)
- MyLocationOverlay implementation [#1035](https://github.com/mapsforge/mapsforge/issues/1035)
@@ -26,14 +26,14 @@ Extra Android components:
- mapsforge-map-android: android specific map elements.
- mapsforge-poi-android: android specific poi elements.
- [androidsvg](http://bigbadaboom.github.io/androidsvg/): SVG library for displaying SVG files as icons.
- [spatialite-android](https://www.gaia-gis.it/fossil/libspatialite/wiki?name=splite-android): SQLite spatial library.
- [sqlite-android](https://sqlite.org/android/): SQLite Android Bindings.
Extra Java components:
- mapsforge-map-awt: a Java-only library to display mapsforge maps.
- mapsforge-poi-awt: java specific poi elements.
- [svg-salamander](https://github.com/blackears/svgSalamander): SVG library for displaying SVG files as icons.
- [xerial/sqlite-jdbc](https://github.com/xerial/sqlite-jdbc): SQLite JDBC library.
- [xerial/sqlite-jdbc](https://github.com/xerial/sqlite-jdbc): SQLite JDBC Driver.
### Branches
View
@@ -44,10 +44,11 @@ implementation 'org.mapsforge:mapsforge-poi:[CURRENT-VERSION]'
#### Android
```groovy
implementation 'org.mapsforge:mapsforge-poi-android:[CURRENT-VERSION]'
implementation 'org.mapsforge:spatialite-android:[CURRENT-VERSION]'
implementation 'org.mapsforge:spatialite-android:[CURRENT-VERSION]:natives-armeabi'
implementation 'org.mapsforge:spatialite-android:[CURRENT-VERSION]:natives-armeabi-v7a'
implementation 'org.mapsforge:spatialite-android:[CURRENT-VERSION]:natives-x86'
implementation 'org.mapsforge:sqlite-android:[CURRENT-VERSION]'
implementation 'org.mapsforge:sqlite-android:[CURRENT-VERSION]:natives-armeabi-v7a'
implementation 'org.mapsforge:sqlite-android:[CURRENT-VERSION]:natives-arm64-v8a'
implementation 'org.mapsforge:sqlite-android:[CURRENT-VERSION]:natives-x86'
implementation 'org.mapsforge:sqlite-android:[CURRENT-VERSION]:natives-x86_64'
```
#### Desktop
View
@@ -8,7 +8,7 @@ If you have any questions or problems, don't hesitate to ask our public [mapsfor
_Points of Interest_ (POIs) are points with a given position, category and data. A POI database is used to store a set of POIs and to search for POIs within a given area.
The mapsforge POI library uses SQLite for storing POIs. For efficiency reasons Android's SQLite implementation is not used. Instead [SpatiaLite](https://www.gaia-gis.it/fossil/libspatialite/index), a spatial extension to SQLite, is used to provide an SQLite implementation with R-tree functionality.
The mapsforge POI library uses SQLite for storing POIs. For efficiency reasons Android's SQLite implementation is not used. Instead [SQLite Android Bindings](https://sqlite.org/android/) is used to provide an SQLite implementation with [R-tree](https://sqlite.org/rtree.html) functionality.
All reading and writing operations are done via classes implementing the `PoiPersistenceManager` interface. This allows adding, removing and changing POIs at any time. POI categories can be defined on creation time only. Categories are implemented as trees and can be accessed via classes implementing the `PoiCategoryManager` interface.
@@ -55,9 +55,9 @@ The `--poi-writer`, or short `--pw` task indicates that the POI writer plugin sh
### Example
With the POI database created you can now use it with mapsforge. For testing purposes, you may also use one of our ready-to-use POI databases from http://download.mapsforge.org/pois/ (not suitable for mass downloads). You will also need the SpatiaLite native library files in your project. You can use the Samples project as a boilerplate, as it already has all necessary files and dependencies. The library files are located each within a separate sub-folder for each target architecture (_armeabi_, _armeabi-v7a_, _x86_). You can delete unneeded architectures to reduce file size.
With the POI database created you can now use it with mapsforge. For testing purposes, you may also use one of our ready-to-use POI databases from http://download.mapsforge.org/pois/ (not suitable for mass downloads). You will also need the SQLite Android Bindings native library files in your project. You can use the Samples project as a boilerplate, as it already has all necessary files and dependencies. The library files are located each within a separate sub-folder for each target architecture (_armeabi-v7a_, _arm64-v8a_, _x86_, _x86_64_). You can delete unneeded architectures to reduce file size.
The sources for those libraries can be found at [spatialite-android](https://www.gaia-gis.it/fossil/libspatialite/wiki?name=splite-android) site. To compile these manually you need the [Android NDK](http://developer.android.com/tools/sdk/ndk/index.html). The compilation process can be started with `ndk-build` from within the `jni` directory. The compiling process also moves the library files to their correct (sub)folders.
The sources for those libraries can be found at [SQLite Android Bindings](https://sqlite.org/android/) site. To compile these manually you need the [Android NDK](https://developer.android.com/ndk/). The compilation process can be started with `ndk-build` from within the `jni` directory. The compiling process also moves the library files to their correct (sub)folders.
With everything set up you can check the ['POI search' example](https://github.com/mapsforge/mapsforge/blob/master/mapsforge-samples-android/src/main/java/org/mapsforge/samples/android/PoiSearchViewer.java) for:
- How a database is opened for read access. Any access to the database is encapsulated via classes implementing `PoiPersistenceManager`. The instantiation of these classes is done via a factory class. The categories and their hierarchy are maintained via classes implementing `PoiCategoryManager`. The category configuration is read-only.
@@ -1,4 +1,4 @@
dependencies {
api project(":mapsforge-poi")
api project(":spatialite-android")
api project(":sqlite-android")
}
@@ -1,7 +1,7 @@
/*
* Copyright 2010, 2011 mapsforge.org
* Copyright 2010, 2011 Karsten Groll
* Copyright 2015-2016 devemux86
* Copyright 2015-2018 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@@ -16,21 +16,21 @@
*/
package org.mapsforge.poi.android.storage;
import android.database.Cursor;
import org.mapsforge.poi.storage.AbstractPoiCategoryManager;
import org.mapsforge.poi.storage.DoubleLinkedPoiCategory;
import org.mapsforge.poi.storage.PoiCategory;
import org.mapsforge.poi.storage.PoiCategoryManager;
import org.mapsforge.poi.storage.UnknownPoiCategoryException;
import org.sqlite.database.sqlite.SQLiteDatabase;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import jsqlite.Database;
import jsqlite.Stmt;
/**
* A {@link PoiCategoryManager} implementation using a SQLite database via wrapper.
* <p/>
@@ -42,7 +42,7 @@
/**
* @param db SQLite database object. (Using SQLite wrapper for Android).
*/
AndroidPoiCategoryManager(Database db) {
AndroidPoiCategoryManager(SQLiteDatabase db) {
this.categoryMap = new TreeMap<>();
try {
@@ -57,21 +57,21 @@
*
* @throws UnknownPoiCategoryException if a category cannot be retrieved by its ID or unique name.
*/
private void loadCategories(Database db) throws UnknownPoiCategoryException {
private void loadCategories(SQLiteDatabase db) throws UnknownPoiCategoryException {
// Maximum ID (for root node)
int maxID = 0;
// Maps categories to their parent IDs
Map<PoiCategory, Integer> parentMap = new HashMap<>();
Cursor cursor = null;
try {
Stmt stmt = db.prepare(SELECT_STATEMENT);
stmt.reset();
while (stmt.step()) {
cursor = db.rawQuery(SELECT_STATEMENT, null);
while (cursor.moveToNext()) {
// Column values
int categoryID = stmt.column_int(0);
String categoryTitle = stmt.column_string(1);
int categoryParentID = stmt.column_int(2);
int categoryID = cursor.getInt(0);
String categoryTitle = cursor.getString(1);
int categoryParentID = cursor.getInt(2);
PoiCategory pc = new DoubleLinkedPoiCategory(categoryTitle, null, categoryID);
this.categoryMap.put(categoryID, pc);
@@ -84,9 +84,16 @@ private void loadCategories(Database db) throws UnknownPoiCategoryException {
maxID = categoryID;
}
}
stmt.close();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
} finally {
try {
if (cursor != null) {
cursor.close();
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
}
// Set root category and remove it from parents map
Oops, something went wrong.

0 comments on commit 59d06f3

Please sign in to comment.