Skip to content

Commit

Permalink
Adopt generated geofence code in common (#2852)
Browse files Browse the repository at this point in the history
  • Loading branch information
flasher297 authored Nov 22, 2024
1 parent 1b26cc0 commit 3ed8ff4
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Mapbox welcomes participation and contributions from everyone.

# main
## Breaking changes ⚠️
* Expose Geofencing with `com.mapbox.annotation.MapboxExperimental` annotation.

## Features ✨ and improvements 🏁
* Introduce experimental `FillExtrusionLayer.fillExtrusionBaseAlignment` and `FillExtrusionLayer.fillExtrusionHeightAlignment` APIs to control the behavior of fill extrusion base over terrain and the behavior of fill extrusion height over terrain respectively.
* Introduce experimental `FillLayer.fillZOffset` and `FillLayer.fillZOffsetTransition` APIs to specify a uniform elevation in meters and define the transition of `fillZOffset` respectively.
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/com/mapbox/maps/testapp/MapboxApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package com.mapbox.maps.testapp
import android.os.StrictMode
import androidx.multidex.MultiDexApplication
import com.mapbox.android.core.permissions.PermissionsManager
import com.mapbox.common.experimental.geofencing.GeofencingError
import com.mapbox.common.experimental.geofencing.GeofencingEvent
import com.mapbox.common.experimental.geofencing.GeofencingFactory
import com.mapbox.common.experimental.geofencing.GeofencingObserver
import com.mapbox.annotation.MapboxExperimental
import com.mapbox.common.geofencing.GeofencingError
import com.mapbox.common.geofencing.GeofencingEvent
import com.mapbox.common.geofencing.GeofencingFactory
import com.mapbox.common.geofencing.GeofencingObserver
import com.mapbox.maps.logD
import com.mapbox.maps.logW
import com.mapbox.maps.testapp.examples.geofence.ExtendedGeofencingActivity
Expand All @@ -16,6 +17,7 @@ import com.mapbox.maps.testapp.examples.geofence.ExtendedGeofencingActivity
**/
class MapboxApplication : MultiDexApplication() {

@MapboxExperimental
private val geofencingObserver: GeofencingObserver = object : GeofencingObserver {

override fun onEntry(event: GeofencingEvent) {
Expand Down Expand Up @@ -81,6 +83,7 @@ class MapboxApplication : MultiDexApplication() {
)
}

@MapboxExperimental
fun registerGeofencingObserver() {
if (PermissionsManager.areLocationPermissionsGranted(this) && !isObserverAdded) {
val geofencing = GeofencingFactory.getOrCreate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import androidx.lifecycle.lifecycleScope
import com.mapbox.api.isochrone.IsochroneCriteria
import com.mapbox.api.isochrone.MapboxIsochrone
import com.mapbox.bindgen.Expected
import com.mapbox.common.experimental.geofencing.GeofencingError
import com.mapbox.common.experimental.geofencing.GeofencingEvent
import com.mapbox.common.experimental.geofencing.GeofencingFactory
import com.mapbox.common.experimental.geofencing.GeofencingObserver
import com.mapbox.common.experimental.geofencing.GeofencingOptions
import com.mapbox.common.experimental.geofencing.GeofencingPropertiesKeys
import com.mapbox.common.geofencing.GeofencingError
import com.mapbox.common.geofencing.GeofencingEvent
import com.mapbox.common.geofencing.GeofencingFactory
import com.mapbox.common.geofencing.GeofencingObserver
import com.mapbox.common.geofencing.GeofencingOptions
import com.mapbox.common.geofencing.GeofencingPropertiesKeys
import com.mapbox.geojson.Feature
import com.mapbox.geojson.FeatureCollection
import com.mapbox.geojson.GeometryCollection
Expand Down Expand Up @@ -73,6 +73,8 @@ import java.util.Date
* even when GeofenceActivity or the whole app is closed.
* [MapboxApplication.ENABLE_BACKGROUND_GEOFENCING] flag turns ON/OFF showcase of background behavior of the geofence engine.
*/

@com.mapbox.annotation.MapboxExperimental
class ExtendedGeofencingActivity : AppCompatActivity() {

private var requestNotificationPermissionLauncher: ActivityResultLauncher<String> =
Expand Down Expand Up @@ -231,7 +233,10 @@ class ExtendedGeofencingActivity : AppCompatActivity() {
locationPermissionHelper.checkBackgroundPermission {
// Postpone access to Geofence engine until we get location permissions
geofencing.configure(
GeofencingOptions(CUSTOM_GEOFENCE_RADIUS, 300_000),
GeofencingOptions.Builder().apply {
defaultRadius = CUSTOM_GEOFENCE_RADIUS
maximumMonitoredFeatures = 300_000
}.build(),
logGeofencingError("configure")
)
startGeofencing()
Expand Down Expand Up @@ -422,10 +427,11 @@ class ExtendedGeofencingActivity : AppCompatActivity() {
featureId?.let {
geofencing.getFeature(featureId) {
it.value?.let { geofenceState ->
val geofencingEvent = GeofencingEvent(
geofenceState.feature,
geofenceState.timestamp ?: Date(),
)

val geofencingEvent = GeofencingEvent.Builder().apply {
feature = geofenceState.feature
timestamp = geofenceState.timestamp ?: Date()
}.build()
when (featureType) {
NOTIFICATION_FEATURE_EXIT -> observer.onExit(geofencingEvent)
NOTIFICATION_FEATURE_ENTRY -> observer.onEntry(geofencingEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.google.gson.JsonObject
import com.mapbox.annotation.MapboxExperimental
import com.mapbox.bindgen.Expected
import com.mapbox.common.experimental.geofencing.GeofencingError
import com.mapbox.common.experimental.geofencing.GeofencingEvent
import com.mapbox.common.experimental.geofencing.GeofencingFactory
import com.mapbox.common.experimental.geofencing.GeofencingObserver
import com.mapbox.common.experimental.geofencing.GeofencingOptions
import com.mapbox.common.experimental.geofencing.GeofencingPropertiesKeys
import com.mapbox.common.geofencing.GeofencingError
import com.mapbox.common.geofencing.GeofencingEvent
import com.mapbox.common.geofencing.GeofencingFactory
import com.mapbox.common.geofencing.GeofencingObserver
import com.mapbox.common.geofencing.GeofencingOptions
import com.mapbox.common.geofencing.GeofencingPropertiesKeys
import com.mapbox.geojson.Feature
import com.mapbox.geojson.GeometryCollection
import com.mapbox.geojson.Point
Expand Down Expand Up @@ -45,6 +46,7 @@ import java.lang.ref.WeakReference
* Geofence callbacks are called when device location enters, dwells, or leaves loaded geofence zone.
* Each aforementioned event is accompanied by rendering received feature (Blue, Green, Red colors ).
*/
@MapboxExperimental
class SimpleGeofencingActivity : AppCompatActivity() {

private lateinit var locationPermissionHelper: LocationPermissionHelper
Expand Down Expand Up @@ -129,7 +131,10 @@ class SimpleGeofencingActivity : AppCompatActivity() {
locationPermissionHelper.checkPermissions {
// Postpone access to Geofence engine until we get location permissions
geofencing.configure(
GeofencingOptions(CUSTOM_GEOFENCE_RADIUS, 300_000),
GeofencingOptions.Builder().apply {
defaultRadius = CUSTOM_GEOFENCE_RADIUS
maximumMonitoredFeatures = 300_000
}.build(),
logGeofencingError("configure")
)
startGeofencing()
Expand Down
2 changes: 1 addition & 1 deletion extension-compose/api/Release/metalava.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ package com.mapbox.maps.extension.compose.ornaments.attribution {

@androidx.compose.runtime.Immutable @com.mapbox.maps.extension.compose.MapboxMapScopeMarker public final class MapAttributionScope {
method @androidx.compose.runtime.Composable public void Attribution(androidx.compose.ui.Modifier modifier = Modifier, androidx.compose.foundation.layout.PaddingValues contentPadding = PaddingValues(92.dp, 4.dp, 4.dp, 4.dp), androidx.compose.ui.Alignment alignment = androidx.compose.ui.Alignment.Companion.BottomStart, long iconColor = Color(4280192171), kotlin.jvm.functions.Function3<? super java.util.List<com.mapbox.maps.plugin.attribution.Attribution>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function1<? super com.mapbox.maps.plugin.attribution.Attribution,kotlin.Unit>,kotlin.Unit> attributionDialog = { attributions, onDismissRequest, onAttributionClick -> AttributionDialog(attributions, onDismissRequest, onAttributionClick) }, kotlin.jvm.functions.Function4<? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,kotlin.Unit> telemetryDialog = { onDismissRequest, onMoreInfo, onDisagree, onAgree -> TelemetryDialog(onDismissRequest, onMoreInfo, onDisagree, onAgree) });
method @androidx.compose.runtime.Composable @com.mapbox.maps.MapboxExperimental public void Attribution(androidx.compose.ui.Modifier modifier = Modifier, androidx.compose.foundation.layout.PaddingValues contentPadding = PaddingValues(92.dp, 4.dp, 4.dp, 4.dp), androidx.compose.ui.Alignment alignment = androidx.compose.ui.Alignment.Companion.BottomStart, long iconColor = Color(4280192171), kotlin.jvm.functions.Function3<? super java.util.List<com.mapbox.maps.plugin.attribution.Attribution>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function1<? super com.mapbox.maps.plugin.attribution.Attribution,kotlin.Unit>,kotlin.Unit> attributionDialog = { attributions, onDismissRequest, onAttributionClick -> AttributionDialog(attributions, onDismissRequest, onAttributionClick) }, kotlin.jvm.functions.Function4<? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,kotlin.Unit> telemetryDialog = { onDismissRequest, onMoreInfo, onDisagree, onAgree -> TelemetryDialog(onDismissRequest, onMoreInfo, onDisagree, onAgree) }, kotlin.jvm.functions.Function4<? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super java.lang.Boolean,kotlin.Unit> geofencingConsentDialog = { onDismissRequest, onDisagree, onAgree, currentUserConsent -> GeofencingConsentDialog(onDismissRequest, onDisagree, onAgree, currentUserConsent) });
method @androidx.compose.runtime.Composable @com.mapbox.annotation.MapboxExperimental @com.mapbox.maps.MapboxExperimental public void Attribution(androidx.compose.ui.Modifier modifier = Modifier, androidx.compose.foundation.layout.PaddingValues contentPadding = PaddingValues(92.dp, 4.dp, 4.dp, 4.dp), androidx.compose.ui.Alignment alignment = androidx.compose.ui.Alignment.Companion.BottomStart, long iconColor = Color(4280192171), kotlin.jvm.functions.Function3<? super java.util.List<com.mapbox.maps.plugin.attribution.Attribution>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function1<? super com.mapbox.maps.plugin.attribution.Attribution,kotlin.Unit>,kotlin.Unit> attributionDialog = { attributions, onDismissRequest, onAttributionClick -> AttributionDialog(attributions, onDismissRequest, onAttributionClick) }, kotlin.jvm.functions.Function4<? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,kotlin.Unit> telemetryDialog = { onDismissRequest, onMoreInfo, onDisagree, onAgree -> TelemetryDialog(onDismissRequest, onMoreInfo, onDisagree, onAgree) }, kotlin.jvm.functions.Function4<? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super kotlin.jvm.functions.Function0<kotlin.Unit>,? super java.lang.Boolean,kotlin.Unit> geofencingConsentDialog = { onDismissRequest, onDisagree, onAgree, currentUserConsent -> GeofencingConsentDialog(onDismissRequest, onDisagree, onAgree, currentUserConsent) });
method @androidx.compose.runtime.Composable public void AttributionDialog(java.util.List<com.mapbox.maps.plugin.attribution.Attribution> attributions, kotlin.jvm.functions.Function0<kotlin.Unit> onDismissRequest, kotlin.jvm.functions.Function1<? super com.mapbox.maps.plugin.attribution.Attribution,kotlin.Unit> onAttributionClick);
method @androidx.compose.runtime.Composable public void GeofencingConsentDialog(kotlin.jvm.functions.Function0<kotlin.Unit> onDismissRequest, kotlin.jvm.functions.Function0<kotlin.Unit> onDisagree, kotlin.jvm.functions.Function0<kotlin.Unit> onAgree, boolean currentUserConsent);
method @androidx.compose.runtime.Composable public void TelemetryDialog(kotlin.jvm.functions.Function0<kotlin.Unit> onDismissRequest, kotlin.jvm.functions.Function0<kotlin.Unit> onMoreInfo, kotlin.jvm.functions.Function0<kotlin.Unit> onDisagree, kotlin.jvm.functions.Function0<kotlin.Unit> onAgree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.DialogProperties
import com.mapbox.common.experimental.geofencing.GeofencingError
import com.mapbox.common.geofencing.GeofencingError
import com.mapbox.maps.MapView
import com.mapbox.maps.MapboxExperimental
import com.mapbox.maps.extension.compose.MapboxMapScopeMarker
Expand Down Expand Up @@ -142,6 +142,7 @@ public class MapAttributionScope internal constructor(
* @param telemetryDialog Defines TelemetryDialog when the Mapbox telemetry is clicked.
* @param geofencingConsentDialog Defines GeofencingConsentDialog when the Mapbox Geofencing is clicked.
*/
@com.mapbox.annotation.MapboxExperimental
@MapboxExperimental
@Composable
public fun Attribution(
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ japicmp = "0.4.1"
# Dependencies

# GlNative and Common are used by the convention plugin
mapboxGlNative = "11.8.0"
mapboxCommon = "24.8.0"
mapboxGlNative = "11.9.0-SNAPSHOT.1115T0701Z.ff7733b"
mapboxCommon = "24.9.0-SNAPSHOT.1115T0701Z.ff7733b"

mapboxBase = "0.11.0"
mapboxGestures = "0.8.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.mapbox.maps

import com.mapbox.common.experimental.geofencing.GeofencingUtils
import com.mapbox.common.experimental.geofencing.GeofencingUtilsUserConsentResponseCallback
import com.mapbox.common.geofencing.GeofencingUtils
import com.mapbox.common.geofencing.GeofencingUtilsUserConsentResponseCallback
import com.mapbox.maps.geofencing.MapGeofencingConsent

@OptIn(MapboxExperimental::class)
@OptIn(MapboxExperimental::class, com.mapbox.annotation.MapboxExperimental::class)
internal class MapGeofencingConsentImpl : MapGeofencingConsent {
override fun setUserConsent(
isConsentGiven: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.view.ContextThemeWrapper
import androidx.core.content.ContextCompat
import com.mapbox.common.experimental.geofencing.GeofencingUtilsUserConsentResponseCallback
import com.mapbox.common.geofencing.GeofencingUtilsUserConsentResponseCallback
import com.mapbox.maps.MapboxExperimental
import com.mapbox.maps.geofencing.MapGeofencingConsent
import com.mapbox.maps.logW
Expand Down Expand Up @@ -140,7 +140,7 @@ class AttributionDialogManagerImpl(
telemetryDialog = builder.show()
}

@OptIn(MapboxExperimental::class)
@OptIn(MapboxExperimental::class, com.mapbox.annotation.MapboxExperimental::class)
private fun showGeofencingConsentDialog() {
val builder = prepareDialogBuilder()
builder.setTitle(R.string.mapbox_attributionGeofencingTitle)
Expand Down
4 changes: 2 additions & 2 deletions sdk-base/api/Release/metalava.txt
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,9 @@ package com.mapbox.maps.extension.style {

package com.mapbox.maps.geofencing {

@com.mapbox.maps.MapboxExperimental public interface MapGeofencingConsent {
@com.mapbox.annotation.MapboxExperimental @com.mapbox.maps.MapboxExperimental public interface MapGeofencingConsent {
method @com.mapbox.maps.MapboxExperimental public boolean getUserConsent();
method @com.mapbox.maps.MapboxExperimental public void setUserConsent(boolean isConsentGiven, com.mapbox.common.experimental.geofencing.GeofencingUtilsUserConsentResponseCallback callback);
method @com.mapbox.maps.MapboxExperimental public void setUserConsent(boolean isConsentGiven, com.mapbox.common.geofencing.GeofencingUtilsUserConsentResponseCallback callback);
method @com.mapbox.maps.MapboxExperimental public boolean shouldShowConsent();
}

Expand Down
2 changes: 1 addition & 1 deletion sdk-base/api/sdk-base.api
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ public abstract interface class com/mapbox/maps/extension/style/StyleContract$St

public abstract interface class com/mapbox/maps/geofencing/MapGeofencingConsent {
public abstract fun getUserConsent ()Z
public abstract fun setUserConsent (ZLcom/mapbox/common/experimental/geofencing/GeofencingUtilsUserConsentResponseCallback;)V
public abstract fun setUserConsent (ZLcom/mapbox/common/geofencing/GeofencingUtilsUserConsentResponseCallback;)V
public abstract fun shouldShowConsent ()Z
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.mapbox.maps.geofencing

import com.mapbox.common.experimental.geofencing.GeofencingUtilsUserConsentResponseCallback
import com.mapbox.common.geofencing.GeofencingUtilsUserConsentResponseCallback
import com.mapbox.maps.MapboxExperimental

/**
* Definition of map Geofencing consent utilities
*/
@com.mapbox.annotation.MapboxExperimental
@MapboxExperimental
interface MapGeofencingConsent {

Expand Down

0 comments on commit 3ed8ff4

Please sign in to comment.