Skip to content

Commit 307a163

Browse files
authored
Bulk update all settings on Android (#564)
1 parent 2fac1c6 commit 307a163

File tree

5 files changed

+99
-91
lines changed

5 files changed

+99
-91
lines changed

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/mapping/CompassMappings.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ import com.mapbox.maps.plugin.compass.generated.CompassSettingsInterface
1212
import java.io.ByteArrayOutputStream
1313

1414
fun CompassSettingsInterface.applyFromFLT(settings: CompassSettings, context: Context) {
15-
settings.enabled?.let { enabled = it }
16-
settings.position?.let { position = it.toPosition() }
17-
settings.marginLeft?.let { marginLeft = it.toDevicePixels(context) }
18-
settings.marginTop?.let { marginTop = it.toDevicePixels(context) }
19-
settings.marginRight?.let { marginRight = it.toDevicePixels(context) }
20-
settings.marginBottom?.let { marginBottom = it.toDevicePixels(context) }
21-
settings.opacity?.let { opacity = it.toFloat() }
22-
settings.rotation?.let { rotation = it.toFloat() }
23-
settings.visibility?.let { visibility = it }
24-
settings.fadeWhenFacingNorth?.let { fadeWhenFacingNorth = it }
25-
settings.clickable?.let { clickable = it }
26-
settings.image?.let { image = if (it.isNotEmpty()) ImageHolder.from(BitmapFactory.decodeByteArray(it, 0, it.size)) else null }
15+
updateSettings {
16+
settings.enabled?.let { this.enabled = it }
17+
settings.position?.let { this.position = it.toPosition() }
18+
settings.marginLeft?.let { this.marginLeft = it.toDevicePixels(context) }
19+
settings.marginTop?.let { this.marginTop = it.toDevicePixels(context) }
20+
settings.marginRight?.let { this.marginRight = it.toDevicePixels(context) }
21+
settings.marginBottom?.let { this.marginBottom = it.toDevicePixels(context) }
22+
settings.opacity?.let { this.opacity = it.toFloat() }
23+
settings.rotation?.let { this.rotation = it.toFloat() }
24+
settings.visibility?.let { this.visibility = it }
25+
settings.fadeWhenFacingNorth?.let { this.fadeWhenFacingNorth = it }
26+
settings.clickable?.let { this.clickable = it }
27+
settings.image?.let { this.image = if (it.isNotEmpty()) ImageHolder.from(BitmapFactory.decodeByteArray(it, 0, it.size)) else null }
28+
}
2729
}
2830

2931
fun CompassSettingsInterface.toFLT(context: Context) = CompassSettings(

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/mapping/GesturesMappings.kt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,27 @@ import com.mapbox.maps.mapbox_maps.toLogicalPixels
99
import com.mapbox.maps.plugin.gestures.generated.GesturesSettingsInterface
1010

1111
fun GesturesSettingsInterface.applyFromFLT(settings: GesturesSettings, context: Context) {
12-
settings.rotateEnabled?.let { rotateEnabled = it }
13-
settings.pinchToZoomEnabled?.let { pinchToZoomEnabled = it }
14-
settings.scrollEnabled?.let { scrollEnabled = it }
15-
settings.simultaneousRotateAndPinchToZoomEnabled?.let { simultaneousRotateAndPinchToZoomEnabled = it }
16-
settings.pitchEnabled?.let { pitchEnabled = it }
17-
settings.scrollMode?.let {
18-
scrollMode = com.mapbox.maps.plugin.ScrollMode.values()[it.ordinal]
12+
updateSettings {
13+
settings.rotateEnabled?.let { this.rotateEnabled = it }
14+
settings.pinchToZoomEnabled?.let { this.pinchToZoomEnabled = it }
15+
settings.scrollEnabled?.let { this.scrollEnabled = it }
16+
settings.simultaneousRotateAndPinchToZoomEnabled?.let { this.simultaneousRotateAndPinchToZoomEnabled = it }
17+
settings.pitchEnabled?.let { this.pitchEnabled = it }
18+
settings.scrollMode?.let {
19+
this.scrollMode = com.mapbox.maps.plugin.ScrollMode.values()[it.ordinal]
20+
}
21+
settings.doubleTapToZoomInEnabled?.let { this.doubleTapToZoomInEnabled = it }
22+
settings.doubleTouchToZoomOutEnabled?.let { this.doubleTouchToZoomOutEnabled = it }
23+
settings.quickZoomEnabled?.let { this.quickZoomEnabled = it }
24+
settings.focalPoint?.let { this.focalPoint = ScreenCoordinate(it.x.toDevicePixels(context).toDouble(), it.y.toDevicePixels(context).toDouble()) }
25+
settings.pinchToZoomDecelerationEnabled?.let { this.pinchToZoomDecelerationEnabled = it }
26+
settings.rotateDecelerationEnabled?.let { this.rotateDecelerationEnabled = it }
27+
settings.scrollDecelerationEnabled?.let { this.scrollDecelerationEnabled = it }
28+
settings.increaseRotateThresholdWhenPinchingToZoom?.let { this.increaseRotateThresholdWhenPinchingToZoom = it }
29+
settings.increasePinchToZoomThresholdWhenRotating?.let { this.increasePinchToZoomThresholdWhenRotating = it }
30+
settings.zoomAnimationAmount?.let { this.zoomAnimationAmount = it.toFloat() }
31+
settings.pinchPanEnabled?.let { this.pinchScrollEnabled = it }
1932
}
20-
settings.doubleTapToZoomInEnabled?.let { doubleTapToZoomInEnabled = it }
21-
settings.doubleTouchToZoomOutEnabled?.let { doubleTouchToZoomOutEnabled = it }
22-
settings.quickZoomEnabled?.let { quickZoomEnabled = it }
23-
settings.focalPoint?.let { focalPoint = ScreenCoordinate(it.x.toDevicePixels(context).toDouble(), it.y.toDevicePixels(context).toDouble()) }
24-
settings.pinchToZoomDecelerationEnabled?.let { pinchToZoomDecelerationEnabled = it }
25-
settings.rotateDecelerationEnabled?.let { rotateDecelerationEnabled = it }
26-
settings.scrollDecelerationEnabled?.let { scrollDecelerationEnabled = it }
27-
settings.increaseRotateThresholdWhenPinchingToZoom?.let { increaseRotateThresholdWhenPinchingToZoom = it }
28-
settings.increasePinchToZoomThresholdWhenRotating?.let { increasePinchToZoomThresholdWhenRotating = it }
29-
settings.zoomAnimationAmount?.let { zoomAnimationAmount = it.toFloat() }
30-
settings.pinchPanEnabled?.let { pinchScrollEnabled = it }
3133
}
3234

3335
fun GesturesSettingsInterface.toFLT(context: Context) = GesturesSettings(

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/mapping/LocationComponentMappings.kt

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,50 @@ import com.mapbox.maps.plugin.locationcomponent.generated.LocationComponentSetti
1313
import java.io.ByteArrayOutputStream
1414

1515
fun LocationComponentSettingsInterface.applyFromFLT(settings: LocationComponentSettings, useDefaultPuck2DIfNeeded: Boolean, context: Context) {
16-
settings.enabled?.let { enabled = it }
17-
settings.pulsingEnabled?.let { pulsingEnabled = it }
18-
settings.pulsingColor?.let { pulsingColor = it.toInt() }
19-
settings.pulsingMaxRadius?.let { pulsingMaxRadius = it.toFloat() }
20-
settings.showAccuracyRing?.let { showAccuracyRing = it }
21-
settings.accuracyRingColor?.let { accuracyRingColor = it.toInt() }
22-
settings.accuracyRingBorderColor?.let { accuracyRingBorderColor = it.toInt() }
23-
settings.layerAbove?.let { layerAbove = it }
24-
settings.layerBelow?.let { layerBelow = it }
25-
settings.puckBearingEnabled?.let { puckBearingEnabled = it }
26-
settings.puckBearing?.let {
27-
puckBearing = com.mapbox.maps.plugin.PuckBearing.values()[it.ordinal]
28-
}
29-
settings.locationPuck?.let {
30-
val puck2D = it.locationPuck2D
31-
val puck3D = it.locationPuck3D
32-
locationPuck = if (puck3D != null) {
33-
com.mapbox.maps.plugin.LocationPuck3D(
34-
puck3D.modelUri!!
35-
).apply {
36-
puck3D.modelUri?.let { modelUri = it }
37-
puck3D.position?.let { position = it.mapNotNull { it?.toFloat() } }
38-
puck3D.modelOpacity?.let { modelOpacity = it.toFloat() }
39-
puck3D.modelScale?.let { modelScale = it.mapNotNull { it?.toFloat() } }
40-
puck3D.modelScaleExpression?.let { modelScaleExpression = it }
41-
puck3D.modelTranslation?.let { modelTranslation = it.mapNotNull { it?.toFloat() } }
42-
puck3D.modelRotation?.let { modelRotation = it.mapNotNull { it?.toFloat() } }
43-
puck3D.modelCastShadows?.let { modelCastShadows = it }
44-
puck3D.modelReceiveShadows?.let { modelReceiveShadows = it }
45-
puck3D.modelScaleMode?.let { modelScaleMode = it.toModelScaleMode() }
46-
puck3D.modelEmissiveStrength?.let { modelEmissiveStrength = it.toFloat() }
47-
puck3D.modelEmissiveStrengthExpression?.let { modelEmissiveStrengthExpression = it }
48-
}
49-
} else {
50-
(if (useDefaultPuck2DIfNeeded) createDefault2DPuck(withBearing = settings.puckBearingEnabled == true) else com.mapbox.maps.plugin.LocationPuck2D())
51-
.apply {
52-
puck2D?.topImage?.let { topImage = if (it.isNotEmpty()) ImageHolder.from(BitmapFactory.decodeByteArray(it, 0, it.size)) else null }
53-
puck2D?.bearingImage?.let { bearingImage = if (it.isNotEmpty()) ImageHolder.from(BitmapFactory.decodeByteArray(it, 0, it.size)) else null }
54-
puck2D?.shadowImage?.let { shadowImage = if (it.isNotEmpty()) ImageHolder.from(BitmapFactory.decodeByteArray(it, 0, it.size)) else null }
55-
puck2D?.scaleExpression?.let { scaleExpression = it }
56-
puck2D?.opacity?.let { opacity = it.toFloat() }
16+
updateSettings {
17+
settings.enabled?.let { this.enabled = it }
18+
settings.pulsingEnabled?.let { this.pulsingEnabled = it }
19+
settings.pulsingColor?.let { this.pulsingColor = it.toInt() }
20+
settings.pulsingMaxRadius?.let { this.pulsingMaxRadius = it.toFloat() }
21+
settings.showAccuracyRing?.let { this.showAccuracyRing = it }
22+
settings.accuracyRingColor?.let { this.accuracyRingColor = it.toInt() }
23+
settings.accuracyRingBorderColor?.let { this.accuracyRingBorderColor = it.toInt() }
24+
settings.layerAbove?.let { this.layerAbove = it }
25+
settings.layerBelow?.let { this.layerBelow = it }
26+
settings.puckBearingEnabled?.let { this.puckBearingEnabled = it }
27+
settings.puckBearing?.let {
28+
this.puckBearing = com.mapbox.maps.plugin.PuckBearing.values()[it.ordinal]
29+
}
30+
settings.locationPuck?.let {
31+
val puck2D = it.locationPuck2D
32+
val puck3D = it.locationPuck3D
33+
this.locationPuck = if (puck3D != null) {
34+
com.mapbox.maps.plugin.LocationPuck3D(
35+
puck3D.modelUri!!
36+
).apply {
37+
puck3D.modelUri?.let { this.modelUri = it }
38+
puck3D.position?.let { this.position = it.mapNotNull { it?.toFloat() } }
39+
puck3D.modelOpacity?.let { this.modelOpacity = it.toFloat() }
40+
puck3D.modelScale?.let { this.modelScale = it.mapNotNull { it?.toFloat() } }
41+
puck3D.modelScaleExpression?.let { this.modelScaleExpression = it }
42+
puck3D.modelTranslation?.let { this.modelTranslation = it.mapNotNull { it?.toFloat() } }
43+
puck3D.modelRotation?.let { this.modelRotation = it.mapNotNull { it?.toFloat() } }
44+
puck3D.modelCastShadows?.let { this.modelCastShadows = it }
45+
puck3D.modelReceiveShadows?.let { this.modelReceiveShadows = it }
46+
puck3D.modelScaleMode?.let { this.modelScaleMode = it.toModelScaleMode() }
47+
puck3D.modelEmissiveStrength?.let { this.modelEmissiveStrength = it.toFloat() }
48+
puck3D.modelEmissiveStrengthExpression?.let { this.modelEmissiveStrengthExpression = it }
5749
}
50+
} else {
51+
(if (useDefaultPuck2DIfNeeded) createDefault2DPuck(withBearing = settings.puckBearingEnabled == true) else com.mapbox.maps.plugin.LocationPuck2D())
52+
.apply {
53+
puck2D?.topImage?.let { this.topImage = if (it.isNotEmpty()) ImageHolder.from(BitmapFactory.decodeByteArray(it, 0, it.size)) else null }
54+
puck2D?.bearingImage?.let { this.bearingImage = if (it.isNotEmpty()) ImageHolder.from(BitmapFactory.decodeByteArray(it, 0, it.size)) else null }
55+
puck2D?.shadowImage?.let { this.shadowImage = if (it.isNotEmpty()) ImageHolder.from(BitmapFactory.decodeByteArray(it, 0, it.size)) else null }
56+
puck2D?.scaleExpression?.let { this.scaleExpression = it }
57+
puck2D?.opacity?.let { this.opacity = it.toFloat() }
58+
}
59+
}
5860
}
5961
}
6062
}

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/mapping/LogoMappings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.mapbox.maps.mapbox_maps.toLogicalPixels
88
import com.mapbox.maps.plugin.logo.generated.LogoSettingsInterface
99

1010
fun LogoSettingsInterface.applyFromFLT(settings: LogoSettings, context: Context) {
11-
this.updateSettings {
11+
updateSettings {
1212
settings.enabled?.let { this.enabled = it }
1313
settings.position?.let { this.position = it.toPosition() }
1414
settings.marginLeft?.let { this.marginLeft = it.toDevicePixels(context) }

android/src/main/kotlin/com/mapbox/maps/mapbox_maps/mapping/ScaleBarMappings.kt

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,27 @@ import com.mapbox.maps.mapbox_maps.toLogicalPixels
88
import com.mapbox.maps.plugin.scalebar.generated.ScaleBarSettingsInterface
99

1010
fun ScaleBarSettingsInterface.applyFromFLT(settings: ScaleBarSettings, context: Context) {
11-
settings.enabled?.let { enabled = it }
12-
settings.position?.let { position = it.toPosition() }
13-
settings.marginLeft?.let { marginLeft = it.toDevicePixels(context) }
14-
settings.marginTop?.let { marginTop = it.toDevicePixels(context) }
15-
settings.marginRight?.let { marginRight = it.toDevicePixels(context) }
16-
settings.marginBottom?.let { marginBottom = it.toDevicePixels(context) }
17-
settings.textColor?.let { textColor = it.toInt() }
18-
settings.primaryColor?.let { primaryColor = it.toInt() }
19-
settings.secondaryColor?.let { secondaryColor = it.toInt() }
20-
settings.borderWidth?.let { borderWidth = it.toDevicePixels(context) }
21-
settings.height?.let { height = it.toDevicePixels(context) }
22-
settings.textBarMargin?.let { textBarMargin = it.toDevicePixels(context) }
23-
settings.textBorderWidth?.let { textBorderWidth = it.toDevicePixels(context) }
24-
settings.textSize?.let { textSize = it.toFloat() }
25-
settings.isMetricUnits?.let { isMetricUnits = it }
26-
settings.refreshInterval?.let { refreshInterval = it }
27-
settings.showTextBorder?.let { showTextBorder = it }
28-
settings.ratio?.let { ratio = it.toFloat() }
29-
settings.useContinuousRendering?.let { useContinuousRendering = it }
11+
updateSettings {
12+
settings.enabled?.let { this.enabled = it }
13+
settings.position?.let { this.position = it.toPosition() }
14+
settings.marginLeft?.let { this.marginLeft = it.toDevicePixels(context) }
15+
settings.marginTop?.let { this.marginTop = it.toDevicePixels(context) }
16+
settings.marginRight?.let { this.marginRight = it.toDevicePixels(context) }
17+
settings.marginBottom?.let { this.marginBottom = it.toDevicePixels(context) }
18+
settings.textColor?.let { this.textColor = it.toInt() }
19+
settings.primaryColor?.let { this.primaryColor = it.toInt() }
20+
settings.secondaryColor?.let { this.secondaryColor = it.toInt() }
21+
settings.borderWidth?.let { this.borderWidth = it.toDevicePixels(context) }
22+
settings.height?.let { this.height = it.toDevicePixels(context) }
23+
settings.textBarMargin?.let { this.textBarMargin = it.toDevicePixels(context) }
24+
settings.textBorderWidth?.let { this.textBorderWidth = it.toDevicePixels(context) }
25+
settings.textSize?.let { this.textSize = it.toFloat() }
26+
settings.isMetricUnits?.let { this.isMetricUnits = it }
27+
settings.refreshInterval?.let { this.refreshInterval = it }
28+
settings.showTextBorder?.let { this.showTextBorder = it }
29+
settings.ratio?.let { this.ratio = it.toFloat() }
30+
settings.useContinuousRendering?.let { this.useContinuousRendering = it }
31+
}
3032
}
3133

3234
fun ScaleBarSettingsInterface.toFLT(context: Context) = ScaleBarSettings(

0 commit comments

Comments
 (0)