Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating to maplibre v10.0.2 #49

Merged
merged 2 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

Maplibre welcomes participation and contributions from everyone.

### v2.0.0 - unreleased - February 25, 2023

-Updated Maplibre version to v10.0.2.
-Incremented minSdk version from 15 to 21 to work same as maplibre implementation.
-Created custom classes for `GoogleLocationEngineImpl`, `Utils`, `LocationEngineProvider` which were removed from default implementation maplibre to provide working with GSM location.
-Corrected resource calls due to renamed res files in maplibre (from `mapbox_` to `maplibre_`).
-All changes are included in this pull request [49](https://github.com/maplibre/maplibre-navigation-android/pull/49)

### v2.0.0 - unreleased

- Update Maplibre to 9.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,22 @@ import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.res.AssetManager
import android.location.Location
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar
import com.mapbox.api.directions.v5.DirectionsCriteria
import com.mapbox.api.directions.v5.models.DirectionsResponse
import com.mapbox.api.directions.v5.models.DirectionsRoute
import com.mapbox.geojson.Point
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.annotations.MarkerOptions
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.location.LocationComponent
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions
import com.mapbox.mapboxsdk.location.engine.LocationEngineCallback
import com.mapbox.mapboxsdk.location.engine.LocationEngineRequest
import com.mapbox.mapboxsdk.location.engine.LocationEngineResult
import com.mapbox.mapboxsdk.location.modes.CameraMode
import com.mapbox.mapboxsdk.location.modes.RenderMode
import com.mapbox.mapboxsdk.maps.MapboxMap
Expand All @@ -41,16 +35,21 @@ import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeLis
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress
import com.mapbox.turf.TurfConstants
import com.mapbox.turf.TurfMeasurement
import okhttp3.Request
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import timber.log.Timber
import java.lang.Exception
import java.lang.ref.WeakReference

class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
MapboxMap.OnMapClickListener, ProgressChangeListener, NavigationEventListener,
MilestoneEventListener, OffRouteListener {
class MockNavigationActivity :
AppCompatActivity(),
OnMapReadyCallback,
MapboxMap.OnMapClickListener,
ProgressChangeListener,
NavigationEventListener,
MilestoneEventListener,
OffRouteListener {
private val BEGIN_ROUTE_MILESTONE = 1001
private lateinit var mapboxMap: MapboxMap

Expand All @@ -63,7 +62,7 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
private var waypoint: Point? = null
private var locationComponent: LocationComponent? = null

private lateinit var binding : ActivityMockNavigationBinding
private lateinit var binding: ActivityMockNavigationBinding

@SuppressLint("MissingPermission")
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -81,22 +80,24 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
customNotification.createNotificationChannel(this)
}
val options = MapboxNavigationOptions.builder()
.navigationNotification(customNotification)
.build()

navigation = MapboxNavigation(this, options)

navigation.addMilestone(RouteMilestone.Builder()
.setIdentifier(BEGIN_ROUTE_MILESTONE)
.setInstruction(BeginRouteInstruction())
.setTrigger(
Trigger.all(
Trigger.lt(TriggerProperty.STEP_INDEX, 3),
Trigger.gt(TriggerProperty.STEP_DISTANCE_TOTAL_METERS, 200),
Trigger.gte(TriggerProperty.STEP_DISTANCE_TRAVELED_METERS, 75)
)
).build())
customNotification.register(MyBroadcastReceiver(navigation), context)
.navigationNotification(customNotification)
.build()

navigation = MapboxNavigation(this, options)

navigation.addMilestone(
RouteMilestone.Builder()
.setIdentifier(BEGIN_ROUTE_MILESTONE)
.setInstruction(BeginRouteInstruction())
.setTrigger(
Trigger.all(
Trigger.lt(TriggerProperty.STEP_INDEX, 3),
Trigger.gt(TriggerProperty.STEP_DISTANCE_TOTAL_METERS, 200),
Trigger.gte(TriggerProperty.STEP_DISTANCE_TRAVELED_METERS, 75),
),
).build(),
)
customNotification.register(MyBroadcastReceiver(navigation), context)

binding.startRouteButton.setOnClickListener {
route?.let { route ->
Expand All @@ -114,8 +115,9 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
it.assign(route)
navigation.locationEngine = it
navigation.startNavigation(route)
if (::mapboxMap.isInitialized)
if (::mapboxMap.isInitialized) {
mapboxMap.removeOnMapClickListener(this)
}
}
}
}
Expand All @@ -125,10 +127,11 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
}

binding.clearPoints.setOnClickListener {
if (::mapboxMap.isInitialized)
if (::mapboxMap.isInitialized) {
mapboxMap.markers.forEach {
mapboxMap.removeMarker(it)
}
}
destination = null
waypoint = null
it.visibility = View.GONE
Expand All @@ -146,7 +149,11 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
navigationMapRoute = NavigationMapRoute(navigation, binding.mapView, mapboxMap)

mapboxMap.addOnMapClickListener(this)
Snackbar.make(findViewById(R.id.container), "Tap map to place waypoint", Snackbar.LENGTH_LONG).show()
Snackbar.make(
findViewById(R.id.container),
"Tap map to place waypoint",
Snackbar.LENGTH_LONG,
).show()

newOrigin()
}
Expand All @@ -158,7 +165,9 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,

locationComponent?.let {
// Activate with a built LocationComponentActivationOptions object
it.activateLocationComponent(LocationComponentActivationOptions.builder(this, style).build())
it.activateLocationComponent(
LocationComponentActivationOptions.builder(this, style).build(),
)

// Enable to make component visible
it.isLocationComponentEnabled = true
Expand All @@ -184,8 +193,9 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
}
}

if (addMarker)
if (addMarker) {
mapboxMap.addMarker(MarkerOptions().position(point))
}
binding.clearPoints.visibility = View.VISIBLE

binding.startRouteButton.visibility = View.VISIBLE
Expand Down Expand Up @@ -222,8 +232,11 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
}

navigationRouteBuilder.build().getRoute(object : Callback<DirectionsResponse> {
override fun onResponse(call: Call<DirectionsResponse>, response: Response<DirectionsResponse>) {
Timber.d("Url: %s", call.request().url().toString())
override fun onResponse(
call: Call<DirectionsResponse>,
response: Response<DirectionsResponse>,
) {
Timber.d("Url: %s", (call.request() as Request).url.toString())
response.body()?.let { response ->
if (response.routes().isNotEmpty()) {
val directionsRoute = response.routes().first()
Expand All @@ -240,19 +253,19 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
}

override fun onProgressChange(location: Location?, routeProgress: RouteProgress?) {

}

override fun onRunning(running: Boolean) {

}

override fun onMilestoneEvent(routeProgress: RouteProgress?, instruction: String?, milestone: Milestone?) {

override fun onMilestoneEvent(
routeProgress: RouteProgress?,
instruction: String?,
milestone: Milestone?,
) {
}

override fun userOffRoute(location: Location?) {

}

private class BeginRouteInstruction : Instruction() {
Expand Down Expand Up @@ -301,8 +314,8 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
binding.mapView.onSaveInstanceState(outState)
}


private class MyBroadcastReceiver internal constructor(navigation: MapboxNavigation) : BroadcastReceiver() {
private class MyBroadcastReceiver internal constructor(navigation: MapboxNavigation) :
BroadcastReceiver() {
private val weakNavigation: WeakReference<MapboxNavigation> = WeakReference(navigation)

override fun onReceive(context: Context, intent: Intent) {
Expand All @@ -314,7 +327,7 @@ class MockNavigationActivity : AppCompatActivity(), OnMapReadyCallback,
mapboxMap.let {
val latLng = LatLng(52.039176, 5.550339)
locationEngine.assignLastLocation(
Point.fromLngLat(latLng.longitude, latLng.latitude)
Point.fromLngLat(latLng.longitude, latLng.latitude),
)
it.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12.0))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Application;

import com.mapbox.mapboxsdk.BuildConfig;
import com.mapbox.mapboxsdk.Mapbox;

import timber.log.Timber;
Expand Down
30 changes: 15 additions & 15 deletions app/src/main/res/layout/activity_mock_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:mapbox_cameraTargetLat="52.039176"
app:mapbox_cameraTargetLng="5.550339"
app:mapbox_cameraZoom="12"
app:mapbox_enableTilePrefetch="true"
app:mapbox_enableZMediaOverlay="true"
app:mapbox_renderTextureMode="true"
app:mapbox_renderTextureTranslucentSurface="true"
app:mapbox_uiAttribution="false"
app:mapbox_uiCompass="false"
app:mapbox_uiDoubleTapGestures="true"
app:mapbox_uiLogo="false"
app:mapbox_uiRotateGestures="true"
app:mapbox_uiScrollGestures="true"
app:mapbox_uiTiltGestures="true"
app:mapbox_uiZoomGestures="true" />
app:maplibre_cameraTargetLat="52.039176"
app:maplibre_cameraTargetLng="5.550339"
app:maplibre_cameraZoom="12"
app:maplibre_enableTilePrefetch="true"
app:maplibre_enableZMediaOverlay="true"
app:maplibre_renderTextureMode="true"
app:maplibre_renderTextureTranslucentSurface="true"
app:maplibre_uiAttribution="false"
app:maplibre_uiCompass="false"
app:maplibre_uiDoubleTapGestures="true"
app:maplibre_uiLogo="false"
app:maplibre_uiRotateGestures="true"
app:maplibre_uiScrollGestures="true"
app:maplibre_uiTiltGestures="true"
app:maplibre_uiZoomGestures="true" />

<Button
android:id="@+id/startRouteButton"
Expand Down
6 changes: 3 additions & 3 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
ext {

androidVersions = [
minSdkVersion : 15,
minSdkVersion : 21,
targetSdkVersion : 33,
compileSdkVersion: 33,
buildToolsVersion: '33.0.1',
kotlinVersion : '1.7.20'
]

version = [
mapLibreVersion : '9.6.0',
mapLibreVersion : '10.0.2',
mapLibreService : '5.9.0',
mapLibreTurf : '5.9.0',
mapLibreAnnotations : '1.0.0',
Expand Down Expand Up @@ -37,7 +37,7 @@ ext {
lifecycle : '1.1.1',
lifecycleVersion : '2.2.0',
picasso : '2.71828',
gmsLocation : '16.0.0',
gmsLocation : '21.0.1',
testRulesVersion : '1.5.0'
]

Expand Down
Loading