Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 00b8c363 authored by DaVinci9196's avatar DaVinci9196 Committed by GitHub
Browse files

HmsMaps: Optimize UI controls (#3129)

parent 95d5fc19
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -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)
            }
+9 −5
Original line number Diff line number Diff line
@@ -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) }
+32 −16
Original line number Diff line number Diff line
@@ -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 }