Skip to content

Commit

Permalink
Merge pull request #70 from ngageoint/develop
Browse files Browse the repository at this point in the history
Release v2.1.9
Fixes for file and camera permissions on android 13
Fix for show my location
  • Loading branch information
jclark118 authored Sep 1, 2023
2 parents aecdb50 + be0dc99 commit 2aab3d5
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 51 deletions.
4 changes: 2 additions & 2 deletions mapcache/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
83 changes: 51 additions & 32 deletions mapcache/src/main/java/mil/nga/mapcache/GeoPackageMapFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -2705,9 +2741,6 @@ private void saveEditFeatures() {
*/
@Override
public void onResume() {
if (locationVisible) {
showMyLocation();
}
super.onResume();
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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();
}
}
Expand Down
10 changes: 5 additions & 5 deletions mapcache/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<resources>

<string name="app_name">MapCache</string>
<string name="app_version">Version 2.1.8</string>
<string name="app_release_date">Released Aug 2023</string>
<string name="app_version">Version 2.1.9</string>
<string name="app_release_date">Released Sept 2023</string>
<string name="app_label_name">MapCache</string>
<string name="title_map">Map</string>
<string name="title_manager">Manager</string>
Expand Down Expand Up @@ -386,9 +386,9 @@
<string name="geopackage_android_url">&lt;a href=http://ngageoint.github.io/geopackage-android>GeoPackage Android on Github&lt;/a></string>
<string name="ogc_url">&lt;a href=http://www.geopackage.org/#implementations_nga>OGC GeoPackage&lt;/a></string>
<string name="release_notes">
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
</string>


Expand Down

0 comments on commit 2aab3d5

Please sign in to comment.