Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMS Maps: Optimize the phenomenon of Uber route drift. #2608

Merged
merged 2 commits into from
Nov 16, 2024
Merged
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 @@ -18,8 +18,6 @@ import android.widget.LinearLayout
import androidx.collection.LongSparseArray
import com.google.android.gms.dynamic.IObjectWrapper
import com.google.android.gms.dynamic.unwrap
import com.google.android.gms.maps.GoogleMap.MAP_TYPE_HYBRID
import com.google.android.gms.maps.GoogleMap.MAP_TYPE_SATELLITE
import com.google.android.gms.maps.GoogleMap.MAP_TYPE_TERRAIN
import com.google.android.gms.maps.GoogleMapOptions
import com.google.android.gms.maps.internal.*
Expand Down Expand Up @@ -87,7 +85,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)

private var storedMapType: Int = options.mapType
val waitingCameraUpdates = mutableListOf<CameraUpdate>()
var locationEnabled: Boolean = false
private val controlLayerRun = Runnable { refreshContainerLayer(false) }

private var markerId = 0L
val markers = mutableMapOf<String, MarkerImpl>()
Expand Down Expand Up @@ -306,8 +304,9 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
internalOnInitializedCallbackList.add(it.getMapReadyCallback())
}

override fun getProjection(): IProjectionDelegate =
map?.projection?.let { ProjectionImpl(it) } ?: DummyProjection()
override fun getProjection(): IProjectionDelegate {
return map?.projection?.let { ProjectionImpl(it) } ?: DummyProjection()
}

override fun setOnCameraChangeListener(listener: IOnCameraChangeListener?) = afterInitialize {
Log.d(TAG, "setOnCameraChangeListener");
Expand Down Expand Up @@ -493,6 +492,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
cameraMoveStartedListener = listener
hmap.setOnCameraMoveStartedListener {
try {
Log.d(TAG, "setCameraMoveStartedListener: ")
cameraMoveStartedListener?.onCameraMoveStarted(it)
} catch (e: Exception) {
Log.w(TAG, e)
Expand All @@ -505,15 +505,12 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
cameraMoveListener = listener
it.setOnCameraMoveListener {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if(mapView != null){
if(mapView!!.parent != null){
mapView!!.parent.onDescendantInvalidated(mapView!!,mapView!!)
}
}
}
Log.d(TAG, "setOnCameraMoveListener: ")
view.removeCallbacks(controlLayerRun)
refreshContainerLayer(true)
cameraMoveListener?.onCameraMove()
cameraChangeListener?.onCameraChange(map?.cameraPosition?.toGms())
view.postDelayed(controlLayerRun, 200)
} catch (e: Exception) {
Log.w(TAG, e)
}
Expand All @@ -525,6 +522,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
cameraMoveCanceledListener = listener
it.setOnCameraMoveCanceledListener {
try {
Log.d(TAG, "setOnCameraMoveCanceledListener: ")
cameraMoveCanceledListener?.onCameraMoveCanceled()
} catch (e: Exception) {
Log.w(TAG, e)
Expand All @@ -537,6 +535,7 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
cameraIdleListener = listener
it.setOnCameraIdleListener {
try {
Log.d(TAG, "setOnCameraIdleListener: ")
cameraIdleListener?.onCameraIdle()
} catch (e: Exception) {
Log.w(TAG, e)
Expand Down Expand Up @@ -804,6 +803,24 @@ class GoogleMapImpl(private val context: Context, var options: GoogleMapOptions)
}
}

private fun refreshContainerLayer(hide: Boolean = false) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
view.onDescendantInvalidated(mapView!!, mapView!!)
}
val parentView = view.parent?.parent
if (parentView != null) {
if (parentView is ViewGroup) {
for (i in 0 until parentView.childCount) {
val viewChild = parentView.getChildAt(i)
// Uber is prone to route drift, so here we hide the corresponding layer
if (viewChild::class.qualifiedName == "com.ubercab.android.map.fu") {
viewChild.visibility = if (hide) View.INVISIBLE else View.VISIBLE
}
}
}
}
}

override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean =
if (super.onTransact(code, data, reply, flags)) {
Log.d(TAG, "onTransact: $code, $data, $flags")
Expand Down