Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down