Skip to content

Commit

Permalink
Show geofencing user consent dialog (#2795)
Browse files Browse the repository at this point in the history
  • Loading branch information
jush authored Oct 14, 2024
1 parent b641e4a commit 54b2e49
Show file tree
Hide file tree
Showing 27 changed files with 695 additions and 171 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ Mapbox welcomes participation and contributions from everyone.
* Dispatch view annotations update before rendering, so that view annotations and map layers are rendered simultaneously and thus decreasing the view annotations latency when using `ViewAnnotationUpdateMode.MAP_FIXED_DELAY` mode.
* Overscale composited tile components in offline.
* Skip rendering landmarks when the camera is inside them.
* Introduce experimental Geofencing API. Implementation example: [GeofencingActivity.kt](app/src/main/java/com/mapbox/maps/testapp/examples/geofence/GeofencingActivity.kt)
* [compose] Deprecate all `Annotation` and `AnnotationGroup` composables that take `onClick` parameter. Now all annotation interactions could be set with appropriate `AnnotationInteractionsState` or `AnnotationGroupInteractionsState` stored in `AnnotationGroupState`.
* [compose] Introduce `AnnotationInteractionsState` and `AnnotationGroupInteractionsState` states that allow to set callbacks for annotation interactions via `onClicked()` and `onLongClicked()`.`PointAnnotationGroupInteractionsState` and `CircleAnnotationGroupInteractionsState` also provide ability to set callbacks for interactions with clusters via `onClusterClicked` and `onClusterLongClicked`.
* [compose] Introduce `remember` (e.g. `rememberPolylineAnnotationGroupInteractionsState` and `rememberPolylineAnnotationInteractionsState`) composable functions to create, init and remember all types of `AnnotationInteractionsState` and `AnnotationGroupInteractionsState`.
* [compose] Introduce `<AnnotationType>InteractionsState.isDraggable` / `<AnnotationType>GroupInteractionsState.isDraggable` API for all annotation types allowing to drag annotations. Callbacks `onDragStarted()`, `onDragged()`,`onDragFinished()` are added as well.
* [compose] Introduce experimental `Attribution(..., geofencingDialog)` compose function to customize Geofencing consent dialog.
* Introduce experimental `MapView.attribution..getMapAttributionDelegate().extraAttributions` to add custom attributions to the attribution dialog.

## Bug fixes 🐞
* Improve zooming performance on dynamic Standard terrain and optimize terrain re-rendering performance on e.g routeline `line-trim-offset` change.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ class CustomAttributionActivity : AppCompatActivity() {
binding.customAttributionFab.setOnClickListener {
Toast.makeText(this, R.string.custom_attribution_custom, Toast.LENGTH_LONG).show()
val config = AttributionParserConfig(
checkBoxes[0].isChecked,
checkBoxes[1].isChecked,
checkBoxes[2].isChecked,
checkBoxes[3].isChecked,
checkBoxes[4].isChecked,
withImproveMap = checkBoxes[0].isChecked,
withCopyrightSign = checkBoxes[1].isChecked,
withTelemetryAttribution = checkBoxes[2].isChecked,
withMapboxAttribution = checkBoxes[3].isChecked,
withMapboxPrivacyPolicy = checkBoxes[4].isChecked,
withMapboxGeofencingConsent = false // This custom dialog does not support geofencing user consent
)
attributionPlugin.setCustomAttributionDialogManager(
CustomAttributionDialog(this, config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ package com.mapbox.maps.testapp.examples.geofence

import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.View
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
Expand Down Expand Up @@ -54,10 +48,7 @@ import com.mapbox.maps.logD
import com.mapbox.maps.logW
import com.mapbox.maps.plugin.PuckBearing
import com.mapbox.maps.plugin.attribution.Attribution
import com.mapbox.maps.plugin.attribution.AttributionDialogManager
import com.mapbox.maps.plugin.attribution.AttributionParserConfig
import com.mapbox.maps.plugin.attribution.attribution
import com.mapbox.maps.plugin.delegates.MapAttributionDelegate
import com.mapbox.maps.plugin.locationcomponent.OnIndicatorPositionChangedListener
import com.mapbox.maps.plugin.locationcomponent.createDefault2DPuck
import com.mapbox.maps.plugin.locationcomponent.location
Expand Down Expand Up @@ -362,8 +353,12 @@ class GeofencingActivity : AppCompatActivity() {
return@ClickInteraction true
}
)
binding.mapView.attribution.setCustomAttributionDialogManager(CustomAttributionDialog(this))

binding.mapView.attribution.getMapAttributionDelegate().extraAttributions = listOf(
Attribution(
"Geofence boundaries courtesy Helsingin seuden liiken HSL (CC-BY)",
"https://hri.fi/data/en_GB/dataset/hsl-n-taksavyohykkeet"
)
)
handleGeofenceIntent(intent)
}

Expand Down Expand Up @@ -603,78 +598,6 @@ class GeofencingActivity : AppCompatActivity() {
}
}

/***
* Custom attribution to show the link to HSL public dataset
*/
inner class CustomAttributionDialog(
private val context: Context,
) : AttributionDialogManager, DialogInterface.OnClickListener {

private lateinit var attributionList: MutableList<Attribution>
private var dialog: AlertDialog? = null
private var mapAttributionDelegate: MapAttributionDelegate? = null

override fun showAttribution(mapAttributionDelegate: MapAttributionDelegate) {
this.mapAttributionDelegate = mapAttributionDelegate
attributionList =
mapAttributionDelegate.parseAttributions(
context,
AttributionParserConfig()
).toMutableList()

// HSL Attribution
attributionList.add(
0,
Attribution(
"Geofence boundaries courtesy Helsingin seuden liiken HSL (CC-BY)",
"https://hri.fi/data/en_GB/dataset/hsl-n-taksavyohykkeet"
)
)
var isActivityFinishing = false
if (context is Activity) {
isActivityFinishing = context.isFinishing
}
if (!isActivityFinishing) {
val attributionTitles = attributionList.map { it.title }.toTypedArray()
val builder = AlertDialog.Builder(context)
builder.setTitle(com.mapbox.maps.plugin.attribution.R.string.mapbox_attributionsDialogTitle)
builder.setAdapter(
ArrayAdapter(
context,
com.mapbox.maps.plugin.attribution.R.layout.mapbox_attribution_list_item,
attributionTitles
),
this
)
dialog = builder.show()
}
}

override fun onStop() {
dialog?.takeIf { it.isShowing }?.dismiss()
}

override fun onClick(dialog: DialogInterface?, which: Int) {
showWebPage(attributionList[which].url)
}

private fun showWebPage(url: String) {
if (context is Activity) {
try {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse(url)
context.startActivity(intent)
} catch (exception: ActivityNotFoundException) {
Toast.makeText(
context,
com.mapbox.maps.plugin.attribution.R.string.mapbox_attributionErrorNoBrowser,
Toast.LENGTH_LONG
).show()
}
}
}
}

companion object {
private const val TAG = "GeofencingActivity"

Expand Down
2 changes: 2 additions & 0 deletions extension-compose/api/Release/metalava.txt
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,9 @@ 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 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
14 changes: 4 additions & 10 deletions extension-compose/api/extension-compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -782,24 +782,18 @@ public final class com/mapbox/maps/extension/compose/ornaments/attribution/Compo
public static final field INSTANCE Lcom/mapbox/maps/extension/compose/ornaments/attribution/ComposableSingletons$MapAttributionScopeKt;
public static field lambda-1 Lkotlin/jvm/functions/Function2;
public static field lambda-2 Lkotlin/jvm/functions/Function2;
public static field lambda-3 Lkotlin/jvm/functions/Function3;
public static field lambda-4 Lkotlin/jvm/functions/Function3;
public static field lambda-5 Lkotlin/jvm/functions/Function3;
public static field lambda-6 Lkotlin/jvm/functions/Function2;
public static field lambda-7 Lkotlin/jvm/functions/Function2;
public static field lambda-3 Lkotlin/jvm/functions/Function4;
public fun <init> ()V
public final fun getLambda-1$extension_compose_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-2$extension_compose_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-3$extension_compose_release ()Lkotlin/jvm/functions/Function3;
public final fun getLambda-4$extension_compose_release ()Lkotlin/jvm/functions/Function3;
public final fun getLambda-5$extension_compose_release ()Lkotlin/jvm/functions/Function3;
public final fun getLambda-6$extension_compose_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-7$extension_compose_release ()Lkotlin/jvm/functions/Function2;
public final fun getLambda-3$extension_compose_release ()Lkotlin/jvm/functions/Function4;
}

public final class com/mapbox/maps/extension/compose/ornaments/attribution/MapAttributionScope {
public final fun Attribution-fWhpE4E (Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/ui/Alignment;JLkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function6;Landroidx/compose/runtime/Composer;II)V
public final fun Attribution-hYmLsZ8 (Landroidx/compose/ui/Modifier;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/ui/Alignment;JLkotlin/jvm/functions/Function5;Lkotlin/jvm/functions/Function6;Lkotlin/jvm/functions/Function6;Landroidx/compose/runtime/Composer;II)V
public final fun AttributionDialog (Ljava/util/List;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
public final fun GeofencingConsentDialog (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;ZLandroidx/compose/runtime/Composer;I)V
public final fun TelemetryDialog (Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;Landroidx/compose/runtime/Composer;I)V
}

Expand Down
Loading

0 comments on commit 54b2e49

Please sign in to comment.