feat!: Mapbox update 2.20 -> 3.2 (WIP)
This commit is contained in:
parent
cd85180f99
commit
9a2b0dd187
6 changed files with 53 additions and 51 deletions
|
@ -7,6 +7,7 @@ plugins {
|
||||||
android {
|
android {
|
||||||
namespace 'eu.ztsh.garmin'
|
namespace 'eu.ztsh.garmin'
|
||||||
compileSdk 34
|
compileSdk 34
|
||||||
|
ndkVersion "23.2.8568313"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "eu.ztsh.garmin"
|
applicationId "eu.ztsh.garmin"
|
||||||
|
@ -36,18 +37,23 @@ android {
|
||||||
viewBinding true
|
viewBinding true
|
||||||
buildConfig = true
|
buildConfig = true
|
||||||
}
|
}
|
||||||
buildToolsVersion '35.0.0'
|
}
|
||||||
|
ext {
|
||||||
|
mapboxVersion = '3.2.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation "com.mapbox.navigationcore:navigation:$mapboxVersion"
|
||||||
implementation "com.mapbox.navigation:ui-dropin:2.20.0"
|
implementation "com.mapbox.navigationcore:ui-maps:$mapboxVersion"
|
||||||
implementation 'androidx.core:core-ktx:1.7.0'
|
implementation "com.mapbox.navigationcore:voice:$mapboxVersion"
|
||||||
implementation 'androidx.appcompat:appcompat:1.4.1'
|
implementation "com.mapbox.navigationcore:tripdata:$mapboxVersion"
|
||||||
implementation 'com.google.android.material:material:1.5.0'
|
implementation "com.mapbox.navigationcore:ui-components:$mapboxVersion"
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
|
implementation 'androidx.core:core-ktx:1.13.1'
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.7.0'
|
||||||
|
implementation 'com.google.android.material:material:1.12.0'
|
||||||
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.bluetooth.BluetoothAdapter
|
||||||
import android.bluetooth.BluetoothDevice
|
import android.bluetooth.BluetoothDevice
|
||||||
import android.bluetooth.BluetoothSocket
|
import android.bluetooth.BluetoothSocket
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.mapbox.navigation.ui.maneuver.model.Maneuver
|
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.SynchronousQueue
|
import java.util.concurrent.SynchronousQueue
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.annotation.SuppressLint
|
||||||
import android.bluetooth.BluetoothAdapter
|
import android.bluetooth.BluetoothAdapter
|
||||||
import android.bluetooth.BluetoothDevice
|
import android.bluetooth.BluetoothDevice
|
||||||
import android.bluetooth.BluetoothManager
|
import android.bluetooth.BluetoothManager
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
@ -18,14 +17,10 @@ import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver
|
import androidx.lifecycle.DefaultLifecycleObserver
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import com.mapbox.navigation.base.formatter.DistanceFormatterOptions
|
|
||||||
import com.mapbox.navigation.base.options.NavigationOptions
|
import com.mapbox.navigation.base.options.NavigationOptions
|
||||||
import com.mapbox.navigation.base.trip.model.RouteProgress
|
|
||||||
import com.mapbox.navigation.core.formatter.MapboxDistanceFormatter
|
|
||||||
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
|
import com.mapbox.navigation.core.lifecycle.MapboxNavigationApp
|
||||||
import com.mapbox.navigation.core.trip.session.RouteProgressObserver
|
|
||||||
import com.mapbox.navigation.ui.maneuver.api.MapboxManeuverApi
|
|
||||||
import eu.ztsh.garmin.databinding.ActivityMainBinding
|
import eu.ztsh.garmin.databinding.ActivityMainBinding
|
||||||
|
import eu.ztsh.garmin.mapbox.NavigationObserver
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
@ -33,18 +28,18 @@ class MainActivity : AppCompatActivity() {
|
||||||
lateinit var garmin: Garmin
|
lateinit var garmin: Garmin
|
||||||
|
|
||||||
private lateinit var binding: ActivityMainBinding
|
private lateinit var binding: ActivityMainBinding
|
||||||
private val mapboxObserver = MapboxObserver()
|
private val navigationObserver = NavigationObserver()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
lifecycle.addObserver(object : DefaultLifecycleObserver {
|
lifecycle.addObserver(object : DefaultLifecycleObserver {
|
||||||
override fun onResume(owner: LifecycleOwner) {
|
override fun onResume(owner: LifecycleOwner) {
|
||||||
MapboxNavigationApp.attach(owner)
|
MapboxNavigationApp.attach(owner)
|
||||||
MapboxNavigationApp.registerObserver(mapboxObserver)
|
MapboxNavigationApp.registerObserver(navigationObserver)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause(owner: LifecycleOwner) {
|
override fun onPause(owner: LifecycleOwner) {
|
||||||
MapboxNavigationApp.detach(owner)
|
MapboxNavigationApp.detach(owner)
|
||||||
MapboxNavigationApp.unregisterObserver(mapboxObserver)
|
MapboxNavigationApp.unregisterObserver(navigationObserver)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -56,7 +51,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
if (!MapboxNavigationApp.isSetup()) {
|
if (!MapboxNavigationApp.isSetup()) {
|
||||||
MapboxNavigationApp.setup {
|
MapboxNavigationApp.setup {
|
||||||
NavigationOptions.Builder(applicationContext)
|
NavigationOptions.Builder(applicationContext)
|
||||||
.accessToken(BuildConfig.MAPBOX_DOWNLOADS_TOKEN)
|
// .accessToken(BuildConfig.MAPBOX_DOWNLOADS_TOKEN)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,37 +61,37 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
MapboxNavigationApp.current()?.registerRouteProgressObserver(routeProgressObserver)
|
// MapboxNavigationApp.current()?.registerRouteProgressObserver(routeProgressObserver)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
MapboxNavigationApp.current()?.unregisterRouteProgressObserver(routeProgressObserver)
|
// MapboxNavigationApp.current()?.unregisterRouteProgressObserver(routeProgressObserver)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
MapboxNavigationApp.current()?.stopTripSession()
|
MapboxNavigationApp.current()?.stopTripSession()
|
||||||
maneuverApi.cancel()
|
// maneuverApi.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define distance formatter options
|
// // Define distance formatter options
|
||||||
private val distanceFormatter: DistanceFormatterOptions by lazy {
|
// private val distanceFormatter: DistanceFormatterOptions by lazy {
|
||||||
DistanceFormatterOptions.Builder(this).build()
|
// DistanceFormatterOptions.Builder(this).build()
|
||||||
}
|
// }
|
||||||
// Create an instance of the Maneuver API
|
// // Create an instance of the Maneuver API
|
||||||
private val maneuverApi: MapboxManeuverApi by lazy {
|
// private val maneuverApi: MapboxManeuverApi by lazy {
|
||||||
MapboxManeuverApi(MapboxDistanceFormatter(distanceFormatter))
|
// MapboxManeuverApi(MapboxDistanceFormatter(distanceFormatter))
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private val routeProgressObserver =
|
// private val routeProgressObserver =
|
||||||
RouteProgressObserver { routeProgress ->
|
// RouteProgressObserver { routeProgress ->
|
||||||
maneuverApi.getManeuvers(routeProgress).value?.apply {
|
// maneuverApi.getManeuvers(routeProgress).value?.apply {
|
||||||
garmin.process(
|
// garmin.process(
|
||||||
this[0]
|
// this[0]
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private fun bluetoothInit() {
|
private fun bluetoothInit() {
|
||||||
val bluetoothManager: BluetoothManager = getSystemService(BluetoothManager::class.java)
|
val bluetoothManager: BluetoothManager = getSystemService(BluetoothManager::class.java)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package eu.ztsh.garmin
|
package eu.ztsh.garmin
|
||||||
|
|
||||||
import com.mapbox.navigation.ui.maneuver.model.Maneuver
|
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
||||||
|
|
||||||
class ManeuverMapper {
|
class ManeuverMapper {
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package eu.ztsh.garmin
|
package eu.ztsh.garmin.mapbox
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.mapbox.navigation.core.MapboxNavigation
|
import com.mapbox.navigation.core.MapboxNavigation
|
||||||
import com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver
|
import com.mapbox.navigation.core.lifecycle.MapboxNavigationObserver
|
||||||
|
|
||||||
class MapboxObserver : MapboxNavigationObserver {
|
class NavigationObserver : MapboxNavigationObserver {
|
||||||
|
|
||||||
override fun onAttached(mapboxNavigation: MapboxNavigation) {
|
override fun onAttached(mapboxNavigation: MapboxNavigation) {
|
||||||
Log.d(TAG, "Attached")
|
Log.d(TAG, "Attached")
|
|
@ -1,9 +1,10 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<com.mapbox.navigation.dropin.NavigationView xmlns:android="http://schemas.android.com/apk/res/android"
|
<com.mapbox.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/navigationView"
|
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/mapView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:accessToken="@string/mapbox_access_token"
|
mapbox:mapbox_locationComponentEnabled = "true"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
mapbox:mapbox_locationComponentPuckBearing = "heading"
|
||||||
|
tools:context=".MainActivity" />
|
||||||
</com.mapbox.navigation.dropin.NavigationView>
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue