(R.id.fab) as FloatingActionButton
+ fab.setColorFilter(ContextCompat.getColor(this, R.color.primary))
+ fab.setOnClickListener { view: View? ->
+ val visibility = layer.filter
+ if (visibility != null && visibility == visible) {
+ layer.setFilter(invisible)
+ fab.setImageResource(R.drawable.ic_layers_clear)
+ } else {
+ layer.setFilter(visible)
+ fab.setImageResource(R.drawable.ic_layers)
+ }
+ }
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.java
deleted file mode 100644
index c2de76ad6..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.fragment;
-
-import android.os.Bundle;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapFragment;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-/**
- * Test activity showcasing using the MapFragment API using SDK Fragments.
- *
- * Uses MapboxMapOptions to initialise the Fragment.
- *
- */
-public class MapFragmentActivity extends AppCompatActivity implements MapFragment.OnMapViewReadyCallback,
- OnMapReadyCallback, MapView.OnDidFinishRenderingFrameListener {
-
- private static final String TAG = "com.mapbox.map";
- private MapboxMap mapboxMap;
- private MapView mapView;
- private boolean initialCameraAnimation = true;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_map_fragment);
-
- MapFragment mapFragment;
- if (savedInstanceState == null) {
- mapFragment = MapFragment.newInstance(createFragmentOptions());
- getFragmentManager()
- .beginTransaction()
- .add(R.id.fragment_container, mapFragment, TAG)
- .commit();
- } else {
- mapFragment = (MapFragment) getFragmentManager().findFragmentByTag(TAG);
- }
- mapFragment.getMapAsync(this);
- }
-
- private MapboxMapOptions createFragmentOptions() {
- MapboxMapOptions options = MapboxMapOptions.createFromAttributes(this, null);
-
- options.scrollGesturesEnabled(false);
- options.zoomGesturesEnabled(false);
- options.tiltGesturesEnabled(false);
- options.rotateGesturesEnabled(false);
- options.debugActive(false);
-
- LatLng dc = new LatLng(38.90252, -77.02291);
-
- options.minZoomPreference(9);
- options.maxZoomPreference(11);
- options.camera(new CameraPosition.Builder()
- .target(dc)
- .zoom(11)
- .build());
- return options;
- }
-
- @Override
- public void onMapViewReady(MapView map) {
- mapView = map;
- mapView.addOnDidFinishRenderingFrameListener(this);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap map) {
- mapboxMap = map;
- mapboxMap.setStyle(Style.getPredefinedStyle("Outdoor"));
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (mapView != null) {
- mapView.removeOnDidFinishRenderingFrameListener(this);
- }
- }
-
- @Override
- public void onDidFinishRenderingFrame(boolean fully) {
- if (initialCameraAnimation && fully && mapboxMap != null) {
- mapboxMap.animateCamera(
- CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().tilt(45.0).build()), 5000);
- initialCameraAnimation = false;
- }
- }
-}
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
new file mode 100644
index 000000000..5b040ddd4
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MapFragmentActivity.kt
@@ -0,0 +1,93 @@
+package com.mapbox.mapboxsdk.testapp.activity.fragment
+
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import com.mapbox.mapboxsdk.camera.CameraPosition
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.* // ktlint-disable no-wildcard-imports
+import com.mapbox.mapboxsdk.maps.MapFragment.OnMapViewReadyCallback
+import com.mapbox.mapboxsdk.maps.MapView.OnDidFinishRenderingFrameListener
+import com.mapbox.mapboxsdk.testapp.R
+
+/**
+ * Test activity showcasing using the MapFragment API using SDK Fragments.
+ *
+ *
+ * Uses MapboxMapOptions to initialise the Fragment.
+ *
+ */
+class MapFragmentActivity :
+ AppCompatActivity(),
+ OnMapViewReadyCallback,
+ OnMapReadyCallback,
+ OnDidFinishRenderingFrameListener {
+ private var mapboxMap: MapboxMap? = null
+ private var mapView: MapView? = null
+ private var initialCameraAnimation = true
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_map_fragment)
+ val mapFragment: MapFragment
+ if (savedInstanceState == null) {
+ mapFragment = MapFragment.newInstance(createFragmentOptions())
+ fragmentManager
+ .beginTransaction()
+ .add(R.id.fragment_container, mapFragment, TAG)
+ .commit()
+ } else {
+ mapFragment = fragmentManager.findFragmentByTag(TAG) as MapFragment
+ }
+ mapFragment.getMapAsync(this)
+ }
+
+ private fun createFragmentOptions(): MapboxMapOptions {
+ val options = MapboxMapOptions.createFromAttributes(this, null)
+ options.scrollGesturesEnabled(false)
+ options.zoomGesturesEnabled(false)
+ options.tiltGesturesEnabled(false)
+ options.rotateGesturesEnabled(false)
+ options.debugActive(false)
+ val dc = LatLng(38.90252, -77.02291)
+ options.minZoomPreference(9.0)
+ options.maxZoomPreference(11.0)
+ options.camera(
+ CameraPosition.Builder()
+ .target(dc)
+ .zoom(11.0)
+ .build()
+ )
+ return options
+ }
+
+ override fun onMapViewReady(map: MapView) {
+ mapView = map
+ mapView!!.addOnDidFinishRenderingFrameListener(this)
+ }
+
+ override fun onMapReady(map: MapboxMap) {
+ mapboxMap = map
+ mapboxMap!!.setStyle(Style.getPredefinedStyle("Outdoor"))
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ if (mapView != null) {
+ mapView!!.removeOnDidFinishRenderingFrameListener(this)
+ }
+ }
+
+ override fun onDidFinishRenderingFrame(fully: Boolean) {
+ if (initialCameraAnimation && fully && mapboxMap != null) {
+ mapboxMap!!.animateCamera(
+ CameraUpdateFactory.newCameraPosition(CameraPosition.Builder().tilt(45.0).build()),
+ 5000
+ )
+ initialCameraAnimation = false
+ }
+ }
+
+ companion object {
+ private const val TAG = "com.mapbox.map"
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MultiMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MultiMapActivity.java
deleted file mode 100644
index b05e3e6c8..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MultiMapActivity.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.fragment;
-
-import android.os.Bundle;
-
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.fragment.app.FragmentManager;
-
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.maps.SupportMapFragment;
-import com.mapbox.mapboxsdk.testapp.R;
-
-/**
- * Test Activity showcasing using multiple static map fragments in one layout.
- */
-public class MultiMapActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_multi_map);
-
- FragmentManager fragmentManager = getSupportFragmentManager();
- initFragmentStyle(fragmentManager, R.id.map1, Style.getPredefinedStyle("Streets"));
- initFragmentStyle(fragmentManager, R.id.map2, Style.getPredefinedStyle("Bright"));
- initFragmentStyle(fragmentManager, R.id.map3, Style.getPredefinedStyle("Satellite Hybrid"));
- initFragmentStyle(fragmentManager, R.id.map4, Style.getPredefinedStyle("Pastel"));
- }
-
- private void initFragmentStyle(FragmentManager fragmentManager, int fragmentId, String styleId) {
- ((SupportMapFragment) fragmentManager.findFragmentById(fragmentId))
- .getMapAsync(mapboxMap -> mapboxMap.setStyle(styleId));
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MultiMapActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MultiMapActivity.kt
new file mode 100644
index 000000000..f9838b9da
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/MultiMapActivity.kt
@@ -0,0 +1,34 @@
+package com.mapbox.mapboxsdk.testapp.activity.fragment
+
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.FragmentManager
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.maps.SupportMapFragment
+import com.mapbox.mapboxsdk.testapp.R
+
+/**
+ * Test Activity showcasing using multiple static map fragments in one layout.
+ */
+class MultiMapActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_multi_map)
+ val fragmentManager = supportFragmentManager
+ initFragmentStyle(fragmentManager, R.id.map1, Style.getPredefinedStyle("Streets"))
+ initFragmentStyle(fragmentManager, R.id.map2, Style.getPredefinedStyle("Bright"))
+ initFragmentStyle(fragmentManager, R.id.map3, Style.getPredefinedStyle("Satellite Hybrid"))
+ initFragmentStyle(fragmentManager, R.id.map4, Style.getPredefinedStyle("Pastel"))
+ }
+
+ private fun initFragmentStyle(
+ fragmentManager: FragmentManager,
+ fragmentId: Int,
+ styleId: String
+ ) {
+ (fragmentManager.findFragmentById(fragmentId) as SupportMapFragment?)
+ ?.getMapAsync(OnMapReadyCallback { mapboxMap: MapboxMap -> mapboxMap.setStyle(styleId) })
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.java
deleted file mode 100644
index 5f1c138af..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.java
+++ /dev/null
@@ -1,98 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.fragment;
-
-import android.os.Bundle;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapFragment;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.maps.SupportMapFragment;
-import com.mapbox.mapboxsdk.testapp.R;
-
-/**
- * Test activity showcasing using the MapFragment API using Support Library Fragments.
- *
- * Uses MapboxMapOptions to initialise the Fragment.
- *
- */
-public class SupportMapFragmentActivity extends AppCompatActivity implements MapFragment.OnMapViewReadyCallback,
- OnMapReadyCallback, MapView.OnDidFinishRenderingFrameListener {
-
- private static final String TAG = "com.mapbox.map";
- private MapboxMap mapboxMap;
- private MapView mapView;
- private boolean initialCameraAnimation = true;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_map_fragment);
- SupportMapFragment mapFragment;
- if (savedInstanceState == null) {
- mapFragment = SupportMapFragment.newInstance(createFragmentOptions());
- getSupportFragmentManager()
- .beginTransaction()
- .add(R.id.fragment_container, mapFragment, TAG)
- .commit();
- } else {
- mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag(TAG);
- }
- mapFragment.getMapAsync(this);
-
- }
-
- private MapboxMapOptions createFragmentOptions() {
- MapboxMapOptions options = MapboxMapOptions.createFromAttributes(this, null);
-
- options.scrollGesturesEnabled(false);
- options.zoomGesturesEnabled(false);
- options.tiltGesturesEnabled(false);
- options.rotateGesturesEnabled(false);
- options.debugActive(false);
-
- LatLng dc = new LatLng(38.90252, -77.02291);
-
- options.minZoomPreference(9);
- options.maxZoomPreference(11);
- options.camera(new CameraPosition.Builder()
- .target(dc)
- .zoom(11)
- .build());
- return options;
- }
-
- @Override
- public void onMapViewReady(MapView map) {
- mapView = map;
- mapView.addOnDidFinishRenderingFrameListener(this);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap map) {
- mapboxMap = map;
- mapboxMap.setStyle(Style.getPredefinedStyle("Satellite Hybrid"));
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.removeOnDidFinishRenderingFrameListener(this);
- }
-
- @Override
- public void onDidFinishRenderingFrame(boolean fully) {
- if (initialCameraAnimation && fully && mapboxMap != null) {
- mapboxMap.animateCamera(
- CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().tilt(45.0).build()), 5000);
- initialCameraAnimation = false;
- }
- }
-}
\ No newline at end of file
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
new file mode 100644
index 000000000..4cfd44e40
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/fragment/SupportMapFragmentActivity.kt
@@ -0,0 +1,91 @@
+package com.mapbox.mapboxsdk.testapp.activity.fragment
+
+import android.os.Bundle // ktlint-disable import-ordering
+import androidx.appcompat.app.AppCompatActivity
+import com.mapbox.mapboxsdk.camera.CameraPosition
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.* // ktlint-disable no-wildcard-imports
+import com.mapbox.mapboxsdk.maps.MapFragment.OnMapViewReadyCallback
+import com.mapbox.mapboxsdk.maps.MapView.OnDidFinishRenderingFrameListener
+import com.mapbox.mapboxsdk.testapp.R
+
+/**
+ * Test activity showcasing using the MapFragment API using Support Library Fragments.
+ *
+ *
+ * Uses MapboxMapOptions to initialise the Fragment.
+ *
+ */
+class SupportMapFragmentActivity :
+ AppCompatActivity(),
+ OnMapViewReadyCallback,
+ OnMapReadyCallback,
+ OnDidFinishRenderingFrameListener {
+ private var mapboxMap: MapboxMap? = null
+ private var mapView: MapView? = null
+ private var initialCameraAnimation = true
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_map_fragment)
+ val mapFragment: SupportMapFragment?
+ if (savedInstanceState == null) {
+ mapFragment = SupportMapFragment.newInstance(createFragmentOptions())
+ supportFragmentManager
+ .beginTransaction()
+ .add(R.id.fragment_container, mapFragment, TAG)
+ .commit()
+ } else {
+ mapFragment = supportFragmentManager.findFragmentByTag(TAG) as SupportMapFragment?
+ }
+ mapFragment!!.getMapAsync(this)
+ }
+
+ private fun createFragmentOptions(): MapboxMapOptions {
+ val options = MapboxMapOptions.createFromAttributes(this, null)
+ options.scrollGesturesEnabled(false)
+ options.zoomGesturesEnabled(false)
+ options.tiltGesturesEnabled(false)
+ options.rotateGesturesEnabled(false)
+ options.debugActive(false)
+ val dc = LatLng(38.90252, -77.02291)
+ options.minZoomPreference(9.0)
+ options.maxZoomPreference(11.0)
+ options.camera(
+ CameraPosition.Builder()
+ .target(dc)
+ .zoom(11.0)
+ .build()
+ )
+ return options
+ }
+
+ override fun onMapViewReady(map: MapView) {
+ mapView = map
+ mapView!!.addOnDidFinishRenderingFrameListener(this)
+ }
+
+ override fun onMapReady(map: MapboxMap) {
+ mapboxMap = map
+ mapboxMap!!.setStyle(Style.getPredefinedStyle("Satellite Hybrid"))
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.removeOnDidFinishRenderingFrameListener(this)
+ }
+
+ override fun onDidFinishRenderingFrame(fully: Boolean) {
+ if (initialCameraAnimation && fully && mapboxMap != null) {
+ mapboxMap!!.animateCamera(
+ CameraUpdateFactory.newCameraPosition(CameraPosition.Builder().tilt(45.0).build()),
+ 5000
+ )
+ initialCameraAnimation = false
+ }
+ }
+
+ companion object {
+ private const val TAG = "com.mapbox.map"
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java
deleted file mode 100644
index e4f97f749..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.imagegenerator;
-
-import android.graphics.Bitmap;
-import android.os.Bundle;
-import android.view.View;
-
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.print.PrintHelper;
-
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-/**
- * Test activity showcasing using the Snaphot API to print a Map.
- */
-public class PrintActivity extends AppCompatActivity implements MapboxMap.SnapshotReadyCallback {
-
- private MapView mapView;
- private MapboxMap mapboxMap;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_print);
-
- mapView = findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(this::initMap);
-
- final View fab = findViewById(R.id.fab);
- if (fab != null) {
- fab.setOnClickListener(view -> {
- if (mapboxMap != null && mapboxMap.getStyle() != null) {
- mapboxMap.snapshot(PrintActivity.this);
- }
- });
- }
- }
-
- private void initMap(MapboxMap mapboxMap) {
- this.mapboxMap = mapboxMap;
- mapboxMap.setStyle(Style.getPredefinedStyle("Streets"));
- }
-
- @Override
- public void onSnapshotReady(Bitmap snapshot) {
- PrintHelper photoPrinter = new PrintHelper(this);
- photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
- photoPrinter.printBitmap("map.jpg - mapbox print job", snapshot);
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-}
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
new file mode 100644
index 000000000..c09dae976
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/PrintActivity.kt
@@ -0,0 +1,79 @@
+package com.mapbox.mapboxsdk.testapp.activity.imagegenerator
+
+import android.graphics.Bitmap
+import android.os.Bundle
+import android.view.View
+import androidx.appcompat.app.AppCompatActivity
+import androidx.print.PrintHelper
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+
+/**
+ * Test activity showcasing using the Snaphot API to print a Map.
+ */
+class PrintActivity : AppCompatActivity(), MapboxMap.SnapshotReadyCallback {
+ private lateinit var mapView: MapView
+ private lateinit var mapboxMap: MapboxMap
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_print)
+ mapView = findViewById(R.id.mapView)
+ mapView.onCreate(savedInstanceState)
+ 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)
+ }
+ }
+ }
+
+ private fun initMap(mapboxMap: MapboxMap) {
+ this.mapboxMap = mapboxMap
+ mapboxMap.setStyle(Style.getPredefinedStyle("Streets"))
+ }
+
+ override fun onSnapshotReady(snapshot: Bitmap) {
+ val photoPrinter = PrintHelper(this)
+ photoPrinter.scaleMode = PrintHelper.SCALE_MODE_FIT
+ photoPrinter.printBitmap("map.jpg - mapbox print job", snapshot)
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java
deleted file mode 100644
index 1b785c287..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.java
+++ /dev/null
@@ -1,159 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.infowindow;
-
-import android.graphics.Color;
-import android.os.Bundle;
-import android.widget.TextView;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.core.content.res.ResourcesCompat;
-
-import com.mapbox.mapboxsdk.annotations.InfoWindow;
-import com.mapbox.mapboxsdk.annotations.Marker;
-import com.mapbox.mapboxsdk.annotations.MarkerOptions;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-import com.mapbox.mapboxsdk.testapp.utils.IconUtils;
-
-import java.util.Locale;
-
-/**
- * Test activity showcasing how to dynamically update InfoWindow when Using an MapboxMap.InfoWindowAdapter.
- */
-public class DynamicInfoWindowAdapterActivity extends AppCompatActivity implements OnMapReadyCallback {
-
- private static final LatLng PARIS = new LatLng(48.864716, 2.349014);
-
- private MapboxMap mapboxMap;
- private MapView mapView;
- private Marker marker;
-
- private MapboxMap.OnMapClickListener mapClickListener = new MapboxMap.OnMapClickListener() {
- @Override
- public boolean onMapClick(@NonNull LatLng point) {
- if (marker == null) {
- return false;
- }
-
- // Distance from click to marker
- double distanceKm = marker.getPosition().distanceTo(point) / 1000;
-
- // Get the info window
- final InfoWindow infoWindow = marker.getInfoWindow();
-
- // Get the view from the info window
- if (infoWindow != null && infoWindow.getView() != null) {
- // Set the new text on the text view in the info window
- TextView textView = (TextView) infoWindow.getView();
- textView.setText(String.format(Locale.getDefault(), "%.2fkm", distanceKm));
- // Update the info window position (as the text length changes)
- textView.post(infoWindow::update);
- }
- return true;
- }
- };
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_infowindow_adapter);
-
- mapView = findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(this);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap map) {
- mapboxMap = map;
-
- map.setStyle(Style.getPredefinedStyle("Streets"));
-
- // Add info window adapter
- addCustomInfoWindowAdapter(mapboxMap);
-
- // Keep info windows open on click
- mapboxMap.getUiSettings().setDeselectMarkersOnTap(false);
-
- // Add a marker
- marker = addMarker(mapboxMap);
- mapboxMap.selectMarker(marker);
-
- // On map click, change the info window contents
- mapboxMap.addOnMapClickListener(mapClickListener);
-
- // Focus on Paris
- mapboxMap.animateCamera(CameraUpdateFactory.newLatLng(PARIS));
- }
-
- private Marker addMarker(MapboxMap mapboxMap) {
- return mapboxMap.addMarker(
- new MarkerOptions()
- .position(PARIS)
- .icon(IconUtils.drawableToIcon(this, R.drawable.ic_location_city,
- ResourcesCompat.getColor(getResources(), R.color.mapbox_blue, getTheme()))
- ));
- }
-
- private void addCustomInfoWindowAdapter(final MapboxMap mapboxMap) {
- final int padding = (int) getResources().getDimension(R.dimen.attr_margin);
- mapboxMap.setInfoWindowAdapter(marker -> {
- TextView textView = new TextView(DynamicInfoWindowAdapterActivity.this);
- textView.setText(marker.getTitle());
- textView.setBackgroundColor(Color.WHITE);
- textView.setText(R.string.action_calculate_distance);
- textView.setPadding(padding, padding, padding, padding);
- return textView;
- });
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (mapboxMap != null) {
- mapboxMap.removeOnMapClickListener(mapClickListener);
- }
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.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
new file mode 100644
index 000000000..cb0debd04
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/DynamicInfoWindowAdapterActivity.kt
@@ -0,0 +1,147 @@
+package com.mapbox.mapboxsdk.testapp.activity.infowindow
+
+import android.graphics.Color
+import android.os.Bundle
+import android.widget.TextView
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.content.res.ResourcesCompat
+import com.mapbox.mapboxsdk.annotations.Marker
+import com.mapbox.mapboxsdk.annotations.MarkerOptions
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.MapboxMap.InfoWindowAdapter
+import com.mapbox.mapboxsdk.maps.MapboxMap.OnMapClickListener
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+import com.mapbox.mapboxsdk.testapp.utils.IconUtils
+import java.util.*
+
+/**
+ * Test activity showcasing how to dynamically update InfoWindow when Using an MapboxMap.InfoWindowAdapter.
+ */
+class DynamicInfoWindowAdapterActivity : AppCompatActivity(), OnMapReadyCallback {
+ private lateinit var mapboxMap: MapboxMap
+ private lateinit var mapView: MapView
+ private var marker: Marker? = null
+ private val mapClickListener = OnMapClickListener { point ->
+ if (marker == null) {
+ return@OnMapClickListener false
+ }
+
+ // Distance from click to marker
+ val distanceKm = marker!!.position.distanceTo(point) / 1000
+
+ // Get the info window
+ val infoWindow = marker!!.infoWindow
+
+ // Get the view from the info window
+ if (infoWindow != null && infoWindow.view != null) {
+ // Set the new text on the text view in the info window
+ val textView = infoWindow.view as TextView?
+ textView!!.text = String.format(Locale.getDefault(), "%.2fkm", distanceKm)
+ // Update the info window position (as the text length changes)
+ textView.post { infoWindow.update() }
+ }
+ true
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_infowindow_adapter)
+ mapView = findViewById(R.id.mapView)
+ mapView.onCreate(savedInstanceState)
+ mapView.getMapAsync(this)
+ }
+
+ override fun onMapReady(map: MapboxMap) {
+ mapboxMap = map
+ map.setStyle(Style.getPredefinedStyle("Streets"))
+
+ // Add info window adapter
+ addCustomInfoWindowAdapter(mapboxMap!!)
+
+ // Keep info windows open on click
+ mapboxMap!!.uiSettings.isDeselectMarkersOnTap = false
+
+ // Add a marker
+ marker = addMarker(mapboxMap!!)
+ mapboxMap!!.selectMarker(marker!!)
+
+ // On map click, change the info window contents
+ mapboxMap!!.addOnMapClickListener(mapClickListener)
+
+ // Focus on Paris
+ mapboxMap!!.animateCamera(CameraUpdateFactory.newLatLng(PARIS))
+ }
+
+ private fun addMarker(mapboxMap: MapboxMap): Marker {
+ return mapboxMap.addMarker(
+ MarkerOptions()
+ .position(PARIS)
+ .icon(
+ IconUtils.drawableToIcon(
+ this,
+ R.drawable.ic_location_city,
+ ResourcesCompat.getColor(resources, R.color.mapbox_blue, theme)
+ )
+ )
+ )
+ }
+
+ private fun addCustomInfoWindowAdapter(mapboxMap: MapboxMap) {
+ val padding = resources.getDimension(R.dimen.attr_margin).toInt()
+ mapboxMap.infoWindowAdapter = InfoWindowAdapter { marker: Marker ->
+ val textView = TextView(this@DynamicInfoWindowAdapterActivity)
+ textView.text = marker.title
+ textView.setBackgroundColor(Color.WHITE)
+ textView.setText(R.string.action_calculate_distance)
+ textView.setPadding(padding, padding, padding, padding)
+ textView
+ }
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ if (mapboxMap != null) {
+ mapboxMap!!.removeOnMapClickListener(mapClickListener)
+ }
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+
+ companion object {
+ private val PARIS = LatLng(48.864716, 2.349014)
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.java
deleted file mode 100644
index b0b3e3662..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.java
+++ /dev/null
@@ -1,200 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.infowindow;
-
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mapbox.mapboxsdk.annotations.Marker;
-import com.mapbox.mapboxsdk.annotations.MarkerOptions;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-import java.text.DecimalFormat;
-
-/**
- * Test activity showcasing using the InfoWindow API above Washington D.C.
- *
- * Allows to test mulitple concurrently open InfoWindows.
- *
- */
-public class InfoWindowActivity extends AppCompatActivity
- implements OnMapReadyCallback, MapboxMap.OnInfoWindowCloseListener, MapboxMap.OnInfoWindowClickListener,
- MapboxMap.OnInfoWindowLongClickListener {
-
- private MapboxMap mapboxMap;
- private MapView mapView;
- private Marker customMarker;
-
- private MapboxMap.OnMapLongClickListener mapLongClickListener = new MapboxMap.OnMapLongClickListener() {
- @Override
- public boolean onMapLongClick(@NonNull LatLng point) {
- if (customMarker != null) {
- // Remove previous added marker
- mapboxMap.removeAnnotation(customMarker);
- customMarker = null;
- }
-
- // Add marker on long click location with default marker image
- customMarker = mapboxMap.addMarker(new MarkerOptions()
- .title("Custom Marker")
- .snippet(new DecimalFormat("#.#####").format(point.getLatitude()) + ", "
- + new DecimalFormat("#.#####").format(point.getLongitude()))
- .position(point));
- return true;
- }
- };
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_infowindow);
-
- mapView = (MapView) findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(this);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- this.mapboxMap = mapboxMap;
- mapboxMap.setStyle(Style.getPredefinedStyle("Streets"), style -> {
- addMarkers();
- addInfoWindowListeners();
- });
- }
-
- private void addMarkers() {
- mapboxMap.addMarker(new MarkerOptions()
- .title("Intersection")
- .snippet("H St NW with 15th St NW")
- .position(new LatLng(38.9002073, -77.03364419)));
-
- mapboxMap.addMarker(new MarkerOptions().title("Intersection")
- .snippet("E St NW with 17th St NW")
- .position(new LatLng(38.8954236, -77.0394623)));
-
- mapboxMap.addMarker(new MarkerOptions().title("The Ellipse").position(new LatLng(38.89393, -77.03654)));
-
- mapboxMap.addMarker(new MarkerOptions().position(new LatLng(38.89596, -77.03434)));
-
- mapboxMap.addMarker(new MarkerOptions().snippet("Lafayette Square").position(new LatLng(38.89949, -77.03656)));
-
- Marker marker = mapboxMap.addMarker(new MarkerOptions()
- .title("White House")
- .snippet("The official residence and principal workplace of the President of the United States, "
- + "located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every"
- + "U.S. president since John Adams in 1800.")
- .position(new LatLng(38.897705003219784, -77.03655168667463)));
-
- // open InfoWindow at startup
- mapboxMap.selectMarker(marker);
- }
-
- private void addInfoWindowListeners() {
- mapboxMap.setOnInfoWindowCloseListener(this);
- mapboxMap.addOnMapLongClickListener(mapLongClickListener);
- mapboxMap.setOnInfoWindowClickListener(this);
- mapboxMap.setOnInfoWindowLongClickListener(this);
- }
-
- private void toggleConcurrentInfoWindow(boolean allowConcurrentInfoWindow) {
- mapboxMap.deselectMarkers();
- mapboxMap.setAllowConcurrentMultipleOpenInfoWindows(allowConcurrentInfoWindow);
- }
-
- private void toggleDeselectMarkersOnTap(boolean deselectMarkersOnTap) {
- mapboxMap.getUiSettings().setDeselectMarkersOnTap(deselectMarkersOnTap);
- }
-
- @Override
- public boolean onInfoWindowClick(@NonNull Marker marker) {
- Toast.makeText(getApplicationContext(), "OnClick: " + marker.getTitle(), Toast.LENGTH_LONG).show();
- // returning true will leave the info window open
- return false;
- }
-
- @Override
- public void onInfoWindowClose(Marker marker) {
- Toast.makeText(getApplicationContext(), "OnClose: " + marker.getTitle(), Toast.LENGTH_LONG).show();
- }
-
- @Override
- public void onInfoWindowLongClick(Marker marker) {
- Toast.makeText(getApplicationContext(), "OnLongClick: " + marker.getTitle(), Toast.LENGTH_LONG).show();
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (mapboxMap != null) {
- mapboxMap.removeOnMapLongClickListener(mapLongClickListener);
- }
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_infowindow, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.action_toggle_concurrent_infowindow:
- toggleConcurrentInfoWindow(!item.isChecked());
- item.setChecked(!item.isChecked());
- return true;
- case R.id.action_toggle_deselect_markers_on_tap:
- toggleDeselectMarkersOnTap(!item.isChecked());
- item.setChecked(!item.isChecked());
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-}
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
new file mode 100644
index 000000000..c53f18632
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowActivity.kt
@@ -0,0 +1,197 @@
+package com.mapbox.mapboxsdk.testapp.activity.infowindow
+
+import android.os.Bundle
+import android.view.Menu
+import android.view.MenuItem
+import android.view.View
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import com.mapbox.mapboxsdk.annotations.Marker
+import com.mapbox.mapboxsdk.annotations.MarkerOptions
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowClickListener
+import com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowCloseListener
+import com.mapbox.mapboxsdk.maps.MapboxMap.OnInfoWindowLongClickListener
+import com.mapbox.mapboxsdk.maps.MapboxMap.OnMapLongClickListener
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+import java.text.DecimalFormat
+
+/**
+ * Test activity showcasing using the InfoWindow API above Washington D.C.
+ *
+ *
+ * Allows to test mulitple concurrently open InfoWindows.
+ *
+ */
+class InfoWindowActivity :
+ AppCompatActivity(),
+ OnMapReadyCallback,
+ OnInfoWindowCloseListener,
+ OnInfoWindowClickListener,
+ OnInfoWindowLongClickListener {
+ private var mapboxMap: MapboxMap? = null
+ private var mapView: MapView? = null
+ private var customMarker: Marker? = null
+ private val mapLongClickListener = OnMapLongClickListener { point ->
+ if (customMarker != null) {
+ // Remove previous added marker
+ mapboxMap!!.removeAnnotation(customMarker!!)
+ customMarker = null
+ }
+
+ // Add marker on long click location with default marker image
+ customMarker = mapboxMap!!.addMarker(
+ MarkerOptions()
+ .title("Custom Marker")
+ .snippet(
+ DecimalFormat("#.#####").format(point.latitude) + ", " +
+ DecimalFormat("#.#####").format(point.longitude)
+ )
+ .position(point)
+ )
+ true
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_infowindow)
+ mapView = findViewById(R.id.mapView) as MapView
+ mapView!!.onCreate(savedInstanceState)
+ mapView!!.getMapAsync(this)
+ }
+
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ this.mapboxMap = mapboxMap
+ mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? ->
+ addMarkers()
+ addInfoWindowListeners()
+ }
+ }
+
+ private fun addMarkers() {
+ mapboxMap!!.addMarker(
+ MarkerOptions()
+ .title("Intersection")
+ .snippet("H St NW with 15th St NW")
+ .position(LatLng(38.9002073, -77.03364419))
+ )
+ mapboxMap!!.addMarker(
+ MarkerOptions().title("Intersection")
+ .snippet("E St NW with 17th St NW")
+ .position(LatLng(38.8954236, -77.0394623))
+ )
+ mapboxMap!!.addMarker(
+ MarkerOptions().title("The Ellipse").position(LatLng(38.89393, -77.03654))
+ )
+ 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(
+ MarkerOptions()
+ .title("White House")
+ .snippet(
+ "The official residence and principal workplace of the President of the United States, " +
+ "located at 1600 Pennsylvania Avenue NW in Washington, D.C. It has been the residence of every" +
+ "U.S. president since John Adams in 1800."
+ )
+ .position(LatLng(38.897705003219784, -77.03655168667463))
+ )
+
+ // open InfoWindow at startup
+ mapboxMap!!.selectMarker(marker)
+ }
+
+ private fun addInfoWindowListeners() {
+ mapboxMap!!.onInfoWindowCloseListener = this
+ mapboxMap!!.addOnMapLongClickListener(mapLongClickListener)
+ mapboxMap!!.onInfoWindowClickListener = this
+ mapboxMap!!.onInfoWindowLongClickListener = this
+ }
+
+ private fun toggleConcurrentInfoWindow(allowConcurrentInfoWindow: Boolean) {
+ mapboxMap!!.deselectMarkers()
+ mapboxMap!!.isAllowConcurrentMultipleOpenInfoWindows = allowConcurrentInfoWindow
+ }
+
+ private fun toggleDeselectMarkersOnTap(deselectMarkersOnTap: Boolean) {
+ mapboxMap!!.uiSettings.isDeselectMarkersOnTap = deselectMarkersOnTap
+ }
+
+ override fun onInfoWindowClick(marker: Marker): Boolean {
+ Toast.makeText(applicationContext, "OnClick: " + marker.title, Toast.LENGTH_LONG).show()
+ // returning true will leave the info window open
+ return false
+ }
+
+ override fun onInfoWindowClose(marker: Marker) {
+ Toast.makeText(applicationContext, "OnClose: " + marker.title, Toast.LENGTH_LONG).show()
+ }
+
+ override fun onInfoWindowLongClick(marker: Marker) {
+ Toast.makeText(applicationContext, "OnLongClick: " + marker.title, Toast.LENGTH_LONG).show()
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ if (mapboxMap != null) {
+ mapboxMap!!.removeOnMapLongClickListener(mapLongClickListener)
+ }
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
+ menuInflater.inflate(R.menu.menu_infowindow, menu)
+ return true
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ return when (item.itemId) {
+ R.id.action_toggle_concurrent_infowindow -> {
+ toggleConcurrentInfoWindow(!item.isChecked)
+ item.isChecked = !item.isChecked
+ true
+ }
+ R.id.action_toggle_deselect_markers_on_tap -> {
+ toggleDeselectMarkersOnTap(!item.isChecked)
+ item.isChecked = !item.isChecked
+ true
+ }
+ else -> super.onOptionsItemSelected(item)
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java
deleted file mode 100644
index ac7db0740..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.infowindow;
-
-import android.graphics.Color;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.TextView;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mapbox.mapboxsdk.annotations.Icon;
-import com.mapbox.mapboxsdk.annotations.Marker;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-import com.mapbox.mapboxsdk.testapp.model.annotations.CityStateMarker;
-import com.mapbox.mapboxsdk.testapp.model.annotations.CityStateMarkerOptions;
-import com.mapbox.mapboxsdk.testapp.utils.IconUtils;
-
-/**
- * Test activity showcasing using an InfoWindowAdapter to provide a custom InfoWindow content.
- */
-public class InfoWindowAdapterActivity extends AppCompatActivity {
-
- private MapView mapView;
- private MapboxMap mapboxMap;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_infowindow_adapter);
-
- mapView = findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(map -> {
- mapboxMap = map;
- map.setStyle(Style.getPredefinedStyle("Streets"), style -> {
- addMarkers();
- addCustomInfoWindowAdapter();
- });
- });
- }
-
- private void 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(generateCityStateMarker("Vatican City", 41.902916, 12.453389, "#009688"));
- mapboxMap.addMarker(generateCityStateMarker("San Marino", 43.942360, 12.457777, "#795548"));
- mapboxMap.addMarker(generateCityStateMarker("Liechtenstein", 47.166000, 9.555373, "#FF5722"));
- }
-
- private CityStateMarkerOptions generateCityStateMarker(String title, double lat, double lng, String color) {
- CityStateMarkerOptions marker = new CityStateMarkerOptions();
- marker.title(title);
- marker.position(new LatLng(lat, lng));
- marker.infoWindowBackground(color);
-
- Icon icon = IconUtils.drawableToIcon(this, R.drawable.ic_location_city, Color.parseColor(color));
- marker.icon(icon);
- return marker;
- }
-
- private void addCustomInfoWindowAdapter() {
- mapboxMap.setInfoWindowAdapter(new MapboxMap.InfoWindowAdapter() {
-
- private int tenDp = (int) getResources().getDimension(R.dimen.attr_margin);
-
- @Override
- public View getInfoWindow(@NonNull Marker marker) {
- TextView textView = new TextView(InfoWindowAdapterActivity.this);
- textView.setText(marker.getTitle());
- textView.setTextColor(Color.WHITE);
-
- if (marker instanceof CityStateMarker) {
- CityStateMarker cityStateMarker = (CityStateMarker) marker;
- textView.setBackgroundColor(Color.parseColor(cityStateMarker.getInfoWindowBackgroundColor()));
- }
-
- textView.setPadding(tenDp, tenDp, tenDp, tenDp);
- return textView;
- }
- });
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-}
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
new file mode 100644
index 000000000..48556d9ad
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/infowindow/InfoWindowAdapterActivity.kt
@@ -0,0 +1,138 @@
+package com.mapbox.mapboxsdk.testapp.activity.infowindow
+
+import android.graphics.Color
+import android.os.Bundle
+import android.view.View
+import android.widget.TextView
+import androidx.appcompat.app.AppCompatActivity
+import com.mapbox.mapboxsdk.annotations.Marker
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.MapboxMap.InfoWindowAdapter
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+import com.mapbox.mapboxsdk.testapp.model.annotations.CityStateMarker
+import com.mapbox.mapboxsdk.testapp.model.annotations.CityStateMarkerOptions
+import com.mapbox.mapboxsdk.testapp.utils.IconUtils
+
+/**
+ * Test activity showcasing using an InfoWindowAdapter to provide a custom InfoWindow content.
+ */
+class InfoWindowAdapterActivity : AppCompatActivity() {
+ private lateinit var mapView: MapView
+ private lateinit var mapboxMap: MapboxMap
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_infowindow_adapter)
+ mapView = findViewById(R.id.mapView)
+ mapView.onCreate(savedInstanceState)
+ mapView.getMapAsync(
+ OnMapReadyCallback { map: MapboxMap ->
+ mapboxMap = map
+ map.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? ->
+ addMarkers()
+ addCustomInfoWindowAdapter()
+ }
+ }
+ )
+ }
+
+ 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(
+ generateCityStateMarker(
+ "Vatican City",
+ 41.902916,
+ 12.453389,
+ "#009688"
+ )
+ )
+ mapboxMap!!.addMarker(
+ generateCityStateMarker(
+ "San Marino",
+ 43.942360,
+ 12.457777,
+ "#795548"
+ )
+ )
+ mapboxMap!!.addMarker(
+ generateCityStateMarker(
+ "Liechtenstein",
+ 47.166000,
+ 9.555373,
+ "#FF5722"
+ )
+ )
+ }
+
+ private fun generateCityStateMarker(
+ title: String,
+ lat: Double,
+ lng: Double,
+ color: String
+ ): CityStateMarkerOptions {
+ val marker = CityStateMarkerOptions()
+ marker.title(title)
+ marker.position(LatLng(lat, lng))
+ marker.infoWindowBackground(color)
+ val icon =
+ IconUtils.drawableToIcon(this, R.drawable.ic_location_city, Color.parseColor(color))
+ marker.icon(icon)
+ return marker
+ }
+
+ private fun addCustomInfoWindowAdapter() {
+ 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)
+ textView.text = marker.title
+ textView.setTextColor(Color.WHITE)
+ if (marker is CityStateMarker) {
+ textView.setBackgroundColor(Color.parseColor(marker.infoWindowBackgroundColor))
+ }
+ textView.setPadding(tenDp, tenDp, tenDp, tenDp)
+ return textView
+ }
+ }
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/BasicLocationPulsingCircleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/BasicLocationPulsingCircleActivity.java
deleted file mode 100644
index 28e865559..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/BasicLocationPulsingCircleActivity.java
+++ /dev/null
@@ -1,215 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.location;
-
-import android.annotation.SuppressLint;
-import android.location.Location;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mapbox.mapboxsdk.location.LocationComponent;
-import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
-import com.mapbox.mapboxsdk.location.LocationComponentOptions;
-import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest;
-import com.mapbox.mapboxsdk.location.modes.CameraMode;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsListener;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsManager;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-import java.util.List;
-
-import static com.mapbox.mapboxsdk.testapp.activity.location.Utils.getNextStyle;
-
-/**
- * This activity shows a basic usage of the LocationComponent's pulsing circle. There's no
- * customization of the pulsing circle's color, radius, speed, etc.
- */
-public class BasicLocationPulsingCircleActivity extends AppCompatActivity implements OnMapReadyCallback {
-
- private static final String SAVED_STATE_LOCATION = "saved_state_location";
- private static final String TAG = "Mbgl-BasicLocationPulsingCircleActivity";
-
- private Location lastLocation;
- private MapView mapView;
- private PermissionsManager permissionsManager;
- private LocationComponent locationComponent;
- private MapboxMap mapboxMap;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_location_layer_basic_pulsing_circle);
-
- mapView = findViewById(R.id.mapView);
-
- if (savedInstanceState != null) {
- lastLocation = savedInstanceState.getParcelable(SAVED_STATE_LOCATION);
- }
- mapView.onCreate(savedInstanceState);
-
- checkPermissions();
- }
-
- @SuppressLint("MissingPermission")
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- this.mapboxMap = mapboxMap;
-
- mapboxMap.setStyle(Style.getPredefinedStyle("Streets"), style -> {
- locationComponent = mapboxMap.getLocationComponent();
-
- LocationComponentOptions locationComponentOptions =
- LocationComponentOptions.builder(BasicLocationPulsingCircleActivity.this)
- .pulseEnabled(true)
- .build();
-
- LocationComponentActivationOptions locationComponentActivationOptions =
- buildLocationComponentActivationOptions(style,locationComponentOptions);
-
- locationComponent.activateLocationComponent(locationComponentActivationOptions);
- locationComponent.setLocationComponentEnabled(true);
- locationComponent.setCameraMode(CameraMode.TRACKING);
- locationComponent.forceLocationUpdate(lastLocation);
- });
- }
-
- private LocationComponentActivationOptions buildLocationComponentActivationOptions(@NonNull Style style,
- @NonNull LocationComponentOptions
- locationComponentOptions) {
- return LocationComponentActivationOptions
- .builder(this, style)
- .locationComponentOptions(locationComponentOptions)
- .useDefaultLocationEngine(true)
- .locationEngineRequest(new LocationEngineRequest.Builder(750)
- .setFastestInterval(750)
- .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
- .build())
- .build();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_pulsing_location_mode, menu);
- return true;
- }
-
- @SuppressLint("MissingPermission")
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (locationComponent == null) {
- return super.onOptionsItemSelected(item);
- }
-
- int id = item.getItemId();
- if (id == R.id.action_map_style_change) {
- loadNewStyle();
- return true;
- } else if (id == R.id.action_component_disable) {
- locationComponent.setLocationComponentEnabled(false);
- return true;
- } else if (id == R.id.action_component_enabled) {
- locationComponent.setLocationComponentEnabled(true);
- return true;
- } else if (id == R.id.action_stop_pulsing) {
- locationComponent.applyStyle(LocationComponentOptions.builder(
- BasicLocationPulsingCircleActivity.this)
- .pulseEnabled(false)
- .build());
- return true;
- } else if (id == R.id.action_start_pulsing) {
- locationComponent.applyStyle(LocationComponentOptions.builder(
- BasicLocationPulsingCircleActivity.this)
- .pulseEnabled(true)
- .build());
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- private void loadNewStyle() {
- mapboxMap.setStyle(new Style.Builder().fromUri(getNextStyle()));
- }
-
- private void checkPermissions() {
- if (PermissionsManager.areLocationPermissionsGranted(this)) {
- mapView.getMapAsync(this);
- } else {
- permissionsManager = new PermissionsManager(new PermissionsListener() {
- @Override
- public void onExplanationNeeded(List permissionsToExplain) {
- Toast.makeText(BasicLocationPulsingCircleActivity.this, "You need to accept location permissions.",
- Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onPermissionResult(boolean granted) {
- if (granted) {
- mapView.getMapAsync(BasicLocationPulsingCircleActivity.this);
- } else {
- finish();
- }
- }
- });
- permissionsManager.requestLocationPermissions(this);
- }
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @SuppressLint("MissingPermission")
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- if (locationComponent != null) {
- outState.putParcelable(SAVED_STATE_LOCATION, locationComponent.getLastKnownLocation());
- }
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-}
\ No newline at end of file
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
new file mode 100644
index 000000000..fd1c143fe
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/BasicLocationPulsingCircleActivity.kt
@@ -0,0 +1,202 @@
+package com.mapbox.mapboxsdk.testapp.activity.location
+
+import android.annotation.SuppressLint
+import android.location.Location
+import android.os.Bundle
+import android.view.Menu
+import android.view.MenuItem
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import com.mapbox.mapboxsdk.location.LocationComponent
+import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions
+import com.mapbox.mapboxsdk.location.LocationComponentOptions
+import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest
+import com.mapbox.mapboxsdk.location.modes.CameraMode
+import com.mapbox.mapboxsdk.location.permissions.PermissionsListener
+import com.mapbox.mapboxsdk.location.permissions.PermissionsManager
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+
+/**
+ * This activity shows a basic usage of the LocationComponent's pulsing circle. There's no
+ * customization of the pulsing circle's color, radius, speed, etc.
+ */
+class BasicLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyCallback {
+ private var lastLocation: Location? = null
+ private lateinit var mapView: MapView
+ private var permissionsManager: PermissionsManager? = null
+ private var locationComponent: LocationComponent? = null
+ private var mapboxMap: MapboxMap? = null
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_location_layer_basic_pulsing_circle)
+ mapView = findViewById(R.id.mapView)
+ if (savedInstanceState != null) {
+ lastLocation = savedInstanceState.getParcelable(SAVED_STATE_LOCATION)
+ }
+ mapView.onCreate(savedInstanceState)
+ checkPermissions()
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ this.mapboxMap = mapboxMap
+ mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style: Style ->
+ locationComponent = mapboxMap.locationComponent
+ val locationComponentOptions =
+ LocationComponentOptions.builder(this@BasicLocationPulsingCircleActivity)
+ .pulseEnabled(true)
+ .build()
+ val locationComponentActivationOptions =
+ buildLocationComponentActivationOptions(style, locationComponentOptions)
+ locationComponent!!.activateLocationComponent(locationComponentActivationOptions)
+ locationComponent!!.isLocationComponentEnabled = true
+ locationComponent!!.cameraMode = CameraMode.TRACKING
+ locationComponent!!.forceLocationUpdate(lastLocation)
+ }
+ }
+
+ private fun buildLocationComponentActivationOptions(
+ style: Style,
+ locationComponentOptions: LocationComponentOptions
+ ): LocationComponentActivationOptions {
+ return LocationComponentActivationOptions
+ .builder(this, style)
+ .locationComponentOptions(locationComponentOptions)
+ .useDefaultLocationEngine(true)
+ .locationEngineRequest(
+ LocationEngineRequest.Builder(750)
+ .setFastestInterval(750)
+ .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
+ .build()
+ )
+ .build()
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
+ menuInflater.inflate(R.menu.menu_pulsing_location_mode, menu)
+ return true
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ if (locationComponent == null) {
+ return super.onOptionsItemSelected(item)
+ }
+ val id = item.itemId
+ if (id == R.id.action_map_style_change) {
+ loadNewStyle()
+ return true
+ } else if (id == R.id.action_component_disable) {
+ locationComponent!!.isLocationComponentEnabled = false
+ return true
+ } else if (id == R.id.action_component_enabled) {
+ locationComponent!!.isLocationComponentEnabled = true
+ return true
+ } else if (id == R.id.action_stop_pulsing) {
+ locationComponent!!.applyStyle(
+ LocationComponentOptions.builder(
+ this@BasicLocationPulsingCircleActivity
+ )
+ .pulseEnabled(false)
+ .build()
+ )
+ return true
+ } else if (id == R.id.action_start_pulsing) {
+ locationComponent!!.applyStyle(
+ LocationComponentOptions.builder(
+ this@BasicLocationPulsingCircleActivity
+ )
+ .pulseEnabled(true)
+ .build()
+ )
+ return true
+ }
+ return super.onOptionsItemSelected(item)
+ }
+
+ private fun loadNewStyle() {
+ mapboxMap!!.setStyle(Style.Builder().fromUri(Utils.nextStyle()))
+ }
+
+ private fun checkPermissions() {
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ mapView!!.getMapAsync(this)
+ } else {
+ permissionsManager = PermissionsManager(object : PermissionsListener {
+ override fun onExplanationNeeded(permissionsToExplain: List) {
+ Toast.makeText(
+ this@BasicLocationPulsingCircleActivity,
+ "You need to accept location permissions.",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+
+ override fun onPermissionResult(granted: Boolean) {
+ if (granted) {
+ mapView!!.getMapAsync(this@BasicLocationPulsingCircleActivity)
+ } else {
+ finish()
+ }
+ }
+ })
+ permissionsManager!!.requestLocationPermissions(this)
+ }
+ }
+
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array,
+ grantResults: IntArray
+ ) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ permissionsManager!!.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ if (locationComponent != null) {
+ outState.putParcelable(SAVED_STATE_LOCATION, locationComponent!!.lastKnownLocation)
+ }
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+
+ companion object {
+ private const val SAVED_STATE_LOCATION = "saved_state_location"
+ private const val TAG = "Mbgl-BasicLocationPulsingCircleActivity"
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/CustomizedLocationPulsingCircleActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/CustomizedLocationPulsingCircleActivity.java
deleted file mode 100644
index 7aa1746c0..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/CustomizedLocationPulsingCircleActivity.java
+++ /dev/null
@@ -1,360 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.location;
-
-import android.annotation.SuppressLint;
-import android.graphics.Color;
-import android.location.Location;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.animation.DecelerateInterpolator;
-import android.view.animation.Interpolator;
-import android.widget.ArrayAdapter;
-import android.widget.Button;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.ListPopupWindow;
-
-import com.mapbox.mapboxsdk.location.LocationComponent;
-import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
-import com.mapbox.mapboxsdk.location.LocationComponentOptions;
-import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest;
-import com.mapbox.mapboxsdk.location.modes.CameraMode;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsListener;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsManager;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static com.mapbox.mapboxsdk.testapp.activity.location.Utils.getNextStyle;
-
-/**
- * This activity shows how to customize the LocationComponent's pulsing circle.
- */
-public class CustomizedLocationPulsingCircleActivity extends AppCompatActivity implements OnMapReadyCallback {
-
- //region
-
- // Adjust these variables to customize the example's pulsing circle UI
- private static final float DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS = 2300;
- private static final float SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS = 800;
- private static final float THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS = 8000;
- private static final float DEFAULT_LOCATION_CIRCLE_PULSE_RADIUS = 35;
- private static final float DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA = .55f;
- private static final Interpolator DEFAULT_LOCATION_CIRCLE_INTERPOLATOR_PULSE_MODE
- = new DecelerateInterpolator();
- private static final boolean DEFAULT_LOCATION_CIRCLE_PULSE_FADE_MODE = true;
- //endregion
-
- //region
- private static int LOCATION_CIRCLE_PULSE_COLOR;
- private static float LOCATION_CIRCLE_PULSE_DURATION = DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS;
- private static final String SAVED_STATE_LOCATION = "saved_state_location";
- private static final String SAVED_STATE_LOCATION_CIRCLE_PULSE_COLOR = "saved_state_color";
- private static final String SAVED_STATE_LOCATION_CIRCLE_PULSE_DURATION = "saved_state_duration";
- private static final String LAYER_BELOW_ID = "poi_transit";
-
- private Location lastLocation;
- private MapView mapView;
- private Button pulsingCircleDurationButton;
- private Button pulsingCircleColorButton;
- private PermissionsManager permissionsManager;
- private LocationComponent locationComponent;
- private MapboxMap mapboxMap;
- private float currentPulseDuration;
- //endregion
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_location_layer_customized_pulsing_circle);
-
- LOCATION_CIRCLE_PULSE_COLOR = Color.BLUE;
-
- mapView = findViewById(R.id.mapView);
-
- if (savedInstanceState != null) {
- lastLocation = savedInstanceState.getParcelable(SAVED_STATE_LOCATION);
- LOCATION_CIRCLE_PULSE_COLOR = savedInstanceState.getInt(SAVED_STATE_LOCATION_CIRCLE_PULSE_COLOR);
- LOCATION_CIRCLE_PULSE_DURATION = savedInstanceState.getFloat(SAVED_STATE_LOCATION_CIRCLE_PULSE_DURATION);
- }
-
- pulsingCircleDurationButton = findViewById(R.id.button_location_circle_duration);
- pulsingCircleDurationButton.setText(String.format("%sms",
- String.valueOf(LOCATION_CIRCLE_PULSE_DURATION)));
- pulsingCircleDurationButton.setOnClickListener(v -> {
- if (locationComponent == null) {
- return;
- }
- showDurationListDialog();
- });
-
- pulsingCircleColorButton = findViewById(R.id.button_location_circle_color);
- pulsingCircleColorButton.setOnClickListener(v -> {
- if (locationComponent == null) {
- return;
- }
- showColorListDialog();
- });
-
- mapView.onCreate(savedInstanceState);
-
- checkPermissions();
- }
-
- @SuppressLint("MissingPermission")
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- this.mapboxMap = mapboxMap;
-
- mapboxMap.setStyle(Style.getPredefinedStyle("Streets"), style -> {
- locationComponent = mapboxMap.getLocationComponent();
-
- LocationComponentOptions locationComponentOptions =
- buildLocationComponentOptions(
- LOCATION_CIRCLE_PULSE_COLOR,
- LOCATION_CIRCLE_PULSE_DURATION)
- .pulseEnabled(true)
- .build();
-
- LocationComponentActivationOptions locationComponentActivationOptions =
- buildLocationComponentActivationOptions(style,locationComponentOptions);
-
- locationComponent.activateLocationComponent(locationComponentActivationOptions);
- locationComponent.setLocationComponentEnabled(true);
- locationComponent.setCameraMode(CameraMode.TRACKING);
- locationComponent.forceLocationUpdate(lastLocation);
- });
- }
-
- private LocationComponentOptions.Builder buildLocationComponentOptions(int pulsingCircleColor,
- float pulsingCircleDuration
- ) {
- currentPulseDuration = pulsingCircleDuration;
- return LocationComponentOptions.builder(this)
- .layerBelow(LAYER_BELOW_ID)
- .pulseFadeEnabled(DEFAULT_LOCATION_CIRCLE_PULSE_FADE_MODE)
- .pulseInterpolator(DEFAULT_LOCATION_CIRCLE_INTERPOLATOR_PULSE_MODE)
- .pulseColor(pulsingCircleColor)
- .pulseAlpha(DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA)
- .pulseSingleDuration(pulsingCircleDuration)
- .pulseMaxRadius(DEFAULT_LOCATION_CIRCLE_PULSE_RADIUS);
- }
-
- @SuppressLint("MissingPermission")
- private void setNewLocationComponentOptions(float newPulsingDuration,
- int newPulsingColor) {
- mapboxMap.getStyle(style -> locationComponent.applyStyle(
- buildLocationComponentOptions(
- newPulsingColor,
- newPulsingDuration)
- .pulseEnabled(true)
- .build()));
- }
-
- private LocationComponentActivationOptions buildLocationComponentActivationOptions(
- @NonNull Style style,
- @NonNull LocationComponentOptions locationComponentOptions) {
- return LocationComponentActivationOptions
- .builder(this, style)
- .locationComponentOptions(locationComponentOptions)
- .useDefaultLocationEngine(true)
- .locationEngineRequest(new LocationEngineRequest.Builder(750)
- .setFastestInterval(750)
- .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
- .build())
- .build();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_pulsing_location_mode, menu);
- return true;
- }
-
- @SuppressLint("MissingPermission")
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (locationComponent == null) {
- return super.onOptionsItemSelected(item);
- }
-
- int id = item.getItemId();
- if (id == R.id.action_map_style_change) {
- loadNewStyle();
- return true;
- } else if (id == R.id.action_component_disable) {
- locationComponent.setLocationComponentEnabled(false);
- return true;
- } else if (id == R.id.action_component_enabled) {
- locationComponent.setLocationComponentEnabled(true);
- return true;
- } else if (id == R.id.action_stop_pulsing) {
- locationComponent.applyStyle(LocationComponentOptions.builder(
- CustomizedLocationPulsingCircleActivity.this)
- .pulseEnabled(false)
- .build());
- return true;
- } else if (id == R.id.action_start_pulsing) {
- locationComponent.applyStyle(buildLocationComponentOptions(
- LOCATION_CIRCLE_PULSE_COLOR,
- LOCATION_CIRCLE_PULSE_DURATION)
- .pulseEnabled(true)
- .build());
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- private void loadNewStyle() {
- mapboxMap.setStyle(new Style.Builder().fromUri(getNextStyle()));
- }
-
- private void checkPermissions() {
- if (PermissionsManager.areLocationPermissionsGranted(this)) {
- mapView.getMapAsync(this);
- } else {
- permissionsManager = new PermissionsManager(new PermissionsListener() {
- @Override
- public void onExplanationNeeded(List permissionsToExplain) {
- Toast.makeText(CustomizedLocationPulsingCircleActivity.this, "You need to accept location permissions.",
- Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onPermissionResult(boolean granted) {
- if (granted) {
- mapView.getMapAsync(CustomizedLocationPulsingCircleActivity.this);
- } else {
- finish();
- }
- }
- });
- permissionsManager.requestLocationPermissions(this);
- }
- }
-
- private void showDurationListDialog() {
- List modes = new ArrayList<>();
- modes.add(String.format("%sms", String.valueOf(DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS)));
- modes.add(String.format("%sms", String.valueOf(SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS)));
- modes.add(String.format("%sms", String.valueOf(THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS)));
- ArrayAdapter profileAdapter = new ArrayAdapter<>(this,
- android.R.layout.simple_list_item_1, modes);
- ListPopupWindow listPopup = new ListPopupWindow(this);
- listPopup.setAdapter(profileAdapter);
- listPopup.setAnchorView(pulsingCircleDurationButton);
- listPopup.setOnItemClickListener((parent, itemView, position, id) -> {
- String selectedMode = modes.get(position);
- pulsingCircleDurationButton.setText(selectedMode);
- if (selectedMode.contentEquals(String.format("%sms",
- String.valueOf(DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS)))) {
- LOCATION_CIRCLE_PULSE_DURATION = DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS;
- setNewLocationComponentOptions(DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS, LOCATION_CIRCLE_PULSE_COLOR);
- } else if (selectedMode.contentEquals(String.format("%sms",
- String.valueOf(SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS)))) {
- LOCATION_CIRCLE_PULSE_DURATION = SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS;
- setNewLocationComponentOptions(SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS, LOCATION_CIRCLE_PULSE_COLOR);
- } else if (selectedMode.contentEquals(String.format("%sms",
- String.valueOf(THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS)))) {
- LOCATION_CIRCLE_PULSE_DURATION = THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS;
- setNewLocationComponentOptions(THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS, LOCATION_CIRCLE_PULSE_COLOR);
- }
- listPopup.dismiss();
- });
- listPopup.show();
- }
-
- private void showColorListDialog() {
- List trackingTypes = new ArrayList<>();
- trackingTypes.add("Blue");
- trackingTypes.add("Red");
- trackingTypes.add("Green");
- trackingTypes.add("Gray");
- ArrayAdapter profileAdapter = new ArrayAdapter<>(this,
- android.R.layout.simple_list_item_1, trackingTypes);
- ListPopupWindow listPopup = new ListPopupWindow(this);
- listPopup.setAdapter(profileAdapter);
- listPopup.setAnchorView(pulsingCircleColorButton);
- listPopup.setOnItemClickListener((parent, itemView, position, id) -> {
- String selectedTrackingType = trackingTypes.get(position);
- pulsingCircleColorButton.setText(selectedTrackingType);
- if (selectedTrackingType.contentEquals("Blue")) {
- LOCATION_CIRCLE_PULSE_COLOR = Color.BLUE;
- setNewLocationComponentOptions(currentPulseDuration, Color.BLUE);
- } else if (selectedTrackingType.contentEquals("Red")) {
- LOCATION_CIRCLE_PULSE_COLOR = Color.RED;
- setNewLocationComponentOptions(currentPulseDuration, Color.RED);
- } else if (selectedTrackingType.contentEquals("Green")) {
- LOCATION_CIRCLE_PULSE_COLOR = Color.GREEN;
- setNewLocationComponentOptions(currentPulseDuration, Color.GREEN);
- } else if (selectedTrackingType.contentEquals("Gray")) {
- LOCATION_CIRCLE_PULSE_COLOR = Color.parseColor("#4a4a4a");
- setNewLocationComponentOptions(currentPulseDuration, Color.parseColor("#4a4a4a"));
- }
- listPopup.dismiss();
- });
- listPopup.show();
- }
-
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @SuppressLint("MissingPermission")
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- if (locationComponent != null) {
- outState.putParcelable(SAVED_STATE_LOCATION, locationComponent.getLastKnownLocation());
- outState.putInt(SAVED_STATE_LOCATION_CIRCLE_PULSE_COLOR, LOCATION_CIRCLE_PULSE_COLOR);
- outState.putFloat(SAVED_STATE_LOCATION_CIRCLE_PULSE_DURATION, LOCATION_CIRCLE_PULSE_DURATION);
- }
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-}
\ No newline at end of file
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
new file mode 100644
index 000000000..9685927c1
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/CustomizedLocationPulsingCircleActivity.kt
@@ -0,0 +1,396 @@
+package com.mapbox.mapboxsdk.testapp.activity.location
+
+import android.annotation.SuppressLint
+import android.graphics.Color
+import android.location.Location
+import android.os.Bundle
+import android.view.Menu
+import android.view.MenuItem
+import android.view.View
+import android.view.animation.DecelerateInterpolator
+import android.view.animation.Interpolator
+import android.widget.AdapterView
+import android.widget.ArrayAdapter
+import android.widget.Button
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.widget.ListPopupWindow
+import com.mapbox.mapboxsdk.location.LocationComponent
+import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions
+import com.mapbox.mapboxsdk.location.LocationComponentOptions
+import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest
+import com.mapbox.mapboxsdk.location.modes.CameraMode
+import com.mapbox.mapboxsdk.location.permissions.PermissionsListener
+import com.mapbox.mapboxsdk.location.permissions.PermissionsManager
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+import java.util.ArrayList
+
+/**
+ * This activity shows how to customize the LocationComponent's pulsing circle.
+ */
+class CustomizedLocationPulsingCircleActivity : AppCompatActivity(), OnMapReadyCallback {
+ private var lastLocation: Location? = null
+ private lateinit var mapView: MapView
+ private lateinit var pulsingCircleDurationButton: Button
+ private lateinit var pulsingCircleColorButton: Button
+ private var permissionsManager: PermissionsManager? = null
+ private var locationComponent: LocationComponent? = null
+ private var mapboxMap: MapboxMap? = null
+ private var currentPulseDuration = 0f
+
+ //endregion
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_location_layer_customized_pulsing_circle)
+ LOCATION_CIRCLE_PULSE_COLOR = Color.BLUE
+ mapView = findViewById(R.id.mapView)
+ if (savedInstanceState != null) {
+ lastLocation = savedInstanceState.getParcelable(SAVED_STATE_LOCATION)
+ LOCATION_CIRCLE_PULSE_COLOR = savedInstanceState.getInt(
+ SAVED_STATE_LOCATION_CIRCLE_PULSE_COLOR
+ )
+ LOCATION_CIRCLE_PULSE_DURATION = savedInstanceState.getFloat(
+ SAVED_STATE_LOCATION_CIRCLE_PULSE_DURATION
+ )
+ }
+ pulsingCircleDurationButton = findViewById(R.id.button_location_circle_duration)
+ pulsingCircleDurationButton.setText(
+ String.format(
+ "%sms",
+ LOCATION_CIRCLE_PULSE_DURATION.toString()
+ )
+ )
+ pulsingCircleDurationButton.setOnClickListener(
+ View.OnClickListener setOnClickListener@{ v: View? ->
+ if (locationComponent == null) {
+ return@setOnClickListener
+ }
+ showDurationListDialog()
+ }
+ )
+ pulsingCircleColorButton = findViewById(R.id.button_location_circle_color)
+ pulsingCircleColorButton.setOnClickListener(
+ View.OnClickListener setOnClickListener@{ v: View? ->
+ if (locationComponent == null) {
+ return@setOnClickListener
+ }
+ showColorListDialog()
+ }
+ )
+ mapView.onCreate(savedInstanceState)
+ checkPermissions()
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ this.mapboxMap = mapboxMap
+ mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style: Style ->
+ locationComponent = mapboxMap.locationComponent
+ val locationComponentOptions = buildLocationComponentOptions(
+ LOCATION_CIRCLE_PULSE_COLOR,
+ LOCATION_CIRCLE_PULSE_DURATION
+ )
+ .pulseEnabled(true)
+ .build()
+ val locationComponentActivationOptions =
+ buildLocationComponentActivationOptions(style, locationComponentOptions)
+ locationComponent!!.activateLocationComponent(locationComponentActivationOptions)
+ locationComponent!!.isLocationComponentEnabled = true
+ locationComponent!!.cameraMode = CameraMode.TRACKING
+ locationComponent!!.forceLocationUpdate(lastLocation)
+ }
+ }
+
+ private fun buildLocationComponentOptions(
+ pulsingCircleColor: Int,
+ pulsingCircleDuration: Float
+ ): LocationComponentOptions.Builder {
+ currentPulseDuration = pulsingCircleDuration
+ return LocationComponentOptions.builder(this)
+ .layerBelow(LAYER_BELOW_ID)
+ .pulseFadeEnabled(DEFAULT_LOCATION_CIRCLE_PULSE_FADE_MODE)
+ .pulseInterpolator(DEFAULT_LOCATION_CIRCLE_INTERPOLATOR_PULSE_MODE)
+ .pulseColor(pulsingCircleColor)
+ .pulseAlpha(DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA)
+ .pulseSingleDuration(pulsingCircleDuration)
+ .pulseMaxRadius(DEFAULT_LOCATION_CIRCLE_PULSE_RADIUS)
+ }
+
+ @SuppressLint("MissingPermission")
+ private fun setNewLocationComponentOptions(
+ newPulsingDuration: Float,
+ newPulsingColor: Int
+ ) {
+ mapboxMap!!.getStyle { style: Style? ->
+ locationComponent!!.applyStyle(
+ buildLocationComponentOptions(
+ newPulsingColor,
+ newPulsingDuration
+ )
+ .pulseEnabled(true)
+ .build()
+ )
+ }
+ }
+
+ private fun buildLocationComponentActivationOptions(
+ style: Style,
+ locationComponentOptions: LocationComponentOptions
+ ): LocationComponentActivationOptions {
+ return LocationComponentActivationOptions
+ .builder(this, style)
+ .locationComponentOptions(locationComponentOptions)
+ .useDefaultLocationEngine(true)
+ .locationEngineRequest(
+ LocationEngineRequest.Builder(750)
+ .setFastestInterval(750)
+ .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
+ .build()
+ )
+ .build()
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
+ menuInflater.inflate(R.menu.menu_pulsing_location_mode, menu)
+ return true
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ if (locationComponent == null) {
+ return super.onOptionsItemSelected(item)
+ }
+ val id = item.itemId
+ if (id == R.id.action_map_style_change) {
+ loadNewStyle()
+ return true
+ } else if (id == R.id.action_component_disable) {
+ locationComponent!!.isLocationComponentEnabled = false
+ return true
+ } else if (id == R.id.action_component_enabled) {
+ locationComponent!!.isLocationComponentEnabled = true
+ return true
+ } else if (id == R.id.action_stop_pulsing) {
+ locationComponent!!.applyStyle(
+ LocationComponentOptions.builder(
+ this@CustomizedLocationPulsingCircleActivity
+ )
+ .pulseEnabled(false)
+ .build()
+ )
+ return true
+ } else if (id == R.id.action_start_pulsing) {
+ locationComponent!!.applyStyle(
+ buildLocationComponentOptions(
+ LOCATION_CIRCLE_PULSE_COLOR,
+ LOCATION_CIRCLE_PULSE_DURATION
+ )
+ .pulseEnabled(true)
+ .build()
+ )
+ return true
+ }
+ return super.onOptionsItemSelected(item)
+ }
+
+ private fun loadNewStyle() {
+ mapboxMap!!.setStyle(Style.Builder().fromUri(Utils.nextStyle()))
+ }
+
+ private fun checkPermissions() {
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ mapView!!.getMapAsync(this)
+ } else {
+ permissionsManager = PermissionsManager(object : PermissionsListener {
+ override fun onExplanationNeeded(permissionsToExplain: List) {
+ Toast.makeText(
+ this@CustomizedLocationPulsingCircleActivity,
+ "You need to accept location permissions.",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+
+ override fun onPermissionResult(granted: Boolean) {
+ if (granted) {
+ mapView!!.getMapAsync(this@CustomizedLocationPulsingCircleActivity)
+ } else {
+ finish()
+ }
+ }
+ })
+ permissionsManager!!.requestLocationPermissions(this)
+ }
+ }
+
+ private fun showDurationListDialog() {
+ val modes: MutableList = ArrayList()
+ modes.add(String.format("%sms", DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()))
+ modes.add(String.format("%sms", SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()))
+ modes.add(String.format("%sms", THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()))
+ val profileAdapter = ArrayAdapter(
+ this,
+ android.R.layout.simple_list_item_1,
+ modes
+ )
+ val listPopup = ListPopupWindow(this)
+ listPopup.setAdapter(profileAdapter)
+ listPopup.anchorView = pulsingCircleDurationButton
+ listPopup.setOnItemClickListener { parent: AdapterView<*>?, itemView: View?, position: Int, id: Long ->
+ val selectedMode = modes[position]
+ pulsingCircleDurationButton!!.text = selectedMode
+ if (selectedMode.contentEquals(
+ String.format(
+ "%sms",
+ DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()
+ )
+ )
+ ) {
+ LOCATION_CIRCLE_PULSE_DURATION = DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS
+ setNewLocationComponentOptions(
+ DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS,
+ LOCATION_CIRCLE_PULSE_COLOR
+ )
+ } else if (selectedMode.contentEquals(
+ String.format(
+ "%sms",
+ SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()
+ )
+ )
+ ) {
+ LOCATION_CIRCLE_PULSE_DURATION = SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS
+ setNewLocationComponentOptions(
+ SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS,
+ LOCATION_CIRCLE_PULSE_COLOR
+ )
+ } else if (selectedMode.contentEquals(
+ String.format(
+ "%sms",
+ THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS.toString()
+ )
+ )
+ ) {
+ LOCATION_CIRCLE_PULSE_DURATION = THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS
+ setNewLocationComponentOptions(
+ THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS,
+ LOCATION_CIRCLE_PULSE_COLOR
+ )
+ }
+ listPopup.dismiss()
+ }
+ listPopup.show()
+ }
+
+ private fun showColorListDialog() {
+ val trackingTypes: MutableList = ArrayList()
+ trackingTypes.add("Blue")
+ trackingTypes.add("Red")
+ trackingTypes.add("Green")
+ trackingTypes.add("Gray")
+ val profileAdapter = ArrayAdapter(
+ this,
+ android.R.layout.simple_list_item_1,
+ trackingTypes
+ )
+ val listPopup = ListPopupWindow(this)
+ listPopup.setAdapter(profileAdapter)
+ listPopup.anchorView = pulsingCircleColorButton
+ listPopup.setOnItemClickListener { parent: AdapterView<*>?, itemView: View?, position: Int, id: Long ->
+ val selectedTrackingType = trackingTypes[position]
+ pulsingCircleColorButton!!.text = selectedTrackingType
+ if (selectedTrackingType.contentEquals("Blue")) {
+ LOCATION_CIRCLE_PULSE_COLOR = Color.BLUE
+ setNewLocationComponentOptions(currentPulseDuration, Color.BLUE)
+ } else if (selectedTrackingType.contentEquals("Red")) {
+ LOCATION_CIRCLE_PULSE_COLOR = Color.RED
+ setNewLocationComponentOptions(currentPulseDuration, Color.RED)
+ } else if (selectedTrackingType.contentEquals("Green")) {
+ LOCATION_CIRCLE_PULSE_COLOR = Color.GREEN
+ setNewLocationComponentOptions(currentPulseDuration, Color.GREEN)
+ } else if (selectedTrackingType.contentEquals("Gray")) {
+ LOCATION_CIRCLE_PULSE_COLOR = Color.parseColor("#4a4a4a")
+ setNewLocationComponentOptions(currentPulseDuration, Color.parseColor("#4a4a4a"))
+ }
+ listPopup.dismiss()
+ }
+ listPopup.show()
+ }
+
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array,
+ grantResults: IntArray
+ ) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ permissionsManager!!.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.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)
+ outState.putFloat(
+ SAVED_STATE_LOCATION_CIRCLE_PULSE_DURATION,
+ LOCATION_CIRCLE_PULSE_DURATION
+ )
+ }
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+
+ companion object {
+ //region
+ // Adjust these variables to customize the example's pulsing circle UI
+ private const val DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS = 2300f
+ private const val SECOND_LOCATION_CIRCLE_PULSE_DURATION_MS = 800f
+ private const val THIRD_LOCATION_CIRCLE_PULSE_DURATION_MS = 8000f
+ private const val DEFAULT_LOCATION_CIRCLE_PULSE_RADIUS = 35f
+ private const val DEFAULT_LOCATION_CIRCLE_PULSE_ALPHA = .55f
+ private val DEFAULT_LOCATION_CIRCLE_INTERPOLATOR_PULSE_MODE: Interpolator =
+ DecelerateInterpolator()
+ private const val DEFAULT_LOCATION_CIRCLE_PULSE_FADE_MODE = true
+
+ //endregion
+ //region
+ private var LOCATION_CIRCLE_PULSE_COLOR = 0
+ private var LOCATION_CIRCLE_PULSE_DURATION = DEFAULT_LOCATION_CIRCLE_PULSE_DURATION_MS
+ private const val SAVED_STATE_LOCATION = "saved_state_location"
+ private const val SAVED_STATE_LOCATION_CIRCLE_PULSE_COLOR = "saved_state_color"
+ private const val SAVED_STATE_LOCATION_CIRCLE_PULSE_DURATION = "saved_state_duration"
+ private const val LAYER_BELOW_ID = "poi_transit"
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java
deleted file mode 100644
index 09fd016c7..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.location;
-
-import android.annotation.SuppressLint;
-import android.graphics.Color;
-import android.os.Bundle;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mapbox.mapboxsdk.location.LocationComponent;
-import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
-import com.mapbox.mapboxsdk.location.LocationComponentOptions;
-import com.mapbox.mapboxsdk.location.modes.CameraMode;
-import com.mapbox.mapboxsdk.location.modes.RenderMode;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsListener;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsManager;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-import java.util.List;
-
-public class LocationComponentActivationActivity extends AppCompatActivity implements OnMapReadyCallback {
-
- private MapView mapView;
- private MapboxMap mapboxMap;
- private PermissionsManager permissionsManager;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_location_layer_activation_builder);
-
- mapView = findViewById(R.id.mapView);
-
- mapView.onCreate(savedInstanceState);
-
- if (PermissionsManager.areLocationPermissionsGranted(this)) {
- mapView.getMapAsync(this);
- } else {
- permissionsManager = new PermissionsManager(new PermissionsListener() {
- @Override
- public void onExplanationNeeded(List permissionsToExplain) {
- Toast.makeText(LocationComponentActivationActivity.this, "You need to accept location permissions.",
- Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onPermissionResult(boolean granted) {
- if (granted) {
- mapView.getMapAsync(LocationComponentActivationActivity.this);
- } else {
- finish();
- }
- }
- });
- permissionsManager.requestLocationPermissions(this);
- }
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- this.mapboxMap = mapboxMap;
- mapboxMap.setStyle(Style.getPredefinedStyle("Bright"),
- style -> activateLocationComponent(style));
- }
-
- @SuppressLint("MissingPermission")
- private void activateLocationComponent(@NonNull Style style) {
- LocationComponent locationComponent = mapboxMap.getLocationComponent();
-
- LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(this)
- .elevation(5)
- .accuracyAlpha(.6f)
- .accuracyColor(Color.GREEN)
- .foregroundDrawable(R.drawable.mapbox_logo_helmet)
- .build();
-
- LocationComponentActivationOptions locationComponentActivationOptions = LocationComponentActivationOptions
- .builder(this, style)
- .locationComponentOptions(locationComponentOptions)
- .useDefaultLocationEngine(true)
- .build();
-
- locationComponent.activateLocationComponent(locationComponentActivationOptions);
- locationComponent.setLocationComponentEnabled(true);
- locationComponent.setRenderMode(RenderMode.NORMAL);
- locationComponent.setCameraMode(CameraMode.TRACKING);
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-}
\ No newline at end of file
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
new file mode 100644
index 000000000..acd03f733
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.kt
@@ -0,0 +1,123 @@
+package com.mapbox.mapboxsdk.testapp.activity.location
+
+import android.annotation.SuppressLint
+import android.graphics.Color
+import android.os.Bundle
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions
+import com.mapbox.mapboxsdk.location.LocationComponentOptions
+import com.mapbox.mapboxsdk.location.modes.CameraMode
+import com.mapbox.mapboxsdk.location.modes.RenderMode
+import com.mapbox.mapboxsdk.location.permissions.PermissionsListener
+import com.mapbox.mapboxsdk.location.permissions.PermissionsManager
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+
+class LocationComponentActivationActivity : AppCompatActivity(), OnMapReadyCallback {
+ private lateinit var mapView: MapView
+ private var mapboxMap: MapboxMap? = null
+ private var permissionsManager: PermissionsManager? = null
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_location_layer_activation_builder)
+ mapView = findViewById(R.id.mapView)
+ mapView.onCreate(savedInstanceState)
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ mapView.getMapAsync(this)
+ } else {
+ permissionsManager = PermissionsManager(object : PermissionsListener {
+ override fun onExplanationNeeded(permissionsToExplain: List) {
+ Toast.makeText(
+ this@LocationComponentActivationActivity,
+ "You need to accept location permissions.",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+
+ override fun onPermissionResult(granted: Boolean) {
+ if (granted) {
+ mapView.getMapAsync(this@LocationComponentActivationActivity)
+ } else {
+ finish()
+ }
+ }
+ })
+ permissionsManager!!.requestLocationPermissions(this)
+ }
+ }
+
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array,
+ grantResults: IntArray
+ ) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ permissionsManager!!.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ }
+
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ this.mapboxMap = mapboxMap
+ mapboxMap.setStyle(
+ Style.getPredefinedStyle("Bright")
+ ) { style: Style -> activateLocationComponent(style) }
+ }
+
+ @SuppressLint("MissingPermission")
+ private fun activateLocationComponent(style: Style) {
+ val locationComponent = mapboxMap!!.locationComponent
+ val locationComponentOptions = LocationComponentOptions.builder(this)
+ .elevation(5f)
+ .accuracyAlpha(.6f)
+ .accuracyColor(Color.GREEN)
+ .foregroundDrawable(R.drawable.mapbox_logo_helmet)
+ .build()
+ val locationComponentActivationOptions = LocationComponentActivationOptions
+ .builder(this, style)
+ .locationComponentOptions(locationComponentOptions)
+ .useDefaultLocationEngine(true)
+ .build()
+ locationComponent.activateLocationComponent(locationComponentActivationOptions)
+ locationComponent.isLocationComponentEnabled = true
+ locationComponent.renderMode = RenderMode.NORMAL
+ locationComponent.cameraMode = CameraMode.TRACKING
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java
deleted file mode 100644
index 19a40a74e..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.location;
-
-import android.annotation.SuppressLint;
-import android.os.Bundle;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.google.android.material.floatingactionbutton.FloatingActionButton;
-import com.mapbox.mapboxsdk.location.LocationComponent;
-import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
-import com.mapbox.mapboxsdk.location.modes.RenderMode;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsListener;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsManager;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-import java.util.List;
-
-public class LocationMapChangeActivity extends AppCompatActivity implements OnMapReadyCallback {
-
- private MapView mapView;
- private MapboxMap mapboxMap;
- private PermissionsManager permissionsManager;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_location_layer_map_change);
-
- mapView = findViewById(R.id.mapView);
- FloatingActionButton stylesFab = findViewById(R.id.fabStyles);
-
- stylesFab.setOnClickListener(v -> {
- if (mapboxMap != null) {
- mapboxMap.setStyle(new Style.Builder().fromUri(Utils.getNextStyle()));
- }
- });
-
- mapView.onCreate(savedInstanceState);
-
- if (PermissionsManager.areLocationPermissionsGranted(this)) {
- mapView.getMapAsync(this);
- } else {
- permissionsManager = new PermissionsManager(new PermissionsListener() {
- @Override
- public void onExplanationNeeded(List permissionsToExplain) {
- Toast.makeText(LocationMapChangeActivity.this, "You need to accept location permissions.",
- Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onPermissionResult(boolean granted) {
- if (granted) {
- mapView.getMapAsync(LocationMapChangeActivity.this);
- } else {
- finish();
- }
- }
- });
- permissionsManager.requestLocationPermissions(this);
- }
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- this.mapboxMap = mapboxMap;
- mapboxMap.setStyle(new Style.Builder().fromUri(Utils.getNextStyle()),
- style -> activateLocationComponent(style));
- }
-
- @SuppressLint("MissingPermission")
- private void activateLocationComponent(@NonNull Style style) {
- LocationComponent locationComponent = mapboxMap.getLocationComponent();
-
- locationComponent.activateLocationComponent(
- LocationComponentActivationOptions
- .builder(this, style)
- .useDefaultLocationEngine(true)
- .build());
-
- locationComponent.setLocationComponentEnabled(true);
- locationComponent.setRenderMode(RenderMode.COMPASS);
-
- locationComponent.addOnLocationClickListener(
- () -> Toast.makeText(this, "Location clicked", Toast.LENGTH_SHORT).show());
-
- locationComponent.addOnLocationLongClickListener(
- () -> Toast.makeText(this, "Location long clicked", Toast.LENGTH_SHORT).show());
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-}
\ No newline at end of file
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
new file mode 100644
index 000000000..eb263d0ac
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.kt
@@ -0,0 +1,135 @@
+package com.mapbox.mapboxsdk.testapp.activity.location
+
+import android.annotation.SuppressLint
+import android.os.Bundle
+import android.view.View
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import com.google.android.material.floatingactionbutton.FloatingActionButton
+import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions
+import com.mapbox.mapboxsdk.location.modes.RenderMode
+import com.mapbox.mapboxsdk.location.permissions.PermissionsListener
+import com.mapbox.mapboxsdk.location.permissions.PermissionsManager
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+
+class LocationMapChangeActivity : AppCompatActivity(), OnMapReadyCallback {
+ private lateinit var mapView: MapView
+ private var mapboxMap: MapboxMap? = null
+ private var permissionsManager: PermissionsManager? = null
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_location_layer_map_change)
+ mapView = findViewById(R.id.mapView)
+ val stylesFab = findViewById(R.id.fabStyles)
+ stylesFab.setOnClickListener { v: View? ->
+ if (mapboxMap != null) {
+ mapboxMap!!.setStyle(Style.Builder().fromUri(Utils.nextStyle()))
+ }
+ }
+ mapView.onCreate(savedInstanceState)
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ mapView.getMapAsync(this)
+ } else {
+ permissionsManager = PermissionsManager(object : PermissionsListener {
+ override fun onExplanationNeeded(permissionsToExplain: List) {
+ Toast.makeText(
+ this@LocationMapChangeActivity,
+ "You need to accept location permissions.",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+
+ override fun onPermissionResult(granted: Boolean) {
+ if (granted) {
+ mapView.getMapAsync(this@LocationMapChangeActivity)
+ } else {
+ finish()
+ }
+ }
+ })
+ permissionsManager!!.requestLocationPermissions(this)
+ }
+ }
+
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array,
+ grantResults: IntArray
+ ) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ permissionsManager!!.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ }
+
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ this.mapboxMap = mapboxMap
+ mapboxMap.setStyle(
+ Style.Builder().fromUri(Utils.nextStyle())
+ ) { style: Style -> activateLocationComponent(style) }
+ }
+
+ @SuppressLint("MissingPermission")
+ private fun activateLocationComponent(style: Style) {
+ val locationComponent = mapboxMap!!.locationComponent
+ locationComponent.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(this, style)
+ .useDefaultLocationEngine(true)
+ .build()
+ )
+ locationComponent.isLocationComponentEnabled = true
+ locationComponent.renderMode = RenderMode.COMPASS
+ locationComponent.addOnLocationClickListener {
+ Toast.makeText(
+ this,
+ "Location clicked",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+ locationComponent.addOnLocationLongClickListener {
+ Toast.makeText(
+ this,
+ "Location long clicked",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java
deleted file mode 100644
index a0bab3d6a..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java
+++ /dev/null
@@ -1,451 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.location;
-
-import android.annotation.SuppressLint;
-import android.content.res.Configuration;
-import android.graphics.RectF;
-import android.location.Location;
-import android.os.Bundle;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.ArrayAdapter;
-import android.widget.Button;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.ListPopupWindow;
-
-import com.mapbox.mapboxsdk.location.LocationComponent;
-import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
-import com.mapbox.mapboxsdk.location.LocationComponentOptions;
-import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener;
-import com.mapbox.mapboxsdk.location.OnLocationCameraTransitionListener;
-import com.mapbox.mapboxsdk.location.OnLocationClickListener;
-import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest;
-import com.mapbox.mapboxsdk.location.modes.CameraMode;
-import com.mapbox.mapboxsdk.location.modes.RenderMode;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsListener;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsManager;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class LocationModesActivity extends AppCompatActivity implements OnMapReadyCallback,
- OnLocationClickListener, OnCameraTrackingChangedListener {
-
- private MapView mapView;
- private Button locationModeBtn;
- private Button locationTrackingBtn;
- private View protectedGestureArea;
-
- private PermissionsManager permissionsManager;
-
- private LocationComponent locationComponent;
- private MapboxMap mapboxMap;
- private boolean defaultStyle = false;
-
- private static final String SAVED_STATE_CAMERA = "saved_state_camera";
- private static final String SAVED_STATE_RENDER = "saved_state_render";
- private static final String SAVED_STATE_LOCATION = "saved_state_location";
-
- @CameraMode.Mode
- private int cameraMode = CameraMode.TRACKING;
-
- @RenderMode.Mode
- private int renderMode = RenderMode.NORMAL;
-
- private Location lastLocation;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_location_layer_mode);
-
- mapView = findViewById(R.id.mapView);
- protectedGestureArea = findViewById(R.id.view_protected_gesture_area);
-
- locationModeBtn = findViewById(R.id.button_location_mode);
- locationModeBtn.setOnClickListener(v -> {
- if (locationComponent == null) {
- return;
- }
- showModeListDialog();
- });
-
- locationTrackingBtn = findViewById(R.id.button_location_tracking);
- locationTrackingBtn.setOnClickListener(v -> {
- if (locationComponent == null) {
- return;
- }
- showTrackingListDialog();
- });
-
-
- if (savedInstanceState != null) {
- cameraMode = savedInstanceState.getInt(SAVED_STATE_CAMERA);
- renderMode = savedInstanceState.getInt(SAVED_STATE_RENDER);
- lastLocation = savedInstanceState.getParcelable(SAVED_STATE_LOCATION);
- }
-
- mapView.onCreate(savedInstanceState);
-
- if (PermissionsManager.areLocationPermissionsGranted(this)) {
- mapView.getMapAsync(this);
- } else {
- permissionsManager = new PermissionsManager(new PermissionsListener() {
- @Override
- public void onExplanationNeeded(List permissionsToExplain) {
- Toast.makeText(LocationModesActivity.this, "You need to accept location permissions.",
- Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onPermissionResult(boolean granted) {
- if (granted) {
- mapView.getMapAsync(LocationModesActivity.this);
- } else {
- finish();
- }
- }
- });
- permissionsManager.requestLocationPermissions(this);
- }
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
- }
-
- @SuppressLint("MissingPermission")
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- this.mapboxMap = mapboxMap;
-
- mapboxMap.setStyle(Style.getPredefinedStyle("Streets"), style -> {
- locationComponent = mapboxMap.getLocationComponent();
- locationComponent.activateLocationComponent(
- LocationComponentActivationOptions
- .builder(this, style)
- .useSpecializedLocationLayer(true)
- .useDefaultLocationEngine(true)
- .locationEngineRequest(new LocationEngineRequest.Builder(750)
- .setFastestInterval(750)
- .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
- .build())
- .build());
-
- toggleStyle();
- locationComponent.setLocationComponentEnabled(true);
- locationComponent.addOnLocationClickListener(this);
- locationComponent.addOnCameraTrackingChangedListener(this);
- locationComponent.setCameraMode(cameraMode);
- setRendererMode(renderMode);
- locationComponent.forceLocationUpdate(lastLocation);
- });
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_location_mode, menu);
- return true;
- }
-
- @SuppressLint("MissingPermission")
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (locationComponent == null) {
- return super.onOptionsItemSelected(item);
- }
-
- int id = item.getItemId();
- if (id == R.id.action_style_change) {
- toggleStyle();
- return true;
- } else if (id == R.id.action_map_style_change) {
- toggleMapStyle();
- return true;
- } else if (id == R.id.action_component_disable) {
- locationComponent.setLocationComponentEnabled(false);
- return true;
- } else if (id == R.id.action_component_enabled) {
- locationComponent.setLocationComponentEnabled(true);
- return true;
- } else if (id == R.id.action_gestures_management_disabled) {
- disableGesturesManagement();
- return true;
- } else if (id == R.id.action_gestures_management_enabled) {
- enableGesturesManagement();
- return true;
- } else if (id == R.id.action_component_throttling_enabled) {
- locationComponent.setMaxAnimationFps(5);
- } else if (id == R.id.action_component_throttling_disabled) {
- locationComponent.setMaxAnimationFps(Integer.MAX_VALUE);
- } else if (id == R.id.action_component_animate_while_tracking) {
- locationComponent.zoomWhileTracking(17, 750, new MapboxMap.CancelableCallback() {
- @Override
- public void onCancel() {
- // No impl
- }
-
- @Override
- public void onFinish() {
- locationComponent.tiltWhileTracking(60);
- }
- });
- if (locationComponent.getCameraMode() == CameraMode.NONE) {
-
- Toast.makeText(this, "Not possible to animate - not tracking", Toast.LENGTH_SHORT).show();
- }
- }
-
- return super.onOptionsItemSelected(item);
- }
-
- private void toggleStyle() {
- if (locationComponent == null) {
- return;
- }
-
- defaultStyle = !defaultStyle;
- LocationComponentOptions options = LocationComponentOptions.createFromAttributes(
- this, defaultStyle ? R.style.mapbox_LocationComponent : R.style.CustomLocationComponent);
-
- if (defaultStyle) {
- int[] padding;
- if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
- padding = new int[] {0, 750, 0, 0};
- } else {
- padding = new int[] {0, 250, 0, 0};
- }
-
- options = options.toBuilder()
- .padding(padding)
- .build();
- }
-
- locationComponent.applyStyle(options);
- }
-
- private void toggleMapStyle() {
- if (locationComponent == null) {
- return;
- }
-
- mapboxMap.getStyle(style -> {
- String styleUrl = Style.getPredefinedStyle("Bright").equals(style.getUri())
- ? Style.getPredefinedStyle("Bright")
- : Style.getPredefinedStyle("Pastel");
- mapboxMap.setStyle(new Style.Builder().fromUri(styleUrl));
- });
- }
-
- private void disableGesturesManagement() {
- if (locationComponent == null) {
- return;
- }
-
- protectedGestureArea.getLayoutParams().height = 0;
- protectedGestureArea.getLayoutParams().width = 0;
-
- LocationComponentOptions options = locationComponent
- .getLocationComponentOptions()
- .toBuilder()
- .trackingGesturesManagement(false)
- .build();
- locationComponent.applyStyle(options);
- }
-
- private void enableGesturesManagement() {
- if (locationComponent == null) {
- return;
- }
-
- RectF rectF = new RectF(0f, 0f, mapView.getWidth() / 2f, mapView.getHeight() / 2f);
- protectedGestureArea.getLayoutParams().height = (int) rectF.bottom;
- protectedGestureArea.getLayoutParams().width = (int) rectF.right;
-
- LocationComponentOptions options = locationComponent
- .getLocationComponentOptions()
- .toBuilder()
- .trackingGesturesManagement(true)
- .trackingMultiFingerProtectedMoveArea(rectF)
- .trackingMultiFingerMoveThreshold(500)
- .build();
- locationComponent.applyStyle(options);
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @SuppressLint("MissingPermission")
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- outState.putInt(SAVED_STATE_CAMERA, cameraMode);
- outState.putInt(SAVED_STATE_RENDER, renderMode);
- if (locationComponent != null) {
- outState.putParcelable(SAVED_STATE_LOCATION, locationComponent.getLastKnownLocation());
- }
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-
- @Override
- public void onLocationComponentClick() {
- Toast.makeText(this, "OnLocationComponentClick", Toast.LENGTH_LONG).show();
- }
-
- private void showModeListDialog() {
- List modes = new ArrayList<>();
- modes.add("Normal");
- modes.add("Compass");
- modes.add("GPS");
- ArrayAdapter profileAdapter = new ArrayAdapter<>(this,
- android.R.layout.simple_list_item_1, modes);
- ListPopupWindow listPopup = new ListPopupWindow(this);
- listPopup.setAdapter(profileAdapter);
- listPopup.setAnchorView(locationModeBtn);
- listPopup.setOnItemClickListener((parent, itemView, position, id) -> {
- String selectedMode = modes.get(position);
- locationModeBtn.setText(selectedMode);
- if (selectedMode.contentEquals("Normal")) {
- setRendererMode(RenderMode.NORMAL);
- } else if (selectedMode.contentEquals("Compass")) {
- setRendererMode(RenderMode.COMPASS);
- } else if (selectedMode.contentEquals("GPS")) {
- setRendererMode(RenderMode.GPS);
- }
- listPopup.dismiss();
- });
- listPopup.show();
- }
-
- private void setRendererMode(@RenderMode.Mode int mode) {
- renderMode = mode;
- locationComponent.setRenderMode(mode);
- if (mode == RenderMode.NORMAL) {
- locationModeBtn.setText("Normal");
- } else if (mode == RenderMode.COMPASS) {
- locationModeBtn.setText("Compass");
- } else if (mode == RenderMode.GPS) {
- locationModeBtn.setText("Gps");
- }
- }
-
- private void showTrackingListDialog() {
- List trackingTypes = new ArrayList<>();
- trackingTypes.add("None");
- trackingTypes.add("None Compass");
- trackingTypes.add("None GPS");
- trackingTypes.add("Tracking");
- trackingTypes.add("Tracking Compass");
- trackingTypes.add("Tracking GPS");
- trackingTypes.add("Tracking GPS North");
- ArrayAdapter profileAdapter = new ArrayAdapter<>(this,
- android.R.layout.simple_list_item_1, trackingTypes);
- ListPopupWindow listPopup = new ListPopupWindow(this);
- listPopup.setAdapter(profileAdapter);
- listPopup.setAnchorView(locationTrackingBtn);
- listPopup.setOnItemClickListener((parent, itemView, position, id) -> {
- String selectedTrackingType = trackingTypes.get(position);
- locationTrackingBtn.setText(selectedTrackingType);
- if (selectedTrackingType.contentEquals("None")) {
- setCameraTrackingMode(CameraMode.NONE);
- } else if (selectedTrackingType.contentEquals("None Compass")) {
- setCameraTrackingMode(CameraMode.NONE_COMPASS);
- } else if (selectedTrackingType.contentEquals("None GPS")) {
- setCameraTrackingMode(CameraMode.NONE_GPS);
- } else if (selectedTrackingType.contentEquals("Tracking")) {
- setCameraTrackingMode(CameraMode.TRACKING);
- } else if (selectedTrackingType.contentEquals("Tracking Compass")) {
- setCameraTrackingMode(CameraMode.TRACKING_COMPASS);
- } else if (selectedTrackingType.contentEquals("Tracking GPS")) {
- setCameraTrackingMode(CameraMode.TRACKING_GPS);
- } else if (selectedTrackingType.contentEquals("Tracking GPS North")) {
- setCameraTrackingMode(CameraMode.TRACKING_GPS_NORTH);
- }
- listPopup.dismiss();
- });
- listPopup.show();
- }
-
- private void setCameraTrackingMode(@CameraMode.Mode int mode) {
- locationComponent.setCameraMode(mode, 1200, 16.0, null, 45.0,
- new OnLocationCameraTransitionListener() {
- @Override
- public void onLocationCameraTransitionFinished(@CameraMode.Mode int cameraMode) {
- Toast.makeText(LocationModesActivity.this, "Transition finished", Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onLocationCameraTransitionCanceled(@CameraMode.Mode int cameraMode) {
- Toast.makeText(LocationModesActivity.this, "Transition canceled", Toast.LENGTH_SHORT).show();
- }
- });
- }
-
- @Override
- public void onCameraTrackingDismissed() {
- locationTrackingBtn.setText("None");
- }
-
- @Override
- public void onCameraTrackingChanged(int currentMode) {
- this.cameraMode = currentMode;
- if (currentMode == CameraMode.NONE) {
- locationTrackingBtn.setText("None");
- } else if (currentMode == CameraMode.NONE_COMPASS) {
- locationTrackingBtn.setText("None Compass");
- } else if (currentMode == CameraMode.NONE_GPS) {
- locationTrackingBtn.setText("None GPS");
- } else if (currentMode == CameraMode.TRACKING) {
- locationTrackingBtn.setText("Tracking");
- } else if (currentMode == CameraMode.TRACKING_COMPASS) {
- locationTrackingBtn.setText("Tracking Compass");
- } else if (currentMode == CameraMode.TRACKING_GPS) {
- locationTrackingBtn.setText("Tracking GPS");
- } else if (currentMode == CameraMode.TRACKING_GPS_NORTH) {
- locationTrackingBtn.setText("Tracking GPS North");
- }
- }
-}
\ No newline at end of file
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
new file mode 100644
index 000000000..a8c915a0d
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.kt
@@ -0,0 +1,449 @@
+package com.mapbox.mapboxsdk.testapp.activity.location
+
+import android.annotation.SuppressLint
+import android.content.res.Configuration
+import android.graphics.RectF
+import android.location.Location
+import android.os.Bundle
+import android.view.Menu
+import android.view.MenuItem
+import android.view.View
+import android.widget.AdapterView
+import android.widget.ArrayAdapter
+import android.widget.Button
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.widget.ListPopupWindow
+import com.mapbox.mapboxsdk.location.LocationComponent
+import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions
+import com.mapbox.mapboxsdk.location.LocationComponentOptions
+import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener
+import com.mapbox.mapboxsdk.location.OnLocationCameraTransitionListener
+import com.mapbox.mapboxsdk.location.OnLocationClickListener
+import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest
+import com.mapbox.mapboxsdk.location.modes.CameraMode
+import com.mapbox.mapboxsdk.location.modes.RenderMode
+import com.mapbox.mapboxsdk.location.permissions.PermissionsListener
+import com.mapbox.mapboxsdk.location.permissions.PermissionsManager
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.MapboxMap.CancelableCallback
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+import java.util.ArrayList
+
+class LocationModesActivity :
+ AppCompatActivity(),
+ OnMapReadyCallback,
+ OnLocationClickListener,
+ OnCameraTrackingChangedListener {
+ private lateinit var mapView: MapView
+ private lateinit var locationModeBtn: Button
+ private lateinit var locationTrackingBtn: Button
+ private var protectedGestureArea: View? = null
+ private var permissionsManager: PermissionsManager? = null
+ private var locationComponent: LocationComponent? = null
+ private var mapboxMap: MapboxMap? = null
+ private var defaultStyle = false
+
+ @CameraMode.Mode
+ private var cameraMode = CameraMode.TRACKING
+
+ @RenderMode.Mode
+ private var renderMode = RenderMode.NORMAL
+ private var lastLocation: Location? = null
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_location_layer_mode)
+ mapView = findViewById(R.id.mapView)
+ protectedGestureArea = findViewById(R.id.view_protected_gesture_area)
+ locationModeBtn = findViewById(R.id.button_location_mode)
+ locationModeBtn.setOnClickListener(
+ View.OnClickListener setOnClickListener@{ v: View? ->
+ if (locationComponent == null) {
+ return@setOnClickListener
+ }
+ showModeListDialog()
+ }
+ )
+ locationTrackingBtn = findViewById(R.id.button_location_tracking)
+ locationTrackingBtn.setOnClickListener(
+ View.OnClickListener setOnClickListener@{ v: View? ->
+ if (locationComponent == null) {
+ return@setOnClickListener
+ }
+ showTrackingListDialog()
+ }
+ )
+ if (savedInstanceState != null) {
+ cameraMode = savedInstanceState.getInt(SAVED_STATE_CAMERA)
+ renderMode = savedInstanceState.getInt(SAVED_STATE_RENDER)
+ lastLocation = savedInstanceState.getParcelable(SAVED_STATE_LOCATION)
+ }
+ mapView.onCreate(savedInstanceState)
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ mapView.getMapAsync(this)
+ } else {
+ permissionsManager = PermissionsManager(object : PermissionsListener {
+ override fun onExplanationNeeded(permissionsToExplain: List) {
+ Toast.makeText(
+ this@LocationModesActivity,
+ "You need to accept location permissions.",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+
+ override fun onPermissionResult(granted: Boolean) {
+ if (granted) {
+ mapView.getMapAsync(this@LocationModesActivity)
+ } else {
+ finish()
+ }
+ }
+ })
+ permissionsManager!!.requestLocationPermissions(this)
+ }
+ }
+
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array,
+ grantResults: IntArray
+ ) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ permissionsManager!!.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ this.mapboxMap = mapboxMap
+ mapboxMap.setStyle(Style.getPredefinedStyle("Streets")) { style: Style? ->
+ locationComponent = mapboxMap.locationComponent
+ locationComponent!!.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(this, style!!)
+ .useSpecializedLocationLayer(true)
+ .useDefaultLocationEngine(true)
+ .locationEngineRequest(
+ LocationEngineRequest.Builder(750)
+ .setFastestInterval(750)
+ .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
+ .build()
+ )
+ .build()
+ )
+ toggleStyle()
+ locationComponent!!.isLocationComponentEnabled = true
+ locationComponent!!.addOnLocationClickListener(this)
+ locationComponent!!.addOnCameraTrackingChangedListener(this)
+ locationComponent!!.cameraMode = cameraMode
+ setRendererMode(renderMode)
+ locationComponent!!.forceLocationUpdate(lastLocation)
+ }
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
+ menuInflater.inflate(R.menu.menu_location_mode, menu)
+ return true
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ if (locationComponent == null) {
+ return super.onOptionsItemSelected(item)
+ }
+ val id = item.itemId
+ if (id == R.id.action_style_change) {
+ toggleStyle()
+ return true
+ } else if (id == R.id.action_map_style_change) {
+ toggleMapStyle()
+ return true
+ } else if (id == R.id.action_component_disable) {
+ locationComponent!!.isLocationComponentEnabled = false
+ return true
+ } else if (id == R.id.action_component_enabled) {
+ locationComponent!!.isLocationComponentEnabled = true
+ return true
+ } else if (id == R.id.action_gestures_management_disabled) {
+ disableGesturesManagement()
+ return true
+ } else if (id == R.id.action_gestures_management_enabled) {
+ enableGesturesManagement()
+ return true
+ } else if (id == R.id.action_component_throttling_enabled) {
+ locationComponent!!.setMaxAnimationFps(5)
+ } else if (id == R.id.action_component_throttling_disabled) {
+ locationComponent!!.setMaxAnimationFps(Int.MAX_VALUE)
+ } else if (id == R.id.action_component_animate_while_tracking) {
+ locationComponent!!.zoomWhileTracking(
+ 17.0,
+ 750,
+ object : CancelableCallback {
+ override fun onCancel() {
+ // No impl
+ }
+
+ override fun onFinish() {
+ locationComponent!!.tiltWhileTracking(60.0)
+ }
+ }
+ )
+ if (locationComponent!!.cameraMode == CameraMode.NONE) {
+ Toast.makeText(this, "Not possible to animate - not tracking", Toast.LENGTH_SHORT)
+ .show()
+ }
+ }
+ return super.onOptionsItemSelected(item)
+ }
+
+ private fun toggleStyle() {
+ if (locationComponent == null) {
+ return
+ }
+ defaultStyle = !defaultStyle
+ var options = LocationComponentOptions.createFromAttributes(
+ this,
+ if (defaultStyle) R.style.mapbox_LocationComponent else R.style.CustomLocationComponent
+ )
+ if (defaultStyle) {
+ val padding: IntArray
+ padding =
+ if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
+ intArrayOf(0, 750, 0, 0)
+ } else {
+ intArrayOf(0, 250, 0, 0)
+ }
+ options = options.toBuilder()
+ .padding(padding)
+ .build()
+ }
+ locationComponent!!.applyStyle(options)
+ }
+
+ private fun toggleMapStyle() {
+ if (locationComponent == null) {
+ return
+ }
+ mapboxMap!!.getStyle { style: Style ->
+ val styleUrl =
+ if (Style.getPredefinedStyle("Bright") == style.uri) Style.getPredefinedStyle("Bright") else Style.getPredefinedStyle(
+ "Pastel"
+ )
+ mapboxMap!!.setStyle(Style.Builder().fromUri(styleUrl))
+ }
+ }
+
+ private fun disableGesturesManagement() {
+ if (locationComponent == null) {
+ return
+ }
+ protectedGestureArea!!.layoutParams.height = 0
+ protectedGestureArea!!.layoutParams.width = 0
+ val options = locationComponent!!
+ .locationComponentOptions
+ .toBuilder()
+ .trackingGesturesManagement(false)
+ .build()
+ locationComponent!!.applyStyle(options)
+ }
+
+ private fun enableGesturesManagement() {
+ if (locationComponent == null) {
+ return
+ }
+ val rectF = RectF(0f, 0f, mapView!!.width / 2f, mapView!!.height / 2f)
+ protectedGestureArea!!.layoutParams.height = rectF.bottom.toInt()
+ protectedGestureArea!!.layoutParams.width = rectF.right.toInt()
+ val options = locationComponent!!
+ .locationComponentOptions
+ .toBuilder()
+ .trackingGesturesManagement(true)
+ .trackingMultiFingerProtectedMoveArea(rectF)
+ .trackingMultiFingerMoveThreshold(500f)
+ .build()
+ locationComponent!!.applyStyle(options)
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ outState.putInt(SAVED_STATE_CAMERA, cameraMode)
+ outState.putInt(SAVED_STATE_RENDER, renderMode)
+ if (locationComponent != null) {
+ outState.putParcelable(SAVED_STATE_LOCATION, locationComponent!!.lastKnownLocation)
+ }
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+
+ override fun onLocationComponentClick() {
+ Toast.makeText(this, "OnLocationComponentClick", Toast.LENGTH_LONG).show()
+ }
+
+ private fun showModeListDialog() {
+ val modes: MutableList = ArrayList()
+ modes.add("Normal")
+ modes.add("Compass")
+ modes.add("GPS")
+ val profileAdapter = ArrayAdapter(
+ this,
+ android.R.layout.simple_list_item_1,
+ modes
+ )
+ val listPopup = ListPopupWindow(this)
+ listPopup.setAdapter(profileAdapter)
+ listPopup.anchorView = locationModeBtn
+ listPopup.setOnItemClickListener { parent: AdapterView<*>?, itemView: View?, position: Int, id: Long ->
+ val selectedMode = modes[position]
+ locationModeBtn!!.text = selectedMode
+ if (selectedMode.contentEquals("Normal")) {
+ setRendererMode(RenderMode.NORMAL)
+ } else if (selectedMode.contentEquals("Compass")) {
+ setRendererMode(RenderMode.COMPASS)
+ } else if (selectedMode.contentEquals("GPS")) {
+ setRendererMode(RenderMode.GPS)
+ }
+ listPopup.dismiss()
+ }
+ listPopup.show()
+ }
+
+ private fun setRendererMode(@RenderMode.Mode mode: Int) {
+ renderMode = mode
+ locationComponent!!.renderMode = mode
+ if (mode == RenderMode.NORMAL) {
+ locationModeBtn!!.text = "Normal"
+ } else if (mode == RenderMode.COMPASS) {
+ locationModeBtn!!.text = "Compass"
+ } else if (mode == RenderMode.GPS) {
+ locationModeBtn!!.text = "Gps"
+ }
+ }
+
+ private fun showTrackingListDialog() {
+ val trackingTypes: MutableList = ArrayList()
+ trackingTypes.add("None")
+ trackingTypes.add("None Compass")
+ trackingTypes.add("None GPS")
+ trackingTypes.add("Tracking")
+ trackingTypes.add("Tracking Compass")
+ trackingTypes.add("Tracking GPS")
+ trackingTypes.add("Tracking GPS North")
+ val profileAdapter = ArrayAdapter(
+ this,
+ android.R.layout.simple_list_item_1,
+ trackingTypes
+ )
+ val listPopup = ListPopupWindow(this)
+ listPopup.setAdapter(profileAdapter)
+ listPopup.anchorView = locationTrackingBtn
+ listPopup.setOnItemClickListener { parent: AdapterView<*>?, itemView: View?, position: Int, id: Long ->
+ val selectedTrackingType = trackingTypes[position]
+ locationTrackingBtn!!.text = selectedTrackingType
+ if (selectedTrackingType.contentEquals("None")) {
+ setCameraTrackingMode(CameraMode.NONE)
+ } else if (selectedTrackingType.contentEquals("None Compass")) {
+ setCameraTrackingMode(CameraMode.NONE_COMPASS)
+ } else if (selectedTrackingType.contentEquals("None GPS")) {
+ setCameraTrackingMode(CameraMode.NONE_GPS)
+ } else if (selectedTrackingType.contentEquals("Tracking")) {
+ setCameraTrackingMode(CameraMode.TRACKING)
+ } else if (selectedTrackingType.contentEquals("Tracking Compass")) {
+ setCameraTrackingMode(CameraMode.TRACKING_COMPASS)
+ } else if (selectedTrackingType.contentEquals("Tracking GPS")) {
+ setCameraTrackingMode(CameraMode.TRACKING_GPS)
+ } else if (selectedTrackingType.contentEquals("Tracking GPS North")) {
+ setCameraTrackingMode(CameraMode.TRACKING_GPS_NORTH)
+ }
+ listPopup.dismiss()
+ }
+ listPopup.show()
+ }
+
+ private fun setCameraTrackingMode(@CameraMode.Mode mode: Int) {
+ locationComponent!!.setCameraMode(
+ mode,
+ 1200,
+ 16.0,
+ null,
+ 45.0,
+ object : OnLocationCameraTransitionListener {
+ override fun onLocationCameraTransitionFinished(@CameraMode.Mode cameraMode: Int) {
+ Toast.makeText(
+ this@LocationModesActivity,
+ "Transition finished",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+
+ override fun onLocationCameraTransitionCanceled(@CameraMode.Mode cameraMode: Int) {
+ Toast.makeText(
+ this@LocationModesActivity,
+ "Transition canceled",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+ }
+ )
+ }
+
+ override fun onCameraTrackingDismissed() {
+ locationTrackingBtn!!.text = "None"
+ }
+
+ override fun onCameraTrackingChanged(currentMode: Int) {
+ cameraMode = currentMode
+ if (currentMode == CameraMode.NONE) {
+ locationTrackingBtn!!.text = "None"
+ } else if (currentMode == CameraMode.NONE_COMPASS) {
+ locationTrackingBtn!!.text = "None Compass"
+ } else if (currentMode == CameraMode.NONE_GPS) {
+ locationTrackingBtn!!.text = "None GPS"
+ } else if (currentMode == CameraMode.TRACKING) {
+ locationTrackingBtn!!.text = "Tracking"
+ } else if (currentMode == CameraMode.TRACKING_COMPASS) {
+ locationTrackingBtn!!.text = "Tracking Compass"
+ } else if (currentMode == CameraMode.TRACKING_GPS) {
+ locationTrackingBtn!!.text = "Tracking GPS"
+ } else if (currentMode == CameraMode.TRACKING_GPS_NORTH) {
+ locationTrackingBtn!!.text = "Tracking GPS North"
+ }
+ }
+
+ companion object {
+ private const val SAVED_STATE_CAMERA = "saved_state_camera"
+ private const val SAVED_STATE_RENDER = "saved_state_render"
+ private const val SAVED_STATE_LOCATION = "saved_state_location"
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java
deleted file mode 100644
index bc7b8afd9..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java
+++ /dev/null
@@ -1,171 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.location;
-
-import android.annotation.SuppressLint;
-import android.os.Bundle;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.google.android.material.floatingactionbutton.FloatingActionButton;
-import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-import com.mapbox.mapboxsdk.location.LocationComponent;
-import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
-import com.mapbox.mapboxsdk.location.engine.LocationEngine;
-import com.mapbox.mapboxsdk.location.engine.LocationEngineProvider;
-import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest;
-import com.mapbox.mapboxsdk.location.modes.RenderMode;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsListener;
-import com.mapbox.mapboxsdk.location.permissions.PermissionsManager;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-import java.util.List;
-
-public class ManualLocationUpdatesActivity extends AppCompatActivity implements OnMapReadyCallback {
-
- private MapView mapView;
- private LocationComponent locationComponent;
- private LocationEngine locationEngine;
- private PermissionsManager permissionsManager;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_location_manual_update);
-
- locationEngine = LocationEngineProvider.getBestLocationEngine(this, false);
-
- FloatingActionButton fabManualUpdate = findViewById(R.id.fabManualLocationChange);
- fabManualUpdate.setOnClickListener(v -> {
- if (locationComponent != null && locationComponent.getLocationEngine() == null) {
- locationComponent.forceLocationUpdate(
- Utils.getRandomLocation(LatLngBounds.from(60, 25, 40, -5)));
- }
- });
- fabManualUpdate.setEnabled(false);
-
- FloatingActionButton fabToggle = findViewById(R.id.fabToggleManualLocation);
- fabToggle.setOnClickListener(v -> {
- if (locationComponent != null) {
- locationComponent.setLocationEngine(locationComponent.getLocationEngine() == null ? locationEngine : null);
-
- if (locationComponent.getLocationEngine() == null) {
- fabToggle.setImageResource(R.drawable.ic_layers_clear);
- fabManualUpdate.setEnabled(true);
- fabManualUpdate.setAlpha(1f);
- Toast.makeText(
- ManualLocationUpdatesActivity.this.getApplicationContext(),
- "LocationEngine disabled, use manual updates",
- Toast.LENGTH_SHORT).show();
- } else {
- fabToggle.setImageResource(R.drawable.ic_layers);
- fabManualUpdate.setEnabled(false);
- fabManualUpdate.setAlpha(0.5f);
- Toast.makeText(
- ManualLocationUpdatesActivity.this.getApplicationContext(),
- "LocationEngine enabled",
- Toast.LENGTH_SHORT).show();
- }
- }
- });
-
- mapView = findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
-
- if (PermissionsManager.areLocationPermissionsGranted(this)) {
- mapView.getMapAsync(this);
- } else {
- permissionsManager = new PermissionsManager(new PermissionsListener() {
- @Override
- public void onExplanationNeeded(List permissionsToExplain) {
- Toast.makeText(ManualLocationUpdatesActivity.this.getApplicationContext(),
- "You need to accept location permissions.",
- Toast.LENGTH_SHORT
- ).show();
- }
-
- @Override
- public void onPermissionResult(boolean granted) {
- if (granted) {
- mapView.getMapAsync(ManualLocationUpdatesActivity.this);
- } else {
- finish();
- }
- }
- });
- permissionsManager.requestLocationPermissions(this);
- }
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
- }
-
- @SuppressLint("MissingPermission")
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- mapboxMap.setStyle(new Style.Builder().fromUri(Style.getPredefinedStyle("Streets")), style -> {
- locationComponent = mapboxMap.getLocationComponent();
-
- locationComponent.activateLocationComponent(
- LocationComponentActivationOptions
- .builder(this, style)
- .locationEngine(locationEngine)
- .locationEngineRequest(new LocationEngineRequest.Builder(500)
- .setFastestInterval(500)
- .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY).build())
- .build());
-
- locationComponent.setLocationComponentEnabled(true);
- locationComponent.setRenderMode(RenderMode.COMPASS);
- });
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-}
\ No newline at end of file
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
new file mode 100644
index 000000000..0d95b639b
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.kt
@@ -0,0 +1,159 @@
+package com.mapbox.mapboxsdk.testapp.activity.location
+
+import android.annotation.SuppressLint
+import android.os.Bundle
+import android.view.View
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import com.google.android.material.floatingactionbutton.FloatingActionButton
+import com.mapbox.mapboxsdk.geometry.LatLngBounds
+import com.mapbox.mapboxsdk.location.LocationComponent
+import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions
+import com.mapbox.mapboxsdk.location.engine.LocationEngine
+import com.mapbox.mapboxsdk.location.engine.LocationEngineProvider
+import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest
+import com.mapbox.mapboxsdk.location.modes.RenderMode
+import com.mapbox.mapboxsdk.location.permissions.PermissionsListener
+import com.mapbox.mapboxsdk.location.permissions.PermissionsManager
+import com.mapbox.mapboxsdk.maps.MapView
+import com.mapbox.mapboxsdk.maps.MapboxMap
+import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
+import com.mapbox.mapboxsdk.maps.Style
+import com.mapbox.mapboxsdk.testapp.R
+
+class ManualLocationUpdatesActivity : AppCompatActivity(), OnMapReadyCallback {
+ private lateinit var mapView: MapView
+ private var locationComponent: LocationComponent? = null
+ private var locationEngine: LocationEngine? = null
+ private var permissionsManager: PermissionsManager? = null
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_location_manual_update)
+ locationEngine = LocationEngineProvider.getBestLocationEngine(this, false)
+ val fabManualUpdate = findViewById(R.id.fabManualLocationChange)
+ fabManualUpdate.setOnClickListener { v: View? ->
+ if (locationComponent != null && locationComponent!!.locationEngine == null) {
+ locationComponent!!.forceLocationUpdate(
+ Utils.getRandomLocation(LatLngBounds.from(60.0, 25.0, 40.0, -5.0))
+ )
+ }
+ }
+ fabManualUpdate.isEnabled = false
+ val fabToggle = findViewById(R.id.fabToggleManualLocation)
+ fabToggle.setOnClickListener { v: View? ->
+ if (locationComponent != null) {
+ locationComponent!!.locationEngine =
+ if (locationComponent!!.locationEngine == null) locationEngine else null
+ if (locationComponent!!.locationEngine == null) {
+ fabToggle.setImageResource(R.drawable.ic_layers_clear)
+ fabManualUpdate.isEnabled = true
+ fabManualUpdate.alpha = 1f
+ Toast.makeText(
+ this@ManualLocationUpdatesActivity.applicationContext,
+ "LocationEngine disabled, use manual updates",
+ Toast.LENGTH_SHORT
+ ).show()
+ } else {
+ fabToggle.setImageResource(R.drawable.ic_layers)
+ fabManualUpdate.isEnabled = false
+ fabManualUpdate.alpha = 0.5f
+ Toast.makeText(
+ this@ManualLocationUpdatesActivity.applicationContext,
+ "LocationEngine enabled",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+ }
+ }
+ mapView = findViewById(R.id.mapView)
+ mapView.onCreate(savedInstanceState)
+ if (PermissionsManager.areLocationPermissionsGranted(this)) {
+ mapView.getMapAsync(this)
+ } else {
+ permissionsManager = PermissionsManager(object : PermissionsListener {
+ override fun onExplanationNeeded(permissionsToExplain: List) {
+ Toast.makeText(
+ this@ManualLocationUpdatesActivity.applicationContext,
+ "You need to accept location permissions.",
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+
+ override fun onPermissionResult(granted: Boolean) {
+ if (granted) {
+ mapView.getMapAsync(this@ManualLocationUpdatesActivity)
+ } else {
+ finish()
+ }
+ }
+ })
+ permissionsManager!!.requestLocationPermissions(this)
+ }
+ }
+
+ override fun onRequestPermissionsResult(
+ requestCode: Int,
+ permissions: Array,
+ grantResults: IntArray
+ ) {
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ permissionsManager!!.onRequestPermissionsResult(requestCode, permissions, grantResults)
+ }
+
+ @SuppressLint("MissingPermission")
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ mapboxMap.setStyle(
+ Style.Builder().fromUri(Style.getPredefinedStyle("Streets"))
+ ) { style: Style? ->
+ locationComponent = mapboxMap.locationComponent
+ locationComponent!!.activateLocationComponent(
+ LocationComponentActivationOptions
+ .builder(this, style!!)
+ .locationEngine(locationEngine)
+ .locationEngineRequest(
+ LocationEngineRequest.Builder(500)
+ .setFastestInterval(500)
+ .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY).build()
+ )
+ .build()
+ )
+ locationComponent!!.isLocationComponentEnabled = true
+ locationComponent!!.renderMode = RenderMode.COMPASS
+ }
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.java
deleted file mode 100644
index c23cd5f34..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.location;
-
-import android.location.Location;
-
-import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-import com.mapbox.mapboxsdk.maps.Style;
-
-import java.util.Random;
-
-import timber.log.Timber;
-
-/**
- * Useful utilities used throughout the test app.
- */
-public class Utils {
-
- private static final String[] STYLES = new String[] {
- Style.getPredefinedStyle("Streets"),
- Style.getPredefinedStyle("Outdoor"),
- Style.getPredefinedStyle("Bright"),
- Style.getPredefinedStyle("Pastel"),
- Style.getPredefinedStyle("Satellite Hybrid")
- };
-
- private static int index;
-
- /**
- * Utility to cycle through map styles. Useful to test if runtime styling source and layers transfer over to new
- * style.
- *
- * @return a string ID representing the map style
- */
- public static String getNextStyle() {
- index++;
- if (index == STYLES.length) {
- index = 0;
- }
- return STYLES[index];
- }
-
- /**
- * Utility for getting a random coordinate inside a provided bounds and creates a {@link Location} from it.
- *
- * @param bounds bounds of the generated location
- * @return a {@link Location} object using the random coordinate
- */
- public static Location getRandomLocation(LatLngBounds bounds) {
- Random random = new Random();
-
- double randomLat = bounds.getLatSouth() + (bounds.getLatNorth() - bounds.getLatSouth()) * random.nextDouble();
- double randomLon = bounds.getLonWest() + (bounds.getLonEast() - bounds.getLonWest()) * random.nextDouble();
-
- Location location = new Location("random-loc");
- location.setLongitude(randomLon);
- location.setLatitude(randomLat);
- Timber.d("getRandomLatLng: %s", location.toString());
- return location;
- }
-}
\ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.kt
new file mode 100644
index 000000000..63131dd80
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/Utils.kt
@@ -0,0 +1,52 @@
+package com.mapbox.mapboxsdk.testapp.activity.location
+
+import android.location.Location
+import com.mapbox.mapboxsdk.geometry.LatLngBounds
+import com.mapbox.mapboxsdk.maps.Style
+import timber.log.Timber
+import java.util.*
+
+/**
+ * Useful utilities used throughout the test app.
+ */
+object Utils {
+ private val STYLES = arrayOf(
+ Style.getPredefinedStyle("Streets"),
+ Style.getPredefinedStyle("Outdoor"),
+ Style.getPredefinedStyle("Bright"),
+ Style.getPredefinedStyle("Pastel"),
+ Style.getPredefinedStyle("Satellite Hybrid")
+ )
+ private var index = 0
+
+ /**
+ * Utility to cycle through map styles. Useful to test if runtime styling source and layers transfer over to new
+ * style.
+ *
+ * @return a string ID representing the map style
+ */
+ fun nextStyle(): String {
+ index++
+ if (index == STYLES.size) {
+ index = 0
+ }
+ return STYLES[index]
+ }
+
+ /**
+ * Utility for getting a random coordinate inside a provided bounds and creates a [Location] from it.
+ *
+ * @param bounds bounds of the generated location
+ * @return a [Location] object using the random coordinate
+ */
+ fun getRandomLocation(bounds: LatLngBounds): Location {
+ val random = Random()
+ val randomLat = bounds.latSouth + (bounds.latNorth - bounds.latSouth) * random.nextDouble()
+ val randomLon = bounds.lonWest + (bounds.lonEast - bounds.lonWest) * random.nextDouble()
+ val location = Location("random-loc")
+ location.longitude = randomLon
+ location.latitude = randomLat
+ Timber.d("getRandomLatLng: %s", location.toString())
+ return location
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.java
deleted file mode 100644
index dfd8c01ee..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.java
+++ /dev/null
@@ -1,284 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.maplayout;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
-
-import com.google.android.material.bottomsheet.BottomSheetBehavior;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-import com.mapbox.mapboxsdk.utils.MapFragmentUtils;
-
-/**
- * Test activity showcasing using a bottomView with a MapView and stacking map fragments below.
- */
-public class BottomSheetActivity extends AppCompatActivity {
-
- private static final String TAG_MAIN_FRAGMENT = "com.mapbox.mapboxsdk.fragment.tag.main";
- private static final String TAG_BOTTOM_FRAGMENT = "com.mapbox.mapboxsdk.fragment.tag.bottom";
- private static final String AMOUNT_OF_MAIN_MAP_FRAGMENTS = "Amount of main map fragments: %s";
- private boolean bottomSheetFragmentAdded;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_bottom_sheet);
-
- ActionBar actionBar = getSupportActionBar();
- if (actionBar != null) {
- actionBar.setDisplayHomeAsUpEnabled(true);
- }
-
- findViewById(R.id.fabFragment).setOnClickListener(v -> addMapFragment());
-
- findViewById(R.id.fabBottomSheet).setOnClickListener(v -> toggleBottomSheetMapFragment());
-
- BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet));
- bottomSheetBehavior.setPeekHeight((int) (64 * getResources().getDisplayMetrics().density));
- bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
- toggleBottomSheetMapFragment();
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == android.R.id.home) {
- onBackPressed();
- }
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- public void onBackPressed() {
- FragmentManager fragmentManager = getSupportFragmentManager();
-
- if (fragmentManager.getBackStackEntryCount() > 0) {
- fragmentManager.popBackStack();
- } else {
- super.onBackPressed();
- }
- }
-
- private void addMapFragment() {
- FragmentManager fragmentManager = getSupportFragmentManager();
- int fragmentCount = fragmentManager.getBackStackEntryCount();
-
- FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
- MainMapFragment mainMapFragment = MainMapFragment.newInstance(this, fragmentCount);
- if (fragmentCount == 0) {
- fragmentTransaction.add(R.id.fragment_container, mainMapFragment, TAG_MAIN_FRAGMENT);
- } else {
- fragmentTransaction.replace(R.id.fragment_container, mainMapFragment, TAG_MAIN_FRAGMENT);
- }
- fragmentTransaction.addToBackStack(String.valueOf(mainMapFragment.hashCode()));
- fragmentTransaction.commit();
- Toast.makeText(getApplicationContext(),
- String.format(AMOUNT_OF_MAIN_MAP_FRAGMENTS, (fragmentCount + 1)),
- Toast.LENGTH_SHORT
- ).show();
- }
-
- private void toggleBottomSheetMapFragment() {
- if (!bottomSheetFragmentAdded) {
- addBottomSheetMapFragment();
- } else {
- removeBottomSheetFragment();
- }
- bottomSheetFragmentAdded = !bottomSheetFragmentAdded;
- }
-
- private void addBottomSheetMapFragment() {
- FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
- fragmentTransaction.add(R.id.fragment_container_bottom, BottomSheetFragment.newInstance(this), TAG_BOTTOM_FRAGMENT);
- fragmentTransaction.commit();
- }
-
- private void removeBottomSheetFragment() {
- Fragment fragment = getSupportFragmentManager().findFragmentByTag(TAG_BOTTOM_FRAGMENT);
- if (fragment != null) {
- getSupportFragmentManager().beginTransaction().remove(fragment).commit();
- }
- }
-
- public static class MainMapFragment extends Fragment implements OnMapReadyCallback {
-
- private static final String[] STYLES = new String[] {
- Style.getPredefinedStyle("Streets"),
- Style.getPredefinedStyle("Satellite Hybrid"),
- Style.getPredefinedStyle("Bright"),
- Style.getPredefinedStyle("Pastel"),
- Style.getPredefinedStyle("Satellite Hybrid"),
- Style.getPredefinedStyle("Outdoor")
- };
-
- private MapView map;
-
- public static MainMapFragment newInstance(Context context, int mapCounter) {
- MainMapFragment mapFragment = new MainMapFragment();
- Bundle bundle = new Bundle();
- bundle.putInt("mapcounter", mapCounter);
- mapFragment.setArguments(bundle);
- MapboxMapOptions mapboxMapOptions = MapboxMapOptions.createFromAttributes(context);
- mapFragment.setArguments(MapFragmentUtils.createFragmentArgs(mapboxMapOptions));
- return mapFragment;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- super.onCreateView(inflater, container, savedInstanceState);
- Context context = inflater.getContext();
- return map = new MapView(context, MapFragmentUtils.resolveArgs(context, getArguments()));
- }
-
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- map.onCreate(savedInstanceState);
- map.getMapAsync(this);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.760545, -122.436055), 15));
- mapboxMap.setStyle(
- new Style.Builder().fromUri(
- STYLES[Math.min(Math.max(getArguments().getInt("mapcounter"), 0), STYLES.length - 1)]
- )
- );
- }
-
- @Override
- public void onStart() {
- super.onStart();
- map.onStart();
- }
-
- @Override
- public void onResume() {
- super.onResume();
- map.onResume();
- }
-
- @Override
- public void onPause() {
- super.onPause();
- map.onPause();
- }
-
- @Override
- public void onStop() {
- super.onStop();
- map.onStop();
- }
-
- @Override
- public void onSaveInstanceState(@NonNull Bundle outState) {
- super.onSaveInstanceState(outState);
- map.onSaveInstanceState(outState);
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- map.onLowMemory();
- }
-
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- map.onDestroy();
- }
- }
-
- public static class BottomSheetFragment extends Fragment implements OnMapReadyCallback {
-
- private MapView map;
-
- public static BottomSheetFragment newInstance(Context context) {
- BottomSheetFragment mapFragment = new BottomSheetFragment();
- MapboxMapOptions mapboxMapOptions = MapboxMapOptions.createFromAttributes(context);
- mapboxMapOptions.renderSurfaceOnTop(true);
- mapFragment.setArguments(MapFragmentUtils.createFragmentArgs(mapboxMapOptions));
- return mapFragment;
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- super.onCreateView(inflater, container, savedInstanceState);
- Context context = inflater.getContext();
- return map = new MapView(context, MapFragmentUtils.resolveArgs(context, getArguments()));
- }
-
- @Override
- public void onViewCreated(View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- map.onCreate(savedInstanceState);
- map.getMapAsync(this);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.760545, -122.436055), 15));
- mapboxMap.setStyle(Style.getPredefinedStyle("Bright"));
- }
-
- @Override
- public void onStart() {
- super.onStart();
- map.onStart();
- }
-
- @Override
- public void onResume() {
- super.onResume();
- map.onResume();
- }
-
- @Override
- public void onPause() {
- super.onPause();
- map.onPause();
- }
-
- @Override
- public void onStop() {
- super.onStop();
- map.onStop();
- }
-
- @Override
- public void onSaveInstanceState(@NonNull Bundle outState) {
- super.onSaveInstanceState(outState);
- map.onSaveInstanceState(outState);
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- map.onLowMemory();
- }
-
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- map.onDestroy();
- }
- }
-}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.kt
new file mode 100644
index 000000000..b5ed8071a
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/BottomSheetActivity.kt
@@ -0,0 +1,275 @@
+package com.mapbox.mapboxsdk.testapp.activity.maplayout
+
+import android.content.Context
+import android.os.Bundle
+import android.view.*
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.Fragment
+import com.google.android.material.bottomsheet.BottomSheetBehavior
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.*
+import com.mapbox.mapboxsdk.testapp.R
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.BottomSheetActivity.BottomSheetFragment
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.BottomSheetActivity.MainMapFragment
+import com.mapbox.mapboxsdk.utils.MapFragmentUtils
+
+/**
+ * Test activity showcasing using a bottomView with a MapView and stacking map fragments below.
+ */
+class BottomSheetActivity : AppCompatActivity() {
+ private var bottomSheetFragmentAdded = false
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_bottom_sheet)
+ val actionBar = supportActionBar
+ actionBar?.setDisplayHomeAsUpEnabled(true)
+ findViewById(R.id.fabFragment).setOnClickListener { v: View? -> addMapFragment() }
+ findViewById(R.id.fabBottomSheet).setOnClickListener { v: View? -> toggleBottomSheetMapFragment() }
+ val bottomSheetBehavior: BottomSheetBehavior<*> =
+ BottomSheetBehavior.from(findViewById(R.id.bottom_sheet))
+ bottomSheetBehavior.peekHeight = (64 * resources.displayMetrics.density).toInt()
+ bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED
+ toggleBottomSheetMapFragment()
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ if (item.itemId == android.R.id.home) {
+ onBackPressed()
+ }
+ return super.onOptionsItemSelected(item)
+ }
+
+ override fun onBackPressed() {
+ val fragmentManager = supportFragmentManager
+ if (fragmentManager.backStackEntryCount > 0) {
+ fragmentManager.popBackStack()
+ } else {
+ super.onBackPressed()
+ }
+ }
+
+ private fun addMapFragment() {
+ val fragmentManager = supportFragmentManager
+ val fragmentCount = fragmentManager.backStackEntryCount
+ val fragmentTransaction = fragmentManager.beginTransaction()
+ val mainMapFragment = MainMapFragment.newInstance(this, fragmentCount)
+ if (fragmentCount == 0) {
+ fragmentTransaction.add(R.id.fragment_container, mainMapFragment, TAG_MAIN_FRAGMENT)
+ } else {
+ fragmentTransaction.replace(R.id.fragment_container, mainMapFragment, TAG_MAIN_FRAGMENT)
+ }
+ fragmentTransaction.addToBackStack(mainMapFragment.hashCode().toString())
+ fragmentTransaction.commit()
+ Toast.makeText(
+ applicationContext,
+ String.format(AMOUNT_OF_MAIN_MAP_FRAGMENTS, fragmentCount + 1),
+ Toast.LENGTH_SHORT
+ ).show()
+ }
+
+ private fun toggleBottomSheetMapFragment() {
+ if (!bottomSheetFragmentAdded) {
+ addBottomSheetMapFragment()
+ } else {
+ removeBottomSheetFragment()
+ }
+ bottomSheetFragmentAdded = !bottomSheetFragmentAdded
+ }
+
+ private fun addBottomSheetMapFragment() {
+ val fragmentTransaction = supportFragmentManager.beginTransaction()
+ fragmentTransaction.add(
+ R.id.fragment_container_bottom,
+ BottomSheetFragment.newInstance(this),
+ TAG_BOTTOM_FRAGMENT
+ )
+ fragmentTransaction.commit()
+ }
+
+ private fun removeBottomSheetFragment() {
+ val fragment = supportFragmentManager.findFragmentByTag(TAG_BOTTOM_FRAGMENT)
+ if (fragment != null) {
+ supportFragmentManager.beginTransaction().remove(fragment).commit()
+ }
+ }
+
+ class MainMapFragment : Fragment(), OnMapReadyCallback {
+ private var map: MapView? = null
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ super.onCreateView(inflater, container, savedInstanceState)
+ val context = inflater.context
+ return MapView(context, MapFragmentUtils.resolveArgs(context, arguments)).also {
+ map = it
+ }
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ map!!.onCreate(savedInstanceState)
+ map!!.getMapAsync(this)
+ }
+
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ mapboxMap.moveCamera(
+ CameraUpdateFactory.newLatLngZoom(
+ LatLng(37.760545, -122.436055),
+ 15.0
+ )
+ )
+ mapboxMap.setStyle(
+ Style.Builder().fromUri(
+ STYLES[
+ Math.min(
+ Math.max(arguments!!.getInt("mapcounter"), 0),
+ STYLES.size - 1
+ )
+ ]
+ )
+ )
+ }
+
+ override fun onStart() {
+ super.onStart()
+ map!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ map!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ map!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ map!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ map!!.onSaveInstanceState(outState)
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ map!!.onLowMemory()
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ map!!.onDestroy()
+ }
+
+ companion object {
+ private val STYLES = arrayOf(
+ Style.getPredefinedStyle("Streets"),
+ Style.getPredefinedStyle("Satellite Hybrid"),
+ Style.getPredefinedStyle("Bright"),
+ Style.getPredefinedStyle("Pastel"),
+ Style.getPredefinedStyle("Satellite Hybrid"),
+ Style.getPredefinedStyle("Outdoor")
+ )
+
+ fun newInstance(context: Context?, mapCounter: Int): MainMapFragment {
+ val mapFragment = MainMapFragment()
+ val bundle = Bundle()
+ bundle.putInt("mapcounter", mapCounter)
+ mapFragment.arguments = bundle
+ val mapboxMapOptions = MapboxMapOptions.createFromAttributes(context!!)
+ mapFragment.arguments = MapFragmentUtils.createFragmentArgs(mapboxMapOptions)
+ return mapFragment
+ }
+ }
+ }
+
+ class BottomSheetFragment : Fragment(), OnMapReadyCallback {
+ private var map: MapView? = null
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ super.onCreateView(inflater, container, savedInstanceState)
+ val context = inflater.context
+ return MapView(context, MapFragmentUtils.resolveArgs(context, arguments)).also {
+ map = it
+ }
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ map!!.onCreate(savedInstanceState)
+ map!!.getMapAsync(this)
+ }
+
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ mapboxMap.moveCamera(
+ CameraUpdateFactory.newLatLngZoom(
+ LatLng(37.760545, -122.436055),
+ 15.0
+ )
+ )
+ mapboxMap.setStyle(Style.getPredefinedStyle("Bright"))
+ }
+
+ override fun onStart() {
+ super.onStart()
+ map!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ map!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ map!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ map!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ map!!.onSaveInstanceState(outState)
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ map!!.onLowMemory()
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ map!!.onDestroy()
+ }
+
+ companion object {
+ fun newInstance(context: Context?): BottomSheetFragment {
+ val mapFragment = BottomSheetFragment()
+ val mapboxMapOptions = MapboxMapOptions.createFromAttributes(context!!)
+ mapboxMapOptions.renderSurfaceOnTop(true)
+ mapFragment.arguments = MapFragmentUtils.createFragmentArgs(mapboxMapOptions)
+ return mapFragment
+ }
+ }
+ }
+
+ companion object {
+ private const val TAG_MAIN_FRAGMENT = "com.mapbox.mapboxsdk.fragment.tag.main"
+ private const val TAG_BOTTOM_FRAGMENT = "com.mapbox.mapboxsdk.fragment.tag.bottom"
+ private const val AMOUNT_OF_MAIN_MAP_FRAGMENTS = "Amount of main map fragments: %s"
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.java
deleted file mode 100644
index 4dcb79ca5..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.java
+++ /dev/null
@@ -1,304 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.maplayout;
-
-import android.content.Context;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.BaseAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.ActionBarDrawerToggle;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.drawerlayout.widget.DrawerLayout;
-
-import com.google.android.material.floatingactionbutton.FloatingActionButton;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.style.layers.Layer;
-import com.mapbox.mapboxsdk.style.layers.Property;
-import com.mapbox.mapboxsdk.testapp.R;
-
-import java.util.List;
-import java.util.Locale;
-
-import timber.log.Timber;
-
-import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
-
-/**
- * Test activity showcasing the different debug modes and allows to cycle between the default map styles.
- */
-public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCallback, MapboxMap.OnFpsChangedListener {
-
- private MapView mapView;
- private MapboxMap mapboxMap;
- private MapboxMap.OnCameraMoveListener cameraMoveListener;
- private ActionBarDrawerToggle actionBarDrawerToggle;
- private int currentStyleIndex;
- private boolean isReportFps = true;
-
- private static final String[] STYLES = new String[] {
- Style.getPredefinedStyle("Streets"),
- Style.getPredefinedStyle("Outdoor"),
- Style.getPredefinedStyle("Bright"),
- Style.getPredefinedStyle("Pastel"),
- Style.getPredefinedStyle("Satellite Hybrid"),
- Style.getPredefinedStyle("Satellite Hybrid") };
- private TextView fpsView;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_debug_mode);
- setupToolbar();
- setupMapView(savedInstanceState);
- setupDebugChangeView();
- setupStyleChangeView();
- }
-
- private void setupToolbar() {
- ActionBar actionBar = getSupportActionBar();
- if (actionBar != null) {
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setHomeButtonEnabled(true);
- DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
- actionBarDrawerToggle = new ActionBarDrawerToggle(this,
- drawerLayout,
- R.string.navigation_drawer_open,
- R.string.navigation_drawer_close
- );
- actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
- actionBarDrawerToggle.syncState();
- }
- }
-
- private void setupMapView(Bundle savedInstanceState) {
- MapboxMapOptions mapboxMapOptions = setupMapboxMapOptions();
- mapView = new MapView(this, mapboxMapOptions);
- ((ViewGroup) findViewById(R.id.coordinator_layout)).addView(mapView, 0);
- mapView.addOnDidFinishLoadingStyleListener(() -> {
- if (mapboxMap != null) {
- setupNavigationView(mapboxMap.getStyle().getLayers());
- }
- });
-
- mapView.setTag(true);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(this);
- mapView.addOnDidFinishLoadingStyleListener(() -> Timber.d("Style loaded"));
- }
-
- protected MapboxMapOptions setupMapboxMapOptions() {
- return MapboxMapOptions.createFromAttributes(this, null);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap map) {
- mapboxMap = map;
- mapboxMap.setStyle(
- new Style.Builder().fromUri(STYLES[currentStyleIndex]), style -> setupNavigationView(style.getLayers())
- );
- setupZoomView();
- setFpsView();
- }
-
- private void setFpsView() {
- fpsView = findViewById(R.id.fpsView);
- mapboxMap.setOnFpsChangedListener(this);
- }
-
- @Override
- public void onFpsChanged(double fps) {
- fpsView.setText(String.format(Locale.US, "FPS: %4.2f", fps));
- }
-
- private void setupNavigationView(List layerList) {
- Timber.v("New style loaded with JSON: %s", mapboxMap.getStyle().getJson());
- final LayerListAdapter adapter = new LayerListAdapter(this, layerList);
- ListView listView = findViewById(R.id.listView);
- listView.setAdapter(adapter);
- listView.setOnItemClickListener((parent, view, position, id) -> {
- Layer clickedLayer = adapter.getItem(position);
- toggleLayerVisibility(clickedLayer);
- closeNavigationView();
- });
- }
-
- private void toggleLayerVisibility(Layer layer) {
- boolean isVisible = layer.getVisibility().getValue().equals(Property.VISIBLE);
- layer.setProperties(
- visibility(
- isVisible ? Property.NONE : Property.VISIBLE
- )
- );
- }
-
- private void closeNavigationView() {
- DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
- drawerLayout.closeDrawers();
- }
-
- private void setupZoomView() {
- final TextView textView = findViewById(R.id.textZoom);
- mapboxMap.addOnCameraMoveListener(cameraMoveListener = new MapboxMap.OnCameraMoveListener() {
- @Override
- public void onCameraMove() {
- textView.setText(String.format(DebugModeActivity.this.getString(
- R.string.debug_zoom), mapboxMap.getCameraPosition().zoom));
- }
- });
- }
-
- private void setupDebugChangeView() {
- FloatingActionButton fabDebug = findViewById(R.id.fabDebug);
- fabDebug.setOnClickListener(view -> {
- if (mapboxMap != null) {
- mapboxMap.setDebugActive(!mapboxMap.isDebugActive());
- Timber.d("Debug FAB: isDebug Active? %s", mapboxMap.isDebugActive());
- }
- });
- }
-
- private void setupStyleChangeView() {
- FloatingActionButton fabStyles = findViewById(R.id.fabStyles);
- fabStyles.setOnClickListener(view -> {
- if (mapboxMap != null) {
- currentStyleIndex++;
- if (currentStyleIndex == STYLES.length) {
- currentStyleIndex = 0;
- }
- mapboxMap.setStyle(new Style.Builder().fromUri(STYLES[currentStyleIndex]));
- }
- });
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- int itemId = item.getItemId();
- if (itemId == R.id.menu_action_toggle_report_fps) {
- isReportFps = !isReportFps;
- fpsView.setVisibility(isReportFps ? View.VISIBLE : View.GONE);
- mapboxMap.setOnFpsChangedListener(isReportFps ? this : null);
- } else if (itemId == R.id.menu_action_limit_to_30_fps) {
- mapView.setMaximumFps(30);
- } else if (itemId == R.id.menu_action_limit_to_60_fps) {
- mapView.setMaximumFps(60);
- }
-
- return actionBarDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_debug, menu);
- return true;
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (mapboxMap != null) {
- mapboxMap.removeOnCameraMoveListener(cameraMoveListener);
- }
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-
- private static class LayerListAdapter extends BaseAdapter {
-
- private LayoutInflater layoutInflater;
- private List layers;
-
- LayerListAdapter(Context context, List layers) {
- this.layoutInflater = LayoutInflater.from(context);
- this.layers = layers;
- }
-
- @Override
- public int getCount() {
- return layers.size();
- }
-
- @Override
- public Layer getItem(int position) {
- return layers.get(position);
- }
-
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- Layer layer = layers.get(position);
- View view = convertView;
- if (view == null) {
- view = layoutInflater.inflate(android.R.layout.simple_list_item_2, parent, false);
- ViewHolder holder = new ViewHolder(
- view.findViewById(android.R.id.text1),
- view.findViewById(android.R.id.text2)
- );
- view.setTag(holder);
- }
- ViewHolder holder = (ViewHolder) view.getTag();
- holder.text.setText(layer.getClass().getSimpleName());
- holder.subText.setText(layer.getId());
- return view;
- }
-
- private static class ViewHolder {
- final TextView text;
- final TextView subText;
-
- ViewHolder(TextView text, TextView subText) {
- this.text = text;
- this.subText = subText;
- }
- }
- }
-}
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
new file mode 100644
index 000000000..8c644627f
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DebugModeActivity.kt
@@ -0,0 +1,270 @@
+package com.mapbox.mapboxsdk.testapp.activity.maplayout
+
+import android.content.Context
+import android.os.Bundle
+import android.view.*
+import android.widget.*
+import androidx.appcompat.app.ActionBarDrawerToggle
+import androidx.appcompat.app.AppCompatActivity
+import androidx.drawerlayout.widget.DrawerLayout
+import com.google.android.material.floatingactionbutton.FloatingActionButton
+import com.mapbox.mapboxsdk.maps.*
+import com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveListener
+import com.mapbox.mapboxsdk.maps.MapboxMap.OnFpsChangedListener
+import com.mapbox.mapboxsdk.style.layers.Layer
+import com.mapbox.mapboxsdk.style.layers.Property
+import com.mapbox.mapboxsdk.style.layers.PropertyFactory
+import com.mapbox.mapboxsdk.testapp.R
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.DebugModeActivity.LayerListAdapter
+import timber.log.Timber
+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 var cameraMoveListener: OnCameraMoveListener? = null
+ private var actionBarDrawerToggle: ActionBarDrawerToggle? = null
+ private var currentStyleIndex = 0
+ private var isReportFps = true
+ private var fpsView: TextView? = null
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_debug_mode)
+ setupToolbar()
+ setupMapView(savedInstanceState)
+ setupDebugChangeView()
+ setupStyleChangeView()
+ }
+
+ private fun setupToolbar() {
+ val actionBar = supportActionBar
+ if (actionBar != null) {
+ supportActionBar!!.setDisplayHomeAsUpEnabled(true)
+ supportActionBar!!.setHomeButtonEnabled(true)
+ val drawerLayout = findViewById(R.id.drawer_layout)
+ actionBarDrawerToggle = ActionBarDrawerToggle(
+ this,
+ drawerLayout,
+ R.string.navigation_drawer_open,
+ R.string.navigation_drawer_close
+ )
+ actionBarDrawerToggle!!.isDrawerIndicatorEnabled = true
+ actionBarDrawerToggle!!.syncState()
+ }
+ }
+
+ private fun setupMapView(savedInstanceState: Bundle?) {
+ val mapboxMapOptions = setupMapboxMapOptions()
+ mapView = MapView(this, mapboxMapOptions)
+ (findViewById(R.id.coordinator_layout) as ViewGroup).addView(mapView, 0)
+ mapView!!.addOnDidFinishLoadingStyleListener {
+ if (mapboxMap != null) {
+ setupNavigationView(mapboxMap!!.style!!.layers)
+ }
+ }
+ mapView!!.tag = true
+ mapView!!.onCreate(savedInstanceState)
+ mapView!!.getMapAsync(this)
+ mapView!!.addOnDidFinishLoadingStyleListener { Timber.d("Style loaded") }
+ }
+
+ protected open fun setupMapboxMapOptions(): MapboxMapOptions {
+ return MapboxMapOptions.createFromAttributes(this, null)
+ }
+
+ override fun onMapReady(map: MapboxMap) {
+ mapboxMap = map
+ mapboxMap!!.setStyle(
+ Style.Builder().fromUri(STYLES[currentStyleIndex])
+ ) { style: Style -> setupNavigationView(style.layers) }
+ setupZoomView()
+ setFpsView()
+ }
+
+ private fun setFpsView() {
+ fpsView = findViewById(R.id.fpsView)
+ mapboxMap!!.setOnFpsChangedListener(this)
+ }
+
+ override fun onFpsChanged(fps: Double) {
+ fpsView!!.text = String.format(Locale.US, "FPS: %4.2f", fps)
+ }
+
+ private fun setupNavigationView(layerList: List) {
+ 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
+ listView.onItemClickListener =
+ AdapterView.OnItemClickListener { parent: AdapterView<*>?, view: View?, position: Int, id: Long ->
+ val clickedLayer = adapter.getItem(position)
+ toggleLayerVisibility(clickedLayer)
+ closeNavigationView()
+ }
+ }
+
+ private fun toggleLayerVisibility(layer: Layer) {
+ val isVisible = layer.visibility.getValue() == Property.VISIBLE
+ layer.setProperties(
+ PropertyFactory.visibility(
+ if (isVisible) Property.NONE else Property.VISIBLE
+ )
+ )
+ }
+
+ private fun closeNavigationView() {
+ val drawerLayout = findViewById(R.id.drawer_layout)
+ drawerLayout.closeDrawers()
+ }
+
+ private fun setupZoomView() {
+ val textView = findViewById(R.id.textZoom)
+ mapboxMap!!.addOnCameraMoveListener(
+ OnCameraMoveListener {
+ textView.text = String.format(
+ this@DebugModeActivity.getString(
+ R.string.debug_zoom
+ ),
+ mapboxMap!!.cameraPosition.zoom
+ )
+ }.also { cameraMoveListener = it }
+ )
+ }
+
+ private fun setupDebugChangeView() {
+ 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)
+ }
+ }
+ }
+
+ private fun setupStyleChangeView() {
+ val fabStyles = findViewById(R.id.fabStyles)
+ fabStyles.setOnClickListener { view: View? ->
+ if (mapboxMap != null) {
+ currentStyleIndex++
+ if (currentStyleIndex == STYLES.size) {
+ currentStyleIndex = 0
+ }
+ mapboxMap!!.setStyle(Style.Builder().fromUri(STYLES[currentStyleIndex]))
+ }
+ }
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ val itemId = item.itemId
+ 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)
+ } else if (itemId == R.id.menu_action_limit_to_30_fps) {
+ mapView!!.setMaximumFps(30)
+ } else if (itemId == R.id.menu_action_limit_to_60_fps) {
+ mapView!!.setMaximumFps(60)
+ }
+ return actionBarDrawerToggle!!.onOptionsItemSelected(item) || super.onOptionsItemSelected(
+ item
+ )
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
+ menuInflater.inflate(R.menu.menu_debug, menu)
+ return true
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ if (mapboxMap != null) {
+ mapboxMap!!.removeOnCameraMoveListener(cameraMoveListener!!)
+ }
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+
+ private class LayerListAdapter internal constructor(context: Context?, layers: List) :
+ BaseAdapter() {
+ private val layoutInflater: LayoutInflater
+ private val layers: List
+ override fun getCount(): Int {
+ return layers.size
+ }
+
+ override fun getItem(position: Int): Layer {
+ return layers[position]
+ }
+
+ override fun getItemId(position: Int): Long {
+ return position.toLong()
+ }
+
+ override fun getView(position: Int, convertView: View, parent: ViewGroup): View {
+ val layer = layers[position]
+ var view = convertView
+ if (view == null) {
+ view = layoutInflater.inflate(android.R.layout.simple_list_item_2, parent, false)
+ val holder = ViewHolder(
+ view.findViewById(android.R.id.text1),
+ view.findViewById(android.R.id.text2)
+ )
+ view.tag = holder
+ }
+ val holder = view.tag as ViewHolder
+ holder.text.text = layer.javaClass.simpleName
+ holder.subText.text = layer.id
+ return view
+ }
+
+ private class ViewHolder internal constructor(val text: TextView, val subText: TextView)
+
+ init {
+ layoutInflater = LayoutInflater.from(context)
+ this.layers = layers
+ }
+ }
+
+ companion object {
+ private val STYLES = arrayOf(
+ Style.getPredefinedStyle("Streets"),
+ Style.getPredefinedStyle("Outdoor"),
+ Style.getPredefinedStyle("Bright"),
+ Style.getPredefinedStyle("Pastel"),
+ Style.getPredefinedStyle("Satellite Hybrid"),
+ Style.getPredefinedStyle("Satellite Hybrid")
+ )
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.java
deleted file mode 100644
index eb14a9343..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.java
+++ /dev/null
@@ -1,162 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.maplayout;
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentTransaction;
-
-import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.maps.UiSettings;
-import com.mapbox.mapboxsdk.testapp.R;
-import com.mapbox.mapboxsdk.utils.MapFragmentUtils;
-
-/**
- * Test activity showcasing having 2 maps on top of each other.
- *
- * The small map is using the `mapbox_enableZMediaOverlay="true"` configuration
- *
- */
-public class DoubleMapActivity extends AppCompatActivity {
-
- private static final String TAG_FRAGMENT = "map";
- private static final LatLng MACHU_PICCHU = new LatLng(-13.1650709, -72.5447154);
- private static final double ZOOM_IN = 12;
- private static final double ZOOM_OUT = 4;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_map_fragment);
-
- if (savedInstanceState == null) {
- MapboxMapOptions options = MapboxMapOptions.createFromAttributes(this, null);
- options.camera(new CameraPosition.Builder()
- .target(MACHU_PICCHU)
- .zoom(ZOOM_IN)
- .build()
- );
-
- DoubleMapFragment doubleMapFragment = new DoubleMapFragment();
- doubleMapFragment.setArguments(MapFragmentUtils.createFragmentArgs(options));
-
- FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
- transaction.add(R.id.fragment_container, doubleMapFragment, TAG_FRAGMENT);
- transaction.commit();
- }
- }
-
- /**
- * Custom fragment containing 2 MapViews.
- */
- public static class DoubleMapFragment extends Fragment {
-
- private MapView mapView;
- private MapView mapViewMini;
-
- @Override
- public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- return inflater.inflate(R.layout.fragment_double_map, container, false);
- }
-
- @Override
- public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
-
- // MapView large
- mapView = new MapView(view.getContext(), MapFragmentUtils.resolveArgs(view.getContext(), getArguments()));
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.getPredefinedStyle("Streets")));
- ((ViewGroup) view.findViewById(R.id.container)).addView(mapView, 0);
-
- // MapView mini
- mapViewMini = view.findViewById(R.id.mini_map);
- mapViewMini.onCreate(savedInstanceState);
- mapViewMini.getMapAsync(mapboxMap -> {
- mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
- new CameraPosition.Builder().target(MACHU_PICCHU)
- .zoom(ZOOM_OUT)
- .build()
- )
- );
- mapboxMap.setStyle(new Style.Builder().fromUri(Style.getPredefinedStyle("Bright")));
-
- UiSettings uiSettings = mapboxMap.getUiSettings();
- uiSettings.setAllGesturesEnabled(false);
- uiSettings.setCompassEnabled(false);
- uiSettings.setAttributionEnabled(false);
- uiSettings.setLogoEnabled(false);
-
- mapboxMap.addOnMapClickListener(point -> {
- // test if we can open 2 activities after each other
- Toast.makeText(mapViewMini.getContext(), "Creating a new Activity instance", Toast.LENGTH_SHORT).show();
- startActivity(new Intent(mapViewMini.getContext(), DoubleMapActivity.class));
-
- return false;
- });
- });
- }
-
- @Override
- public void onResume() {
- super.onResume();
- mapView.onResume();
- mapViewMini.onResume();
- }
-
- @Override
- public void onStart() {
- super.onStart();
- mapView.onStart();
- mapViewMini.onStart();
- }
-
- @Override
- public void onPause() {
- super.onPause();
- mapView.onPause();
- mapViewMini.onPause();
- }
-
- @Override
- public void onStop() {
- super.onStop();
- mapView.onStop();
- mapViewMini.onStop();
- }
-
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- mapView.onDestroy();
- mapViewMini.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- mapViewMini.onLowMemory();
- }
-
- @Override
- public void onSaveInstanceState(@NonNull Bundle outState) {
- super.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/DoubleMapActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.kt
new file mode 100644
index 000000000..382c5fc87
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/DoubleMapActivity.kt
@@ -0,0 +1,158 @@
+package com.mapbox.mapboxsdk.testapp.activity.maplayout
+
+import android.content.Intent
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.Toast
+import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.Fragment
+import com.mapbox.mapboxsdk.camera.CameraPosition
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.*
+import com.mapbox.mapboxsdk.testapp.R
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.DoubleMapActivity.DoubleMapFragment
+import com.mapbox.mapboxsdk.utils.MapFragmentUtils
+
+/**
+ * Test activity showcasing having 2 maps on top of each other.
+ *
+ *
+ * The small map is using the `mapbox_enableZMediaOverlay="true"` configuration
+ *
+ */
+class DoubleMapActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_map_fragment)
+ if (savedInstanceState == null) {
+ val options = MapboxMapOptions.createFromAttributes(this, null)
+ options.camera(
+ CameraPosition.Builder()
+ .target(MACHU_PICCHU)
+ .zoom(ZOOM_IN)
+ .build()
+ )
+ val doubleMapFragment = DoubleMapFragment()
+ doubleMapFragment.arguments = MapFragmentUtils.createFragmentArgs(options)
+ val transaction = supportFragmentManager.beginTransaction()
+ transaction.add(R.id.fragment_container, doubleMapFragment, TAG_FRAGMENT)
+ transaction.commit()
+ }
+ }
+
+ /**
+ * Custom fragment containing 2 MapViews.
+ */
+ class DoubleMapFragment : Fragment() {
+ private lateinit var mapView: MapView
+ private lateinit var mapViewMini: MapView
+ override fun onCreateView(
+ inflater: LayoutInflater,
+ container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ return inflater.inflate(R.layout.fragment_double_map, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
+ // MapView large
+ mapView = MapView(view.context, MapFragmentUtils.resolveArgs(view.context, arguments))
+ mapView!!.onCreate(savedInstanceState)
+ mapView!!.getMapAsync { mapboxMap: MapboxMap ->
+ mapboxMap.setStyle(
+ Style.getPredefinedStyle(
+ "Streets"
+ )
+ )
+ }
+ (view.findViewById(R.id.container) as ViewGroup).addView(mapView, 0)
+
+ // MapView mini
+ mapViewMini = view.findViewById(R.id.mini_map)
+ mapViewMini.onCreate(savedInstanceState)
+ mapViewMini.getMapAsync(
+ OnMapReadyCallback { mapboxMap: MapboxMap ->
+ mapboxMap.moveCamera(
+ CameraUpdateFactory.newCameraPosition(
+ CameraPosition.Builder().target(MACHU_PICCHU)
+ .zoom(ZOOM_OUT)
+ .build()
+ )
+ )
+ mapboxMap.setStyle(Style.Builder().fromUri(Style.getPredefinedStyle("Bright")))
+ val uiSettings = mapboxMap.uiSettings
+ uiSettings.setAllGesturesEnabled(false)
+ uiSettings.isCompassEnabled = false
+ uiSettings.isAttributionEnabled = false
+ uiSettings.isLogoEnabled = false
+ mapboxMap.addOnMapClickListener { point: LatLng? ->
+ // test if we can open 2 activities after each other
+ Toast.makeText(
+ mapViewMini.getContext(),
+ "Creating a new Activity instance",
+ Toast.LENGTH_SHORT
+ ).show()
+ startActivity(Intent(mapViewMini.getContext(), DoubleMapActivity::class.java))
+ false
+ }
+ }
+ )
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ mapViewMini!!.onResume()
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ mapViewMini!!.onStart()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ mapViewMini!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ mapViewMini!!.onStop()
+ }
+
+ override fun onDestroyView() {
+ super.onDestroyView()
+ mapView!!.onDestroy()
+ mapViewMini!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ mapViewMini!!.onLowMemory()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.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);
+ }
+ }
+
+ companion object {
+ private const val TAG_FRAGMENT = "map"
+ private val MACHU_PICCHU = LatLng(-13.1650709, -72.5447154)
+ private const val ZOOM_IN = 12.0
+ private const val ZOOM_OUT = 4.0
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java
deleted file mode 100644
index a33d25c85..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.java
+++ /dev/null
@@ -1,156 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.maplayout;
-
-import android.graphics.Color;
-import android.os.Bundle;
-import android.view.Gravity;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.FrameLayout;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mapbox.mapboxsdk.annotations.PolygonOptions;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
-import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-/**
- * Test activity showcasing restricting user gestures to a bounds around Iceland, almost worldview and IDL.
- */
-public class LatLngBoundsForCameraActivity extends AppCompatActivity implements OnMapReadyCallback {
-
- private static final LatLngBounds ICELAND_BOUNDS = new LatLngBounds.Builder()
- .include(new LatLng(66.852863, -25.985652))
- .include(new LatLng(62.985661, -12.626277))
- .build();
-
- private static final LatLngBounds ALMOST_WORLD_BOUNDS = new LatLngBounds.Builder()
- .include(new LatLng(20.0, 170.0))
- .include(new LatLng(-20, -170.0))
- .build();
-
- private static final LatLngBounds CROSS_IDL_BOUNDS = new LatLngBounds.Builder()
- .include(new LatLng(20.0, 170.0))
- .include(new LatLng(-20, 190.0))
- .build();
-
- private MapView mapView;
- private MapboxMap mapboxMap;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_restricted_bounds);
-
- mapView = findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(this);
- }
-
- @Override
- public void onMapReady(@NonNull MapboxMap mapboxMap) {
- this.mapboxMap = mapboxMap;
- mapboxMap.setStyle(Style.getPredefinedStyle("Satellite Hybrid"));
- mapboxMap.setMinZoomPreference(2);
- mapboxMap.getUiSettings().setFlingVelocityAnimationEnabled(false);
- showCrosshair();
- setupBounds(ICELAND_BOUNDS);
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu_bounds, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.menu_action_allmost_world_bounds:
- setupBounds(ALMOST_WORLD_BOUNDS);
- return true;
- case R.id.menu_action_cross_idl:
- setupBounds(CROSS_IDL_BOUNDS);
- return true;
- case R.id.menu_action_reset:
- setupBounds(null);
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
-
- private void setupBounds(@Nullable LatLngBounds bounds) {
- mapboxMap.setLatLngBoundsForCameraTarget(bounds);
- showBoundsArea(bounds);
- }
-
- private void showBoundsArea(@Nullable LatLngBounds bounds) {
- mapboxMap.clear();
- if (bounds != null) {
- PolygonOptions boundsArea = new PolygonOptions()
- .add(bounds.getNorthWest())
- .add(bounds.getNorthEast())
- .add(bounds.getSouthEast())
- .add(bounds.getSouthWest());
- boundsArea.alpha(0.25f);
- boundsArea.fillColor(Color.RED);
- mapboxMap.addPolygon(boundsArea);
- }
- }
-
- private void showCrosshair() {
- View crosshair = new View(this);
- crosshair.setLayoutParams(new FrameLayout.LayoutParams(10, 10, Gravity.CENTER));
- crosshair.setBackgroundColor(Color.BLUE);
- mapView.addView(crosshair);
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-}
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
new file mode 100644
index 000000000..03588d337
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LatLngBoundsForCameraActivity.kt
@@ -0,0 +1,135 @@
+package com.mapbox.mapboxsdk.testapp.activity.maplayout
+
+import android.graphics.Color
+import android.os.Bundle
+import android.view.*
+import android.widget.FrameLayout
+import androidx.appcompat.app.AppCompatActivity
+import com.mapbox.mapboxsdk.annotations.PolygonOptions
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.geometry.LatLngBounds
+import com.mapbox.mapboxsdk.maps.*
+import com.mapbox.mapboxsdk.testapp.R
+
+/**
+ * Test activity showcasing restricting user gestures to a bounds around Iceland, almost worldview and IDL.
+ */
+class LatLngBoundsForCameraActivity : AppCompatActivity(), OnMapReadyCallback {
+ private lateinit var mapView: MapView
+ private var mapboxMap: MapboxMap? = null
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_restricted_bounds)
+ mapView = findViewById(R.id.mapView)
+ mapView.onCreate(savedInstanceState)
+ mapView.getMapAsync(this)
+ }
+
+ override fun onMapReady(mapboxMap: MapboxMap) {
+ this.mapboxMap = mapboxMap
+ mapboxMap.setStyle(Style.getPredefinedStyle("Satellite Hybrid"))
+ mapboxMap.setMinZoomPreference(2.0)
+ mapboxMap.uiSettings.isFlingVelocityAnimationEnabled = false
+ showCrosshair()
+ setupBounds(ICELAND_BOUNDS)
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu): Boolean {
+ menuInflater.inflate(R.menu.menu_bounds, menu)
+ return true
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ when (item.itemId) {
+ R.id.menu_action_allmost_world_bounds -> {
+ setupBounds(ALMOST_WORLD_BOUNDS)
+ return true
+ }
+ R.id.menu_action_cross_idl -> {
+ setupBounds(CROSS_IDL_BOUNDS)
+ return true
+ }
+ R.id.menu_action_reset -> {
+ setupBounds(null)
+ return true
+ }
+ }
+ return super.onOptionsItemSelected(item)
+ }
+
+ private fun setupBounds(bounds: LatLngBounds?) {
+ mapboxMap!!.setLatLngBoundsForCameraTarget(bounds)
+ showBoundsArea(bounds)
+ }
+
+ private fun showBoundsArea(bounds: LatLngBounds?) {
+ mapboxMap!!.clear()
+ if (bounds != null) {
+ val boundsArea = PolygonOptions()
+ .add(bounds.northWest)
+ .add(bounds.northEast)
+ .add(bounds.southEast)
+ .add(bounds.southWest)
+ boundsArea.alpha(0.25f)
+ boundsArea.fillColor(Color.RED)
+ mapboxMap!!.addPolygon(boundsArea)
+ }
+ }
+
+ private fun showCrosshair() {
+ val crosshair = View(this)
+ crosshair.layoutParams = FrameLayout.LayoutParams(10, 10, Gravity.CENTER)
+ crosshair.setBackgroundColor(Color.BLUE)
+ mapView!!.addView(crosshair)
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+
+ companion object {
+ private val ICELAND_BOUNDS = LatLngBounds.Builder()
+ .include(LatLng(66.852863, -25.985652))
+ .include(LatLng(62.985661, -12.626277))
+ .build()
+ private val ALMOST_WORLD_BOUNDS = LatLngBounds.Builder()
+ .include(LatLng(20.0, 170.0))
+ .include(LatLng((-20).toDouble(), -170.0))
+ .build()
+ private val CROSS_IDL_BOUNDS = LatLngBounds.Builder()
+ .include(LatLng(20.0, 170.0))
+ .include(LatLng((-20).toDouble(), 190.0))
+ .build()
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LocalGlyphActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LocalGlyphActivity.java
deleted file mode 100644
index d20f98a6f..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LocalGlyphActivity.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.maplayout;
-
-import android.os.Bundle;
-
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mapbox.mapboxsdk.camera.CameraPosition;
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-/**
- * Test activity that displays the city of Suzhou with a mixture of server-generated
- * latin glyphs and CJK glyphs generated locally using "Droid Sans" as a font family.
- */
-public class LocalGlyphActivity extends AppCompatActivity {
- private MapView mapView;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_local_glyph);
-
- mapView = findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(mapboxMap -> {
- mapboxMap.setStyle(Style.getPredefinedStyle("Streets"));
- // Set initial position to Suzhou
- mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
- new CameraPosition.Builder()
- .target(new LatLng(31.3003, 120.7457))
- .zoom(11)
- .bearing(0)
- .tilt(0)
- .build()));
- });
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mapView.onSaveInstanceState(outState);
- }
-}
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
new file mode 100644
index 000000000..e77848c60
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/LocalGlyphActivity.kt
@@ -0,0 +1,74 @@
+package com.mapbox.mapboxsdk.testapp.activity.maplayout
+
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import com.mapbox.mapboxsdk.camera.CameraPosition
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.*
+import com.mapbox.mapboxsdk.testapp.R
+
+/**
+ * Test activity that displays the city of Suzhou with a mixture of server-generated
+ * latin glyphs and CJK glyphs generated locally using "Droid Sans" as a font family.
+ */
+class LocalGlyphActivity : AppCompatActivity() {
+ private lateinit var mapView: MapView
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_local_glyph)
+ mapView = findViewById(R.id.mapView)
+ mapView.onCreate(savedInstanceState)
+ mapView.getMapAsync(
+ OnMapReadyCallback { mapboxMap: MapboxMap ->
+ mapboxMap.setStyle(Style.getPredefinedStyle("Streets"))
+ // Set initial position to Suzhou
+ mapboxMap.moveCamera(
+ CameraUpdateFactory.newCameraPosition(
+ CameraPosition.Builder()
+ .target(LatLng(31.3003, 120.7457))
+ .zoom(11.0)
+ .bearing(0.0)
+ .tilt(0.0)
+ .build()
+ )
+ )
+ }
+ )
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.java
deleted file mode 100644
index 93e11b809..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.maplayout;
-
-import android.os.Bundle;
-
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
-import com.mapbox.mapboxsdk.geometry.LatLng;
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-import timber.log.Timber;
-
-/**
- * Test activity showcasing how to listen to map change events.
- */
-public class MapChangeActivity extends AppCompatActivity {
-
- private MapView mapView;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_map_simple);
-
- mapView = findViewById(R.id.mapView);
- mapView.addOnCameraIsChangingListener(() -> Timber.v("OnCameraIsChanging"));
- mapView.addOnCameraDidChangeListener(animated -> Timber.v("OnCamaraDidChange: animated: %s", animated));
- mapView.addOnCameraWillChangeListener(animated -> Timber.v("OnCameraWilChange: animated: %s", animated));
- mapView.addOnDidFailLoadingMapListener(errorMessage -> Timber.v("OnDidFailLoadingMap: %s", errorMessage));
- mapView.addOnDidFinishLoadingMapListener(() -> Timber.v("OnDidFinishLoadingMap"));
- mapView.addOnDidFinishLoadingStyleListener(() -> Timber.v("OnDidFinishLoadingStyle"));
- mapView.addOnDidFinishRenderingFrameListener(fully -> Timber.v("OnDidFinishRenderingFrame: fully: %s", fully));
- mapView.addOnDidFinishRenderingMapListener(fully -> Timber.v("OnDidFinishRenderingMap: fully: %s", fully));
- mapView.addOnDidBecomeIdleListener(() -> Timber.v("OnDidBecomeIdle"));
- mapView.addOnSourceChangedListener(sourceId -> Timber.v("OnSourceChangedListener: source with id: %s", sourceId));
- mapView.addOnWillStartLoadingMapListener(() -> Timber.v("OnWillStartLoadingMap"));
- mapView.addOnWillStartRenderingFrameListener(() -> Timber.v("OnWillStartRenderingFrame"));
- mapView.addOnWillStartRenderingMapListener(() -> Timber.v("OnWillStartRenderingMap"));
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(mapboxMap -> {
- mapboxMap.setStyle(Style.getPredefinedStyle("Streets"));
- mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
- new LatLng(55.754020, 37.620948), 12), 9000);
- });
- }
-
- @Override
- protected void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- protected void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- mapView.onLowMemory();
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- mapView.onDestroy();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.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
new file mode 100644
index 000000000..4315b55ff
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapChangeActivity.kt
@@ -0,0 +1,137 @@
+package com.mapbox.mapboxsdk.testapp.activity.maplayout
+
+import android.os.Bundle
+import androidx.appcompat.app.AppCompatActivity
+import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
+import com.mapbox.mapboxsdk.geometry.LatLng
+import com.mapbox.mapboxsdk.maps.*
+import com.mapbox.mapboxsdk.maps.MapView.OnCameraDidChangeListener
+import com.mapbox.mapboxsdk.maps.MapView.OnCameraIsChangingListener
+import com.mapbox.mapboxsdk.maps.MapView.OnCameraWillChangeListener
+import com.mapbox.mapboxsdk.maps.MapView.OnDidBecomeIdleListener
+import com.mapbox.mapboxsdk.maps.MapView.OnDidFailLoadingMapListener
+import com.mapbox.mapboxsdk.maps.MapView.OnDidFinishLoadingMapListener
+import com.mapbox.mapboxsdk.maps.MapView.OnDidFinishLoadingStyleListener
+import com.mapbox.mapboxsdk.maps.MapView.OnDidFinishRenderingFrameListener
+import com.mapbox.mapboxsdk.maps.MapView.OnDidFinishRenderingMapListener
+import com.mapbox.mapboxsdk.maps.MapView.OnSourceChangedListener
+import com.mapbox.mapboxsdk.maps.MapView.OnWillStartLoadingMapListener
+import com.mapbox.mapboxsdk.maps.MapView.OnWillStartRenderingFrameListener
+import com.mapbox.mapboxsdk.maps.MapView.OnWillStartRenderingMapListener
+import com.mapbox.mapboxsdk.testapp.R
+import timber.log.Timber
+
+/**
+ * Test activity showcasing how to listen to map change events.
+ */
+class MapChangeActivity : AppCompatActivity() {
+ private lateinit var mapView: MapView
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_map_simple)
+ mapView = findViewById(R.id.mapView)
+ mapView.addOnCameraIsChangingListener(OnCameraIsChangingListener { Timber.v("OnCameraIsChanging") })
+ mapView.addOnCameraDidChangeListener(
+ OnCameraDidChangeListener { animated: Boolean ->
+ Timber.v(
+ "OnCamaraDidChange: animated: %s",
+ animated
+ )
+ }
+ )
+ mapView.addOnCameraWillChangeListener(
+ OnCameraWillChangeListener { animated: Boolean ->
+ Timber.v(
+ "OnCameraWilChange: animated: %s",
+ animated
+ )
+ }
+ )
+ mapView.addOnDidFailLoadingMapListener(
+ OnDidFailLoadingMapListener { errorMessage: String? ->
+ Timber.v(
+ "OnDidFailLoadingMap: %s",
+ errorMessage
+ )
+ }
+ )
+ mapView.addOnDidFinishLoadingMapListener(OnDidFinishLoadingMapListener { Timber.v("OnDidFinishLoadingMap") })
+ mapView.addOnDidFinishLoadingStyleListener(OnDidFinishLoadingStyleListener { Timber.v("OnDidFinishLoadingStyle") })
+ mapView.addOnDidFinishRenderingFrameListener(
+ OnDidFinishRenderingFrameListener { fully: Boolean ->
+ Timber.v(
+ "OnDidFinishRenderingFrame: fully: %s",
+ fully
+ )
+ }
+ )
+ mapView.addOnDidFinishRenderingMapListener(
+ OnDidFinishRenderingMapListener { fully: Boolean ->
+ Timber.v(
+ "OnDidFinishRenderingMap: fully: %s",
+ fully
+ )
+ }
+ )
+ mapView.addOnDidBecomeIdleListener(OnDidBecomeIdleListener { Timber.v("OnDidBecomeIdle") })
+ mapView.addOnSourceChangedListener(
+ OnSourceChangedListener { sourceId: String? ->
+ Timber.v(
+ "OnSourceChangedListener: source with id: %s",
+ sourceId
+ )
+ }
+ )
+ mapView.addOnWillStartLoadingMapListener(OnWillStartLoadingMapListener { Timber.v("OnWillStartLoadingMap") })
+ mapView.addOnWillStartRenderingFrameListener(OnWillStartRenderingFrameListener { Timber.v("OnWillStartRenderingFrame") })
+ mapView.addOnWillStartRenderingMapListener(OnWillStartRenderingMapListener { Timber.v("OnWillStartRenderingMap") })
+ mapView.onCreate(savedInstanceState)
+ mapView.getMapAsync(
+ OnMapReadyCallback { mapboxMap: MapboxMap ->
+ mapboxMap.setStyle(Style.getPredefinedStyle("Streets"))
+ mapboxMap.animateCamera(
+ CameraUpdateFactory.newLatLngZoom(
+ LatLng(55.754020, 37.620948),
+ 12.0
+ ),
+ 9000
+ )
+ }
+ )
+ }
+
+ override fun onStart() {
+ super.onStart()
+ mapView!!.onStart()
+ }
+
+ override fun onResume() {
+ super.onResume()
+ mapView!!.onResume()
+ }
+
+ override fun onPause() {
+ super.onPause()
+ mapView!!.onPause()
+ }
+
+ override fun onStop() {
+ super.onStop()
+ mapView!!.onStop()
+ }
+
+ override fun onLowMemory() {
+ super.onLowMemory()
+ mapView!!.onLowMemory()
+ }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ mapView!!.onDestroy()
+ }
+
+ override fun onSaveInstanceState(outState: Bundle) {
+ super.onSaveInstanceState(outState)
+ mapView!!.onSaveInstanceState(outState)
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java
deleted file mode 100644
index ce700b1ab..000000000
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package com.mapbox.mapboxsdk.testapp.activity.maplayout;
-
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Button;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.fragment.app.DialogFragment;
-import androidx.fragment.app.FragmentManager;
-
-import com.mapbox.mapboxsdk.maps.MapView;
-import com.mapbox.mapboxsdk.maps.Style;
-import com.mapbox.mapboxsdk.testapp.R;
-
-/**
- * Test activity showcasing showing a Map inside of a DialogFragment.
- */
-public class MapInDialogActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_map_in_dialog);
-
- Button button = findViewById(R.id.button_open_dialog);
- button.setOnClickListener(view -> {
- FragmentManager fm = getSupportFragmentManager();
- MapDialogFragment editNameDialogFragment = MapDialogFragment.newInstance("Map Dialog");
- editNameDialogFragment.show(fm, "fragment_dialog_map");
- });
- }
-
- public static class MapDialogFragment extends DialogFragment {
-
- private MapView mapView;
-
- public MapDialogFragment() {
- }
-
- public static MapDialogFragment newInstance(String title) {
- MapDialogFragment frag = new MapDialogFragment();
- Bundle args = new Bundle();
- args.putString("title", title);
- frag.setArguments(args);
- return frag;
- }
-
- @Override
- public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- return inflater.inflate(R.layout.fragment_dialog_map, container);
- }
-
- @Override
- public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- mapView = view.findViewById(R.id.mapView);
- mapView.onCreate(savedInstanceState);
- mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(Style.getPredefinedStyle("Outdoor")));
- }
-
- @Override
- public void onStart() {
- super.onStart();
- mapView.onStart();
- }
-
- @Override
- public void onResume() {
- super.onResume();
- mapView.onResume();
- }
-
- @Override
- public void onPause() {
- super.onPause();
- mapView.onPause();
- }
-
- @Override
- public void onStop() {
- super.onStop();
- mapView.onStop();
- }
-
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- mapView.onDestroy();
- mapView = null;
- }
-
- @Override
- public void onLowMemory() {
- super.onLowMemory();
- if (mapView != null) {
- mapView.onLowMemory();
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- if (mapView != null) {
- mapView.onSaveInstanceState(outState);
- }
- }
- }
-}
\ No newline at end of file
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
new file mode 100644
index 000000000..5646684fc
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/maplayout/MapInDialogActivity.kt
@@ -0,0 +1,101 @@
+package com.mapbox.mapboxsdk.testapp.activity.maplayout
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.*
+import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.DialogFragment
+import com.mapbox.mapboxsdk.maps.*
+import com.mapbox.mapboxsdk.testapp.R
+import com.mapbox.mapboxsdk.testapp.activity.maplayout.MapInDialogActivity.MapDialogFragment
+
+/**
+ * Test activity showcasing showing a Map inside of a DialogFragment.
+ */
+class MapInDialogActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_map_in_dialog)
+ val button = findViewById