diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.kt index 82169c59e..bc0f45654 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.kt @@ -22,8 +22,8 @@ import java.util.ArrayList * */ class PolygonActivity : AppCompatActivity(), OnMapReadyCallback { - private var mapView: MapView? = null - private var mapboxMap: MapboxMap? = null + private lateinit var mapView: MapView + private lateinit var mapboxMap: MapboxMap private var polygon: Polygon? = null private var fullAlpha = true private var polygonIsVisible = true @@ -47,9 +47,9 @@ class PolygonActivity : AppCompatActivity(), OnMapReadyCallback { // create map mapView = MapView(this, options) - mapView!!.id = R.id.mapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync(this) + mapView.id = R.id.mapView + mapView.onCreate(savedInstanceState) + mapView.getMapAsync(this) setContentView(mapView) } @@ -63,7 +63,7 @@ class PolygonActivity : AppCompatActivity(), OnMapReadyCallback { Toast.LENGTH_SHORT ).show() } - polygon = mapboxMap!!.addPolygon( + polygon = mapboxMap.addPolygon( PolygonOptions() .addAll(Config.STAR_SHAPE_POINTS) .fillColor(Config.BLUE_COLOR) @@ -72,37 +72,37 @@ class PolygonActivity : AppCompatActivity(), OnMapReadyCallback { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimationTypeActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimationTypeActivity.kt index 7f400c882..ca5774b84 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimationTypeActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraAnimationTypeActivity.kt @@ -50,7 +50,7 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { private var cameraState = false private val cameraIdleListener = OnCameraIdleListener { if (mapboxMap != null) { - Timber.w(mapboxMap!!.cameraPosition.toString()) + Timber.w(mapboxMap.cameraPosition.toString()) } } @@ -64,10 +64,10 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { override fun onMapReady(map: MapboxMap) { mapboxMap = map - mapboxMap!!.setStyle(Style.Builder().fromUri(Style.getPredefinedStyle("Streets"))) - mapboxMap!!.uiSettings.isAttributionEnabled = false - mapboxMap!!.uiSettings.isLogoEnabled = false - mapboxMap!!.addOnCameraIdleListener(cameraIdleListener) + mapboxMap.setStyle(Style.Builder().fromUri(Style.getPredefinedStyle("Streets"))) + mapboxMap.uiSettings.isAttributionEnabled = false + mapboxMap.uiSettings.isLogoEnabled = false + mapboxMap.addOnCameraIdleListener(cameraIdleListener) // handle move button clicks val moveButton = findViewById(R.id.cameraMoveButton) @@ -79,7 +79,7 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { .tilt(30.0) .tilt(0.0) .build() - mapboxMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)) + mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)) } // handle ease button clicks @@ -92,7 +92,7 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { .bearing(180.0) .tilt(30.0) .build() - mapboxMap!!.easeCamera( + mapboxMap.easeCamera( CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback @@ -104,7 +104,7 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { animateButton?.setOnClickListener { view: View? -> val cameraPosition = CameraPosition.Builder().target(nextLatLng).bearing(270.0).tilt(20.0).build() - mapboxMap!!.animateCamera( + mapboxMap.animateCamera( CameraUpdateFactory.newCameraPosition(cameraPosition), 7500, callback @@ -120,40 +120,40 @@ class CameraAnimationTypeActivity : AppCompatActivity(), OnMapReadyCallback { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() if (mapboxMap != null) { - mapboxMap!!.removeOnCameraIdleListener(cameraIdleListener) + mapboxMap.removeOnCameraIdleListener(cameraIdleListener) } - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.kt index 331d53432..58a23a867 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/CameraPositionActivity.kt @@ -204,7 +204,7 @@ class CameraPositionActivity : FragmentActivity(), OnMapReadyCallback, View.OnCl val cameraPosition = CameraPosition.Builder().target(LatLng(latitude, longitude)).zoom(zoom).bearing(bearing).tilt(tilt).build() - mapboxMap!!.animateCamera( + mapboxMap?.animateCamera( CameraUpdateFactory.newCameraPosition(cameraPosition), 5000, object : CancelableCallback { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/GestureDetectorActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/GestureDetectorActivity.kt index d659fdf58..37eea9c3c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/GestureDetectorActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/GestureDetectorActivity.kt @@ -57,52 +57,52 @@ class GestureDetectorActivity : AppCompatActivity() { override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() gestureAlertsAdapter!!.cancelUpdates() - mapView!!.onPause() + mapView.onPause() } override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } private fun initializeMap() { - gesturesManager = mapboxMap!!.gesturesManager + gesturesManager = mapboxMap.gesturesManager val layoutParams = recyclerView!!.layoutParams as RelativeLayout.LayoutParams - layoutParams.height = (mapView!!.height / 1.75).toInt() - layoutParams.width = mapView!!.width / 3 + layoutParams.height = (mapView.height / 1.75).toInt() + layoutParams.width = mapView.width / 3 recyclerView!!.layoutParams = layoutParams attachListeners() - fixedFocalPointEnabled(mapboxMap!!.uiSettings.focalPoint != null) + fixedFocalPointEnabled(mapboxMap.uiSettings.focalPoint != null) } fun attachListeners() { - mapboxMap!!.addOnMoveListener( + mapboxMap.addOnMoveListener( object : OnMoveListener { override fun onMoveBegin(detector: MoveGestureDetector) { gestureAlertsAdapter!!.addAlert( @@ -124,7 +124,7 @@ class GestureDetectorActivity : AppCompatActivity() { } } ) - mapboxMap!!.addOnRotateListener( + mapboxMap.addOnRotateListener( object : OnRotateListener { override fun onRotateBegin(detector: RotateGestureDetector) { gestureAlertsAdapter!!.addAlert( @@ -146,7 +146,7 @@ class GestureDetectorActivity : AppCompatActivity() { } } ) - mapboxMap!!.addOnScaleListener( + mapboxMap.addOnScaleListener( object : OnScaleListener { override fun onScaleBegin(detector: StandardScaleGestureDetector) { gestureAlertsAdapter!!.addAlert( @@ -194,7 +194,7 @@ class GestureDetectorActivity : AppCompatActivity() { } } ) - mapboxMap!!.addOnShoveListener( + mapboxMap.addOnShoveListener( object : OnShoveListener { override fun onShoveBegin(detector: ShoveGestureDetector) { gestureAlertsAdapter!!.addAlert( @@ -223,7 +223,7 @@ class GestureDetectorActivity : AppCompatActivity() { } override fun onOptionsItemSelected(item: MenuItem): Boolean { - val uiSettings = mapboxMap!!.uiSettings + val uiSettings = mapboxMap.uiSettings when (item.itemId) { R.id.menu_gesture_focus_point -> { fixedFocalPointEnabled(focalPointLatLng == null) @@ -274,8 +274,8 @@ class GestureDetectorActivity : AppCompatActivity() { private fun fixedFocalPointEnabled(enabled: Boolean) { if (enabled) { focalPointLatLng = LatLng(51.50325, -0.12968) - marker = mapboxMap!!.addMarker(MarkerOptions().position(focalPointLatLng)) - mapboxMap!!.easeCamera( + marker = mapboxMap.addMarker(MarkerOptions().position(focalPointLatLng)) + mapboxMap.easeCamera( CameraUpdateFactory.newLatLngZoom(focalPointLatLng!!, 16.0), object : CancelableCallback { override fun onCancel() { @@ -289,18 +289,18 @@ class GestureDetectorActivity : AppCompatActivity() { ) } else { if (marker != null) { - mapboxMap!!.removeMarker(marker!!) + mapboxMap.removeMarker(marker!!) marker = null } focalPointLatLng = null - mapboxMap!!.uiSettings.focalPoint = null + mapboxMap.uiSettings.focalPoint = null } } private fun recalculateFocalPoint() { if (focalPointLatLng != null) { - mapboxMap!!.uiSettings.focalPoint = - mapboxMap!!.projection.toScreenLocation(focalPointLatLng!!) + mapboxMap.uiSettings.focalPoint = + mapboxMap.projection.toScreenLocation(focalPointLatLng!!) } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ManualZoomActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ManualZoomActivity.kt index 5c7a7d557..767a3d7cf 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ManualZoomActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ManualZoomActivity.kt @@ -24,13 +24,13 @@ class ManualZoomActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_manual_zoom) mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> this@ManualZoomActivity.mapboxMap = mapboxMap mapboxMap.setStyle( Style.Builder().fromUri(Style.getPredefinedStyle("Satellite Hybrid")) ) - val uiSettings = this@ManualZoomActivity.mapboxMap!!.uiSettings + val uiSettings = this@ManualZoomActivity.mapboxMap.uiSettings uiSettings.setAllGesturesEnabled(false) } } @@ -43,24 +43,24 @@ class ManualZoomActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { return when (item.itemId) { R.id.action_zoom_in -> { - mapboxMap!!.animateCamera(CameraUpdateFactory.zoomIn()) + mapboxMap.animateCamera(CameraUpdateFactory.zoomIn()) true } R.id.action_zoom_out -> { - mapboxMap!!.animateCamera(CameraUpdateFactory.zoomOut()) + mapboxMap.animateCamera(CameraUpdateFactory.zoomOut()) true } R.id.action_zoom_by -> { - mapboxMap!!.animateCamera(CameraUpdateFactory.zoomBy(2.0)) + mapboxMap.animateCamera(CameraUpdateFactory.zoomBy(2.0)) true } R.id.action_zoom_to -> { - mapboxMap!!.animateCamera(CameraUpdateFactory.zoomTo(2.0)) + mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(2.0)) true } R.id.action_zoom_to_point -> { val view = window.decorView - mapboxMap!!.animateCamera( + mapboxMap.animateCamera( CameraUpdateFactory.zoomBy( 1.0, Point(view.measuredWidth / 4, view.measuredHeight / 4) @@ -74,36 +74,36 @@ class ManualZoomActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/MaxMinZoomActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/MaxMinZoomActivity.kt index 7c0e1bc1f..db1167655 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/MaxMinZoomActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/MaxMinZoomActivity.kt @@ -17,7 +17,7 @@ class MaxMinZoomActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mapboxMap: MapboxMap private val clickListener = OnMapClickListener { if (mapboxMap != null) { - mapboxMap!!.setStyle(Style.Builder().fromUri(Style.getPredefinedStyle("Outdoor"))) + mapboxMap.setStyle(Style.Builder().fromUri(Style.getPredefinedStyle("Outdoor"))) } true } @@ -35,47 +35,47 @@ class MaxMinZoomActivity : AppCompatActivity(), OnMapReadyCallback { override fun onMapReady(map: MapboxMap) { mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Streets")) - mapboxMap!!.setMinZoomPreference(3.0) - mapboxMap!!.setMaxZoomPreference(5.0) - mapboxMap!!.addOnMapClickListener(clickListener) + mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) + mapboxMap.setMinZoomPreference(3.0) + mapboxMap.setMaxZoomPreference(5.0) + mapboxMap.addOnMapClickListener(clickListener) } override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() if (mapboxMap != null) { - mapboxMap!!.removeOnMapClickListener(clickListener) + mapboxMap.removeOnMapClickListener(clickListener) } - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ScrollByActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ScrollByActivity.kt index 7a06bfa6f..6a3cb969e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ScrollByActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/camera/ScrollByActivity.kt @@ -53,14 +53,14 @@ class ScrollByActivity : AppCompatActivity(), OnMapReadyCallback { override fun onMapReady(map: MapboxMap) { mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Pastel")) - val uiSettings = mapboxMap!!.uiSettings + mapboxMap.setStyle(Style.getPredefinedStyle("Pastel")) + val uiSettings = mapboxMap.uiSettings uiSettings.isLogoEnabled = false uiSettings.isAttributionEnabled = false val fab = findViewById(R.id.fab) fab.setColorFilter(ContextCompat.getColor(this@ScrollByActivity, R.color.primary)) fab.setOnClickListener { view: View? -> - mapboxMap!!.scrollBy( + mapboxMap.scrollBy( (seekBarX!!.progress * MULTIPLIER_PER_PIXEL).toFloat(), (seekBarY!!.progress * MULTIPLIER_PER_PIXEL).toFloat() ) @@ -69,37 +69,37 @@ class ScrollByActivity : AppCompatActivity(), OnMapReadyCallback { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.kt index 090fcadca..5b8d813fc 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/customlayer/CustomLayerActivity.kt @@ -37,13 +37,13 @@ class CustomLayerActivity : AppCompatActivity() { mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> mapboxMap = map!! - mapboxMap!!.moveCamera( + mapboxMap.moveCamera( CameraUpdateFactory.newLatLngZoom( LatLng(39.91448, -243.60947), 10.0 ) ) - mapboxMap!!.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? -> initFab() } + mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? -> initFab() } } ) } @@ -61,7 +61,7 @@ class CustomLayerActivity : AppCompatActivity() { } private fun swapCustomLayer() { - val style = mapboxMap!!.style + val style = mapboxMap.style if (customLayer != null) { style!!.removeLayer(customLayer!!) customLayer = null @@ -78,43 +78,43 @@ class CustomLayerActivity : AppCompatActivity() { private fun updateLayer() { if (mapboxMap != null) { - mapboxMap!!.triggerRepaint() + mapboxMap.triggerRepaint() } } override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.kt index 0df2e7236..c195b2004 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxCountActivity.kt @@ -19,8 +19,8 @@ import timber.log.Timber * Test activity showcasing using the query rendered features API to count features in a rectangle. */ class QueryRenderedFeaturesBoxCountActivity : AppCompatActivity() { - var mapView: MapView? = null - var mapboxMap: MapboxMap? = null + lateinit var mapView: MapView + lateinit var mapboxMap: MapboxMap private set override fun onCreate(savedInstanceState: Bundle?) { @@ -30,14 +30,14 @@ class QueryRenderedFeaturesBoxCountActivity : AppCompatActivity() { // Initialize map as normal mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> this@QueryRenderedFeaturesBoxCountActivity.mapboxMap = mapboxMap mapboxMap.setStyle(Style.Builder().fromUri(Style.getPredefinedStyle("Streets"))) selectionBox.setOnClickListener { view: View? -> // Query - val top = selectionBox.top - mapView!!.top - val left = selectionBox.left - mapView!!.left + val top = selectionBox.top - mapView.top + val left = selectionBox.left - mapView.left val box = RectF( left.toFloat(), top.toFloat(), @@ -88,41 +88,41 @@ class QueryRenderedFeaturesBoxCountActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() if (mapboxMap != null) { // Regression test for #14394 - mapboxMap!!.queryRenderedFeatures(PointF(0F, 0F)) + mapboxMap.queryRenderedFeatures(PointF(0F, 0F)) } } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.kt index 551c8896f..a6500def9 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxHighlightActivity.kt @@ -22,8 +22,8 @@ import timber.log.Timber * Demo's query rendered features */ class QueryRenderedFeaturesBoxHighlightActivity : AppCompatActivity() { - var mapView: MapView? = null - var mapboxMap: MapboxMap? = null + lateinit var mapView: MapView + lateinit var mapboxMap: MapboxMap private set override fun onCreate(savedInstanceState: Bundle?) { @@ -33,8 +33,8 @@ class QueryRenderedFeaturesBoxHighlightActivity : AppCompatActivity() { // Initialize map as normal mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> this@QueryRenderedFeaturesBoxHighlightActivity.mapboxMap = mapboxMap // Add layer / source @@ -43,8 +43,8 @@ class QueryRenderedFeaturesBoxHighlightActivity : AppCompatActivity() { .withProperties(PropertyFactory.fillColor(Color.RED)) selectionBox.setOnClickListener { view: View? -> // Query - val top = selectionBox.top - mapView!!.top - val left = selectionBox.left - mapView!!.left + val top = selectionBox.top - mapView.top + val left = selectionBox.left - mapView.left val box = RectF( left.toFloat(), top.toFloat(), @@ -79,36 +79,36 @@ class QueryRenderedFeaturesBoxHighlightActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.kt index 4b4ecbde1..69e2da923 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesBoxSymbolCountActivity.kt @@ -23,8 +23,8 @@ import java.io.IOException * Test activity showcasing using the query rendered features API to count Symbols in a rectangle. */ class QueryRenderedFeaturesBoxSymbolCountActivity : AppCompatActivity() { - var mapView: MapView? = null - var mapboxMap: MapboxMap? = null + lateinit var mapView: MapView + lateinit var mapboxMap: MapboxMap private set private lateinit var toast: Toast override fun onCreate(savedInstanceState: Bundle?) { @@ -34,12 +34,12 @@ class QueryRenderedFeaturesBoxSymbolCountActivity : AppCompatActivity() { // Initialize map as normal mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> this@QueryRenderedFeaturesBoxSymbolCountActivity.mapboxMap = mapboxMap try { val testPoints = ResourceUtils.readRawResource( - mapView!!.context, + mapView.context, R.raw.test_points_utrecht ) val markerImage = @@ -68,8 +68,8 @@ class QueryRenderedFeaturesBoxSymbolCountActivity : AppCompatActivity() { } selectionBox.setOnClickListener { view: View? -> // Query - val top = selectionBox.top - mapView!!.top - val left = selectionBox.left - mapView!!.left + val top = selectionBox.top - mapView.top + val left = selectionBox.left - mapView.left val box = RectF( left.toFloat(), top.toFloat(), @@ -95,36 +95,36 @@ class QueryRenderedFeaturesBoxSymbolCountActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.kt index a322ba88b..4c194aab9 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QueryRenderedFeaturesPropertiesActivity.kt @@ -23,13 +23,13 @@ import timber.log.Timber * Test activity showcasing using the query rendered features API to query feature properties on Map click. */ class QueryRenderedFeaturesPropertiesActivity : AppCompatActivity() { - var mapView: MapView? = null - var mapboxMap: MapboxMap? = null + lateinit var mapView: MapView + lateinit var mapboxMap: MapboxMap private set private var marker: Marker? = null private val mapClickListener = OnMapClickListener { point -> val density = resources.displayMetrics.density - val pixel = mapboxMap!!.projection.toScreenLocation(point) + val pixel = mapboxMap.projection.toScreenLocation(point) Timber.i( "Requesting features for %sx%s (%sx%s adjusted for density)", pixel.x, @@ -37,19 +37,19 @@ class QueryRenderedFeaturesPropertiesActivity : AppCompatActivity() { pixel.x / density, pixel.y / density ) - val features = mapboxMap!!.queryRenderedFeatures(pixel) + val features = mapboxMap.queryRenderedFeatures(pixel) // Debug output debugOutput(features) // Remove any previous markers if (marker != null) { - mapboxMap!!.removeMarker(marker!!) + mapboxMap.removeMarker(marker!!) } // Add a marker on the clicked point - marker = mapboxMap!!.addMarker(CustomMarkerOptions().position(point)!!.features(features)) - mapboxMap!!.selectMarker(marker!!) + marker = mapboxMap.addMarker(CustomMarkerOptions().position(point)!!.features(features)) + mapboxMap.selectMarker(marker!!) true } @@ -59,8 +59,8 @@ class QueryRenderedFeaturesPropertiesActivity : AppCompatActivity() { // Initialize map as normal mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? -> this@QueryRenderedFeaturesPropertiesActivity.mapboxMap = mapboxMap @@ -135,40 +135,40 @@ class QueryRenderedFeaturesPropertiesActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() if (mapboxMap != null) { - mapboxMap!!.removeOnMapClickListener(mapClickListener) + mapboxMap.removeOnMapClickListener(mapClickListener) } - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } private class CustomMarker internal constructor( diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QuerySourceFeaturesActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QuerySourceFeaturesActivity.kt index e6e79013f..ffd9eac04 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QuerySourceFeaturesActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/feature/QuerySourceFeaturesActivity.kt @@ -23,19 +23,21 @@ import com.mapbox.mapboxsdk.testapp.R * Test activity showcasing using the query source features API to query feature counts */ class QuerySourceFeaturesActivity : AppCompatActivity() { - var mapView: MapView? = null - private var mapboxMap: MapboxMap? = null + lateinit var mapView: MapView + private lateinit var mapboxMap: MapboxMap override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_query_source_features) // Initialize map as normal mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { map: MapboxMap? -> - mapboxMap = map - mapboxMap!!.getStyle { style: Style -> initStyle(style) } - mapboxMap!!.setStyle(Style.getPredefinedStyle("Streets")) + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { map: MapboxMap? -> + if (map != null) { + mapboxMap = map + } + mapboxMap.getStyle { style: Style -> initStyle(style) } + mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) } } @@ -61,7 +63,7 @@ class QuerySourceFeaturesActivity : AppCompatActivity() { style.addLayer(layer) // Add a click listener - mapboxMap!!.addOnMapClickListener { point: LatLng? -> + mapboxMap.addOnMapClickListener { point: LatLng? -> // Query val features = source.querySourceFeatures( Expression.eq( @@ -95,36 +97,36 @@ class QuerySourceFeaturesActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.kt index 5b040ddd4..232cca8a8 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.kt @@ -22,8 +22,8 @@ class MapFragmentActivity : OnMapViewReadyCallback, OnMapReadyCallback, OnDidFinishRenderingFrameListener { - private var mapboxMap: MapboxMap? = null - private var mapView: MapView? = null + private lateinit var mapboxMap: MapboxMap + private lateinit var mapView: MapView private var initialCameraAnimation = true override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -62,24 +62,24 @@ class MapFragmentActivity : override fun onMapViewReady(map: MapView) { mapView = map - mapView!!.addOnDidFinishRenderingFrameListener(this) + mapView.addOnDidFinishRenderingFrameListener(this) } override fun onMapReady(map: MapboxMap) { mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Outdoor")) + mapboxMap.setStyle(Style.getPredefinedStyle("Outdoor")) } override fun onDestroy() { super.onDestroy() if (mapView != null) { - mapView!!.removeOnDidFinishRenderingFrameListener(this) + mapView.removeOnDidFinishRenderingFrameListener(this) } } override fun onDidFinishRenderingFrame(fully: Boolean) { if (initialCameraAnimation && fully && mapboxMap != null) { - mapboxMap!!.animateCamera( + mapboxMap.animateCamera( CameraUpdateFactory.newCameraPosition(CameraPosition.Builder().tilt(45.0).build()), 5000 ) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.kt index 4cfd44e40..71c3f0e6c 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.kt @@ -22,8 +22,8 @@ class SupportMapFragmentActivity : OnMapViewReadyCallback, OnMapReadyCallback, OnDidFinishRenderingFrameListener { - private var mapboxMap: MapboxMap? = null - private var mapView: MapView? = null + private lateinit var mapboxMap: MapboxMap + private lateinit var mapView: MapView private var initialCameraAnimation = true override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -62,22 +62,22 @@ class SupportMapFragmentActivity : override fun onMapViewReady(map: MapView) { mapView = map - mapView!!.addOnDidFinishRenderingFrameListener(this) + mapView.addOnDidFinishRenderingFrameListener(this) } override fun onMapReady(map: MapboxMap) { mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Satellite Hybrid")) + mapboxMap.setStyle(Style.getPredefinedStyle("Satellite Hybrid")) } override fun onDestroy() { super.onDestroy() - mapView!!.removeOnDidFinishRenderingFrameListener(this) + mapView.removeOnDidFinishRenderingFrameListener(this) } override fun onDidFinishRenderingFrame(fully: Boolean) { if (initialCameraAnimation && fully && mapboxMap != null) { - mapboxMap!!.animateCamera( + mapboxMap.animateCamera( CameraUpdateFactory.newCameraPosition(CameraPosition.Builder().tilt(45.0).build()), 5000 ) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.kt index c09dae976..9569dfdcd 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.kt @@ -25,8 +25,8 @@ class PrintActivity : AppCompatActivity(), MapboxMap.SnapshotReadyCallback { mapView.getMapAsync(OnMapReadyCallback { mapboxMap: MapboxMap -> initMap(mapboxMap) }) val fab = findViewById(R.id.fab) fab?.setOnClickListener { view: View? -> - if (mapboxMap != null && mapboxMap!!.style != null) { - mapboxMap!!.snapshot(this@PrintActivity) + if (mapboxMap != null && mapboxMap.style != null) { + mapboxMap.snapshot(this@PrintActivity) } } } @@ -44,36 +44,36 @@ class PrintActivity : AppCompatActivity(), MapboxMap.SnapshotReadyCallback { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.kt index 1b7d474d6..68234482d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.kt @@ -64,17 +64,17 @@ class DynamicInfoWindowAdapterActivity : AppCompatActivity(), OnMapReadyCallback addCustomInfoWindowAdapter(mapboxMap!!) // Keep info windows open on click - mapboxMap!!.uiSettings.isDeselectMarkersOnTap = false + mapboxMap.uiSettings.isDeselectMarkersOnTap = false // Add a marker marker = addMarker(mapboxMap!!) - mapboxMap!!.selectMarker(marker!!) + mapboxMap.selectMarker(marker!!) // On map click, change the info window contents - mapboxMap!!.addOnMapClickListener(mapClickListener) + mapboxMap.addOnMapClickListener(mapClickListener) // Focus on Paris - mapboxMap!!.animateCamera(CameraUpdateFactory.newLatLng(PARIS)) + mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(PARIS)) } private fun addMarker(mapboxMap: MapboxMap): Marker { @@ -105,40 +105,40 @@ class DynamicInfoWindowAdapterActivity : AppCompatActivity(), OnMapReadyCallback override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() if (mapboxMap != null) { - mapboxMap!!.removeOnMapClickListener(mapClickListener) + mapboxMap.removeOnMapClickListener(mapClickListener) } - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.kt index c53f18632..3a2f7e169 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.kt @@ -33,18 +33,18 @@ class InfoWindowActivity : OnInfoWindowCloseListener, OnInfoWindowClickListener, OnInfoWindowLongClickListener { - private var mapboxMap: MapboxMap? = null - private var mapView: MapView? = null + private lateinit var mapboxMap: MapboxMap + private lateinit var mapView: MapView private var customMarker: Marker? = null private val mapLongClickListener = OnMapLongClickListener { point -> if (customMarker != null) { // Remove previous added marker - mapboxMap!!.removeAnnotation(customMarker!!) + mapboxMap.removeAnnotation(customMarker!!) customMarker = null } // Add marker on long click location with default marker image - customMarker = mapboxMap!!.addMarker( + customMarker = mapboxMap.addMarker( MarkerOptions() .title("Custom Marker") .snippet( @@ -60,8 +60,8 @@ class InfoWindowActivity : super.onCreate(savedInstanceState) setContentView(R.layout.activity_infowindow) mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync(this) + mapView.onCreate(savedInstanceState) + mapView.getMapAsync(this) } override fun onMapReady(mapboxMap: MapboxMap) { @@ -73,25 +73,25 @@ class InfoWindowActivity : } private fun addMarkers() { - mapboxMap!!.addMarker( + mapboxMap.addMarker( MarkerOptions() .title("Intersection") .snippet("H St NW with 15th St NW") .position(LatLng(38.9002073, -77.03364419)) ) - mapboxMap!!.addMarker( + mapboxMap.addMarker( MarkerOptions().title("Intersection") .snippet("E St NW with 17th St NW") .position(LatLng(38.8954236, -77.0394623)) ) - mapboxMap!!.addMarker( + mapboxMap.addMarker( MarkerOptions().title("The Ellipse").position(LatLng(38.89393, -77.03654)) ) - mapboxMap!!.addMarker(MarkerOptions().position(LatLng(38.89596, -77.03434))) - mapboxMap!!.addMarker( + mapboxMap.addMarker(MarkerOptions().position(LatLng(38.89596, -77.03434))) + mapboxMap.addMarker( MarkerOptions().snippet("Lafayette Square").position(LatLng(38.89949, -77.03656)) ) - val marker = mapboxMap!!.addMarker( + val marker = mapboxMap.addMarker( MarkerOptions() .title("White House") .snippet( @@ -103,23 +103,23 @@ class InfoWindowActivity : ) // open InfoWindow at startup - mapboxMap!!.selectMarker(marker) + mapboxMap.selectMarker(marker) } private fun addInfoWindowListeners() { - mapboxMap!!.onInfoWindowCloseListener = this - mapboxMap!!.addOnMapLongClickListener(mapLongClickListener) - mapboxMap!!.onInfoWindowClickListener = this - mapboxMap!!.onInfoWindowLongClickListener = this + mapboxMap.onInfoWindowCloseListener = this + mapboxMap.addOnMapLongClickListener(mapLongClickListener) + mapboxMap.onInfoWindowClickListener = this + mapboxMap.onInfoWindowLongClickListener = this } private fun toggleConcurrentInfoWindow(allowConcurrentInfoWindow: Boolean) { - mapboxMap!!.deselectMarkers() - mapboxMap!!.isAllowConcurrentMultipleOpenInfoWindows = allowConcurrentInfoWindow + mapboxMap.deselectMarkers() + mapboxMap.isAllowConcurrentMultipleOpenInfoWindows = allowConcurrentInfoWindow } private fun toggleDeselectMarkersOnTap(deselectMarkersOnTap: Boolean) { - mapboxMap!!.uiSettings.isDeselectMarkersOnTap = deselectMarkersOnTap + mapboxMap.uiSettings.isDeselectMarkersOnTap = deselectMarkersOnTap } override fun onInfoWindowClick(marker: Marker): Boolean { @@ -138,40 +138,40 @@ class InfoWindowActivity : override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() if (mapboxMap != null) { - mapboxMap!!.removeOnMapLongClickListener(mapLongClickListener) + mapboxMap.removeOnMapLongClickListener(mapLongClickListener) } - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.kt index 48556d9ad..bc1edc028 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.kt @@ -40,10 +40,10 @@ class InfoWindowAdapterActivity : AppCompatActivity() { } private fun addMarkers() { - mapboxMap!!.addMarker(generateCityStateMarker("Andorra", 42.505777, 1.52529, "#F44336")) - mapboxMap!!.addMarker(generateCityStateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5")) - mapboxMap!!.addMarker(generateCityStateMarker("Monaco", 43.738418, 7.424616, "#673AB7")) - mapboxMap!!.addMarker( + mapboxMap.addMarker(generateCityStateMarker("Andorra", 42.505777, 1.52529, "#F44336")) + mapboxMap.addMarker(generateCityStateMarker("Luxembourg", 49.815273, 6.129583, "#3F51B5")) + mapboxMap.addMarker(generateCityStateMarker("Monaco", 43.738418, 7.424616, "#673AB7")) + mapboxMap.addMarker( generateCityStateMarker( "Vatican City", 41.902916, @@ -51,7 +51,7 @@ class InfoWindowAdapterActivity : AppCompatActivity() { "#009688" ) ) - mapboxMap!!.addMarker( + mapboxMap.addMarker( generateCityStateMarker( "San Marino", 43.942360, @@ -59,7 +59,7 @@ class InfoWindowAdapterActivity : AppCompatActivity() { "#795548" ) ) - mapboxMap!!.addMarker( + mapboxMap.addMarker( generateCityStateMarker( "Liechtenstein", 47.166000, @@ -86,7 +86,7 @@ class InfoWindowAdapterActivity : AppCompatActivity() { } private fun addCustomInfoWindowAdapter() { - mapboxMap!!.infoWindowAdapter = object : InfoWindowAdapter { + mapboxMap.infoWindowAdapter = object : InfoWindowAdapter { private val tenDp = resources.getDimension(R.dimen.attr_margin).toInt() override fun getInfoWindow(marker: Marker): View? { val textView = TextView(this@InfoWindowAdapterActivity) @@ -103,36 +103,36 @@ class InfoWindowAdapterActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/BasicLocationPulsingCircleActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/BasicLocationPulsingCircleActivity.kt index fd1c143fe..7b1d9b365 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/BasicLocationPulsingCircleActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/BasicLocationPulsingCircleActivity.kt @@ -29,7 +29,7 @@ class BasicLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyCallba private lateinit var mapView: MapView private var permissionsManager: PermissionsManager? = null private var locationComponent: LocationComponent? = null - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_location_layer_basic_pulsing_circle) @@ -119,12 +119,12 @@ class BasicLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyCallba } private fun loadNewStyle() { - mapboxMap!!.setStyle(Style.Builder().fromUri(Utils.nextStyle())) + mapboxMap.setStyle(Style.Builder().fromUri(Utils.nextStyle())) } private fun checkPermissions() { if (PermissionsManager.areLocationPermissionsGranted(this)) { - mapView!!.getMapAsync(this) + mapView.getMapAsync(this) } else { permissionsManager = PermissionsManager(object : PermissionsListener { override fun onExplanationNeeded(permissionsToExplain: List) { @@ -137,7 +137,7 @@ class BasicLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyCallba override fun onPermissionResult(granted: Boolean) { if (granted) { - mapView!!.getMapAsync(this@BasicLocationPulsingCircleActivity) + mapView.getMapAsync(this@BasicLocationPulsingCircleActivity) } else { finish() } @@ -158,28 +158,28 @@ class BasicLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyCallba override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } @SuppressLint("MissingPermission") override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) if (locationComponent != null) { outState.putParcelable(SAVED_STATE_LOCATION, locationComponent!!.lastKnownLocation) } @@ -187,12 +187,12 @@ class BasicLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyCallba override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/CustomizedLocationPulsingCircleActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/CustomizedLocationPulsingCircleActivity.kt index 14e7ace69..4380d93be 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/CustomizedLocationPulsingCircleActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/CustomizedLocationPulsingCircleActivity.kt @@ -38,7 +38,7 @@ class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyC private lateinit var pulsingCircleColorButton: Button private var permissionsManager: PermissionsManager? = null private var locationComponent: LocationComponent? = null - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var currentPulseDuration = 0f //endregion @@ -124,7 +124,7 @@ class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyC newPulsingDuration: Float, newPulsingColor: Int ) { - mapboxMap!!.getStyle { style: Style? -> + mapboxMap.getStyle { style: Style? -> locationComponent!!.applyStyle( buildLocationComponentOptions( newPulsingColor, @@ -197,12 +197,12 @@ class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyC } private fun loadNewStyle() { - mapboxMap!!.setStyle(Style.Builder().fromUri(Utils.nextStyle())) + mapboxMap.setStyle(Style.Builder().fromUri(Utils.nextStyle())) } private fun checkPermissions() { if (PermissionsManager.areLocationPermissionsGranted(this)) { - mapView!!.getMapAsync(this) + mapView.getMapAsync(this) } else { permissionsManager = PermissionsManager(object : PermissionsListener { override fun onExplanationNeeded(permissionsToExplain: List) { @@ -215,7 +215,7 @@ class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyC override fun onPermissionResult(granted: Boolean) { if (granted) { - mapView!!.getMapAsync(this@CustomizedLocationPulsingCircleActivity) + mapView.getMapAsync(this@CustomizedLocationPulsingCircleActivity) } else { finish() } @@ -329,28 +329,28 @@ class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyC override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } @SuppressLint("MissingPermission") override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) if (locationComponent != null) { outState.putParcelable(SAVED_STATE_LOCATION, locationComponent!!.lastKnownLocation) outState.putInt(SAVED_STATE_LOCATION_CIRCLE_PULSE_COLOR, LOCATION_CIRCLE_PULSE_COLOR) @@ -363,12 +363,12 @@ class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyC override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.kt index fd7afdde1..58a7881c5 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.kt @@ -19,7 +19,7 @@ import com.mapbox.mapboxsdk.testapp.R class LocationComponentActivationActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var permissionsManager: PermissionsManager? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -68,7 +68,7 @@ class LocationComponentActivationActivity : AppCompatActivity(), OnMapReadyCallb @SuppressLint("MissingPermission") private fun activateLocationComponent(style: Style) { - val locationComponent = mapboxMap!!.locationComponent + val locationComponent = mapboxMap.locationComponent val locationComponentOptions = LocationComponentOptions.builder(this) .elevation(5f) .accuracyAlpha(.6f) @@ -88,36 +88,36 @@ class LocationComponentActivationActivity : AppCompatActivity(), OnMapReadyCallb override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.kt index eb263d0ac..f7dfbed78 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.kt @@ -18,7 +18,7 @@ import com.mapbox.mapboxsdk.testapp.R class LocationMapChangeActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var permissionsManager: PermissionsManager? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -27,7 +27,7 @@ class LocationMapChangeActivity : AppCompatActivity(), OnMapReadyCallback { val stylesFab = findViewById(R.id.fabStyles) stylesFab.setOnClickListener { v: View? -> if (mapboxMap != null) { - mapboxMap!!.setStyle(Style.Builder().fromUri(Utils.nextStyle())) + mapboxMap.setStyle(Style.Builder().fromUri(Utils.nextStyle())) } } mapView.onCreate(savedInstanceState) @@ -73,7 +73,7 @@ class LocationMapChangeActivity : AppCompatActivity(), OnMapReadyCallback { @SuppressLint("MissingPermission") private fun activateLocationComponent(style: Style) { - val locationComponent = mapboxMap!!.locationComponent + val locationComponent = mapboxMap.locationComponent locationComponent.activateLocationComponent( LocationComponentActivationOptions .builder(this, style) @@ -100,36 +100,36 @@ class LocationMapChangeActivity : AppCompatActivity(), OnMapReadyCallback { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.kt index 975fb8eb2..650008183 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.kt @@ -43,7 +43,7 @@ class LocationModesActivity : private var protectedGestureArea: View? = null private var permissionsManager: PermissionsManager? = null private var locationComponent: LocationComponent? = null - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var defaultStyle = false @CameraMode.Mode @@ -225,7 +225,7 @@ class LocationModesActivity : if (locationComponent == null) { return } - mapboxMap!!.getStyle { style: Style -> + mapboxMap.getStyle { style: Style -> val styleUrl = Style.getPredefinedStyle( if (Style.getPredefinedStyle("Bright") == style.uri) { @@ -235,7 +235,7 @@ class LocationModesActivity : } ) - mapboxMap!!.setStyle(Style.Builder().fromUri(styleUrl)) + mapboxMap.setStyle(Style.Builder().fromUri(styleUrl)) } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.kt index 0d95b639b..9d956caf7 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.kt @@ -124,36 +124,36 @@ class ManualLocationUpdatesActivity : AppCompatActivity(), OnMapReadyCallback { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.kt index 3fa496c13..1222b3742 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.kt @@ -22,8 +22,8 @@ import java.util.* * Test activity showcasing the different debug modes and allows to cycle between the default map styles. */ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsChangedListener { - private var mapView: MapView? = null - private var mapboxMap: MapboxMap? = null + private lateinit var mapView: MapView + private lateinit var mapboxMap: MapboxMap private var cameraMoveListener: OnCameraMoveListener? = null private var actionBarDrawerToggle: ActionBarDrawerToggle? = null private var currentStyleIndex = 0 @@ -59,15 +59,15 @@ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsCha val mapboxMapOptions = setupMapboxMapOptions() mapView = MapView(this, mapboxMapOptions) (findViewById(R.id.coordinator_layout) as ViewGroup).addView(mapView, 0) - mapView!!.addOnDidFinishLoadingStyleListener { + mapView.addOnDidFinishLoadingStyleListener { if (mapboxMap != null) { - setupNavigationView(mapboxMap!!.style!!.layers) + setupNavigationView(mapboxMap.style!!.layers) } } - mapView!!.tag = true - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync(this) - mapView!!.addOnDidFinishLoadingStyleListener { Timber.d("Style loaded") } + mapView.tag = true + mapView.onCreate(savedInstanceState) + mapView.getMapAsync(this) + mapView.addOnDidFinishLoadingStyleListener { Timber.d("Style loaded") } } protected open fun setupMapboxMapOptions(): MapboxMapOptions { @@ -76,7 +76,7 @@ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsCha override fun onMapReady(map: MapboxMap) { mapboxMap = map - mapboxMap!!.setStyle( + mapboxMap.setStyle( Style.Builder().fromUri(STYLES[currentStyleIndex]) ) { style: Style -> setupNavigationView(style.layers) } setupZoomView() @@ -85,7 +85,7 @@ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsCha private fun setFpsView() { fpsView = findViewById(R.id.fpsView) - mapboxMap!!.setOnFpsChangedListener(this) + mapboxMap.setOnFpsChangedListener(this) } override fun onFpsChanged(fps: Double) { @@ -93,7 +93,7 @@ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsCha } private fun setupNavigationView(layerList: List) { - Timber.v("New style loaded with JSON: %s", mapboxMap!!.style!!.json) + Timber.v("New style loaded with JSON: %s", mapboxMap.style!!.json) val adapter = LayerListAdapter(this, layerList) val listView = findViewById(R.id.listView) listView.adapter = adapter @@ -121,13 +121,13 @@ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsCha private fun setupZoomView() { val textView = findViewById(R.id.textZoom) - mapboxMap!!.addOnCameraMoveListener( + mapboxMap.addOnCameraMoveListener( OnCameraMoveListener { textView.text = String.format( this@DebugModeActivity.getString( R.string.debug_zoom ), - mapboxMap!!.cameraPosition.zoom + mapboxMap.cameraPosition.zoom ) }.also { cameraMoveListener = it } ) @@ -137,8 +137,8 @@ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsCha val fabDebug = findViewById(R.id.fabDebug) fabDebug.setOnClickListener { view: View? -> if (mapboxMap != null) { - mapboxMap!!.isDebugActive = !mapboxMap!!.isDebugActive - Timber.d("Debug FAB: isDebug Active? %s", mapboxMap!!.isDebugActive) + mapboxMap.isDebugActive = !mapboxMap.isDebugActive + Timber.d("Debug FAB: isDebug Active? %s", mapboxMap.isDebugActive) } } } @@ -151,7 +151,7 @@ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsCha if (currentStyleIndex == STYLES.size) { currentStyleIndex = 0 } - mapboxMap!!.setStyle(Style.Builder().fromUri(STYLES[currentStyleIndex])) + mapboxMap.setStyle(Style.Builder().fromUri(STYLES[currentStyleIndex])) } } } @@ -161,11 +161,11 @@ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsCha if (itemId == R.id.menu_action_toggle_report_fps) { isReportFps = !isReportFps fpsView!!.visibility = if (isReportFps) View.VISIBLE else View.GONE - mapboxMap!!.setOnFpsChangedListener(if (isReportFps) this else null) + mapboxMap.setOnFpsChangedListener(if (isReportFps) this else null) } else if (itemId == R.id.menu_action_limit_to_30_fps) { - mapView!!.setMaximumFps(30) + mapView.setMaximumFps(30) } else if (itemId == R.id.menu_action_limit_to_60_fps) { - mapView!!.setMaximumFps(60) + mapView.setMaximumFps(60) } return actionBarDrawerToggle!!.onOptionsItemSelected(item) || super.onOptionsItemSelected( item @@ -179,40 +179,40 @@ open class DebugModeActivity : AppCompatActivity(), OnMapReadyCallback, OnFpsCha override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() if (mapboxMap != null) { - mapboxMap!!.removeOnCameraMoveListener(cameraMoveListener!!) + mapboxMap.removeOnCameraMoveListener(cameraMoveListener!!) } - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } private class LayerListAdapter(context: Context?, layers: List) : diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.kt index d322fe05e..7629832d8 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.kt @@ -62,8 +62,8 @@ class DoubleMapActivity : AppCompatActivity() { // MapView large mapView = MapView(view.context, MapFragmentUtils.resolveArgs(view.context, arguments)) - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> mapboxMap.setStyle( Style.getPredefinedStyle( "Streets" @@ -106,43 +106,43 @@ class DoubleMapActivity : AppCompatActivity() { override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() mapViewMini!!.onResume() } override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() mapViewMini!!.onStart() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() mapViewMini!!.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() mapViewMini!!.onStop() } override fun onDestroyView() { super.onDestroyView() - mapView!!.onDestroy() + mapView.onDestroy() mapViewMini!!.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() mapViewMini!!.onLowMemory() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) // Mini map view is not interactive in this case, so we shouldn't save the instance. // If we'd like to support state saving for both maps, they'd have to be kept in separate fragments. // mapViewMini.onSaveInstanceState(outState); diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.kt index 03588d337..1d4607dde 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.kt @@ -16,7 +16,7 @@ import com.mapbox.mapboxsdk.testapp.R */ class LatLngBoundsForCameraActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_restricted_bounds) @@ -58,12 +58,12 @@ class LatLngBoundsForCameraActivity : AppCompatActivity(), OnMapReadyCallback { } private fun setupBounds(bounds: LatLngBounds?) { - mapboxMap!!.setLatLngBoundsForCameraTarget(bounds) + mapboxMap.setLatLngBoundsForCameraTarget(bounds) showBoundsArea(bounds) } private fun showBoundsArea(bounds: LatLngBounds?) { - mapboxMap!!.clear() + mapboxMap.clear() if (bounds != null) { val boundsArea = PolygonOptions() .add(bounds.northWest) @@ -72,7 +72,7 @@ class LatLngBoundsForCameraActivity : AppCompatActivity(), OnMapReadyCallback { .add(bounds.southWest) boundsArea.alpha(0.25f) boundsArea.fillColor(Color.RED) - mapboxMap!!.addPolygon(boundsArea) + mapboxMap.addPolygon(boundsArea) } } @@ -80,42 +80,42 @@ class LatLngBoundsForCameraActivity : AppCompatActivity(), OnMapReadyCallback { val crosshair = View(this) crosshair.layoutParams = FrameLayout.LayoutParams(10, 10, Gravity.CENTER) crosshair.setBackgroundColor(Color.BLUE) - mapView!!.addView(crosshair) + mapView.addView(crosshair) } override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LocalGlyphActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LocalGlyphActivity.kt index e77848c60..e2ef8d5cb 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LocalGlyphActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LocalGlyphActivity.kt @@ -39,36 +39,36 @@ class LocalGlyphActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.kt index 4315b55ff..9fb5e117e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.kt @@ -102,36 +102,36 @@ class MapChangeActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.kt index 5646684fc..b6d1c9a9f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.kt @@ -51,40 +51,40 @@ class MapInDialogActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onDestroyView() { super.onDestroyView() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() if (mapView != null) { - mapView!!.onLowMemory() + mapView.onLowMemory() } } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) if (mapView != null) { - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.kt index 17656702b..01117c0db 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapPaddingActivity.kt @@ -16,7 +16,7 @@ import com.mapbox.mapboxsdk.testapp.R */ class MapPaddingActivity : AppCompatActivity() { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_map_padding) @@ -43,37 +43,37 @@ class MapPaddingActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onCreateOptionsMenu(menu: Menu): Boolean { @@ -89,8 +89,8 @@ class MapPaddingActivity : AppCompatActivity() { .bearing(40.0) .tilt(45.0) .build() - mapboxMap!!.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)) - mapboxMap!!.addMarker(MarkerOptions().title("Center map").position(bangalore)) + mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)) + mapboxMap.addMarker(MarkerOptions().title("Center map").position(bangalore)) } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.kt index ff0dffade..819527ab3 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/SimpleMapActivity.kt @@ -30,37 +30,37 @@ class SimpleMapActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/VisibilityChangeActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/VisibilityChangeActivity.kt index 343588e77..eb00d6f7f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/VisibilityChangeActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/VisibilityChangeActivity.kt @@ -15,7 +15,7 @@ import com.mapbox.mapboxsdk.testapp.activity.maplayout.VisibilityChangeActivity. */ class VisibilityChangeActivity : AppCompatActivity() { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private val handler = Handler() private var runnable: Runnable? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -25,9 +25,11 @@ class VisibilityChangeActivity : AppCompatActivity() { mapView.onCreate(savedInstanceState) mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> - mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Streets")) - mapboxMap!!.animateCamera( + if (map != null) { + mapboxMap = map + } + mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) + mapboxMap.animateCamera( CameraUpdateFactory.newLatLngZoom( LatLng(55.754020, 37.620948), 12.0 @@ -65,9 +67,9 @@ class VisibilityChangeActivity : AppCompatActivity() { if (isViewHiearchyReady) { if (isEvenStep) { viewParent!!.visibility = View.VISIBLE - mapView!!.visibility = View.VISIBLE + mapView?.visibility = View.VISIBLE } else if (isFirstOrThirdStep) { - mapView!!.visibility = visibilityForStep + mapView?.visibility = visibilityForStep } else if (isFifthOrSeventhStep) { viewParent!!.visibility = visibilityForStep } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.kt index 66bf3244c..e4865d1d8 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/OfflineActivity.kt @@ -39,8 +39,8 @@ class OfflineActivity : AppCompatActivity(), DownloadRegionDialogListener { /* * UI elements */ - private var mapView: MapView? = null - private var mapboxMap: MapboxMap? = null + private lateinit var mapView: MapView + private lateinit var mapboxMap: MapboxMap private var progressBar: ProgressBar? = null private var downloadRegion: Button? = null private var listRegions: Button? = null @@ -63,8 +63,8 @@ class OfflineActivity : AppCompatActivity(), DownloadRegionDialogListener { // Set up map mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> Timber.d("Map is ready") this@OfflineActivity.mapboxMap = mapboxMap mapboxMap.setStyle(Style.Builder().fromUri(STYLE_URL)) @@ -96,37 +96,37 @@ class OfflineActivity : AppCompatActivity(), DownloadRegionDialogListener { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } /* @@ -193,9 +193,9 @@ class OfflineActivity : AppCompatActivity(), DownloadRegionDialogListener { startProgress() // Definition - val bounds = mapboxMap!!.projection.visibleRegion.latLngBounds - val minZoom = mapboxMap!!.cameraPosition.zoom - val maxZoom = mapboxMap!!.maxZoomLevel + val bounds = mapboxMap.projection.visibleRegion.latLngBounds + val minZoom = mapboxMap.cameraPosition.zoom + val maxZoom = mapboxMap.maxZoomLevel val pixelRatio = this.resources.displayMetrics.density val definition = OfflineTilePyramidRegionDefinition( STYLE_URL, diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/UpdateMetadataActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/UpdateMetadataActivity.kt index 66981bbce..8a58424df 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/UpdateMetadataActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/offline/UpdateMetadataActivity.kt @@ -29,7 +29,7 @@ class UpdateMetadataActivity : AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener { private var adapter: OfflineRegionMetadataAdapter? = null - private var mapView: MapView? = null + private lateinit var mapView: MapView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_metadata_update) @@ -73,14 +73,14 @@ class UpdateMetadataActivity : val container = findViewById(R.id.container) container.removeAllViews() container.addView(MapView(view.context).also { mapView = it }) - mapView!!.onCreate(null) - mapView!!.getMapAsync { map: MapboxMap -> + mapView.onCreate(null) + mapView.getMapAsync { map: MapboxMap -> map.setOfflineRegionDefinition( adapter!!.getItem(position).definition ) } - mapView!!.onStart() - mapView!!.onResume() + mapView.onStart() + mapView.onResume() return true } @@ -129,9 +129,9 @@ class UpdateMetadataActivity : override fun onDestroy() { super.onDestroy() if (mapView != null) { - mapView!!.onPause() - mapView!!.onStop() - mapView!!.onDestroy() + mapView.onPause() + mapView.onStop() + mapView.onDestroy() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/storage/UrlTransformActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/storage/UrlTransformActivity.kt index 3dcff36c5..227f4e617 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/storage/UrlTransformActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/storage/UrlTransformActivity.kt @@ -16,7 +16,7 @@ import timber.log.Timber * Test activity showcasing the url transform */ class UrlTransformActivity : AppCompatActivity() { - private var mapView: MapView? = null + private lateinit var mapView: MapView /** * Be sure to use an isolated class so the activity is not leaked when @@ -38,11 +38,11 @@ class UrlTransformActivity : AppCompatActivity() { // Initialize map as normal mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) + mapView.onCreate(savedInstanceState) // Get a handle to the file source and set the resource transform FileSource.getInstance(this@UrlTransformActivity).setResourceTransform(Transform()) - mapView!!.getMapAsync { map: MapboxMap -> + mapView.getMapAsync { map: MapboxMap -> Timber.i("Map loaded") map.setStyle(Style.getPredefinedStyle("Streets")) } @@ -50,27 +50,27 @@ class UrlTransformActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { @@ -78,11 +78,11 @@ class UrlTransformActivity : AppCompatActivity() { // Example of how to reset the transform callback FileSource.getInstance(this@UrlTransformActivity).setResourceTransform(null) - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/AnimatedSymbolLayerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/AnimatedSymbolLayerActivity.kt index adf42271c..94c76b263 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/AnimatedSymbolLayerActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/AnimatedSymbolLayerActivity.kt @@ -34,7 +34,7 @@ import java.util.* class AnimatedSymbolLayerActivity : AppCompatActivity() { private val random = Random() private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var style: Style? = null private val randomCars: MutableList = ArrayList() private var randomCarSource: GeoJsonSource? = null @@ -293,7 +293,7 @@ class AnimatedSymbolLayerActivity : AppCompatActivity() { private val latLngInBounds: LatLng get() { - val bounds = mapboxMap!!.projection.visibleRegion.latLngBounds + val bounds = mapboxMap.projection.visibleRegion.latLngBounds val generator = Random() val randomLat = bounds.latitudeSouth + generator.nextDouble() * bounds.latitudeNorth - bounds.latitudeSouth val randomLon = bounds.longitudeWest + generator.nextDouble() * bounds.longitudeEast - bounds.longitudeWest diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/BuildingFillExtrusionActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/BuildingFillExtrusionActivity.kt index ba6e6d974..f2e1bbc08 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/BuildingFillExtrusionActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/BuildingFillExtrusionActivity.kt @@ -24,7 +24,7 @@ import com.mapbox.mapboxsdk.utils.ColorUtils */ class BuildingFillExtrusionActivity : AppCompatActivity() { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var light: Light? = null private var isMapAnchorLight = false private var isLowIntensityLight = false @@ -37,8 +37,10 @@ class BuildingFillExtrusionActivity : AppCompatActivity() { mapView.onCreate(savedInstanceState) mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> - mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Streets")) { style: Style -> + if (map != null) { + mapboxMap = map + } + mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style: Style -> setupBuildings(style) setupLight() } @@ -66,7 +68,7 @@ class BuildingFillExtrusionActivity : AppCompatActivity() { } private fun setupLight() { - light = mapboxMap!!.style!!.light + light = mapboxMap.style!!.light findViewById(R.id.fabLightPosition).setOnClickListener { v: View? -> isInitPosition = !isInitPosition if (isInitPosition) { @@ -103,36 +105,36 @@ class BuildingFillExtrusionActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.kt index ae496d5f3..8afaa8862 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CircleLayerActivity.kt @@ -32,7 +32,7 @@ import java.net.URISyntaxException */ class CircleLayerActivity : AppCompatActivity(), View.OnClickListener { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private lateinit var styleFab: FloatingActionButton private lateinit var routeFab: FloatingActionButton private var layer: CircleLayer? = null @@ -46,11 +46,13 @@ class CircleLayerActivity : AppCompatActivity(), View.OnClickListener { mapView.onCreate(savedInstanceState) mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> - mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Satellite Hybrid")) + if (map != null) { + mapboxMap = map + } + mapboxMap.setStyle(Style.getPredefinedStyle("Satellite Hybrid")) mapView.addOnDidFinishLoadingStyleListener( OnDidFinishLoadingStyleListener { - val style = mapboxMap!!.style + val style = mapboxMap.style addBusStopSource(style) addBusStopCircleLayer(style) initFloatingActionButtons() @@ -105,13 +107,13 @@ class CircleLayerActivity : AppCompatActivity(), View.OnClickListener { } private fun removeOldSource() { - mapboxMap!!.style!!.removeSource(SOURCE_ID) - mapboxMap!!.style!!.removeLayer(LAYER_ID) + mapboxMap.style!!.removeSource(SOURCE_ID) + mapboxMap.style!!.removeLayer(LAYER_ID) } private fun addClusteredSource() { try { - mapboxMap!!.style!!.addSource( + mapboxMap.style!!.addSource( GeoJsonSource( SOURCE_ID_CLUSTER, URI(URL_BUS_ROUTES), @@ -149,7 +151,7 @@ class CircleLayerActivity : AppCompatActivity(), View.OnClickListener { unclustered.setProperties( PropertyFactory.iconImage("bus-15") ) - mapboxMap!!.style!!.addLayer(unclustered) + mapboxMap.style!!.addLayer(unclustered) for (i in layers.indices) { // Add some nice circles val circles = CircleLayer("cluster-$i", SOURCE_ID_CLUSTER) @@ -188,7 +190,7 @@ class CircleLayerActivity : AppCompatActivity(), View.OnClickListener { ) } ) - mapboxMap!!.style!!.addLayer(circles) + mapboxMap.style!!.addLayer(circles) } // Add the count labels @@ -200,7 +202,7 @@ class CircleLayerActivity : AppCompatActivity(), View.OnClickListener { PropertyFactory.textIgnorePlacement(true), PropertyFactory.textAllowOverlap(true) ) - mapboxMap!!.style!!.addLayer(count) + mapboxMap.style!!.addLayer(count) } private fun removeFabs() { @@ -215,17 +217,17 @@ class CircleLayerActivity : AppCompatActivity(), View.OnClickListener { } private fun removeBusStop() { - mapboxMap!!.style!!.removeLayer(layer!!) - mapboxMap!!.style!!.removeSource(source!!) + mapboxMap.style!!.removeLayer(layer!!) + mapboxMap.style!!.removeSource(source!!) } private fun loadNewStyle() { - mapboxMap!!.setStyle(Style.Builder().fromUri(nextStyle)) + mapboxMap.setStyle(Style.Builder().fromUri(nextStyle)) } private fun addBusStop() { - mapboxMap!!.style!!.addLayer(layer!!) - mapboxMap!!.style!!.addSource(source!!) + mapboxMap.style!!.addLayer(layer!!) + mapboxMap.style!!.addSource(source!!) } private val nextStyle: String @@ -239,37 +241,37 @@ class CircleLayerActivity : AppCompatActivity(), View.OnClickListener { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } private object Data { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.kt index 7fadf3c8f..1edeb6390 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/CustomSpriteActivity.kt @@ -27,7 +27,7 @@ import timber.log.Timber */ class CustomSpriteActivity : AppCompatActivity() { private var source: GeoJsonSource? = null - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private lateinit var mapView: MapView private lateinit var layer: Layer public override fun onCreate(savedInstanceState: Bundle?) { @@ -66,7 +66,7 @@ class CustomSpriteActivity : AppCompatActivity() { "point", FeatureCollection.fromFeatures(arrayOf(Feature.fromGeometry(point))) ) - mapboxMap!!.style!!.addSource(source!!) + mapboxMap.style!!.addSource(source!!) // Add a symbol layer that references that point source layer = SymbolLayer("layer", "point") @@ -77,7 +77,7 @@ class CustomSpriteActivity : AppCompatActivity() { ) // lets add a circle below labels! - mapboxMap!!.style!!.addLayerBelow(layer, "water_intermittent") + mapboxMap.style!!.addLayerBelow(layer, "water_intermittent") fab.setImageResource(R.drawable.ic_directions_car_black) } else { // Update point @@ -96,7 +96,7 @@ class CustomSpriteActivity : AppCompatActivity() { ) // Move the camera as well - mapboxMap!!.moveCamera( + mapboxMap.moveCamera( CameraUpdateFactory.newLatLng( LatLng( point.latitude(), @@ -114,37 +114,37 @@ class CustomSpriteActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DataDrivenStyleActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DataDrivenStyleActivity.kt index 964e4f2d7..6fe1ead9d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DataDrivenStyleActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/DataDrivenStyleActivity.kt @@ -30,7 +30,7 @@ import java.io.IOException */ class DataDrivenStyleActivity : AppCompatActivity() { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var idleListener: IdleZoomListener? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -42,8 +42,10 @@ class DataDrivenStyleActivity : AppCompatActivity() { mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> // Store for later - mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? -> + if (map != null) { + mapboxMap = map + } + mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? -> // Add a parks layer addParksLayer() @@ -52,7 +54,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { } // Center and Zoom (Amsterdam, zoomed to streets) - mapboxMap!!.animateCamera( + mapboxMap.animateCamera( CameraUpdateFactory.newLatLngZoom( LatLng(52.379189, 4.899431), 14.0 @@ -64,7 +66,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun setupDebugZoomView() { val textView = findViewById(R.id.textZoom) as TextView - mapboxMap!!.addOnCameraIdleListener( + mapboxMap.addOnCameraIdleListener( IdleZoomListener( mapboxMap, textView @@ -79,40 +81,40 @@ class DataDrivenStyleActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() if (mapboxMap != null && idleListener != null) { - mapboxMap!!.removeOnCameraIdleListener(idleListener!!) + mapboxMap.removeOnCameraIdleListener(idleListener!!) } - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -159,7 +161,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun addExponentialZoomFunction() { Timber.i("Add exponential zoom function") - val layer = mapboxMap!!.style!!.getLayerAs("water")!! + val layer = mapboxMap.style!!.getLayerAs("water")!! layer.setProperties( PropertyFactory.fillColor( Expression.interpolate( @@ -176,7 +178,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun addIntervalZoomFunction() { Timber.i("Add interval zoom function") - val layer = mapboxMap!!.style!!.getLayerAs("water")!! + val layer = mapboxMap.style!!.getLayerAs("water")!! layer.setProperties( PropertyFactory.fillColor( Expression.step( @@ -193,7 +195,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun addExponentialSourceFunction() { Timber.i("Add exponential source function") - val layer = mapboxMap!!.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! + val layer = mapboxMap.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! layer.setProperties( PropertyFactory.fillColor( Expression.interpolate( @@ -210,7 +212,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun addCategoricalSourceFunction() { Timber.i("Add categorical source function") - val layer = mapboxMap!!.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! + val layer = mapboxMap.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! layer.setProperties( PropertyFactory.fillColor( Expression.match( @@ -230,7 +232,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun addIdentitySourceFunction() { Timber.i("Add identity source function") - val layer = mapboxMap!!.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! + val layer = mapboxMap.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! layer.setProperties( PropertyFactory.fillOpacity( Expression.get("fill-opacity") @@ -241,7 +243,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun addIntervalSourceFunction() { Timber.i("Add interval source function") - val layer = mapboxMap!!.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! + val layer = mapboxMap.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! layer.setProperties( PropertyFactory.fillColor( Expression.step( @@ -258,7 +260,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun addCompositeExponentialFunction() { Timber.i("Add composite exponential function") - val layer = mapboxMap!!.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! + val layer = mapboxMap.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! layer.setProperties( PropertyFactory.fillColor( Expression.interpolate( @@ -302,7 +304,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun addCompositeIntervalFunction() { Timber.i("Add composite interval function") - val layer = mapboxMap!!.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! + val layer = mapboxMap.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! layer.setProperties( PropertyFactory.fillColor( Expression.interpolate( @@ -346,7 +348,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { private fun addCompositeCategoricalFunction() { Timber.i("Add composite categorical function") - val layer = mapboxMap!!.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! + val layer = mapboxMap.style!!.getLayerAs(AMSTERDAM_PARKS_LAYER)!! layer.setProperties( PropertyFactory.fillColor( Expression.step( @@ -516,7 +518,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { "amsterdam-parks-source", ResourceUtils.readRawResource(this, R.raw.amsterdam) ) - mapboxMap!!.style!!.addSource(source) + mapboxMap.style!!.addSource(source) } catch (ioException: IOException) { Toast.makeText( this@DataDrivenStyleActivity, @@ -527,7 +529,7 @@ class DataDrivenStyleActivity : AppCompatActivity() { } // Add a fill layer - mapboxMap!!.style!! + mapboxMap.style!! .addLayer( FillLayer(AMSTERDAM_PARKS_LAYER, source.getId()) .withProperties( diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionActivity.kt index 71d77c6d1..566418d8f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionActivity.kt @@ -67,36 +67,36 @@ class FillExtrusionActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionStyleTestActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionStyleTestActivity.kt index 2fb3f62cf..963f17b52 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionStyleTestActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/FillExtrusionStyleTestActivity.kt @@ -12,8 +12,8 @@ import com.mapbox.mapboxsdk.testapp.R * Test activity used for instrumentation tests of fill extrusion. */ class FillExtrusionStyleTestActivity : AppCompatActivity() { - var mapView: MapView? = null - var mapboxMap: MapboxMap? = null + lateinit var mapView: MapView + lateinit var mapboxMap: MapboxMap private set override fun onCreate(savedInstanceState: Bundle?) { @@ -22,8 +22,8 @@ class FillExtrusionStyleTestActivity : AppCompatActivity() { // Initialize map as normal mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> mapboxMap.setStyle( Style.Builder().fromUri(Style.getPredefinedStyle("Streets")) ) { style: Style? -> this@FillExtrusionStyleTestActivity.mapboxMap = mapboxMap } @@ -32,36 +32,36 @@ class FillExtrusionStyleTestActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.kt index 22918db98..895d48609 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.kt @@ -33,7 +33,7 @@ import java.util.Objects */ class GeoJsonClusteringActivity : AppCompatActivity() { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var clusterSource: GeoJsonSource? = null private var clickOptionCounter = 0 override fun onCreate(savedInstanceState: Bundle?) { @@ -46,8 +46,10 @@ class GeoJsonClusteringActivity : AppCompatActivity() { mapView.onCreate(savedInstanceState) mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> - mapboxMap = map - mapboxMap!!.animateCamera( + if (map != null) { + mapboxMap = map + } + mapboxMap.animateCamera( CameraUpdateFactory.newLatLngZoom( LatLng(37.7749, 122.4194), 0.0 @@ -73,7 +75,7 @@ class GeoJsonClusteringActivity : AppCompatActivity() { ) ) try { - mapboxMap!!.setStyle( + mapboxMap.setStyle( Style.Builder() .fromUri(Style.getPredefinedStyle("Bright")) .withSource(createClusterSource().also { clusterSource = it }) @@ -93,10 +95,10 @@ class GeoJsonClusteringActivity : AppCompatActivity() { } catch (exception: URISyntaxException) { Timber.e(exception) } - mapboxMap!!.addOnMapClickListener { latLng: LatLng? -> - val point = mapboxMap!!.projection.toScreenLocation(latLng!!) + mapboxMap.addOnMapClickListener { latLng: LatLng? -> + val point = mapboxMap.projection.toScreenLocation(latLng!!) val features = - mapboxMap!!.queryRenderedFeatures(point, "cluster-0", "cluster-1", "cluster-2") + mapboxMap.queryRenderedFeatures(point, "cluster-0", "cluster-1", "cluster-2") if (!features.isEmpty()) { onClusterClick(features[0], Point(point.x.toInt(), point.y.toInt())) } @@ -113,8 +115,8 @@ class GeoJsonClusteringActivity : AppCompatActivity() { private fun onClusterClick(cluster: Feature, clickPoint: Point) { if (clickOptionCounter == 0) { val nextZoomLevel = clusterSource!!.getClusterExpansionZoom(cluster).toDouble() - val zoomDelta = nextZoomLevel - mapboxMap!!.cameraPosition.zoom - mapboxMap!!.animateCamera( + val zoomDelta = nextZoomLevel - mapboxMap.cameraPosition.zoom + mapboxMap.animateCamera( CameraUpdateFactory.zoomBy( zoomDelta + CAMERA_ZOOM_DELTA, clickPoint diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GradientLineActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GradientLineActivity.kt index 17c79638f..624b8a20f 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GradientLineActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GradientLineActivity.kt @@ -70,37 +70,37 @@ class GradientLineActivity : AppCompatActivity(), OnMapReadyCallback { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/HeatmapLayerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/HeatmapLayerActivity.kt index 4c24ba736..a6aee14b4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/HeatmapLayerActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/HeatmapLayerActivity.kt @@ -19,7 +19,7 @@ import java.net.URISyntaxException */ class HeatmapLayerActivity : AppCompatActivity() { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_heatmaplayer) @@ -27,9 +27,11 @@ class HeatmapLayerActivity : AppCompatActivity() { mapView.onCreate(savedInstanceState) mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> - mapboxMap = map + if (map != null) { + mapboxMap = map + } try { - mapboxMap!!.setStyle( + mapboxMap.setStyle( Style.Builder() .fromUri(Style.getPredefinedStyle("Pastel")) .withSource(createEarthquakeSource()) @@ -152,37 +154,37 @@ class HeatmapLayerActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/HillshadeLayerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/HillshadeLayerActivity.kt index 0c9e9d808..da81b1129 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/HillshadeLayerActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/HillshadeLayerActivity.kt @@ -12,7 +12,7 @@ import com.mapbox.mapboxsdk.testapp.R */ class HillshadeLayerActivity : AppCompatActivity() { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_fill_extrusion_layer) @@ -20,10 +20,12 @@ class HillshadeLayerActivity : AppCompatActivity() { mapView.onCreate(savedInstanceState) mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> - mapboxMap = map + if (map != null) { + mapboxMap = map + } val rasterDemSource = RasterDemSource(SOURCE_ID, SOURCE_URL) val hillshadeLayer = HillshadeLayer(LAYER_ID, SOURCE_ID) - mapboxMap!!.setStyle( + mapboxMap.setStyle( Style.Builder() .fromUri(Style.getPredefinedStyle("Streets")) .withLayerBelow(hillshadeLayer, LAYER_BELOW_ID) @@ -35,37 +37,37 @@ class HillshadeLayerActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RealTimeGeoJsonActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RealTimeGeoJsonActivity.kt index 762bfcd28..fd6ceb572 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RealTimeGeoJsonActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RealTimeGeoJsonActivity.kt @@ -20,21 +20,21 @@ import java.net.URISyntaxException * */ class RealTimeGeoJsonActivity : AppCompatActivity(), OnMapReadyCallback { - private var mapView: MapView? = null - private var mapboxMap: MapboxMap? = null + private lateinit var mapView: MapView + private lateinit var mapboxMap: MapboxMap private var handler: Handler? = null private var runnable: Runnable? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_default) mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync(this) + mapView.onCreate(savedInstanceState) + mapView.getMapAsync(this) } override fun onMapReady(map: MapboxMap) { mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Streets")) { style -> // add source + mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style -> // add source try { style.addSource(GeoJsonSource(ID_GEOJSON_SOURCE, URI(URL_GEOJSON_SOURCE))) } catch (malformedUriException: URISyntaxException) { @@ -57,22 +57,22 @@ class RealTimeGeoJsonActivity : AppCompatActivity(), OnMapReadyCallback { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } public override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } public override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() runnable?.let { handler!!.removeCallbacks(it) } @@ -80,12 +80,12 @@ class RealTimeGeoJsonActivity : AppCompatActivity(), OnMapReadyCallback { override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } private class RefreshGeoJsonRunnable internal constructor( diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.kt index 01b33d2ed..67a1067d6 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleActivity.kt @@ -45,7 +45,7 @@ import java.util.Collections */ class RuntimeStyleActivity : AppCompatActivity() { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var styleLoaded = false var lngLats = listOf( Arrays.asList( @@ -82,16 +82,18 @@ class RuntimeStyleActivity : AppCompatActivity() { mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> // Store for later - mapboxMap = map + if (map != null) { + mapboxMap = map + } // Center and Zoom (Amsterdam, zoomed to streets) - mapboxMap!!.animateCamera( + mapboxMap.animateCamera( CameraUpdateFactory.newLatLngZoom( LatLng(52.379189, 4.899431), 1.0 ) ) - mapboxMap!!.setStyle( + mapboxMap.setStyle( Style.Builder() .fromUri(Style.getPredefinedStyle("Streets")) // set custom transition .withTransition(TransitionOptions(250, 50)) @@ -119,37 +121,37 @@ class RuntimeStyleActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } override fun onOptionsItemSelected(item: MenuItem): Boolean { @@ -258,7 +260,7 @@ class RuntimeStyleActivity : AppCompatActivity() { } private fun listLayers() { - val layers = mapboxMap!!.style!! + val layers = mapboxMap.style!! .layers val builder = StringBuilder("Layers:") for (layer in layers) { @@ -269,7 +271,7 @@ class RuntimeStyleActivity : AppCompatActivity() { } private fun listSources() { - val sources = mapboxMap!!.style!! + val sources = mapboxMap.style!! .sources val builder = StringBuilder("Sources:") for (source in sources) { @@ -282,21 +284,21 @@ class RuntimeStyleActivity : AppCompatActivity() { private fun setLayerInvisible() { val roadLayers = arrayOf("water") for (roadLayer in roadLayers) { - val layer = mapboxMap!!.style!!.getLayer(roadLayer) + val layer = mapboxMap.style!!.getLayer(roadLayer) layer?.setProperties(PropertyFactory.visibility(Property.NONE)) } } private fun setRoadSymbolPlacement() { // Zoom so that the labels are visible first - mapboxMap!!.animateCamera( + mapboxMap.animateCamera( CameraUpdateFactory.zoomTo(14.0), object : DefaultCallback() { override fun onFinish() { val roadLayers = arrayOf("road-label-small", "road-label-medium", "road-label-large") for (roadLayer in roadLayers) { - val layer = mapboxMap!!.style!! + val layer = mapboxMap.style!! .getLayer(roadLayer) layer?.setProperties(PropertyFactory.symbolPlacement(Property.SYMBOL_PLACEMENT_POINT)) } @@ -306,12 +308,12 @@ class RuntimeStyleActivity : AppCompatActivity() { } private fun setBackgroundOpacity() { - val background = mapboxMap!!.style!!.getLayer("background") + val background = mapboxMap.style!!.getLayer("background") background?.setProperties(PropertyFactory.backgroundOpacity(0.2f)) } private fun setWaterColor() { - val water = mapboxMap!!.style!!.getLayerAs("water") + val water = mapboxMap.style!!.getLayerAs("water") if (water != null) { water.fillColorTransition = TransitionOptions(7500, 1000) water.setProperties( @@ -329,7 +331,7 @@ class RuntimeStyleActivity : AppCompatActivity() { private fun removeBuildings() { // Zoom to see buildings first - mapboxMap!!.style!!.removeLayer("building") + mapboxMap.style!!.removeLayer("building") } private fun addParksLayer() { @@ -345,7 +347,7 @@ class RuntimeStyleActivity : AppCompatActivity() { ).show() return } - mapboxMap!!.style!!.addSource(source) + mapboxMap.style!!.addSource(source) var layer: FillLayer? = FillLayer("parksLayer", "amsterdam-spots") layer!!.setProperties( PropertyFactory.fillColor(Color.RED), @@ -364,15 +366,15 @@ class RuntimeStyleActivity : AppCompatActivity() { ) ) ) - mapboxMap!!.style!!.addLayerBelow(layer, "building") + mapboxMap.style!!.addLayerBelow(layer, "building") // layer.setPaintProperty(fillColor(Color.RED)); // XXX But not after the object is attached // Or get the object later and set it. It's all good. - mapboxMap!!.style!!.getLayer("parksLayer")!! + mapboxMap.style!!.getLayer("parksLayer")!! .setProperties(PropertyFactory.fillColor(Color.RED)) // You can get a typed layer, if you're sure it's of that type. Use with care - layer = mapboxMap!!.style!!.getLayerAs("parksLayer") + layer = mapboxMap.style!!.getLayerAs("parksLayer") // And get some properties val fillAntialias = layer!!.fillAntialias Timber.d("Fill anti alias: %s", fillAntialias.getValue()) @@ -383,7 +385,7 @@ class RuntimeStyleActivity : AppCompatActivity() { Timber.d("Visibility: %s", visibility.getValue()) // Get a good look at it all - mapboxMap!!.animateCamera(CameraUpdateFactory.zoomTo(12.0)) + mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(12.0)) } private fun addDynamicParksLayer() { @@ -402,7 +404,7 @@ class RuntimeStyleActivity : AppCompatActivity() { } // Add an empty source - mapboxMap!!.style!!.addSource(GeoJsonSource("dynamic-park-source")) + mapboxMap.style!!.addSource(GeoJsonSource("dynamic-park-source")) val layer = FillLayer("dynamic-parks-layer", "dynamic-park-source") layer.setProperties( PropertyFactory.fillColor(Color.GREEN), @@ -420,10 +422,10 @@ class RuntimeStyleActivity : AppCompatActivity() { ) ) ) - mapboxMap!!.style!!.addLayer(layer) + mapboxMap.style!!.addLayer(layer) // Get a good look at it all - mapboxMap!!.animateCamera(CameraUpdateFactory.zoomTo(12.0)) + mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(12.0)) // Animate the parks source animateParksSource(parks, 0) @@ -439,7 +441,7 @@ class RuntimeStyleActivity : AppCompatActivity() { Timber.d("Updating parks source") // change the source val park = if (counter < parks.features()!!.size - 1) counter else 0 - val source = mapboxMap!!.style!!.getSourceAs("dynamic-park-source") + val source = mapboxMap.style!!.getSourceAs("dynamic-park-source") if (source == null) { Timber.e("Source not found") Toast.makeText(this@RuntimeStyleActivity, "Source not found", Toast.LENGTH_SHORT) @@ -460,7 +462,7 @@ class RuntimeStyleActivity : AppCompatActivity() { private fun addTerrainLayer() { // Add a source val source: Source = VectorSource("my-terrain-source", "maptiler://sources/hillshades") - mapboxMap!!.style!!.addSource(source) + mapboxMap.style!!.addSource(source) var layer: LineLayer? = LineLayer("terrainLayer", "my-terrain-source") layer!!.sourceLayer = "contour" layer.setProperties( @@ -471,7 +473,7 @@ class RuntimeStyleActivity : AppCompatActivity() { ) // adding layers below "road" layers - val layers = mapboxMap!!.style!! + val layers = mapboxMap.style!! .layers var latestLayer: Layer? = null Collections.reverse(layers) @@ -487,16 +489,16 @@ class RuntimeStyleActivity : AppCompatActivity() { } } if (latestLayer != null) { - mapboxMap!!.style!!.addLayerBelow(layer, latestLayer.id) + mapboxMap.style!!.addLayerBelow(layer, latestLayer.id) } // Need to get a fresh handle - layer = mapboxMap!!.style!!.getLayerAs("terrainLayer") + layer = mapboxMap.style!!.getLayerAs("terrainLayer") // Make sure it's also applied after the fact layer!!.minZoom = 10f layer.maxZoom = 15f - layer = mapboxMap!!.style!!.getLayer("terrainLayer") as LineLayer? + layer = mapboxMap.style!!.getLayer("terrainLayer") as LineLayer? Toast.makeText( this, String.format( @@ -511,14 +513,14 @@ class RuntimeStyleActivity : AppCompatActivity() { private fun addSatelliteLayer() { // Add a source val source: Source = RasterSource("my-raster-source", "maptiler://sources/satellite", 512) - mapboxMap!!.style!!.addSource(source) + mapboxMap.style!!.addSource(source) // Add a layer - mapboxMap!!.style!!.addLayer(RasterLayer("satellite-layer", "my-raster-source")) + mapboxMap.style!!.addLayer(RasterLayer("satellite-layer", "my-raster-source")) } private fun updateWaterColorOnZoom() { - val layer = mapboxMap!!.style!!.getLayerAs("water") ?: return + val layer = mapboxMap.style!!.getLayerAs("water") ?: return // Set a zoom function to update the color of the water layer.setProperties( @@ -535,7 +537,7 @@ class RuntimeStyleActivity : AppCompatActivity() { ) // do some animations to show it off properly - mapboxMap!!.animateCamera(CameraUpdateFactory.zoomTo(1.0), 1500) + mapboxMap.animateCamera(CameraUpdateFactory.zoomTo(1.0), 1500) } private fun addCustomTileSource() { @@ -545,7 +547,7 @@ class RuntimeStyleActivity : AppCompatActivity() { tileSet.minZoom = 0f tileSet.maxZoom = 14f val source: Source = VectorSource("custom-tile-source", tileSet) - mapboxMap!!.style!!.addSource(source) + mapboxMap.style!!.addSource(source) // Add a layer val lineLayer = LineLayer("custom-tile-layers", "custom-tile-source") @@ -557,12 +559,12 @@ class RuntimeStyleActivity : AppCompatActivity() { PropertyFactory.lineWidth(2.0f), PropertyFactory.lineColor(Color.GREEN) ) - mapboxMap!!.style!!.addLayer(lineLayer) + mapboxMap.style!!.addLayer(lineLayer) } private fun styleFillColorLayer() { - mapboxMap!!.setStyle(Style.Builder().fromUri("asset://fill_color_style.json")) - mapboxMap!!.moveCamera( + mapboxMap.setStyle(Style.Builder().fromUri("asset://fill_color_style.json")) + mapboxMap.moveCamera( CameraUpdateFactory.newLatLngZoom( LatLng(31.0, (-100).toDouble()), 3.0 @@ -571,8 +573,8 @@ class RuntimeStyleActivity : AppCompatActivity() { } private fun styleFillFilterLayer() { - mapboxMap!!.setStyle(Style.Builder().fromUri("asset://fill_filter_style.json")) - mapboxMap!!.moveCamera( + mapboxMap.setStyle(Style.Builder().fromUri("asset://fill_filter_style.json")) + mapboxMap.moveCamera( CameraUpdateFactory.newLatLngZoom( LatLng(31.0, (-100).toDouble()), 3.0 @@ -585,7 +587,7 @@ class RuntimeStyleActivity : AppCompatActivity() { return@postDelayed } Timber.d("Styling filtered fill layer") - val states = mapboxMap!!.style!!.getLayer("states") as FillLayer? + val states = mapboxMap.style!!.getLayer("states") as FillLayer? if (states != null) { states.setFilter(Expression.eq(Expression.get("name"), Expression.literal("Texas"))) states.fillOpacityTransition = TransitionOptions(2500, 0) @@ -607,8 +609,8 @@ class RuntimeStyleActivity : AppCompatActivity() { } private fun styleTextSizeFilterLayer() { - mapboxMap!!.setStyle(Style.Builder().fromUri("asset://fill_filter_style.json")) - mapboxMap!!.moveCamera( + mapboxMap.setStyle(Style.Builder().fromUri("asset://fill_filter_style.json")) + mapboxMap.moveCamera( CameraUpdateFactory.newLatLngZoom( LatLng(31.0, (-100).toDouble()), 3.0 @@ -621,7 +623,7 @@ class RuntimeStyleActivity : AppCompatActivity() { return@postDelayed } Timber.d("Styling text size fill layer") - val states = mapboxMap!!.style!!.getLayer("state-label-lg") as SymbolLayer? + val states = mapboxMap.style!!.getLayer("state-label-lg") as SymbolLayer? if (states != null) { states.setProperties( PropertyFactory.textSize( @@ -650,8 +652,8 @@ class RuntimeStyleActivity : AppCompatActivity() { } private fun styleLineFilterLayer() { - mapboxMap!!.setStyle(Style.Builder().fromUri("asset://line_filter_style.json")) - mapboxMap!!.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(40.0, (-97).toDouble()), 5.0)) + mapboxMap.setStyle(Style.Builder().fromUri("asset://line_filter_style.json")) + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(40.0, (-97).toDouble()), 5.0)) val handler = Handler(mainLooper) handler.postDelayed( { @@ -659,7 +661,7 @@ class RuntimeStyleActivity : AppCompatActivity() { return@postDelayed } Timber.d("Styling filtered line layer") - val counties = mapboxMap!!.style!!.getLayer("counties") as LineLayer? + val counties = mapboxMap.style!!.getLayer("counties") as LineLayer? if (counties != null) { counties.setFilter(Expression.eq(Expression.get("NAME10"), "Washington")) counties.setProperties( @@ -680,8 +682,8 @@ class RuntimeStyleActivity : AppCompatActivity() { } private fun styleNumericFillLayer() { - mapboxMap!!.setStyle(Style.Builder().fromUri("asset://numeric_filter_style.json")) - mapboxMap!!.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(40.0, (-97).toDouble()), 5.0)) + mapboxMap.setStyle(Style.Builder().fromUri("asset://numeric_filter_style.json")) + mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(40.0, (-97).toDouble()), 5.0)) val handler = Handler(mainLooper) handler.postDelayed( { @@ -689,7 +691,7 @@ class RuntimeStyleActivity : AppCompatActivity() { return@postDelayed } Timber.d("Styling numeric fill layer") - val regions = mapboxMap!!.style!!.getLayer("regions") as FillLayer? + val regions = mapboxMap.style!!.getLayer("regions") as FillLayer? if (regions != null) { regions.setFilter( Expression.all( @@ -720,10 +722,10 @@ class RuntimeStyleActivity : AppCompatActivity() { } private fun bringWaterToFront() { - val water = mapboxMap!!.style!!.getLayer("water") + val water = mapboxMap.style!!.getLayer("water") if (water != null) { - mapboxMap!!.style!!.removeLayer(water) - mapboxMap!!.style!!.addLayerAt(water, mapboxMap!!.style!!.layers.size - 1) + mapboxMap.style!!.removeLayer(water) + mapboxMap.style!!.addLayerAt(water, mapboxMap.style!!.layers.size - 1) } else { Toast.makeText(this, "No water layer in this style", Toast.LENGTH_SHORT).show() } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTimingTestActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTimingTestActivity.kt index 47c91c95f..8307b6371 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTimingTestActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/RuntimeStyleTimingTestActivity.kt @@ -13,8 +13,8 @@ import com.mapbox.mapboxsdk.testapp.R * Test activity for unit test execution */ class RuntimeStyleTimingTestActivity : AppCompatActivity() { - var mapView: MapView? = null - var mapboxMap: MapboxMap? = null + lateinit var mapView: MapView + lateinit var mapboxMap: MapboxMap private set override fun onCreate(savedInstanceState: Bundle?) { @@ -23,8 +23,8 @@ class RuntimeStyleTimingTestActivity : AppCompatActivity() { // Initialize map as normal mapView = findViewById(R.id.mapView) as MapView - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> this@RuntimeStyleTimingTestActivity.mapboxMap = mapboxMap val parksLayer = CircleLayer("parks", "parks_source") parksLayer.sourceLayer = "parks" @@ -48,36 +48,36 @@ class RuntimeStyleTimingTestActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StretchableImageActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StretchableImageActivity.kt index 433f4972a..9c432c137 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StretchableImageActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StretchableImageActivity.kt @@ -22,7 +22,7 @@ import java.util.ArrayList * Test stretchable image as a background for text.. */ class StretchableImageActivity : AppCompatActivity(), OnMapReadyCallback { - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private lateinit var mapView: MapView public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -66,7 +66,7 @@ class StretchableImageActivity : AppCompatActivity(), OnMapReadyCallback { Timber.e("json is null.") return } - val style = mapboxMap!!.style + val style = mapboxMap.style if (style != null) { val featureCollection = FeatureCollection.fromJson(json) val stretchSource = GeoJsonSource(STRETCH_SOURCE, featureCollection) @@ -125,37 +125,37 @@ class StretchableImageActivity : AppCompatActivity(), OnMapReadyCallback { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StyleFileActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StyleFileActivity.kt index 38b031790..59a9e4a16 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StyleFileActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/StyleFileActivity.kt @@ -24,7 +24,7 @@ import java.lang.ref.WeakReference * Test activity showcasing how to use a file:// resource for the style.json and how to use MapboxMap#setStyleJson. */ class StyleFileActivity : AppCompatActivity() { - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private lateinit var mapView: MapView public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -33,8 +33,10 @@ class StyleFileActivity : AppCompatActivity() { mapView.onCreate(savedInstanceState) mapView.getMapAsync( OnMapReadyCallback { map: MapboxMap? -> - mapboxMap = map - mapboxMap!!.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? -> + if (map != null) { + mapboxMap = map + } + mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? -> val fab = findViewById(R.id.fab_file) fab.setColorFilter(ContextCompat.getColor(this@StyleFileActivity, R.color.primary)) fab.setOnClickListener { view: View -> @@ -149,36 +151,36 @@ class StyleFileActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolLayerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolLayerActivity.kt index 5d7154765..00900d2b6 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolLayerActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolLayerActivity.kt @@ -51,8 +51,8 @@ class SymbolLayerActivity : AppCompatActivity(), OnMapClickListener, OnMapReadyC private var markerSymbolLayer: SymbolLayer? = null private var mapboxSignSymbolLayer: SymbolLayer? = null private var numberFormatSymbolLayer: SymbolLayer? = null - private var mapboxMap: MapboxMap? = null - private var mapView: MapView? = null + private lateinit var mapboxMap: MapboxMap + private lateinit var mapView: MapView public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_symbollayer) @@ -69,13 +69,13 @@ class SymbolLayerActivity : AppCompatActivity(), OnMapClickListener, OnMapReadyC // Create map programmatically, add to view hierarchy mapView = MapView(this, mapboxMapOptions) - mapView!!.getMapAsync(this) - mapView!!.onCreate(savedInstanceState) + mapView.getMapAsync(this) + mapView.onCreate(savedInstanceState) (findViewById(R.id.container) as ViewGroup).addView(mapView) // Use OnStyleImageMissing API to lazily load an icon - mapView!!.addOnStyleImageMissingListener { id: String? -> - val style = mapboxMap!!.style + mapView.addOnStyleImageMissingListener { id: String? -> + val style = mapboxMap.style if (style != null) { Timber.e("Adding image with id: %s", id) val androidIcon = @@ -167,8 +167,8 @@ class SymbolLayerActivity : AppCompatActivity(), OnMapClickListener, OnMapReadyC override fun onMapClick(point: LatLng): Boolean { // Query which features are clicked - val screenLoc = mapboxMap!!.projection.toScreenLocation(point) - val markerFeatures = mapboxMap!!.queryRenderedFeatures(screenLoc, MARKER_LAYER) + val screenLoc = mapboxMap.projection.toScreenLocation(point) + val markerFeatures = mapboxMap.queryRenderedFeatures(screenLoc, MARKER_LAYER) if (!markerFeatures.isEmpty()) { for (feature in Objects.requireNonNull(markerCollection!!.features())!!) { if (feature.getStringProperty(ID_FEATURE_PROPERTY) @@ -195,7 +195,7 @@ class SymbolLayerActivity : AppCompatActivity(), OnMapClickListener, OnMapReadyC } markerSource!!.setGeoJson(markerCollection) } else { - val mapboxSignFeatures = mapboxMap!!.queryRenderedFeatures(screenLoc, MAPBOX_SIGN_LAYER) + val mapboxSignFeatures = mapboxMap.queryRenderedFeatures(screenLoc, MAPBOX_SIGN_LAYER) if (!mapboxSignFeatures.isEmpty()) { shuffleMapboxSign() } @@ -282,40 +282,40 @@ class SymbolLayerActivity : AppCompatActivity(), OnMapClickListener, OnMapReadyC override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() if (mapboxMap != null) { - mapboxMap!!.removeOnMapClickListener(this) + mapboxMap.removeOnMapClickListener(this) } - mapView!!.onDestroy() + mapView.onDestroy() } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.kt index 9c7dc7cfa..b5ad9949d 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/ZoomFunctionSymbolLayerActivity.kt @@ -26,20 +26,20 @@ import timber.log.Timber */ class ZoomFunctionSymbolLayerActivity : AppCompatActivity() { private lateinit var mapView: MapView - private var mapboxMap: MapboxMap? = null + private lateinit var mapboxMap: MapboxMap private var source: GeoJsonSource? = null private var layer: SymbolLayer? = null private var isInitialPosition = true private var isSelected = false private var isShowingSymbolLayer = true private val mapClickListener = OnMapClickListener { point -> - val screenPoint = mapboxMap!!.projection.toScreenLocation(point) - val featureList = mapboxMap!!.queryRenderedFeatures(screenPoint, LAYER_ID) + val screenPoint = mapboxMap.projection.toScreenLocation(point) + val featureList = mapboxMap.queryRenderedFeatures(screenPoint, LAYER_ID) if (!featureList.isEmpty()) { val feature = featureList[0] val selectedNow = feature.getBooleanProperty(KEY_PROPERTY_SELECTED) isSelected = !selectedNow - updateSource(mapboxMap!!.style) + updateSource(mapboxMap.style) } else { Timber.e("No features found") } @@ -123,7 +123,7 @@ class ZoomFunctionSymbolLayerActivity : AppCompatActivity() { if (mapboxMap != null) { if (item.itemId == R.id.menu_action_change_location) { isInitialPosition = !isInitialPosition - updateSource(mapboxMap!!.style) + updateSource(mapboxMap.style) } else if (item.itemId == R.id.menu_action_toggle_source) { toggleSymbolLayerVisibility() } @@ -133,37 +133,37 @@ class ZoomFunctionSymbolLayerActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } public override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } public override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewAnimationActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewAnimationActivity.kt index 4cd2ba698..d9f1b2591 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewAnimationActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewAnimationActivity.kt @@ -17,8 +17,8 @@ import java.util.* * Test animating a [android.view.TextureView] backed map. */ class TextureViewAnimationActivity : AppCompatActivity() { - private var mapView: MapView? = null - private var mapboxMap: MapboxMap? = null + private lateinit var mapView: MapView + private lateinit var mapboxMap: MapboxMap private var handler: Handler? = null private var delayed: Runnable? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -39,7 +39,7 @@ class TextureViewAnimationActivity : AppCompatActivity() { private fun setupMapView(savedInstanceState: Bundle?) { mapView = findViewById(R.id.mapView) as MapView - mapView!!.getMapAsync { mapboxMap: MapboxMap -> + mapView.getMapAsync { mapboxMap: MapboxMap -> this@TextureViewAnimationActivity.mapboxMap = mapboxMap mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) setFpsView(mapboxMap) @@ -86,22 +86,22 @@ class TextureViewAnimationActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() if (handler != null && delayed != null) { handler!!.removeCallbacks(delayed!!) } @@ -109,17 +109,17 @@ class TextureViewAnimationActivity : AppCompatActivity() { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } companion object { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewResizeActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewResizeActivity.kt index a4e2cd3a1..b0ebda7ee 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewResizeActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewResizeActivity.kt @@ -44,46 +44,46 @@ class TextureViewResizeActivity : AppCompatActivity() { fabDebug.setOnClickListener { view: View? -> if (mapView != null) { val parent = findViewById(R.id.coordinator_layout) - val width = if (parent.width == mapView!!.width) parent.width / 2 else parent.width + val width = if (parent.width == mapView.width) parent.width / 2 else parent.width val height = - if (parent.height == mapView!!.height) parent.height / 2 else parent.height - mapView!!.layoutParams = CoordinatorLayout.LayoutParams(width, height) + if (parent.height == mapView.height) parent.height / 2 else parent.height + mapView.layoutParams = CoordinatorLayout.LayoutParams(width, height) } } } override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewTransparentBackgroundActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewTransparentBackgroundActivity.kt index ec2c55a89..56b317fc4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewTransparentBackgroundActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/textureview/TextureViewTransparentBackgroundActivity.kt @@ -17,7 +17,7 @@ import java.io.IOException * Example showcasing how to create a TextureView with a transparent background. */ class TextureViewTransparentBackgroundActivity : AppCompatActivity() { - private var mapView: MapView? = null + private lateinit var mapView: MapView private val mapboxMap: MapboxMap? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -43,8 +43,8 @@ class TextureViewTransparentBackgroundActivity : AppCompatActivity() { .build() ) mapView = MapView(this, mapboxMapOptions) - mapView!!.onCreate(savedInstanceState) - mapView!!.getMapAsync { mapboxMap: MapboxMap -> initMap(mapboxMap) } + mapView.onCreate(savedInstanceState) + mapView.getMapAsync { mapboxMap: MapboxMap -> initMap(mapboxMap) } (findViewById(R.id.coordinator_layout) as ViewGroup).addView(mapView) } @@ -60,36 +60,36 @@ class TextureViewTransparentBackgroundActivity : AppCompatActivity() { override fun onStart() { super.onStart() - mapView!!.onStart() + mapView.onStart() } override fun onResume() { super.onResume() - mapView!!.onResume() + mapView.onResume() } override fun onPause() { super.onPause() - mapView!!.onPause() + mapView.onPause() } override fun onStop() { super.onStop() - mapView!!.onStop() + mapView.onStop() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - mapView!!.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) } override fun onDestroy() { super.onDestroy() - mapView!!.onDestroy() + mapView.onDestroy() } override fun onLowMemory() { super.onLowMemory() - mapView!!.onLowMemory() + mapView.onLowMemory() } }