From 94c5c2e203efb906e86b8d4d4f416647736b2d76 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 17 Feb 2016 08:54:22 +0100 Subject: [PATCH] [android] #2816 - make save instance state robuster + cleanup some old permission annotations --- .../mapboxsdk/constants/MapboxConstants.java | 1 + .../java/com/mapbox/mapboxsdk/maps/MapView.java | 15 ++++++--------- .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 1 - 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java index a68e89fb74a..f04087818b2 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java @@ -68,6 +68,7 @@ public class MapboxConstants { public static final String FRAG_ARG_MAPBOXMAPOPTIONS = "MapboxMapOptions"; // Save instance state keys + public static final String STATE_HAS_SAVED_STATE = "savedState"; public static final String STATE_CAMERA_POSITION = "cameraPosition"; public static final String STATE_ZOOM_ENABLED = "zoomEnabled"; public static final String STATE_SCROLL_ENABLED = "scrollEnabled"; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 772b62e990d..c2ccb1b243f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -309,7 +309,7 @@ private void initialize(@NonNull Context context, @Nullable AttributeSet attrs) */ @UiThread public void onCreate(@Nullable Bundle savedInstanceState) { - if (savedInstanceState != null) { + if (savedInstanceState != null && savedInstanceState.getBoolean(MapboxConstants.STATE_HAS_SAVED_STATE)) { // Get previous camera position CameraPosition cameraPosition = savedInstanceState.getParcelable(MapboxConstants.STATE_CAMERA_POSITION); @@ -363,7 +363,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) { // User did not accept location permissions } + //noinspection ResourceType setMyLocationTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE)); + //noinspection ResourceType setMyBearingTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE)); } else { // Force a check for Telemetry @@ -402,6 +404,7 @@ public void onMapChanged(@MapChange int change) { @UiThread public void onSaveInstanceState(@NonNull Bundle outState) { + outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true); outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, mMapboxMap.getCameraPosition()); outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, mMapboxMap.isDebugActive()); outState.putString(MapboxConstants.STATE_STYLE_URL, mMapboxMap.getStyleUrl()); @@ -1145,7 +1148,7 @@ int getTopOffsetPixelsForIcon(Icon icon) { /** * Sets the distance from the edges of the map view’s frame to the edges of the map * view’s logical viewport. - *

+ *

* When the value of this property is equal to {0,0,0,0}, viewport * properties such as `centerCoordinate` assume a viewport that matches the map * view’s frame. Otherwise, those properties are inset, excluding part of the @@ -1413,7 +1416,7 @@ void setBearing(float bearing) { /** * Sets Bearing in degrees - *

+ *

* NOTE: Used by UserLocationView * * @param bearing Bearing in degrees @@ -2369,7 +2372,6 @@ void setOnMyLocationChangeListener(@Nullable MapboxMap.OnMyLocationChangeListene * See {@link MyLocationTracking} for different values. * * @param myLocationTrackingMode The location tracking mode to be used. - * @throws SecurityException if no suitable permission is present * @see MyLocationTracking */ @UiThread @@ -2410,16 +2412,11 @@ int getMyLocationTrackingMode() { * See {@link MyBearingTracking} for different values. * * @param myBearingTrackingMode The bearing tracking mode to be used. - * @throws SecurityException if no suitable permission is present * @see MyBearingTracking */ @UiThread - @RequiresPermission(anyOf = { - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION}) void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) { if (myBearingTrackingMode != MyBearingTracking.NONE && !mMapboxMap.isMyLocationEnabled()) { - //noinspection ResourceType mMapboxMap.setMyLocationEnabled(true); } mUserLocationView.setMyBearingTrackingMode(myBearingTrackingMode); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index af3a535d7c7..8e8265e7607 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -1265,7 +1265,6 @@ public boolean isMyLocationEnabled() { * or @link android.Manifest.permission#ACCESS_FINE_LOCATION. * * @param enabled True to enable; false to disable. - * @throws SecurityException if no suitable permission is present */ @UiThread public void setMyLocationEnabled(boolean enabled) {