Skip to content

Commit

Permalink
Port changes from main to release branch for 2.0.0-rc.1 (#546)
Browse files Browse the repository at this point in the history
* Gradle 8 compatibility (#524)

* Add namespace attribute to plugin's build.gradle

* Apply Gradle's plugins declaratively

* Bump Gradle wrapper to version 8 for the example app

* Add changelog entry

* Bump Flutter sdk version on CI

* Bump docker image for building Android on CI

* Silence R8 errors

* Update example/android/app/build.gradle

Co-authored-by: Ramon <[email protected]>

* Remove proguard exclusions from the example app

* Bump Kotlin to 1.8.22 in examples app

---------

Co-authored-by: Ramon <[email protected]>

* Map events race condition fix (#534)

* Subscribe to initial map events upon map widget initialization

* Regenerate code

* Add option to enable/disable map widget attribution (#536)

* Add option to enable/disable map widget attribution

* Enable Android snapshots to be consumed

* Update logo settings in bulk

* Update attribution settings in bulk

* Prepare 2.0.0-rc.1 (#545)

---------

Co-authored-by: Ramon <[email protected]>
  • Loading branch information
evil159 and jush authored May 16, 2024
1 parent 20cb112 commit 75c8ad4
Show file tree
Hide file tree
Showing 43 changed files with 342 additions and 243 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ jobs:
type: string
default: example/build/app/outputs/apk
docker:
- image: cimg/android:2022.09
- image: cimg/android:2024.04
resource_class: 2xlarge
steps:
- checkout
- flutter/install_sdk_and_pub:
version: 3.16.9
version: 3.19.6
app-dir: example
- run:
name: ktlint
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
- add-mapbox-submodules-key
- macos/install-rosetta
- flutter/install_sdk_and_pub:
version: 3.16.9
version: 3.19.6
app-dir: example
- flutter/install_ios_pod:
app-dir: example
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### main

### 2.0.0-rc.1

* Update Maps SDK to 11.4.0-rc.2.

### 2.0.0-beta.1

* Introduce experimental `RasterArraySource`, note that `rasterLayers` is a get-only property and cannot be set.
Expand Down Expand Up @@ -162,6 +166,7 @@ PolylineAnnotationOptions(
* Fix camera center not applied from map init options.
* [iOS] Free up resources upon map widget disposal. This should help to reduce the amount of used memory when previously shown map widget is removed from the widget tree.
* Fix multi-word enum cases decoding/encoding when being sent to/from the platform side.
* [Android] Add Gradle 8 compatibility.

### 1.1.0

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Contributions welcome!
| Point Annotations | :white_check_mark: | :white_check_mark: |
| Line Annotations | :white_check_mark: | :white_check_mark: |
| Fill Annotations | :white_check_mark: | :white_check_mark: |
| Snapshotter | :white_check_mark: | :white_check_mark: |
| Offline | :x: | :x: |
| Viewport | :x: | :x: |
| Style DSL | :x: | :x: |
Expand Down
17 changes: 16 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ rootProject.allprojects {
password = token
}
}
maven {
url 'https://api.mapbox.com/downloads/v2/snapshots/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
username = "mapbox"
password = token
}
}
}
}

Expand All @@ -42,6 +52,7 @@ apply plugin: 'kotlin-android'
android {
compileSdk 33

namespace 'com.mapbox.maps.mapbox_maps'
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
Expand All @@ -53,6 +64,10 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}
}

if (file("$rootDir/gradle/ktlint.gradle").exists() && file("$rootDir/gradle/lint.gradle").exists()) {
Expand All @@ -63,7 +78,7 @@ if (file("$rootDir/gradle/ktlint.gradle").exists() && file("$rootDir/gradle/lint
}

dependencies {
implementation "com.mapbox.maps:android:11.4.0-beta.2"
implementation "com.mapbox.maps:android:11.4.0-rc.2"

implementation "androidx.annotation:annotation:1.7.1"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import java.util.Date

class MapboxEventHandler(
private val eventProvider: Observable,
binaryMessenger: BinaryMessenger
binaryMessenger: BinaryMessenger,
eventTypes: List<Int>
) : MethodChannel.MethodCallHandler {
private val channel: MethodChannel
private val cancellables = HashSet<Cancelable>()
Expand All @@ -48,6 +49,11 @@ class MapboxEventHandler(
init {
channel = MethodChannel(binaryMessenger, "com.mapbox.maps.flutter.map_events")
channel.setMethodCallHandler(this)

eventTypes
.map { _MapEvent.ofRaw(it) }
.filterNotNull()
.forEach { subscribeToEvent(it) }
}

override fun onMethodCall(methodCall: MethodCall, result: MethodChannel.Result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class MapboxMapController(
private val lifecycleProvider: MapboxMapsPlugin.LifecycleProvider,
messenger: BinaryMessenger,
channelSuffix: Int,
pluginVersion: String
pluginVersion: String,
eventTypes: List<Int>
) : PlatformView,
DefaultLifecycleObserver,
MethodChannel.MethodCallHandler {
Expand Down Expand Up @@ -122,7 +123,7 @@ class MapboxMapController(
val mapboxMap = mapView.mapboxMap
this.mapView = mapView
this.mapboxMap = mapboxMap
eventHandler = MapboxEventHandler(mapboxMap.styleManager, proxyBinaryMessenger)
eventHandler = MapboxEventHandler(mapboxMap.styleManager, proxyBinaryMessenger, eventTypes)
styleController = StyleController(context, mapboxMap)
cameraController = CameraController(mapboxMap, context)
projectionController = MapProjectionController(mapboxMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class MapboxMapFactory(
val textureView = params["textureView"] as? Boolean ?: false
val styleUri = params["styleUri"] as? String ?: Style.MAPBOX_STREETS
val pluginVersion = params["mapboxPluginVersion"] as String
val eventTypes: List<Int> = params["eventTypes"] as List<Int>

val mapInitOptions = MapInitOptions(
context = context,
mapOptions = mapOptionsBuilder.build(),
Expand All @@ -130,6 +132,7 @@ class MapboxMapFactory(
messenger,
channelSuffix,
pluginVersion,
eventTypes
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import com.mapbox.maps.mapbox_maps.toLogicalPixels
import com.mapbox.maps.plugin.attribution.generated.AttributionSettingsInterface

fun AttributionSettingsInterface.applyFromFLT(settings: AttributionSettings, context: Context) {
settings.iconColor?.let { iconColor = it.toInt() }
settings.position?.let { position = it.toPosition() }
settings.marginLeft?.let { marginLeft = it.toDevicePixels(context) }
settings.marginTop?.let { marginTop = it.toDevicePixels(context) }
settings.marginRight?.let { marginRight = it.toDevicePixels(context) }
settings.marginBottom?.let { marginBottom = it.toDevicePixels(context) }
settings.clickable?.let { clickable = it }
updateSettings {
settings.enabled?.let { this.enabled = it }
settings.iconColor?.let { this.iconColor = it.toInt() }
settings.position?.let { this.position = it.toPosition() }
settings.marginLeft?.let { this.marginLeft = it.toDevicePixels(context) }
settings.marginTop?.let { this.marginTop = it.toDevicePixels(context) }
settings.marginRight?.let { this.marginRight = it.toDevicePixels(context) }
settings.marginBottom?.let { this.marginBottom = it.toDevicePixels(context) }
settings.clickable?.let { this.clickable = it }
}
}

fun AttributionSettingsInterface.toFLT(context: Context) = AttributionSettings(
enabled = enabled,
iconColor = iconColor.toUInt().toLong(),
position = position.toOrnamentPosition(),
marginLeft = marginLeft.toLogicalPixels(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import com.mapbox.maps.mapbox_maps.toLogicalPixels
import com.mapbox.maps.plugin.logo.generated.LogoSettingsInterface

fun LogoSettingsInterface.applyFromFLT(settings: LogoSettings, context: Context) {
settings.position?.let { position = it.toPosition() }
settings.marginLeft?.let { marginLeft = it.toDevicePixels(context) }
settings.marginTop?.let { marginTop = it.toDevicePixels(context) }
settings.marginRight?.let { marginRight = it.toDevicePixels(context) }
settings.marginBottom?.let { marginBottom = it.toDevicePixels(context) }
this.updateSettings {
settings.enabled?.let { this.enabled = it }
settings.position?.let { this.position = it.toPosition() }
settings.marginLeft?.let { this.marginLeft = it.toDevicePixels(context) }
settings.marginTop?.let { this.marginTop = it.toDevicePixels(context) }
settings.marginRight?.let { this.marginRight = it.toDevicePixels(context) }
settings.marginBottom?.let { this.marginBottom = it.toDevicePixels(context) }
}
}

fun LogoSettingsInterface.toFLT(context: Context) = LogoSettings(
enabled = enabled,
position = position.toOrnamentPosition(),
marginLeft = marginLeft.toLogicalPixels(context),
marginTop = marginTop.toLogicalPixels(context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ data class CompassSettings(
* Generated class from Pigeon that represents data sent in messages.
*/
data class AttributionSettings(
/**
* Whether the attribution icon is visible on the map.
* Restricted API. Please contact Mapbox to discuss your use case if you intend to use this property.
*/
val enabled: Boolean? = null,
/** Defines text color of the attribution icon. */
val iconColor: Long? = null,
/** Defines where the attribution icon is positioned on the map */
Expand All @@ -577,20 +582,22 @@ data class AttributionSettings(
companion object {
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): AttributionSettings {
val iconColor = list[0].let { if (it is Int) it.toLong() else it as Long? }
val position = (list[1] as Int?)?.let {
val enabled = list[0] as Boolean?
val iconColor = list[1].let { if (it is Int) it.toLong() else it as Long? }
val position = (list[2] as Int?)?.let {
OrnamentPosition.ofRaw(it)
}
val marginLeft = list[2] as Double?
val marginTop = list[3] as Double?
val marginRight = list[4] as Double?
val marginBottom = list[5] as Double?
val clickable = list[6] as Boolean?
return AttributionSettings(iconColor, position, marginLeft, marginTop, marginRight, marginBottom, clickable)
val marginLeft = list[3] as Double?
val marginTop = list[4] as Double?
val marginRight = list[5] as Double?
val marginBottom = list[6] as Double?
val clickable = list[7] as Boolean?
return AttributionSettings(enabled, iconColor, position, marginLeft, marginTop, marginRight, marginBottom, clickable)
}
}
fun toList(): List<Any?> {
return listOf<Any?>(
enabled,
iconColor,
position?.raw,
marginLeft,
Expand All @@ -608,6 +615,11 @@ data class AttributionSettings(
* Generated class from Pigeon that represents data sent in messages.
*/
data class LogoSettings(
/**
* Whether the logo is visible on the map.
* Restricted API. Please contact Mapbox to discuss your use case if you intend to use this property.
*/
val enabled: Boolean? = null,
/** Defines where the logo is positioned on the map */
val position: OrnamentPosition? = null,
/** Defines the margin to the left that the attribution icon honors. This property is specified in pixels. */
Expand All @@ -623,18 +635,20 @@ data class LogoSettings(
companion object {
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): LogoSettings {
val position = (list[0] as Int?)?.let {
val enabled = list[0] as Boolean?
val position = (list[1] as Int?)?.let {
OrnamentPosition.ofRaw(it)
}
val marginLeft = list[1] as Double?
val marginTop = list[2] as Double?
val marginRight = list[3] as Double?
val marginBottom = list[4] as Double?
return LogoSettings(position, marginLeft, marginTop, marginRight, marginBottom)
val marginLeft = list[2] as Double?
val marginTop = list[3] as Double?
val marginRight = list[4] as Double?
val marginBottom = list[5] as Double?
return LogoSettings(enabled, position, marginLeft, marginTop, marginRight, marginBottom)
}
}
fun toList(): List<Any?> {
return listOf<Any?>(
enabled,
position?.raw,
marginLeft,
marginTop,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private object _SnapshotterInstanceManagerCodec : StandardMessageCodec() {

/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface _SnapshotterInstanceManager {
fun setupSnapshotterForSuffix(suffix: String, options: MapSnapshotOptions)
fun setupSnapshotterForSuffix(suffix: String, eventTypes: List<Long>, options: MapSnapshotOptions)
fun tearDownSnapshotterForSuffix(suffix: String)

companion object {
Expand All @@ -216,10 +216,11 @@ interface _SnapshotterInstanceManager {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val suffixArg = args[0] as String
val optionsArg = args[1] as MapSnapshotOptions
val eventTypesArg = args[1] as List<Long>
val optionsArg = args[2] as MapSnapshotOptions
var wrapped: List<Any?>
try {
api.setupSnapshotterForSuffix(suffixArg, optionsArg)
api.setupSnapshotterForSuffix(suffixArg, eventTypesArg, optionsArg)
wrapped = listOf<Any?>(null)
} catch (exception: Throwable) {
wrapped = wrapError(exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ class SnapshotterInstanceManager(
private var proxyMessengers = HashMap<String, ProxyBinaryMessenger>()

@SuppressLint("RestrictedApi")
override fun setupSnapshotterForSuffix(suffix: String, options: MapSnapshotOptions) {
override fun setupSnapshotterForSuffix(
suffix: String,
eventTypes: List<Long>,
options: MapSnapshotOptions
) {
val snapshotter = Snapshotter(
context,
options = options.toSnapshotOptions(context),
overlayOptions = options.toSnapshotOverlayOptions()
)
val proxyBinaryMessenger = ProxyBinaryMessenger(messenger, suffix)
val styleManager: com.mapbox.maps.StyleManager = snapshotter.styleManager() // TODO: expose this on Android
val eventHandler = MapboxEventHandler(styleManager, proxyBinaryMessenger)
val eventHandler = MapboxEventHandler(styleManager, proxyBinaryMessenger, eventTypes.map { it.toInt() })
val snapshotterController = SnapshotterController(context, snapshotter, eventHandler)
val mapboxStyleManager = MapboxStyleManager(
styleManager,
Expand Down
Loading

0 comments on commit 75c8ad4

Please sign in to comment.