Skip to content

Commit

Permalink
Merge pull request #69 from ngageoint/develop
Browse files Browse the repository at this point in the history
v2.1.8 release
  • Loading branch information
jclark118 authored Aug 24, 2023
2 parents 2969bd2 + 3e4b202 commit aecdb50
Show file tree
Hide file tree
Showing 13 changed files with 521 additions and 324 deletions.
19 changes: 14 additions & 5 deletions mapcache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def googleMapsApiReleaseKey = hasProperty('RELEASE_MAPS_MAPCACHE_API_KEY') ? REL
def googleMapsApiKeyDebug = hasProperty('DEBUG_MAPS_API_KEY') ? DEBUG_MAPS_API_KEY : ''

android {
compileSdkVersion 31
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
Expand All @@ -14,9 +14,9 @@ android {
applicationId "mil.nga.mapcache"
resValue "string", "applicationId", applicationId
minSdkVersion 28
targetSdkVersion 31
versionCode 53
versionName '2.1.7'
targetSdkVersion 33
versionCode 55
versionName '2.1.8'
multiDexEnabled true
}
buildTypes {
Expand All @@ -38,6 +38,13 @@ android {
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}
sourceSets {
main {
java {
srcDirs 'src/main/java', 'src/test'
}
}
}
}

task androidAppVersion {
Expand All @@ -51,7 +58,7 @@ dependencies {
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
api 'androidx.appcompat:appcompat:1.3.0'
api 'com.google.android.material:material:1.6.0'
api 'androidx.preference:preference:1.2.0'
api 'androidx.preference:preference:1.2.1'
api 'androidx.lifecycle:lifecycle-extensions:2.2.0'
api 'mil.nga.geopackage.map:geopackage-android-map:6.7.1' // comment out to build locally
//api project(':geopackage-map') // uncomment me to build locally
Expand All @@ -64,8 +71,10 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
implementation 'org.locationtech.jts:jts-core:1.18.2'
implementation 'junit:junit:4.12'
testImplementation 'androidx.multidex:multidex:2.0.1'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
implementation 'com.github.matomo-org:matomo-sdk-android:v2.0.0'
}

Expand Down
25 changes: 18 additions & 7 deletions mapcache/src/main/java/mil/nga/mapcache/GeoPackageMapFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.os.Looper;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import androidx.preference.PreferenceManager;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
Expand Down Expand Up @@ -100,6 +100,7 @@
import org.jetbrains.annotations.NotNull;
import org.locationtech.proj4j.units.Units;

import java.io.File;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.text.DecimalFormat;
Expand Down Expand Up @@ -160,6 +161,7 @@
import mil.nga.mapcache.listeners.OnDialogButtonClickListener;
import mil.nga.mapcache.listeners.SensorCallback;
import mil.nga.mapcache.load.DownloadTask;
import mil.nga.mapcache.load.Downloader;
import mil.nga.mapcache.load.ILoadTilesTask;
import mil.nga.mapcache.load.ImportTask;
import mil.nga.mapcache.load.ShareTask;
Expand Down Expand Up @@ -592,6 +594,8 @@ private enum EditType {
*/
ActivityResultLauncher<Intent> importGeoPackageActivityResultLauncher;
ActivityResultLauncher<Intent> preferencePageActivityResultLauncher;
ActivityResultLauncher<Intent> downloadTaskResultLauncher;



/**
Expand Down Expand Up @@ -1076,7 +1080,10 @@ public void onRenameGP(String oldName, String newName) {
public void onShareGP(String gpName) {
// Set the geopackage name before we ask permissions and get routed back through MainActivity
// to exportGeoPackageToExternal()
File databaseFile = geoPackageViewModel.getDatabaseFile(gpName);
shareTask.setFileExternal(geoPackageViewModel.isExternal(gpName));
shareTask.setGeoPackageName(gpName);
shareTask.setGeoPackageFile(databaseFile);
getImportPermissions(MainActivity.MANAGER_PERMISSIONS_REQUEST_ACCESS_EXPORT_DATABASE);
}

Expand Down Expand Up @@ -1842,7 +1849,7 @@ public void showMapIcons() {
ViewAnimation.rotateFadeIn(settingsIcon, 200);
layerFab.show();
}


/**
* Launches a wizard to create a new tile layer in the given geopackage
Expand Down Expand Up @@ -1900,8 +1907,10 @@ public void importGeopackageFromFile() {
* Save a GeoPackage to external disk (after we've been given permission)
*/
public void exportGeoPackageToExternal() {
if (shareTask != null && shareTask.getGeoPackageName() != null) {
shareTask.askToSaveOrShare(shareTask.getGeoPackageName());

if (shareTask != null && shareTask.getGeoPackageName() != null &&
shareTask.getGeoPackageFile() != null) {
shareTask.askToSaveOrShare();
}
}

Expand Down Expand Up @@ -2026,9 +2035,11 @@ public View getView(int position, View convertView, ViewGroup parent) {
if (nameValid && urlValid) {
String database = inputName.getText() != null ? inputName.getText().toString() : "";
String url = inputUrl.getText() != null ? inputUrl.getText().toString() : "";
DownloadTask downloadTask = new DownloadTask(database, url, getActivity());

downloadTask.execute();
// Use new Downloader to import the GeoPackage
Downloader geoPackageDownloader = new Downloader(getActivity());
geoPackageDownloader.downloadGeoPackage(geoPackageViewModel, url, database);
// DownloadTask downloadTask = new DownloadTask(database, url, getActivity());
// downloadTask.execute();
alertDialog.dismiss();
} else if (!nameValid) {
inputName.requestFocus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import androidx.preference.PreferenceManager;
import android.util.Log;

import java.io.FileInputStream;
Expand Down
23 changes: 10 additions & 13 deletions mapcache/src/main/java/mil/nga/mapcache/io/MapCacheFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,22 @@ public static String getDisplayName(Context context, Uri uri, String path) {
* @param uri
* @return
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
private static String getDisplayName(Context context, Uri uri) {

String name = null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
ContentResolver resolver = context.getContentResolver();
Cursor nameCursor = resolver.query(uri, null, null, null, null);
try {
if (nameCursor.getCount() > 0) {
int displayNameIndex = nameCursor
.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME);
if (displayNameIndex >= 0 && nameCursor.moveToFirst()) {
name = nameCursor.getString(displayNameIndex);
}
ContentResolver resolver = context.getContentResolver();
Cursor nameCursor = resolver.query(uri, null, null, null, null);
try {
if (nameCursor.getCount() > 0) {
int displayNameIndex = nameCursor
.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME);
if (displayNameIndex >= 0 && nameCursor.moveToFirst()) {
name = nameCursor.getString(displayNameIndex);
}
} finally {
nameCursor.close();
}
} finally {
nameCursor.close();
}

if (name == null) {
Expand Down
109 changes: 109 additions & 0 deletions mapcache/src/main/java/mil/nga/mapcache/load/Downloader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package mil.nga.mapcache.load

import android.app.AlertDialog
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.appcompat.widget.AppCompatImageView
import androidx.fragment.app.FragmentActivity
import mil.nga.geopackage.io.GeoPackageProgress
import mil.nga.mapcache.R
import mil.nga.mapcache.viewmodel.GeoPackageViewModel
import java.net.URL
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

/**
* Downloads a GeoPackage via the GeoPackageViewModel, providing feedback and cancel action via
* an AlertDialog
*/
class Downloader(val activity : FragmentActivity) : GeoPackageProgress{

private var max: Int = 0
private var progress: Int = 0
private val alertDialog: AlertDialog
private val myExecutor: ExecutorService = Executors.newSingleThreadExecutor()
private var geoPackageName : String = ""

/**
* Create the alert dialog
*/
init {
val builder = AlertDialog.Builder(activity, R.style.AppCompatAlertDialogStyle)

// Create Alert window with basic input text layout
val inflater = LayoutInflater.from(activity)
val alertView: View = inflater.inflate(R.layout.basic_label_alert, null)

// Set dialog view info
val alertLogo = alertView.findViewById<AppCompatImageView>(R.id.alert_logo)
alertLogo.setImageResource(R.drawable.material_add_box)
val titleText = alertView.findViewById<TextView>(R.id.alert_title)
titleText.setText(R.string.import_geopackage_url)
val actionLabel = alertView.findViewById<View>(R.id.action_label) as TextView
actionLabel.setText("Importing GeoPackage")
actionLabel.visibility = View.VISIBLE

// Cancel button
builder.setPositiveButton("Cancel") {alertDialog, which ->
myExecutor.shutdownNow()
}

builder.setView(alertView)
builder.setCancelable(false)
alertDialog = builder.create()
}


/**
* Ask the viewmodel to download the given database from the given url. Show the alert dialog
* and allow cancel
*/
fun downloadGeoPackage(viewModel : GeoPackageViewModel, url : String, database : String){
val handler = android.os.Handler(Looper.getMainLooper())
val theUrl = URL(url)
var completeMessage : String = "Import failed"
geoPackageName = database
alertDialog.show()
myExecutor.submit {
try {
if (!viewModel.importGeoPackage(database, theUrl, this)) {
completeMessage = "Failed to import GeoPackage '$database' at url '$url'"
} else {
completeMessage = "GeoPackage imported"
}
} catch (e: InterruptedException){
Thread.currentThread().interrupt()
}
handler.post {
alertDialog.dismiss()
}
}
}

/**
* Sets the max download
*/
override fun setMax(max: Int) {
this.max = max
}

/**
* Add download progress, then update the alert dialog
*/
override fun addProgress(progress: Int) {
this.progress += progress
val percentComplete = (this.progress / max.toDouble() * 100).toInt()
val actionLabel = alertDialog.findViewById<View>(R.id.action_label) as TextView
actionLabel.text = "Importing $geoPackageName: $percentComplete%"
}

override fun isActive(): Boolean {
return true
}

override fun cleanupOnCancel(): Boolean {
return true
}
}
Loading

0 comments on commit aecdb50

Please sign in to comment.