diff --git a/README.md b/README.md index 39d9259ea..7a2ee547e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ With this SDK you can implement turn-by-turn navigation in your own Android app - No Telemetry -## Why have we forked +## Why have we forked¬ 1. Mapbox decided to put a closed-source component to their navigation SDK and introduced a non-open-source license. Maplibre wants an open-source solution. 2. Mapbox decided to put telemetry in their SDK. We couldn't turn this off without adjusting the source. diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e5f4b3c75..0d8a94c2a 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -28,7 +28,7 @@ android { defaultConfig { applicationId = "org.maplibre.navigation.android.example" compileSdk = 35 - minSdk = 21 + minSdk = 23 versionCode = 1 versionName = project.properties.get("versionName") as String? ?: "0.0.0" diff --git a/app/src/main/java/org/maplibre/navigation/android/example/GraphHopperNavigationActivity.kt b/app/src/main/java/org/maplibre/navigation/android/example/GraphHopperNavigationActivity.kt index 7d9d8f310..210ec6fd7 100644 --- a/app/src/main/java/org/maplibre/navigation/android/example/GraphHopperNavigationActivity.kt +++ b/app/src/main/java/org/maplibre/navigation/android/example/GraphHopperNavigationActivity.kt @@ -60,9 +60,9 @@ class GraphHopperNavigationActivity : binding = ActivityNavigationUiBinding.inflate(layoutInflater) setContentView(binding.root) - binding.mapView.apply { + binding.navigationView.apply { onCreate(savedInstanceState) - getMapAsync(this@GraphHopperNavigationActivity) +// getMapAsync(this@GraphHopperNavigationActivity) } binding.startRouteButton.setOnClickListener { @@ -86,18 +86,18 @@ class GraphHopperNavigationActivity : simulateRoute = checked } - binding.clearPoints.setOnClickListener { - if (::mapLibreMap.isInitialized) { - mapLibreMap.markers.forEach { - mapLibreMap.removeMarker(it) - } - } - destination = null - it.visibility = View.GONE - binding.startRouteLayout.visibility = View.GONE - - navigationMapRoute?.removeRoute() - } +// binding.clearPoints.setOnClickListener { +// if (::mapLibreMap.isInitialized) { +// mapLibreMap.markers.forEach { +// mapLibreMap.removeMarker(it) +// } +// } +// destination = null +// it.visibility = View.GONE +// binding.startRouteLayout.visibility = View.GONE +// +// navigationMapRoute?.removeRoute() +// } } override fun onMapReady(mapLibreMap: MapLibreMap) { @@ -106,7 +106,7 @@ class GraphHopperNavigationActivity : Style.Builder().fromUri(getString(R.string.map_style_light)) ) { style -> enableLocationComponent(style) - navigationMapRoute = NavigationMapRoute(binding.mapView, mapLibreMap) +// navigationMapRoute = NavigationMapRoute(binding.mapView, mapLibreMap) mapLibreMap.addOnMapClickListener(this) Snackbar.make( @@ -143,7 +143,7 @@ class GraphHopperNavigationActivity : destination = Point(point.longitude, point.latitude) mapLibreMap.addMarker(MarkerOptions().position(point)) - binding.clearPoints.visibility = View.VISIBLE +// binding.clearPoints.visibility = View.VISIBLE calculateRoute() return true } @@ -187,7 +187,7 @@ class GraphHopperNavigationActivity : // Create request object. Requires graphhopper_url to be set in developer-config.xml val request = Request.Builder() .header("User-Agent", "MapLibre Android Navigation SDK Demo App") - .url(getString(R.string.graphhopper_url)) +// .url(getString(R.string.graphhopper_url)) .post(requestBodyJson.toRequestBody("application/json; charset=utf-8".toMediaType())) .build() @@ -246,27 +246,27 @@ class GraphHopperNavigationActivity : override fun onResume() { super.onResume() - binding.mapView.onResume() +// binding.mapView.onResume() } override fun onPause() { super.onPause() - binding.mapView.onPause() +// binding.mapView.onPause() } override fun onStart() { super.onStart() - binding.mapView.onStart() +// binding.mapView.onStart() } override fun onStop() { super.onStop() - binding.mapView.onStop() +// binding.mapView.onStop() } override fun onLowMemory() { super.onLowMemory() - binding.mapView.onLowMemory() +// binding.mapView.onLowMemory() } override fun onDestroy() { @@ -274,11 +274,11 @@ class GraphHopperNavigationActivity : if (::mapLibreMap.isInitialized) { mapLibreMap.removeOnMapClickListener(this) } - binding.mapView.onDestroy() +// binding.mapView.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - binding.mapView.onSaveInstanceState(outState) +// binding.mapView.onSaveInstanceState(outState) } } diff --git a/app/src/main/java/org/maplibre/navigation/android/example/NavigationUIActivity.kt b/app/src/main/java/org/maplibre/navigation/android/example/NavigationUIActivity.kt index e0860b469..8e0526139 100644 --- a/app/src/main/java/org/maplibre/navigation/android/example/NavigationUIActivity.kt +++ b/app/src/main/java/org/maplibre/navigation/android/example/NavigationUIActivity.kt @@ -1,14 +1,9 @@ package org.maplibre.navigation.android.example -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.snackbar.Snackbar -import org.maplibre.navigation.core.models.DirectionsResponse -import org.maplibre.geojson.Point -import org.maplibre.android.annotations.MarkerOptions +import android.preference.PreferenceManager +import androidx.activity.ComponentActivity +import okhttp3.Request import org.maplibre.android.camera.CameraPosition import org.maplibre.android.geometry.LatLng import org.maplibre.android.location.LocationComponent @@ -16,28 +11,31 @@ import org.maplibre.android.location.LocationComponentActivationOptions import org.maplibre.android.location.modes.CameraMode import org.maplibre.android.location.modes.RenderMode import org.maplibre.android.maps.MapLibreMap -import org.maplibre.android.maps.OnMapReadyCallback import org.maplibre.android.maps.Style +import org.maplibre.android.plugins.annotation.SymbolOptions +import org.maplibre.android.style.layers.Property.ICON_ANCHOR_CENTER +import org.maplibre.geojson.Point +import org.maplibre.navigation.android.example.databinding.ActivityNavigationUiBinding +import org.maplibre.navigation.android.navigation.ui.v5.NavigationRequest import org.maplibre.navigation.android.navigation.ui.v5.NavigationLauncher -import org.maplibre.navigation.android.navigation.ui.v5.NavigationLauncherOptions +import org.maplibre.navigation.android.navigation.ui.v5.RoutingService +import org.maplibre.navigation.android.navigation.ui.v5.NavigationViewOptions +import org.maplibre.navigation.android.navigation.ui.v5.OnNavigationReadyCallback +import org.maplibre.navigation.android.navigation.ui.v5.listeners.NavigationListener +import org.maplibre.navigation.android.navigation.ui.v5.route.NavigationMapRoute import org.maplibre.navigation.android.navigation.ui.v5.route.NavigationRoute +import org.maplibre.navigation.core.models.DirectionsResponse import org.maplibre.navigation.core.models.DirectionsRoute -import org.maplibre.turf.TurfConstants -import org.maplibre.turf.TurfMeasurement -import okhttp3.Request -import org.maplibre.navigation.android.example.databinding.ActivityNavigationUiBinding -import org.maplibre.navigation.android.navigation.ui.v5.route.NavigationMapRoute import org.maplibre.navigation.core.models.UnitType +import org.maplibre.navigation.core.navigation.NavigationConstants import retrofit2.Call import retrofit2.Callback import retrofit2.Response import timber.log.Timber +import java.util.Locale -class NavigationUIActivity : - AppCompatActivity(), - OnMapReadyCallback, - MapLibreMap.OnMapClickListener { - private lateinit var mapLibreMap: MapLibreMap +class NavigationUIActivity : ComponentActivity(), MapLibreMap.OnMapClickListener, + OnNavigationReadyCallback, NavigationListener { // Navigation related variables private var route: DirectionsRoute? = null @@ -49,8 +47,10 @@ class NavigationUIActivity : private lateinit var binding: ActivityNavigationUiBinding private var simulateRoute = false + var mapLibreMap: MapLibreMap? = null + + private var isStarted = false - @SuppressLint("MissingPermission") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -60,71 +60,117 @@ class NavigationUIActivity : binding = ActivityNavigationUiBinding.inflate(layoutInflater) setContentView(binding.root) - binding.mapView.apply { - onCreate(savedInstanceState) - getMapAsync(this@NavigationUIActivity) - } - binding.startRouteButton.setOnClickListener { - route?.let { route -> - val userLocation = mapLibreMap.locationComponent.lastKnownLocation ?: return@let - - val options = NavigationLauncherOptions.builder() - .directionsRoute(route) - .shouldSimulateRoute(simulateRoute) - .initialMapCameraPosition( + binding.navigationView.apply { + onCreate(savedInstanceState, mapStyleUri = "https://api.maptiler.com/maps/streets-v2/style.json?key=ZkZSWT2Q0ta4f3S1VyrZ") + initialize( + simulateRoute, + onMapReadyCallback = { + this@NavigationUIActivity.mapLibreMap = it + val initialMapCameraPosition = CameraPosition.Builder() - .target(LatLng(userLocation.latitude, userLocation.longitude)).build() - ) - .lightThemeResId(R.style.TestNavigationViewLight) - .darkThemeResId(R.style.TestNavigationViewDark) - .build() - NavigationLauncher.startNavigation(this@NavigationUIActivity, options) - } + .target(LatLng(43.230633, 76.933810)) + .zoom(16.0) + .build() + it.cameraPosition = initialMapCameraPosition + it.setMaxZoomPreference(18.0) + it.setMinZoomPreference(5.0) + getDrawable(R.drawable.ic_car_top)?.let { + mapLibreMap?.style?.addImage("DRIVER_MARKER_ICON_ID", + it + ) + } + val symbolOptions = SymbolOptions() + .withLatLng(LatLng(43.230361,76.930137)) + .withIconImage("DRIVER_MARKER_ICON_ID") + .withIconAnchor(ICON_ANCHOR_CENTER) + + binding.navigationView.addSymbol(symbolOptions) + } + ) + } - binding.simulateRouteSwitch.setOnCheckedChangeListener { _, checked -> - simulateRoute = checked + binding.locate.setOnClickListener { +// val initialMapCameraPosition = +// CameraPosition.Builder() +// .target(LatLng(43.230633, 76.933810)) +// .zoom(16.0) +// .build() +// mapLibreMap?.animateCamera(CameraUpdateFactory.newCameraPosition(initialMapCameraPosition)) + mapLibreMap?.locationComponent?.setCameraMode( + CameraMode.TRACKING_GPS, + 750, + 16.0, + null, + null, + null + ) + + mapLibreMap?.locationComponent?.renderMode = RenderMode.GPS } +// binding.mapView.apply { +// onCreate(savedInstanceState) +// getMapAsync(this@NavigationUIActivity) +// } - binding.clearPoints.setOnClickListener { - if (::mapLibreMap.isInitialized) { - mapLibreMap.markers.forEach { - mapLibreMap.removeMarker(it) - } - } - destination = null - waypoint = null - it.visibility = View.GONE - binding.startRouteLayout.visibility = View.GONE + val points = mutableListOf() +// points.add(Pair(76.928316, 43.236109)) + points.add(Point.fromLngLat(76.933810, 43.230633)) + points.add(Point.fromLngLat(76.920187, 43.236783)) +// points.add(Pair(76.930137, 43.230361)) + binding.simulateRouteSwitch.setOnCheckedChangeListener { _, isChecked -> +// mapLibreMap?.locationComponent?.cameraMode = CameraMode.TRACKING + simulateRoute = isChecked + if (simulateRoute) { + + } else { - navigationMapRoute?.removeRoute() + } + mapLibreMap?.locationComponent?.setCameraMode(CameraMode.TRACKING_GPS, 100, 16.0, null, null, null) } - } + binding.navigationView.showInstructionView() + binding.startRouteButton.setOnClickListener { + if (isStarted) { + binding.navigationView.stopNavigation() + binding.navigationView.retrieveNavigationMapLibreMap()?.removeRoute() + isStarted = false + } else { + isStarted = true + binding.navigationView.calculateRouteAndStartNavigation( + NavigationRequest( + origin = Point.fromLngLat(76.93312659859657, 43.2283288597314), + stops = points, + destination = Point.fromLngLat(76.92803341895342,43.23938818876529,), + routingService = RoutingService.Mapbox(getString(R.string.base_url), getString(R.string.mapbox_access_token)), + language = Locale.getDefault() + ) + ) + binding.navigationView.enableNavigatorSound(false) - override fun onMapReady(mapLibreMap: MapLibreMap) { - this.mapLibreMap = mapLibreMap - mapLibreMap.setStyle( - Style.Builder().fromUri(getString(R.string.map_style_light)) - ) { style -> - enableLocationComponent(style) - navigationMapRoute = NavigationMapRoute(binding.mapView, mapLibreMap) - - mapLibreMap.addOnMapClickListener(this) - - Snackbar.make( - findViewById(R.id.container), - "Tap map to place waypoint", - Snackbar.LENGTH_LONG, - ).show() + } } + +// binding.clearPoints.setOnClickListener { +// if (::mapboxMap.isInitialized) { +// mapboxMap.markers.forEach { +// mapboxMap.removeMarker(it) +// } +// } +// destination = null +// waypoint = null +// it.visibility = View.GONE +// binding.startRouteLayout.visibility = View.GONE +// +// navigationMapRoute?.removeRoute() +// } } @SuppressWarnings("MissingPermission") private fun enableLocationComponent(style: Style) { // Get an instance of the component - locationComponent = mapLibreMap.locationComponent +// locationComponent = mapLibreMap.locationComponent locationComponent?.let { // Activate with a built LocationComponentActivationOptions object @@ -144,46 +190,46 @@ class NavigationUIActivity : } override fun onMapClick(point: LatLng): Boolean { - var addMarker = true - when { - destination == null -> destination = Point.fromLngLat(point.longitude, point.latitude) - waypoint == null -> waypoint = Point.fromLngLat(point.longitude, point.latitude) - else -> { - Toast.makeText(this, "Only 2 waypoints supported", Toast.LENGTH_LONG).show() - addMarker = false - } - } - - if (addMarker) { - mapLibreMap.addMarker(MarkerOptions().position(point)) - binding.clearPoints.visibility = View.VISIBLE - } - calculateRoute() +// var addMarker = true +// when { +// destination == null -> destination = Point.fromLngLat(point.longitude, point.latitude) +// waypoint == null -> waypoint = Point.fromLngLat(point.longitude, point.latitude) +// else -> { +// Toast.makeText(this, "Only 2 waypoints supported", Toast.LENGTH_LONG).show() +// addMarker = false +// } +// } +// +// if (addMarker) { +// mapboxMap.addMarker(MarkerOptions().position(point)) +// binding.clearPoints.visibility = View.VISIBLE +// } +// calculateRoute() return true } private fun calculateRoute() { - binding.startRouteLayout.visibility = View.GONE - val userLocation = mapLibreMap.locationComponent.lastKnownLocation +// binding.startRouteLayout.visibility = View.GONE +// val userLocation = mapLibreMap.locationComponent.lastKnownLocation val destination = destination - if (userLocation == null) { - Timber.d("calculateRoute: User location is null, therefore, origin can't be set.") - return - } +// if (userLocation == null) { +// Timber.d("calculateRoute: User location is null, therefore, origin can't be set.") +// return +// } if (destination == null) { return } - val origin = Point.fromLngLat(userLocation.longitude, userLocation.latitude) - if (TurfMeasurement.distance(origin, destination, TurfConstants.UNIT_METERS) < 50) { - binding.startRouteLayout.visibility = View.GONE - return - } +// val origin = Point.fromLngLat(userLocation.longitude, userLocation.latitude) +// if (TurfMeasurement.distance(origin, destination, TurfConstants.UNIT_METERS) < 50) { +// binding.startRouteLayout.visibility = View.GONE +// return +// } val navigationRouteBuilder = NavigationRoute.builder(this).apply { this.accessToken(getString(R.string.mapbox_access_token)) - this.origin(origin) +// this.origin(origin) this.destination(destination) this.voiceUnits(UnitType.METRIC) this.alternatives(true) @@ -193,6 +239,20 @@ class NavigationUIActivity : this.baseUrl(getString(R.string.base_url)) } + + navigationRouteBuilder.addWaypoint( + Point.fromLngLat(76.930137, 43.230361) + ) + + navigationRouteBuilder.addWaypoint( + Point.fromLngLat(76.928316, 43.236109) + ) + + navigationRouteBuilder.addWaypoint( + Point.fromLngLat(76.920187, 43.236783) + ) + + navigationRouteBuilder.build().getRoute(object : Callback { override fun onResponse( call: Call, @@ -201,10 +261,13 @@ class NavigationUIActivity : Timber.d("Url: %s", (call.request() as Request).url.toString()) response.body()?.let { response -> if (response.routes.isNotEmpty()) { - val maplibreResponse = DirectionsResponse.fromJson(response.toJson()); + val maplibreResponse = + DirectionsResponse.fromJson( + response.toJson() + ); this@NavigationUIActivity.route = maplibreResponse.routes.first() navigationMapRoute?.addRoutes(maplibreResponse.routes) - binding.startRouteLayout.visibility = View.VISIBLE +// binding.startRouteLayout.visibility = View.VISIBLE } } @@ -218,39 +281,81 @@ class NavigationUIActivity : override fun onResume() { super.onResume() - binding.mapView.onResume() + binding.navigationView.onResume() } override fun onPause() { super.onPause() - binding.mapView.onPause() + binding.navigationView.onPause() } override fun onStart() { super.onStart() - binding.mapView.onStart() + binding.navigationView.onStart() } override fun onStop() { super.onStop() - binding.mapView.onStop() + binding.navigationView.onStop() } override fun onLowMemory() { super.onLowMemory() - binding.mapView.onLowMemory() + binding.navigationView.onLowMemory() } override fun onDestroy() { super.onDestroy() - if (::mapLibreMap.isInitialized) { - mapLibreMap.removeOnMapClickListener(this) - } - binding.mapView.onDestroy() +// if (::mapboxMap.isInitialized) { +// mapboxMap.removeOnMapClickListener(this) +// } + binding.navigationView.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - binding.mapView.onSaveInstanceState(outState) + binding.navigationView.onSaveInstanceState(outState) + } + + override fun onNavigationReady(isRunning: Boolean) { +// val options = NavigationViewOptions.builder() +// options.navigationListener(this) +// extractRoute(options) +// extractConfiguration(options) +// options.navigationOptions(MapLibreNavigationOptions.Builder().build()) +// binding.navigationView.startNavigation(options.build()) + } + + override fun onCancelNavigation() { + finishNavigation() + } + + override fun onNavigationFinished() { + finishNavigation() + } + + override fun onNavigationRunning() { + // Intentionally empty + } + + private fun extractRoute(options: NavigationViewOptions.Builder) { + val route = NavigationLauncher.extractRoute(this) + options.directionsRoute(route) + } + + private fun extractConfiguration(options: NavigationViewOptions.Builder) { + val preferences = PreferenceManager.getDefaultSharedPreferences(this) + options.shouldSimulateRoute( + preferences.getBoolean( + NavigationConstants.NAVIGATION_VIEW_SIMULATE_ROUTE, + false + ) + ) + } + + private fun finishNavigation() { + NavigationLauncher.cleanUpPreferences(this) +// binding.navigationView.stopNavigation() + finish() } } diff --git a/app/src/main/java/org/maplibre/navigation/android/example/NavigationWithCustomForegroundNotificationActivity.kt b/app/src/main/java/org/maplibre/navigation/android/example/NavigationWithCustomForegroundNotificationActivity.kt index 03146e514..c24c374da 100644 --- a/app/src/main/java/org/maplibre/navigation/android/example/NavigationWithCustomForegroundNotificationActivity.kt +++ b/app/src/main/java/org/maplibre/navigation/android/example/NavigationWithCustomForegroundNotificationActivity.kt @@ -145,6 +145,9 @@ class NavigationWithCustomForegroundNotificationActivity : AppCompatActivity(), this.destination(Point.fromLngLat(9.756259, 52.342620)) this.voiceUnits(UnitType.METRIC) this.alternatives(true) + // If you are using this with the GraphHopper Directions API, you need to uncomment user and profile here. + this.user("gh") + this.profile("car") this.baseUrl(getString(R.string.base_url)) } diff --git a/app/src/main/java/org/maplibre/navigation/android/example/NavigationWithForegroundNotificationActivity.kt b/app/src/main/java/org/maplibre/navigation/android/example/NavigationWithForegroundNotificationActivity.kt index 4c7538922..f16b79b58 100644 --- a/app/src/main/java/org/maplibre/navigation/android/example/NavigationWithForegroundNotificationActivity.kt +++ b/app/src/main/java/org/maplibre/navigation/android/example/NavigationWithForegroundNotificationActivity.kt @@ -140,11 +140,14 @@ class NavigationWithForegroundNotificationActivity : AppCompatActivity(), OnMapR private fun calculateRouteAndStartNavigation() { val navigationRouteBuilder = NavigationRoute.builder(this).apply { this.accessToken(getString(R.string.mapbox_access_token)) - this.origin(Point.fromLngLat(9.7536318, 52.3717979)) - this.addWaypoint(Point.fromLngLat(9.741052, 52.360496)) - this.destination(Point.fromLngLat(9.756259, 52.342620)) + this.origin(Point.fromLngLat( 10.246249, 50.055795)) + this.destination(Point.fromLngLat( 10.245291,50.056129)) + this.addWaypoint(Point.fromLngLat(10.243814,50.055662)) this.voiceUnits(UnitType.METRIC) this.alternatives(true) + // If you are using this with the GraphHopper Directions API, you need to uncomment user and profile here. + this.user("gh") + this.profile("car") this.baseUrl(getString(R.string.base_url)) } diff --git a/app/src/main/java/org/maplibre/navigation/android/example/ValhallaNavigationActivity.kt b/app/src/main/java/org/maplibre/navigation/android/example/ValhallaNavigationActivity.kt index addde514c..41289e2f8 100644 --- a/app/src/main/java/org/maplibre/navigation/android/example/ValhallaNavigationActivity.kt +++ b/app/src/main/java/org/maplibre/navigation/android/example/ValhallaNavigationActivity.kt @@ -56,50 +56,47 @@ class ValhallaNavigationActivity : override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - if (BuildConfig.DEBUG) { - Timber.plant(Timber.DebugTree()) - } - - binding = ActivityNavigationUiBinding.inflate(layoutInflater) - setContentView(binding.root) - binding.mapView.apply { - onCreate(savedInstanceState) - getMapAsync(this@ValhallaNavigationActivity) - } - - binding.startRouteButton.setOnClickListener { - route?.let { route -> - val userLocation = mapLibreMap.locationComponent.lastKnownLocation ?: return@let - val options = NavigationLauncherOptions.builder() - .directionsRoute(route) - .shouldSimulateRoute(simulateRoute) - .initialMapCameraPosition( - CameraPosition.Builder() - .target(LatLng(userLocation.latitude, userLocation.longitude)).build() - ) - .lightThemeResId(R.style.TestNavigationViewLight) - .darkThemeResId(R.style.TestNavigationViewDark) - .build() - NavigationLauncher.startNavigation(this@ValhallaNavigationActivity, options) - } - } - - binding.simulateRouteSwitch.setOnCheckedChangeListener { _, checked -> - simulateRoute = checked - } - - binding.clearPoints.setOnClickListener { - if (::mapLibreMap.isInitialized) { - mapLibreMap.markers.forEach { - mapLibreMap.removeMarker(it) - } - } - destination = null - it.visibility = View.GONE - binding.startRouteLayout.visibility = View.GONE - - navigationMapRoute?.removeRoute() - } +// if (BuildConfig.DEBUG) { +// Timber.plant(Timber.DebugTree()) +// } +// +// binding = ActivityNavigationUiBinding.inflate(layoutInflater) +// setContentView(binding.root) +// binding.mapView.apply { +// onCreate(savedInstanceState) +// getMapAsync(this@ValhallaNavigationActivity) +// } +// +// binding.startRouteButton.setOnClickListener { +// route?.let { route -> +// val userLocation = mapboxMap.locationComponent.lastKnownLocation ?: return@let +// val options = NavigationLauncherOptions.builder() +// .directionsRoute(route) +// .shouldSimulateRoute(simulateRoute) +// .initialMapCameraPosition(CameraPosition.Builder().target(LatLng(userLocation.latitude, userLocation.longitude)).build()) +// .lightThemeResId(R.style.TestNavigationViewLight) +// .darkThemeResId(R.style.TestNavigationViewDark) +// .build() +// NavigationLauncher.startNavigation(this@ValhallaNavigationActivity, options) +// } +// } +// +// binding.simulateRouteSwitch.setOnCheckedChangeListener { _, checked -> +// simulateRoute = checked +// } +// +// binding.clearPoints.setOnClickListener { +// if (::mapboxMap.isInitialized) { +// mapboxMap.markers.forEach { +// mapboxMap.removeMarker(it) +// } +// } +// destination = null +// it.visibility = View.GONE +// binding.startRouteLayout.visibility = View.GONE +// +// navigationMapRoute?.removeRoute() +// } } override fun onMapReady(mapLibreMap: MapLibreMap) { @@ -108,15 +105,19 @@ class ValhallaNavigationActivity : Style.Builder().fromUri(getString(R.string.map_style_light)) ) { style -> enableLocationComponent(style) - navigationMapRoute = NavigationMapRoute(binding.mapView, mapLibreMap) - mapLibreMap.addOnMapClickListener(this) - - Snackbar.make( - findViewById(R.id.container), - "Tap map to place destination", - Snackbar.LENGTH_LONG, - ).show() } +// +// navigationMapRoute = NavigationMapRoute( +// binding.mapView, +// mapboxMap +// ) + + mapLibreMap.addOnMapClickListener(this) + Snackbar.make( + findViewById(R.id.container), + "Tap map to place destination", + Snackbar.LENGTH_LONG, + ).show() } @SuppressWarnings("MissingPermission") @@ -145,7 +146,7 @@ class ValhallaNavigationActivity : destination = Point.fromLngLat(point.longitude, point.latitude) mapLibreMap.addMarker(MarkerOptions().position(point)) - binding.clearPoints.visibility = View.VISIBLE +// binding.clearPoints.visibility = View.VISIBLE calculateRoute() return true } @@ -278,27 +279,27 @@ class ValhallaNavigationActivity : override fun onResume() { super.onResume() - binding.mapView.onResume() +// binding.mapView.onResume() } override fun onPause() { super.onPause() - binding.mapView.onPause() +// binding.mapView.onPause() } override fun onStart() { super.onStart() - binding.mapView.onStart() +// binding.mapView.onStart() } override fun onStop() { super.onStop() - binding.mapView.onStop() +// binding.mapView.onStop() } override fun onLowMemory() { super.onLowMemory() - binding.mapView.onLowMemory() +// binding.mapView.onLowMemory() } override fun onDestroy() { @@ -306,11 +307,11 @@ class ValhallaNavigationActivity : if (::mapLibreMap.isInitialized) { mapLibreMap.removeOnMapClickListener(this) } - binding.mapView.onDestroy() +// binding.mapView.onDestroy() } override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - binding.mapView.onSaveInstanceState(outState) +// binding.mapView.onSaveInstanceState(outState) } } diff --git a/app/src/main/res/layout/activity_navigation_ui.xml b/app/src/main/res/layout/activity_navigation_ui.xml index 220bc6706..3b6643380 100644 --- a/app/src/main/res/layout/activity_navigation_ui.xml +++ b/app/src/main/res/layout/activity_navigation_ui.xml @@ -6,32 +6,28 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + app:layout_constraintTop_toTopOf="parent"/> + @@ -53,8 +49,8 @@ android:id="@+id/simulateRouteSwitch" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/simulate_route" - android:textColor="@color/white" + android:text="simulate_route" + android:textColor="@color/maplibre_navigation_route_upcoming_maneuver_arrow_color" app:switchPadding="4dp" />