Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #2816 - make save instance state robuster + cleanup some ol…
Browse files Browse the repository at this point in the history
…d permission annotations
  • Loading branch information
tobrun committed Feb 17, 2016
1 parent 44ec2ad commit 94c5c2e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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.
* <p/>
* <p>
* 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
Expand Down Expand Up @@ -1413,7 +1416,7 @@ void setBearing(float bearing) {

/**
* Sets Bearing in degrees
* <p/>
* <p>
* NOTE: Used by UserLocationView
*
* @param bearing Bearing in degrees
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 94c5c2e

Please sign in to comment.