diff --git a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt index 0f239266f2..223fac9992 100644 --- a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt +++ b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt @@ -441,7 +441,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) } override fun getUiSettings(): IUiSettingsDelegate = - map?.uiSettings?.let { UiSettingsImpl(it, view) } ?: UiSettingsCache().also { + map?.uiSettings?.let { UiSettingsImpl(it, view) } ?: UiSettingsCache(view).also { internalOnInitializedCallbackList.add(it.getMapReadyCallback()) } @@ -661,13 +661,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) if (SDK_INT >= 26) { mapView?.let { it.parent?.onDescendantInvalidated(it, it) } } - map?.let { - val cameraPosition = it.cameraPosition - val tilt = cameraPosition.tilt - val bearing = cameraPosition.bearing - val useFast = tilt < 1f && (bearing % 360f < 1f || bearing % 360f > 359f) - projectionImpl?.updateProjectionState(it.projection, useFast) - } + map?.let { projectionImpl?.updateProjectionState(it.cameraPosition, it.projection) } cameraMoveListener?.onCameraMove() cameraChangeListener?.onCameraChange(map?.cameraPosition?.toGms()) } catch (e: Exception) { @@ -784,7 +778,12 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) map.setOnCameraMoveListener { Log.d(TAG, "initMap: onCameraMove: ") try { + if (SDK_INT >= 26) { + mapView?.let { it.parent?.onDescendantInvalidated(it, it) } + } + map.let { projectionImpl?.updateProjectionState(it.cameraPosition, it.projection) } cameraMoveListener?.onCameraMove() + cameraChangeListener?.onCameraChange(map.cameraPosition?.toGms()) } catch (e: Exception) { Log.w(TAG, e) } diff --git a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/Projection.kt b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/Projection.kt index b054c95e21..a83370608d 100644 --- a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/Projection.kt +++ b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/Projection.kt @@ -15,6 +15,7 @@ import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.LatLngBounds import com.google.android.gms.maps.model.VisibleRegion import com.huawei.hms.maps.Projection +import com.huawei.hms.maps.model.CameraPosition import org.microg.gms.maps.hms.utils.toGms import org.microg.gms.maps.hms.utils.toHms import kotlin.math.roundToInt @@ -38,11 +39,14 @@ class ProjectionImpl(private var projection: Projection, private var withoutTilt private var farRightX = farRight?.x ?: (farLeftX + 1) private var nearLeftY = nearLeft?.y ?: (farLeftY + 1) - fun updateProjectionState(newProjection: Projection, useFastMode: Boolean) { - Log.d(TAG, "updateProjectionState: useFastMode: $useFastMode") - projection = newProjection - visibleRegion = newProjection.visibleRegion - withoutTiltOrBearing = useFastMode + fun updateProjectionState(cameraPosition: CameraPosition, projection: Projection) { + val tilt = cameraPosition.tilt + val bearing = cameraPosition.bearing + val useFast = tilt < 1f && (bearing % 360f < 1f || bearing % 360f > 359f) + Log.d(TAG, "updateProjectionState: useFastMode: $useFast") + + visibleRegion = projection.visibleRegion + withoutTiltOrBearing = useFast farLeft = visibleRegion.farLeft?.let { projection.toScreenLocation(it) } farRight = visibleRegion.farRight?.let { projection.toScreenLocation(it) } diff --git a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/UiSettings.kt b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/UiSettings.kt index cb2f59492b..945b06e539 100644 --- a/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/UiSettings.kt +++ b/play-services-maps/core/hms/src/main/kotlin/org/microg/gms/maps/hms/UiSettings.kt @@ -19,7 +19,20 @@ private const val TAG = "GmsMapsUiSettings" /** * This class "implements" unimplemented methods to avoid duplication in subclasses */ -abstract class AbstractUiSettings : IUiSettingsDelegate.Stub() { +abstract class AbstractUiSettings(rootView: ViewGroup) : IUiSettingsDelegate.Stub() { + + protected val mapUiController = MapUiController(rootView) + + init { + mapUiController.initUiStates( + mapOf( + MapUiElement.MyLocationButton to false, + MapUiElement.ZoomView to false, + MapUiElement.CompassView to false + ) + ) + } + override fun setZoomControlsEnabled(zoom: Boolean) { Log.d(TAG, "unimplemented Method: setZoomControlsEnabled") } @@ -66,22 +79,12 @@ abstract class AbstractUiSettings : IUiSettingsDelegate.Stub() { } } -class UiSettingsImpl(private val uiSettings: UiSettings, rootView: ViewGroup) : IUiSettingsDelegate.Stub() { - - private val mapUiController = MapUiController(rootView) +class UiSettingsImpl(private val uiSettings: UiSettings, rootView: ViewGroup) : AbstractUiSettings(rootView) { init { uiSettings.isZoomControlsEnabled = false uiSettings.isCompassEnabled = false - uiSettings.isMapToolbarEnabled = false uiSettings.isMyLocationButtonEnabled = false - mapUiController.initUiStates( - mapOf( - MapUiElement.MyLocationButton to false, - MapUiElement.ZoomView to false, - MapUiElement.CompassView to false - ) - ) } override fun setZoomControlsEnabled(zoom: Boolean) { @@ -180,7 +183,7 @@ class UiSettingsImpl(private val uiSettings: UiSettings, rootView: ViewGroup) : } } -class UiSettingsCache : AbstractUiSettings() { +class UiSettingsCache(rootView: ViewGroup) : AbstractUiSettings(rootView) { private var compass: Boolean? = null private var scrollGestures: Boolean? = null @@ -300,15 +303,28 @@ class UiSettingsCache : AbstractUiSettings() { fun getMapReadyCallback(): OnMapReadyCallback = OnMapReadyCallback { map -> val uiSettings = map.uiSettings - compass?.let { uiSettings.isCompassEnabled = it } + uiSettings.isZoomControlsEnabled = false + uiSettings.isCompassEnabled = false + uiSettings.isMyLocationButtonEnabled = false + + compass?.let { + uiSettings.isCompassEnabled = it + mapUiController.setUiEnabled(MapUiElement.CompassView, it) + } scrollGestures?.let { uiSettings.isScrollGesturesEnabled = it } zoomGestures?.let { uiSettings.isZoomGesturesEnabled = it } tiltGestures?.let { uiSettings.isTiltGesturesEnabled = it } rotateGestures?.let { uiSettings.isRotateGesturesEnabled = it } isAllGesturesEnabled?.let { uiSettings.setAllGesturesEnabled(it) } - isZoomControlsEnabled?.let { uiSettings.isZoomControlsEnabled = it } - isMyLocationButtonEnabled?.let { uiSettings.isMyLocationButtonEnabled = it } + isZoomControlsEnabled?.let { + uiSettings.isZoomControlsEnabled = it + mapUiController.setUiEnabled(MapUiElement.ZoomView, it) + } + isMyLocationButtonEnabled?.let { + uiSettings.isMyLocationButtonEnabled = it + mapUiController.setUiEnabled(MapUiElement.MyLocationButton, it) + } isIndoorLevelPickerEnabled?.let { uiSettings.isIndoorLevelPickerEnabled = it } isMapToolbarEnabled?.let { uiSettings.isMapToolbarEnabled = it } isScrollGesturesEnabledDuringRotateOrZoom?.let { uiSettings.isScrollGesturesEnabledDuringRotateOrZoom = it }