Skip to content

Commit

Permalink
open external GeoPackage support
Browse files Browse the repository at this point in the history
  • Loading branch information
bosborn committed Mar 12, 2021
1 parent b37ea52 commit 54c01f2
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 64 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Adheres to [Semantic Versioning](http://semver.org/).

---

## 5.0.1 (TBD)
## 5.1.0 (TBD)

* TBD
* Open external GeoPackage support, without a required Context

## [5.0.0](https://github.com/ngageoint/geopackage-android/releases/tag/5.0.0) (03-09-2021)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,40 @@ public void testImportDocumentAsExternalLink() {
loadCorruptFile.delete());
}

/**
* Test opening an external file GeoPackage
*/
@Test
public void testOpenExternal() {

GeoPackageManager manager = GeoPackageFactory.getExternalManager();

// Copy the test db file from assets to the internal storage
TestUtils.copyAssetFileToInternalStorage(activity, testContext,
TestConstants.IMPORT_DB_FILE_NAME);

// Open
String externalLocation = TestUtils.getAssetFileInternalStorageLocation(
activity, TestConstants.IMPORT_DB_FILE_NAME);
File externalFile = new File(externalLocation);
DocumentFile externalDocument = DocumentFile.fromFile(externalFile);

GeoPackage geoPackage = manager.openExternal(externalLocation);
assertNotNull("Failed to open database", geoPackage);
geoPackage.close();

geoPackage = manager.openExternal(externalFile);
assertNotNull("Failed to open database", geoPackage);
geoPackage.close();

geoPackage = manager.openExternal(externalDocument);
assertNotNull("Failed to open database", geoPackage);
geoPackage.close();

// Delete the file
assertTrue("External file could not be deleted", externalFile.delete());
}

/**
* Test creating a database GeoPackage at a file
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,14 @@ public static GeoPackageManager getManager(Context context) {
return new GeoPackageManagerImpl(context);
}

/**
* Get a GeoPackage Manager for operating only on external GeoPackages
*
* @return GeoPackage manager
* @since 5.1.0
*/
public static GeoPackageManager getExternalManager() {
return getManager(null);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mil.nga.geopackage;

import android.content.ContentValues;
import android.content.Context;
import android.net.Uri;
import android.os.Build;

Expand All @@ -23,6 +24,14 @@
*/
public interface GeoPackageManager {

/**
* Get the application context
*
* @return context
* @since 5.1.0
*/
public Context getContext();

/**
* List all GeoPackage databases sorted alphabetically
*
Expand Down Expand Up @@ -716,6 +725,60 @@ public boolean importGeoPackage(String name, URL url, boolean override,
*/
public GeoPackage open(String database, boolean writable);

/**
* Open an external GeoPackage
*
* @param path full file path
* @return open GeoPackage
* @since 5.1.0
*/
public GeoPackage openExternal(File path);

/**
* Open an external GeoPackage
*
* @param path full file path
* @param writable true to open as writable, false as read only
* @return 5.1.0
*/
public GeoPackage openExternal(File path, boolean writable);

/**
* Open an external GeoPackage
*
* @param path full file path
* @return open GeoPackage
* @since 5.1.0
*/
public GeoPackage openExternal(String path);

/**
* Open an external GeoPackage
*
* @param path full file path
* @param writable true to open as writable, false as read only
* @return 5.1.0
*/
public GeoPackage openExternal(String path, boolean writable);

/**
* Open an external GeoPackage
*
* @param file document file
* @return open GeoPackage
* @since 5.1.0
*/
public GeoPackage openExternal(DocumentFile file);

/**
* Open an external GeoPackage
*
* @param file document file
* @param writable true to open as writable, false as read only
* @return 5.1.0
*/
public GeoPackage openExternal(DocumentFile file, boolean writable);

/**
* Is import database header validation enabled.
* This causes a small time increase when importing a database to check the header bytes.
Expand Down
Loading

0 comments on commit 54c01f2

Please sign in to comment.