|
10 | 10 | import static fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailFragment.LAST_ZOOM;
|
11 | 11 |
|
12 | 12 | import android.content.Intent;
|
| 13 | +import android.content.pm.PackageManager; |
13 | 14 | import android.graphics.BitmapFactory;
|
14 | 15 | import android.location.Location;
|
15 | 16 | import android.os.Bundle;
|
|
21 | 22 | import android.widget.Button;
|
22 | 23 | import android.widget.ImageView;
|
23 | 24 | import android.widget.TextView;
|
24 |
| -import android.widget.Toast; |
25 | 25 | import androidx.annotation.NonNull;
|
26 | 26 | import androidx.annotation.Nullable;
|
27 | 27 | import androidx.appcompat.app.ActionBar;
|
|
56 | 56 | import fr.free.nrw.commons.MapStyle;
|
57 | 57 | import fr.free.nrw.commons.R;
|
58 | 58 | import fr.free.nrw.commons.Utils;
|
| 59 | +import fr.free.nrw.commons.filepicker.Constants; |
59 | 60 | import fr.free.nrw.commons.kvstore.JsonKvStore;
|
60 | 61 | import fr.free.nrw.commons.location.LocationPermissionsHelper;
|
61 | 62 | import fr.free.nrw.commons.location.LocationPermissionsHelper.Dialog;
|
|
72 | 73 | * Helps to pick location and return the result with an intent
|
73 | 74 | */
|
74 | 75 | public class LocationPickerActivity extends BaseActivity implements OnMapReadyCallback,
|
75 |
| - OnCameraMoveStartedListener, OnCameraIdleListener, Observer<CameraPosition> { |
| 76 | + OnCameraMoveStartedListener, OnCameraIdleListener, Observer<CameraPosition>, LocationPermissionCallback { |
76 | 77 |
|
77 | 78 | /**
|
78 | 79 | * DROPPED_MARKER_LAYER_ID : id for layer
|
@@ -474,30 +475,21 @@ private void getCenter() {
|
474 | 475 | R.string.upload_map_location_access
|
475 | 476 | );
|
476 | 477 | LocationPermissionsHelper locationPermissionsHelper = new LocationPermissionsHelper(
|
477 |
| - this, locationManager, new LocationPermissionCallback() { |
478 |
| - @Override |
479 |
| - public void onLocationPermissionDenied(String toastMessage) { |
480 |
| - // Do nothing |
481 |
| - } |
482 |
| - |
483 |
| - @Override |
484 |
| - public void onLocationPermissionGranted() { |
485 |
| - fr.free.nrw.commons.location.LatLng currLocation = locationManager.getLastLocation(); |
486 |
| - if (currLocation != null) { |
487 |
| - final CameraPosition position; |
488 |
| - position = new CameraPosition.Builder() |
489 |
| - .target(new com.mapbox.mapboxsdk.geometry.LatLng(currLocation.getLatitude(), |
490 |
| - currLocation.getLongitude(), 0)) // Sets the new camera position |
491 |
| - .zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level |
492 |
| - .build(); |
493 |
| - |
494 |
| - mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000); |
495 |
| - } |
496 |
| - } |
497 |
| - }); |
| 478 | + this, locationManager, this); |
498 | 479 | locationPermissionsHelper.handleLocationPermissions(locationAccessDialog, locationOffDialog);
|
499 | 480 | }
|
500 | 481 |
|
| 482 | + @Override |
| 483 | + public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions, |
| 484 | + @NonNull final int[] grantResults) { |
| 485 | + if (requestCode == Constants.RequestCodes.LOCATION && grantResults[0] == PackageManager.PERMISSION_GRANTED) { |
| 486 | + onLocationPermissionGranted(); |
| 487 | + } else { |
| 488 | + onLocationPermissionDenied(""); |
| 489 | + } |
| 490 | + super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
| 491 | + } |
| 492 | + |
501 | 493 | @Override
|
502 | 494 | protected void onStart() {
|
503 | 495 | super.onStart();
|
@@ -539,4 +531,24 @@ public void onLowMemory() {
|
539 | 531 | super.onLowMemory();
|
540 | 532 | mapView.onLowMemory();
|
541 | 533 | }
|
| 534 | + |
| 535 | + @Override |
| 536 | + public void onLocationPermissionDenied(String toastMessage) { |
| 537 | + //do nothing |
| 538 | + } |
| 539 | + |
| 540 | + @Override |
| 541 | + public void onLocationPermissionGranted() { |
| 542 | + fr.free.nrw.commons.location.LatLng currLocation = locationManager.getLastLocation(); |
| 543 | + if (currLocation != null) { |
| 544 | + final CameraPosition position; |
| 545 | + position = new CameraPosition.Builder() |
| 546 | + .target(new com.mapbox.mapboxsdk.geometry.LatLng(currLocation.getLatitude(), |
| 547 | + currLocation.getLongitude(), 0)) // Sets the new camera position |
| 548 | + .zoom(mapboxMap.getCameraPosition().zoom) // Same zoom level |
| 549 | + .build(); |
| 550 | + |
| 551 | + mapboxMap.animateCamera(CameraUpdateFactory.newCameraPosition(position), 1000); |
| 552 | + } |
| 553 | + } |
542 | 554 | }
|
0 commit comments