diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2016-10-31 13:17:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-31 13:17:56 +0100 |
commit | ccc3964270e32145b050d97bf4c678941a5c6092 (patch) | |
tree | 7c917036dbe4c542d5bd42a6e997dcec78d6f8e7 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | |
parent | 38ee3408c224194054f7e4941a22dfd8b65f0d6f (diff) | |
download | qtlocation-mapboxgl-ccc3964270e32145b050d97bf4c678941a5c6092.tar.gz |
Android Nougat compatibility: onstart/onstop on MapView (#6830)
* introduce onstart/onstop on MapView
* update wear module
* update fragments
* update changeling
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 77 |
1 files changed, 55 insertions, 22 deletions
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 af0eacb378..ee2e32697e 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 @@ -160,6 +160,9 @@ public class MapView extends FrameLayout { private List<OnMapReadyCallback> onMapReadyCallbackList; private SnapshotRequest snapshotRequest; + private boolean onStartCalled; + private boolean onStopCalled; + @UiThread public MapView(@NonNull Context context) { super(context); @@ -573,16 +576,35 @@ public class MapView extends FrameLayout { } /** - * You must call this method from the parent's {@link Activity#onDestroy()} or {@link Fragment#onDestroy()}. + * You must call this method from the parent's {@link Activity#onStart()} or {@link Fragment#onStart()} */ @UiThread - public void onDestroy() { - destroyed = true; - nativeMapView.terminateContext(); - nativeMapView.terminateDisplay(); - nativeMapView.destroySurface(); - nativeMapView.destroy(); - nativeMapView = null; + public void onStart() { + onStartCalled = true; + + // Register for connectivity changes + connectivityReceiver = new ConnectivityReceiver(); + getContext().registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); + + nativeMapView.update(); + myLocationView.onStart(); + + // In case that no style was set or was loaded through MapboxMapOptions + if (!styleWasSet) { + setStyleUrl(styleUrl); + } + } + + /** + * You must call this method from the parent's {@link Activity#onResume()} or {@link Fragment#onResume()}. + */ + @UiThread + public void onResume() { + if (!onStartCalled) { + // TODO: 26/10/16, can be removed after 5.0.0 release + throw new IllegalStateException("MapView#onStart() was not called. " + + "You must call this method from the parent's {@link Activity#onStart()} or {@link Fragment#onStart()}."); + } } /** @@ -590,33 +612,44 @@ public class MapView extends FrameLayout { */ @UiThread public void onPause() { + // replaced by onStop in v5.0.0, keep around for future development + } + + /** + * You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}. + */ + @UiThread + public void onStop() { + onStopCalled = true; + // Unregister for connectivity changes if (connectivityReceiver != null) { getContext().unregisterReceiver(connectivityReceiver); connectivityReceiver = null; } - myLocationView.onPause(); + myLocationView.onStop(); } /** - * You must call this method from the parent's {@link Activity#onResume()} or {@link Fragment#onResume()}. + * You must call this method from the parent's {@link Activity#onDestroy()} or {@link Fragment#onDestroy()}. */ @UiThread - public void onResume() { - // Register for connectivity changes - connectivityReceiver = new ConnectivityReceiver(); - getContext().registerReceiver(connectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); - - nativeMapView.update(); - myLocationView.onResume(); - - // In case that no style was set or was loaded through MapboxMapOptions - if (!styleWasSet) { - setStyleUrl(styleUrl); + public void onDestroy() { + if (!onStopCalled) { + // TODO: 26/10/16, can be removed after 5.0.0 release + throw new IllegalStateException("MapView#onStop() was not called. " + + "You must call this method from the parent's {@link Activity#onStop()} or {@link Fragment#onStop()}."); } - } + destroyed = true; + nativeMapView.terminateContext(); + nativeMapView.terminateDisplay(); + nativeMapView.destroySurface(); + nativeMapView.destroy(); + nativeMapView = null; + } + void setFocalPoint(PointF focalPoint) { if (focalPoint == null) { // resetting focal point, |