@@ -266,7 +266,7 @@ public class GeoPackageMapFragment extends Fragment implements
266266 /**
267267 * True when the location is shown on the map.
268268 */
269- private static boolean locationVisible = false ;
269+ private boolean locationVisible = false ;
270270
271271 /**
272272 * True when we are showing bearing on the map
@@ -1422,11 +1422,27 @@ private void showMyLocation() {
14221422 } else {
14231423 ActivityCompat .requestPermissions (getActivity (), new String []{Manifest .permission .ACCESS_FINE_LOCATION }, MainActivity .MAP_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION );
14241424 }
1425+ } else {
1426+ // Only zoom when turning location on, not when hiding it
1427+ if (locationVisible ) {
1428+ zoomToMyLocation ();
1429+ }
14251430 }
1426- // Only zoom when turning location on, not when hiding it
1427- if (locationVisible ) {
1428- zoomToMyLocation ();
1431+ }
1432+
1433+ /**
1434+ * Set the my location enabled state on the map if permission has been granted
1435+ *
1436+ * @return true if updated, false if permission is required
1437+ */
1438+ public boolean setMyLocationEnabled () {
1439+ boolean updated = false ;
1440+ if (map != null && getActivity () != null && ContextCompat .checkSelfPermission (getActivity (), Manifest .permission .ACCESS_FINE_LOCATION ) == PackageManager .PERMISSION_GRANTED ) {
1441+ map .setMyLocationEnabled (locationVisible );
1442+ updated = true ;
1443+ map .getUiSettings ().setMyLocationButtonEnabled (false );
14291444 }
1445+ return updated ;
14301446 }
14311447
14321448 /**
@@ -1870,22 +1886,42 @@ this, getActivity(), getContext(), this,
18701886 */
18711887 private void getImportPermissions (int returnCode ) {
18721888 if (getActivity () != null ) {
1873- if (ActivityCompat .shouldShowRequestPermissionRationale (getActivity (), Manifest .permission .WRITE_EXTERNAL_STORAGE )) {
1874- new AlertDialog .Builder (getActivity (), R .style .AppCompatAlertDialogStyle )
1875- .setTitle (R .string .storage_access_rational_title )
1876- .setMessage (R .string .storage_access_rational_message )
1877- .setPositiveButton (android .R .string .ok , (DialogInterface dialog , int which ) ->
1878- ActivityCompat .requestPermissions (getActivity (), new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE }, returnCode )
1879- )
1880- .create ()
1881- .show ();
1882-
1889+ //TODO: update permissions to remove Write external storage permissions
1890+ if (android .os .Build .VERSION .SDK_INT >= Build .VERSION_CODES .Q ){
1891+ executeRequestCode (returnCode );
18831892 } else {
1884- ActivityCompat .requestPermissions (getActivity (), new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE }, returnCode );
1893+ if (ActivityCompat .shouldShowRequestPermissionRationale (getActivity (), Manifest .permission .WRITE_EXTERNAL_STORAGE )) {
1894+ new AlertDialog .Builder (getActivity (), R .style .AppCompatAlertDialogStyle )
1895+ .setTitle (R .string .storage_access_rational_title )
1896+ .setMessage (R .string .storage_access_rational_message )
1897+ .setPositiveButton (android .R .string .ok , (DialogInterface dialog , int which ) ->
1898+ ActivityCompat .requestPermissions (getActivity (), new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE }, returnCode )
1899+ )
1900+ .create ()
1901+ .show ();
1902+
1903+ } else {
1904+ ActivityCompat .requestPermissions (getActivity (), new String []{Manifest .permission .WRITE_EXTERNAL_STORAGE }, returnCode );
1905+ }
18851906 }
18861907 }
18871908 }
18881909
1910+ /**
1911+ * Force execution of given request code option without permissions
1912+ * @param requestCode request code matching MainActivity onRequestPermissionsResult functions
1913+ */
1914+ private void executeRequestCode (int requestCode ){
1915+ switch (requestCode ) {
1916+ case MainActivity .MANAGER_PERMISSIONS_REQUEST_ACCESS_IMPORT_EXTERNAL :
1917+ importGeopackageFromFile ();
1918+ break ;
1919+ case MainActivity .MANAGER_PERMISSIONS_REQUEST_ACCESS_EXPORT_DATABASE :
1920+ exportGeoPackageToExternal ();
1921+ break ;
1922+ }
1923+ }
1924+
18891925
18901926 /**
18911927 * Import a GeoPackage from a file (after we've been given permission)
@@ -2705,9 +2741,6 @@ private void saveEditFeatures() {
27052741 */
27062742 @ Override
27072743 public void onResume () {
2708- if (locationVisible ) {
2709- showMyLocation ();
2710- }
27112744 super .onResume ();
27122745 }
27132746
@@ -2754,20 +2787,6 @@ public void onHiddenChanged(boolean hidden) {
27542787 }
27552788 }
27562789
2757- /**
2758- * Set the my location enabled state on the map if permission has been granted
2759- *
2760- * @return true if updated, false if permission is required
2761- */
2762- public boolean setMyLocationEnabled () {
2763- boolean updated = false ;
2764- if (map != null && getActivity () != null && ContextCompat .checkSelfPermission (getActivity (), Manifest .permission .ACCESS_FINE_LOCATION ) == PackageManager .PERMISSION_GRANTED ) {
2765- map .setMyLocationEnabled (locationVisible );
2766- updated = true ;
2767- map .getUiSettings ().setMyLocationButtonEnabled (false );
2768- }
2769- return updated ;
2770- }
27712790
27722791 /**
27732792 * Handle map menu clicks
0 commit comments