From e69a1b7a0dd2f6a4d8cf8a3aa8d7a80a397bdc2c Mon Sep 17 00:00:00 2001 From: Davinci9196 Date: Thu, 6 Nov 2025 17:22:01 +0800 Subject: [PATCH 1/6] HmsMaps: Optimize UI controls --- .../org/microg/gms/maps/hms/GoogleMap.kt | 12 ++--- .../org/microg/gms/maps/hms/Projection.kt | 15 ++++-- .../org/microg/gms/maps/hms/UiSettings.kt | 48 ++++++++++++------- 3 files changed, 45 insertions(+), 30 deletions(-) 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..64263f77a4 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,12 +441,12 @@ 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()) } override fun getProjection(): IProjectionDelegate { - return projectionImpl ?: map?.projection?.let { + return map?.let { projectionImpl?.updateProjectionState(it.cameraPosition, it.projection) } ?: map?.projection?.let { val experiment = try { map?.cameraPosition?.tilt == 0.0f && map?.cameraPosition?.bearing == 0.0f } catch (e: Exception) { @@ -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) { 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..949d4c0605 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): IProjectionDelegate { + 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) } @@ -56,6 +60,7 @@ class ProjectionImpl(private var projection: Projection, private var withoutTilt farLeftY = farLeft?.y ?: 0 farRightX = farRight?.x ?: (farLeftX + 1) nearLeftY = nearLeft?.y ?: (farLeftY + 1) + return this } private fun isInvalid(): Boolean { 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 } From 4ecf6c5c57b962c9b4acf996b5292d8466e6bfec Mon Sep 17 00:00:00 2001 From: Davinci9196 Date: Fri, 14 Nov 2025 11:38:41 +0800 Subject: [PATCH 2/6] sync listener --- .../hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt | 5 +++++ 1 file changed, 5 insertions(+) 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 64263f77a4..7a9f08497c 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 @@ -778,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) } From cdb6f0e7508b5fd616a540b5e391f3ea8aa5fd6f Mon Sep 17 00:00:00 2001 From: Davinci9196 Date: Tue, 18 Nov 2025 20:29:28 +0800 Subject: [PATCH 3/6] Added processing when the map is not displayed --- .../hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt | 5 +++++ 1 file changed, 5 insertions(+) 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 7a9f08497c..a3199e7613 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 @@ -958,6 +958,11 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) runCallbacks() } if (!wasCallbackActive) isInvokingInitializedCallbacks.set(false) + } else if (mapView?.isShown == false) { + runOnMainLooper(forceQueue = true) { + Log.d("$TAG:$tag", "Invoking callback now: map cannot be initialized because it is not shown (yet)") + runCallbacks() + } } else { Log.d( "$TAG:$tag", From 8a80a76a0b1d7175abe19baddd671fc02deafda8 Mon Sep 17 00:00:00 2001 From: Davinci9196 Date: Fri, 28 Nov 2025 11:49:42 +0800 Subject: [PATCH 4/6] update --- .../hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt | 2 +- .../hms/src/main/kotlin/org/microg/gms/maps/hms/Projection.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) 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 a3199e7613..4b2bfb8048 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 @@ -446,7 +446,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) } override fun getProjection(): IProjectionDelegate { - return map?.let { projectionImpl?.updateProjectionState(it.cameraPosition, it.projection) } ?: map?.projection?.let { + return projectionImpl ?: map?.projection?.let { val experiment = try { map?.cameraPosition?.tilt == 0.0f && map?.cameraPosition?.bearing == 0.0f } catch (e: Exception) { 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 949d4c0605..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 @@ -39,7 +39,7 @@ 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(cameraPosition: CameraPosition, projection: Projection): IProjectionDelegate { + fun updateProjectionState(cameraPosition: CameraPosition, projection: Projection) { val tilt = cameraPosition.tilt val bearing = cameraPosition.bearing val useFast = tilt < 1f && (bearing % 360f < 1f || bearing % 360f > 359f) @@ -60,7 +60,6 @@ class ProjectionImpl(private var projection: Projection, private var withoutTilt farLeftY = farLeft?.y ?: 0 farRightX = farRight?.x ?: (farLeftX + 1) nearLeftY = nearLeft?.y ?: (farLeftY + 1) - return this } private fun isInvalid(): Boolean { From 41ee85e5bd84a4d714cd485eb0119e3b09801dba Mon Sep 17 00:00:00 2001 From: Davinci9196 Date: Wed, 17 Dec 2025 17:57:51 +0800 Subject: [PATCH 5/6] clear code --- .../src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) 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 4b2bfb8048..6ba5435ed5 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 @@ -657,7 +657,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) cameraMoveListener = listener it.setOnCameraMoveListener { try { - Log.d(TAG, "Listener: onCameraMove: ") +// Log.d(TAG, "Listener: onCameraMove: ") if (SDK_INT >= 26) { mapView?.let { it.parent?.onDescendantInvalidated(it, it) } } @@ -776,7 +776,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) } map.setOnCameraMoveListener { - Log.d(TAG, "initMap: onCameraMove: ") +// Log.d(TAG, "initMap: onCameraMove: ") try { if (SDK_INT >= 26) { mapView?.let { it.parent?.onDescendantInvalidated(it, it) } @@ -958,11 +958,6 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) runCallbacks() } if (!wasCallbackActive) isInvokingInitializedCallbacks.set(false) - } else if (mapView?.isShown == false) { - runOnMainLooper(forceQueue = true) { - Log.d("$TAG:$tag", "Invoking callback now: map cannot be initialized because it is not shown (yet)") - runCallbacks() - } } else { Log.d( "$TAG:$tag", From be18f484f380382b326cdb50f43f1e1e5deaad3b Mon Sep 17 00:00:00 2001 From: Davinci9196 Date: Wed, 17 Dec 2025 18:42:11 +0800 Subject: [PATCH 6/6] clean code --- .../hms/src/main/kotlin/org/microg/gms/maps/hms/GoogleMap.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 6ba5435ed5..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 @@ -657,7 +657,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) cameraMoveListener = listener it.setOnCameraMoveListener { try { -// Log.d(TAG, "Listener: onCameraMove: ") + Log.d(TAG, "Listener: onCameraMove: ") if (SDK_INT >= 26) { mapView?.let { it.parent?.onDescendantInvalidated(it, it) } } @@ -776,7 +776,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions) } map.setOnCameraMoveListener { -// Log.d(TAG, "initMap: onCameraMove: ") + Log.d(TAG, "initMap: onCameraMove: ") try { if (SDK_INT >= 26) { mapView?.let { it.parent?.onDescendantInvalidated(it, it) }