[6.1.0] code opt of mapbiz delay when callback in main thread
This commit is contained in:
@@ -3,6 +3,8 @@ package com.mogo.map
|
||||
import android.graphics.Point
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.text.TextUtils
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
@@ -79,12 +81,20 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
|
||||
override var currentMapVisualAngle: VisualAngleMode = VisualAngleMode.MODE_MEDIUM_SIGHT
|
||||
private set
|
||||
|
||||
//地图的接口回调操作都在主线程返回,基于此类回调,业务在使用时注意切换子线程/线程池处理
|
||||
private val handler by lazy {
|
||||
val thread = HandlerThread(TAG)
|
||||
thread.start()
|
||||
Handler(thread.looper)
|
||||
}
|
||||
|
||||
init {
|
||||
i(M_MAP + TAG, "AMapViewWrapper: init")
|
||||
this.mMapView = mMapView
|
||||
initViews()
|
||||
initListeners()
|
||||
mIMap = AMapWrapper(this.mMapView.getMapAutoViewHelper(), this.mMapView, this)
|
||||
handler.post {}
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
@@ -204,8 +214,10 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
|
||||
* @param laneId
|
||||
*/
|
||||
override fun onRoadIdInfo(roadId: String?, laneId: String?) {
|
||||
if (roadId != null && !TextUtils.isEmpty(roadId)) {
|
||||
invokeListenersOnRoadIdGet(roadId)
|
||||
handler.post {
|
||||
if (roadId != null && !TextUtils.isEmpty(roadId)) {
|
||||
invokeListenersOnRoadIdGet(roadId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,25 +226,30 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
|
||||
//对驶入驶出路口做二次过滤,防止多次回调
|
||||
if (it.status == 0 && newValue!!.status == 1) {
|
||||
//径直进入路口
|
||||
i("$M_MAP$TAG", "进入路口 :${newValue.cross_id}")
|
||||
invokeRoadChange(0, newValue)
|
||||
handler.post {
|
||||
// i("$M_MAP$TAG", "进入路口 :${newValue.cross_id}")
|
||||
invokeRoadChange(0, newValue)
|
||||
}
|
||||
}
|
||||
if ((it.status == 1 && newValue!!.status == 0)) {
|
||||
//径直驶出路口
|
||||
i("$M_MAP$TAG", "驶出路口 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
|
||||
invokeRoadChange(1, newValue)
|
||||
handler.post {
|
||||
// i("$M_MAP$TAG", "驶出路口 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
|
||||
invokeRoadChange(1, newValue)
|
||||
}
|
||||
return@let
|
||||
}
|
||||
if ((newValue!!.cross_id_end.isNotEmpty() && oldValue.cross_id_end != newValue.cross_id_end)) {
|
||||
//路口发生变化
|
||||
i("$M_MAP$TAG", "路段发生变化 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
|
||||
invokeRoadChange(2, newValue)
|
||||
handler.post {
|
||||
// i("$M_MAP$TAG", "路段发生变化 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
|
||||
invokeRoadChange(2, newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRoadCrossInfo(roadCross: RoadCross?) {
|
||||
d(M_MAP + TAG, "onRoadCrossInfo:roadCross$roadCross")
|
||||
roadCross?.let {
|
||||
this.roadCross = it
|
||||
}
|
||||
@@ -240,9 +257,11 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
|
||||
|
||||
override fun onStopLineInfo(stopLine: StopLine?) {
|
||||
stopLine?.let {
|
||||
if (it.road_id.isNotEmpty() && it.points.size > 0) {
|
||||
d(M_MAP + TAG, "onStopLineInfo: $it")
|
||||
invokeListenersOnStopLineGet(it)
|
||||
handler.post {
|
||||
if (it.road_id.isNotEmpty() && it.points.size > 0) {
|
||||
d(M_MAP + TAG, "onStopLineInfo: $it")
|
||||
invokeListenersOnStopLineGet(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -560,20 +579,21 @@ class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIControlle
|
||||
|
||||
override fun changeCurrentIcon(iconId: Int) {
|
||||
if (checkAMapView()) {
|
||||
val changeResult = mMapView.getMapAutoViewHelper()!!.getMyLocationStyle()!!
|
||||
.myLocationIcon(iconId, true)
|
||||
if (!changeResult) {
|
||||
val count = reChangeIconCount.incrementAndGet()
|
||||
MapTraceUtil.log(
|
||||
"", ChainConstant.CHAIN_CODE_HD_MAP_ICON_SET, TAG,
|
||||
mapOf("changeCurrentIcon-count" to "$count")
|
||||
)
|
||||
if (count >= 3) {
|
||||
return
|
||||
handler.post {
|
||||
val changeResult = mMapView.getMapAutoViewHelper()!!.getMyLocationStyle()!!
|
||||
.myLocationIcon(iconId, true)
|
||||
if (!changeResult) {
|
||||
val count = reChangeIconCount.incrementAndGet()
|
||||
MapTraceUtil.log(
|
||||
"", ChainConstant.CHAIN_CODE_HD_MAP_ICON_SET, TAG,
|
||||
mapOf("changeCurrentIcon-count" to "$count")
|
||||
)
|
||||
if (count >= 3) {
|
||||
return@post
|
||||
}
|
||||
handler.postDelayed({ changeCurrentIcon(iconId) },300L)
|
||||
reChangeIconCount.set(0)
|
||||
}
|
||||
UiThreadHandler.postDelayed({ changeCurrentIcon(iconId) }, 3000L,
|
||||
UiThreadHandler.MODE.QUEUE)
|
||||
reChangeIconCount.set(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user