diff --git a/mapcache/build.gradle b/mapcache/build.gradle index dc20d2fc..8c004eb4 100644 --- a/mapcache/build.gradle +++ b/mapcache/build.gradle @@ -15,8 +15,8 @@ android { resValue "string", "applicationId", applicationId minSdkVersion 28 targetSdkVersion 33 - versionCode 55 - versionName '2.1.8' + versionCode 56 + versionName '2.1.9' multiDexEnabled true } buildTypes { diff --git a/mapcache/src/main/java/mil/nga/mapcache/GeoPackageMapFragment.java b/mapcache/src/main/java/mil/nga/mapcache/GeoPackageMapFragment.java index 0b41af5f..f46d9b01 100644 --- a/mapcache/src/main/java/mil/nga/mapcache/GeoPackageMapFragment.java +++ b/mapcache/src/main/java/mil/nga/mapcache/GeoPackageMapFragment.java @@ -266,7 +266,7 @@ public class GeoPackageMapFragment extends Fragment implements /** * True when the location is shown on the map. */ - private static boolean locationVisible = false; + private boolean locationVisible = false; /** * True when we are showing bearing on the map @@ -1422,11 +1422,27 @@ private void showMyLocation() { } else { ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MainActivity.MAP_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); } + } else { + // Only zoom when turning location on, not when hiding it + if (locationVisible) { + zoomToMyLocation(); + } } - // Only zoom when turning location on, not when hiding it - if (locationVisible) { - zoomToMyLocation(); + } + + /** + * Set the my location enabled state on the map if permission has been granted + * + * @return true if updated, false if permission is required + */ + public boolean setMyLocationEnabled() { + boolean updated = false; + if (map != null && getActivity() != null && ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { + map.setMyLocationEnabled(locationVisible); + updated = true; + map.getUiSettings().setMyLocationButtonEnabled(false); } + return updated; } /** @@ -1870,22 +1886,42 @@ this, getActivity(), getContext(), this, */ private void getImportPermissions(int returnCode) { if (getActivity() != null) { - if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) { - new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle) - .setTitle(R.string.storage_access_rational_title) - .setMessage(R.string.storage_access_rational_message) - .setPositiveButton(android.R.string.ok, (DialogInterface dialog, int which) -> - ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, returnCode) - ) - .create() - .show(); - + //TODO: update permissions to remove Write external storage permissions + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){ + executeRequestCode(returnCode); } else { - ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, returnCode); + if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle) + .setTitle(R.string.storage_access_rational_title) + .setMessage(R.string.storage_access_rational_message) + .setPositiveButton(android.R.string.ok, (DialogInterface dialog, int which) -> + ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, returnCode) + ) + .create() + .show(); + + } else { + ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, returnCode); + } } } } + /** + * Force execution of given request code option without permissions + * @param requestCode request code matching MainActivity onRequestPermissionsResult functions + */ + private void executeRequestCode(int requestCode){ + switch (requestCode) { + case MainActivity.MANAGER_PERMISSIONS_REQUEST_ACCESS_IMPORT_EXTERNAL: + importGeopackageFromFile(); + break; + case MainActivity.MANAGER_PERMISSIONS_REQUEST_ACCESS_EXPORT_DATABASE: + exportGeoPackageToExternal(); + break; + } + } + /** * Import a GeoPackage from a file (after we've been given permission) @@ -2705,9 +2741,6 @@ private void saveEditFeatures() { */ @Override public void onResume() { - if (locationVisible) { - showMyLocation(); - } super.onResume(); } @@ -2754,20 +2787,6 @@ public void onHiddenChanged(boolean hidden) { } } - /** - * Set the my location enabled state on the map if permission has been granted - * - * @return true if updated, false if permission is required - */ - public boolean setMyLocationEnabled() { - boolean updated = false; - if (map != null && getActivity() != null && ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { - map.setMyLocationEnabled(locationVisible); - updated = true; - map.getUiSettings().setMyLocationButtonEnabled(false); - } - return updated; - } /** * Handle map menu clicks diff --git a/mapcache/src/main/java/mil/nga/mapcache/view/map/feature/FeatureViewActivity.java b/mapcache/src/main/java/mil/nga/mapcache/view/map/feature/FeatureViewActivity.java index 1e881dc6..bd22573d 100644 --- a/mapcache/src/main/java/mil/nga/mapcache/view/map/feature/FeatureViewActivity.java +++ b/mapcache/src/main/java/mil/nga/mapcache/view/map/feature/FeatureViewActivity.java @@ -11,6 +11,7 @@ import android.graphics.BitmapFactory; import android.media.Image; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.provider.MediaStore; @@ -523,7 +524,7 @@ private Bitmap getImageResult(Uri uri){ /** - * Check permissions for camera use + * Check permissions for camera use. Note, only check write_external if < android 10 */ public static boolean checkAndRequestPermissions(final Activity context) { int writeExternalPermission = ContextCompat.checkSelfPermission(context, @@ -534,9 +535,11 @@ public static boolean checkAndRequestPermissions(final Activity context) { if (cameraPermission != PackageManager.PERMISSION_GRANTED) { listPermissionsNeeded.add(Manifest.permission.CAMERA); } - if (writeExternalPermission != PackageManager.PERMISSION_GRANTED) { - listPermissionsNeeded - .add(Manifest.permission.WRITE_EXTERNAL_STORAGE); + if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q){ + if (writeExternalPermission != PackageManager.PERMISSION_GRANTED) { + listPermissionsNeeded + .add(Manifest.permission.WRITE_EXTERNAL_STORAGE); + } } if (!listPermissionsNeeded.isEmpty()) { ActivityCompat.requestPermissions(context, listPermissionsNeeded @@ -555,19 +558,26 @@ public static boolean checkAndRequestPermissions(final Activity context) { @Override public void onRequestPermissionsResult(int requestCode, @NotNull String[] permissions, @NotNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); + boolean flagged = false; if (requestCode == REQUEST_ID_MULTIPLE_PERMISSIONS) { if (ContextCompat.checkSelfPermission(FeatureViewActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getApplicationContext(), - "FlagUp Requires Access to Camara.", Toast.LENGTH_SHORT) + "Camera permissions required", Toast.LENGTH_SHORT) .show(); - - } else if (ContextCompat.checkSelfPermission(FeatureViewActivity.this, - Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - Toast.makeText(getApplicationContext(), - "FlagUp Requires Access to Your Storage.", - Toast.LENGTH_SHORT).show(); - } else { + flagged = true; + } + if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) { + if (ContextCompat.checkSelfPermission(FeatureViewActivity.this, + Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + Toast.makeText(getApplicationContext(), + "Storage permissions required", + Toast.LENGTH_SHORT).show(); + flagged = true; + + } + } + if(!flagged) { takePicture(); } } diff --git a/mapcache/src/main/res/values/strings.xml b/mapcache/src/main/res/values/strings.xml index 7c664b5c..262bf79e 100644 --- a/mapcache/src/main/res/values/strings.xml +++ b/mapcache/src/main/res/values/strings.xml @@ -2,8 +2,8 @@ MapCache - Version 2.1.8 - Released Aug 2023 + Version 2.1.9 + Released Sept 2023 MapCache Map Manager @@ -386,9 +386,9 @@ <a href=http://ngageoint.github.io/geopackage-android>GeoPackage Android on Github</a> <a href=http://www.geopackage.org/#implementations_nga>OGC GeoPackage</a> - Release Notes - 2.1.8\n \n - - Backend performance improvements\n - - Usability enhancements + Release Notes - 2.1.9\n \n + - Fixes for file and camera permissions on android 13\n + - Fix for show my location